Switched to using an event for handling leaf break speeds rather than overriding shears
This commit is contained in:
parent
fc4b7a3142
commit
ac5c03abae
4 changed files with 99 additions and 58 deletions
|
@ -1,12 +1,5 @@
|
|||
package biomesoplenty;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
@ -21,6 +14,7 @@ import biomesoplenty.configuration.BOPPotions;
|
|||
import biomesoplenty.configuration.BOPVanillaCompat;
|
||||
import biomesoplenty.handlers.BOPCraftHandler;
|
||||
import biomesoplenty.handlers.BonemealHandler;
|
||||
import biomesoplenty.handlers.BreakSpeedHandler;
|
||||
import biomesoplenty.handlers.EntityEventHandler;
|
||||
import biomesoplenty.handlers.SoundHandler;
|
||||
import biomesoplenty.handlers.TickHandlerClient;
|
||||
|
@ -30,12 +24,9 @@ import biomesoplenty.helpers.CreativeTabsBOP;
|
|||
import biomesoplenty.helpers.Localizations;
|
||||
import biomesoplenty.helpers.Version;
|
||||
import biomesoplenty.integration.BOPCrossIntegration;
|
||||
import biomesoplenty.integration.TConstructIntegration;
|
||||
import biomesoplenty.world.WorldProviderBOPhell;
|
||||
import biomesoplenty.world.WorldProviderPromised;
|
||||
import biomesoplenty.world.WorldTypeSize;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import cpw.mods.fml.common.Mod.Init;
|
||||
import cpw.mods.fml.common.Mod.Instance;
|
||||
|
@ -108,6 +99,7 @@ public class BiomesOPlenty
|
|||
MinecraftForge.EVENT_BUS.register(new BonemealHandler());
|
||||
MinecraftForge.EVENT_BUS.register(new EntityEventHandler());
|
||||
MinecraftForge.EVENT_BUS.register(new BOPLiquidHelper());
|
||||
MinecraftForge.EVENT_BUS.register(new BreakSpeedHandler());
|
||||
|
||||
proxy.registerRenderers();
|
||||
|
||||
|
|
|
@ -33,7 +33,6 @@ import biomesoplenty.items.ItemEnderporter;
|
|||
import biomesoplenty.items.ItemShroomPowder;
|
||||
import biomesoplenty.items.ItemSoulManipulator;
|
||||
import biomesoplenty.items.ItemSunflowerSeeds;
|
||||
import biomesoplenty.items.overrides.ItemShears;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
|
||||
|
@ -94,9 +93,6 @@ public class BOPItems {
|
|||
EnumToolMaterialAmethyst = EnumHelper.addToolMaterial("AMETHYST", 4, 2013, 15.0F, 5, 16);
|
||||
EnumArmorMaterialFlowerBand = EnumHelper.addArmorMaterial("FLOWERBAND", -1, new int[]{0, 0, 0, 0}, 0);
|
||||
|
||||
//Override Items
|
||||
shears = (new ItemShears(clearItem(Item.shears))).setUnlocalizedName("shears").setCreativeTab(CreativeTabs.tabTools);
|
||||
|
||||
initializeItems();
|
||||
|
||||
MinecraftForge.setToolClass(Items.shovelAmethyst.get(), "shovel", 4);
|
||||
|
|
97
src/minecraft/biomesoplenty/handlers/BreakSpeedHandler.java
Normal file
97
src/minecraft/biomesoplenty/handlers/BreakSpeedHandler.java
Normal file
|
@ -0,0 +1,97 @@
|
|||
package biomesoplenty.handlers;
|
||||
|
||||
import biomesoplenty.api.Blocks;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.EnumToolMaterial;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemAxe;
|
||||
import net.minecraft.item.ItemPickaxe;
|
||||
import net.minecraft.item.ItemSpade;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumMovingObjectType;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.event.ForgeSubscribe;
|
||||
import net.minecraftforge.event.Event.Result;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
|
||||
public class BreakSpeedHandler
|
||||
{
|
||||
@ForgeSubscribe
|
||||
public void breakSpeed(PlayerEvent.BreakSpeed event)
|
||||
{
|
||||
Item item = null;
|
||||
World world = event.entityLiving.worldObj;
|
||||
|
||||
if (event.entityPlayer.getCurrentEquippedItem() != null)
|
||||
{
|
||||
item = Item.itemsList[event.entityPlayer.getCurrentEquippedItem().itemID];
|
||||
}
|
||||
|
||||
MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(event.entityPlayer.worldObj, event.entityPlayer, true);
|
||||
|
||||
if (movingobjectposition != null)
|
||||
{
|
||||
if (movingobjectposition.typeOfHit == EnumMovingObjectType.TILE)
|
||||
{
|
||||
int i = movingobjectposition.blockX;
|
||||
int j = movingobjectposition.blockY;
|
||||
int k = movingobjectposition.blockZ;
|
||||
|
||||
if (item != null)
|
||||
{
|
||||
if (item.itemID == Item.shears.itemID)
|
||||
{
|
||||
Block block = Block.blocksList[world.getBlockId(i, j, k)];
|
||||
|
||||
if (Blocks.shearBlockIds.get(block.blockID) != null)
|
||||
{
|
||||
event.newSpeed = Float.parseFloat(Blocks.shearBlockIds.get(block.blockID).toString());
|
||||
}
|
||||
else if (block.blockID == Block.web.blockID | block.blockID == Block.leaves.blockID)
|
||||
{
|
||||
event.newSpeed = 15.0F;
|
||||
}
|
||||
else if (block.blockID == Block.cloth.blockID)
|
||||
{
|
||||
event.newSpeed = 5.0F;
|
||||
}
|
||||
else
|
||||
{
|
||||
event.newSpeed = item.getStrVsBlock(new ItemStack(item, 1), block);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static MovingObjectPosition getMovingObjectPositionFromPlayer(World par1World, EntityPlayer par2EntityPlayer, boolean par3)
|
||||
{
|
||||
float f = 1.0F;
|
||||
float f1 = par2EntityPlayer.prevRotationPitch + (par2EntityPlayer.rotationPitch - par2EntityPlayer.prevRotationPitch) * f;
|
||||
float f2 = par2EntityPlayer.prevRotationYaw + (par2EntityPlayer.rotationYaw - par2EntityPlayer.prevRotationYaw) * f;
|
||||
double d0 = par2EntityPlayer.prevPosX + (par2EntityPlayer.posX - par2EntityPlayer.prevPosX) * (double)f;
|
||||
double d1 = par2EntityPlayer.prevPosY + (par2EntityPlayer.posY - par2EntityPlayer.prevPosY) * (double)f + 1.62D - (double)par2EntityPlayer.yOffset;
|
||||
double d2 = par2EntityPlayer.prevPosZ + (par2EntityPlayer.posZ - par2EntityPlayer.prevPosZ) * (double)f;
|
||||
Vec3 vec3 = par1World.getWorldVec3Pool().getVecFromPool(d0, d1, d2);
|
||||
float f3 = MathHelper.cos(-f2 * 0.017453292F - (float)Math.PI);
|
||||
float f4 = MathHelper.sin(-f2 * 0.017453292F - (float)Math.PI);
|
||||
float f5 = -MathHelper.cos(-f1 * 0.017453292F);
|
||||
float f6 = MathHelper.sin(-f1 * 0.017453292F);
|
||||
float f7 = f4 * f5;
|
||||
float f8 = f3 * f5;
|
||||
double d3 = 5.0D;
|
||||
if (par2EntityPlayer instanceof EntityPlayerMP)
|
||||
{
|
||||
d3 = ((EntityPlayerMP)par2EntityPlayer).theItemInWorldManager.getBlockReachDistance();
|
||||
}
|
||||
Vec3 vec31 = vec3.addVector((double)f7 * d3, (double)f6 * d3, (double)f8 * d3);
|
||||
return par1World.rayTraceBlocks_do_do(vec3, vec31, par3, !par3);
|
||||
}
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
package biomesoplenty.items.overrides;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import biomesoplenty.api.Blocks;
|
||||
|
||||
public class ItemShears extends net.minecraft.item.ItemShears
|
||||
{
|
||||
public ItemShears(int var1)
|
||||
{
|
||||
super(var1);
|
||||
maxStackSize = 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the strength of the stack against a given block. 1.0F base, (Quality+1)*2 if correct blocktype, 1.5F if
|
||||
* sword
|
||||
*/
|
||||
@Override
|
||||
public float getStrVsBlock(ItemStack par1ItemStack, Block par2Block)
|
||||
{
|
||||
Float Strength = null;
|
||||
|
||||
if (Blocks.shearBlockIds.get(par2Block.blockID) != null)
|
||||
{
|
||||
Strength = Float.parseFloat(Blocks.shearBlockIds.get(par2Block.blockID).toString());
|
||||
}
|
||||
else if (par2Block.blockID == Block.web.blockID | par2Block.blockID == Block.leaves.blockID)
|
||||
{
|
||||
Strength = 15.0F;
|
||||
}
|
||||
else if (par2Block.blockID == Block.cloth.blockID)
|
||||
{
|
||||
Strength = 5.0F;
|
||||
}
|
||||
else
|
||||
{
|
||||
Strength = super.getStrVsBlock(par1ItemStack, par2Block);
|
||||
}
|
||||
|
||||
return Strength;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue