From fcca10b1b95c7f1f63557bc61d8f0f8cf3be475a Mon Sep 17 00:00:00 2001 From: boubou19 Date: Tue, 22 Jul 2025 15:19:37 +0200 Subject: [PATCH] Restore methods so other addons work again (#193) Co-authored-by: Alexdoru <57050655+Alexdoru@users.noreply.github.com> --- .../java/tconstruct/armor/TinkerArmor.java | 3 +- .../tconstruct/armor/TinkerArmorEvents.java | 222 ++++++++++-------- .../armor/player/TPlayerHandler.java | 113 +++++---- .../java/tconstruct/client/ArmorControls.java | 25 +- .../tconstruct/client/tabs/TabRegistry.java | 28 +-- .../gadgets/item/ItemSlimeBoots.java | 117 ++++----- .../java/tconstruct/world/TinkerWorld.java | 2 +- .../tconstruct/world/TinkerWorldEvents.java | 158 +++++++------ 8 files changed, 378 insertions(+), 290 deletions(-) diff --git a/src/main/java/tconstruct/armor/TinkerArmor.java b/src/main/java/tconstruct/armor/TinkerArmor.java index 31511fe4..9c193825 100644 --- a/src/main/java/tconstruct/armor/TinkerArmor.java +++ b/src/main/java/tconstruct/armor/TinkerArmor.java @@ -9,7 +9,6 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemArmor.ArmorMaterial; import net.minecraft.item.ItemStack; import net.minecraft.util.StatCollector; -import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.util.EnumHelper; import net.minecraftforge.oredict.ShapedOreRecipe; @@ -91,7 +90,7 @@ public class TinkerArmor { public void preInit(FMLPreInitializationEvent event) { proxy.preInit(); - MinecraftForge.EVENT_BUS.register(new TinkerArmorEvents.EventHandler()); + new TinkerArmorEvents().registerEvents(); FMLCommonHandler.instance().bus().register(new ArmorAbilities()); TinkerArmor.dryingRack = new DryingRack().setBlockName("Armor.DryingRack"); diff --git a/src/main/java/tconstruct/armor/TinkerArmorEvents.java b/src/main/java/tconstruct/armor/TinkerArmorEvents.java index 5dec3d64..70a079a4 100644 --- a/src/main/java/tconstruct/armor/TinkerArmorEvents.java +++ b/src/main/java/tconstruct/armor/TinkerArmorEvents.java @@ -13,11 +13,13 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.EntityJoinWorldEvent; import net.minecraftforge.event.entity.living.LivingAttackEvent; import net.minecraftforge.event.entity.living.LivingDropsEvent; import net.minecraftforge.event.entity.living.LivingEvent.LivingJumpEvent; import net.minecraftforge.event.entity.living.LivingFallEvent; +import net.minecraftforge.event.entity.player.PlayerEvent; import com.kuba6000.mobsinfo.api.IMobExtraInfoProvider; import com.kuba6000.mobsinfo.api.MobDrop; @@ -35,6 +37,49 @@ import tconstruct.util.network.ArmourGuiSyncPacket; @Optional.Interface(iface = "com.kuba6000.mobsinfo.api.IMobExtraInfoProvider", modid = "mobsinfo") public class TinkerArmorEvents implements IMobExtraInfoProvider { + public void registerEvents() { + MinecraftForge.EVENT_BUS.register(new EventHandler()); + } + + public void onLivingDrop(LivingDropsEvent event) { + // ANY CHANGE MADE IN HERE MUST ALSO BE MADE IN provideDropsInformation! + if (event.entityLiving == null) return; + + if (!event.entityLiving.worldObj.getGameRules().getGameRuleBooleanValue("doMobLoot")) return; + + if (TConstruct.random.nextInt(200) == 0 && event.entityLiving instanceof IMob + && event.source.damageType.equals("player")) { + ItemStack dropStack = new ItemStack(TinkerArmor.heartCanister, 1, 1); + EntityItem entityitem = new EntityItem( + event.entityLiving.worldObj, + event.entityLiving.posX, + event.entityLiving.posY, + event.entityLiving.posZ, + dropStack); + entityitem.delayBeforeCanPickup = 10; + event.drops.add(entityitem); + } + + if (event.entityLiving instanceof IBossDisplayData) { + String entityName = event.entityLiving.getClass().getSimpleName().toLowerCase(); + for (String name : PHConstruct.heartDropBlacklist) + if (name.toLowerCase(Locale.US).equals(entityName)) return; + + int count = event.entityLiving instanceof EntityDragon ? 5 : 1; + for (int i = 0; i < count; i++) { + ItemStack dropStack = new ItemStack(TinkerArmor.heartCanister, 1, 3); + EntityItem entityitem = new EntityItem( + event.entityLiving.worldObj, + event.entityLiving.posX, + event.entityLiving.posY, + event.entityLiving.posZ, + dropStack); + entityitem.delayBeforeCanPickup = 10; + event.drops.add(entityitem); + } + } + } + @Optional.Method(modid = "mobsinfo") @Override public void provideExtraDropsInformation(@Nonnull String entityString, @Nonnull ArrayList drops, @@ -68,120 +113,105 @@ public class TinkerArmorEvents implements IMobExtraInfoProvider { } } - public static class EventHandler { + /* Abilities */ + public void armorMineSpeed(PlayerEvent.BreakSpeed event) { + if (event.entityPlayer == null) return; + + ItemStack glove = TPlayerStats.get(event.entityPlayer).armor.getStackInSlot(1); + if (event.entityPlayer.worldObj.isRemote) { // todo: sync extended inventory with clients so this stuff and + // rendering is done + // properly... + if (ArmorProxyClient.armorExtended != null) glove = ArmorProxyClient.armorExtended.getStackInSlot(1); + else glove = null; + } + if (glove == null || !glove.hasTagCompound()) return; + + // ok, we got a glove. bonus mining speeeeed + NBTTagCompound tags = glove.getTagCompound().getCompoundTag(TinkerArmor.travelGlove.getBaseTagName()); + float mineSpeed = tags.getInteger("MiningSpeed"); + + float modifier = 1f + mineSpeed / 1000f; + float base = mineSpeed / 250f; + event.newSpeed = (event.originalSpeed + base) * modifier; + } + + public void jumpHeight(LivingJumpEvent event) { + ItemStack stack = event.entityLiving.getEquipmentInSlot(2); + if (stack != null && stack.getItem() instanceof TravelWings) { + event.entityLiving.motionY += 0.2; + } + } + + public void slimefall(LivingFallEvent event) { + ItemStack boots = event.entityLiving.getEquipmentInSlot(1); + if (boots != null && boots.getItem() instanceof IModifyable) { + NBTTagCompound tag = boots.getTagCompound() + .getCompoundTag(((IModifyable) boots.getItem()).getBaseTagName()); + int sole = tag.getInteger("Slimy Soles"); + if (sole > 0) { + event.distance /= (1 + sole); + event.entityLiving.fallDistance /= (1 + sole); + } + } + } + + public void perfectDodge(LivingAttackEvent event) { + if (!event.source.isProjectile()) return; + + // perfect dodge? + if (!(event.entityLiving instanceof EntityPlayer)) return; + + EntityPlayer player = (EntityPlayer) event.entityLiving; + ItemStack chest = player.getCurrentArmor(2); + if (chest == null || !(chest.getItem() instanceof IModifyable) || !chest.hasTagCompound()) return; + + NBTTagCompound tags = chest.getTagCompound().getCompoundTag(((IModifyable) chest.getItem()).getBaseTagName()); + int dodge = tags.getInteger("Perfect Dodge"); + if (dodge > TConstruct.random.nextInt(10)) event.setCanceled(true); + } + + public void joinWorld(EntityJoinWorldEvent event) { + if (event.entity instanceof EntityPlayerMP) { + EntityPlayerMP player = (EntityPlayerMP) event.entity; + TPlayerStats stats = TPlayerStats.get(player); + NBTTagCompound tag = new NBTTagCompound(); + stats.saveNBTData(tag); + ArmourGuiSyncPacket syncPacket = new ArmourGuiSyncPacket(tag); + TConstruct.packetPipeline.sendTo(syncPacket, player); + } + } + + public class EventHandler { @SubscribeEvent - public void onLivingDrop(LivingDropsEvent event) { - // ANY CHANGE MADE IN HERE MUST ALSO BE MADE IN provideDropsInformation! - if (event.entityLiving == null) return; - - if (!event.entityLiving.worldObj.getGameRules().getGameRuleBooleanValue("doMobLoot")) return; - - if (TConstruct.random.nextInt(200) == 0 && event.entityLiving instanceof IMob - && event.source.damageType.equals("player")) { - ItemStack dropStack = new ItemStack(TinkerArmor.heartCanister, 1, 1); - EntityItem entityitem = new EntityItem( - event.entityLiving.worldObj, - event.entityLiving.posX, - event.entityLiving.posY, - event.entityLiving.posZ, - dropStack); - entityitem.delayBeforeCanPickup = 10; - event.drops.add(entityitem); - } - - if (event.entityLiving instanceof IBossDisplayData) { - String entityName = event.entityLiving.getClass().getSimpleName().toLowerCase(); - for (String name : PHConstruct.heartDropBlacklist) - if (name.toLowerCase(Locale.US).equals(entityName)) return; - - int count = event.entityLiving instanceof EntityDragon ? 5 : 1; - for (int i = 0; i < count; i++) { - ItemStack dropStack = new ItemStack(TinkerArmor.heartCanister, 1, 3); - EntityItem entityitem = new EntityItem( - event.entityLiving.worldObj, - event.entityLiving.posX, - event.entityLiving.posY, - event.entityLiving.posZ, - dropStack); - entityitem.delayBeforeCanPickup = 10; - event.drops.add(entityitem); - } - } + public void onLivingDropWrapper(LivingDropsEvent event) { + TinkerArmorEvents.this.onLivingDrop(event); } /* Abilities */ @SubscribeEvent - public void armorMineSpeed(net.minecraftforge.event.entity.player.PlayerEvent.BreakSpeed event) { - if (event.entityPlayer == null) return; - - ItemStack glove = TPlayerStats.get(event.entityPlayer).armor.getStackInSlot(1); - if (event.entityPlayer.worldObj.isRemote) { // todo: sync extended inventory with clients so this stuff and - // rendering is done - // properly... - if (ArmorProxyClient.armorExtended != null) glove = ArmorProxyClient.armorExtended.getStackInSlot(1); - else glove = null; - } - if (glove == null || !glove.hasTagCompound()) return; - - // ok, we got a glove. bonus mining speeeeed - NBTTagCompound tags = glove.getTagCompound().getCompoundTag(TinkerArmor.travelGlove.getBaseTagName()); - float mineSpeed = tags.getInteger("MiningSpeed"); - - float modifier = 1f + mineSpeed / 1000f; - float base = mineSpeed / 250f; - event.newSpeed = (event.originalSpeed + base) * modifier; + public void armorMineSpeedWrapper(PlayerEvent.BreakSpeed event) { + TinkerArmorEvents.this.armorMineSpeed(event); } @SubscribeEvent - public void jumpHeight(LivingJumpEvent event) { - ItemStack stack = event.entityLiving.getEquipmentInSlot(2); - if (stack != null && stack.getItem() instanceof TravelWings) { - event.entityLiving.motionY += 0.2; - } + public void jumpHeightWrapper(LivingJumpEvent event) { + TinkerArmorEvents.this.jumpHeight(event); } @SubscribeEvent - public void slimefall(LivingFallEvent event) { - ItemStack boots = event.entityLiving.getEquipmentInSlot(1); - if (boots != null && boots.getItem() instanceof IModifyable) { - NBTTagCompound tag = boots.getTagCompound() - .getCompoundTag(((IModifyable) boots.getItem()).getBaseTagName()); - int sole = tag.getInteger("Slimy Soles"); - if (sole > 0) { - event.distance /= (1 + sole); - event.entityLiving.fallDistance /= (1 + sole); - } - } + public void slimefallWrapper(LivingFallEvent event) { + TinkerArmorEvents.this.slimefall(event); } @SubscribeEvent - public void perfectDodge(LivingAttackEvent event) { - if (!event.source.isProjectile()) return; - - // perfect dodge? - if (!(event.entityLiving instanceof EntityPlayer)) return; - - EntityPlayer player = (EntityPlayer) event.entityLiving; - ItemStack chest = player.getCurrentArmor(2); - if (chest == null || !(chest.getItem() instanceof IModifyable) || !chest.hasTagCompound()) return; - - NBTTagCompound tags = chest.getTagCompound() - .getCompoundTag(((IModifyable) chest.getItem()).getBaseTagName()); - int dodge = tags.getInteger("Perfect Dodge"); - if (dodge > TConstruct.random.nextInt(10)) event.setCanceled(true); + public void perfectDodgeWrapper(LivingAttackEvent event) { + TinkerArmorEvents.this.perfectDodge(event); } @SubscribeEvent - public void joinWorld(EntityJoinWorldEvent event) { - if (event.entity instanceof EntityPlayerMP) { - EntityPlayerMP player = (EntityPlayerMP) event.entity; - TPlayerStats stats = TPlayerStats.get(player); - NBTTagCompound tag = new NBTTagCompound(); - stats.saveNBTData(tag); - ArmourGuiSyncPacket syncPacket = new ArmourGuiSyncPacket(tag); - TConstruct.packetPipeline.sendTo(syncPacket, player); - } + public void joinWorldWrapper(EntityJoinWorldEvent event) { + TinkerArmorEvents.this.joinWorld(event); } } } diff --git a/src/main/java/tconstruct/armor/player/TPlayerHandler.java b/src/main/java/tconstruct/armor/player/TPlayerHandler.java index 48631dca..d6524506 100644 --- a/src/main/java/tconstruct/armor/player/TPlayerHandler.java +++ b/src/main/java/tconstruct/armor/player/TPlayerHandler.java @@ -49,6 +49,20 @@ public class TPlayerHandler { MinecraftForge.EVENT_BUS.register(handler); } + public void PlayerLoggedInEvent(PlayerLoggedInEvent event) { + onPlayerLogin(event.player); + } + + public void onPlayerRespawn(PlayerRespawnEvent event) { + onPlayerRespawn(event.player); + } + + public void onEntityConstructing(EntityEvent.EntityConstructing event) { + if (event.entity instanceof EntityPlayer && TPlayerStats.get((EntityPlayer) event.entity) == null) { + TPlayerStats.register((EntityPlayer) event.entity); + } + } + public void onPlayerLogin(EntityPlayer player) { // Lookup player TPlayerStats stats = TPlayerStats.get(player); @@ -200,6 +214,49 @@ public class TPlayerHandler { } } + public void livingFall(LivingFallEvent evt) // Only for negating fall damage + { + if (evt.entityLiving instanceof EntityPlayer) { + evt.distance -= 1; + } + } + + public void playerDeath(LivingDeathEvent event) { + if (!(event.entity instanceof EntityPlayer)) return; + + if (!event.entity.worldObj.isRemote) { + TPlayerStats properties = (TPlayerStats) event.entity.getExtendedProperties(TPlayerStats.PROP_NAME); + properties.hunger = ((EntityPlayer) event.entity).getFoodStats().getFoodLevel(); + playerStats.put(event.entity.getPersistentID(), properties); + } + } + + public void playerDrops(PlayerDropsEvent evt) { + // After playerDeath event. Modifying saved data. + TPlayerStats stats = playerStats.get(evt.entityPlayer.getPersistentID()); + + stats.level = evt.entityPlayer.experienceLevel / 2; + // stats.health = 20; + int hunger = evt.entityPlayer.getFoodStats().getFoodLevel(); + if (hunger < 6) stats.hunger = 6; + else stats.hunger = evt.entityPlayer.getFoodStats().getFoodLevel(); + + if (evt.entityPlayer.capturedDrops != evt.drops) { + evt.entityPlayer.capturedDrops.clear(); + } + + evt.entityPlayer.captureDrops = true; + stats.armor.dropItems(); + stats.knapsack.dropItems(); + evt.entityPlayer.captureDrops = false; + + if (evt.entityPlayer.capturedDrops != evt.drops) { + evt.drops.addAll(evt.entityPlayer.capturedDrops); + } + + playerStats.put(evt.entityPlayer.getPersistentID(), stats); + } + /* Modify Player */ public void updateSize(String user, float offset) { /* @@ -268,66 +325,34 @@ public class TPlayerHandler { public class EventHandler { @SubscribeEvent - public void PlayerLoggedInEvent(PlayerLoggedInEvent event) { - onPlayerLogin(event.player); + public void PlayerLoggedInEventWrapper(PlayerLoggedInEvent event) { + TPlayerHandler.this.PlayerLoggedInEvent(event); } @SubscribeEvent - public void onPlayerRespawn(PlayerRespawnEvent event) { - TPlayerHandler.this.onPlayerRespawn(event.player); + public void onPlayerRespawnWrapper(PlayerRespawnEvent event) { + TPlayerHandler.this.onPlayerRespawn(event); } @SubscribeEvent - public void onEntityConstructing(EntityEvent.EntityConstructing event) { - if (event.entity instanceof EntityPlayer && TPlayerStats.get((EntityPlayer) event.entity) == null) { - TPlayerStats.register((EntityPlayer) event.entity); - } + public void onEntityConstructingWrapper(EntityEvent.EntityConstructing event) { + TPlayerHandler.this.onEntityConstructing(event); } @SubscribeEvent - public void livingFall(LivingFallEvent evt) // Only for negating fall damage + public void livingFallWrapper(LivingFallEvent evt) // Only for negating fall damage { - if (evt.entityLiving instanceof EntityPlayer) { - evt.distance -= 1; - } + TPlayerHandler.this.livingFall(evt); } @SubscribeEvent - public void playerDeath(LivingDeathEvent event) { - if (!(event.entity instanceof EntityPlayer)) return; - - if (!event.entity.worldObj.isRemote) { - TPlayerStats properties = (TPlayerStats) event.entity.getExtendedProperties(TPlayerStats.PROP_NAME); - properties.hunger = ((EntityPlayer) event.entity).getFoodStats().getFoodLevel(); - playerStats.put(event.entity.getPersistentID(), properties); - } + public void playerDeathWrapper(LivingDeathEvent event) { + TPlayerHandler.this.playerDeath(event); } @SubscribeEvent - public void playerDrops(PlayerDropsEvent evt) { - // After playerDeath event. Modifying saved data. - TPlayerStats stats = playerStats.get(evt.entityPlayer.getPersistentID()); - - stats.level = evt.entityPlayer.experienceLevel / 2; - // stats.health = 20; - int hunger = evt.entityPlayer.getFoodStats().getFoodLevel(); - if (hunger < 6) stats.hunger = 6; - else stats.hunger = evt.entityPlayer.getFoodStats().getFoodLevel(); - - if (evt.entityPlayer.capturedDrops != evt.drops) { - evt.entityPlayer.capturedDrops.clear(); - } - - evt.entityPlayer.captureDrops = true; - stats.armor.dropItems(); - stats.knapsack.dropItems(); - evt.entityPlayer.captureDrops = false; - - if (evt.entityPlayer.capturedDrops != evt.drops) { - evt.drops.addAll(evt.entityPlayer.capturedDrops); - } - - playerStats.put(evt.entityPlayer.getPersistentID(), stats); + public void playerDropsWrapper(PlayerDropsEvent evt) { + TPlayerHandler.this.playerDrops(evt); } } } diff --git a/src/main/java/tconstruct/client/ArmorControls.java b/src/main/java/tconstruct/client/ArmorControls.java index c337e3ee..9cf34245 100644 --- a/src/main/java/tconstruct/client/ArmorControls.java +++ b/src/main/java/tconstruct/client/ArmorControls.java @@ -84,6 +84,19 @@ public class ArmorControls { invKey = mc.gameSettings.keyBindInventory; } + public void keyEvent(KeyInputEvent event) { + if (!isNotEnoughKeysLoaded) { + checkAndPerformKeyActions(null, false); + } + } + + @Optional.Method(modid = "notenoughkeys") + public void keyEventSpecial(KeyBindingPressedEvent event) { + if (event.keyBinding != null && event.isKeyBindingPressed) { + checkAndPerformKeyActions(event.keyBinding, true); + } + } + private void checkAndPerformKeyActions(KeyBinding keyBinding, boolean inputFromNotEnoughKeys) { if (inputFromNotEnoughKeys ? keyBinding == armorKey : armorKey.isPressed()) { openArmorGui(); @@ -202,18 +215,14 @@ public class ArmorControls { public class EventHandler { @SubscribeEvent - public void keyEvent(KeyInputEvent event) { - if (!isNotEnoughKeysLoaded) { - checkAndPerformKeyActions(null, false); - } + public void keyEventWrapper(KeyInputEvent event) { + ArmorControls.this.keyEvent(event); } @Optional.Method(modid = "notenoughkeys") @SubscribeEvent - public void keyEventSpecial(KeyBindingPressedEvent event) { - if (event.keyBinding != null && event.isKeyBindingPressed) { - checkAndPerformKeyActions(event.keyBinding, true); - } + public void keyEventSpecialWrapper(KeyBindingPressedEvent event) { + ArmorControls.this.keyEventSpecial(event); } } } diff --git a/src/main/java/tconstruct/client/tabs/TabRegistry.java b/src/main/java/tconstruct/client/tabs/TabRegistry.java index 90c05f41..5d7b5e6d 100644 --- a/src/main/java/tconstruct/client/tabs/TabRegistry.java +++ b/src/main/java/tconstruct/client/tabs/TabRegistry.java @@ -32,6 +32,20 @@ public class TabRegistry { return tabList; } + // Client method + public void guiPostInit(GuiScreenEvent.InitGuiEvent.Post event) { + if ((event.gui instanceof GuiInventory)) { + int xSize = 176; + int ySize = 166; + int guiLeft = (event.gui.width - xSize) / 2; + int guiTop = (event.gui.height - ySize) / 2; + guiLeft += getPotionOffset(); + + updateTabValues(guiLeft, guiTop, InventoryTabVanilla.class); + addTabsToList(event.gui.buttonList); + } + } + private static final Minecraft mc = FMLClientHandler.instance().getClient(); public static void openInventoryGui() { @@ -80,20 +94,6 @@ public class TabRegistry { return 0; } - // Client method - public void guiPostInit(GuiScreenEvent.InitGuiEvent.Post event) { - if ((event.gui instanceof GuiInventory)) { - int xSize = 176; - int ySize = 166; - int guiLeft = (event.gui.width - xSize) / 2; - int guiTop = (event.gui.height - ySize) / 2; - guiLeft += getPotionOffset(); - - updateTabValues(guiLeft, guiTop, InventoryTabVanilla.class); - addTabsToList(event.gui.buttonList); - } - } - public class EventHandler { @SideOnly(Side.CLIENT) diff --git a/src/main/java/tconstruct/gadgets/item/ItemSlimeBoots.java b/src/main/java/tconstruct/gadgets/item/ItemSlimeBoots.java index 9c2e4b65..f692dbd6 100644 --- a/src/main/java/tconstruct/gadgets/item/ItemSlimeBoots.java +++ b/src/main/java/tconstruct/gadgets/item/ItemSlimeBoots.java @@ -72,6 +72,63 @@ public class ItemSlimeBoots extends ItemArmor implements ISpecialArmor { return itemStackIn; } + /** Called when an entity lands to handle the event */ + // RUBBERY BOUNCY BOUNCERY WOOOOO + public void onFall(LivingFallEvent event) { + final EntityLivingBase living = event.entityLiving; + // using fall distance as the event distance could be reduced by jump boost + if (living == null || living.fallDistance <= 2f) { + return; + } + // can the entity bounce? + if (!SlimeBounceHandler.hasSlimeBoots(living)) { + return; + } + + // reduced fall damage when crouching + if (living.isSneaking()) { + event.distance = 1; + return; + } + + // thing is wearing slime boots. let's get bouncyyyyy + event.setCanceled(true); + // skip further client processing on players + if (living.worldObj.isRemote) { + living.playSound("mob.slime.small", 1f, 1f); + SlimeBounceHandler.addBounceHandler(living); + return; + } + + // server players behave differently than non-server players, they have no + // velocity during the event, so we need to reverse engineer it + Vec3 motion = SlimeBounceHandler.getMotion(living); + if (living instanceof EntityPlayerMP) { + // velocity is lost on server players, but we don't have to defer the bounce + double gravity = 0.2353455252; + double time = Math.sqrt(living.fallDistance / gravity); + double velocity = gravity * time / 2; + living.motionX = motion.xCoord / 0.95f; + living.motionY = velocity; + living.motionZ = motion.zCoord / 0.95f; + living.velocityChanged = true; + // preserve momentum + SlimeBounceHandler.addBounceHandler(living); + } else { + // for non-players, need to defer the bounce + // only slow down half as much when bouncing + living.motionX = motion.xCoord / 0.95f; + living.motionY = motion.yCoord * -0.9; + living.motionZ = motion.zCoord / 0.95f; + SlimeBounceHandler.addBounceHandler(living, SlimeBounceHandler.getMotion(living).yCoord); + } + // update airborn status + living.isAirBorne = true; + living.onGround = false; + event.distance = 0f; + living.playSound("mob.slime.small", 1f, 1f); + } + @Override public int getArmorDisplay(EntityPlayer player, ItemStack armor, int slot) { return 0; @@ -175,65 +232,15 @@ public class ItemSlimeBoots extends ItemArmor implements ISpecialArmor { return new FancyEntityItem(world, location, itemstack); } - public static class EventHandler { + public class EventHandler { - /** Called when an entity lands to handle the event */ + /** + * Called when an entity lands to handle the event + */ @SubscribeEvent // RUBBERY BOUNCY BOUNCERY WOOOOO public void onFall(LivingFallEvent event) { - final EntityLivingBase living = event.entityLiving; - // using fall distance as the event distance could be reduced by jump boost - if (living == null || living.fallDistance <= 2f) { - return; - } - // can the entity bounce? - if (!SlimeBounceHandler.hasSlimeBoots(living)) { - return; - } - - // reduced fall damage when crouching - if (living.isSneaking()) { - event.distance = 1; - return; - } - - // thing is wearing slime boots. let's get bouncyyyyy - event.setCanceled(true); - // skip further client processing on players - if (living.worldObj.isRemote) { - living.playSound("mob.slime.small", 1f, 1f); - SlimeBounceHandler.addBounceHandler(living); - return; - } - - // server players behave differently than non-server players, they have no - // velocity during the event, so we need to reverse engineer it - Vec3 motion = SlimeBounceHandler.getMotion(living); - if (living instanceof EntityPlayerMP) { - // velocity is lost on server players, but we don't have to defer the bounce - double gravity = 0.2353455252; - double time = Math.sqrt(living.fallDistance / gravity); - double velocity = gravity * time / 2; - living.motionX = motion.xCoord / 0.95f; - living.motionY = velocity; - living.motionZ = motion.zCoord / 0.95f; - living.velocityChanged = true; - // preserve momentum - SlimeBounceHandler.addBounceHandler(living); - } else { - // for non-players, need to defer the bounce - // only slow down half as much when bouncing - living.motionX = motion.xCoord / 0.95f; - living.motionY = motion.yCoord * -0.9; - living.motionZ = motion.zCoord / 0.95f; - SlimeBounceHandler.addBounceHandler(living, SlimeBounceHandler.getMotion(living).yCoord); - } - // update airborn status - living.isAirBorne = true; - living.onGround = false; - event.distance = 0f; - living.playSound("mob.slime.small", 1f, 1f); + ItemSlimeBoots.this.onFall(event); } - } } diff --git a/src/main/java/tconstruct/world/TinkerWorld.java b/src/main/java/tconstruct/world/TinkerWorld.java index 9def5603..61c85fa8 100644 --- a/src/main/java/tconstruct/world/TinkerWorld.java +++ b/src/main/java/tconstruct/world/TinkerWorld.java @@ -149,7 +149,7 @@ public class TinkerWorld { @Handler public void preInit(FMLPreInitializationEvent event) { - MinecraftForge.EVENT_BUS.register(new TinkerWorldEvents.EventHandler()); + new TinkerWorldEvents().registerEvents(); // Blocks TinkerWorld.meatBlock = new MeatBlock().setBlockName("tconstruct.meatblock"); diff --git a/src/main/java/tconstruct/world/TinkerWorldEvents.java b/src/main/java/tconstruct/world/TinkerWorldEvents.java index a9d1d54b..51d2a359 100644 --- a/src/main/java/tconstruct/world/TinkerWorldEvents.java +++ b/src/main/java/tconstruct/world/TinkerWorldEvents.java @@ -19,6 +19,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.world.World; +import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.living.LivingDropsEvent; import net.minecraftforge.event.entity.living.LivingHurtEvent; import net.minecraftforge.event.entity.living.LivingSpawnEvent; @@ -40,6 +41,28 @@ import tconstruct.util.config.PHConstruct; @Optional.Interface(iface = "com.kuba6000.mobsinfo.api.IMobExtraInfoProvider", modid = "mobsinfo") public class TinkerWorldEvents implements IMobExtraInfoProvider { + public void registerEvents() { + MinecraftForge.EVENT_BUS.register(new EventHandler()); + } + + public void onLivingSpawn(LivingSpawnEvent.SpecialSpawn event) { + EntityLivingBase living = event.entityLiving; + if (living.getClass() == EntitySpider.class && TConstruct.random.nextInt(100) == 0) { + EntityCreeper creeper = new EntityCreeper(living.worldObj); + spawnEntityLiving(living.posX, living.posY + 1, living.posZ, creeper, living.worldObj); + if (living.riddenByEntity != null) creeper.mountEntity(living.riddenByEntity); + else creeper.mountEntity(living); + + EntityXPOrb orb = new EntityXPOrb( + living.worldObj, + living.posX, + living.posY, + living.posZ, + TConstruct.random.nextInt(20) + 20); + orb.mountEntity(creeper); + } + } + public static void spawnEntityLiving(double x, double y, double z, EntityLiving entity, World world) { if (!world.isRemote) { entity.setPosition(x, y, z); @@ -48,6 +71,66 @@ public class TinkerWorldEvents implements IMobExtraInfoProvider { } } + /* Bonemeal */ + public void bonemealEvent(BonemealEvent event) { + if (!event.world.isRemote) { + if (event.block == TinkerWorld.slimeSapling) { + if (TinkerWorld.slimeSapling + .boneFertilize(event.world, event.x, event.y, event.z, event.world.rand, event.entityPlayer)) + event.setResult(Event.Result.ALLOW); + else event.setCanceled(true); + } + } + } + + /* Damage */ + public void onHurt(LivingHurtEvent event) { + EntityLivingBase reciever = event.entityLiving; + if (reciever instanceof EntityPlayer) { + EntityPlayer player = (EntityPlayer) event.entityLiving; + // Cutlass + ItemStack stack = player.getCurrentEquippedItem(); + if (stack != null && player.isUsingItem()) { + Item item = stack.getItem(); + if (item == TinkerTools.cutlass) { + player.addPotionEffect(new PotionEffect(Potion.moveSpeed.id, 3 * 20, 1)); + } else if (item == TinkerTools.battlesign) { + event.ammount *= 1.5; // Puts battlesign blocking at 3/4 instead of 1/2 + } + } + } else if (reciever instanceof EntityCreeper) { + Entity attacker = event.source.getEntity(); + if (attacker instanceof EntityLivingBase) { + Entity target = ((EntityCreeper) reciever).getAttackTarget(); + if (target != null) { + float d1 = reciever.getDistanceToEntity(((EntityCreeper) reciever).getAttackTarget()); + float d2 = reciever.getDistanceToEntity(attacker); + if (d2 < d1) { + ((EntityCreeper) event.entityLiving) + .setAttackTarget((EntityLivingBase) event.source.getEntity()); + } + } + } + } + } + + public void onLivingDrop(LivingDropsEvent event) { + // ANY CHANGE MADE IN HERE MUST ALSO BE MADE IN provideExtraDropsInformation! + if (event.entityLiving == null) return; + + if (event.entityLiving.getClass() == EntityGhast.class) { + if (PHConstruct.uhcGhastDrops) { + for (EntityItem o : event.drops) { + if (o.getEntityItem().getItem() == Items.ghast_tear) { + o.setEntityItemStack(new ItemStack(Items.gold_ingot, 1)); + } + } + } else { + ItemHelper.addDrops(event, new ItemStack(Items.ghast_tear, 1)); + } + } + } + @Optional.Method(modid = "mobsinfo") @Override public void provideExtraDropsInformation(@Nonnull String entityString, @Nonnull ArrayList drops, @@ -71,93 +154,28 @@ public class TinkerWorldEvents implements IMobExtraInfoProvider { } } - public static class EventHandler { + public class EventHandler { @SubscribeEvent public void onLivingSpawn(LivingSpawnEvent.SpecialSpawn event) { - EntityLivingBase living = event.entityLiving; - if (living.getClass() == EntitySpider.class && TConstruct.random.nextInt(100) == 0) { - EntityCreeper creeper = new EntityCreeper(living.worldObj); - spawnEntityLiving(living.posX, living.posY + 1, living.posZ, creeper, living.worldObj); - if (living.riddenByEntity != null) creeper.mountEntity(living.riddenByEntity); - else creeper.mountEntity(living); - - EntityXPOrb orb = new EntityXPOrb( - living.worldObj, - living.posX, - living.posY, - living.posZ, - TConstruct.random.nextInt(20) + 20); - orb.mountEntity(creeper); - } + TinkerWorldEvents.this.onLivingSpawn(event); } /* Bonemeal */ @SubscribeEvent public void bonemealEvent(BonemealEvent event) { - if (!event.world.isRemote) { - if (event.block == TinkerWorld.slimeSapling) { - if (TinkerWorld.slimeSapling.boneFertilize( - event.world, - event.x, - event.y, - event.z, - event.world.rand, - event.entityPlayer)) - event.setResult(Event.Result.ALLOW); - else event.setCanceled(true); - } - } + TinkerWorldEvents.this.bonemealEvent(event); } /* Damage */ @SubscribeEvent public void onHurt(LivingHurtEvent event) { - EntityLivingBase reciever = event.entityLiving; - if (reciever instanceof EntityPlayer) { - EntityPlayer player = (EntityPlayer) event.entityLiving; - // Cutlass - ItemStack stack = player.getCurrentEquippedItem(); - if (stack != null && player.isUsingItem()) { - Item item = stack.getItem(); - if (item == TinkerTools.cutlass) { - player.addPotionEffect(new PotionEffect(Potion.moveSpeed.id, 3 * 20, 1)); - } else if (item == TinkerTools.battlesign) { - event.ammount *= 1.5; // Puts battlesign blocking at 3/4 instead of 1/2 - } - } - } else if (reciever instanceof EntityCreeper) { - Entity attacker = event.source.getEntity(); - if (attacker instanceof EntityLivingBase) { - Entity target = ((EntityCreeper) reciever).getAttackTarget(); - if (target != null) { - float d1 = reciever.getDistanceToEntity(((EntityCreeper) reciever).getAttackTarget()); - float d2 = reciever.getDistanceToEntity(attacker); - if (d2 < d1) { - ((EntityCreeper) event.entityLiving) - .setAttackTarget((EntityLivingBase) event.source.getEntity()); - } - } - } - } + TinkerWorldEvents.this.onHurt(event); } @SubscribeEvent public void onLivingDrop(LivingDropsEvent event) { - // ANY CHANGE MADE IN HERE MUST ALSO BE MADE IN provideExtraDropsInformation! - if (event.entityLiving == null) return; - - if (event.entityLiving.getClass() == EntityGhast.class) { - if (PHConstruct.uhcGhastDrops) { - for (EntityItem o : event.drops) { - if (o.getEntityItem().getItem() == Items.ghast_tear) { - o.setEntityItemStack(new ItemStack(Items.gold_ingot, 1)); - } - } - } else { - ItemHelper.addDrops(event, new ItemStack(Items.ghast_tear, 1)); - } - } + TinkerWorldEvents.this.onLivingDrop(event); } } }