From 9209d0843f61e7e062c50cc66e3f2263635655d5 Mon Sep 17 00:00:00 2001 From: Blood-Asp Date: Tue, 13 Jun 2017 18:58:18 +0200 Subject: [PATCH] Port GT6 timber changes --- .../gregtech/api/interfaces/IToolStats.java | 3 +++ .../api/items/GT_MetaGenerated_Tool.java | 12 ++++++++++++ src/main/java/gregtech/common/GT_Proxy.java | 17 +++++++++++++++++ .../java/gregtech/common/tools/GT_Tool.java | 12 ++++++++++++ .../java/gregtech/common/tools/GT_Tool_Axe.java | 16 ++++++++++++++++ .../common/tools/GT_Tool_Chainsaw_LV.java | 16 ++++++++++++++++ 6 files changed, 76 insertions(+) diff --git a/src/main/java/gregtech/api/interfaces/IToolStats.java b/src/main/java/gregtech/api/interfaces/IToolStats.java index 3c03bb85..70aaeb20 100644 --- a/src/main/java/gregtech/api/interfaces/IToolStats.java +++ b/src/main/java/gregtech/api/interfaces/IToolStats.java @@ -8,6 +8,7 @@ import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.DamageSource; +import net.minecraft.world.World; import net.minecraftforge.event.world.BlockEvent; import java.util.List; @@ -156,4 +157,6 @@ public interface IToolStats { public IIconContainer getIcon(boolean aIsToolHead, ItemStack aStack); public short[] getRGBa(boolean aIsToolHead, ItemStack aStack); + + public float getMiningSpeed(Block aBlock, byte aMetaData, float aDefault, EntityPlayer aPlayer, World worldObj, int aX, int aY, int aZ); } \ No newline at end of file diff --git a/src/main/java/gregtech/api/items/GT_MetaGenerated_Tool.java b/src/main/java/gregtech/api/items/GT_MetaGenerated_Tool.java index baa5d23b..80b5fc21 100644 --- a/src/main/java/gregtech/api/items/GT_MetaGenerated_Tool.java +++ b/src/main/java/gregtech/api/items/GT_MetaGenerated_Tool.java @@ -1,6 +1,7 @@ package gregtech.api.items; import buildcraft.api.tools.IToolWrench; +import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Optional; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -42,6 +43,7 @@ import net.minecraft.util.IIcon; import net.minecraft.util.MathHelper; import net.minecraft.world.World; import net.minecraftforge.common.IShearable; +import net.minecraftforge.event.entity.player.PlayerEvent; import net.minecraftforge.event.world.BlockEvent; import java.util.ArrayList; @@ -208,12 +210,22 @@ public abstract class GT_MetaGenerated_Tool extends GT_MetaBase_Item implements /** * Called by the Block Harvesting Event within the GT_Proxy */ + @Mod.EventHandler public void onHarvestBlockEvent(ArrayList aDrops, ItemStack aStack, EntityPlayer aPlayer, Block aBlock, int aX, int aY, int aZ, byte aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent) { IToolStats tStats = getToolStats(aStack); if (isItemStackUsable(aStack) && getDigSpeed(aStack, aBlock, aMetaData) > 0.0F) doDamage(aStack, tStats.convertBlockDrops(aDrops, aStack, aPlayer, aBlock, aX, aY, aZ, aMetaData, aFortune, aSilkTouch, aEvent) * tStats.getToolDamagePerDropConversion()); } + @Mod.EventHandler + public float onBlockBreakSpeedEvent(float aDefault, ItemStack aStack, EntityPlayer aPlayer, Block aBlock, int aX, int aY, int aZ, byte aMetaData, PlayerEvent.BreakSpeed aEvent) + { + IToolStats tStats = getToolStats(aStack); + float tTest = tStats == null ? aDefault : tStats.getMiningSpeed(aBlock, aMetaData, aDefault, aPlayer, aPlayer.worldObj, aX, aY, aZ); + System.out.println("test: "+tTest+" default: "+aDefault); + return tTest; + } + @Override public boolean onBlockStartBreak(ItemStack aStack, int aX, int aY, int aZ, EntityPlayer aPlayer) { diff --git a/src/main/java/gregtech/common/GT_Proxy.java b/src/main/java/gregtech/common/GT_Proxy.java index 3f8a24ad..304978c4 100644 --- a/src/main/java/gregtech/common/GT_Proxy.java +++ b/src/main/java/gregtech/common/GT_Proxy.java @@ -38,6 +38,7 @@ import gregtech.common.items.armor.gui.ContainerElectricArmor1; import gregtech.common.items.armor.gui.GuiElectricArmor1; import gregtech.common.items.armor.gui.GuiModularArmor; import gregtech.common.items.armor.gui.InventoryArmor; +import gregtech.common.tools.GT_Tool; import net.minecraft.enchantment.Enchantment; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.Entity; @@ -69,6 +70,7 @@ import net.minecraftforge.event.entity.EntityJoinWorldEvent; import net.minecraftforge.event.entity.living.EnderTeleportEvent; import net.minecraftforge.event.entity.player.ArrowLooseEvent; import net.minecraftforge.event.entity.player.ArrowNockEvent; +import net.minecraftforge.event.entity.player.PlayerEvent; import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.event.terraingen.OreGenEvent; import net.minecraftforge.event.world.BlockEvent; @@ -1796,6 +1798,21 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler { ////DO NOTHING - this chunk data was already loaded and stored in hash map //} } + + @SubscribeEvent + public void onBlockBreakSpeedEvent(PlayerEvent.BreakSpeed aEvent) + { + if (aEvent.newSpeed > 0.0F) + { + if (aEvent.entityPlayer != null) + { + ItemStack aStack = aEvent.entityPlayer.getCurrentEquippedItem(); + if ((aStack != null) && ((aStack.getItem() instanceof GT_MetaGenerated_Tool))) { + aEvent.newSpeed = ((GT_MetaGenerated_Tool)aStack.getItem()).onBlockBreakSpeedEvent(aEvent.newSpeed, aStack, aEvent.entityPlayer, aEvent.block, aEvent.x, aEvent.y, aEvent.z, (byte)aEvent.metadata, aEvent); + } + } + } + } public static class OreDictEventContainer { public final OreDictionary.OreRegisterEvent mEvent; diff --git a/src/main/java/gregtech/common/tools/GT_Tool.java b/src/main/java/gregtech/common/tools/GT_Tool.java index a1596ba9..299d59ed 100644 --- a/src/main/java/gregtech/common/tools/GT_Tool.java +++ b/src/main/java/gregtech/common/tools/GT_Tool.java @@ -14,6 +14,7 @@ import net.minecraft.stats.AchievementList; import net.minecraft.util.DamageSource; import net.minecraft.util.EntityDamageSource; import net.minecraft.util.IChatComponent; +import net.minecraft.world.World; import net.minecraftforge.event.world.BlockEvent; import java.util.List; @@ -145,4 +146,15 @@ public abstract class GT_Tool public float getMagicDamageAgainstEntity(float aOriginalDamage, Entity aEntity, ItemStack aStack, EntityPlayer aPlayer) { return aOriginalDamage; } + + public float getMiningSpeed(Block aBlock, byte aMetaData) + { + return isMinableBlock(aBlock, aMetaData) ? 1.0F : 0.0F; + } + + + @Override + public float getMiningSpeed(Block aBlock, byte aMetaData, float aDefault, EntityPlayer aPlayer, World worldObj, int aX, int aY, int aZ) { + return getMiningSpeed(aBlock, aMetaData); + } } diff --git a/src/main/java/gregtech/common/tools/GT_Tool_Axe.java b/src/main/java/gregtech/common/tools/GT_Tool_Axe.java index f74aeca5..c536361b 100644 --- a/src/main/java/gregtech/common/tools/GT_Tool_Axe.java +++ b/src/main/java/gregtech/common/tools/GT_Tool_Axe.java @@ -12,6 +12,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.IChatComponent; +import net.minecraft.world.World; import net.minecraftforge.event.world.BlockEvent; import java.util.List; @@ -96,6 +97,21 @@ public class GT_Tool_Axe } return rAmount; } + + public float getMiningSpeed(Block aBlock, byte aMetaData, float aDefault, EntityPlayer aPlayer, World aWorld, int aX, int aY, int aZ) + { + if (aBlock.isWood(aPlayer.worldObj, aX, aY, aZ) && OrePrefixes.log.contains(new ItemStack(aBlock, 1, aMetaData))){ + float rAmount = 1.0F;float tIncrement = 1.0F; + if ((GregTech_API.sTimber) && !aPlayer.isSneaking()){ + int tY = aY + 1; + for (int tH = aPlayer.worldObj.getHeight(); (tY < tH) && (aPlayer.worldObj.getBlock(aX, tY, aZ) == aBlock); tY++){ + tIncrement += 0.1F;rAmount += tIncrement; + } + } + return 2.0F * aDefault / rAmount; + } + return (aBlock.getMaterial() == Material.leaves) || (aBlock.getMaterial() == Material.vine) || (aBlock.getMaterial() == Material.plants) || (aBlock.getMaterial() == Material.gourd) ? aDefault / 4.0F : aDefault; + } public ItemStack getBrokenItem(ItemStack aStack) { return null; diff --git a/src/main/java/gregtech/common/tools/GT_Tool_Chainsaw_LV.java b/src/main/java/gregtech/common/tools/GT_Tool_Chainsaw_LV.java index a1acbf10..93722c52 100644 --- a/src/main/java/gregtech/common/tools/GT_Tool_Chainsaw_LV.java +++ b/src/main/java/gregtech/common/tools/GT_Tool_Chainsaw_LV.java @@ -20,6 +20,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.IChatComponent; +import net.minecraft.world.World; import net.minecraftforge.common.IShearable; import net.minecraftforge.event.world.BlockEvent; @@ -135,6 +136,21 @@ public class GT_Tool_Chainsaw_LV } return rAmount; } + + public float getMiningSpeed(Block aBlock, byte aMetaData, float aDefault, EntityPlayer aPlayer, World aWorld, int aX, int aY, int aZ) + { + if (aBlock.isWood(aPlayer.worldObj, aX, aY, aZ) && OrePrefixes.log.contains(new ItemStack(aBlock, 1, aMetaData))){ + float rAmount = 1.0F;float tIncrement = 1.0F; + if ((GregTech_API.sTimber) && !aPlayer.isSneaking()){ + int tY = aY + 1; + for (int tH = aPlayer.worldObj.getHeight(); (tY < tH) && (aPlayer.worldObj.getBlock(aX, tY, aZ) == aBlock); tY++){ + tIncrement += 0.1F;rAmount += tIncrement; + } + } + return 2.0F * aDefault / rAmount; + } + return (aBlock.getMaterial() == Material.leaves) || (aBlock.getMaterial() == Material.vine) || (aBlock.getMaterial() == Material.plants) || (aBlock.getMaterial() == Material.gourd) ? aDefault / 4.0F : aDefault; + } public IIconContainer getIcon(boolean aIsToolHead, ItemStack aStack) { return aIsToolHead ? GT_MetaGenerated_Tool.getPrimaryMaterial(aStack).mIconSet.mTextures[gregtech.api.enums.OrePrefixes.toolHeadChainsaw.mTextureIndex] : Textures.ItemIcons.POWER_UNIT_LV;