Added an option to require shears for flower drops

This commit is contained in:
Adubbz 2016-01-13 00:37:28 +11:00
parent dd38421d45
commit c25dcedc13
4 changed files with 75 additions and 2 deletions

View file

@ -8,9 +8,12 @@
package biomesoplenty.common.block;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import biomesoplenty.api.block.BOPBlocks;
import biomesoplenty.common.config.GameplayConfigurationHandler;
import biomesoplenty.common.enums.BOPFlowers;
import biomesoplenty.common.item.ItemBOPFlower;
import biomesoplenty.common.util.block.VariantPagingHelper;
@ -24,6 +27,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemShears;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.tileentity.TileEntity;
@ -31,10 +35,11 @@ import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.IShearable;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockBOPFlower extends BlockBOPDecoration
public class BlockBOPFlower extends BlockBOPDecoration implements IShearable
{
// setup paged variant property
@ -284,6 +289,32 @@ public class BlockBOPFlower extends BlockBOPDecoration
}
//
// The below three methods are used for the require shears setting
//
@Override
public boolean isShearable(ItemStack item, IBlockAccess world, BlockPos pos)
{
return GameplayConfigurationHandler.flowerDropsNeedShears;
}
@Override
public void dropBlockAsItemWithChance(World world, BlockPos pos, IBlockState state, float chance, int fortune)
{
EntityPlayer player = this.harvesters.get();
boolean usingShears = (player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() instanceof ItemShears);
//Player must use shears when flowerDropsNeedShears is enabled
if (GameplayConfigurationHandler.flowerDropsNeedShears && !usingShears)
return;
super.dropBlockAsItemWithChance(world, pos, state, chance, fortune);
}
@Override
public List<ItemStack> onSheared(ItemStack item, IBlockAccess world, BlockPos pos, int fortune) { return new ArrayList<ItemStack>(); }

View file

@ -198,7 +198,7 @@ public class BlockBOPPlant extends BlockBOPDecoration implements IShearable
public void harvestBlock(World world, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity tileentity)
{
super.harvestBlock(world, player, pos, state, tileentity);
boolean usingShears = (player.getCurrentEquippedItem() == null || !(player.getCurrentEquippedItem().getItem() instanceof ItemShears));
boolean usingShears = (player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() instanceof ItemShears);
switch ((BOPPlants) state.getValue(this.variantProperty))
{
// suffer cactus damage if you harvest thorn without shears

View file

@ -0,0 +1,40 @@
/*******************************************************************************
* Copyright 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.config;
import java.io.File;
import biomesoplenty.core.BiomesOPlenty;
import net.minecraftforge.common.config.Configuration;
public class GameplayConfigurationHandler
{
public static Configuration config;
public static boolean flowerDropsNeedShears;
public static void init(File configFile)
{
config = new Configuration(configFile);
try
{
config.load();
flowerDropsNeedShears = config.getBoolean("Flower Drops Need Shears", "Convenience Settings", false, "Require shears to be used to collect flower drops.");
}
catch (Exception e)
{
BiomesOPlenty.logger.error("Biomes O' Plenty has encountered a problem loading gameplay.cfg", e);
}
finally
{
if (config.hasChanged()) config.save();
}
}
}

View file

@ -10,12 +10,14 @@ package biomesoplenty.common.init;
import java.io.File;
import biomesoplenty.common.config.GameplayConfigurationHandler;
import biomesoplenty.common.config.MiscConfigurationHandler;
public class ModConfiguration
{
public static void init(File configDirectory)
{
GameplayConfigurationHandler.init(new File(configDirectory, "gameplay.cfg"));
MiscConfigurationHandler.init(new File(configDirectory, "misc.cfg"));
}
}