Rewrite base blocks to be less weird
Added base ItemBlock classes for each base type (to be used later)
This commit is contained in:
parent
ea43fbce7d
commit
3e0f3f5aa1
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
73
src/main/java/WayofTime/bloodmagic/block/base/BlockEnum.java
Normal file
73
src/main/java/WayofTime/bloodmagic/block/base/BlockEnum.java
Normal 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();
|
||||
}
|
||||
}
|
|
@ -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<ItemStack> 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<ItemStack> 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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<String> 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<ItemStack> 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<ItemStack> 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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<AxisAlignedBB> 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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,10 +18,7 @@ public class PropertyString extends PropertyHelper<String>
|
|||
protected PropertyString(String name, String[] values)
|
||||
{
|
||||
super(name, String.class);
|
||||
|
||||
HashSet<String> hashSet = Sets.newHashSet();
|
||||
hashSet.addAll(Arrays.asList(values));
|
||||
allowedValues = ImmutableSet.copyOf(hashSet);
|
||||
allowedValues = ImmutableSet.copyOf(values);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue