More Baubles support

* Wireless Charger charges Baubles items
* Fix: No more log spam without Baubles installed
* EIO Magnet now can be worn as amulet (Magnet must be enabled first)
This commit is contained in:
HenryLoenwind committed 2015-03-19 10:48:30 +01:00
1 parent 7b1745ae5c
commit e8feb577b7
6 files changed
+92 -17

No files matched your search

@@ -2,15 +2,19 @@ package crazypants.enderio.item;
import java.util.List;
import baubles.api.BaubleType;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import cofh.api.energy.ItemEnergyContainer;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Optional.Method;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@@ -20,9 +24,12 @@ import crazypants.enderio.ModObject;
import crazypants.enderio.config.Config;
import crazypants.enderio.gui.IResourceTooltipProvider;
import crazypants.enderio.machine.power.PowerDisplayUtil;
import crazypants.enderio.tool.BaublesTool;
import crazypants.util.ItemUtil;
import cpw.mods.fml.common.Optional;
public class ItemMagnet extends ItemEnergyContainer implements IResourceTooltipProvider {
@Optional.Interface(iface="baubles.api.IBauble", modid="Baubles", striprefs=true)
public class ItemMagnet extends ItemEnergyContainer implements IResourceTooltipProvider, baubles.api.IBauble {
private static final String ACTIVE_KEY = "magnetActive";
@@ -55,10 +62,12 @@ public class ItemMagnet extends ItemEnergyContainer implements IResourceTooltipP
EnderIO.itemMagnet.extractEnergy(itemStack, Config.magnetPowerUsePerSecondRF, false);
}
static MagnetController controller = new MagnetController();
public static ItemMagnet create() {
ItemMagnet result = new ItemMagnet();
result.init();
FMLCommonHandler.instance().bus().register(new MagnetController());
FMLCommonHandler.instance().bus().register(controller);
return result;
}
@@ -164,4 +173,51 @@ public class ItemMagnet extends ItemEnergyContainer implements IResourceTooltipP
return getUnlocalizedName();
}
@Override
@Method(modid = "Baubles")
public BaubleType getBaubleType(ItemStack itemstack) {
return baubles.api.BaubleType.AMULET;
}
@Override
@Method(modid = "Baubles")
public void onWornTick(ItemStack itemstack, EntityLivingBase player) {
if (player instanceof EntityPlayer && hasPower(itemstack)) {
controller.doHoover((EntityPlayer) player);
if(!player.worldObj.isRemote && player.worldObj.getTotalWorldTime() % 20 == 0) {
ItemMagnet.drainPerSecondPower(itemstack);
IInventory baubles = BaublesTool.getInstance().getBaubles((EntityPlayer)player);
if (baubles != null) {
for (int i = 0; i < baubles.getSizeInventory(); i++) {
if (baubles.getStackInSlot(i) == itemstack) {
baubles.setInventorySlotContents(i, itemstack);
}
}
}
}
}
}
@Override
@Method(modid = "Baubles")
public void onEquipped(ItemStack itemstack, EntityLivingBase player) {
}
@Override
@Method(modid = "Baubles")
public void onUnequipped(ItemStack itemstack, EntityLivingBase player) {
}
@Override
@Method(modid = "Baubles")
public boolean canEquip(ItemStack itemstack, EntityLivingBase player) {
return isActive(itemstack);
}
@Override
@Method(modid = "Baubles")
public boolean canUnequip(ItemStack itemstack, EntityLivingBase player) {
return true;
}
}
@@ -40,7 +40,7 @@ public class MagnetController implements IEntitySelector {
return null;
}
private void doHoover(EntityPlayer player) {
public void doHoover(EntityPlayer player) {
AxisAlignedBB aabb = AxisAlignedBB.getBoundingBox(
player.posX - Config.magnetRange, player.posY - Config.magnetRange, player.posZ - Config.magnetRange,
@@ -5,6 +5,8 @@ import java.util.HashMap;
import java.util.Map;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import cpw.mods.fml.common.FMLCommonHandler;
@@ -12,6 +14,7 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import cpw.mods.fml.relauncher.Side;
import crazypants.enderio.config.Config;
import crazypants.enderio.tool.BaublesTool;
import crazypants.util.BlockCoord;
public class WirelessChargerController {
@@ -90,6 +93,17 @@ public class WirelessChargerController {
private boolean chargeFromCapBank(EntityPlayer player, IWirelessCharger capBank) {
boolean res = capBank.chargeItems(player.inventory.armorInventory);
res |= capBank.chargeItems(player.inventory.mainInventory);
IInventory baubles = BaublesTool.getInstance().getBaubles(player);
if (baubles != null) {
ItemStack[] item = new ItemStack[1];
for (int i = 0; i < baubles.getSizeInventory(); i++) {
item[0] = baubles.getStackInSlot(i);
if(capBank.chargeItems(item)) {
baubles.setInventorySlotContents(i, item[0]);
res = true;
}
}
}
return res;
}
@@ -2,11 +2,10 @@ package crazypants.enderio.tool;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import cpw.mods.fml.common.Optional.Method;
public class BaublesTool {
private static final BaublesTool instance = new withBaubles();
private static final BaublesTool instance = new BaublesToolwithBaubles();
public static BaublesTool getInstance() {
return instance;
@@ -20,15 +19,4 @@ public class BaublesTool {
return null;
}
private static class withBaubles extends BaublesTool {
@Method(modid = "Baubles")
public boolean hasBaubles() {
return true;
}
@Method(modid = "Baubles")
public IInventory getBaubles(EntityPlayer player) {
return baubles.api.BaublesApi.getBaubles(player);
}
}
}
@@ -0,0 +1,17 @@
package crazypants.enderio.tool;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import cpw.mods.fml.common.Optional;
// this cannot be an inner class as fml/Optional does not support them
class BaublesToolwithBaubles extends BaublesTool {
@Optional.Method(modid = "Baubles")
public boolean hasBaubles() {
return true;
}
@Optional.Method(modid = "Baubles")
public IInventory getBaubles(EntityPlayer player) {
return baubles.api.BaublesApi.getBaubles(player);
}
}