Cleaned up our system for blockstates/variants to be a bit more simple/flexible
This commit is contained in:
parent
f6ab4fe08c
commit
a1d0b0b830
18 changed files with 365 additions and 246 deletions
|
@ -8,12 +8,16 @@
|
|||
|
||||
package biomesoplenty.api.block;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import biomesoplenty.common.util.block.BlockStateUtils;
|
||||
import biomesoplenty.common.util.inventory.CreativeTabBOP;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.properties.PropertyEnum;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
|
@ -21,48 +25,28 @@ import net.minecraft.item.Item;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public abstract class BOPBlock extends Block
|
||||
{
|
||||
private final PropertyEnum variantProperty;
|
||||
public ImmutableSet<IBlockState> presetStates;
|
||||
|
||||
protected BOPBlock(Material material, PropertyEnum variantProperty)
|
||||
protected BOPBlock(Material material)
|
||||
{
|
||||
super(material);
|
||||
|
||||
this.variantProperty = variantProperty;
|
||||
|
||||
if (variantProperty != null) this.setDefaultState(this.blockState.getBaseState().withProperty(variantProperty, (Comparable)variantProperty.getAllowedValues().toArray()[0]));
|
||||
this.presetStates = BlockStateUtils.getValidStatesForProperties(this.getDefaultState(), this.getPresetProperties());
|
||||
|
||||
this.setCreativeTab(CreativeTabBOP.instance);
|
||||
}
|
||||
|
||||
protected BOPBlock(Material material)
|
||||
{
|
||||
this(material, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getStateFromMeta(int meta)
|
||||
{
|
||||
return hasVariants() ? this.getDefaultState().withProperty(variantProperty, (Comparable)variantProperty.getAllowedValues().toArray()[meta]) : super.getStateFromMeta(meta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(IBlockState state)
|
||||
{
|
||||
return hasVariants() ? ((Enum)state.getValue(variantProperty)).ordinal() : super.getMetaFromState(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void getSubBlocks(Item item, CreativeTabs tab, List list)
|
||||
{
|
||||
if (hasVariants())
|
||||
if (this.hasPresetProperties())
|
||||
{
|
||||
for (IBOPVariant value : getVariants())
|
||||
for (IBlockState state : presetStates)
|
||||
{
|
||||
list.add(new ItemStack(item, 1, value.getDefaultMetadata()));
|
||||
list.add(new ItemStack(item, 1, this.getMetaFromState(state)));
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -70,6 +54,7 @@ public abstract class BOPBlock extends Block
|
|||
list.add(new ItemStack(item, 1, 0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int damageDropped(IBlockState state)
|
||||
|
@ -77,18 +62,20 @@ public abstract class BOPBlock extends Block
|
|||
return this.getMetaFromState(state);
|
||||
}
|
||||
|
||||
public final boolean hasVariants()
|
||||
{
|
||||
return variantProperty != null;
|
||||
}
|
||||
|
||||
public final Collection<IBOPVariant> getVariants()
|
||||
{
|
||||
return (Collection<IBOPVariant>)variantProperty.getAllowedValues();
|
||||
}
|
||||
|
||||
public final IBOPVariant getVariantFromMeta(int metadata)
|
||||
{
|
||||
return (IBOPVariant)this.getStateFromMeta(metadata).getValue(variantProperty);
|
||||
}
|
||||
public IProperty[] getPresetProperties()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean hasPresetProperties()
|
||||
{
|
||||
return getPresetProperties() != null;
|
||||
}
|
||||
|
||||
public String getStateName(IBlockState state, boolean fullName)
|
||||
{
|
||||
String unlocalizedName = state.getBlock().getUnlocalizedName();
|
||||
|
||||
return unlocalizedName.substring(unlocalizedName.indexOf(".") + 1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,9 +26,9 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
|||
|
||||
public class BOPPlant extends BOPBlock
|
||||
{
|
||||
protected BOPPlant(PropertyEnum variantProperty)
|
||||
protected BOPPlant()
|
||||
{
|
||||
super(Material.plants, variantProperty);
|
||||
super(Material.plants);
|
||||
|
||||
this.setTickRandomly(true);
|
||||
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright 2014, the Biomes O' Plenty Team
|
||||
*
|
||||
* This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License.
|
||||
*
|
||||
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
|
||||
******************************************************************************/
|
||||
|
||||
package biomesoplenty.api.block;
|
||||
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
|
||||
public interface IBOPVariant extends IStringSerializable
|
||||
{
|
||||
public String getBaseName();
|
||||
public int getDefaultMetadata();
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright 2014, the Biomes O' Plenty Team
|
||||
*
|
||||
* This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License.
|
||||
*
|
||||
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
|
||||
******************************************************************************/
|
||||
|
||||
package biomesoplenty.common.block;
|
||||
|
||||
public class BlockBOPColorizedLeaves extends BlockBOPLeavesBase
|
||||
{
|
||||
|
||||
}
|
|
@ -10,8 +10,6 @@ package biomesoplenty.common.block;
|
|||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.properties.PropertyEnum;
|
||||
import net.minecraft.block.state.BlockState;
|
||||
|
@ -19,25 +17,20 @@ import net.minecraft.block.state.IBlockState;
|
|||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemShears;
|
||||
import net.minecraft.potion.Potion;
|
||||
import net.minecraft.potion.PotionEffect;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumParticleTypes;
|
||||
import net.minecraft.util.EnumWorldBlockLayer;
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import biomesoplenty.api.block.BOPPlant;
|
||||
import biomesoplenty.api.block.IBOPVariant;
|
||||
import biomesoplenty.common.block.BlockBOPMushroom.MushroomType;
|
||||
import biomesoplenty.common.util.inventory.CreativeTabBOP;
|
||||
import biomesoplenty.common.block.BlockBOPLog.LogType;
|
||||
|
||||
public class BlockBOPFlower extends BOPPlant
|
||||
{
|
||||
|
@ -45,7 +38,7 @@ public class BlockBOPFlower extends BOPPlant
|
|||
|
||||
public BlockBOPFlower()
|
||||
{
|
||||
super(VARIANT_PROP);
|
||||
this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT_PROP, FlowerType.CLOVER));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -110,6 +103,20 @@ public class BlockBOPFlower extends BOPPlant
|
|||
((EntityLivingBase)entity).addPotionEffect(new PotionEffect(Potion.wither.id, 200));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getStateFromMeta(int meta)
|
||||
{
|
||||
return this.getDefaultState().withProperty(VARIANT_PROP, FlowerType.values()[meta]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(IBlockState state)
|
||||
{
|
||||
int meta = ((FlowerType)state.getValue(VARIANT_PROP)).ordinal();
|
||||
|
||||
return meta;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockState createBlockState()
|
||||
|
@ -117,6 +124,18 @@ public class BlockBOPFlower extends BOPPlant
|
|||
return new BlockState(this, new IProperty[] { VARIANT_PROP });
|
||||
}
|
||||
|
||||
@Override
|
||||
public IProperty[] getPresetProperties()
|
||||
{
|
||||
return new IProperty[] { VARIANT_PROP };
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStateName(IBlockState state, boolean fullName)
|
||||
{
|
||||
return ((FlowerType)state.getValue(VARIANT_PROP)).getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlockBoundsBasedOnState(IBlockAccess world, BlockPos pos)
|
||||
{
|
||||
|
@ -170,7 +189,7 @@ public class BlockBOPFlower extends BOPPlant
|
|||
|
||||
//TODO: Readd eyebulb in as a seperate block
|
||||
//TODO: Readd dandelion blowing
|
||||
public static enum FlowerType implements IBOPVariant
|
||||
public static enum FlowerType implements IStringSerializable
|
||||
{
|
||||
CLOVER,
|
||||
SWAMPFLOWER,
|
||||
|
@ -188,12 +207,6 @@ public class BlockBOPFlower extends BOPPlant
|
|||
PINK_HIBISCUS,
|
||||
LILY_OF_THE_VALLEY,
|
||||
BURNING_BLOSSOM;
|
||||
|
||||
@Override
|
||||
public String getBaseName()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
|
@ -206,11 +219,5 @@ public class BlockBOPFlower extends BOPPlant
|
|||
{
|
||||
return getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDefaultMetadata()
|
||||
{
|
||||
return this.ordinal();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
package biomesoplenty.common.block;
|
||||
|
||||
import biomesoplenty.api.block.BOPPlant;
|
||||
import biomesoplenty.api.block.IBOPVariant;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.properties.PropertyEnum;
|
||||
|
@ -17,6 +16,7 @@ import net.minecraft.block.state.BlockState;
|
|||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
|
@ -26,7 +26,7 @@ public class BlockBOPFlower2 extends BOPPlant
|
|||
|
||||
public BlockBOPFlower2()
|
||||
{
|
||||
super(VARIANT_PROP);
|
||||
this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT_PROP, FlowerType.LAVENDER));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -45,19 +45,45 @@ public class BlockBOPFlower2 extends BOPPlant
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getStateFromMeta(int meta)
|
||||
{
|
||||
return this.getDefaultState().withProperty(VARIANT_PROP, FlowerType.values()[meta]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(IBlockState state)
|
||||
{
|
||||
int meta = ((FlowerType)state.getValue(VARIANT_PROP)).ordinal();
|
||||
|
||||
return meta;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockState createBlockState()
|
||||
{
|
||||
return new BlockState(this, new IProperty[] { VARIANT_PROP });
|
||||
}
|
||||
|
||||
@Override
|
||||
public IProperty[] getPresetProperties()
|
||||
{
|
||||
return new IProperty[] { VARIANT_PROP };
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStateName(IBlockState state, boolean fullName)
|
||||
{
|
||||
return ((FlowerType)state.getValue(VARIANT_PROP)).getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlockBoundsBasedOnState(IBlockAccess world, BlockPos pos)
|
||||
{
|
||||
this.setBlockBounds(0.1F, 0.0F, 0.1F, 0.9F, 0.8F, 0.9F);
|
||||
}
|
||||
|
||||
public static enum FlowerType implements IBOPVariant
|
||||
public static enum FlowerType implements IStringSerializable
|
||||
{
|
||||
LAVENDER,
|
||||
GOLDENROD,
|
||||
|
@ -66,13 +92,6 @@ public class BlockBOPFlower2 extends BOPPlant
|
|||
ICY_IRIS,
|
||||
ROSE;
|
||||
|
||||
@Override
|
||||
public String getBaseName()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return this.name().toLowerCase();
|
||||
|
@ -83,11 +102,5 @@ public class BlockBOPFlower2 extends BOPPlant
|
|||
{
|
||||
return getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDefaultMetadata()
|
||||
{
|
||||
return this.ordinal();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright 2014, the Biomes O' Plenty Team
|
||||
*
|
||||
* This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License.
|
||||
*
|
||||
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
|
||||
******************************************************************************/
|
||||
|
||||
package biomesoplenty.common.block;
|
||||
|
||||
import biomesoplenty.api.block.BOPBlock;
|
||||
import net.minecraft.block.material.Material;
|
||||
|
||||
public abstract class BlockBOPLeavesBase extends BOPBlock
|
||||
{
|
||||
protected boolean fastGraphics;
|
||||
|
||||
protected BlockBOPLeavesBase()
|
||||
{
|
||||
super(Material.leaves);
|
||||
|
||||
this.fastGraphics = false;
|
||||
}
|
||||
|
||||
}
|
|
@ -13,8 +13,7 @@ import net.minecraft.block.properties.PropertyEnum;
|
|||
import net.minecraft.block.state.BlockState;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import biomesoplenty.api.block.IBOPVariant;
|
||||
import biomesoplenty.common.block.BlockBOPPlanks.PlankType;
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
|
||||
public class BlockBOPLog extends BlockBOPLogBase
|
||||
{
|
||||
|
@ -22,7 +21,7 @@ public class BlockBOPLog extends BlockBOPLogBase
|
|||
|
||||
public BlockBOPLog()
|
||||
{
|
||||
super(VARIANT_PROP);
|
||||
this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT_PROP, LogType.SACRED_OAK).withProperty(AXIS_PROP, EnumFacing.Axis.Y));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -53,20 +52,26 @@ public class BlockBOPLog extends BlockBOPLogBase
|
|||
{
|
||||
return new BlockState(this, new IProperty[] { AXIS_PROP, VARIANT_PROP });
|
||||
}
|
||||
|
||||
@Override
|
||||
public IProperty[] getPresetProperties()
|
||||
{
|
||||
return new IProperty[] { VARIANT_PROP };
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStateName(IBlockState state, boolean fullName)
|
||||
{
|
||||
return ((LogType)state.getValue(VARIANT_PROP)).getName() + (fullName ? "_log" : "");
|
||||
}
|
||||
|
||||
public static enum LogType implements IBOPVariant
|
||||
public static enum LogType implements IStringSerializable
|
||||
{
|
||||
SACRED_OAK,
|
||||
CHERRY,
|
||||
DARK,
|
||||
FIR,
|
||||
ETHEREAL;
|
||||
|
||||
@Override
|
||||
public String getBaseName()
|
||||
{
|
||||
return "log";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
|
@ -79,11 +84,5 @@ public class BlockBOPLog extends BlockBOPLogBase
|
|||
{
|
||||
return getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDefaultMetadata()
|
||||
{
|
||||
return this.ordinal() * 3 + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,12 +8,12 @@
|
|||
|
||||
package biomesoplenty.common.block;
|
||||
|
||||
import biomesoplenty.api.block.IBOPVariant;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.properties.PropertyEnum;
|
||||
import net.minecraft.block.state.BlockState;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
|
||||
public class BlockBOPLog2 extends BlockBOPLogBase
|
||||
{
|
||||
|
@ -21,7 +21,7 @@ public class BlockBOPLog2 extends BlockBOPLogBase
|
|||
|
||||
public BlockBOPLog2()
|
||||
{
|
||||
super(VARIANT_PROP);
|
||||
this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT_PROP, LogType.MAGIC).withProperty(AXIS_PROP, EnumFacing.Axis.Y));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -53,7 +53,19 @@ public class BlockBOPLog2 extends BlockBOPLogBase
|
|||
return new BlockState(this, new IProperty[] { AXIS_PROP, VARIANT_PROP });
|
||||
}
|
||||
|
||||
public static enum LogType implements IBOPVariant
|
||||
@Override
|
||||
public IProperty[] getPresetProperties()
|
||||
{
|
||||
return new IProperty[] { VARIANT_PROP };
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStateName(IBlockState state, boolean fullName)
|
||||
{
|
||||
return ((LogType)state.getValue(VARIANT_PROP)).getName() + (fullName ? "_log" : "");
|
||||
}
|
||||
|
||||
public static enum LogType implements IStringSerializable
|
||||
{
|
||||
MAGIC,
|
||||
MANGROVE,
|
||||
|
@ -61,12 +73,6 @@ public class BlockBOPLog2 extends BlockBOPLogBase
|
|||
REDWOOD,
|
||||
WILLOW;
|
||||
|
||||
@Override
|
||||
public String getBaseName()
|
||||
{
|
||||
return "log";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
|
@ -78,11 +84,5 @@ public class BlockBOPLog2 extends BlockBOPLogBase
|
|||
{
|
||||
return getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDefaultMetadata()
|
||||
{
|
||||
return this.ordinal() * 3 + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,12 +8,12 @@
|
|||
|
||||
package biomesoplenty.common.block;
|
||||
|
||||
import biomesoplenty.api.block.IBOPVariant;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.properties.PropertyEnum;
|
||||
import net.minecraft.block.state.BlockState;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
|
||||
public class BlockBOPLog3 extends BlockBOPLogBase
|
||||
{
|
||||
|
@ -21,7 +21,7 @@ public class BlockBOPLog3 extends BlockBOPLogBase
|
|||
|
||||
public BlockBOPLog3()
|
||||
{
|
||||
super(VARIANT_PROP);
|
||||
this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT_PROP, LogType.DEAD).withProperty(AXIS_PROP, EnumFacing.Axis.Y));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -53,7 +53,21 @@ public class BlockBOPLog3 extends BlockBOPLogBase
|
|||
return new BlockState(this, new IProperty[] { AXIS_PROP, VARIANT_PROP });
|
||||
}
|
||||
|
||||
public static enum LogType implements IBOPVariant
|
||||
@Override
|
||||
public IProperty[] getPresetProperties()
|
||||
{
|
||||
return new IProperty[] { VARIANT_PROP };
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStateName(IBlockState state, boolean fullName)
|
||||
{
|
||||
LogType type = (LogType)state.getValue(VARIANT_PROP);
|
||||
|
||||
return type.getName() + (fullName && type != LogType.GIANT_FLOWER_STEM ? "_log" : "");
|
||||
}
|
||||
|
||||
public static enum LogType implements IStringSerializable
|
||||
{
|
||||
DEAD,
|
||||
GIANT_FLOWER_STEM,
|
||||
|
@ -61,12 +75,6 @@ public class BlockBOPLog3 extends BlockBOPLogBase
|
|||
HELL_BARK,
|
||||
JACARANDA;
|
||||
|
||||
@Override
|
||||
public String getBaseName()
|
||||
{
|
||||
return this.equals(GIANT_FLOWER_STEM) ? null : "log";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
|
@ -78,11 +86,5 @@ public class BlockBOPLog3 extends BlockBOPLogBase
|
|||
{
|
||||
return getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDefaultMetadata()
|
||||
{
|
||||
return this.ordinal() * 3 + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,12 +8,13 @@
|
|||
|
||||
package biomesoplenty.common.block;
|
||||
|
||||
import biomesoplenty.api.block.IBOPVariant;
|
||||
import biomesoplenty.common.block.BlockBOPLog3.LogType;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.properties.PropertyEnum;
|
||||
import net.minecraft.block.state.BlockState;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
|
||||
public class BlockBOPLog4 extends BlockBOPLogBase
|
||||
{
|
||||
|
@ -21,7 +22,7 @@ public class BlockBOPLog4 extends BlockBOPLogBase
|
|||
|
||||
public BlockBOPLog4()
|
||||
{
|
||||
super(VARIANT_PROP);
|
||||
this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT_PROP, LogType.MAHOGANY).withProperty(AXIS_PROP, EnumFacing.Axis.Y));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -53,16 +54,22 @@ public class BlockBOPLog4 extends BlockBOPLogBase
|
|||
return new BlockState(this, new IProperty[] { AXIS_PROP, VARIANT_PROP });
|
||||
}
|
||||
|
||||
public static enum LogType implements IBOPVariant
|
||||
@Override
|
||||
public IProperty[] getPresetProperties()
|
||||
{
|
||||
return new IProperty[] { VARIANT_PROP };
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStateName(IBlockState state, boolean fullName)
|
||||
{
|
||||
return ((LogType)state.getValue(VARIANT_PROP)).getName() + (fullName ? "_log" : "");
|
||||
}
|
||||
|
||||
public static enum LogType implements IStringSerializable
|
||||
{
|
||||
MAHOGANY;
|
||||
|
||||
@Override
|
||||
public String getBaseName()
|
||||
{
|
||||
return "log";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
|
@ -74,11 +81,5 @@ public class BlockBOPLog4 extends BlockBOPLogBase
|
|||
{
|
||||
return getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDefaultMetadata()
|
||||
{
|
||||
return this.ordinal() * 3 + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,11 +23,9 @@ public abstract class BlockBOPLogBase extends BOPBlock
|
|||
{
|
||||
public static final PropertyEnum AXIS_PROP = PropertyEnum.create("axis", EnumFacing.Axis.class);
|
||||
|
||||
protected BlockBOPLogBase(PropertyEnum variantProperty)
|
||||
protected BlockBOPLogBase()
|
||||
{
|
||||
super(Material.wood, variantProperty);
|
||||
|
||||
this.setDefaultState(this.getDefaultState().withProperty(AXIS_PROP, EnumFacing.Axis.Y));
|
||||
super(Material.wood);
|
||||
|
||||
this.setHarvestLevel("axe", 0);
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
package biomesoplenty.common.block;
|
||||
|
||||
import biomesoplenty.api.block.BOPPlant;
|
||||
import biomesoplenty.api.block.IBOPVariant;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.properties.PropertyEnum;
|
||||
|
@ -17,6 +16,7 @@ import net.minecraft.block.state.BlockState;
|
|||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
|
@ -26,7 +26,7 @@ public class BlockBOPMushroom extends BOPPlant
|
|||
|
||||
public BlockBOPMushroom()
|
||||
{
|
||||
super(VARIANT_PROP);
|
||||
this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT_PROP, MushroomType.TOADSTOOL));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -69,19 +69,45 @@ public class BlockBOPMushroom extends BOPPlant
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getStateFromMeta(int meta)
|
||||
{
|
||||
return this.getDefaultState().withProperty(VARIANT_PROP, MushroomType.values()[meta]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(IBlockState state)
|
||||
{
|
||||
int meta = ((MushroomType)state.getValue(VARIANT_PROP)).ordinal();
|
||||
|
||||
return meta;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockState createBlockState()
|
||||
{
|
||||
return new BlockState(this, new IProperty[] { VARIANT_PROP });
|
||||
}
|
||||
|
||||
@Override
|
||||
public IProperty[] getPresetProperties()
|
||||
{
|
||||
return new IProperty[] { VARIANT_PROP };
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStateName(IBlockState state, boolean fullName)
|
||||
{
|
||||
return ((MushroomType)state.getValue(VARIANT_PROP)).getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlockBoundsBasedOnState(IBlockAccess world, BlockPos pos)
|
||||
{
|
||||
this.setBlockBounds(0.3F, 0.0F, 0.3F, 0.7F, 0.4F, 0.7F);
|
||||
}
|
||||
|
||||
public static enum MushroomType implements IBOPVariant
|
||||
public static enum MushroomType implements IStringSerializable
|
||||
{
|
||||
TOADSTOOL,
|
||||
PORTOBELLO,
|
||||
|
@ -90,12 +116,6 @@ public class BlockBOPMushroom extends BOPPlant
|
|||
FLAT_MUSHROOM,
|
||||
SHADOW_SHROOM;
|
||||
|
||||
@Override
|
||||
public String getBaseName()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
|
@ -108,10 +128,5 @@ public class BlockBOPMushroom extends BOPPlant
|
|||
return getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDefaultMetadata()
|
||||
{
|
||||
return this.ordinal();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,31 +16,58 @@ import net.minecraft.block.state.BlockState;
|
|||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
import biomesoplenty.api.block.BOPBlock;
|
||||
import biomesoplenty.api.block.IBOPVariant;
|
||||
import biomesoplenty.common.util.inventory.CreativeTabBOP;
|
||||
|
||||
//TODO: Commented methods and calls
|
||||
public class BlockBOPPlanks extends BOPBlock
|
||||
{
|
||||
public static PropertyEnum VARIANT_PROP = PropertyEnum.create("variant", PlankType.class);
|
||||
|
||||
public BlockBOPPlanks()
|
||||
{
|
||||
super(Material.wood, VARIANT_PROP);
|
||||
super(Material.wood);
|
||||
|
||||
//this.setHarvestLevel("axe", 0);
|
||||
this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT_PROP, PlankType.SACRED_OAK));
|
||||
|
||||
this.setHarvestLevel("axe", 0);
|
||||
|
||||
this.setHardness(2.0F);
|
||||
this.setStepSound(Block.soundTypeWood);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getStateFromMeta(int meta)
|
||||
{
|
||||
return this.getDefaultState().withProperty(VARIANT_PROP, PlankType.values()[meta]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(IBlockState state)
|
||||
{
|
||||
int meta = ((PlankType)state.getValue(VARIANT_PROP)).ordinal();
|
||||
|
||||
return meta;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockState createBlockState()
|
||||
{
|
||||
return new BlockState(this, new IProperty[] { VARIANT_PROP });
|
||||
}
|
||||
|
||||
@Override
|
||||
public IProperty[] getPresetProperties()
|
||||
{
|
||||
return new IProperty[] { VARIANT_PROP };
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStateName(IBlockState state, boolean fullName)
|
||||
{
|
||||
PlankType type = (PlankType)state.getValue(VARIANT_PROP);
|
||||
|
||||
return type.getName() + (fullName && type != PlankType.BAMBOO_THATCHING ? "_planks" : "");
|
||||
}
|
||||
|
||||
public static enum PlankType implements IBOPVariant
|
||||
public static enum PlankType implements IStringSerializable
|
||||
{
|
||||
SACRED_OAK,
|
||||
CHERRY,
|
||||
|
@ -57,12 +84,6 @@ public class BlockBOPPlanks extends BOPBlock
|
|||
HELL_BARK,
|
||||
JACARANDA,
|
||||
MAHOGANY;
|
||||
|
||||
@Override
|
||||
public String getBaseName()
|
||||
{
|
||||
return this.equals(BAMBOO_THATCHING) ? null : "planks";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
|
@ -75,11 +96,5 @@ public class BlockBOPPlanks extends BOPBlock
|
|||
{
|
||||
return getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDefaultMetadata()
|
||||
{
|
||||
return this.ordinal();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,8 +23,6 @@ public class BlockBamboo extends BOPPlant
|
|||
{
|
||||
public BlockBamboo()
|
||||
{
|
||||
super(null);
|
||||
|
||||
this.setHardness(0.2F);
|
||||
this.setStepSound(Block.soundTypeWood);
|
||||
|
||||
|
|
|
@ -9,12 +9,15 @@
|
|||
package biomesoplenty.common.init;
|
||||
|
||||
import static biomesoplenty.api.block.BOPBlocks.*;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.resources.model.ModelBakery;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import biomesoplenty.api.block.BOPBlock;
|
||||
import biomesoplenty.api.block.IBOPVariant;
|
||||
import biomesoplenty.common.block.BlockAsh;
|
||||
import biomesoplenty.common.block.BlockBOPFlower;
|
||||
import biomesoplenty.common.block.BlockBOPFlower2;
|
||||
|
@ -26,6 +29,7 @@ import biomesoplenty.common.block.BlockBOPMushroom;
|
|||
import biomesoplenty.common.block.BlockBOPPlanks;
|
||||
import biomesoplenty.common.block.BlockBamboo;
|
||||
import biomesoplenty.common.item.ItemBlockWithVariants;
|
||||
import biomesoplenty.common.util.block.BlockStateUtils;
|
||||
import biomesoplenty.core.BiomesOPlenty;
|
||||
|
||||
public class ModBlocks
|
||||
|
@ -48,16 +52,16 @@ public class ModBlocks
|
|||
{
|
||||
block.setUnlocalizedName(name);
|
||||
|
||||
if (block.hasVariants())
|
||||
if (block.hasPresetProperties())
|
||||
{
|
||||
GameRegistry.registerBlock(block, ItemBlockWithVariants.class, name);
|
||||
|
||||
for (IBOPVariant variant : block.getVariants())
|
||||
for (IBlockState state : block.presetStates)
|
||||
{
|
||||
String variantName = variant.getName() + (variant.getBaseName() != null ? "_" + variant.getBaseName() : "");
|
||||
String stateName = block.getStateName(state, true);
|
||||
|
||||
ModelBakery.addVariantName(Item.getItemFromBlock(block), BiomesOPlenty.MOD_ID + ":" + variantName);
|
||||
BiomesOPlenty.proxy.registerBlockForMeshing(block, variant.getDefaultMetadata(), variantName);
|
||||
ModelBakery.addVariantName(Item.getItemFromBlock(block), BiomesOPlenty.MOD_ID + ":" + stateName);
|
||||
BiomesOPlenty.proxy.registerBlockForMeshing(block, block.getMetaFromState(state), stateName);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
@ -32,12 +32,13 @@ public class ItemBlockWithVariants extends ItemBlock
|
|||
@Override
|
||||
public String getUnlocalizedName(ItemStack stack)
|
||||
{
|
||||
BOPBlock bopBlock = (BOPBlock)this.block;
|
||||
BOPBlock block = (BOPBlock)this.block;
|
||||
|
||||
if (bopBlock.hasVariants())
|
||||
if (block.hasPresetProperties())
|
||||
{
|
||||
return super.getUnlocalizedName() + "." + bopBlock.getVariantFromMeta(stack.getMetadata()).getName();
|
||||
return super.getUnlocalizedName() + "." + block.getStateName(block.getStateFromMeta(stack.getMetadata()), false);
|
||||
}
|
||||
|
||||
else return super.getUnlocalizedName();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,10 +8,18 @@
|
|||
|
||||
package biomesoplenty.common.util.block;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
|
||||
import com.google.common.collect.HashBasedTable;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
public class BlockStateUtils
|
||||
{
|
||||
|
@ -39,4 +47,131 @@ public class BlockStateUtils
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ImmutableSet<IBlockState> getValidStatesForProperties(IBlockState baseState, IProperty... properties)
|
||||
{
|
||||
if (properties == null) return null;
|
||||
|
||||
Set<IBlockState> validStates = Sets.newHashSet();
|
||||
PropertyIndexer propertyIndexer = new PropertyIndexer(properties);
|
||||
|
||||
do
|
||||
{
|
||||
IBlockState currentState = baseState;
|
||||
|
||||
for (IProperty property : properties)
|
||||
{
|
||||
IndexedProperty indexedProperty = propertyIndexer.getIndexedProperty(property);
|
||||
|
||||
currentState = currentState.withProperty(property, indexedProperty.getCurrentValue());
|
||||
}
|
||||
|
||||
validStates.add(currentState);
|
||||
}
|
||||
while (propertyIndexer.increment());
|
||||
|
||||
return ImmutableSet.copyOf(validStates);
|
||||
}
|
||||
|
||||
private static class PropertyIndexer
|
||||
{
|
||||
private HashMap<IProperty, IndexedProperty> indexedProperties = new HashMap();
|
||||
|
||||
private IProperty finalProperty;
|
||||
|
||||
private PropertyIndexer(IProperty... properties)
|
||||
{
|
||||
finalProperty = properties[properties.length - 1];
|
||||
|
||||
IndexedProperty previousIndexedProperty = null;
|
||||
|
||||
for (IProperty property : properties)
|
||||
{
|
||||
IndexedProperty indexedProperty = new IndexedProperty(property);
|
||||
|
||||
if (previousIndexedProperty != null)
|
||||
{
|
||||
indexedProperty.parent = previousIndexedProperty;
|
||||
previousIndexedProperty.child = indexedProperty;
|
||||
}
|
||||
|
||||
indexedProperties.put(property, indexedProperty);
|
||||
previousIndexedProperty = indexedProperty;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean increment()
|
||||
{
|
||||
return indexedProperties.get(finalProperty).increment();
|
||||
}
|
||||
|
||||
public IndexedProperty getIndexedProperty(IProperty property)
|
||||
{
|
||||
return indexedProperties.get(property);
|
||||
}
|
||||
}
|
||||
|
||||
private static class IndexedProperty
|
||||
{
|
||||
private ArrayList<Comparable> validValues = new ArrayList();
|
||||
|
||||
private int maxCount;
|
||||
private int counter;
|
||||
|
||||
private IndexedProperty parent;
|
||||
private IndexedProperty child;
|
||||
|
||||
private IndexedProperty(IProperty property)
|
||||
{
|
||||
this.validValues.addAll(property.getAllowedValues());
|
||||
this.maxCount = this.validValues.size() - 1;
|
||||
}
|
||||
|
||||
public boolean increment()
|
||||
{
|
||||
if (counter < maxCount) counter++;
|
||||
else
|
||||
{
|
||||
if (hasParent())
|
||||
{
|
||||
resetSelfAndChildren();
|
||||
return this.parent.increment();
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void resetSelfAndChildren()
|
||||
{
|
||||
counter = 0;
|
||||
if (this.hasChild()) this.child.resetSelfAndChildren();
|
||||
}
|
||||
|
||||
public boolean hasParent()
|
||||
{
|
||||
return parent != null;
|
||||
}
|
||||
|
||||
public boolean hasChild()
|
||||
{
|
||||
return child != null;
|
||||
}
|
||||
|
||||
public int getCounter()
|
||||
{
|
||||
return counter;
|
||||
}
|
||||
|
||||
public int getMaxCount()
|
||||
{
|
||||
return maxCount;
|
||||
}
|
||||
|
||||
public Comparable getCurrentValue()
|
||||
{
|
||||
return validValues.get(counter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue