2020-09-09 16:49:01 +02:00
|
|
|
package de.ellpeck.actuallyadditions.common.blocks;
|
2015-11-09 18:05:52 +01:00
|
|
|
|
2020-09-09 16:49:01 +02:00
|
|
|
import de.ellpeck.actuallyadditions.common.ActuallyAdditions;
|
|
|
|
import de.ellpeck.actuallyadditions.common.items.metalists.TheCrystals;
|
|
|
|
import de.ellpeck.actuallyadditions.common.util.StringUtil;
|
2015-11-09 18:05:52 +01:00
|
|
|
import net.minecraft.block.Block;
|
2020-09-08 00:46:45 +02:00
|
|
|
import net.minecraft.block.SoundType;
|
2015-11-09 18:05:52 +01:00
|
|
|
import net.minecraft.block.material.Material;
|
2016-11-21 16:23:48 +01:00
|
|
|
import net.minecraft.block.properties.PropertyEnum;
|
|
|
|
import net.minecraft.block.state.BlockStateContainer;
|
2016-01-07 21:41:28 +01:00
|
|
|
import net.minecraft.block.state.IBlockState;
|
2015-11-09 18:05:52 +01:00
|
|
|
import net.minecraft.creativetab.CreativeTabs;
|
2020-09-09 17:18:09 +02:00
|
|
|
import net.minecraft.item.BlockItem;
|
2015-11-09 18:05:52 +01:00
|
|
|
import net.minecraft.item.EnumRarity;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2016-11-19 21:11:17 +01:00
|
|
|
import net.minecraft.util.NonNullList;
|
2019-05-02 09:08:15 +02:00
|
|
|
import net.minecraftforge.common.IRarity;
|
2020-09-08 00:46:45 +02:00
|
|
|
import net.minecraftforge.common.ToolType;
|
2016-01-07 18:20:59 +01:00
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
2015-11-09 18:05:52 +01:00
|
|
|
|
2020-09-08 00:46:45 +02:00
|
|
|
public class BlockCrystal extends Block {
|
2015-11-09 18:05:52 +01:00
|
|
|
|
2016-06-17 23:50:38 +02:00
|
|
|
public static final TheCrystals[] ALL_CRYSTALS = TheCrystals.values();
|
2016-11-21 16:23:48 +01:00
|
|
|
private static final PropertyEnum<TheCrystals> TYPE = PropertyEnum.create("type", TheCrystals.class);
|
2015-11-09 18:05:52 +01:00
|
|
|
|
2016-11-16 20:31:16 +01:00
|
|
|
private final boolean isEmpowered;
|
2016-08-03 13:36:42 +02:00
|
|
|
|
2020-09-08 00:46:45 +02:00
|
|
|
public BlockCrystal(boolean isEmpowered) {
|
|
|
|
super(Properties.create(Material.ROCK)
|
|
|
|
.hardnessAndResistance(1.5f, 10.0f)
|
|
|
|
.harvestTool(ToolType.PICKAXE)
|
|
|
|
.sound(SoundType.STONE));
|
|
|
|
|
2016-08-03 13:36:42 +02:00
|
|
|
this.isEmpowered = isEmpowered;
|
2015-11-09 18:05:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-02 09:08:15 +02:00
|
|
|
public int damageDropped(IBlockState state) {
|
2016-01-07 21:41:28 +01:00
|
|
|
return this.getMetaFromState(state);
|
2015-11-09 18:05:52 +01:00
|
|
|
}
|
|
|
|
|
2016-06-10 21:52:37 +02:00
|
|
|
@Override
|
2015-11-09 18:05:52 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2019-05-02 09:08:15 +02:00
|
|
|
public void getSubBlocks(CreativeTabs tab, NonNullList<ItemStack> list) {
|
|
|
|
for (int j = 0; j < ALL_CRYSTALS.length; j++) {
|
2017-06-17 00:48:49 +02:00
|
|
|
list.add(new ItemStack(this, 1, j));
|
2015-11-09 18:05:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-01 20:32:49 +01:00
|
|
|
@Override
|
2020-09-09 09:58:55 +02:00
|
|
|
protected BlockItemBase getItemBlock() {
|
2016-04-20 21:39:03 +02:00
|
|
|
return new TheItemBlock(this);
|
2016-02-01 20:32:49 +01:00
|
|
|
}
|
|
|
|
|
2016-02-01 17:49:55 +01:00
|
|
|
@Override
|
2019-05-02 09:08:15 +02:00
|
|
|
public void registerRendering() {
|
|
|
|
for (int i = 0; i < ALL_CRYSTALS.length; i++) {
|
|
|
|
ActuallyAdditions.PROXY.addRenderRegister(new ItemStack(this, 1, i), this.getRegistryName(), TYPE.getName() + "=" + ALL_CRYSTALS[i].name);
|
2016-02-01 17:49:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-09 18:05:52 +01:00
|
|
|
@Override
|
2019-05-02 09:08:15 +02:00
|
|
|
public IBlockState getStateFromMeta(int meta) {
|
2016-11-21 16:23:48 +01:00
|
|
|
return this.getDefaultState().withProperty(TYPE, TheCrystals.values()[meta]);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-02 09:08:15 +02:00
|
|
|
public int getMetaFromState(IBlockState state) {
|
2016-11-21 16:23:48 +01:00
|
|
|
return state.getValue(TYPE).ordinal();
|
2015-11-09 18:05:52 +01:00
|
|
|
}
|
|
|
|
|
2016-01-10 15:29:44 +01:00
|
|
|
@Override
|
2019-05-02 09:08:15 +02:00
|
|
|
protected BlockStateContainer createBlockState() {
|
2016-11-21 16:23:48 +01:00
|
|
|
return new BlockStateContainer(this, TYPE);
|
|
|
|
}
|
|
|
|
|
2020-09-09 17:18:09 +02:00
|
|
|
public static class TheItemBlock extends BlockItem {
|
2015-11-09 18:05:52 +01:00
|
|
|
|
2019-05-02 09:08:15 +02:00
|
|
|
public TheItemBlock(Block block) {
|
2015-11-09 18:05:52 +01:00
|
|
|
super(block);
|
|
|
|
this.setHasSubtypes(true);
|
|
|
|
this.setMaxDamage(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-02 09:08:15 +02:00
|
|
|
public String getTranslationKey(ItemStack stack) {
|
|
|
|
return stack.getItemDamage() >= ALL_CRYSTALS.length ? StringUtil.BUGGED_ITEM_NAME : this.getTranslationKey() + "_" + ALL_CRYSTALS[stack.getItemDamage()].name;
|
2015-11-09 18:05:52 +01:00
|
|
|
}
|
2016-08-03 13:36:42 +02:00
|
|
|
|
|
|
|
@Override
|
2019-05-02 09:08:15 +02:00
|
|
|
public boolean hasEffect(ItemStack stack) {
|
|
|
|
return this.block instanceof BlockCrystal && ((BlockCrystal) this.block).isEmpowered;
|
2016-08-03 13:36:42 +02:00
|
|
|
}
|
2015-11-09 18:05:52 +01:00
|
|
|
}
|
|
|
|
}
|