Intial work on BoP Farmland

This commit is contained in:
GirafiStudios 2016-02-06 23:25:26 +01:00
parent c707ddc279
commit 666a6d742b
24 changed files with 385 additions and 66 deletions

View file

@ -112,6 +112,7 @@ public class BOPBlocks
public static Block grass;
public static Block waterlily;
public static Block dirt;
public static Block farmland;
public static Block stone_formations;
public static Block hard_ice;
public static Block dried_sand;

View file

@ -1,8 +1,8 @@
/*******************************************************************************
* Copyright 2014-2016, the Biomes O' Plenty Team
*
*
* This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License.
*
*
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
******************************************************************************/
@ -34,8 +34,6 @@ import biomesoplenty.common.item.ItemBOPBlock;
public class BlockBOPDirt extends Block implements IBOPBlock, ISustainsPlantType
{
// TODO: make it ploughable into farmland
// add properties
public static enum BOPDirtType implements IStringSerializable
{
@ -55,7 +53,7 @@ public class BlockBOPDirt extends Block implements IBOPBlock, ISustainsPlantType
public static final PropertyBool COARSE = PropertyBool.create("coarse");
@Override
protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { COARSE, VARIANT });}
// implement IBOPBlock
@Override
public Class<? extends ItemBlock> getItemClass() { return ItemBOPBlock.class; }
@ -71,20 +69,20 @@ public class BlockBOPDirt extends Block implements IBOPBlock, ISustainsPlantType
return (Boolean.TRUE.equals(state.getValue(COARSE)) ? "coarse_" : "") + ((BOPDirtType) state.getValue(VARIANT)).getName() + "_dirt";
}
public BlockBOPDirt() {
super(Material.ground);
// set some defaults
this.setTickRandomly(true);
this.setHardness(0.5F);
this.setHarvestLevel("shovel", 0);
this.setStepSound(Block.soundTypeGravel);
this.setStepSound(Block.soundTypeGravel);
this.setDefaultState( this.blockState.getBaseState().withProperty(COARSE, Boolean.valueOf(false)).withProperty(VARIANT, BOPDirtType.LOAMY) );
}
@Override
public IBlockState getStateFromMeta(int meta)
{
@ -98,17 +96,17 @@ public class BlockBOPDirt extends Block implements IBOPBlock, ISustainsPlantType
// 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)).ordinal();
}
// our blocks usually drop their current state as opposed to a single 'default' state
@Override
public int damageDropped(IBlockState state)
{
return this.getMetaFromState(state);
}
@Override
public boolean canSustainPlantType(IBlockAccess world, BlockPos pos, EnumPlantType plantType)
{
{
switch (plantType)
{
// support desert, plains and cave plants
@ -127,13 +125,13 @@ public class BlockBOPDirt extends Block implements IBOPBlock, ISustainsPlantType
return false;
}
}
@Override
public boolean canSustainPlant(IBlockAccess world, BlockPos pos, EnumFacing direction, net.minecraftforge.common.IPlantable plantable)
{
return this.canSustainPlantType(world, pos, plantable.getPlantType(world, pos.offset(direction)));
}
@Override
@SideOnly(Side.CLIENT)
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {
@ -143,14 +141,14 @@ public class BlockBOPDirt extends Block implements IBOPBlock, ISustainsPlantType
pullGrassFromNeighbors(world, pos, grassState, rand, 4, 1, 3, 1);
}
}
// BOPGrass variants spread randomly to BOPDirt on the grass's updateTick
// However, vanilla grass does not. This function fixes this by 'pulling' grass from nearby vanilla grass blocks at the same rate as it would spread to vanilla dirt
public void pullGrassFromNeighbors(World world, BlockPos pos, IBlockState grassState, Random rand, int tries, int xzSpread, int downSpread, int upSpread)
{
// if there's not enough light then there's no chance of this block becoming grassy
if (world.getLightFromNeighbors(pos.up()) < 4 || world.getBlockState(pos.up()).getBlock().getLightOpacity(world, pos.up()) > 2) {return;}
int numNearbyGrassSpreadingBlocks = 0;
BlockPos pos1;
for (int dy = -downSpread; dy <= upSpread; dy++)
@ -169,7 +167,7 @@ public class BlockBOPDirt extends Block implements IBOPBlock, ISustainsPlantType
}
}
if (numNearbyGrassSpreadingBlocks == 0) {return;}
// each grass block gets 4 tries to spread grass, chance of this block being chosen each time is 1 / volume of blocks close enough
// overall chance of spread = 1 - chance of not spreading
int vol = (xzSpread * 2 + 1) * (xzSpread * 2 + 1) * (upSpread + downSpread + 1);
@ -179,8 +177,8 @@ public class BlockBOPDirt extends Block implements IBOPBlock, ISustainsPlantType
world.setBlockState(pos, grassState);
}
}
// get the blockstate which corresponds to the type of grass which grows on this dirt
public static IBlockState getGrassBlockState(IBlockState state)
{
@ -190,7 +188,7 @@ public class BlockBOPDirt extends Block implements IBOPBlock, ISustainsPlantType
return null;
}
switch ((BOPDirtType) state.getValue(VARIANT))
{
{
case LOAMY:
return BOPBlocks.grass.getDefaultState().withProperty(BlockBOPGrass.VARIANT, BlockBOPGrass.BOPGrassType.LOAMY);
case SANDY:
@ -202,15 +200,15 @@ public class BlockBOPDirt extends Block implements IBOPBlock, ISustainsPlantType
return Blocks.grass.getDefaultState();
}
}
public Block getGrassBlock(IBlockState state)
{
return getGrassBlockState(state).getBlock();
}
public int getGrassBlockMeta(IBlockState state)
{
return this.getGrassBlock(state).getMetaFromState(getGrassBlockState(state));
}
}

View file

@ -0,0 +1,185 @@
package biomesoplenty.common.block;
import biomesoplenty.api.block.BOPBlocks;
import biomesoplenty.api.block.IBOPBlock;
import biomesoplenty.common.item.ItemBOPBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockFarmland;
import net.minecraft.block.material.Material;
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.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.EnumPlantType;
import net.minecraftforge.common.IPlantable;
import java.util.ArrayList;
import java.util.Random;
public class BlockBOPFarmland extends BlockFarmland implements IBOPBlock
{
public static enum BOPFarmlandType implements IStringSerializable
{
LOAMY, SANDY, SILTY;
@Override
public String getName()
{
return this.name().toLowerCase();
}
@Override
public String toString()
{
return this.getName();
}
}
public static final PropertyEnum VARIANT = PropertyEnum.create("variant", BOPFarmlandType.class);
@Override
protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { MOISTURE, VARIANT });}
@Override
public Class<? extends ItemBlock> getItemClass() { return ItemBOPBlock.class; }
@Override
public int getItemRenderColor(IBlockState state, int tintIndex) { return this.getRenderColor(state); }
@Override
public IProperty[] getPresetProperties() { return new IProperty[] { VARIANT }; }
@Override
public IProperty[] getNonRenderingProperties() { return null; }
@Override
public String getStateName(IBlockState state) {
BOPFarmlandType farmlandType = (BOPFarmlandType)state.getValue(VARIANT);
return farmlandType + "_farmland";
}
public BlockBOPFarmland()
{
super();
this.setHardness(0.6F);
this.setHarvestLevel("shovel", 0);
this.setStepSound(soundTypeGravel);
this.setDefaultState(this.blockState.getBaseState().withProperty(MOISTURE, Integer.valueOf(0)).withProperty(VARIANT, BOPFarmlandType.LOAMY));
}
public IBlockState getStateFromMeta(int meta)
{
return this.getDefaultState().withProperty(MOISTURE, Integer.valueOf(meta & 7)).withProperty(VARIANT, BOPFarmlandType.values()[Math.min(2, meta & 7)]);
}
public int getMetaFromState(IBlockState state)
{
return ((BOPFarmlandType) state.getValue(VARIANT)).ordinal();
}
@Override
public void updateTick(World world, BlockPos pos, IBlockState state, Random random)
{
int i = (state.getValue(MOISTURE)).intValue();
if (!this.hasWater(world, pos) && !world.canLightningStrike(pos.up()))
{
if (i > 0)
{
world.setBlockState(pos, state.withProperty(MOISTURE, Integer.valueOf(i - 1)), 2);
}
else if (!this.hasCrops(world, pos))
{
world.setBlockState(pos, BOPBlocks.dirt.getDefaultState());
}
}
else if (i < 7)
{
world.setBlockState(pos, state.withProperty(MOISTURE, Integer.valueOf(0)), 2);
}
}
private boolean hasWater(World world, BlockPos pos)
{
for (BlockPos.MutableBlockPos mutableblockpos : BlockPos.getAllInBoxMutable(pos.add(-4, 0, -4), pos.add(4, 1, 4)))
{
if (world.getBlockState(mutableblockpos).getBlock().getMaterial() == Material.water)
{
return true;
}
}
return false;
}
private boolean hasCrops(World world, BlockPos pos)
{
Block block = world.getBlockState(pos.up()).getBlock();
return block instanceof IPlantable && canSustainPlant(world, pos, EnumFacing.UP, (IPlantable)block);
}
@Override
public void onNeighborBlockChange(World world, BlockPos pos, IBlockState state, Block neighborBlock)
{
super.onNeighborBlockChange(world, pos, state, neighborBlock);
if (world.getBlockState(pos.up()).getBlock().getMaterial().isSolid())
{
world.setBlockState(pos, BOPBlocks.dirt.getDefaultState());
}
}
@Override
public void onFallenUpon(World world, BlockPos pos, Entity entity, float fallDistance)
{
if (entity instanceof EntityLivingBase)
{
if (!world.isRemote && world.rand.nextFloat() < fallDistance - 0.5F)
{
if (!(entity instanceof EntityPlayer) && !world.getGameRules().getBoolean("mobGriefing"))
{
return;
}
world.setBlockState(pos, BOPBlocks.dirt.getDefaultState()); //TODO Check, was setBlock(pos, BOPBlocks.dirt, (world.getBlockMetadata(pos) / 2) * 2, 2);
}
}
}
@Override
public ArrayList<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune)
{
ArrayList<ItemStack> ret = new ArrayList<ItemStack>();
ret.add(new ItemStack(BOPBlocks.dirt, 1, (state.getBlock().getMetaFromState(state) / 2) * 2)); //TODO Check
return ret;
}
@Override
public ItemStack getPickBlock(MovingObjectPosition target, World world, BlockPos pos, EntityPlayer player)
{
return new ItemStack(BOPBlocks.dirt, 1, this.getMetaFromState(world.getBlockState(pos)));
}
@Override
public boolean canSustainPlant(IBlockAccess world, BlockPos pos, EnumFacing direction, IPlantable plantable)
{
EnumPlantType plantType = plantable.getPlantType(world, pos.up());
switch (plantType)
{
case Crop:
return true;
default:
return super.canSustainPlant(world, pos, direction, plantable);
}
}
}

View file

@ -45,9 +45,6 @@ import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockBOPGrass extends BlockGrass implements IBOPBlock, ISustainsPlantType
{
// TODO: make it ploughable into farmland
// add properties (note we also inherit the SNOWY property from BlockGrass)
public static enum BOPGrassType implements IStringSerializable
{

View file

@ -0,0 +1,60 @@
package biomesoplenty.common.handler;
import biomesoplenty.api.block.BOPBlocks;
import biomesoplenty.common.block.BlockBOPDirt;
import biomesoplenty.common.block.BlockBOPGrass;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.util.BlockPos;
import net.minecraftforge.event.entity.player.UseHoeEvent;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
public class UseHoeEventHandler {
@SubscribeEvent
public void useHoe(UseHoeEvent event)
{
if (event.getResult() != Event.Result.DEFAULT || event.isCanceled())
{
return;
}
BlockPos pos = event.pos;
IBlockState state = event.world.getBlockState(pos);
Block block = state.getBlock();
boolean result = false;
if (block instanceof BlockBOPDirt || block instanceof BlockBOPGrass)
{
result = true;
if (!(block instanceof BlockBOPGrass))
{
if ((state.getBlock().getMetaFromState(state) & 1) == 1)
{
event.world.setBlockState(pos, state.getBlock().getStateFromMeta(state.getBlock().getMetaFromState(state) - 1), 2);
}
else
{
event.world.setBlockState(pos, BOPBlocks.farmland.getDefaultState(), 2);
}
}
else
{
event.world.setBlockState(pos, Blocks.farmland.getDefaultState());
}
}
if (result)
{
if (!event.entityPlayer.capabilities.isCreativeMode)
{
event.current.damageItem(1, event.entityLiving);
}
event.world.playSoundEffect((double)((float)pos.getX() + 0.5F), (double)((float)pos.getY() + 0.5F), (double)((float)pos.getZ() + 0.5F), block.stepSound.getStepSound(), (state.getBlock().stepSound.getVolume() + 1.0F) / 2.0F, state.getBlock().stepSound.getFrequency() * 0.8F);
event.entityPlayer.swingItem();
}
}
}

View file

@ -13,6 +13,8 @@ import static biomesoplenty.api.item.BOPItems.blood_bucket;
import static biomesoplenty.api.item.BOPItems.honey_bucket;
import static biomesoplenty.api.item.BOPItems.poison_bucket;
import static biomesoplenty.api.item.BOPItems.hot_spring_water_bucket;
import biomesoplenty.common.block.*;
import net.minecraft.block.Block;
import net.minecraft.block.BlockSlab;
import net.minecraft.block.BlockStairs;
@ -32,44 +34,6 @@ import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fml.common.registry.GameRegistry;
import biomesoplenty.api.block.IBOPBlock;
import biomesoplenty.api.item.BOPItems;
import biomesoplenty.common.block.BlockBOPAsh;
import biomesoplenty.common.block.BlockBOPBamboo;
import biomesoplenty.common.block.BlockBOPBiomeBlock;
import biomesoplenty.common.block.BlockBOPBones;
import biomesoplenty.common.block.BlockBOPCoral;
import biomesoplenty.common.block.BlockBOPCrystal;
import biomesoplenty.common.block.BlockBOPDirt;
import biomesoplenty.common.block.BlockBOPDoor;
import biomesoplenty.common.block.BlockBOPDoubleOtherSlab;
import biomesoplenty.common.block.BlockBOPDoublePlant;
import biomesoplenty.common.block.BlockBOPDoubleWoodSlab;
import biomesoplenty.common.block.BlockBOPFence;
import biomesoplenty.common.block.BlockBOPFenceGate;
import biomesoplenty.common.block.BlockBOPFlesh;
import biomesoplenty.common.block.BlockBOPFlower;
import biomesoplenty.common.block.BlockBOPGem;
import biomesoplenty.common.block.BlockBOPGemOre;
import biomesoplenty.common.block.BlockBOPGeneric;
import biomesoplenty.common.block.BlockBOPGrass;
import biomesoplenty.common.block.BlockBOPHalfOtherSlab;
import biomesoplenty.common.block.BlockBOPHalfWoodSlab;
import biomesoplenty.common.block.BlockBOPHive;
import biomesoplenty.common.block.BlockBOPHoney;
import biomesoplenty.common.block.BlockBOPLeaves;
import biomesoplenty.common.block.BlockBOPLilypad;
import biomesoplenty.common.block.BlockBOPLog;
import biomesoplenty.common.block.BlockBOPMud;
import biomesoplenty.common.block.BlockBOPMushroom;
import biomesoplenty.common.block.BlockBOPPlanks;
import biomesoplenty.common.block.BlockBOPPlant;
import biomesoplenty.common.block.BlockBOPSand;
import biomesoplenty.common.block.BlockBOPSapling;
import biomesoplenty.common.block.BlockBOPSeaweed;
import biomesoplenty.common.block.BlockBOPStone;
import biomesoplenty.common.block.BlockBOPTerrarium;
import biomesoplenty.common.block.BlockBOPTurnip;
import biomesoplenty.common.block.BlockBOPVine;
import biomesoplenty.common.block.BlockBOPWoodStairs;
import biomesoplenty.common.command.BOPCommand;
import biomesoplenty.common.enums.BOPWoods;
import biomesoplenty.common.fluids.BloodFluid;
@ -115,6 +79,7 @@ public class ModBlocks
grass = registerBlock( new BlockBOPGrass(), "grass" );
waterlily = registerBlock( new BlockBOPLilypad(), "waterlily" );
dirt = registerBlock( new BlockBOPDirt(), "dirt" );
farmland = registerBlock( new BlockBOPFarmland(), "farmland" );
crystal = registerBlock( new BlockBOPCrystal(), "crystal" );
biome_block = registerBlock( new BlockBOPBiomeBlock(), "biome_block" );

View file

@ -34,6 +34,7 @@ public class ModHandlers
MinecraftForge.EVENT_BUS.register(new PotionParalysisEventHandler());
MinecraftForge.EVENT_BUS.register(new PotionPossessionEventHandler());
MinecraftForge.EVENT_BUS.register(new ItemEventHandler());
MinecraftForge.EVENT_BUS.register(new UseHoeEventHandler());
FMLCommonHandler.instance().bus().register(new AchievementEventHandler());
if (FMLCommonHandler.instance().getSide() == Side.CLIENT)

View file

@ -0,0 +1,28 @@
{
"variants": {
"moisture=0,variant=loamy": { "model": "biomesoplenty:loamy_farmland_dry" },
"moisture=1,variant=loamy": { "model": "biomesoplenty:loamy_farmland_dry" },
"moisture=2,variant=loamy": { "model": "biomesoplenty:loamy_farmland_dry" },
"moisture=3,variant=loamy": { "model": "biomesoplenty:loamy_farmland_dry" },
"moisture=4,variant=loamy": { "model": "biomesoplenty:loamy_farmland_dry" },
"moisture=5,variant=loamy": { "model": "biomesoplenty:loamy_farmland_dry" },
"moisture=6,variant=loamy": { "model": "biomesoplenty:loamy_farmland_dry" },
"moisture=7,variant=loamy": { "model": "biomesoplenty:loamy_farmland_moist" },
"moisture=0,variant=sandy": { "model": "biomesoplenty:sandy_farmland_dry" },
"moisture=1,variant=sandy": { "model": "biomesoplenty:sandy_farmland_dry" },
"moisture=2,variant=sandy": { "model": "biomesoplenty:sandy_farmland_dry" },
"moisture=3,variant=sandy": { "model": "biomesoplenty:sandy_farmland_dry" },
"moisture=4,variant=sandy": { "model": "biomesoplenty:sandy_farmland_dry" },
"moisture=5,variant=sandy": { "model": "biomesoplenty:sandy_farmland_dry" },
"moisture=6,variant=sandy": { "model": "biomesoplenty:sandy_farmland_dry" },
"moisture=7,variant=sandy": { "model": "biomesoplenty:sandy_farmland_moist" },
"moisture=0,variant=silty": { "model": "biomesoplenty:silty_farmland_dry" },
"moisture=1,variant=silty": { "model": "biomesoplenty:silty_farmland_dry" },
"moisture=2,variant=silty": { "model": "biomesoplenty:silty_farmland_dry" },
"moisture=3,variant=silty": { "model": "biomesoplenty:silty_farmland_dry" },
"moisture=4,variant=silty": { "model": "biomesoplenty:silty_farmland_dry" },
"moisture=5,variant=silty": { "model": "biomesoplenty:silty_farmland_dry" },
"moisture=6,variant=silty": { "model": "biomesoplenty:silty_farmland_dry" },
"moisture=7,variant=silty": { "model": "biomesoplenty:silty_farmland_moist" }
}
}

View file

@ -0,0 +1,11 @@
{
"forge_marker": 1,
"defaults": {
"model": "biomesoplenty:loamy_farmland_dry"
},
"variants": {
"inventory": [{
"transform": "forge:default-block"
}]
}
}

View file

@ -0,0 +1,11 @@
{
"forge_marker": 1,
"defaults": {
"model": "biomesoplenty:sandy_farmland_dry"
},
"variants": {
"inventory": [{
"transform": "forge:default-block"
}]
}
}

View file

@ -0,0 +1,11 @@
{
"forge_marker": 1,
"defaults": {
"model": "biomesoplenty:silty_farmland_dry"
},
"variants": {
"inventory": [{
"transform": "forge:default-block"
}]
}
}

View file

@ -206,6 +206,9 @@ tile.ethereal_fence.name=Ethereal Fence
tile.ethereal_fence_gate.name=Ethereal Fence Gate
tile.ethereal_wood_slab.name=Ethereal Wood Slab
tile.ethereal_stairs.name=Ethereal Wood Stairs
tile.farmland.loamy_farmland.name=Loamy Farmland
tile.farmland.sandy_farmland.name=Sandy Farmland
tile.farmland.silty_farmland.name=Silty Farmland
tile.fir_fence.name=Fir Fence
tile.fir_fence_gate.name=Fir Fence Gate
tile.fir_wood_slab.name=Fir Wood Slab

View file

@ -0,0 +1,8 @@
{
"parent": "block/farmland",
"textures": {
"particle": "biomesoplenty:blocks/dirt_loamy",
"dirt": "biomesoplenty:blocks/dirt_loamy",
"top": "biomesoplenty:blocks/farmland_dry_loamy"
}
}

View file

@ -0,0 +1,8 @@
{
"parent": "block/farmland",
"textures": {
"particle": "biomesoplenty:blocks/dirt_loamy",
"dirt": "biomesoplenty:blocks/dirt_loamy",
"top": "biomesoplenty:blocks/farmland_moist_loamy"
}
}

View file

@ -0,0 +1,8 @@
{
"parent": "block/farmland",
"textures": {
"particle": "biomesoplenty:blocks/dirt_sandy",
"dirt": "biomesoplenty:blocks/dirt_sandy",
"top": "biomesoplenty:blocks/farmland_dry_sandy"
}
}

View file

@ -0,0 +1,8 @@
{
"parent": "block/farmland",
"textures": {
"particle": "biomesoplenty:blocks/dirt_sandy",
"dirt": "biomesoplenty:blocks/dirt_sandy",
"top": "biomesoplenty:blocks/farmland_moist_sandy"
}
}

View file

@ -0,0 +1,8 @@
{
"parent": "block/farmland",
"textures": {
"particle": "biomesoplenty:blocks/dirt_silty",
"dirt": "biomesoplenty:blocks/dirt_silty",
"top": "biomesoplenty:blocks/farmland_dry_silty"
}
}

View file

@ -0,0 +1,8 @@
{
"parent": "block/farmland",
"textures": {
"particle": "biomesoplenty:blocks/dirt_silty",
"dirt": "biomesoplenty:blocks/dirt_silty",
"top": "biomesoplenty:blocks/farmland_moist_silty"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 332 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 336 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 335 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 567 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 649 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 617 B