Changed most of the BlockString blocks to a BlockEnum in order to solve a loading issue with schematics.
This commit is contained in:
parent
3e0f3f5aa1
commit
5cb5ec4264
59 changed files with 727 additions and 843 deletions
|
@ -16,13 +16,14 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
|||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
public class BlockEnum<E extends Enum<E> & IStringSerializable> extends Block {
|
||||
|
||||
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) {
|
||||
public BlockEnum(Material material, Class<E> enumClass, String propName)
|
||||
{
|
||||
super(material);
|
||||
|
||||
this.types = enumClass.getEnumConstants();
|
||||
|
@ -31,43 +32,51 @@ public class BlockEnum<E extends Enum<E> & IStringSerializable> extends Block {
|
|||
setDefaultState(getBlockState().getBaseState());
|
||||
}
|
||||
|
||||
public BlockEnum(Material material, Class<E> enumClass) {
|
||||
public BlockEnum(Material material, Class<E> enumClass)
|
||||
{
|
||||
this(material, enumClass, "type");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final BlockStateContainer createBlockState() {
|
||||
protected final BlockStateContainer createBlockState()
|
||||
{
|
||||
return new BlockStateContainer.Builder(this).build(); // Blank to avoid crashes
|
||||
}
|
||||
|
||||
@Override
|
||||
public final BlockStateContainer getBlockState() {
|
||||
public final BlockStateContainer getBlockState()
|
||||
{
|
||||
return realStateContainer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getStateFromMeta(int meta) {
|
||||
public IBlockState getStateFromMeta(int meta)
|
||||
{
|
||||
return getDefaultState().withProperty(property, types[meta]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(IBlockState state) {
|
||||
public int getMetaFromState(IBlockState state)
|
||||
{
|
||||
return state.getValue(property).ordinal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int damageDropped(IBlockState state) {
|
||||
public int damageDropped(IBlockState state)
|
||||
{
|
||||
return getMetaFromState(state);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void getSubBlocks(Item item, CreativeTabs tab, List<ItemStack> subBlocks) {
|
||||
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() {
|
||||
protected BlockStateContainer createStateContainer()
|
||||
{
|
||||
return new BlockStateContainer.Builder(this).add(property).build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
package WayofTime.bloodmagic.block.base;
|
||||
|
||||
import net.minecraft.block.ITileEntityProvider;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public abstract class BlockEnumContainer<E extends Enum<E> & IStringSerializable> extends BlockEnum<E> implements ITileEntityProvider
|
||||
{
|
||||
public BlockEnumContainer(Material material, Class<E> enumClass, String propName)
|
||||
{
|
||||
super(material, enumClass, propName);
|
||||
|
||||
this.isBlockContainer = true;
|
||||
}
|
||||
|
||||
public BlockEnumContainer(Material material, Class<E> enumClass)
|
||||
{
|
||||
this(material, enumClass, "type");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
|
||||
{
|
||||
super.breakBlock(worldIn, pos, state);
|
||||
worldIn.removeTileEntity(pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean eventReceived(IBlockState state, World worldIn, BlockPos pos, int eventID, int eventParam)
|
||||
{
|
||||
super.eventReceived(state, worldIn, pos, eventID, eventParam);
|
||||
TileEntity tileentity = worldIn.getTileEntity(pos);
|
||||
return tileentity != null && tileentity.receiveClientEvent(eventID, eventParam);
|
||||
}
|
||||
}
|
|
@ -9,26 +9,29 @@ import net.minecraft.entity.EntityLivingBase;
|
|||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
import net.minecraft.util.Rotation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
public class BlockStringPillar extends BlockString
|
||||
public class BlockEnumPillar<E extends Enum<E> & IStringSerializable> extends BlockEnum<E>
|
||||
{
|
||||
public BlockStringPillar(Material material, String[] values, String propName)
|
||||
public BlockEnumPillar(Material material, Class<E> enumClass, String propName)
|
||||
{
|
||||
super(material, values, propName);
|
||||
super(material, enumClass, propName);
|
||||
}
|
||||
|
||||
public BlockStringPillar(Material material, String[] values)
|
||||
public BlockEnumPillar(Material material, Class<E> enumClass)
|
||||
{
|
||||
this(material, values, "type");
|
||||
this(material, enumClass, "type");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockStateContainer createStateContainer() {
|
||||
protected BlockStateContainer createStateContainer()
|
||||
{
|
||||
return new BlockStateContainer.Builder(this).add(getProperty(), BlockRotatedPillar.AXIS).build();
|
||||
}
|
||||
|
|
@ -8,29 +8,32 @@ import net.minecraft.entity.EntityLivingBase;
|
|||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
import net.minecraft.util.Mirror;
|
||||
import net.minecraft.util.Rotation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
public class BlockStringPillarCap extends BlockString
|
||||
public class BlockEnumPillarCap<E extends Enum<E> & IStringSerializable> extends BlockEnum<E>
|
||||
{
|
||||
public static final PropertyDirection FACING = PropertyDirection.create("facing");
|
||||
|
||||
public BlockStringPillarCap(Material material, String[] values, String propName)
|
||||
public BlockEnumPillarCap(Material material, Class<E> enumClass, String propName)
|
||||
{
|
||||
super(material, values, propName);
|
||||
super(material, enumClass, propName);
|
||||
}
|
||||
|
||||
public BlockStringPillarCap(Material material, String[] values)
|
||||
public BlockEnumPillarCap(Material material, Class<E> enumClass)
|
||||
{
|
||||
this(material, values, "type");
|
||||
this(material, enumClass, "type");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockStateContainer createStateContainer() {
|
||||
protected BlockStateContainer createStateContainer()
|
||||
{
|
||||
return new BlockStateContainer.Builder(this).add(getProperty(), FACING).build();
|
||||
}
|
||||
|
|
@ -4,7 +4,6 @@ import java.util.List;
|
|||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import WayofTime.bloodmagic.BloodMagic;
|
||||
import net.minecraft.block.BlockHorizontal;
|
||||
import net.minecraft.block.BlockStairs;
|
||||
import net.minecraft.block.BlockStairs.EnumHalf;
|
||||
|
@ -18,6 +17,7 @@ import net.minecraft.entity.EntityLivingBase;
|
|||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
import net.minecraft.util.Mirror;
|
||||
import net.minecraft.util.Rotation;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
|
@ -27,10 +27,13 @@ import net.minecraft.util.math.Vec3d;
|
|||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
public class BlockStringStairs extends BlockString
|
||||
import WayofTime.bloodmagic.BloodMagic;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
public class BlockEnumStairs<E extends Enum<E> & IStringSerializable> extends BlockEnum<E>
|
||||
{
|
||||
public static final PropertyDirection FACING = BlockHorizontal.FACING;
|
||||
|
||||
|
@ -53,18 +56,19 @@ public class BlockStringStairs extends BlockString
|
|||
protected static final AxisAlignedBB AABB_OCT_BOT_SW = new AxisAlignedBB(0.0D, 0.0D, 0.5D, 0.5D, 0.5D, 1.0D);
|
||||
protected static final AxisAlignedBB AABB_OCT_BOT_SE = new AxisAlignedBB(0.5D, 0.0D, 0.5D, 1.0D, 0.5D, 1.0D);
|
||||
|
||||
public BlockStringStairs(Material material, String[] values, String propName)
|
||||
public BlockEnumStairs(Material material, Class<E> enumClass, String propName)
|
||||
{
|
||||
super(material, values, propName);
|
||||
super(material, enumClass, propName);
|
||||
}
|
||||
|
||||
public BlockStringStairs(Material material, String[] values)
|
||||
public BlockEnumStairs(Material material, Class<E> enumClass)
|
||||
{
|
||||
this(material, values, "type");
|
||||
this(material, enumClass, "type");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockStateContainer createStateContainer() {
|
||||
protected BlockStateContainer createStateContainer()
|
||||
{
|
||||
return new BlockStateContainer.Builder(this).add(getProperty(), FACING, BlockStairs.HALF, BlockStairs.SHAPE).build();
|
||||
}
|
||||
|
||||
|
@ -282,7 +286,7 @@ public class BlockStringStairs extends BlockString
|
|||
|
||||
public static boolean isBlockStairs(IBlockState state)
|
||||
{
|
||||
return state.getBlock() instanceof BlockStairs || state.getBlock() instanceof BlockStringStairs;
|
||||
return state.getBlock() instanceof BlockStairs || state.getBlock() instanceof BlockEnumStairs;
|
||||
}
|
||||
|
||||
@Override
|
|
@ -3,23 +3,21 @@ package WayofTime.bloodmagic.block.base;
|
|||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockFenceGate;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.properties.PropertyBool;
|
||||
import net.minecraft.block.state.BlockStateContainer;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.property.ExtendedBlockState;
|
||||
import net.minecraftforge.common.property.IUnlistedProperty;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class BlockStringWall extends BlockString
|
||||
public class BlockEnumWall<E extends Enum<E> & IStringSerializable> extends BlockEnum<E>
|
||||
{
|
||||
public static final PropertyBool UP = PropertyBool.create("up");
|
||||
public static final PropertyBool NORTH = PropertyBool.create("north");
|
||||
|
@ -32,18 +30,19 @@ public class BlockStringWall extends BlockString
|
|||
AABB_BY_INDEX[15].setMaxY(1.5D) };
|
||||
|
||||
// Most of this is copied from BlockWall - if there is an issue when porting, look there first.
|
||||
public BlockStringWall(Material material, String[] values, String propName)
|
||||
public BlockEnumWall(Material material, Class<E> enumClass, String propName)
|
||||
{
|
||||
super(material, values, propName);
|
||||
super(material, enumClass, propName);
|
||||
}
|
||||
|
||||
public BlockStringWall(Material material, String[] values)
|
||||
public BlockEnumWall(Material material, Class<E> enumClass)
|
||||
{
|
||||
this(material, values, "type");
|
||||
this(material, enumClass, "type");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockStateContainer createStateContainer() {
|
||||
protected BlockStateContainer createStateContainer()
|
||||
{
|
||||
return new BlockStateContainer.Builder(this).add(getProperty(), UP, NORTH, EAST, SOUTH, WEST).build();
|
||||
}
|
||||
|
|
@ -48,38 +48,48 @@ public class BlockString extends Block
|
|||
}
|
||||
|
||||
@Override
|
||||
protected final BlockStateContainer createBlockState() {
|
||||
protected final BlockStateContainer createBlockState()
|
||||
{
|
||||
return new BlockStateContainer.Builder(this).build(); // Blank to avoid crashes
|
||||
}
|
||||
|
||||
@Override
|
||||
public final BlockStateContainer getBlockState() {
|
||||
public final BlockStateContainer getBlockState()
|
||||
{
|
||||
return realStateContainer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getStateFromMeta(int meta) {
|
||||
public IBlockState getStateFromMeta(int meta)
|
||||
{
|
||||
return getDefaultState().withProperty(property, types[meta]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(IBlockState state) {
|
||||
public int getMetaFromState(IBlockState state)
|
||||
{
|
||||
return ArrayUtils.indexOf(types, state.getValue(property));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int damageDropped(IBlockState state) {
|
||||
public int damageDropped(IBlockState state)
|
||||
{
|
||||
return getMetaFromState(state);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void getSubBlocks(Item item, CreativeTabs tab, List<ItemStack> subBlocks) {
|
||||
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 BlockStateContainer createStateContainer() {
|
||||
return new BlockStateContainer.Builder(this).add(property).build();
|
||||
protected BlockStateContainer createStateContainer()
|
||||
{
|
||||
System.out.println("");
|
||||
BlockStateContainer ctn = new BlockStateContainer.Builder(this).add(property).build();
|
||||
System.out.println("Number of states: " + ctn.getValidStates().size());
|
||||
return ctn;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue