block cleanup #2
This commit is contained in:
parent
54511912dd
commit
473ef16043
41 changed files with 278 additions and 757 deletions
|
@ -34,18 +34,22 @@ import common.world.AWorldServer;
|
|||
|
||||
public class BlockDoublePlant extends BlockBush implements IGrowable
|
||||
{
|
||||
public static final PropertyEnum<BlockDoublePlant.EnumPlantType> VARIANT = PropertyEnum.<BlockDoublePlant.EnumPlantType>create("variant", BlockDoublePlant.EnumPlantType.class);
|
||||
public static final PropertyEnum<BlockDoublePlant.EnumBlockHalf> HALF = PropertyEnum.<BlockDoublePlant.EnumBlockHalf>create("half", BlockDoublePlant.EnumBlockHalf.class);
|
||||
public static final PropertyEnum<Facing> FACING = BlockDirectional.FACING;
|
||||
|
||||
public BlockDoublePlant()
|
||||
private final EnumPlantType type;
|
||||
|
||||
public BlockDoublePlant(EnumPlantType type)
|
||||
{
|
||||
super(Material.BUSH);
|
||||
this.setDefaultState(this.getBaseState().withProperty(VARIANT, BlockDoublePlant.EnumPlantType.SUNFLOWER).withProperty(HALF, BlockDoublePlant.EnumBlockHalf.LOWER).withProperty(FACING, Facing.NORTH));
|
||||
this.type = type;
|
||||
this.setDefaultState(this.getBaseState().withProperty(HALF, BlockDoublePlant.EnumBlockHalf.LOWER).withProperty(FACING, Facing.NORTH));
|
||||
this.setHardness(0.0F);
|
||||
this.setStepSound(SoundType.GRASS);
|
||||
// this.setDisplay("doublePlant");
|
||||
// this.setTickRandomly();
|
||||
}
|
||||
|
||||
public EnumPlantType getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public void updateTick(AWorldServer worldIn, BlockPos pos, State state, Random rand)
|
||||
|
@ -59,8 +63,8 @@ public class BlockDoublePlant extends BlockBush implements IGrowable
|
|||
worldIn.setState(pos, Blocks.air.getState());
|
||||
pos = pos.down();
|
||||
if(!upper || worldIn.getState(pos).getBlock() == this)
|
||||
worldIn.setState(pos, state.getValue(VARIANT) == EnumPlantType.GRASS || worldIn.rand.chance(20) ? Blocks.air.getState() :
|
||||
Blocks.tallgrass.getState().withProperty(BlockTallGrass.TYPE, BlockTallGrass.EnumType.DEAD_BUSH));
|
||||
worldIn.setState(pos, this.type == EnumPlantType.GRASS || worldIn.rand.chance(20) ? Blocks.air.getState() :
|
||||
Blocks.dead_bush.getState());
|
||||
return;
|
||||
}
|
||||
super.updateTick(worldIn, pos, state, rand);
|
||||
|
@ -71,21 +75,6 @@ public class BlockDoublePlant extends BlockBush implements IGrowable
|
|||
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
|
||||
}
|
||||
|
||||
public BlockDoublePlant.EnumPlantType getVariant(IWorldAccess worldIn, BlockPos pos)
|
||||
{
|
||||
State iblockstate = worldIn.getState(pos);
|
||||
|
||||
if (iblockstate.getBlock() == this)
|
||||
{
|
||||
iblockstate = this.getActualState(iblockstate, worldIn, pos);
|
||||
return (BlockDoublePlant.EnumPlantType)iblockstate.getValue(VARIANT);
|
||||
}
|
||||
else
|
||||
{
|
||||
return BlockDoublePlant.EnumPlantType.FERN;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
|
||||
{
|
||||
return super.canPlaceBlockAt(worldIn, pos) && worldIn.isAirBlock(pos.up());
|
||||
|
@ -104,8 +93,7 @@ public class BlockDoublePlant extends BlockBush implements IGrowable
|
|||
}
|
||||
else
|
||||
{
|
||||
BlockDoublePlant.EnumPlantType blockdoubleplant$enumplanttype = (BlockDoublePlant.EnumPlantType)this.getActualState(iblockstate, worldIn, pos).getValue(VARIANT);
|
||||
return blockdoubleplant$enumplanttype == BlockDoublePlant.EnumPlantType.FERN || blockdoubleplant$enumplanttype == BlockDoublePlant.EnumPlantType.GRASS;
|
||||
return this.type == BlockDoublePlant.EnumPlantType.FERN || this.type == BlockDoublePlant.EnumPlantType.GRASS;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -160,29 +148,18 @@ public class BlockDoublePlant extends BlockBush implements IGrowable
|
|||
}
|
||||
else
|
||||
{
|
||||
BlockDoublePlant.EnumPlantType blockdoubleplant$enumplanttype = (BlockDoublePlant.EnumPlantType)state.getValue(VARIANT);
|
||||
return blockdoubleplant$enumplanttype == BlockDoublePlant.EnumPlantType.FERN ? null : (blockdoubleplant$enumplanttype == BlockDoublePlant.EnumPlantType.GRASS ? (rand.chance(8) ? Items.wheat : null) : ItemRegistry.getItemFromBlock(this));
|
||||
return this.type == BlockDoublePlant.EnumPlantType.FERN ? null : (this.type == BlockDoublePlant.EnumPlantType.GRASS ? (rand.chance(8) ? Items.wheat : null) : ItemRegistry.getItemFromBlock(this));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the metadata of the item this Block can drop. This method is called when the block gets destroyed. It
|
||||
* returns the metadata of the dropped item based on the old metadata of the block.
|
||||
*/
|
||||
public int damageDropped(State state)
|
||||
{
|
||||
return state.getValue(HALF) != BlockDoublePlant.EnumBlockHalf.UPPER && state.getValue(VARIANT) != BlockDoublePlant.EnumPlantType.GRASS ? ((BlockDoublePlant.EnumPlantType)state.getValue(VARIANT)).getMeta() : 0;
|
||||
}
|
||||
|
||||
public int colorMultiplier(IWorldAccess worldIn, BlockPos pos, int renderPass)
|
||||
{
|
||||
BlockDoublePlant.EnumPlantType blockdoubleplant$enumplanttype = this.getVariant(worldIn, pos);
|
||||
return blockdoubleplant$enumplanttype != BlockDoublePlant.EnumPlantType.GRASS && blockdoubleplant$enumplanttype != BlockDoublePlant.EnumPlantType.FERN ? 16777215 : Colorizer.getGrassColor(worldIn, pos);
|
||||
return this.type != BlockDoublePlant.EnumPlantType.GRASS && this.type != BlockDoublePlant.EnumPlantType.FERN ? 16777215 : Colorizer.getGrassColor(worldIn, pos);
|
||||
}
|
||||
|
||||
public void placeAt(World worldIn, BlockPos lowerPos, BlockDoublePlant.EnumPlantType variant, int flags)
|
||||
public void placeAt(World worldIn, BlockPos lowerPos, int flags)
|
||||
{
|
||||
worldIn.setState(lowerPos, this.getState().withProperty(HALF, BlockDoublePlant.EnumBlockHalf.LOWER).withProperty(VARIANT, variant), flags);
|
||||
worldIn.setState(lowerPos, this.getState().withProperty(HALF, BlockDoublePlant.EnumBlockHalf.LOWER), flags);
|
||||
worldIn.setState(lowerPos.up(), this.getState().withProperty(HALF, BlockDoublePlant.EnumBlockHalf.UPPER), flags);
|
||||
}
|
||||
|
||||
|
@ -211,9 +188,8 @@ public class BlockDoublePlant extends BlockBush implements IGrowable
|
|||
// if (!player.creative)
|
||||
// {
|
||||
State iblockstate = worldIn.getState(pos.down());
|
||||
BlockDoublePlant.EnumPlantType blockdoubleplant$enumplanttype = (BlockDoublePlant.EnumPlantType)iblockstate.getValue(VARIANT);
|
||||
|
||||
if (blockdoubleplant$enumplanttype != BlockDoublePlant.EnumPlantType.FERN && blockdoubleplant$enumplanttype != BlockDoublePlant.EnumPlantType.GRASS)
|
||||
if (this.type != BlockDoublePlant.EnumPlantType.FERN && this.type != BlockDoublePlant.EnumPlantType.GRASS)
|
||||
{
|
||||
worldIn.destroyBlock(pos.down(), true);
|
||||
}
|
||||
|
@ -250,47 +226,23 @@ public class BlockDoublePlant extends BlockBush implements IGrowable
|
|||
|
||||
private boolean onHarvest(World worldIn, BlockPos pos, State state, EntityNPC player)
|
||||
{
|
||||
BlockDoublePlant.EnumPlantType blockdoubleplant$enumplanttype = (BlockDoublePlant.EnumPlantType)state.getValue(VARIANT);
|
||||
|
||||
if (blockdoubleplant$enumplanttype != BlockDoublePlant.EnumPlantType.FERN && blockdoubleplant$enumplanttype != BlockDoublePlant.EnumPlantType.GRASS)
|
||||
if (this.type != BlockDoublePlant.EnumPlantType.FERN && this.type != BlockDoublePlant.EnumPlantType.GRASS)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// player.triggerAchievement(StatRegistry.mineBlockStatArray[BlockRegistry.getIdFromBlock(this)]);
|
||||
int i = (blockdoubleplant$enumplanttype == BlockDoublePlant.EnumPlantType.GRASS ? BlockTallGrass.EnumType.GRASS : BlockTallGrass.EnumType.FERN).getMeta();
|
||||
spawnAsEntity(worldIn, pos, new ItemStack(Blocks.tallgrass, 2, i));
|
||||
spawnAsEntity(worldIn, pos, new ItemStack(this.type == BlockDoublePlant.EnumPlantType.GRASS ? Blocks.tallgrass : Blocks.fern, 2));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
|
||||
*/
|
||||
public void getSubBlocks(Item itemIn, CheatTab tab, List<ItemStack> list)
|
||||
{
|
||||
for (BlockDoublePlant.EnumPlantType blockdoubleplant$enumplanttype : BlockDoublePlant.EnumPlantType.values())
|
||||
{
|
||||
list.add(new ItemStack(itemIn, 1, blockdoubleplant$enumplanttype.getMeta()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the meta to use for the Pick Block ItemStack result
|
||||
*/
|
||||
public int getDamageValue(World worldIn, BlockPos pos)
|
||||
{
|
||||
return this.getVariant(worldIn, pos).getMeta();
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this IGrowable can grow
|
||||
*/
|
||||
public boolean canGrow(World worldIn, BlockPos pos, State state, boolean isClient)
|
||||
{
|
||||
BlockDoublePlant.EnumPlantType blockdoubleplant$enumplanttype = this.getVariant(worldIn, pos);
|
||||
return blockdoubleplant$enumplanttype != BlockDoublePlant.EnumPlantType.GRASS && blockdoubleplant$enumplanttype != BlockDoublePlant.EnumPlantType.FERN;
|
||||
return this.type != BlockDoublePlant.EnumPlantType.GRASS && this.type != BlockDoublePlant.EnumPlantType.FERN;
|
||||
}
|
||||
|
||||
public boolean canUseBonemeal(World worldIn, Random rand, BlockPos pos, State state)
|
||||
|
@ -300,7 +252,7 @@ public class BlockDoublePlant extends BlockBush implements IGrowable
|
|||
|
||||
public void grow(AWorldServer worldIn, Random rand, BlockPos pos, State state)
|
||||
{
|
||||
spawnAsEntity(worldIn, pos, new ItemStack(this, 1, this.getVariant(worldIn, pos).getMeta()));
|
||||
spawnAsEntity(worldIn, pos, new ItemStack(this));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -308,26 +260,7 @@ public class BlockDoublePlant extends BlockBush implements IGrowable
|
|||
*/
|
||||
public State getStateFromMeta(int meta)
|
||||
{
|
||||
return (meta & 8) > 0 ? this.getState().withProperty(HALF, BlockDoublePlant.EnumBlockHalf.UPPER) : this.getState().withProperty(HALF, BlockDoublePlant.EnumBlockHalf.LOWER).withProperty(VARIANT, BlockDoublePlant.EnumPlantType.byMetadata(meta & 7));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the actual Block state of this Block at the given position. This applies properties not visible in the
|
||||
* metadata, such as fence connections.
|
||||
*/
|
||||
public State getActualState(State state, IWorldAccess worldIn, BlockPos pos)
|
||||
{
|
||||
if (state.getValue(HALF) == BlockDoublePlant.EnumBlockHalf.UPPER)
|
||||
{
|
||||
State iblockstate = worldIn.getState(pos.down());
|
||||
|
||||
if (iblockstate.getBlock() == this)
|
||||
{
|
||||
state = state.withProperty(VARIANT, iblockstate.getValue(VARIANT));
|
||||
}
|
||||
}
|
||||
|
||||
return state;
|
||||
return (meta & 8) > 0 ? this.getState().withProperty(HALF, BlockDoublePlant.EnumBlockHalf.UPPER) : this.getState().withProperty(HALF, BlockDoublePlant.EnumBlockHalf.LOWER);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -335,21 +268,16 @@ public class BlockDoublePlant extends BlockBush implements IGrowable
|
|||
*/
|
||||
public int getMetaFromState(State state)
|
||||
{
|
||||
return state.getValue(HALF) == BlockDoublePlant.EnumBlockHalf.UPPER ? 8 | ((Facing)state.getValue(FACING)).getHorizontalIndex() : ((BlockDoublePlant.EnumPlantType)state.getValue(VARIANT)).getMeta();
|
||||
return state.getValue(HALF) == BlockDoublePlant.EnumBlockHalf.UPPER ? 8 | ((Facing)state.getValue(FACING)).getHorizontalIndex() : 0;
|
||||
}
|
||||
|
||||
protected IProperty[] getProperties()
|
||||
{
|
||||
return new IProperty[] {HALF, VARIANT, FACING};
|
||||
return new IProperty[] {HALF, FACING};
|
||||
}
|
||||
|
||||
// public EnumOffsetType getOffsetType()
|
||||
// {
|
||||
// return EnumOffsetType.XZ;
|
||||
// }
|
||||
|
||||
public Model getModel(ModelProvider provider, String name, State state) {
|
||||
if(state.getValue(VARIANT) == EnumPlantType.SUNFLOWER && state.getValue(HALF) == EnumBlockHalf.UPPER)
|
||||
if(this.type == EnumPlantType.SUNFLOWER && state.getValue(HALF) == EnumBlockHalf.UPPER)
|
||||
return provider.getModel("sunflower_front")
|
||||
.add(0.8f, 0f, 8f, 15.2f, 8f, 8f).noShade().rotate(8, 8, 8, Axis.Y, 45, true).ns("sunflower_top")
|
||||
.uv(0, 8, 16, 16).noCull()
|
||||
|
@ -357,11 +285,11 @@ public class BlockDoublePlant extends BlockBush implements IGrowable
|
|||
.uv(0, 8, 16, 16).noCull()
|
||||
.add(9.6f, -1f, 1f, 9.6f, 15f, 15f).noShade().rotate(8, 8, 8, Axis.Z, 22.5f, true).w("sunflower_back")
|
||||
.uv(0, 0, 16, 16).noCull().e().uv(0, 0, 16, 16).noCull();
|
||||
else if(state.getValue(VARIANT) == EnumPlantType.FERN || state.getValue(VARIANT) == EnumPlantType.GRASS)
|
||||
return provider.getModel(state.getValue(VARIANT).getName() + "_" + (state.getValue(HALF) == EnumBlockHalf.UPPER
|
||||
else if(this.type == EnumPlantType.FERN || this.type == EnumPlantType.GRASS)
|
||||
return provider.getModel(this.type.getName() + "_" + (state.getValue(HALF) == EnumBlockHalf.UPPER
|
||||
? "top" : "bottom")).crossTint();
|
||||
else
|
||||
return provider.getModel(state.getValue(VARIANT).getName() + "_" + (state.getValue(HALF) == EnumBlockHalf.UPPER
|
||||
return provider.getModel(this.type.getName() + "_" + (state.getValue(HALF) == EnumBlockHalf.UPPER
|
||||
? "top" : "bottom")).cross();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue