diff --git a/src/main/java/tconstruct/armor/PlayerAbilityHelper.java b/src/main/java/tconstruct/armor/PlayerAbilityHelper.java index 61251f77..d8b21049 100644 --- a/src/main/java/tconstruct/armor/PlayerAbilityHelper.java +++ b/src/main/java/tconstruct/armor/PlayerAbilityHelper.java @@ -9,8 +9,10 @@ import net.minecraft.nbt.NBTTagList; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; +import cpw.mods.fml.common.Optional; import tconstruct.armor.player.ArmorExtended; import tconstruct.armor.player.TPlayerStats; +import tconstruct.compat.BaublesHelper; import tconstruct.compat.LoadedMods; import tconstruct.util.config.PHConstruct; @@ -71,16 +73,10 @@ public class PlayerAbilityHelper { belt.getTagCompound().setTag("Inventory", slots); } + @Optional.Method(modid = "Baubles") private static ItemStack getBaublesBelt(EntityPlayer player) { - baubles.common.container.InventoryBaubles baubleInventory = baubles.common.lib.PlayerHandler - .getPlayerBaubles(player); - if (baubleInventory == null || baubleInventory.stackList == null) return null; - for (ItemStack bauble : baubleInventory.stackList) { - if (bauble != null && bauble.getItem() == TinkerArmor.travelBelt) { - return bauble; - } - } - return null; + return BaublesHelper + .findFirstMatchingBauble(player, stack -> stack != null && stack.getItem() == TinkerArmor.travelBelt); } public static void setEntitySize(Entity entity, float width, float height) { diff --git a/src/main/java/tconstruct/armor/TinkerArmorEvents.java b/src/main/java/tconstruct/armor/TinkerArmorEvents.java index 2d68183a..aca3aad4 100644 --- a/src/main/java/tconstruct/armor/TinkerArmorEvents.java +++ b/src/main/java/tconstruct/armor/TinkerArmorEvents.java @@ -30,6 +30,7 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent; import tconstruct.TConstruct; import tconstruct.armor.items.TravelWings; import tconstruct.armor.player.TPlayerStats; +import tconstruct.compat.BaublesHelper; import tconstruct.compat.LoadedMods; import tconstruct.library.modifier.IModifyable; import tconstruct.util.config.PHConstruct; @@ -92,16 +93,7 @@ public class TinkerArmorEvents { else glove = null; } if (glove == null && LoadedMods.baubles) { - baubles.common.container.InventoryBaubles baubleInventory = baubles.common.lib.PlayerHandler - .getPlayerBaubles(event.entityPlayer); - if (baubleInventory != null && baubleInventory.stackList != null) { - for (ItemStack bauble : baubleInventory.stackList) { - if (bauble != null && bauble.getItem() == TinkerArmor.travelGlove) { - glove = bauble; - break; - } - } - } + glove = getBaublesTravelGlove(event.entityPlayer); } // original speed <= 0 means the block shouldn't be broken, don't increase further if (glove == null || !glove.hasTagCompound() @@ -117,6 +109,12 @@ public class TinkerArmorEvents { event.newSpeed = (event.originalSpeed + base) * modifier; } + @Optional.Method(modid = "Baubles") + private ItemStack getBaublesTravelGlove(EntityPlayer player) { + return BaublesHelper + .findFirstMatchingBauble(player, stack -> stack != null && stack.getItem() == TinkerArmor.travelGlove); + } + public void jumpHeight(LivingJumpEvent event) { ItemStack stack = event.entityLiving.getEquipmentInSlot(2); if (stack != null && stack.getItem() instanceof TravelWings) { diff --git a/src/main/java/tconstruct/armor/items/HeartCanister.java b/src/main/java/tconstruct/armor/items/HeartCanister.java index 50ec9126..de9c7acc 100644 --- a/src/main/java/tconstruct/armor/items/HeartCanister.java +++ b/src/main/java/tconstruct/armor/items/HeartCanister.java @@ -131,8 +131,7 @@ public class HeartCanister extends CraftingItem implements IHealthAccessory, IBa @Override @Optional.Method(modid = "Baubles") public BaubleType getBaubleType(ItemStack itemStack) { - int meta = itemStack.getItemDamage(); - return (meta == 2 || meta == 4 || meta == 6) ? BaubleType.UNIVERSAL : BaubleType.RING; + return BaubleType.UNIVERSAL; } @Override diff --git a/src/main/java/tconstruct/armor/player/ArmorExtended.java b/src/main/java/tconstruct/armor/player/ArmorExtended.java index 96e891cf..9956ab0f 100644 --- a/src/main/java/tconstruct/armor/player/ArmorExtended.java +++ b/src/main/java/tconstruct/armor/player/ArmorExtended.java @@ -17,6 +17,7 @@ import net.minecraft.nbt.NBTTagList; import cpw.mods.fml.common.Optional; import cpw.mods.fml.common.network.ByteBufUtils; import io.netty.buffer.ByteBuf; +import tconstruct.compat.BaublesHelper; import tconstruct.compat.LoadedMods; import tconstruct.library.accessory.IHealthAccessory; import tconstruct.util.config.PHConstruct; @@ -145,12 +146,11 @@ public class ArmorExtended implements IInventory { @Optional.Method(modid = "Baubles") private int getBaublesHealthBoost(EntityPlayer player) { int bonusHP = 0; - baubles.common.container.InventoryBaubles baubleInventory = baubles.common.lib.PlayerHandler - .getPlayerBaubles(player); - if (baubleInventory == null || baubleInventory.stackList == null) { + ItemStack[] baubleStacks = BaublesHelper.getBaubleStacks(player); + if (baubleStacks == null) { return 0; } - for (ItemStack stack : baubleInventory.stackList) { + for (ItemStack stack : baubleStacks) { if (stack != null && stack.getItem() instanceof IHealthAccessory) { bonusHP += ((IHealthAccessory) stack.getItem()).getHealthBoost(stack); } diff --git a/src/main/java/tconstruct/armor/player/TPlayerHandler.java b/src/main/java/tconstruct/armor/player/TPlayerHandler.java index c33d3c98..0414421f 100644 --- a/src/main/java/tconstruct/armor/player/TPlayerHandler.java +++ b/src/main/java/tconstruct/armor/player/TPlayerHandler.java @@ -26,6 +26,7 @@ import net.minecraftforge.event.entity.player.PlayerDropsEvent; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.Loader; +import cpw.mods.fml.common.Optional; import cpw.mods.fml.common.eventhandler.EventPriority; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent; @@ -33,6 +34,7 @@ import cpw.mods.fml.common.gameevent.PlayerEvent.PlayerRespawnEvent; import cpw.mods.fml.relauncher.Side; import mantle.player.PlayerUtils; import tconstruct.TConstruct; +import tconstruct.compat.BaublesHelper; import tconstruct.compat.LoadedMods; import tconstruct.library.tools.AbilityHelper; import tconstruct.tools.TinkerTools; @@ -198,34 +200,9 @@ public class TPlayerHandler { stats.armor.recalculateHealth(player, stats); } + @Optional.Method(modid = "Baubles") private ItemStack tryMoveToBaubles(EntityPlayer player, ItemStack stack) { - if (stack == null || stack.stackSize <= 0) { - return null; - } - if (!(stack.getItem() instanceof baubles.api.IBauble)) { - return stack; - } - - baubles.common.container.InventoryBaubles baubleInventory = baubles.common.lib.PlayerHandler - .getPlayerBaubles(player); - if (baubleInventory == null || baubleInventory.stackList == null) { - return stack; - } - - ItemStack remaining = stack.copy(); - for (int i = 0; i < baubleInventory.getSizeInventory() && remaining.stackSize > 0; i++) { - if (!baubleInventory.isItemValidForSlot(i, remaining)) { - continue; - } - ItemStack inSlot = baubleInventory.getStackInSlot(i); - if (inSlot == null) { - ItemStack placed = remaining.copy(); - placed.stackSize = 1; - baubleInventory.setInventorySlotContents(i, placed); - remaining.stackSize -= 1; - } - } - return remaining.stackSize > 0 ? remaining : null; + return BaublesHelper.tryMoveToBaubles(player, stack); } void spawnPigmanModifier(EntityPlayer entityplayer) { diff --git a/src/main/java/tconstruct/client/ArmorControls.java b/src/main/java/tconstruct/client/ArmorControls.java index 07ad558c..5edbbbaa 100644 --- a/src/main/java/tconstruct/client/ArmorControls.java +++ b/src/main/java/tconstruct/client/ArmorControls.java @@ -25,7 +25,7 @@ import tconstruct.armor.ArmorProxyCommon; import tconstruct.armor.PlayerAbilityHelper; import tconstruct.armor.TinkerArmor; import tconstruct.armor.items.TravelGear; -import tconstruct.compat.LoadedMods; +import tconstruct.compat.BaublesHelper; import tconstruct.util.config.PHConstruct; import tconstruct.util.network.AccessoryInventoryPacket; import tconstruct.util.network.BeltPacket; @@ -182,21 +182,11 @@ public class ArmorControls { return false; } + @Optional.Method(modid = "Baubles") private static boolean hasBaublesTravelBelt() { - if (!LoadedMods.baubles) { - return false; - } - baubles.common.container.InventoryBaubles baubleInventory = baubles.common.lib.PlayerHandler - .getPlayerBaubles(mc.thePlayer); - if (baubleInventory == null || baubleInventory.stackList == null) { - return false; - } - for (ItemStack bauble : baubleInventory.stackList) { - if (bauble != null && bauble.getItem() == TinkerArmor.travelBelt) { - return true; - } - } - return false; + return BaublesHelper.findFirstMatchingBauble( + mc.thePlayer, + stack -> stack != null && stack.getItem() == TinkerArmor.travelBelt) != null; } public void landOnGround() { diff --git a/src/main/java/tconstruct/compat/BaublesHelper.java b/src/main/java/tconstruct/compat/BaublesHelper.java new file mode 100644 index 00000000..666060db --- /dev/null +++ b/src/main/java/tconstruct/compat/BaublesHelper.java @@ -0,0 +1,82 @@ +package tconstruct.compat; + +import java.util.function.Predicate; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; + +import cpw.mods.fml.common.Optional; + +public final class BaublesHelper { + + private BaublesHelper() {} + + @Optional.Method(modid = "Baubles") + public static ItemStack findFirstMatchingBauble(EntityPlayer player, Predicate matcher) { + IInventory baubleInventory = getBaubleInventory(player); + if (baubleInventory == null) { + return null; + } + for (int i = 0; i < baubleInventory.getSizeInventory(); i++) { + ItemStack stack = baubleInventory.getStackInSlot(i); + if (matcher.test(stack)) { + return stack; + } + } + return null; + } + + @Optional.Method(modid = "Baubles") + public static ItemStack[] getBaubleStacks(EntityPlayer player) { + IInventory baubleInventory = getBaubleInventory(player); + if (baubleInventory == null) { + return null; + } + ItemStack[] stacks = new ItemStack[baubleInventory.getSizeInventory()]; + for (int i = 0; i < stacks.length; i++) { + stacks[i] = baubleInventory.getStackInSlot(i); + } + return stacks; + } + + @Optional.Method(modid = "Baubles") + public static ItemStack tryMoveToBaubles(EntityPlayer player, ItemStack stack) { + if (stack == null || stack.stackSize <= 0) { + return null; + } + if (!(stack.getItem() instanceof baubles.api.IBauble)) { + return stack; + } + + IInventory baubleInventory = getBaubleInventory(player); + if (baubleInventory == null) { + return stack; + } + + ItemStack remaining = stack.copy(); + for (int i = 0; i < baubleInventory.getSizeInventory() && remaining.stackSize > 0; i++) { + if (!baubleInventory.isItemValidForSlot(i, remaining)) { + continue; + } + ItemStack inSlot = baubleInventory.getStackInSlot(i); + if (inSlot == null) { + ItemStack placed = remaining.copy(); + placed.stackSize = 1; + baubleInventory.setInventorySlotContents(i, placed); + remaining.stackSize -= 1; + } + } + return remaining.stackSize > 0 ? remaining : null; + } + + @Optional.Method(modid = "Baubles") + private static IInventory getBaubleInventory(EntityPlayer player) { + baubles.common.container.InventoryBaubles baubleInventory = baubles.common.lib.PlayerHandler + .getPlayerBaubles(player); + if (baubleInventory == null) { + return null; + } + return baubleInventory; + } +} diff --git a/src/main/java/tconstruct/world/blocks/ConveyorBase.java b/src/main/java/tconstruct/world/blocks/ConveyorBase.java index 7c61bdf5..656e4f66 100644 --- a/src/main/java/tconstruct/world/blocks/ConveyorBase.java +++ b/src/main/java/tconstruct/world/blocks/ConveyorBase.java @@ -29,7 +29,8 @@ public class ConveyorBase extends MantleBlock { texturename = name; } - public boolean isBlockReplaceable(World world, int x, int y, int z) { + @Override + public boolean isReplaceable(IBlockAccess world, int x, int y, int z) { return false; }