Rewrite base blocks to be less weird

Added base ItemBlock classes for each base type (to be used later)
This commit is contained in:
Nicholas Ignoffo 2016-10-15 09:21:30 -07:00
parent ea43fbce7d
commit 3e0f3f5aa1
14 changed files with 265 additions and 209 deletions

View file

@ -107,9 +107,7 @@ public class BlockInversionPillar extends BlockStringContainer implements IVaria
return new TileInversionPillar(EnumDemonWillType.values()[meta % 5]); return new TileInversionPillar(EnumDemonWillType.values()[meta % 5]);
} }
@Override protected BlockStateContainer createStateContainer() {
protected BlockStateContainer createRealBlockState() return new BlockStateContainer.Builder(this).add(getProperty(), Properties.StaticProperty).add(Properties.AnimationProperty).build();
{
return new ExtendedBlockState(this, new IProperty[] { stringProp, Properties.StaticProperty }, new IUnlistedProperty[] { unlistedStringProp, Properties.AnimationProperty });
} }
} }

View file

@ -133,14 +133,14 @@ public class BlockRitualController extends BlockStringContainer implements IVari
public ResourceLocation getLinkedEntry(World world, BlockPos pos, EntityPlayer player, ItemStack stack) public ResourceLocation getLinkedEntry(World world, BlockPos pos, EntityPlayer player, ItemStack stack)
{ {
IBlockState state = world.getBlockState(pos); 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); TileMasterRitualStone mrs = (TileMasterRitualStone) world.getTileEntity(pos);
if (mrs == null || mrs.getCurrentRitual() == null) if (mrs == null || mrs.getCurrentRitual() == null)
return null; return null;
else else
return new ResourceLocation("bloodmagic", "ritual_" + mrs.getCurrentRitual().getName()); 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())); ImperfectRitual imperfectRitual = ImperfectRitualRegistry.getRitualForBlock(BlockStack.getStackFromPos(world, pos.up()));
if (imperfectRitual != null) if (imperfectRitual != null)

View file

@ -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<E extends Enum<E> & IStringSerializable> extends Block {
private final E[] types;
private final PropertyEnum<E> property;
private final BlockStateContainer realStateContainer;
public BlockEnum(Material material, Class<E> 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<E> 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<ItemStack> subBlocks) {
for (E type : types)
subBlocks.add(new ItemStack(item, 1, type.ordinal()));
}
protected BlockStateContainer createStateContainer() {
return new BlockStateContainer.Builder(this).add(property).build();
}
}

View file

@ -1,24 +1,14 @@
package WayofTime.bloodmagic.block.base; package WayofTime.bloodmagic.block.base;
import WayofTime.bloodmagic.block.property.UnlistedPropertyInteger;
import lombok.Getter; import lombok.Getter;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyInteger; import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs; 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.Item;
import net.minecraft.item.ItemStack; 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.Side;
import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.fml.relauncher.SideOnly;
@ -28,28 +18,22 @@ import java.util.List;
* Creates a block that has multiple meta-based states. * Creates a block that has multiple meta-based states.
* *
* These states will be numbered 0 through {@code maxMeta}. * These states will be numbered 0 through {@code maxMeta}.
*
* For {@link net.minecraft.tileentity.TileEntity}'s, use
* {@link BlockIntegerContainer}.
*/ */
@Getter @Getter
public class BlockInteger extends Block public class BlockInteger extends Block
{ {
private final int maxMeta; private final int maxMeta;
private final PropertyInteger metaProp; private final PropertyInteger property;
private final IUnlistedProperty unlistedMetaProp; private final BlockStateContainer realStateContainer;
private final BlockStateContainer realBlockState;
public BlockInteger(Material material, int maxMeta, String propName) public BlockInteger(Material material, int maxMeta, String propName)
{ {
super(material); super(material);
this.maxMeta = maxMeta; this.maxMeta = maxMeta;
this.property = PropertyInteger.create(propName, 0, maxMeta);
this.metaProp = PropertyInteger.create(propName, 0, maxMeta); this.realStateContainer = createStateContainer();
this.unlistedMetaProp = new UnlistedPropertyInteger(maxMeta, propName); setDefaultState(getBlockState().getBaseState());
this.realBlockState = createRealBlockState();
setupStates();
} }
public BlockInteger(Material material, int maxMeta) public BlockInteger(Material material, int maxMeta)
@ -58,66 +42,38 @@ public class BlockInteger extends Block
} }
@Override @Override
public IBlockState getStateFromMeta(int meta) protected final BlockStateContainer createBlockState() {
{ return new BlockStateContainer.Builder(this).build(); // Blank to avoid crashes
return getDefaultState().withProperty(metaProp, meta);
} }
@Override @Override
public int getMetaFromState(IBlockState state) public final BlockStateContainer getBlockState() {
{ return realStateContainer;
return (Integer) state.getValue(metaProp);
} }
@Override @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); 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) @SideOnly(Side.CLIENT)
public void getSubBlocks(Item item, CreativeTabs creativeTabs, List<ItemStack> list) @Override
{ public void getSubBlocks(Item item, CreativeTabs tab, List<ItemStack> subBlocks) {
for (int i = 0; i < maxMeta + 1; i++) for (int i = 0; i < maxMeta; i++)
list.add(new ItemStack(this, 1, i)); subBlocks.add(new ItemStack(item, 1, i));
} }
private void setupStates() protected BlockStateContainer createStateContainer() {
{ return new BlockStateContainer.Builder(this).add(property).build();
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 });
} }
} }

View file

@ -1,28 +1,19 @@
package WayofTime.bloodmagic.block.base; package WayofTime.bloodmagic.block.base;
import java.util.Arrays;
import java.util.List; import java.util.List;
import lombok.Getter; import lombok.Getter;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs; import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos; import WayofTime.bloodmagic.block.property.PropertyString;
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.Side;
import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.fml.relauncher.SideOnly;
import WayofTime.bloodmagic.block.property.PropertyString; import org.apache.commons.lang3.ArrayUtils;
import WayofTime.bloodmagic.block.property.UnlistedPropertyString;
/** /**
* Creates a block that has multiple meta-based states. * 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 * 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 * way, each value is {@code toLowerCase()}'ed, so the blockstate JSON needs all
* values to be lowercase. * values to be lowercase.
*
* For {@link net.minecraft.tileentity.TileEntity}'s, use
* {@link BlockStringContainer}.
*/ */
@Getter @Getter
public class BlockString extends Block public class BlockString extends Block
{ {
private final int maxMeta; private final int maxMeta;
private final List<String> values; private final String[] types;
protected final PropertyString stringProp; private final PropertyString property;
protected final IUnlistedProperty unlistedStringProp; private final BlockStateContainer realStateContainer;
private final BlockStateContainer realBlockState;
public BlockString(Material material, String[] values, String propName) public BlockString(Material material, String[] values, String propName)
{ {
super(material); super(material);
this.maxMeta = values.length - 1; this.maxMeta = values.length;
this.values = Arrays.asList(values); this.types = values;
this.stringProp = PropertyString.create(propName, values); this.property = PropertyString.create(propName, values);
this.unlistedStringProp = new UnlistedPropertyString(values, propName); this.realStateContainer = createStateContainer();
this.realBlockState = createRealBlockState(); setDefaultState(getBlockState().getBaseState());
setupStates();
} }
public BlockString(Material material, String[] values) public BlockString(Material material, String[] values)
@ -62,60 +48,38 @@ public class BlockString extends Block
} }
@Override @Override
public IBlockState getStateFromMeta(int meta) protected final BlockStateContainer createBlockState() {
{ return new BlockStateContainer.Builder(this).build(); // Blank to avoid crashes
return getBlockState().getBaseState().withProperty(stringProp, values.get(meta));
} }
@Override @Override
public int getMetaFromState(IBlockState state) public final BlockStateContainer getBlockState() {
{ return realStateContainer;
return values.indexOf(String.valueOf(state.getValue(stringProp)));
} }
@Override @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); 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) @SideOnly(Side.CLIENT)
public void getSubBlocks(Item item, CreativeTabs creativeTabs, List<ItemStack> list) @Override
{ public void getSubBlocks(Item item, CreativeTabs tab, List<ItemStack> subBlocks) {
for (int i = 0; i < maxMeta + 1; i++) for (int i = 0; i < maxMeta; i++)
list.add(new ItemStack(this, 1, i)); subBlocks.add(new ItemStack(item, 1, i));
} }
protected void setupStates() protected BlockStateContainer createStateContainer() {
{ return new BlockStateContainer.Builder(this).add(property).build();
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 });
} }
} }

View file

@ -13,8 +13,7 @@ import net.minecraft.util.Rotation;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.property.ExtendedBlockState; import org.apache.commons.lang3.ArrayUtils;
import net.minecraftforge.common.property.IUnlistedProperty;
public class BlockStringPillar extends BlockString public class BlockStringPillar extends BlockString
{ {
@ -28,10 +27,15 @@ public class BlockStringPillar extends BlockString
this(material, values, "type"); this(material, values, "type");
} }
@Override
protected BlockStateContainer createStateContainer() {
return new BlockStateContainer.Builder(this).add(getProperty(), BlockRotatedPillar.AXIS).build();
}
@Override @Override
public IBlockState getStateFromMeta(int meta) 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) switch (meta / 5)
{ {
@ -62,7 +66,7 @@ public class BlockStringPillar extends BlockString
@Override @Override
public int getMetaFromState(IBlockState state) 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)) 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 @Override
protected ItemStack createStackedBlock(IBlockState state) protected ItemStack createStackedBlock(IBlockState state)
{ {
@ -141,6 +133,6 @@ public class BlockStringPillar extends BlockString
@Override @Override
public int damageDropped(IBlockState state) public int damageDropped(IBlockState state)
{ {
return this.getValues().indexOf(state.getValue(this.getStringProp())); return super.getMetaFromState(state);
} }
} }

View file

@ -1,13 +1,11 @@
package WayofTime.bloodmagic.block.base; package WayofTime.bloodmagic.block.base;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyDirection; import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.Mirror; 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.BlockPos;
import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.property.ExtendedBlockState; import org.apache.commons.lang3.ArrayUtils;
import net.minecraftforge.common.property.IUnlistedProperty;
public class BlockStringPillarCap extends BlockString public class BlockStringPillarCap extends BlockString
{ {
@ -32,17 +29,22 @@ public class BlockStringPillarCap extends BlockString
this(material, values, "type"); this(material, values, "type");
} }
@Override
protected BlockStateContainer createStateContainer() {
return new BlockStateContainer.Builder(this).add(getProperty(), FACING).build();
}
@Override @Override
public IBlockState getStateFromMeta(int meta) 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)); return state.withProperty(FACING, EnumFacing.getFront(meta / 2));
} }
@Override @Override
public int getMetaFromState(IBlockState state) 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(); return i + 2 * state.getValue(FACING).getIndex();
} }
@ -64,18 +66,6 @@ public class BlockStringPillarCap extends BlockString
return state.withRotation(mirrorIn.toRotation(state.getValue(FACING))); 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 @Override
protected ItemStack createStackedBlock(IBlockState state) protected ItemStack createStackedBlock(IBlockState state)
{ {
@ -91,6 +81,6 @@ public class BlockStringPillarCap extends BlockString
@Override @Override
public int damageDropped(IBlockState state) public int damageDropped(IBlockState state)
{ {
return this.getValues().indexOf(state.getValue(this.getStringProp())); return super.getMetaFromState(state);
} }
} }

View file

@ -10,7 +10,6 @@ import net.minecraft.block.BlockStairs;
import net.minecraft.block.BlockStairs.EnumHalf; import net.minecraft.block.BlockStairs.EnumHalf;
import net.minecraft.block.BlockStairs.EnumShape; import net.minecraft.block.BlockStairs.EnumShape;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyDirection; import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState; 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.util.math.Vec3d;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.property.ExtendedBlockState;
import net.minecraftforge.common.property.IUnlistedProperty;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import org.apache.commons.lang3.ArrayUtils;
public class BlockStringStairs extends BlockString public class BlockStringStairs extends BlockString
{ {
@ -65,6 +63,11 @@ public class BlockStringStairs extends BlockString
this(material, values, "type"); this(material, values, "type");
} }
@Override
protected BlockStateContainer createStateContainer() {
return new BlockStateContainer.Builder(this).add(getProperty(), FACING, BlockStairs.HALF, BlockStairs.SHAPE).build();
}
@Override @Override
public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entityIn) public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entityIn)
{ {
@ -206,7 +209,7 @@ public class BlockStringStairs extends BlockString
public IBlockState getStateFromMeta(int meta) public IBlockState getStateFromMeta(int meta)
{ {
IBlockState state = getBlockState().getBaseState().withProperty(BlockStairs.HALF, (meta & 8) > 0 ? BlockStairs.EnumHalf.TOP : BlockStairs.EnumHalf.BOTTOM); 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; return state;
} }
@ -222,7 +225,7 @@ public class BlockStringStairs extends BlockString
} }
i = i | 5 - state.getValue(FACING).getIndex(); 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 @Override
@ -340,12 +343,6 @@ public class BlockStringStairs extends BlockString
return super.withMirror(state, mirrorIn); 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 @Override
protected ItemStack createStackedBlock(IBlockState state) protected ItemStack createStackedBlock(IBlockState state)
{ {
@ -355,7 +352,7 @@ public class BlockStringStairs extends BlockString
@Override @Override
public int damageDropped(IBlockState state) public int damageDropped(IBlockState state)
{ {
return this.getValues().indexOf(state.getValue(this.getStringProp())); return super.getMetaFromState(state);
} }
@Override @Override

View file

@ -42,6 +42,11 @@ public class BlockStringWall extends BlockString
this(material, values, "type"); this(material, values, "type");
} }
@Override
protected BlockStateContainer createStateContainer() {
return new BlockStateContainer.Builder(this).add(getProperty(), UP, NORTH, EAST, SOUTH, WEST).build();
}
@Override @Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) 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); 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 @Override
protected ItemStack createStackedBlock(IBlockState state) protected ItemStack createStackedBlock(IBlockState state)
{ {
@ -145,6 +138,6 @@ public class BlockStringWall extends BlockString
@Override @Override
public int damageDropped(IBlockState state) public int damageDropped(IBlockState state)
{ {
return this.getValues().indexOf(state.getValue(this.getStringProp())); return super.getMetaFromState(state);
} }
} }

View file

@ -18,10 +18,7 @@ public class PropertyString extends PropertyHelper<String>
protected PropertyString(String name, String[] values) protected PropertyString(String name, String[] values)
{ {
super(name, String.class); super(name, String.class);
allowedValues = ImmutableSet.copyOf(values);
HashSet<String> hashSet = Sets.newHashSet();
hashSet.addAll(Arrays.asList(values));
allowedValues = ImmutableSet.copyOf(hashSet);
} }
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)

View file

@ -65,7 +65,7 @@ public class ItemInscriptionTool extends ItemBindableBase implements IVariantPro
stack = NBTHelper.checkNBT(stack); stack = NBTHelper.checkNBT(stack);
int uses = stack.getTagCompound().getInteger(Constants.NBT.USES); 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) if (!player.capabilities.isCreativeMode)
{ {
stack.getTagCompound().setInteger(Constants.NBT.USES, --uses); stack.getTagCompound().setInteger(Constants.NBT.USES, --uses);

View file

@ -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<E extends Enum<E> & IStringSerializable> extends ItemBlock {
public ItemBlockEnum(BlockEnum<E> block) {
super(block);
if (block.getTypes().length > 1)
setHasSubtypes(true);
}
@SuppressWarnings("unchecked")
@Override
public BlockEnum<E> getBlock() {
return (BlockEnum<E>) 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;
}
}

View file

@ -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;
}
}

View file

@ -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;
}
}