diff --git a/src/main/java/WayofTime/bloodmagic/block/BlockInversionPillar.java b/src/main/java/WayofTime/bloodmagic/block/BlockInversionPillar.java index 9945415f..e0c5c807 100644 --- a/src/main/java/WayofTime/bloodmagic/block/BlockInversionPillar.java +++ b/src/main/java/WayofTime/bloodmagic/block/BlockInversionPillar.java @@ -107,9 +107,7 @@ public class BlockInversionPillar extends BlockStringContainer implements IVaria return new TileInversionPillar(EnumDemonWillType.values()[meta % 5]); } - @Override - protected BlockStateContainer createRealBlockState() - { - return new ExtendedBlockState(this, new IProperty[] { stringProp, Properties.StaticProperty }, new IUnlistedProperty[] { unlistedStringProp, Properties.AnimationProperty }); + protected BlockStateContainer createStateContainer() { + return new BlockStateContainer.Builder(this).add(getProperty(), Properties.StaticProperty).add(Properties.AnimationProperty).build(); } } diff --git a/src/main/java/WayofTime/bloodmagic/block/BlockRitualController.java b/src/main/java/WayofTime/bloodmagic/block/BlockRitualController.java index 577f0c13..dc0b9f6a 100644 --- a/src/main/java/WayofTime/bloodmagic/block/BlockRitualController.java +++ b/src/main/java/WayofTime/bloodmagic/block/BlockRitualController.java @@ -133,14 +133,14 @@ public class BlockRitualController extends BlockStringContainer implements IVari public ResourceLocation getLinkedEntry(World world, BlockPos pos, EntityPlayer player, ItemStack stack) { IBlockState state = world.getBlockState(pos); - if (state.getValue(getStringProp()).equals(names[0])) + if (state.getValue(getProperty()).equals(names[0])) { TileMasterRitualStone mrs = (TileMasterRitualStone) world.getTileEntity(pos); if (mrs == null || mrs.getCurrentRitual() == null) return null; else return new ResourceLocation("bloodmagic", "ritual_" + mrs.getCurrentRitual().getName()); - } else if (state.getValue(getStringProp()).equals(names[1])) + } else if (state.getValue(getProperty()).equals(names[1])) { ImperfectRitual imperfectRitual = ImperfectRitualRegistry.getRitualForBlock(BlockStack.getStackFromPos(world, pos.up())); if (imperfectRitual != null) diff --git a/src/main/java/WayofTime/bloodmagic/block/base/BlockEnum.java b/src/main/java/WayofTime/bloodmagic/block/base/BlockEnum.java new file mode 100644 index 00000000..182f6f4f --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/block/base/BlockEnum.java @@ -0,0 +1,73 @@ +package WayofTime.bloodmagic.block.base; + +import lombok.Getter; +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.block.properties.PropertyEnum; +import net.minecraft.block.state.BlockStateContainer; +import net.minecraft.block.state.IBlockState; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IStringSerializable; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import java.util.List; + +@Getter +public class BlockEnum & IStringSerializable> extends Block { + + private final E[] types; + private final PropertyEnum property; + private final BlockStateContainer realStateContainer; + + public BlockEnum(Material material, Class enumClass, String propName) { + super(material); + + this.types = enumClass.getEnumConstants(); + this.property = PropertyEnum.create(propName, enumClass); + this.realStateContainer = createStateContainer(); + setDefaultState(getBlockState().getBaseState()); + } + + public BlockEnum(Material material, Class enumClass) { + this(material, enumClass, "type"); + } + + @Override + protected final BlockStateContainer createBlockState() { + return new BlockStateContainer.Builder(this).build(); // Blank to avoid crashes + } + + @Override + public final BlockStateContainer getBlockState() { + return realStateContainer; + } + + @Override + public IBlockState getStateFromMeta(int meta) { + return getDefaultState().withProperty(property, types[meta]); + } + + @Override + public int getMetaFromState(IBlockState state) { + return state.getValue(property).ordinal(); + } + + @Override + public int damageDropped(IBlockState state) { + return getMetaFromState(state); + } + + @SideOnly(Side.CLIENT) + @Override + public void getSubBlocks(Item item, CreativeTabs tab, List subBlocks) { + for (E type : types) + subBlocks.add(new ItemStack(item, 1, type.ordinal())); + } + + protected BlockStateContainer createStateContainer() { + return new BlockStateContainer.Builder(this).add(property).build(); + } +} diff --git a/src/main/java/WayofTime/bloodmagic/block/base/BlockInteger.java b/src/main/java/WayofTime/bloodmagic/block/base/BlockInteger.java index c36b9f8d..bac679b4 100644 --- a/src/main/java/WayofTime/bloodmagic/block/base/BlockInteger.java +++ b/src/main/java/WayofTime/bloodmagic/block/base/BlockInteger.java @@ -1,24 +1,14 @@ package WayofTime.bloodmagic.block.base; -import WayofTime.bloodmagic.block.property.UnlistedPropertyInteger; import lombok.Getter; import net.minecraft.block.Block; import net.minecraft.block.material.Material; -import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyInteger; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.RayTraceResult; -import net.minecraft.world.World; -import net.minecraftforge.common.property.ExtendedBlockState; -import net.minecraftforge.common.property.IExtendedBlockState; -import net.minecraftforge.common.property.IUnlistedProperty; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -28,28 +18,22 @@ import java.util.List; * Creates a block that has multiple meta-based states. * * These states will be numbered 0 through {@code maxMeta}. - * - * For {@link net.minecraft.tileentity.TileEntity}'s, use - * {@link BlockIntegerContainer}. */ @Getter public class BlockInteger extends Block { private final int maxMeta; - private final PropertyInteger metaProp; - private final IUnlistedProperty unlistedMetaProp; - private final BlockStateContainer realBlockState; + private final PropertyInteger property; + private final BlockStateContainer realStateContainer; public BlockInteger(Material material, int maxMeta, String propName) { super(material); this.maxMeta = maxMeta; - - this.metaProp = PropertyInteger.create(propName, 0, maxMeta); - this.unlistedMetaProp = new UnlistedPropertyInteger(maxMeta, propName); - this.realBlockState = createRealBlockState(); - setupStates(); + this.property = PropertyInteger.create(propName, 0, maxMeta); + this.realStateContainer = createStateContainer(); + setDefaultState(getBlockState().getBaseState()); } public BlockInteger(Material material, int maxMeta) @@ -58,66 +42,38 @@ public class BlockInteger extends Block } @Override - public IBlockState getStateFromMeta(int meta) - { - return getDefaultState().withProperty(metaProp, meta); + protected final BlockStateContainer createBlockState() { + return new BlockStateContainer.Builder(this).build(); // Blank to avoid crashes } @Override - public int getMetaFromState(IBlockState state) - { - return (Integer) state.getValue(metaProp); + public final BlockStateContainer getBlockState() { + return realStateContainer; } @Override - public int damageDropped(IBlockState state) - { + public IBlockState getStateFromMeta(int meta) { + return getDefaultState().withProperty(property, meta); + } + + @Override + public int getMetaFromState(IBlockState state) { + return state.getValue(property); + } + + @Override + public int damageDropped(IBlockState state) { return getMetaFromState(state); } - @Override - public BlockStateContainer getBlockState() - { - return this.realBlockState; - } - - @Override - public BlockStateContainer createBlockState() - { - return Blocks.AIR.getBlockState(); - } - - @Override - public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) - { - return new ItemStack(this, 1, this.getMetaFromState(world.getBlockState(pos))); - } - - @Override @SideOnly(Side.CLIENT) - public void getSubBlocks(Item item, CreativeTabs creativeTabs, List list) - { - for (int i = 0; i < maxMeta + 1; i++) - list.add(new ItemStack(this, 1, i)); + @Override + public void getSubBlocks(Item item, CreativeTabs tab, List subBlocks) { + for (int i = 0; i < maxMeta; i++) + subBlocks.add(new ItemStack(item, 1, i)); } - private void setupStates() - { - this.setDefaultState(getExtendedBlockState().withProperty(unlistedMetaProp, 0).withProperty(metaProp, 0)); - } - - public ExtendedBlockState getBaseExtendedState() - { - return (ExtendedBlockState) this.getBlockState(); - } - - public IExtendedBlockState getExtendedBlockState() - { - return (IExtendedBlockState) this.getBaseExtendedState().getBaseState(); - } - - private BlockStateContainer createRealBlockState() - { - return new ExtendedBlockState(this, new IProperty[] { metaProp }, new IUnlistedProperty[] { unlistedMetaProp }); + protected BlockStateContainer createStateContainer() { + return new BlockStateContainer.Builder(this).add(property).build(); } } diff --git a/src/main/java/WayofTime/bloodmagic/block/base/BlockString.java b/src/main/java/WayofTime/bloodmagic/block/base/BlockString.java index ae8aeb3e..d2b9b65c 100644 --- a/src/main/java/WayofTime/bloodmagic/block/base/BlockString.java +++ b/src/main/java/WayofTime/bloodmagic/block/base/BlockString.java @@ -1,28 +1,19 @@ package WayofTime.bloodmagic.block.base; -import java.util.Arrays; import java.util.List; import lombok.Getter; import net.minecraft.block.Block; import net.minecraft.block.material.Material; -import net.minecraft.block.properties.IProperty; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.RayTraceResult; -import net.minecraft.world.World; -import net.minecraftforge.common.property.ExtendedBlockState; -import net.minecraftforge.common.property.IExtendedBlockState; -import net.minecraftforge.common.property.IUnlistedProperty; +import WayofTime.bloodmagic.block.property.PropertyString; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -import WayofTime.bloodmagic.block.property.PropertyString; -import WayofTime.bloodmagic.block.property.UnlistedPropertyString; +import org.apache.commons.lang3.ArrayUtils; /** * Creates a block that has multiple meta-based states. @@ -30,30 +21,25 @@ import WayofTime.bloodmagic.block.property.UnlistedPropertyString; * These states will be named after the given string array. Somewhere along the * way, each value is {@code toLowerCase()}'ed, so the blockstate JSON needs all * values to be lowercase. - * - * For {@link net.minecraft.tileentity.TileEntity}'s, use - * {@link BlockStringContainer}. */ @Getter public class BlockString extends Block { private final int maxMeta; - private final List values; - protected final PropertyString stringProp; - protected final IUnlistedProperty unlistedStringProp; - private final BlockStateContainer realBlockState; + private final String[] types; + private final PropertyString property; + private final BlockStateContainer realStateContainer; public BlockString(Material material, String[] values, String propName) { super(material); - this.maxMeta = values.length - 1; - this.values = Arrays.asList(values); + this.maxMeta = values.length; + this.types = values; - this.stringProp = PropertyString.create(propName, values); - this.unlistedStringProp = new UnlistedPropertyString(values, propName); - this.realBlockState = createRealBlockState(); - setupStates(); + this.property = PropertyString.create(propName, values); + this.realStateContainer = createStateContainer(); + setDefaultState(getBlockState().getBaseState()); } public BlockString(Material material, String[] values) @@ -62,60 +48,38 @@ public class BlockString extends Block } @Override - public IBlockState getStateFromMeta(int meta) - { - return getBlockState().getBaseState().withProperty(stringProp, values.get(meta)); + protected final BlockStateContainer createBlockState() { + return new BlockStateContainer.Builder(this).build(); // Blank to avoid crashes } @Override - public int getMetaFromState(IBlockState state) - { - return values.indexOf(String.valueOf(state.getValue(stringProp))); + public final BlockStateContainer getBlockState() { + return realStateContainer; } @Override - public int damageDropped(IBlockState state) - { + public IBlockState getStateFromMeta(int meta) { + return getDefaultState().withProperty(property, types[meta]); + } + + @Override + public int getMetaFromState(IBlockState state) { + return ArrayUtils.indexOf(types, state.getValue(property)); + } + + @Override + public int damageDropped(IBlockState state) { return getMetaFromState(state); } - @Override - public BlockStateContainer getBlockState() - { - return this.realBlockState; - } - - @Override - public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) - { - return new ItemStack(this, 1, this.getMetaFromState(world.getBlockState(pos))); - } - - @Override @SideOnly(Side.CLIENT) - public void getSubBlocks(Item item, CreativeTabs creativeTabs, List list) - { - for (int i = 0; i < maxMeta + 1; i++) - list.add(new ItemStack(this, 1, i)); + @Override + public void getSubBlocks(Item item, CreativeTabs tab, List subBlocks) { + for (int i = 0; i < maxMeta; i++) + subBlocks.add(new ItemStack(item, 1, i)); } - protected void setupStates() - { - this.setDefaultState(getExtendedBlockState().withProperty(unlistedStringProp, values.get(0)).withProperty(stringProp, values.get(0))); - } - - public ExtendedBlockState getBaseExtendedState() - { - return (ExtendedBlockState) this.getBlockState(); - } - - public IExtendedBlockState getExtendedBlockState() - { - return (IExtendedBlockState) this.getBaseExtendedState().getBaseState(); - } - - protected BlockStateContainer createRealBlockState() - { - return new ExtendedBlockState(this, new IProperty[] { stringProp }, new IUnlistedProperty[] { unlistedStringProp }); + protected BlockStateContainer createStateContainer() { + return new BlockStateContainer.Builder(this).add(property).build(); } } diff --git a/src/main/java/WayofTime/bloodmagic/block/base/BlockStringPillar.java b/src/main/java/WayofTime/bloodmagic/block/base/BlockStringPillar.java index 3f07047e..396a8b40 100644 --- a/src/main/java/WayofTime/bloodmagic/block/base/BlockStringPillar.java +++ b/src/main/java/WayofTime/bloodmagic/block/base/BlockStringPillar.java @@ -13,8 +13,7 @@ import net.minecraft.util.Rotation; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; import net.minecraft.world.World; -import net.minecraftforge.common.property.ExtendedBlockState; -import net.minecraftforge.common.property.IUnlistedProperty; +import org.apache.commons.lang3.ArrayUtils; public class BlockStringPillar extends BlockString { @@ -28,10 +27,15 @@ public class BlockStringPillar extends BlockString this(material, values, "type"); } + @Override + protected BlockStateContainer createStateContainer() { + return new BlockStateContainer.Builder(this).add(getProperty(), BlockRotatedPillar.AXIS).build(); + } + @Override public IBlockState getStateFromMeta(int meta) { - IBlockState state = getBlockState().getBaseState().withProperty(this.getStringProp(), this.getValues().get(meta % 5)); + IBlockState state = getBlockState().getBaseState().withProperty(this.getProperty(), getTypes()[meta % 5]); switch (meta / 5) { @@ -62,7 +66,7 @@ public class BlockStringPillar extends BlockString @Override public int getMetaFromState(IBlockState state) { - int i = this.getValues().indexOf(state.getValue(this.getStringProp())); + int i = ArrayUtils.indexOf(getTypes(), state.getValue(getProperty())); switch (state.getValue(BlockRotatedPillar.AXIS)) { @@ -114,18 +118,6 @@ public class BlockStringPillar extends BlockString } } - @Override - protected void setupStates() - { - this.setDefaultState(getExtendedBlockState().withProperty(this.getUnlistedStringProp(), this.getValues().get(0)).withProperty(this.getStringProp(), this.getValues().get(0)).withProperty(BlockRotatedPillar.AXIS, EnumFacing.Axis.Y)); - } - - @Override - protected BlockStateContainer createRealBlockState() - { - return new ExtendedBlockState(this, new IProperty[] { this.getStringProp(), BlockRotatedPillar.AXIS }, new IUnlistedProperty[] { this.getUnlistedStringProp() }); - } - @Override protected ItemStack createStackedBlock(IBlockState state) { @@ -141,6 +133,6 @@ public class BlockStringPillar extends BlockString @Override public int damageDropped(IBlockState state) { - return this.getValues().indexOf(state.getValue(this.getStringProp())); + return super.getMetaFromState(state); } } diff --git a/src/main/java/WayofTime/bloodmagic/block/base/BlockStringPillarCap.java b/src/main/java/WayofTime/bloodmagic/block/base/BlockStringPillarCap.java index eded7d9c..4c96a000 100644 --- a/src/main/java/WayofTime/bloodmagic/block/base/BlockStringPillarCap.java +++ b/src/main/java/WayofTime/bloodmagic/block/base/BlockStringPillarCap.java @@ -1,13 +1,11 @@ package WayofTime.bloodmagic.block.base; import net.minecraft.block.material.Material; -import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyDirection; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumFacing; import net.minecraft.util.Mirror; @@ -15,8 +13,7 @@ import net.minecraft.util.Rotation; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; import net.minecraft.world.World; -import net.minecraftforge.common.property.ExtendedBlockState; -import net.minecraftforge.common.property.IUnlistedProperty; +import org.apache.commons.lang3.ArrayUtils; public class BlockStringPillarCap extends BlockString { @@ -32,17 +29,22 @@ public class BlockStringPillarCap extends BlockString this(material, values, "type"); } + @Override + protected BlockStateContainer createStateContainer() { + return new BlockStateContainer.Builder(this).add(getProperty(), FACING).build(); + } + @Override public IBlockState getStateFromMeta(int meta) { - IBlockState state = getBlockState().getBaseState().withProperty(this.getStringProp(), this.getValues().get(meta % 2)); + IBlockState state = getBlockState().getBaseState().withProperty(this.getProperty(), getTypes()[meta % 2]); return state.withProperty(FACING, EnumFacing.getFront(meta / 2)); } @Override public int getMetaFromState(IBlockState state) { - int i = this.getValues().indexOf(state.getValue(this.getStringProp())); + int i = ArrayUtils.indexOf(getTypes(), state.getValue(getProperty())); return i + 2 * state.getValue(FACING).getIndex(); } @@ -64,18 +66,6 @@ public class BlockStringPillarCap extends BlockString return state.withRotation(mirrorIn.toRotation(state.getValue(FACING))); } - @Override - protected void setupStates() - { - this.setDefaultState(getExtendedBlockState().withProperty(this.getUnlistedStringProp(), this.getValues().get(0)).withProperty(this.getStringProp(), this.getValues().get(0)).withProperty(FACING, EnumFacing.UP)); - } - - @Override - protected BlockStateContainer createRealBlockState() - { - return new ExtendedBlockState(this, new IProperty[] { this.getStringProp(), FACING }, new IUnlistedProperty[] { this.getUnlistedStringProp() }); - } - @Override protected ItemStack createStackedBlock(IBlockState state) { @@ -91,6 +81,6 @@ public class BlockStringPillarCap extends BlockString @Override public int damageDropped(IBlockState state) { - return this.getValues().indexOf(state.getValue(this.getStringProp())); + return super.getMetaFromState(state); } } diff --git a/src/main/java/WayofTime/bloodmagic/block/base/BlockStringStairs.java b/src/main/java/WayofTime/bloodmagic/block/base/BlockStringStairs.java index 41fedc7d..5cf8687e 100644 --- a/src/main/java/WayofTime/bloodmagic/block/base/BlockStringStairs.java +++ b/src/main/java/WayofTime/bloodmagic/block/base/BlockStringStairs.java @@ -10,7 +10,6 @@ import net.minecraft.block.BlockStairs; import net.minecraft.block.BlockStairs.EnumHalf; import net.minecraft.block.BlockStairs.EnumShape; import net.minecraft.block.material.Material; -import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyDirection; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; @@ -27,10 +26,9 @@ import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.Vec3d; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; -import net.minecraftforge.common.property.ExtendedBlockState; -import net.minecraftforge.common.property.IUnlistedProperty; import com.google.common.collect.Lists; +import org.apache.commons.lang3.ArrayUtils; public class BlockStringStairs extends BlockString { @@ -65,6 +63,11 @@ public class BlockStringStairs extends BlockString this(material, values, "type"); } + @Override + protected BlockStateContainer createStateContainer() { + return new BlockStateContainer.Builder(this).add(getProperty(), FACING, BlockStairs.HALF, BlockStairs.SHAPE).build(); + } + @Override public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List collidingBoxes, @Nullable Entity entityIn) { @@ -206,7 +209,7 @@ public class BlockStringStairs extends BlockString public IBlockState getStateFromMeta(int meta) { IBlockState state = getBlockState().getBaseState().withProperty(BlockStairs.HALF, (meta & 8) > 0 ? BlockStairs.EnumHalf.TOP : BlockStairs.EnumHalf.BOTTOM); - state = state.withProperty(FACING, EnumFacing.getFront(5 - (meta & 6) / 2)).withProperty(this.getStringProp(), this.getValues().get(meta % 2)); + state = state.withProperty(FACING, EnumFacing.getFront(5 - (meta & 6) / 2)).withProperty(this.getProperty(), getTypes()[meta % 2]); return state; } @@ -222,7 +225,7 @@ public class BlockStringStairs extends BlockString } i = i | 5 - state.getValue(FACING).getIndex(); - return i * 2 + this.getValues().indexOf(state.getValue(this.getStringProp())); + return i * 2 + ArrayUtils.indexOf(getTypes(), state.getValue(getProperty())); } @Override @@ -340,12 +343,6 @@ public class BlockStringStairs extends BlockString return super.withMirror(state, mirrorIn); } - @Override - protected BlockStateContainer createRealBlockState() - { - return new ExtendedBlockState(this, new IProperty[] { BlockStairs.HALF, BlockStairs.SHAPE, FACING, this.getStringProp() }, new IUnlistedProperty[] { this.getUnlistedStringProp() }); - } - @Override protected ItemStack createStackedBlock(IBlockState state) { @@ -355,7 +352,7 @@ public class BlockStringStairs extends BlockString @Override public int damageDropped(IBlockState state) { - return this.getValues().indexOf(state.getValue(this.getStringProp())); + return super.getMetaFromState(state); } @Override diff --git a/src/main/java/WayofTime/bloodmagic/block/base/BlockStringWall.java b/src/main/java/WayofTime/bloodmagic/block/base/BlockStringWall.java index 495b57db..aa798d5e 100644 --- a/src/main/java/WayofTime/bloodmagic/block/base/BlockStringWall.java +++ b/src/main/java/WayofTime/bloodmagic/block/base/BlockStringWall.java @@ -42,6 +42,11 @@ public class BlockStringWall extends BlockString this(material, values, "type"); } + @Override + protected BlockStateContainer createStateContainer() { + return new BlockStateContainer.Builder(this).add(getProperty(), UP, NORTH, EAST, SOUTH, WEST).build(); + } + @Override public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) { @@ -124,18 +129,6 @@ public class BlockStringWall extends BlockString return state.withProperty(UP, !flag4 || !worldIn.isAirBlock(pos.up())).withProperty(NORTH, canNorth).withProperty(EAST, canEast).withProperty(SOUTH, canSouth).withProperty(WEST, canWest); } - @Override - protected void setupStates() - { - this.setDefaultState(getExtendedBlockState().withProperty(this.getUnlistedStringProp(), this.getValues().get(0)).withProperty(this.getStringProp(), this.getValues().get(0)).withProperty(UP, true).withProperty(NORTH, false).withProperty(SOUTH, false).withProperty(EAST, false).withProperty(WEST, false)); - } - - @Override - protected BlockStateContainer createRealBlockState() - { - return new ExtendedBlockState(this, new IProperty[] { UP, NORTH, SOUTH, EAST, WEST, this.getStringProp() }, new IUnlistedProperty[] { this.getUnlistedStringProp() }); - } - @Override protected ItemStack createStackedBlock(IBlockState state) { @@ -145,6 +138,6 @@ public class BlockStringWall extends BlockString @Override public int damageDropped(IBlockState state) { - return this.getValues().indexOf(state.getValue(this.getStringProp())); + return super.getMetaFromState(state); } } diff --git a/src/main/java/WayofTime/bloodmagic/block/property/PropertyString.java b/src/main/java/WayofTime/bloodmagic/block/property/PropertyString.java index bd9cc104..1fa570bc 100644 --- a/src/main/java/WayofTime/bloodmagic/block/property/PropertyString.java +++ b/src/main/java/WayofTime/bloodmagic/block/property/PropertyString.java @@ -18,10 +18,7 @@ public class PropertyString extends PropertyHelper protected PropertyString(String name, String[] values) { super(name, String.class); - - HashSet hashSet = Sets.newHashSet(); - hashSet.addAll(Arrays.asList(values)); - allowedValues = ImmutableSet.copyOf(hashSet); + allowedValues = ImmutableSet.copyOf(values); } @SideOnly(Side.CLIENT) diff --git a/src/main/java/WayofTime/bloodmagic/item/ItemInscriptionTool.java b/src/main/java/WayofTime/bloodmagic/item/ItemInscriptionTool.java index 0594ea68..88e7361a 100644 --- a/src/main/java/WayofTime/bloodmagic/item/ItemInscriptionTool.java +++ b/src/main/java/WayofTime/bloodmagic/item/ItemInscriptionTool.java @@ -65,7 +65,7 @@ public class ItemInscriptionTool extends ItemBindableBase implements IVariantPro stack = NBTHelper.checkNBT(stack); int uses = stack.getTagCompound().getInteger(Constants.NBT.USES); - world.setBlockState(pos, state.withProperty(((BlockRitualStone) state.getBlock()).getStringProp(), getType(stack).getName())); + world.setBlockState(pos, state.withProperty(((BlockRitualStone) state.getBlock()).getProperty(), getType(stack).getName())); if (!player.capabilities.isCreativeMode) { stack.getTagCompound().setInteger(Constants.NBT.USES, --uses); diff --git a/src/main/java/WayofTime/bloodmagic/item/block/base/ItemBlockEnum.java b/src/main/java/WayofTime/bloodmagic/item/block/base/ItemBlockEnum.java new file mode 100644 index 00000000..0ec613c2 --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/item/block/base/ItemBlockEnum.java @@ -0,0 +1,33 @@ +package WayofTime.bloodmagic.item.block.base; + +import WayofTime.bloodmagic.block.base.BlockEnum; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IStringSerializable; +import net.minecraft.util.math.MathHelper; + +public class ItemBlockEnum & IStringSerializable> extends ItemBlock { + + public ItemBlockEnum(BlockEnum block) { + super(block); + + if (block.getTypes().length > 1) + setHasSubtypes(true); + } + + @SuppressWarnings("unchecked") + @Override + public BlockEnum getBlock() { + return (BlockEnum) super.getBlock(); + } + + @Override + public String getUnlocalizedName(ItemStack stack) { + return getBlock().getUnlocalizedName() + "." + getBlock().getTypes()[MathHelper.clamp_int(stack.getItemDamage(), 0, 15)].getName(); + } + + @Override + public int getMetadata(int damage) { + return damage; + } +} diff --git a/src/main/java/WayofTime/bloodmagic/item/block/base/ItemBlockInteger.java b/src/main/java/WayofTime/bloodmagic/item/block/base/ItemBlockInteger.java new file mode 100644 index 00000000..038c4e22 --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/item/block/base/ItemBlockInteger.java @@ -0,0 +1,31 @@ +package WayofTime.bloodmagic.item.block.base; + +import WayofTime.bloodmagic.block.base.BlockInteger; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; + +public class ItemBlockInteger extends ItemBlock { + + public ItemBlockInteger(BlockInteger block) { + super(block); + + if (block.getMaxMeta() > 1) + setHasSubtypes(true); + } + + @SuppressWarnings("unchecked") + @Override + public BlockInteger getBlock() { + return (BlockInteger) super.getBlock(); + } + + @Override + public String getUnlocalizedName(ItemStack stack) { + return getBlock().getUnlocalizedName() + "." + stack.getItemDamage(); + } + + @Override + public int getMetadata(int damage) { + return damage; + } +} diff --git a/src/main/java/WayofTime/bloodmagic/item/block/base/ItemBlockString.java b/src/main/java/WayofTime/bloodmagic/item/block/base/ItemBlockString.java new file mode 100644 index 00000000..3fdea986 --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/item/block/base/ItemBlockString.java @@ -0,0 +1,32 @@ +package WayofTime.bloodmagic.item.block.base; + +import WayofTime.bloodmagic.block.base.BlockString; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; +import net.minecraft.util.math.MathHelper; + +public class ItemBlockString extends ItemBlock { + + public ItemBlockString(BlockString block) { + super(block); + + if (block.getTypes().length> 1) + setHasSubtypes(true); + } + + @SuppressWarnings("unchecked") + @Override + public BlockString getBlock() { + return (BlockString) super.getBlock(); + } + + @Override + public String getUnlocalizedName(ItemStack stack) { + return getBlock().getUnlocalizedName() + "." + getBlock().getTypes()[MathHelper.clamp_int(stack.getItemDamage(), 0, 15)]; + } + + @Override + public int getMetadata(int damage) { + return damage; + } +}