Scrap concept of "named states", go back to looping through properties for block sub-types

This commit is contained in:
Cheeserolls 2015-04-03 22:32:02 +01:00
parent 8ca7e90be0
commit 68e56e5324
35 changed files with 430 additions and 391 deletions

View File

@ -8,16 +8,17 @@
package biomesoplenty.api.block;
import java.util.Map;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.ItemBlock;
public interface IBOPBlock {
public Map<String, IBlockState> getNamedStates();
public IBlockState getNamedState(String name);
public Class<? extends ItemBlock> getItemClass();
public int getItemRenderColor(IBlockState state, int tintIndex);
public IProperty[] getPresetProperties();
public IProperty[] getRenderProperties();
public IBlockState getDefaultState();
public String getStateName(IBlockState state);
}

View File

@ -8,9 +8,6 @@
package biomesoplenty.common.block;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
@ -38,14 +35,15 @@ public class BlockBOPDirt extends Block implements IBOPBlock
@Override
protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { COARSE, VARIANT });}
// implement IDHBlock
private Map<String, IBlockState> namedStates = new HashMap<String, IBlockState>();
public Map<String, IBlockState> getNamedStates() {return this.namedStates;}
public IBlockState getNamedState(String name) {return this.namedStates.get(name);}
public Class<? extends ItemBlock> getItemClass() {return ItemBOPBlock.class;}
public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);}
// implement IBOPBlock
public Class<? extends ItemBlock> getItemClass() { return ItemBOPBlock.class; }
public int getItemRenderColor(IBlockState state, int tintIndex) { return this.getRenderColor(state); }
public IProperty[] getPresetProperties() { return new IProperty[] {COARSE, VARIANT}; }
public IProperty[] getRenderProperties() { return new IProperty[] {COARSE, VARIANT}; }
public String getStateName(IBlockState state)
{
return (Boolean.TRUE.equals(state.getValue(COARSE)) ? "coarse_" : "") + ((BOPDirtType) state.getValue(VARIANT)).getName() + "_dirt";
}
public BlockBOPDirt() {
@ -55,17 +53,8 @@ public class BlockBOPDirt extends Block implements IBOPBlock
// set some defaults
this.setHardness(0.5F);
this.setHarvestLevel("shovel", 0);
this.setStepSound(Block.soundTypeGravel);
// define named states
this.namedStates.put("loamy_dirt", this.blockState.getBaseState().withProperty(COARSE, Boolean.valueOf(false)).withProperty(VARIANT, BOPDirtType.LOAMY) );
this.namedStates.put("sandy_dirt", this.blockState.getBaseState().withProperty(COARSE, Boolean.valueOf(false)).withProperty(VARIANT, BOPDirtType.SANDY) );
this.namedStates.put("silty_dirt", this.blockState.getBaseState().withProperty(COARSE, Boolean.valueOf(false)).withProperty(VARIANT, BOPDirtType.SILTY) );
this.namedStates.put("coarse_loamy_dirt", this.blockState.getBaseState().withProperty(COARSE, Boolean.valueOf(true)).withProperty(VARIANT, BOPDirtType.LOAMY) );
this.namedStates.put("coarse_sandy_dirt", this.blockState.getBaseState().withProperty(COARSE, Boolean.valueOf(true)).withProperty(VARIANT, BOPDirtType.SANDY) );
this.namedStates.put("coarse_silty_dirt", this.blockState.getBaseState().withProperty(COARSE, Boolean.valueOf(true)).withProperty(VARIANT, BOPDirtType.SILTY) );
this.setDefaultState(this.namedStates.get("loamy_dirt"));
this.setStepSound(Block.soundTypeGravel);
this.setDefaultState( this.blockState.getBaseState().withProperty(COARSE, Boolean.valueOf(false)).withProperty(VARIANT, BOPDirtType.LOAMY) );
}

View File

@ -8,12 +8,10 @@
package biomesoplenty.common.block;
import java.util.HashMap;
import java.util.Map;
import biomesoplenty.api.block.IBOPBlock;
import net.minecraft.block.BlockDoor;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
@ -24,13 +22,13 @@ import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockBOPDoor extends BlockDoor implements IBOPBlock
{
// implement IDHBlock
protected Map<String, IBlockState> namedStates = new HashMap<String, IBlockState>();
public Map<String, IBlockState> getNamedStates() {return this.namedStates;}
public IBlockState getNamedState(String name) {return this.namedStates.get(name);}
public Class<? extends ItemBlock> getItemClass() {return null;}
public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);}
// implement IBOPBlock
public Class<? extends ItemBlock> getItemClass() { return null; }
public int getItemRenderColor(IBlockState state, int tintIndex) { return this.getRenderColor(state); }
public IProperty[] getPresetProperties() { return new IProperty[] {}; }
public IProperty[] getRenderProperties() { return new IProperty[] {FACING, OPEN, HINGE, HALF}; }
public String getStateName(IBlockState state) {return "";}
private Item doorItem;

View File

@ -8,24 +8,23 @@
package biomesoplenty.common.block;
import java.util.HashMap;
import java.util.Map;
import biomesoplenty.api.block.IBOPBlock;
import biomesoplenty.common.item.ItemBOPBlock;
import net.minecraft.block.BlockFence;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.ItemBlock;
public class BlockBOPFence extends BlockFence implements IBOPBlock
{
// implement IDHBlock
protected Map<String, IBlockState> namedStates = new HashMap<String, IBlockState>();
public Map<String, IBlockState> getNamedStates() {return this.namedStates;}
public IBlockState getNamedState(String name) {return this.namedStates.get(name);}
public Class<? extends ItemBlock> getItemClass() {return ItemBOPBlock.class;}
public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);}
{
// implement IBOPBlock
public Class<? extends ItemBlock> getItemClass() { return ItemBOPBlock.class; }
public int getItemRenderColor(IBlockState state, int tintIndex) { return this.getRenderColor(state); }
public IProperty[] getPresetProperties() { return new IProperty[] {}; }
public IProperty[] getRenderProperties() { return new IProperty[] {NORTH, EAST, SOUTH, WEST}; }
public String getStateName(IBlockState state) {return "";}
public BlockBOPFence()

View File

@ -8,12 +8,10 @@
package biomesoplenty.common.block;
import java.util.HashMap;
import java.util.Map;
import biomesoplenty.api.block.IBOPBlock;
import biomesoplenty.common.item.ItemBOPBlock;
import net.minecraft.block.BlockFenceGate;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.ItemBlock;
@ -22,13 +20,13 @@ import net.minecraft.item.ItemBlock;
//this kind of thing going on: this.registerBlockWithStateMapper(Blocks.oak_fence_gate, (new StateMap.Builder()).addPropertiesToIgnore(new IProperty[] {BlockFenceGate.POWERED}).build());
public class BlockBOPFenceGate extends BlockFenceGate implements IBOPBlock
{
// implement IDHBlock
protected Map<String, IBlockState> namedStates = new HashMap<String, IBlockState>();
public Map<String, IBlockState> getNamedStates() {return this.namedStates;}
public IBlockState getNamedState(String name) {return this.namedStates.get(name);}
public Class<? extends ItemBlock> getItemClass() {return ItemBOPBlock.class;}
public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);}
// implement IBOPBlock
public Class<? extends ItemBlock> getItemClass() { return ItemBOPBlock.class; }
public int getItemRenderColor(IBlockState state, int tintIndex) { return this.getRenderColor(state); }
public IProperty[] getPresetProperties() { return new IProperty[] {}; }
public IProperty[] getRenderProperties() { return new IProperty[] {FACING, OPEN, IN_WALL}; }
public String getStateName(IBlockState state) {return "";}
public BlockBOPFenceGate()

View File

@ -45,20 +45,22 @@ public class BlockBOPFlower1 extends BlockDecoration {
};
public static final PropertyEnum VARIANT = PropertyEnum.create("variant", FlowerType.class);
@Override
protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { VARIANT });}
protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { VARIANT });}
// implement IBOPBlock
public IProperty[] getPresetProperties() { return new IProperty[] {VARIANT}; }
public IProperty[] getRenderProperties() { return new IProperty[] {VARIANT}; }
public String getStateName(IBlockState state)
{
return ((FlowerType) state.getValue(VARIANT)).getName();
}
public BlockBOPFlower1()
{
super();
// define named states
for(FlowerType flowerType : FlowerType.values())
{
this.namedStates.put(flowerType.getName(), this.blockState.getBaseState().withProperty(VARIANT, flowerType));
}
this.setDefaultState(this.getNamedState("clover"));
super();
this.setDefaultState( this.blockState.getBaseState().withProperty(VARIANT, FlowerType.CLOVER) );
}

View File

@ -33,20 +33,22 @@ public class BlockBOPFlower2 extends BlockDecoration {
};
public static final PropertyEnum VARIANT = PropertyEnum.create("variant", FlowerType.class);
@Override
protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { VARIANT });}
protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { VARIANT });}
// implement IBOPBlock
public IProperty[] getPresetProperties() { return new IProperty[] {VARIANT}; }
public IProperty[] getRenderProperties() { return new IProperty[] {VARIANT}; }
public String getStateName(IBlockState state)
{
return ((FlowerType) state.getValue(VARIANT)).getName();
}
public BlockBOPFlower2()
{
super();
// define named states
for(FlowerType flowerType : FlowerType.values())
{
this.namedStates.put(flowerType.getName(), this.blockState.getBaseState().withProperty(VARIANT, flowerType));
}
this.setDefaultState(this.getNamedState("lavender"));
this.setDefaultState( this.blockState.getBaseState().withProperty(VARIANT, FlowerType.LAVENDER) );
}

View File

@ -8,25 +8,23 @@
package biomesoplenty.common.block;
import java.util.HashMap;
import java.util.Map;
import biomesoplenty.api.block.IBOPBlock;
import biomesoplenty.common.item.ItemBOPBlock;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.ItemBlock;
public class BlockBOPGeneric extends Block implements IBOPBlock
{
// implement IDHBlock
protected Map<String, IBlockState> namedStates = new HashMap<String, IBlockState>();
public Map<String, IBlockState> getNamedStates() {return this.namedStates;}
public IBlockState getNamedState(String name) {return this.namedStates.get(name);}
public Class<? extends ItemBlock> getItemClass() {return ItemBOPBlock.class;}
public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);}
// implement IBOPBlock
public Class<? extends ItemBlock> getItemClass() { return ItemBOPBlock.class; }
public int getItemRenderColor(IBlockState state, int tintIndex) { return this.getRenderColor(state); }
public IProperty[] getPresetProperties() { return new IProperty[] {}; }
public IProperty[] getRenderProperties() { return new IProperty[] {}; }
public String getStateName(IBlockState state) {return "";}
public BlockBOPGeneric() {

View File

@ -8,8 +8,6 @@
package biomesoplenty.common.block;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import biomesoplenty.api.block.BOPBlocks;
@ -47,15 +45,24 @@ public class BlockBOPGrass extends BlockGrass implements IBOPBlock
public static enum BOPGrassType implements IStringSerializable {SPECTRAL_MOSS, SMOLDERING, LOAMY, SANDY, SILTY, ORIGIN, OVERGROWN_NETHERRACK; public String getName() {return this.name().toLowerCase();}};
public static final PropertyEnum VARIANT = PropertyEnum.create("variant", BOPGrassType.class);
@Override
protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { VARIANT, SNOWY });}
protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { SNOWY, VARIANT });}
// implement IDHBlock
private Map<String, IBlockState> namedStates = new HashMap<String, IBlockState>();
public Map<String, IBlockState> getNamedStates() {return this.namedStates;}
public IBlockState getNamedState(String name) {return this.namedStates.get(name);}
public Class<? extends ItemBlock> getItemClass() {return ItemBOPBlock.class;}
public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);}
// implement IBOPBlock
public Class<? extends ItemBlock> getItemClass() { return ItemBOPBlock.class; }
public int getItemRenderColor(IBlockState state, int tintIndex) { return this.getRenderColor(state); }
public IProperty[] getPresetProperties() { return new IProperty[] {VARIANT}; }
public IProperty[] getRenderProperties() { return new IProperty[] {SNOWY, VARIANT}; }
public String getStateName(IBlockState state) {
BOPGrassType grassType = (BOPGrassType)state.getValue(VARIANT);
switch (grassType)
{
case SPECTRAL_MOSS: case OVERGROWN_NETHERRACK:
return grassType.getName();
default:
return grassType.getName() + "_grass_block";
}
}
public BlockBOPGrass()
@ -66,17 +73,7 @@ public class BlockBOPGrass extends BlockGrass implements IBOPBlock
this.setHardness(0.6F);
this.setHarvestLevel("shovel", 0); // TODO: I think this just determines which tool speeds up digging - need to investigate more
this.setStepSound(Block.soundTypeGrass);
// define named states
this.namedStates.put("spectral_moss", this.blockState.getBaseState().withProperty(SNOWY, Boolean.valueOf(false)).withProperty(VARIANT, BOPGrassType.SPECTRAL_MOSS) );
this.namedStates.put("smoldering_grass_block", this.blockState.getBaseState().withProperty(SNOWY, Boolean.valueOf(false)).withProperty(VARIANT, BOPGrassType.SMOLDERING) );
this.namedStates.put("loamy_grass_block", this.blockState.getBaseState().withProperty(SNOWY, Boolean.valueOf(false)).withProperty(VARIANT, BOPGrassType.LOAMY) );
this.namedStates.put("sandy_grass_block", this.blockState.getBaseState().withProperty(SNOWY, Boolean.valueOf(false)).withProperty(VARIANT, BOPGrassType.SANDY) );
this.namedStates.put("silty_grass_block", this.blockState.getBaseState().withProperty(SNOWY, Boolean.valueOf(false)).withProperty(VARIANT, BOPGrassType.SILTY) );
this.namedStates.put("origin_grass_block", this.blockState.getBaseState().withProperty(SNOWY, Boolean.valueOf(false)).withProperty(VARIANT, BOPGrassType.ORIGIN) );
this.namedStates.put("overgrown_netherrack", this.blockState.getBaseState().withProperty(SNOWY, Boolean.valueOf(false)).withProperty(VARIANT, BOPGrassType.OVERGROWN_NETHERRACK) );
this.setDefaultState(this.namedStates.get("loamy_grass_block"));
this.setDefaultState(this.blockState.getBaseState().withProperty(SNOWY, Boolean.valueOf(false)).withProperty(VARIANT, BOPGrassType.LOAMY));
}

View File

