Add snowy property to new grass variants, add coarse property to new dirt variants, improve grass spreading algorithm
This commit is contained in:
parent
0be25df63e
commit
a4e7e0fdd9
|
@ -8,14 +8,20 @@
|
|||
|
||||
package biomesoplenty.common.block;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockDirt;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.properties.PropertyBool;
|
||||
import net.minecraft.block.properties.PropertyEnum;
|
||||
import net.minecraft.block.state.BlockState;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
import biomesoplenty.api.block.BOPBlock;
|
||||
import biomesoplenty.api.block.BOPBlocks;
|
||||
|
@ -23,11 +29,12 @@ import biomesoplenty.api.block.BOPBlocks;
|
|||
public class BlockBOPDirt extends BOPBlock
|
||||
{
|
||||
|
||||
public static final PropertyBool COARSE = PropertyBool.create("coarse");
|
||||
public static final PropertyEnum VARIANT_PROP = PropertyEnum.create("variant", BOPDirtType.class);
|
||||
|
||||
public BlockBOPDirt() {
|
||||
super(Material.ground);
|
||||
this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT_PROP, BOPDirtType.LOAMY));
|
||||
this.setDefaultState(this.blockState.getBaseState().withProperty(COARSE, Boolean.valueOf(false)).withProperty(VARIANT_PROP, BOPDirtType.LOAMY));
|
||||
this.setHardness(0.5F);
|
||||
this.setHarvestLevel("shovel", 0);
|
||||
this.setStepSound(Block.soundTypeGravel);
|
||||
|
@ -36,38 +43,36 @@ public class BlockBOPDirt extends BOPBlock
|
|||
@Override
|
||||
public IBlockState getStateFromMeta(int meta)
|
||||
{
|
||||
// only one property to worry about, the variant, so just map according to integer index in BOPDirtType
|
||||
return this.getDefaultState().withProperty(VARIANT_PROP, BOPDirtType.values()[meta]);
|
||||
// both variant and coarseness saved in meta, first bit coarseness, other bits variant
|
||||
return this.getDefaultState().withProperty(COARSE, Boolean.valueOf((meta & 8) > 0)).withProperty(VARIANT_PROP, BOPDirtType.values()[Math.min(2, meta & 7)]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(IBlockState state)
|
||||
{
|
||||
// only one property to worry about, the variant, so just map according to integer index in BOPDirtType
|
||||
return ((BOPDirtType) state.getValue(VARIANT_PROP)).ordinal();
|
||||
// both variant and coarseness saved in meta, first bit coarseness, other bits variant
|
||||
return (Boolean.TRUE.equals(state.getValue(COARSE)) ? 8 : 0) | ((BOPDirtType) state.getValue(VARIANT_PROP)).ordinal();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockState createBlockState()
|
||||
{
|
||||
return new BlockState(this, new IProperty[] { VARIANT_PROP });
|
||||
return new BlockState(this, new IProperty[] { COARSE, VARIANT_PROP });
|
||||
}
|
||||
|
||||
@Override
|
||||
public IProperty[] getPresetProperties()
|
||||
{
|
||||
return new IProperty[] { VARIANT_PROP };
|
||||
return new IProperty[] { COARSE, VARIANT_PROP };
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStateName(IBlockState state, boolean fullName)
|
||||
{
|
||||
return ((BOPDirtType) state.getValue(VARIANT_PROP)).getName();
|
||||
return (Boolean.TRUE.equals(state.getValue(COARSE)) ? "coarse_" : "") + ((BOPDirtType) state.getValue(VARIANT_PROP)).getName() + "_dirt";
|
||||
}
|
||||
|
||||
|
||||
|
||||
// enum representing the variants of grass
|
||||
// enum representing the variants of dirt
|
||||
public static enum BOPDirtType implements IStringSerializable
|
||||
{
|
||||
LOAMY, SANDY, SILTY;
|
||||
|
@ -75,7 +80,7 @@ public class BlockBOPDirt extends BOPBlock
|
|||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return this.name().toLowerCase() + "_dirt";
|
||||
return this.name().toLowerCase();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -18,6 +18,7 @@ import net.minecraft.block.BlockTallGrass;
|
|||
import net.minecraft.block.IGrowable;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.properties.PropertyBool;
|
||||
import net.minecraft.block.properties.PropertyEnum;
|
||||
import net.minecraft.block.state.BlockState;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
|
@ -42,35 +43,43 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
|||
public class BlockBOPGrass extends BOPBlock implements IGrowable
|
||||
{
|
||||
public static final PropertyEnum VARIANT_PROP = PropertyEnum.create("variant", BOPGrassType.class);
|
||||
public static final PropertyBool SNOWY = PropertyBool.create("snowy");
|
||||
|
||||
public BlockBOPGrass()
|
||||
{
|
||||
super(Material.grass);
|
||||
this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT_PROP, BOPGrassType.SPECTRALMOSS));
|
||||
this.setDefaultState(this.blockState.getBaseState().withProperty(SNOWY, Boolean.valueOf(false)).withProperty(VARIANT_PROP, BOPGrassType.SPECTRALMOSS));
|
||||
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);
|
||||
this.setTickRandomly(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
|
||||
{
|
||||
Block block = worldIn.getBlockState(pos.up()).getBlock();
|
||||
return state.withProperty(SNOWY, Boolean.valueOf(block == Blocks.snow || block == Blocks.snow_layer));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getStateFromMeta(int meta)
|
||||
{
|
||||
// only one property to worry about, the variant, so just map according to integer index in BOPGrassType
|
||||
// only one property in meta to worry about, the variant, so just map according to integer index in BOPGrassType
|
||||
return this.getDefaultState().withProperty(VARIANT_PROP, BOPGrassType.values()[meta]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(IBlockState state)
|
||||
{
|
||||
// only one property to worry about, the variant, so just map according to integer index in BOPGrassType
|
||||
// only one property in meta to worry about, the variant, so just map according to integer index in BOPGrassType
|
||||
return ((BOPGrassType) state.getValue(VARIANT_PROP)).ordinal();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockState createBlockState()
|
||||
{
|
||||
return new BlockState(this, new IProperty[] { VARIANT_PROP });
|
||||
return new BlockState(this, new IProperty[] { VARIANT_PROP, SNOWY });
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -252,15 +261,16 @@ public class BlockBOPGrass extends BOPBlock implements IGrowable
|
|||
|
||||
}
|
||||
|
||||
// spread grass to suitable nearby grass blocks
|
||||
// spread grass to suitable nearby blocks
|
||||
// tries - number of times to try and spread to a random nearby block
|
||||
// xzSpread - how far can the grass spread in the x and z directions
|
||||
// downSpread - how far can the grass spread downwards
|
||||
// upSpread - how far can the grass spread upwards
|
||||
// TODO: let grass spread across different dirt types? onto vanilla dirt too (and vice verca)?
|
||||
// TODO: find a way to get vanilla grass to spread to BOP dirt types
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void spreadGrass(World world, BlockPos pos, IBlockState state, Random rand, int tries, int xzSpread, int downSpread, int upSpread)
|
||||
{
|
||||
|
||||
// the type of grass which is spreading
|
||||
BOPGrassType grassType = (BOPGrassType)state.getValue(VARIANT_PROP);
|
||||
// the type of dirt this grass grows on
|
||||
|
@ -280,24 +290,21 @@ public class BlockBOPGrass extends BOPBlock implements IGrowable
|
|||
{
|
||||
// pick a random nearby position, and get the block, block state, and block above
|
||||
BlockPos pos1 = pos.add(rand.nextInt(xzSpread * 2 + 1) - xzSpread, rand.nextInt(downSpread + upSpread + 1) - downSpread, rand.nextInt(xzSpread * 2 + 1) - xzSpread);
|
||||
IBlockState iblockstate1 = world.getBlockState(pos1);
|
||||
Block block1 = iblockstate1.getBlock();
|
||||
Block blockAbove = world.getBlockState(pos1.up()).getBlock();
|
||||
IBlockState target = world.getBlockState(pos1);
|
||||
Block blockAboveTarget = world.getBlockState(pos1.up()).getBlock();
|
||||
|
||||
// see if the randomly chosen nearby block is the right type for this grass (same block and meta as dirtBlockState)
|
||||
// TODO: is it ok to just compare the equality of the states? IE iblockstate1==dirtBlockState ?
|
||||
if (block1==grassType.getDirtBlock() && block1.getMetaFromState(iblockstate1)==grassType.getDirtBlockMeta())
|
||||
// see if this type of grass can spread to the target block
|
||||
IBlockState targetGrass = grassType.spreadsToGrass(target);
|
||||
if (targetGrass == null) {break;}
|
||||
|
||||
// if there's enough light, turn the block to the relevant grass block
|
||||
if (world.getLightFromNeighbors(pos1.up()) >= 4 && blockAboveTarget.getLightOpacity(world, pos1.up()) <= 2)
|
||||
{
|
||||
// if there's enough light and it isn't covered, turn the block to the relevant grass block
|
||||
if (world.getLightFromNeighbors(pos1.up()) >= 4 && blockAbove.getLightOpacity(world, pos1.up()) <= 2)
|
||||
{
|
||||
world.setBlockState(pos1, this.getDefaultState().withProperty(VARIANT_PROP, grassType));
|
||||
}
|
||||
}
|
||||
world.setBlockState(pos1, targetGrass);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -370,15 +377,6 @@ public class BlockBOPGrass extends BOPBlock implements IGrowable
|
|||
}
|
||||
}
|
||||
|
||||
/* TODO: don't understand the intention here.. grass turns to dirt when a plant grows???
|
||||
@Override
|
||||
public void onPlantGrow(World world, int x, int y, int z, int sourceX, int sourceY, int sourceZ)
|
||||
{
|
||||
world.setBlock(x, y, z, BOPCBlocks.newBopDirt, world.getBlockMetadata(x, y, z) * 2, 2);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getCollisionBoundingBox(World world, BlockPos pos, IBlockState state)
|
||||
{
|
||||
|
@ -451,7 +449,7 @@ public class BlockBOPGrass extends BOPBlock implements IGrowable
|
|||
}
|
||||
|
||||
// get the blockstate which corresponds to the type of dirt which this grass variant grows on
|
||||
// this is used to determine what drops when you break the grass block, and also which nearby blocks this grass can spread to
|
||||
// this is used to determine what drops when you break the grass block, and the type of dirt it reverts to when covered
|
||||
public IBlockState getDirtBlockState()
|
||||
{
|
||||
switch(this)
|
||||
|
@ -478,6 +476,55 @@ public class BlockBOPGrass extends BOPBlock implements IGrowable
|
|||
{
|
||||
return this.getDirtBlock().getMetaFromState(this.getDirtBlockState());
|
||||
}
|
||||
|
||||
// if this type of grass can spread to the target block, return the grass which it will transform into
|
||||
// otherwise return null
|
||||
// this affects the grass spreading algorithm above, BlockBOPGrass.spreadGrass()
|
||||
public IBlockState spreadsToGrass(IBlockState target) {
|
||||
|
||||
switch(this)
|
||||
{
|
||||
// spectral moss only spreads to end stone
|
||||
case SPECTRALMOSS:
|
||||
if (target.getBlock()==Blocks.end_stone)
|
||||
{
|
||||
return BOPBlocks.grass.getDefaultState().withProperty(BlockBOPGrass.VARIANT_PROP, BlockBOPGrass.BOPGrassType.SPECTRALMOSS);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// loamy/sandy/silty grasses spread to any kind of dirt
|
||||
case LOAMY: case SANDY: case SILTY:
|
||||
// vanilla dirt gets vanilla grass spread to it
|
||||
if (target.getBlock() == Blocks.dirt && target.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.DIRT)
|
||||
{
|
||||
return Blocks.grass.getDefaultState();
|
||||
}
|
||||
// BOP dirt get's the corresponding BOP grass spread to it (unless it's coarse - grass doesn't grow on coarse dirt)
|
||||
else if (target.getBlock() == BOPBlocks.dirt && Boolean.FALSE.equals(target.getValue(BlockBOPDirt.COARSE)) )
|
||||
{
|
||||
BlockBOPDirt.BOPDirtType targetDirtType = (BlockBOPDirt.BOPDirtType)target.getValue(BlockBOPDirt.VARIANT_PROP);
|
||||
switch (targetDirtType)
|
||||
{
|
||||
case LOAMY: case SANDY: case SILTY:
|
||||
return targetDirtType.getGrassBlockState();
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// smoldering grass doesn't spread at all
|
||||
case SMOLDERING: default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -66,6 +66,7 @@ public class ModBlocks
|
|||
grass = registerBlock(new BlockBOPGrass(), "grass");
|
||||
waterlily = registerBlock(new BlockBOPLilypad(), "waterlily");
|
||||
dirt = registerBlock(new BlockBOPDirt(), "dirt");
|
||||
|
||||
}
|
||||
|
||||
private static Block registerBlock(BOPBlock block, String name)
|
||||
|
@ -82,9 +83,10 @@ public class ModBlocks
|
|||
for (IBlockState state : block.presetStates)
|
||||
{
|
||||
String stateName = block.getStateName(state, true);
|
||||
int stateMeta = block.getMetaFromState(state);
|
||||
|
||||
BiomesOPlenty.proxy.addVariantName(Item.getItemFromBlock(block), BiomesOPlenty.MOD_ID + ":" + stateName);
|
||||
BiomesOPlenty.proxy.registerBlockForMeshing(block, block.getMetaFromState(state), stateName);
|
||||
BiomesOPlenty.proxy.registerBlockForMeshing(block, stateMeta, stateName);
|
||||
|
||||
GuiEventHandler.blockCount++;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
{
|
||||
"variants": {
|
||||
"variant=loamy_dirt": { "model": "biomesoplenty:loamy_dirt" },
|
||||
"variant=sandy_dirt": { "model": "biomesoplenty:sandy_dirt" },
|
||||
"variant=silty_dirt": { "model": "biomesoplenty:silty_dirt" }
|
||||
"coarse=false,variant=loamy": { "model": "biomesoplenty:loamy_dirt" },
|
||||
"coarse=false,variant=sandy": { "model": "biomesoplenty:sandy_dirt" },
|
||||
"coarse=false,variant=silty": { "model": "biomesoplenty:silty_dirt" },
|
||||
"coarse=true,variant=loamy": { "model": "biomesoplenty:coarse_loamy_dirt" },
|
||||
"coarse=true,variant=sandy": { "model": "biomesoplenty:coarse_sandy_dirt" },
|
||||
"coarse=true,variant=silty": { "model": "biomesoplenty:coarse_silty_dirt" }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
{
|
||||
"variants": {
|
||||
"variant=smoldering_grass_block": { "model": "biomesoplenty:smoldering_grass_block" },
|
||||
"variant=spectral_moss": { "model": "biomesoplenty:spectral_moss" },
|
||||
"variant=loamy_grass_block": { "model": "biomesoplenty:loamy_grass_block" },
|
||||
"variant=sandy_grass_block": { "model": "biomesoplenty:sandy_grass_block" },
|
||||
"variant=silty_grass_block": { "model": "biomesoplenty:silty_grass_block" }
|
||||
"snowy=false,variant=smoldering_grass_block": { "model": "biomesoplenty:smoldering_grass_block" },
|
||||
"snowy=true,variant=smoldering_grass_block": { "model": "biomesoplenty:smoldering_grass_block" },
|
||||
"snowy=false,variant=spectral_moss": { "model": "biomesoplenty:spectral_moss" },
|
||||
"snowy=true,variant=spectral_moss": { "model": "biomesoplenty:spectral_moss" },
|
||||
"snowy=false,variant=loamy_grass_block": { "model": "biomesoplenty:loamy_grass_block" },
|
||||
"snowy=true,variant=loamy_grass_block": { "model": "biomesoplenty:loamy_grass_block_snowed" },
|
||||
"snowy=false,variant=sandy_grass_block": { "model": "biomesoplenty:sandy_grass_block" },
|
||||
"snowy=true,variant=sandy_grass_block": { "model": "biomesoplenty:sandy_grass_block_snowed" },
|
||||
"snowy=false,variant=silty_grass_block": { "model": "biomesoplenty:silty_grass_block" },
|
||||
"snowy=true,variant=silty_grass_block": { "model": "biomesoplenty:silty_grass_block_snowed" }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -133,10 +133,12 @@ tile.waterlily.lily_medium.name=Medium Lily Pad
|
|||
tile.waterlily.lily_small.name=Small Lily Pad
|
||||
tile.waterlily.lily_tiny.name=Tiny Lily Pad
|
||||
|
||||
tile.dirt.loamy_dirt=Loamy Dirt
|
||||
tile.dirt.sandy_dirt=Sandy Dirt
|
||||
tile.dirt.silty_dirt=Silty Dirt
|
||||
|
||||
tile.dirt.loamy_dirt.name=Loamy Dirt
|
||||
tile.dirt.sandy_dirt.name=Sandy Dirt
|
||||
tile.dirt.silty_dirt.name=Silty Dirt
|
||||
tile.dirt.coarse_loamy_dirt.name=Coarse Loamy Dirt
|
||||
tile.dirt.coarse_sandy_dirt.name=Coarse Sandy Dirt
|
||||
tile.dirt.coarse_silty_dirt.name=Coarse Silty Dirt
|
||||
|
||||
item.fleshchunk.name=Chunk of Flesh
|
||||
item.mudball.name=Mud Ball
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"parent": "block/cube_all",
|
||||
"textures": {
|
||||
"all": "biomesoplenty:blocks/coarse_dirt_loamy"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"parent": "block/cube_all",
|
||||
"textures": {
|
||||
"all": "biomesoplenty:blocks/coarse_dirt_sandy"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"parent": "block/cube_all",
|
||||
"textures": {
|
||||
"all": "biomesoplenty:blocks/coarse_dirt_silty"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"parent": "block/cube_bottom_top",
|
||||
"textures": {
|
||||
"particle": "biomesoplenty:blocks/dirt_loamy",
|
||||
"bottom": "biomesoplenty:blocks/dirt_loamy",
|
||||
"top": "biomesoplenty:blocks/grass_top",
|
||||
"side": "biomesoplenty:blocks/grass_loamy_side_snowed"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"parent": "block/cube_bottom_top",
|
||||
"textures": {
|
||||
"particle": "biomesoplenty:blocks/dirt_sandy",
|
||||
"bottom": "biomesoplenty:blocks/dirt_sandy",
|
||||
"top": "biomesoplenty:blocks/grass_top",
|
||||
"side": "biomesoplenty:blocks/grass_sandy_side_snowed"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"parent": "block/cube_bottom_top",
|
||||
"textures": {
|
||||
"particle": "biomesoplenty:blocks/dirt_silty",
|
||||
"bottom": "biomesoplenty:blocks/dirt_silty",
|
||||
"top": "biomesoplenty:blocks/grass_top",
|
||||
"side": "biomesoplenty:blocks/grass_silty_side_snowed"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"parent": "biomesoplenty:block/coarse_loamy_dirt",
|
||||
"display": {
|
||||
"thirdperson": {
|
||||
"rotation": [ 10, -45, 170 ],
|
||||
"translation": [ 0, 1.5, -2.75 ],
|
||||
"scale": [ 0.375, 0.375, 0.375 ]
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"parent": "biomesoplenty:block/coarse_sandy_dirt",
|
||||
"display": {
|
||||
"thirdperson": {
|
||||
"rotation": [ 10, -45, 170 ],
|
||||
"translation": [ 0, 1.5, -2.75 ],
|
||||
"scale": [ 0.375, 0.375, 0.375 ]
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"parent": "biomesoplenty:block/coarse_silty_dirt",
|
||||
"display": {
|
||||
"thirdperson": {
|
||||
"rotation": [ 10, -45, 170 ],
|
||||
"translation": [ 0, 1.5, -2.75 ],
|
||||
"scale": [ 0.375, 0.375, 0.375 ]
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 563 B |
Binary file not shown.
After Width: | Height: | Size: 618 B |
Binary file not shown.
After Width: | Height: | Size: 602 B |
Loading…
Reference in New Issue