Merge pull request #659 from GirafiStudios/BOP-1.8.9-3.0.x

Added Loamy, Sandy & Silty Farmland + UseHoeEventHandler. Closes #589
This commit is contained in:
Adubbz 2016-02-07 16:31:56 +11:00
commit f131d97f89
22 changed files with 447 additions and 68 deletions

View File

@ -112,6 +112,8 @@ public class BOPBlocks
public static Block grass;
public static Block waterlily;
public static Block dirt;
public static Block farmland_0;
public static Block farmland_1;
public static Block stone_formations;
public static Block hard_ice;
public static Block dried_sand;

View File

@ -10,6 +10,7 @@ package biomesoplenty.common.block;
import java.util.Random;
import biomesoplenty.common.util.block.VariantPagingHelper;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
@ -34,10 +35,8 @@ 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
public static enum BOPDirtType implements IStringSerializable, VariantPagingHelper.IPagedVariants
{
LOAMY, SANDY, SILTY;
@Override

View File

@ -0,0 +1,217 @@
/*******************************************************************************
* 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/.
******************************************************************************/
package biomesoplenty.common.block;
import biomesoplenty.api.block.BOPBlocks;
import biomesoplenty.api.block.IBOPBlock;
import biomesoplenty.common.item.ItemBOPBlock;
import biomesoplenty.common.util.block.VariantPagingHelper;
import net.minecraft.block.Block;
import net.minecraft.block.BlockDirt;
import net.minecraft.block.BlockFarmland;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
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.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
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.Random;
public class BlockBOPFarmland extends BlockFarmland implements IBOPBlock
{
public static VariantPagingHelper<BlockBOPFarmland, BlockBOPDirt.BOPDirtType> paging = new VariantPagingHelper<BlockBOPFarmland, BlockBOPDirt.BOPDirtType>(2, BlockBOPDirt.BOPDirtType.class);
private static IProperty currentVariantProperty;
public static void createAllPages()
{
int numPages = paging.getNumPages();
for (int i = 0; i < numPages; ++i)
{
currentVariantProperty = paging.getVariantProperty(i);
paging.addBlock(i, new BlockBOPFarmland());
}
}
public IProperty variantProperty;
@Override
protected BlockState createBlockState()
{
this.variantProperty = currentVariantProperty;
return new BlockState(this, new IProperty[] { MOISTURE, this.variantProperty });
}
@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[] { this.variantProperty }; }
@Override
public IProperty[] getNonRenderingProperties() { return null; }
@Override
public String getStateName(IBlockState state)
{
return ((BlockBOPDirt.BOPDirtType) state.getValue(this.variantProperty)).getName() + "_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)));
}
public IBlockState getStateFromMeta(int meta)
{
return this.getDefaultState().withProperty(this.variantProperty, paging.getVariant(this, meta & 1)).withProperty(MOISTURE, Integer.valueOf(meta >> 1));
}
public int getMetaFromState(IBlockState state)
{
BlockBOPDirt.BOPDirtType dirt = (BlockBOPDirt.BOPDirtType) state.getValue(this.variantProperty);
int meta = paging.getIndex(dirt);
meta |= state.getValue(MOISTURE) << 1;
return meta;
}
@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, this.getDirtBlockState(world.getBlockState(pos)));
}
}
else if (i < 7)
{
world.setBlockState(pos, state.withProperty(MOISTURE, Integer.valueOf(7)), 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)
{
if (world.getBlockState(pos.up()).getBlock().getMaterial().isSolid())
{
world.setBlockState(pos, this.getDirtBlockState(world.getBlockState(pos)));
}
}
@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, this.getDirtBlockState(world.getBlockState(pos)));
}
}
}
@Override
public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
return Item.getItemFromBlock(BOPBlocks.dirt);
}
@Override
public int damageDropped(IBlockState state)
{
return BOPBlocks.dirt.getMetaFromState(this.getDirtBlockState(state));
}
@Override
public ItemStack getPickBlock(MovingObjectPosition target, World world, BlockPos pos, EntityPlayer player)
{
return new ItemStack(BOPBlocks.dirt, 1, BOPBlocks.dirt.getMetaFromState(this.getDirtBlockState(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);
}
}
public IBlockState getDirtBlockState(IBlockState state)
{
switch ((BlockBOPDirt.BOPDirtType) state.getValue(this.variantProperty))
{
case LOAMY:
return BOPBlocks.dirt.getDefaultState().withProperty(BlockBOPDirt.VARIANT, BlockBOPDirt.BOPDirtType.LOAMY);
case SANDY:
return BOPBlocks.dirt.getDefaultState().withProperty(BlockBOPDirt.VARIANT, BlockBOPDirt.BOPDirtType.SANDY);
case SILTY:
return BOPBlocks.dirt.getDefaultState().withProperty(BlockBOPDirt.VARIANT, BlockBOPDirt.BOPDirtType.SILTY);
default:
return Blocks.dirt.getStateFromMeta(BlockDirt.DirtType.DIRT.getMetadata());
}
}
}

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,79 @@
/*******************************************************************************
* 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/.
******************************************************************************/
package biomesoplenty.common.handler;
import biomesoplenty.common.block.BlockBOPDirt;
import biomesoplenty.common.block.BlockBOPFarmland;
import biomesoplenty.common.block.BlockBOPGrass;
import net.minecraft.block.Block;
import net.minecraft.block.BlockDirt;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
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;
}
World world = event.world;
BlockPos pos = event.pos;
IBlockState state = world.getBlockState(pos);
Block block = state.getBlock();
boolean result = false;
if (block instanceof BlockBOPDirt)
{
result = true;
if (state.getValue(BlockBOPDirt.COARSE))
{
world.setBlockState(pos, state.withProperty(BlockBOPDirt.COARSE, Boolean.valueOf(false)));
} else
{
world.setBlockState(pos, BlockBOPFarmland.paging.getVariantState((BlockBOPDirt.BOPDirtType) state.getValue(BlockBOPDirt.VARIANT)));
}
}
else if (block instanceof BlockBOPGrass)
{
result = true;
BlockBOPGrass grass = (BlockBOPGrass) state.getBlock();
Block dirtBlock = grass.getDirtBlockState(state).getBlock();
if (dirtBlock instanceof BlockBOPDirt)
{
BlockBOPDirt.BOPDirtType dirtType = (BlockBOPDirt.BOPDirtType) grass.getDirtBlockState(state).getValue(BlockBOPDirt.VARIANT);
world.setBlockState(pos, BlockBOPFarmland.paging.getVariantState(dirtType));
}
else if (dirtBlock instanceof BlockDirt && state.getValue(BlockBOPGrass.VARIANT) != BlockBOPGrass.BOPGrassType.SMOLDERING)
{
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;
@ -172,6 +136,10 @@ public class ModBlocks
leaves_4 = registerBlock( BlockBOPLeaves.paging.getBlock(4), "leaves_4" );
leaves_5 = registerBlock( BlockBOPLeaves.paging.getBlock(5), "leaves_5" );
BlockBOPFarmland.createAllPages();
farmland_0 = registerBlock( BlockBOPFarmland.paging.getBlock(0), "farmland_0");
farmland_1 = registerBlock( BlockBOPFarmland.paging.getBlock(1), "farmland_1");
// 22 tree types, 8 per BlockBOPSapling instance, needs 3 'pages'
BlockBOPSapling.createAllPages();
sapling_0 = registerBlock( BlockBOPSapling.paging.getBlock(0), "sapling_0");

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,20 @@
{
"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" }
}
}

View File

@ -0,0 +1,12 @@
{
"variants": {
"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_0.loamy_farmland.name=Loamy Farmland
tile.farmland_0.sandy_farmland.name=Sandy Farmland
tile.farmland_1.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"
}
}