@ -8,9 +8,7 @@
package biomesoplenty.common.block;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import biomesoplenty.api.block.IBOPBlock;
@ -37,15 +35,15 @@ public class BlockBOPLeaves extends BlockLeaves implements IBOPBlock
// add properties - note CHECK_DECAY and DECAYABLE are both inherited from BlockLeaves
@Override
protected BlockState createBlockState() {return new BlockState(this, new IProperty[] {CHECK_DECAY, DECAYABLE});}
// implement IDHBlock
private Map<String, IBlockState> namedStates = new HashMap<String, IBlockState>();
public Map<String, IBlockState> getNamedStates() {return this.namedStates;}
public IBlockState getNamedState(String name) {return this.namedStates.get(name);}
public Class<? extends ItemBlock> getItemClass() {return ItemBOPBlock.class;}
public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);}
// implement IBOPBlock
public Class<? extends ItemBlock> getItemClass() { return ItemBOPBlock.class; }
public int getItemRenderColor(IBlockState state, int tintIndex) { return this.getRenderColor(state); }
public IProperty[] getPresetProperties() { return new IProperty[] {}; }
public IProperty[] getRenderProperties() { return new IProperty[] {}; }
public String getStateName(IBlockState state) {return "";}
private ItemStack sapling;
private ItemStack fruit;
private int saplingDropChance;

View File

@ -8,9 +8,6 @@
package biomesoplenty.common.block;
import java.util.HashMap;
import java.util.Map;
import biomesoplenty.api.block.IBOPBlock;
import biomesoplenty.common.item.ItemBOPLilypad;
import net.minecraft.block.BlockLilyPad;
@ -30,26 +27,29 @@ public class BlockBOPLilypad extends BlockLilyPad implements IBOPBlock
public static final PropertyEnum VARIANT = PropertyEnum.create("variant", LilypadType.class);
@Override
protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { VARIANT });}
// implement IDHBlock
private Map<String, IBlockState> namedStates = new HashMap<String, IBlockState>();
public Map<String, IBlockState> getNamedStates() {return this.namedStates;}
public IBlockState getNamedState(String name) {return this.namedStates.get(name);}
// need to use a custom item class because of the unique way lilies are placed
public Class<? extends ItemBlock> getItemClass() {return ItemBOPLilypad.class;}
public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);}
// implement IBOPBlock
// need to use a custom item class because of the unique way lilies are placed
public Class<? extends ItemBlock> getItemClass() { return ItemBOPLilypad.class; }
public int getItemRenderColor(IBlockState state, int tintIndex) { return this.getRenderColor(state); }
public IProperty[] getPresetProperties() { return new IProperty[] {VARIANT}; }
public IProperty[] getRenderProperties() { return new IProperty[] {VARIANT}; }
public String getStateName(IBlockState state) {
LilypadType type = (LilypadType) state.getValue(VARIANT);
switch (type)
{
case DUCKWEED:
return type.getName();
default:
return "lily_"+type.getName();
}
}
public BlockBOPLilypad()
{
// define named states
this.namedStates.put("lily_medium", this.blockState.getBaseState().withProperty(VARIANT, LilypadType.MEDIUM) );
this.namedStates.put("lily_small", this.blockState.getBaseState().withProperty(VARIANT, LilypadType.SMALL) );
this.namedStates.put("lily_tiny", this.blockState.getBaseState().withProperty(VARIANT, LilypadType.TINY) );
this.namedStates.put("duckweed", this.blockState.getBaseState().withProperty(VARIANT, LilypadType.DUCKWEED) );
this.setDefaultState(this.namedStates.get("lily_medium"));
this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, LilypadType.MEDIUM));
}
@Override

View File

@ -8,9 +8,6 @@
package biomesoplenty.common.block;
import java.util.HashMap;
import java.util.Map;
import biomesoplenty.api.block.IBOPBlock;
import biomesoplenty.common.item.ItemBOPBlock;
import net.minecraft.block.BlockLog;
@ -25,13 +22,14 @@ public class BlockBOPLog extends BlockLog implements IBOPBlock
// add properties (note we inherit LOG_AXIS property from parent BlockLog)
@Override
protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { LOG_AXIS });}
// implement IDHBlock
protected Map<String, IBlockState> namedStates = new HashMap<String, IBlockState>();
public Map<String, IBlockState> getNamedStates() {return this.namedStates;}
public IBlockState getNamedState(String name) {return this.namedStates.get(name);}
public Class<? extends ItemBlock> getItemClass() {return ItemBOPBlock.class;}
public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);}
// implement IBOPBlock
public Class<? extends ItemBlock> getItemClass() { return ItemBOPBlock.class; }
public int getItemRenderColor(IBlockState state, int tintIndex) { return this.getRenderColor(state); }
public IProperty[] getPresetProperties() { return new IProperty[] {}; }
public IProperty[] getRenderProperties() { return new IProperty[] {LOG_AXIS}; }
public String getStateName(IBlockState state) {return "";}
public BlockBOPLog()

View File

@ -9,12 +9,14 @@
package biomesoplenty.common.block;
import biomesoplenty.api.block.BOPBlocks;
import biomesoplenty.common.item.ItemBOPBlock;
import net.minecraft.block.Block;
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.init.Blocks;
import net.minecraft.item.ItemBlock;
import net.minecraft.util.BlockPos;
import net.minecraft.util.IStringSerializable;
import net.minecraft.world.IBlockAccess;
@ -30,22 +32,24 @@ public class BlockBOPMushroom extends BlockDecoration
public static final PropertyEnum VARIANT = PropertyEnum.create("variant", MushroomType.class);
@Override
protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { VARIANT });}
// implement IBOPBlock
public Class<? extends ItemBlock> getItemClass() { return ItemBOPBlock.class; }
public int getItemRenderColor(IBlockState state, int tintIndex) { return this.getRenderColor(state); }
public IProperty[] getPresetProperties() { return new IProperty[] {VARIANT}; }
public IProperty[] getRenderProperties() { return new IProperty[] {VARIANT}; }
public String getStateName(IBlockState state)
{
return ((MushroomType) state.getValue(VARIANT)).getName();
}
public BlockBOPMushroom()
{
// set some defaults
this.setBlockBoundsByRadiusAndHeight(0.2F, 0.4F);
// define named states
this.namedStates.put("toadstool", this.blockState.getBaseState().withProperty(VARIANT, MushroomType.TOADSTOOL));
this.namedStates.put("portobello", this.blockState.getBaseState().withProperty(VARIANT, MushroomType.PORTOBELLO));
this.namedStates.put("blue_milk_cap", this.blockState.getBaseState().withProperty(VARIANT, MushroomType.BLUE_MILK_CAP));
this.namedStates.put("glowshroom", this.blockState.getBaseState().withProperty(VARIANT, MushroomType.GLOWSHROOM));
this.namedStates.put("flat_mushroom", this.blockState.getBaseState().withProperty(VARIANT, MushroomType.FLAT_MUSHROOM));
this.namedStates.put("shadow_shroom", this.blockState.getBaseState().withProperty(VARIANT, MushroomType.SHADOW_SHROOM));
this.setDefaultState(this.namedStates.get("toadstool"));
this.setBlockBoundsByRadiusAndHeight(0.2F, 0.4F);
this.setDefaultState( this.blockState.getBaseState().withProperty(VARIANT, MushroomType.TOADSTOOL) );
}
// map from state to meta and vice verca
@ -94,7 +98,6 @@ public class BlockBOPMushroom extends BlockDecoration
boolean onStone = (groundBlock == Blocks.stone || groundBlock == BOPBlocks.stone); // TODO: hard dirt too? the other edge cases?
boolean onEndstone = (groundBlock == Blocks.end_stone);
//System.out.println("ground block is " + BlockStateUtils.getStateInfoAsString(groundState));
if (groundBlock instanceof BlockBOPGrass)
{
switch ((BlockBOPGrass.BOPGrassType) groundState.getValue(BlockBOPGrass.VARIANT))

View File

@ -8,24 +8,22 @@
package biomesoplenty.common.block;
import java.util.HashMap;
import java.util.Map;
import biomesoplenty.api.block.IBOPBlock;
import biomesoplenty.common.item.ItemBOPBlock;
import net.minecraft.block.BlockStairs;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.ItemBlock;
public class BlockBOPStairs extends BlockStairs implements IBOPBlock
{
// implement IDHBlock
protected Map<String, IBlockState> namedStates = new HashMap<String, IBlockState>();
public Map<String, IBlockState> getNamedStates() {return this.namedStates;}
public IBlockState getNamedState(String name) {return this.namedStates.get(name);}
public Class<? extends ItemBlock> getItemClass() {return ItemBOPBlock.class;}
public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);}
// implement IBOPBlock
public Class<? extends ItemBlock> getItemClass() { return ItemBOPBlock.class; }
public int getItemRenderColor(IBlockState state, int tintIndex) { return this.getRenderColor(state); }
public IProperty[] getPresetProperties() { return new IProperty[] {}; }
public IProperty[] getRenderProperties() { return new IProperty[] {FACING, HALF, SHAPE}; }
public String getStateName(IBlockState state) {return "";}
public BlockBOPStairs(IBlockState modelState)

View File

@ -8,9 +8,6 @@
package biomesoplenty.common.block;
import java.util.HashMap;
import java.util.Map;
import biomesoplenty.api.block.IBOPBlock;
import biomesoplenty.common.item.ItemBOPBlock;
import net.minecraft.block.Block;
@ -37,13 +34,17 @@ public class BlockBOPStone extends Block implements IBOPBlock
@Override
protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { VARIANT, POLISHED });}
// implement IDHBlock
private Map<String, IBlockState> namedStates = new HashMap<String, IBlockState>();
public Map<String, IBlockState> getNamedStates() {return this.namedStates;}
public IBlockState getNamedState(String name) {return this.namedStates.get(name);}
public Class<? extends ItemBlock> getItemClass() {return ItemBOPBlock.class;}
public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);}
// implement IBOPBlock
public Class<? extends ItemBlock> getItemClass() { return ItemBOPBlock.class; }
public int getItemRenderColor(IBlockState state, int tintIndex) { return this.getRenderColor(state); }
public IProperty[] getPresetProperties() { return new IProperty[] {VARIANT, POLISHED}; }
public IProperty[] getRenderProperties() { return new IProperty[] {VARIANT, POLISHED}; }
public String getStateName(IBlockState state)
{
return (Boolean.TRUE.equals(state.getValue(POLISHED)) ? "polished_" : "") + ((StoneType) state.getValue(VARIANT)).getName();
}
public BlockBOPStone()
{
@ -51,20 +52,10 @@ public class BlockBOPStone extends Block implements IBOPBlock
// set some defaults
this.setStepSound(Block.soundTypeStone);
this.setHarvestLevel("pickaxe", 1, this.getDefaultState().withProperty(VARIANT, StoneType.LIMESTONE));
this.setHarvestLevel("pickaxe", 2, this.getDefaultState().withProperty(VARIANT, StoneType.SILTSTONE));
this.setHarvestLevel("pickaxe", 3, this.getDefaultState().withProperty(VARIANT, StoneType.SHALE));
// define named states
this.namedStates.put("limestone", this.blockState.getBaseState().withProperty(VARIANT, StoneType.LIMESTONE).withProperty(POLISHED, Boolean.valueOf(false)) );
this.namedStates.put("siltstone", this.blockState.getBaseState().withProperty(VARIANT, StoneType.SILTSTONE).withProperty(POLISHED, Boolean.valueOf(false)) );
this.namedStates.put("shale", this.blockState.getBaseState().withProperty(VARIANT, StoneType.SHALE).withProperty(POLISHED, Boolean.valueOf(false)) );
this.namedStates.put("polished_limestone", this.blockState.getBaseState().withProperty(VARIANT, StoneType.LIMESTONE).withProperty(POLISHED, Boolean.valueOf(true)) );
this.namedStates.put("polished_siltstone", this.blockState.getBaseState().withProperty(VARIANT, StoneType.SILTSTONE).withProperty(POLISHED, Boolean.valueOf(true)) );
this.namedStates.put("polished_shale", this.blockState.getBaseState().withProperty(VARIANT, StoneType.SHALE).withProperty(POLISHED, Boolean.valueOf(true)) );
this.setDefaultState(this.namedStates.get("limestone"));
this.setDefaultState( this.blockState.getBaseState().withProperty(VARIANT, StoneType.LIMESTONE).withProperty(POLISHED, Boolean.valueOf(false)) );
}

View File

@ -8,12 +8,10 @@
package biomesoplenty.common.block;
import java.util.HashMap;
import java.util.Map;
import biomesoplenty.api.block.IBOPBlock;
import biomesoplenty.common.item.ItemBOPBlock;
import net.minecraft.block.BlockVine;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.ItemBlock;
import net.minecraft.util.BlockPos;
@ -23,13 +21,14 @@ import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockBOPVine extends BlockVine implements IBOPBlock
{
// implement IDHBlock
protected Map<String, IBlockState> namedStates = new HashMap<String, IBlockState>();
public Map<String, IBlockState> getNamedStates() {return this.namedStates;}
public IBlockState getNamedState(String name) {return this.namedStates.get(name);}
public Class<? extends ItemBlock> getItemClass() {return ItemBOPBlock.class;}
public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);}
// implement IBOPBlock
public Class<? extends ItemBlock> getItemClass() { return ItemBOPBlock.class; }
public int getItemRenderColor(IBlockState state, int tintIndex) { return this.getRenderColor(state); }
public IProperty[] getPresetProperties() { return new IProperty[] {}; }
public IProperty[] getRenderProperties() { return new IProperty[] {UP, NORTH, EAST, SOUTH, WEST}; }
public String getStateName(IBlockState state) {return "";}
// if set to true, (the default), use BlockVine getBlockColor(), getRenderColor() and colorMultiplier() functions to color the texture based on biome
// if set to false, use 0xFFFFFF for all the color functions so that the texture is used as it is

View File

@ -27,7 +27,8 @@ public class BlockBamboo extends BlockDecoration
// add properties
public static final PropertyInteger AGE = PropertyInteger.create("age", 0, 15);
@Override
protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { AGE });}
protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { AGE });}
public BlockBamboo()
{
@ -96,7 +97,6 @@ public class BlockBamboo extends BlockDecoration
int age = ((Integer)state.getValue(AGE)).intValue();
int treeHeight = 1;
while (worldIn.getBlockState(pos.down(treeHeight)).getBlock() == this) {++treeHeight;}
//System.out.println("Banboo age: "+age+" tree height: "+treeHeight);
if (treeHeight < 4)
{

View File

@ -8,9 +8,6 @@
package biomesoplenty.common.block;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
@ -40,13 +37,15 @@ public class BlockBones extends Block implements IBOPBlock
@Override
protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { AXIS, VARIANT });}
// implement IDHBlock
private Map<String, IBlockState> namedStates = new HashMap<String, IBlockState>();
public Map<String, IBlockState> getNamedStates() {return this.namedStates;}
public IBlockState getNamedState(String name) {return this.namedStates.get(name);}
public Class<? extends ItemBlock> getItemClass() {return ItemBOPBlock.class;}
public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);}
// implement IBOPBlock
public Class<? extends ItemBlock> getItemClass() { return ItemBOPBlock.class; }
public int getItemRenderColor(IBlockState state, int tintIndex) { return this.getRenderColor(state); }
public IProperty[] getPresetProperties() { return new IProperty[] {VARIANT}; }
public IProperty[] getRenderProperties() { return new IProperty[] {AXIS, VARIANT}; }
public String getStateName(IBlockState state)
{
return ((BoneType) state.getValue(VARIANT)).getName() + "_bone_segment";
}
public BlockBones()
{
@ -56,14 +55,8 @@ public class BlockBones extends Block implements IBOPBlock
this.setHardness(3.0F);
this.setResistance(5.0F);
this.setStepSound(Block.soundTypeStone);
// define named states
this.namedStates.put("small_bone_segment", this.blockState.getBaseState().withProperty(AXIS, EnumFacing.Axis.Y).withProperty(VARIANT, BoneType.SMALL));
this.namedStates.put("medium_bone_segment", this.blockState.getBaseState().withProperty(AXIS, EnumFacing.Axis.Y).withProperty(VARIANT, BoneType.MEDIUM));
this.namedStates.put("large_bone_segment", this.blockState.getBaseState().withProperty(AXIS, EnumFacing.Axis.Y).withProperty(VARIANT, BoneType.LARGE));
this.setDefaultState(this.namedStates.get("large_bone_segment"));
this.setDefaultState(this.blockState.getBaseState().withProperty(AXIS, EnumFacing.Axis.Y).withProperty(VARIANT, BoneType.LARGE));
}

View File

@ -34,6 +34,22 @@ public class BlockCoral extends BlockDecoration
@Override
protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { LEVEL, VARIANT });}
// implement IBOPBlock
public IProperty[] getPresetProperties() { return new IProperty[] {VARIANT}; }
public IProperty[] getRenderProperties() { return new IProperty[] {VARIANT}; }
public String getStateName(IBlockState state)
{
CoralType type = (CoralType) state.getValue(VARIANT);
switch (type)
{
case ALGAE:
return type.getName();
default:
return type.getName()+"_coral";
}
}
public BlockCoral()
{
super(Material.water);
@ -42,15 +58,7 @@ public class BlockCoral extends BlockDecoration
this.setHardness(0.6F);
this.setStepSound(Block.soundTypeSand);
this.setBlockBoundsByRadiusAndHeight(0.4F, 0.8F);
// define named states
this.namedStates.put("pink_coral", this.blockState.getBaseState().withProperty(LEVEL, 15).withProperty(VARIANT, CoralType.PINK) );
this.namedStates.put("orange_coral", this.blockState.getBaseState().withProperty(LEVEL, 15).withProperty(VARIANT, CoralType.ORANGE) );
this.namedStates.put("blue_coral", this.blockState.getBaseState().withProperty(LEVEL, 15).withProperty(VARIANT, CoralType.BLUE) );
this.namedStates.put("glowing_coral", this.blockState.getBaseState().withProperty(LEVEL, 15).withProperty(VARIANT, CoralType.GLOWING) );
this.namedStates.put("algae", this.blockState.getBaseState().withProperty(LEVEL, 15).withProperty(VARIANT, CoralType.ALGAE) );
this.setDefaultState(this.namedStates.get("pink_coral"));
this.setDefaultState( this.blockState.getBaseState().withProperty(LEVEL, 15).withProperty(VARIANT, CoralType.PINK) );
}

View File

@ -8,8 +8,6 @@
package biomesoplenty.common.block;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import biomesoplenty.api.block.IBOPBlock;
@ -17,6 +15,7 @@ import biomesoplenty.api.item.BOPItems;
import biomesoplenty.common.item.ItemBOPBlock;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
@ -24,12 +23,12 @@ import net.minecraft.item.ItemBlock;
public class BlockCrystal extends Block implements IBOPBlock
{
// implement IDHBlock
protected Map<String, IBlockState> namedStates = new HashMap<String, IBlockState>();
public Map<String, IBlockState> getNamedStates() {return this.namedStates;}
public IBlockState getNamedState(String name) {return this.namedStates.get(name);}
public Class<? extends ItemBlock> getItemClass() {return ItemBOPBlock.class;}
public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);}
// implement IBOPBlock
public Class<? extends ItemBlock> getItemClass() { return ItemBOPBlock.class; }
public int getItemRenderColor(IBlockState state, int tintIndex) { return this.getRenderColor(state); }
public IProperty[] getPresetProperties() { return new IProperty[] {}; }
public IProperty[] getRenderProperties() { return new IProperty[] {}; }
public String getStateName(IBlockState state) {return "";}
public BlockCrystal() {

View File

@ -8,12 +8,11 @@
package biomesoplenty.common.block;
import java.util.HashMap;
import java.util.Map;
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.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemBlock;
@ -31,12 +30,12 @@ import biomesoplenty.common.item.ItemBOPBlock;
public class BlockDecoration extends Block implements IBOPBlock
{
// implement IDHBlock
protected Map<String, IBlockState> namedStates = new HashMap<String, IBlockState>();
public Map<String, IBlockState> getNamedStates() {return this.namedStates;}
public IBlockState getNamedState(String name) {return this.namedStates.get(name);}
public Class<? extends ItemBlock> getItemClass() {return ItemBOPBlock.class;}
public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);}
// implement IBOPBlock
public Class<? extends ItemBlock> getItemClass() { return ItemBOPBlock.class; }
public int getItemRenderColor(IBlockState state, int tintIndex) { return this.getRenderColor(state); }
public IProperty[] getPresetProperties() { return new IProperty[] {}; }
public IProperty[] getRenderProperties() { return new IProperty[] {}; }
public String getStateName(IBlockState state) {return "";}
// constructor

View File

@ -30,6 +30,8 @@ class BlockDoubleDecoration extends BlockDecoration {
public static enum Half implements IStringSerializable {LOWER, UPPER; public String getName() {return this.name().toLowerCase();}};
public static final PropertyEnum HALF = PropertyEnum.create("half", Half.class);
protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { HALF });}
public IProperty[] getRenderProperties() { return new IProperty[] {HALF}; }
public float radius;
public float height;

View File

@ -12,7 +12,6 @@ import java.util.List;
import java.util.Random;
import biomesoplenty.api.block.BOPBlocks;
import biomesoplenty.common.block.BlockFoliage.FoliageType;
import net.minecraft.block.Block;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
@ -40,16 +39,20 @@ public class BlockDoubleFoliage extends BlockDoubleDecoration implements ISheara
@Override
protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { HALF, VARIANT });}
// implement IBOPBlock
public IProperty[] getPresetProperties() { return new IProperty[] {VARIANT}; }
public IProperty[] getRenderProperties() { return new IProperty[] {HALF, VARIANT}; }
public String getStateName(IBlockState state)
{
return ((FoliageType) state.getValue(VARIANT)).getName();
}
public BlockDoubleFoliage()
{
super();
// define named states
for(FoliageType foliageType : FoliageType.values())
{
this.namedStates.put(foliageType.getName(), this.blockState.getBaseState().withProperty(HALF, Half.LOWER) .withProperty(VARIANT, foliageType));
}
this.setDefaultState(this.getNamedState("flax"));
this.setDefaultState( this.blockState.getBaseState().withProperty(HALF, Half.LOWER) .withProperty(VARIANT, FoliageType.FLAX) );
}
// map from state to meta and vice verca - use highest bit for Half, and lower bits for variant

View File

@ -8,13 +8,11 @@
package biomesoplenty.common.block;
import java.util.HashMap;
import java.util.Map;
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.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
@ -34,13 +32,12 @@ import biomesoplenty.common.item.ItemBOPBlock;
public class BlockFlesh extends Block implements IBOPBlock
{
// implement IDHBlock
private Map<String, IBlockState> namedStates = new HashMap<String, IBlockState>();
public Map<String, IBlockState> getNamedStates() {return this.namedStates;}
public IBlockState getNamedState(String name) {return this.namedStates.get(name);}
public Class<? extends ItemBlock> getItemClass() {return ItemBOPBlock.class;}
public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);}
// implement IBOPBlock
public Class<? extends ItemBlock> getItemClass() { return ItemBOPBlock.class; }
public int getItemRenderColor(IBlockState state, int tintIndex) { return this.getRenderColor(state); }
public IProperty[] getPresetProperties() { return new IProperty[] {}; }
public IProperty[] getRenderProperties() { return new IProperty[] {}; }
public String getStateName(IBlockState state) {return "";}
public BlockFlesh() {
super(Material.sponge);

View File

@ -52,18 +52,20 @@ public class BlockFoliage extends BlockDecoration implements IShearable
@Override
protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { VARIANT });}
// implement IBOPBlock
public IProperty[] getPresetProperties() { return new IProperty[] {VARIANT}; }
public IProperty[] getRenderProperties() { return new IProperty[] {VARIANT}; }
public String getStateName(IBlockState state)
{
return ((FoliageType) state.getValue(VARIANT)).getName();
}
public BlockFoliage()
{
super();
// define named states
for(FoliageType foliageType : FoliageType.values())
{
this.namedStates.put(foliageType.getName(), this.blockState.getBaseState().withProperty(VARIANT, foliageType));
}
this.setDefaultState(this.getNamedState("shortgrass"));
this.setDefaultState( this.blockState.getBaseState().withProperty(VARIANT, FoliageType.SHORTGRASS) );
}
// map from state to meta and vice verca

View File

@ -33,22 +33,24 @@ public class BlockFruit extends BlockDecoration
public static final PropertyEnum VARIANT = PropertyEnum.create("variant", FruitType.class);
@Override
protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { VARIANT });}
// implement IBOPBlock
public IProperty[] getPresetProperties() { return new IProperty[] {VARIANT}; }
public IProperty[] getRenderProperties() { return new IProperty[] {VARIANT}; }
public String getStateName(IBlockState state)
{
return ((FruitType) state.getValue(VARIANT)).getName() + "_block";
}
// constructor
public BlockFruit() {
// set some defaults
this.setStepSound(Block.soundTypeGrass);
this.setBlockBoundsByRadiusAndHeight(0.25F, 0.25F, true);
// define named states
this.namedStates.put("apple_block", this.blockState.getBaseState().withProperty(VARIANT, FruitType.APPLE));
this.namedStates.put("persimmon_block", this.blockState.getBaseState().withProperty(VARIANT, FruitType.PERSIMMON));
this.namedStates.put("peach_block", this.blockState.getBaseState().withProperty(VARIANT, FruitType.PEACH));
this.namedStates.put("pear_block", this.blockState.getBaseState().withProperty(VARIANT, FruitType.PEAR));
this.setDefaultState(this.namedStates.get("apple_block"));
this.setBlockBoundsByRadiusAndHeight(0.25F, 0.25F, true);
this.setDefaultState( this.blockState.getBaseState().withProperty(VARIANT, FruitType.APPLE) );
}
// map from state to meta and vice verca

View File

@ -8,9 +8,6 @@
package biomesoplenty.common.block;
import java.util.HashMap;
import java.util.Map;
import biomesoplenty.api.block.IBOPBlock;
import biomesoplenty.common.item.ItemBOPBlock;
import net.minecraft.block.Block;
@ -30,14 +27,17 @@ public class BlockGem extends Block implements IBOPBlock
public static final PropertyEnum VARIANT = PropertyEnum.create("variant", GemType.class);
@Override
protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { VARIANT });}
// implement IDHBlock
private Map<String, IBlockState> namedStates = new HashMap<String, IBlockState>();
public Map<String, IBlockState> getNamedStates() {return this.namedStates;}
public IBlockState getNamedState(String name) {return this.namedStates.get(name);}
public Class<? extends ItemBlock> getItemClass() {return ItemBOPBlock.class;}
public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);}
// implement IBOPBlock
public Class<? extends ItemBlock> getItemClass() { return ItemBOPBlock.class; }
public int getItemRenderColor(IBlockState state, int tintIndex) { return this.getRenderColor(state); }
public IProperty[] getPresetProperties() { return new IProperty[] {VARIANT}; }
public IProperty[] getRenderProperties() { return new IProperty[] {VARIANT}; }
public String getStateName(IBlockState state)
{
return ((GemType) state.getValue(VARIANT)).getName() + "_block";
}
public BlockGem()
@ -49,19 +49,7 @@ public class BlockGem extends Block implements IBOPBlock
this.setResistance(10.0F);
this.setStepSound(Block.soundTypeMetal);
this.setHarvestLevel("pickaxe", 2);
// define named states
this.namedStates.put("amethyst_block", this.blockState.getBaseState().withProperty(VARIANT, GemType.AMETHYST) );
this.namedStates.put("ruby_block", this.blockState.getBaseState().withProperty(VARIANT, GemType.RUBY) );
this.namedStates.put("peridot_block", this.blockState.getBaseState().withProperty(VARIANT, GemType.PERIDOT) );
this.namedStates.put("topaz_block", this.blockState.getBaseState().withProperty(VARIANT, GemType.TOPAZ) );
this.namedStates.put("tanzanite_block", this.blockState.getBaseState().withProperty(VARIANT, GemType.TANZANITE) );
this.namedStates.put("malachite_block", this.blockState.getBaseState().withProperty(VARIANT, GemType.MALACHITE) );
this.namedStates.put("sapphire_block", this.blockState.getBaseState().withProperty(VARIANT, GemType.SAPPHIRE) );
this.namedStates.put("amber_block", this.blockState.getBaseState().withProperty(VARIANT, GemType.AMBER) );
this.setDefaultState(this.namedStates.get("amethyst_block"));
this.setDefaultState( this.blockState.getBaseState().withProperty(VARIANT, GemType.AMETHYST) );
}
// map from state to meta and vice verca

View File

@ -10,14 +10,13 @@ package biomesoplenty.common.block;
import static biomesoplenty.common.block.BlockGem.VARIANT;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import biomesoplenty.api.block.IBOPBlock;
import biomesoplenty.api.item.BOPItems;
import biomesoplenty.common.block.BlockGem.GemType;
import biomesoplenty.common.item.ItemBOPBlock;
import biomesoplenty.common.util.block.BlockStateUtils;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
@ -32,15 +31,18 @@ public class BlockGemOre extends Block implements IBOPBlock
// add properties (note VARIANT is imported statically from the BlockGem class)
@Override
protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { VARIANT });}
// implement IDHBlock
private Map<String, IBlockState> namedStates = new HashMap<String, IBlockState>();
public Map<String, IBlockState> getNamedStates() {return this.namedStates;}
public IBlockState getNamedState(String name) {return this.namedStates.get(name);}
public Class<? extends ItemBlock> getItemClass() {return ItemBOPBlock.class;}
public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);}
// implement IBOPBlock
public Class<? extends ItemBlock> getItemClass() { return ItemBOPBlock.class; }
public int getItemRenderColor(IBlockState state, int tintIndex) { return this.getRenderColor(state); }
public IProperty[] getPresetProperties() { return new IProperty[] {VARIANT}; }
public IProperty[] getRenderProperties() { return new IProperty[] {VARIANT}; }
public String getStateName(IBlockState state)
{
return ((GemType) state.getValue(VARIANT)).getName() + "_ore";
}
public BlockGemOre()
{
@ -49,23 +51,15 @@ public class BlockGemOre extends Block implements IBOPBlock
// set some defaults
this.setHardness(3.0F);
this.setResistance(5.0F);
this.setStepSound(Block.soundTypePiston);
// define named states
this.namedStates.put("amethyst_ore", this.blockState.getBaseState().withProperty(VARIANT, GemType.AMETHYST) );
this.namedStates.put("ruby_ore", this.blockState.getBaseState().withProperty(VARIANT, GemType.RUBY) );
this.namedStates.put("peridot_ore", this.blockState.getBaseState().withProperty(VARIANT, GemType.PERIDOT) );
this.namedStates.put("topaz_ore", this.blockState.getBaseState().withProperty(VARIANT, GemType.TOPAZ) );
this.namedStates.put("tanzanite_ore", this.blockState.getBaseState().withProperty(VARIANT, GemType.TANZANITE) );
this.namedStates.put("malachite_ore", this.blockState.getBaseState().withProperty(VARIANT, GemType.MALACHITE) );
this.namedStates.put("sapphire_ore", this.blockState.getBaseState().withProperty(VARIANT, GemType.SAPPHIRE) );
this.namedStates.put("amber_ore", this.blockState.getBaseState().withProperty(VARIANT, GemType.AMBER) );
this.setDefaultState(this.namedStates.get("amethyst_ore"));
this.setStepSound(Block.soundTypePiston);
this.setDefaultState( this.blockState.getBaseState().withProperty(VARIANT, GemType.AMETHYST) );
// all variants need pickaxe:2 to harvest, except amethyst which needs pickaxe:3
for (IBlockState state : this.namedStates.values()) {this.setHarvestLevel("pickaxe", 2, state);}
this.setHarvestLevel("pickaxe", 3, this.namedStates.get("amethyst_ore"));
for (IBlockState state : BlockStateUtils.getBlockPresets(this))
{
this.setHarvestLevel("pickaxe", 2, state);
}
this.setHarvestLevel("pickaxe", 3, this.blockState.getBaseState().withProperty(VARIANT, GemType.AMETHYST));
}

View File

@ -8,8 +8,6 @@
package biomesoplenty.common.block;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import net.minecraft.block.Block;
@ -37,13 +35,16 @@ public class BlockHive extends Block implements IBOPBlock
@Override
protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { VARIANT });}
// implement IDHBlock
private Map<String, IBlockState> namedStates = new HashMap<String, IBlockState>();
public Map<String, IBlockState> getNamedStates() {return this.namedStates;}
public IBlockState getNamedState(String name) {return this.namedStates.get(name);}
public Class<? extends ItemBlock> getItemClass() {return ItemBOPBlock.class;}
public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);}
// implement IBOPBlock
public Class<? extends ItemBlock> getItemClass() { return ItemBOPBlock.class; }
public int getItemRenderColor(IBlockState state, int tintIndex) { return this.getRenderColor(state); }
public IProperty[] getPresetProperties() { return new IProperty[] {VARIANT}; }
public IProperty[] getRenderProperties() { return new IProperty[] {VARIANT}; }
public String getStateName(IBlockState state)
{
return ((HiveType) state.getValue(VARIANT)).getName() + "_block";
}
public BlockHive()
{
@ -52,15 +53,7 @@ public class BlockHive extends Block implements IBOPBlock
// set some defaults
this.setHardness(0.5F);
this.setStepSound(Block.soundTypeGrass);
// define named states
this.namedStates.put("hive_block", this.blockState.getBaseState().withProperty(VARIANT, HiveType.HIVE) );
this.namedStates.put("honeycomb_block", this.blockState.getBaseState().withProperty(VARIANT, HiveType.HONEYCOMB) );
this.namedStates.put("empty_honeycomb_block", this.blockState.getBaseState().withProperty(VARIANT, HiveType.EMPTY_HONEYCOMB) );
this.namedStates.put("filled_honeycomb_block", this.blockState.getBaseState().withProperty(VARIANT, HiveType.FILLED_HONEYCOMB) );
this.setDefaultState(this.namedStates.get("hive_block"));
this.setDefaultState( this.blockState.getBaseState().withProperty(VARIANT, HiveType.HIVE) );
}
// map from state to meta and vice verca

View File

@ -8,8 +8,6 @@
package biomesoplenty.common.block;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import net.minecraft.block.Block;
@ -40,15 +38,17 @@ public class BlockMud extends Block implements IBOPBlock
@Override
protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { VARIANT });}
// implement IDHBlock
private Map<String, IBlockState> namedStates = new HashMap<String, IBlockState>();
public Map<String, IBlockState> getNamedStates() {return this.namedStates;}
public IBlockState getNamedState(String name) {return this.namedStates.get(name);}
public Class<? extends ItemBlock> getItemClass() {return ItemBOPBlock.class;}
public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);}
// implement IBOPBlock
public Class<? extends ItemBlock> getItemClass() { return ItemBOPBlock.class; }
public int getItemRenderColor(IBlockState state, int tintIndex) { return this.getRenderColor(state); }
public IProperty[] getPresetProperties() { return new IProperty[] {VARIANT}; }
public IProperty[] getRenderProperties() { return new IProperty[] {VARIANT}; }
public String getStateName(IBlockState state)
{
return ((MudType) state.getValue(VARIANT)).getName();
}
// constructor
public BlockMud() {
super(Material.sand);
@ -56,12 +56,7 @@ public class BlockMud extends Block implements IBOPBlock
// set some defaults
this.setHardness(0.6F);
this.setStepSound(Block.soundTypeSand);
// define named states
this.namedStates.put("mud", this.blockState.getBaseState().withProperty(VARIANT, MudType.MUD) );
this.namedStates.put("quicksand", this.blockState.getBaseState().withProperty(VARIANT, MudType.QUICKSAND) );
this.setDefaultState(this.namedStates.get("mud"));
this.setDefaultState( this.blockState.getBaseState().withProperty(VARIANT, MudType.MUD) );
}

View File

@ -27,6 +27,16 @@ public class BlockStoneFormations extends BlockDecoration
public static final PropertyEnum VARIANT = PropertyEnum.create("variant", StoneFormationType.class);
@Override
protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { VARIANT });}
// implement IBOPBlock
public IProperty[] getPresetProperties() { return new IProperty[] {VARIANT}; }
public IProperty[] getRenderProperties() { return new IProperty[] {VARIANT}; }
public String getStateName(IBlockState state)
{
return ((StoneFormationType) state.getValue(VARIANT)).getName();
}
// constructor
public BlockStoneFormations() {
@ -34,13 +44,7 @@ public class BlockStoneFormations extends BlockDecoration
// set some defaults
this.setHardness(0.5F);
this.setStepSound(Block.soundTypePiston);
// define named states
this.namedStates.put("stalactite", this.blockState.getBaseState().withProperty(VARIANT, StoneFormationType.STALACTITE) );
this.namedStates.put("stalagmite", this.blockState.getBaseState().withProperty(VARIANT, StoneFormationType.STALAGMITE) );
this.setDefaultState(this.namedStates.get("stalagmite"));
this.setDefaultState( this.blockState.getBaseState().withProperty(VARIANT, StoneFormationType.STALAGMITE) );
}
// map from state to meta and vice verca

View File

@ -8,27 +8,27 @@
package biomesoplenty.common.block;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.block.BlockCrops;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import biomesoplenty.api.block.IBOPBlock;
import biomesoplenty.api.item.BOPItems;
import biomesoplenty.common.item.ItemBOPBlock;
// TODO: stop snow settling on this (floats above it)
public class BlockTurnip extends BlockCrops implements IBOPBlock
{
// implement IDHBlock
private Map<String, IBlockState> namedStates = new HashMap<String, IBlockState>();
public Map<String, IBlockState> getNamedStates() {return this.namedStates;}
public IBlockState getNamedState(String name) {return this.namedStates.get(name);}
public Class<? extends ItemBlock> getItemClass() {return null;}
public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);}
// implement IBOPBlock
public Class<? extends ItemBlock> getItemClass() { return ItemBOPBlock.class; }
public int getItemRenderColor(IBlockState state, int tintIndex) { return this.getRenderColor(state); }
public IProperty[] getPresetProperties() { return new IProperty[] {}; }
public IProperty[] getRenderProperties() { return new IProperty[] {AGE}; }
public String getStateName(IBlockState state) {return "";}
@Override
protected Item getSeed()

View File

@ -10,7 +10,7 @@ package biomesoplenty.common.init;
import static biomesoplenty.api.block.BOPBlocks.*;
import java.util.Map;
import com.google.common.collect.ImmutableSet;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
@ -57,6 +57,7 @@ import biomesoplenty.common.block.BlockStoneFormations;
import biomesoplenty.common.block.BlockTurnip;
import biomesoplenty.common.block.BlockFlesh;
import biomesoplenty.common.handler.GuiEventHandler;
import biomesoplenty.common.util.block.BlockStateUtils;
import biomesoplenty.common.util.inventory.CreativeTabBOP;
import biomesoplenty.core.BiomesOPlenty;
@ -282,21 +283,22 @@ public class ModBlocks
if (block instanceof IBOPBlock)
{
// if this block supports the IBOPBlock interface then we can use getNamedStates() and getItemClass()
// if this block supports the IBOPBlock interface then we can determine the item block class, and sub-blocks automatically
IBOPBlock bopBlock = (IBOPBlock)block;
GameRegistry.registerBlock(block, bopBlock.getItemClass(), blockName);
if (bopBlock.getNamedStates().isEmpty())
ImmutableSet<IBlockState> presets = BlockStateUtils.getBlockPresets(bopBlock);
if (presets.isEmpty())
{
// block has no named variants to register
// block has no sub-blocks to register
registerBlockVariant(block, blockName, block.getMetaFromState(block.getDefaultState()));
}
else
{
// register all the named variants
for (Map.Entry<String,IBlockState> entry : bopBlock.getNamedStates().entrySet())
// register all the sub-blocks
for (IBlockState state : presets)
{
String stateName = entry.getKey();
IBlockState state = entry.getValue();
String stateName = bopBlock.getStateName(state);
int stateMeta = block.getMetaFromState(state);
registerBlockVariant(block, stateName, stateMeta);
}

View File

@ -11,8 +11,12 @@ package biomesoplenty.common.item;
import java.util.List;
import java.util.Map;
import com.google.common.collect.ImmutableSet;
import biomesoplenty.api.block.BOPBlocks;
import biomesoplenty.api.block.IBOPBlock;
import biomesoplenty.common.block.BlockBOPGrass;
import biomesoplenty.common.util.block.BlockStateUtils;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
@ -45,14 +49,15 @@ public class ItemBOPBlock extends ItemBlock
@Override
@SideOnly(Side.CLIENT)
public void getSubItems(Item itemIn, CreativeTabs tab, List subItems)
{
if (bopBlock.getNamedStates().isEmpty())
{
ImmutableSet<IBlockState> presets = BlockStateUtils.getBlockPresets(bopBlock);
if (presets.isEmpty())
{
subItems.add(new ItemStack(this.block, 1, this.block.getMetaFromState( this.block.getDefaultState() )));
}
else
{
for (IBlockState state : this.bopBlock.getNamedStates().values())
for (IBlockState state : presets)
{
subItems.add(new ItemStack(this.block, 1, this.block.getMetaFromState(state)));
}
@ -75,17 +80,18 @@ public class ItemBOPBlock extends ItemBlock
@Override
public String getUnlocalizedName(ItemStack stack)
{
if (bopBlock.getNamedStates().isEmpty())
ImmutableSet<IBlockState> presets = BlockStateUtils.getBlockPresets(bopBlock);
if (presets.isEmpty())
{
return super.getUnlocalizedName();
}
else
{
int meta = stack.getMetadata();
for (Map.Entry<String,IBlockState> entry : bopBlock.getNamedStates().entrySet()) {
if (block.getMetaFromState(entry.getValue()) == meta)
for (IBlockState state : presets) {
if (block.getMetaFromState(state) == meta)
{
return super.getUnlocalizedName() + "." + entry.getKey();
return super.getUnlocalizedName() + "." + bopBlock.getStateName(state);
}
}
return super.getUnlocalizedName() + "." + meta;

View File

@ -11,11 +11,15 @@ package biomesoplenty.common.util.block;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.Stack;
import java.util.Map.Entry;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.IBlockState;
import biomesoplenty.api.block.BOPBlocks;
import biomesoplenty.api.block.IBOPBlock;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
@ -42,6 +46,81 @@ public class BlockStateUtils
}
public static ImmutableSet<IBlockState> getBlockPresets(IBOPBlock block)
{
return getStatesSet(block.getDefaultState(), block.getPresetProperties());
}
public static ImmutableSet<IBlockState> getBlockRenderStates(IBOPBlock block)
{
return getStatesSet(block.getDefaultState(), block.getRenderProperties());
}
public static ImmutableSet<IBlockState> getStatesSet(IBlockState baseState, IProperty... properties)
{
Stack<IProperty> propStack = new Stack<IProperty>();
List<IBlockState> states = new ArrayList<IBlockState>();
for (IProperty prop : properties) {propStack.push(prop);}
if (!propStack.isEmpty())
{
AddStatesToList(baseState, states, propStack);
}
ImmutableSet<IBlockState> ret = ImmutableSet.copyOf(states);
return ret;
}
private static void AddStatesToList(IBlockState state, List<IBlockState> list, Stack<IProperty> stack)
{
if (stack.empty())
{
list.add(state);
return;
}
else
{
IProperty prop = stack.pop();
for (Object value : prop.getAllowedValues())
{
AddStatesToList(state.withProperty(prop, (Comparable)value), list, stack);
}
stack.push(prop);
}
}
/*
public static Map<String,IBlockState> getStatesSetNamed(IBlockState baseState, IProperty... properties)
{
Stack<IProperty> propStack = new Stack<IProperty>();
Map<String,IBlockState> states = new HashMap<String, IBlockState>();
for (IProperty prop : properties) {propStack.push(prop);}
AddStatesToMap(baseState, states, propStack);
return states;
}
private static void AddStatesToMap(IBlockState state, Map<String, IBlockState> map, Stack<IProperty> stack)
{
if (stack.empty())
{
map.put(state.getBlock().getStateName(state), state);
return;
}
else
{
IProperty prop = stack.pop();
for (Object value : prop.getAllowedValues())
{
AddStatesToMap(state.withProperty(prop, (Comparable)value), map, stack);
}
stack.push(prop);
}
}
*/
public static IProperty getPropertyByName(IBlockState blockState, String propertyName)
{
for (IProperty property : (ImmutableSet<IProperty>) blockState.getProperties().keySet())
@ -52,6 +131,7 @@ public class BlockStateUtils
return null;
}
public static boolean isValidPropertyName(IBlockState blockState, String propertyName)
{
@ -199,4 +279,5 @@ public class BlockStateUtils
return validValues.get(counter);
}
}
}