Made batteries output by sneak-right-clicking and added tesla support for items

This commit is contained in:
Ellpeck 2016-07-25 02:07:16 +02:00
parent eeecb6c5cd
commit c166c3752d
18 changed files with 309 additions and 66 deletions

View file

@ -45,6 +45,7 @@ import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
import de.ellpeck.actuallyadditions.mod.update.UpdateChecker; import de.ellpeck.actuallyadditions.mod.update.UpdateChecker;
import de.ellpeck.actuallyadditions.mod.util.ModUtil; import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance; import net.minecraftforge.fml.common.Mod.Instance;
@ -66,6 +67,8 @@ public class ActuallyAdditions{
@SidedProxy(clientSide = ModUtil.PROXY_CLIENT, serverSide = ModUtil.PROXY_SERVER) @SidedProxy(clientSide = ModUtil.PROXY_CLIENT, serverSide = ModUtil.PROXY_SERVER)
public static IProxy proxy; public static IProxy proxy;
public static boolean teslaLoaded;
static{ static{
//For some reason, this has to be done here //For some reason, this has to be done here
FluidRegistry.enableUniversalBucket(); FluidRegistry.enableUniversalBucket();
@ -79,6 +82,14 @@ public class ActuallyAdditions{
Lenses.init(); Lenses.init();
InitBooklet.preInit(); InitBooklet.preInit();
if(Loader.isModLoaded("Tesla")){
ModUtil.LOGGER.info("Tesla loaded... Activating Tesla Power System integration...");
ActuallyAdditions.teslaLoaded = true;
}
else{
ModUtil.LOGGER.info("Tesla not found! Skipping Tesla Power System integration.");
}
new ConfigurationHandler(event.getSuggestedConfigurationFile()); new ConfigurationHandler(event.getSuggestedConfigurationFile());
PacketHandler.init(); PacketHandler.init();
InitToolMaterials.init(); InitToolMaterials.init();

View file

@ -11,9 +11,11 @@
package de.ellpeck.actuallyadditions.mod.inventory; package de.ellpeck.actuallyadditions.mod.inventory;
import cofh.api.energy.IEnergyContainerItem; import cofh.api.energy.IEnergyContainerItem;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotImmovable; import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotImmovable;
import de.ellpeck.actuallyadditions.mod.items.ItemDrill; import de.ellpeck.actuallyadditions.mod.items.ItemDrill;
import de.ellpeck.actuallyadditions.mod.items.ItemDrillUpgrade; import de.ellpeck.actuallyadditions.mod.items.ItemDrillUpgrade;
import de.ellpeck.actuallyadditions.mod.util.compat.TeslaUtil;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ClickType; import net.minecraft.inventory.ClickType;
@ -39,7 +41,7 @@ public class ContainerDrill extends Container{
this.addSlotToContainer(new Slot(this.drillInventory, i, 44+i*18, 19){ this.addSlotToContainer(new Slot(this.drillInventory, i, 44+i*18, 19){
@Override @Override
public boolean isItemValid(ItemStack stack){ public boolean isItemValid(ItemStack stack){
return stack.getItem() instanceof ItemDrillUpgrade || stack.getItem() instanceof IEnergyContainerItem; return stack.getItem() instanceof ItemDrillUpgrade || stack.getItem() instanceof IEnergyContainerItem || (ActuallyAdditions.teslaLoaded && stack.hasCapability(TeslaUtil.teslaProducer, null));
} }
}); });
} }
@ -80,7 +82,7 @@ public class ContainerDrill extends Container{
//Other Slots in Inventory excluded //Other Slots in Inventory excluded
if(slot >= inventoryStart){ if(slot >= inventoryStart){
//Shift from Inventory //Shift from Inventory
if(newStack.getItem() instanceof ItemDrillUpgrade || newStack.getItem() instanceof IEnergyContainerItem){ if(newStack.getItem() instanceof ItemDrillUpgrade || newStack.getItem() instanceof IEnergyContainerItem || (ActuallyAdditions.teslaLoaded && newStack.hasCapability(TeslaUtil.teslaProducer, null))){
if(!this.mergeItemStack(newStack, 0, 5, false)){ if(!this.mergeItemStack(newStack, 0, 5, false)){
return null; return null;
} }

View file

@ -11,9 +11,11 @@
package de.ellpeck.actuallyadditions.mod.inventory; package de.ellpeck.actuallyadditions.mod.inventory;
import cofh.api.energy.IEnergyContainerItem; import cofh.api.energy.IEnergyContainerItem;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotOutput; import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotOutput;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase; import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityEnergizer; import de.ellpeck.actuallyadditions.mod.tile.TileEntityEnergizer;
import de.ellpeck.actuallyadditions.mod.util.compat.TeslaUtil;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container; import net.minecraft.inventory.Container;
@ -91,7 +93,7 @@ public class ContainerEnergizer extends Container{
//Other Slots in Inventory excluded //Other Slots in Inventory excluded
else if(slot >= inventoryStart){ else if(slot >= inventoryStart){
//Shift from Inventory //Shift from Inventory
if(newStack.getItem() instanceof IEnergyContainerItem){ if(newStack.getItem() instanceof IEnergyContainerItem || (ActuallyAdditions.teslaLoaded && newStack.hasCapability(TeslaUtil.teslaConsumer, null))){
if(!this.mergeItemStack(newStack, 0, 1, false)){ if(!this.mergeItemStack(newStack, 0, 1, false)){
return null; return null;
} }

View file

@ -11,9 +11,11 @@
package de.ellpeck.actuallyadditions.mod.inventory; package de.ellpeck.actuallyadditions.mod.inventory;
import cofh.api.energy.IEnergyContainerItem; import cofh.api.energy.IEnergyContainerItem;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotOutput; import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotOutput;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase; import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityEnervator; import de.ellpeck.actuallyadditions.mod.tile.TileEntityEnervator;
import de.ellpeck.actuallyadditions.mod.util.compat.TeslaUtil;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container; import net.minecraft.inventory.Container;
@ -90,7 +92,7 @@ public class ContainerEnervator extends Container{
//Other Slots in Inventory excluded //Other Slots in Inventory excluded
else if(slot >= inventoryStart){ else if(slot >= inventoryStart){
//Shift from Inventory //Shift from Inventory
if(newStack.getItem() instanceof IEnergyContainerItem){ if(newStack.getItem() instanceof IEnergyContainerItem || (ActuallyAdditions.teslaLoaded && newStack.hasCapability(TeslaUtil.teslaProducer, null))){
if(!this.mergeItemStack(newStack, 0, 1, false)){ if(!this.mergeItemStack(newStack, 0, 1, false)){
return null; return null;
} }

View file

@ -10,9 +10,25 @@
package de.ellpeck.actuallyadditions.mod.items; package de.ellpeck.actuallyadditions.mod.items;
import cofh.api.energy.IEnergyContainerItem;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.items.base.ItemEnergy; import de.ellpeck.actuallyadditions.mod.items.base.ItemEnergy;
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
import de.ellpeck.actuallyadditions.mod.util.compat.TeslaUtil;
import net.darkhax.tesla.api.ITeslaConsumer;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumRarity; import net.minecraft.item.EnumRarity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.world.World;
import java.util.List;
public class ItemBattery extends ItemEnergy{ public class ItemBattery extends ItemEnergy{
@ -21,9 +37,71 @@ public class ItemBattery extends ItemEnergy{
this.setMaxStackSize(1); this.setMaxStackSize(1);
} }
@Override @Override
public EnumRarity getRarity(ItemStack stack){ public EnumRarity getRarity(ItemStack stack){
return EnumRarity.RARE; return EnumRarity.RARE;
} }
@Override
public boolean hasEffect(ItemStack stack){
return this.isDischargeMode(stack);
}
@Override
public void onUpdate(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected){
if(!world.isRemote && entity instanceof EntityPlayer && this.isDischargeMode(stack)){
EntityPlayer player = (EntityPlayer)entity;
for(int i = 0; i < player.inventory.getSizeInventory(); i++){
ItemStack slot = player.inventory.getStackInSlot(i);
if(slot != null){
int received = 0;
Item item = slot.getItem();
if(item instanceof IEnergyContainerItem){
received = ((IEnergyContainerItem)item).receiveEnergy(slot, this.getEnergyStored(stack), false);
}
else if(ActuallyAdditions.teslaLoaded && slot.hasCapability(TeslaUtil.teslaConsumer, null)){
ITeslaConsumer cap = slot.getCapability(TeslaUtil.teslaConsumer, null);
if(cap != null){
received = (int)cap.givePower(this.getEnergyStored(stack), false);
}
}
if(received > 0){
this.extractEnergy(stack, received, false);
}
}
}
}
}
@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World worldIn, EntityPlayer player, EnumHand hand){
if(!worldIn.isRemote && player.isSneaking()){
boolean isDischarge = this.isDischargeMode(stack);
this.setDischargeMode(stack, !isDischarge);
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
}
return super.onItemRightClick(stack, worldIn, player, hand);
}
private boolean isDischargeMode(ItemStack stack){
return stack.hasTagCompound() && stack.getTagCompound().getBoolean("DischargeMode");
}
private void setDischargeMode(ItemStack stack, boolean mode){
if(!stack.hasTagCompound()){
stack.setTagCompound(new NBTTagCompound());
}
stack.getTagCompound().setBoolean("DischargeMode", mode);
}
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean bool){
super.addInformation(stack, player, list, bool);
list.add(StringUtil.localize("tooltip."+ModUtil.MOD_ID+".battery."+(this.isDischargeMode(stack) ? "discharge" : "noDischarge")));
list.add(StringUtil.localize("tooltip."+ModUtil.MOD_ID+".battery.changeMode"));
}
} }

View file

@ -22,6 +22,8 @@ import de.ellpeck.actuallyadditions.mod.tile.TileEntityInventoryBase;
import de.ellpeck.actuallyadditions.mod.util.ItemUtil; import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
import de.ellpeck.actuallyadditions.mod.util.ModUtil; import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import de.ellpeck.actuallyadditions.mod.util.WorldUtil; import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
import de.ellpeck.actuallyadditions.mod.util.compat.TeslaUtil;
import net.darkhax.tesla.api.ITeslaProducer;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
@ -193,17 +195,24 @@ public class ItemDrill extends ItemEnergy{
loadSlotsFromNBT(slots, stack); loadSlotsFromNBT(slots, stack);
if(slots != null && slots.length > 0){ if(slots != null && slots.length > 0){
for(ItemStack slotStack : slots){ for(ItemStack slotStack : slots){
if(slotStack != null && slotStack.getItem() instanceof IEnergyContainerItem){ if(slotStack != null){
if(this.getEnergyStored(stack) < this.getMaxEnergyStored(stack)){ Item item = slotStack.getItem();
int energy = ((IEnergyContainerItem)slotStack.getItem()).getEnergyStored(slotStack);
if(energy > 0){
//Charge the Drill and discharge the "Upgrade"
int toReceive = ((IEnergyContainerItem)stack.getItem()).receiveEnergy(stack, energy, true);
int actualReceive = ((IEnergyContainerItem)slotStack.getItem()).extractEnergy(slotStack, toReceive, false);
((IEnergyContainerItem)stack.getItem()).receiveEnergy(stack, actualReceive, false);
int extracted = 0;
int maxExtract = this.getMaxEnergyStored(stack)-this.getEnergyStored(stack);
if(item instanceof IEnergyContainerItem){
extracted = ((IEnergyContainerItem)item).extractEnergy(slotStack, maxExtract, false);
}
else if(ActuallyAdditions.teslaLoaded && slotStack.hasCapability(TeslaUtil.teslaProducer, null)){
ITeslaProducer cap = slotStack.getCapability(TeslaUtil.teslaProducer, null);
if(cap != null){
extracted = (int)cap.takePower(maxExtract, false);
} }
} }
if(extracted > 0){
this.receiveEnergy(stack, extracted, false);
}
} }
} }
} }

View file

@ -13,12 +13,14 @@ package de.ellpeck.actuallyadditions.mod.items.base;
import cofh.api.energy.ItemEnergyContainer; import cofh.api.energy.ItemEnergyContainer;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.util.ItemUtil; import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
import de.ellpeck.actuallyadditions.mod.util.compat.ItemTeslaWrapper;
import net.minecraft.creativetab.CreativeTabs; import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.fml.relauncher.SideOnly;
@ -108,4 +110,9 @@ public abstract class ItemEnergy extends ItemEnergyContainer{
compound.setInteger("Energy", energy); compound.setInteger("Energy", energy);
stack.setTagCompound(compound); stack.setTagCompound(compound);
} }
@Override
public ICapabilityProvider initCapabilities(ItemStack stack, NBTTagCompound nbt){
return ActuallyAdditions.teslaLoaded ? new ItemTeslaWrapper(stack, this) : null;
}
} }

View file

@ -12,6 +12,7 @@ package de.ellpeck.actuallyadditions.mod.tile;
import cofh.api.energy.IEnergyProvider; import cofh.api.energy.IEnergyProvider;
import cofh.api.energy.IEnergyReceiver; import cofh.api.energy.IEnergyReceiver;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigIntValues; import de.ellpeck.actuallyadditions.mod.config.values.ConfigIntValues;
import de.ellpeck.actuallyadditions.mod.network.PacketHandler; import de.ellpeck.actuallyadditions.mod.network.PacketHandler;
import de.ellpeck.actuallyadditions.mod.network.PacketServerToClient; import de.ellpeck.actuallyadditions.mod.network.PacketServerToClient;
@ -39,7 +40,6 @@ import net.minecraftforge.fml.common.registry.GameRegistry;
public abstract class TileEntityBase extends TileEntity implements ITickable{ public abstract class TileEntityBase extends TileEntity implements ITickable{
public static boolean teslaLoaded;
public final String name; public final String name;
public boolean isRedstonePowered; public boolean isRedstonePowered;
public boolean isPulseMode; public boolean isPulseMode;
@ -105,14 +105,6 @@ public abstract class TileEntityBase extends TileEntity implements ITickable{
register(TileEntityBookletStand.class, "BookletStand"); register(TileEntityBookletStand.class, "BookletStand");
register(TileEntityDisplayStand.class, "DisplayStand"); register(TileEntityDisplayStand.class, "DisplayStand");
register(TileEntityShockSuppressor.class, "ShockSuppressor"); register(TileEntityShockSuppressor.class, "ShockSuppressor");
if(Loader.isModLoaded("Tesla")){
ModUtil.LOGGER.info("Tesla loaded... Activating Tesla Power System integration...");
teslaLoaded = true;
}
else{
ModUtil.LOGGER.info("Tesla not found! Skipping Tesla Power System integration.");
}
} }
private static void register(Class<? extends TileEntityBase> tileClass, String legacyName){ private static void register(Class<? extends TileEntityBase> tileClass, String legacyName){
@ -280,7 +272,7 @@ public abstract class TileEntityBase extends TileEntity implements ITickable{
return (T)tank; return (T)tank;
} }
} }
else if(teslaLoaded){ else if(ActuallyAdditions.teslaLoaded){
T cap = TeslaUtil.wrapTeslaToRF(this, capability, facing); T cap = TeslaUtil.wrapTeslaToRF(this, capability, facing);
if(cap != null){ if(cap != null){
return cap; return cap;

View file

@ -13,6 +13,10 @@ package de.ellpeck.actuallyadditions.mod.tile;
import cofh.api.energy.EnergyStorage; import cofh.api.energy.EnergyStorage;
import cofh.api.energy.IEnergyContainerItem; import cofh.api.energy.IEnergyContainerItem;
import cofh.api.energy.IEnergyReceiver; import cofh.api.energy.IEnergyReceiver;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.util.compat.TeslaUtil;
import net.darkhax.tesla.api.ITeslaConsumer;
import net.darkhax.tesla.api.ITeslaHolder;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
@ -44,17 +48,40 @@ public class TileEntityEnergizer extends TileEntityInventoryBase implements IEne
public void updateEntity(){ public void updateEntity(){
super.updateEntity(); super.updateEntity();
if(!this.worldObj.isRemote){ if(!this.worldObj.isRemote){
if(this.slots[0] != null && this.slots[0].getItem() instanceof IEnergyContainerItem && this.slots[1] == null){ if(this.slots[0] != null && this.slots[1] == null){
if(this.storage.getEnergyStored() > 0){ if(this.storage.getEnergyStored() > 0){
int received = ((IEnergyContainerItem)this.slots[0].getItem()).receiveEnergy(this.slots[0], this.storage.getEnergyStored(), false); int received = 0;
this.storage.extractEnergy(received, false); boolean canTakeUp = false;
}
if(((IEnergyContainerItem)this.slots[0].getItem()).getEnergyStored(this.slots[0]) >= ((IEnergyContainerItem)this.slots[0].getItem()).getMaxEnergyStored(this.slots[0])){ if(this.slots[0].getItem() instanceof IEnergyContainerItem){
this.slots[1] = this.slots[0].copy(); IEnergyContainerItem item = (IEnergyContainerItem)this.slots[0].getItem();
this.slots[0].stackSize--; received = (item.receiveEnergy(this.slots[0], this.storage.getEnergyStored(), false));
if(this.slots[0].stackSize <= 0){ canTakeUp = item.getEnergyStored(this.slots[0]) >= item.getMaxEnergyStored(this.slots[0]);
this.slots[0] = null; }
else if(ActuallyAdditions.teslaLoaded){
if(this.slots[0].hasCapability(TeslaUtil.teslaConsumer, null)){
ITeslaConsumer cap = this.slots[0].getCapability(TeslaUtil.teslaConsumer, null);
if(cap != null){
received = (int)cap.givePower(this.storage.getEnergyStored(), false);
}
}
if(this.slots[0].hasCapability(TeslaUtil.teslaHolder, null)){
ITeslaHolder cap = this.slots[0].getCapability(TeslaUtil.teslaHolder, null);
if(cap != null){
canTakeUp = cap.getStoredPower() >= cap.getCapacity();
}
}
}
if(received > 0){
this.storage.extractEnergy(received, false);
}
if(canTakeUp){
this.slots[1] = this.slots[0].copy();
this.slots[0].stackSize--;
if(this.slots[0].stackSize <= 0){
this.slots[0] = null;
}
} }
} }
} }
@ -67,7 +94,7 @@ public class TileEntityEnergizer extends TileEntityInventoryBase implements IEne
@Override @Override
public boolean isItemValidForSlot(int i, ItemStack stack){ public boolean isItemValidForSlot(int i, ItemStack stack){
return i == 0 && stack.getItem() instanceof IEnergyContainerItem; return i == 0 && (stack.getItem() instanceof IEnergyContainerItem || (ActuallyAdditions.teslaLoaded && stack.hasCapability(TeslaUtil.teslaConsumer, null)));
} }
@Override @Override

View file

@ -13,6 +13,10 @@ package de.ellpeck.actuallyadditions.mod.tile;
import cofh.api.energy.EnergyStorage; import cofh.api.energy.EnergyStorage;
import cofh.api.energy.IEnergyContainerItem; import cofh.api.energy.IEnergyContainerItem;
import cofh.api.energy.IEnergyProvider; import cofh.api.energy.IEnergyProvider;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.util.compat.TeslaUtil;
import net.darkhax.tesla.api.ITeslaHolder;
import net.darkhax.tesla.api.ITeslaProducer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
@ -44,17 +48,41 @@ public class TileEntityEnervator extends TileEntityInventoryBase implements IEne
public void updateEntity(){ public void updateEntity(){
super.updateEntity(); super.updateEntity();
if(!this.worldObj.isRemote){ if(!this.worldObj.isRemote){
if(this.slots[0] != null && this.slots[0].getItem() instanceof IEnergyContainerItem && this.slots[1] == null){ if(this.slots[0] != null && this.slots[1] == null){
if(((IEnergyContainerItem)this.slots[0].getItem()).getEnergyStored(this.slots[0]) > 0){ if(this.storage.getEnergyStored() < this.storage.getMaxEnergyStored()){
int toReceive = ((IEnergyContainerItem)this.slots[0].getItem()).extractEnergy(this.slots[0], this.storage.getMaxEnergyStored()-this.storage.getEnergyStored(), false); int extracted = 0;
this.storage.receiveEnergy(toReceive, false); boolean canTakeUp = false;
}
if(((IEnergyContainerItem)this.slots[0].getItem()).getEnergyStored(this.slots[0]) <= 0){ int maxExtract = this.storage.getMaxEnergyStored()-this.storage.getEnergyStored();
this.slots[1] = this.slots[0].copy(); if(this.slots[0].getItem() instanceof IEnergyContainerItem){
this.slots[0].stackSize--; IEnergyContainerItem item = (IEnergyContainerItem)this.slots[0].getItem();
if(this.slots[0].stackSize <= 0){ extracted = item.extractEnergy(this.slots[0], maxExtract, false);
this.slots[0] = null; canTakeUp = item.getEnergyStored(this.slots[0]) <= 0;
}
else if(ActuallyAdditions.teslaLoaded){
if(this.slots[0].hasCapability(TeslaUtil.teslaProducer, null)){
ITeslaProducer cap = this.slots[0].getCapability(TeslaUtil.teslaProducer, null);
if(cap != null){
extracted = (int)cap.takePower(maxExtract, false);
}
}
if(this.slots[0].hasCapability(TeslaUtil.teslaHolder, null)){
ITeslaHolder cap = this.slots[0].getCapability(TeslaUtil.teslaHolder, null);
if(cap != null){
canTakeUp = cap.getStoredPower() <= 0;
}
}
}
if(extracted > 0){
this.storage.receiveEnergy(extracted, false);
}
if(canTakeUp){
this.slots[1] = this.slots[0].copy();
this.slots[0].stackSize--;
if(this.slots[0].stackSize <= 0){
this.slots[0] = null;
}
} }
} }
} }
@ -67,7 +95,7 @@ public class TileEntityEnervator extends TileEntityInventoryBase implements IEne
@Override @Override
public boolean isItemValidForSlot(int i, ItemStack stack){ public boolean isItemValidForSlot(int i, ItemStack stack){
return i == 0 && stack.getItem() instanceof IEnergyContainerItem; return i == 0 && (stack.getItem() instanceof IEnergyContainerItem || (ActuallyAdditions.teslaLoaded && stack.hasCapability(TeslaUtil.teslaProducer, null)));
} }
@Override @Override

View file

@ -11,8 +11,8 @@
package de.ellpeck.actuallyadditions.mod.tile; package de.ellpeck.actuallyadditions.mod.tile;
import cofh.api.energy.IEnergyReceiver; import cofh.api.energy.IEnergyReceiver;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues; import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigIntValues;
import de.ellpeck.actuallyadditions.mod.misc.LaserRelayConnectionHandler; import de.ellpeck.actuallyadditions.mod.misc.LaserRelayConnectionHandler;
import de.ellpeck.actuallyadditions.mod.util.compat.TeslaUtil; import de.ellpeck.actuallyadditions.mod.util.compat.TeslaUtil;
import net.darkhax.tesla.api.ITeslaConsumer; import net.darkhax.tesla.api.ITeslaConsumer;
@ -78,7 +78,7 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay implements
BlockPos pos = this.getPos().offset(side); BlockPos pos = this.getPos().offset(side);
TileEntity tile = this.worldObj.getTileEntity(pos); TileEntity tile = this.worldObj.getTileEntity(pos);
if(tile != null && !(tile instanceof TileEntityLaserRelay)){ if(tile != null && !(tile instanceof TileEntityLaserRelay)){
if(tile instanceof IEnergyReceiver || (teslaLoaded && tile.hasCapability(TeslaUtil.teslaConsumer, side.getOpposite()))){ if(tile instanceof IEnergyReceiver || (ActuallyAdditions.teslaLoaded && tile.hasCapability(TeslaUtil.teslaConsumer, side.getOpposite()))){
this.receiversAround.put(side, tile); this.receiversAround.put(side, tile);
} }
} }
@ -114,7 +114,7 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay implements
transmitted += deduct; transmitted += deduct;
} }
} }
else if(teslaLoaded && tile.hasCapability(TeslaUtil.teslaConsumer, opp)){ else if(ActuallyAdditions.teslaLoaded && tile.hasCapability(TeslaUtil.teslaConsumer, opp)){
ITeslaConsumer cap = tile.getCapability(TeslaUtil.teslaConsumer, opp); ITeslaConsumer cap = tile.getCapability(TeslaUtil.teslaConsumer, opp);
if(cap != null){ if(cap != null){
int theoreticalReceived = (int)cap.givePower(Math.min(maxTransfer, lowestCap)-transmitted, true); int theoreticalReceived = (int)cap.givePower(Math.min(maxTransfer, lowestCap)-transmitted, true);

View file

@ -14,6 +14,7 @@ import cofh.api.energy.IEnergyConnection;
import cofh.api.energy.IEnergyHandler; import cofh.api.energy.IEnergyHandler;
import cofh.api.energy.IEnergyProvider; import cofh.api.energy.IEnergyProvider;
import cofh.api.energy.IEnergyReceiver; import cofh.api.energy.IEnergyReceiver;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.blocks.BlockPhantom; import de.ellpeck.actuallyadditions.mod.blocks.BlockPhantom;
import de.ellpeck.actuallyadditions.mod.util.compat.TeslaUtil; import de.ellpeck.actuallyadditions.mod.util.compat.TeslaUtil;
import net.darkhax.tesla.api.ITeslaConsumer; import net.darkhax.tesla.api.ITeslaConsumer;
@ -37,7 +38,7 @@ public class TileEntityPhantomEnergyface extends TileEntityPhantomface implement
if(tile instanceof IEnergyReceiver){ if(tile instanceof IEnergyReceiver){
return ((IEnergyReceiver)tile).receiveEnergy(from, maxReceive, simulate); return ((IEnergyReceiver)tile).receiveEnergy(from, maxReceive, simulate);
} }
else if(teslaLoaded && tile.hasCapability(TeslaUtil.teslaConsumer, from)){ else if(ActuallyAdditions.teslaLoaded && tile.hasCapability(TeslaUtil.teslaConsumer, from)){
ITeslaConsumer cap = tile.getCapability(TeslaUtil.teslaConsumer, from); ITeslaConsumer cap = tile.getCapability(TeslaUtil.teslaConsumer, from);
if(cap != null){ if(cap != null){
return (int)cap.givePower(maxReceive, simulate); return (int)cap.givePower(maxReceive, simulate);
@ -56,7 +57,7 @@ public class TileEntityPhantomEnergyface extends TileEntityPhantomface implement
if(tile instanceof IEnergyProvider){ if(tile instanceof IEnergyProvider){
return ((IEnergyProvider)tile).extractEnergy(from, maxExtract, simulate); return ((IEnergyProvider)tile).extractEnergy(from, maxExtract, simulate);
} }
else if(teslaLoaded && tile.hasCapability(TeslaUtil.teslaProducer, from)){ else if(ActuallyAdditions.teslaLoaded && tile.hasCapability(TeslaUtil.teslaProducer, from)){
ITeslaProducer cap = tile.getCapability(TeslaUtil.teslaProducer, from); ITeslaProducer cap = tile.getCapability(TeslaUtil.teslaProducer, from);
if(cap != null){ if(cap != null){
return (int)cap.takePower(maxExtract, simulate); return (int)cap.takePower(maxExtract, simulate);
@ -75,7 +76,7 @@ public class TileEntityPhantomEnergyface extends TileEntityPhantomface implement
if(tile instanceof IEnergyHandler){ if(tile instanceof IEnergyHandler){
return ((IEnergyHandler)tile).getEnergyStored(from); return ((IEnergyHandler)tile).getEnergyStored(from);
} }
else if(teslaLoaded && tile.hasCapability(TeslaUtil.teslaHolder, from)){ else if(ActuallyAdditions.teslaLoaded && tile.hasCapability(TeslaUtil.teslaHolder, from)){
ITeslaHolder cap = tile.getCapability(TeslaUtil.teslaHolder, from); ITeslaHolder cap = tile.getCapability(TeslaUtil.teslaHolder, from);
if(cap != null){ if(cap != null){
return (int)cap.getStoredPower(); return (int)cap.getStoredPower();
@ -94,7 +95,7 @@ public class TileEntityPhantomEnergyface extends TileEntityPhantomface implement
if(tile instanceof IEnergyHandler){ if(tile instanceof IEnergyHandler){
return ((IEnergyHandler)tile).getMaxEnergyStored(from); return ((IEnergyHandler)tile).getMaxEnergyStored(from);
} }
else if(teslaLoaded && tile.hasCapability(TeslaUtil.teslaHolder, from)){ else if(ActuallyAdditions.teslaLoaded && tile.hasCapability(TeslaUtil.teslaHolder, from)){
ITeslaHolder cap = tile.getCapability(TeslaUtil.teslaHolder, from); ITeslaHolder cap = tile.getCapability(TeslaUtil.teslaHolder, from);
if(cap != null){ if(cap != null){
return (int)cap.getCapacity(); return (int)cap.getCapacity();
@ -109,7 +110,7 @@ public class TileEntityPhantomEnergyface extends TileEntityPhantomface implement
public boolean isBoundThingInRange(){ public boolean isBoundThingInRange(){
if(super.isBoundThingInRange()){ if(super.isBoundThingInRange()){
TileEntity tile = this.worldObj.getTileEntity(this.boundPosition); TileEntity tile = this.worldObj.getTileEntity(this.boundPosition);
return tile != null && (tile instanceof IEnergyHandler || (teslaLoaded && tile.hasCapability(TeslaUtil.teslaHolder, null))); return tile != null && (tile instanceof IEnergyHandler || (ActuallyAdditions.teslaLoaded && tile.hasCapability(TeslaUtil.teslaHolder, null)));
} }
else{ else{
return false; return false;
@ -125,7 +126,7 @@ public class TileEntityPhantomEnergyface extends TileEntityPhantomface implement
return ((IEnergyConnection)tile).canConnectEnergy(from); return ((IEnergyConnection)tile).canConnectEnergy(from);
} }
else{ else{
return teslaLoaded && tile.hasCapability(TeslaUtil.teslaHolder, from); return ActuallyAdditions.teslaLoaded && tile.hasCapability(TeslaUtil.teslaHolder, from);
} }
} }
} }

View file

@ -13,7 +13,11 @@ package de.ellpeck.actuallyadditions.mod.tile;
import cofh.api.energy.EnergyStorage; import cofh.api.energy.EnergyStorage;
import cofh.api.energy.IEnergyContainerItem; import cofh.api.energy.IEnergyContainerItem;
import cofh.api.energy.IEnergyReceiver; import cofh.api.energy.IEnergyReceiver;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.util.compat.TeslaUtil;
import net.darkhax.tesla.api.ITeslaConsumer;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
@ -58,10 +62,23 @@ public class TileEntityPlayerInterface extends TileEntityInventoryBase implement
for(int i = 0; i < player.inventory.getSizeInventory(); i++){ for(int i = 0; i < player.inventory.getSizeInventory(); i++){
if(this.storage.getEnergyStored() > 0){ if(this.storage.getEnergyStored() > 0){
ItemStack slot = player.inventory.getStackInSlot(i); ItemStack slot = player.inventory.getStackInSlot(i);
if(slot != null && slot.getItem() instanceof IEnergyContainerItem){ if(slot != null){
int received = ((IEnergyContainerItem)slot.getItem()).receiveEnergy(slot, this.storage.getEnergyStored(), false); Item item = slot.getItem();
this.storage.extractEnergy(received, false);
changed = true; int received = 0;
if(item instanceof IEnergyContainerItem){
received = ((IEnergyContainerItem)item).receiveEnergy(slot, this.storage.getEnergyStored(), false);
}
else if(ActuallyAdditions.teslaLoaded && slot.hasCapability(TeslaUtil.teslaConsumer, null)){
ITeslaConsumer cap = slot.getCapability(TeslaUtil.teslaConsumer, null);
if(cap != null){
received = (int)cap.givePower(this.storage.getEnergyStored(), false);
}
}
if(received > 0){
this.storage.extractEnergy(received, false);
}
} }
} }
else{ else{

View file

@ -12,7 +12,7 @@ package de.ellpeck.actuallyadditions.mod.util;
import cofh.api.energy.IEnergyProvider; import cofh.api.energy.IEnergyProvider;
import cofh.api.energy.IEnergyReceiver; import cofh.api.energy.IEnergyReceiver;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.util.compat.TeslaUtil; import de.ellpeck.actuallyadditions.mod.util.compat.TeslaUtil;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockLiquid; import net.minecraft.block.BlockLiquid;
@ -118,7 +118,7 @@ public final class WorldUtil{
} }
} }
} }
else if(TileEntityBase.teslaLoaded){ else if(ActuallyAdditions.teslaLoaded){
TeslaUtil.doWrappedTeslaRFInteraction(tile, otherTile, side); TeslaUtil.doWrappedTeslaRFInteraction(tile, otherTile, side);
} }
} }

View file

@ -0,0 +1,64 @@
/*
* This file ("ItemTeslaWrapper.java") is part of the Actually Additions mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* © 2015-2016 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.util.compat;
import cofh.api.energy.IEnergyContainerItem;
import net.darkhax.tesla.api.ITeslaConsumer;
import net.darkhax.tesla.api.ITeslaHolder;
import net.darkhax.tesla.api.ITeslaProducer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import javax.annotation.Nullable;
public class ItemTeslaWrapper implements ITeslaProducer, ITeslaHolder, ITeslaConsumer, ICapabilityProvider{
private final ItemStack stack;
private final IEnergyContainerItem item;
public ItemTeslaWrapper(ItemStack stack, IEnergyContainerItem item){
this.stack = stack;
this.item = item;
}
@Override
public long givePower(long power, boolean simulated){
return this.item.receiveEnergy(this.stack, (int)power, simulated);
}
@Override
public long getStoredPower(){
return this.item.getEnergyStored(this.stack);
}
@Override
public long getCapacity(){
return this.item.getMaxEnergyStored(this.stack);
}
@Override
public long takePower(long power, boolean simulated){
return this.item.extractEnergy(this.stack, (int)power, simulated);
}
@Override
public boolean hasCapability(Capability<?> capability, @Nullable EnumFacing facing){
return capability == TeslaUtil.teslaProducer || capability == TeslaUtil.teslaHolder || capability == TeslaUtil.teslaConsumer;
}
@Override
public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing){
return this.hasCapability(capability, facing) ? (T)this : null;
}
}

View file

@ -27,7 +27,7 @@ import java.util.Map;
public final class TeslaUtil{ public final class TeslaUtil{
private static final Map<TileEntityBase, TeslaHandler[]> TESLA_MAP = new HashMap<TileEntityBase, TeslaHandler[]>(); private static final Map<TileEntityBase, TileTeslaWrapper[]> TESLA_MAP = new HashMap<TileEntityBase, TileTeslaWrapper[]>();
@CapabilityInject(ITeslaConsumer.class) @CapabilityInject(ITeslaConsumer.class)
public static Capability<ITeslaConsumer> teslaConsumer; public static Capability<ITeslaConsumer> teslaConsumer;
@CapabilityInject(ITeslaProducer.class) @CapabilityInject(ITeslaProducer.class)
@ -67,16 +67,16 @@ public final class TeslaUtil{
} }
} }
private static TeslaHandler getHandler(TileEntityBase tile, EnumFacing facing){ private static TileTeslaWrapper getHandler(TileEntityBase tile, EnumFacing facing){
TeslaHandler[] handlers = TESLA_MAP.get(tile); TileTeslaWrapper[] handlers = TESLA_MAP.get(tile);
if(handlers == null || handlers.length != 6){ if(handlers == null || handlers.length != 6){
handlers = new TeslaHandler[6]; handlers = new TileTeslaWrapper[6];
TESLA_MAP.put(tile, handlers); TESLA_MAP.put(tile, handlers);
} }
int side = facing.ordinal(); int side = facing.ordinal();
if(handlers[side] == null){ if(handlers[side] == null){
handlers[side] = new TeslaHandler(tile, facing); handlers[side] = new TileTeslaWrapper(tile, facing);
} }
return handlers[side]; return handlers[side];
} }

View file

@ -19,12 +19,12 @@ import net.darkhax.tesla.api.ITeslaHolder;
import net.darkhax.tesla.api.ITeslaProducer; import net.darkhax.tesla.api.ITeslaProducer;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
public class TeslaHandler implements ITeslaProducer, ITeslaHolder, ITeslaConsumer{ public class TileTeslaWrapper implements ITeslaProducer, ITeslaHolder, ITeslaConsumer{
private final EnumFacing side; private final EnumFacing side;
private final TileEntityBase tile; private final TileEntityBase tile;
public TeslaHandler(TileEntityBase tile, EnumFacing side){ public TileTeslaWrapper(TileEntityBase tile, EnumFacing side){
this.tile = tile; this.tile = tile;
this.side = side; this.side = side;
} }

View file

@ -536,6 +536,9 @@ tooltip.actuallyadditions.playerProbe.disconnect.1=The player you were probing h
tooltip.actuallyadditions.playerProbe.disconnect.2=The player you were probing has disconnected before you could strap him to the Player Interface! Data will be cleared! tooltip.actuallyadditions.playerProbe.disconnect.2=The player you were probing has disconnected before you could strap him to the Player Interface! Data will be cleared!
tooltip.actuallyadditions.playerProbe.probing=Probing tooltip.actuallyadditions.playerProbe.probing=Probing
tooltip.actuallyadditions.playerProbe.notice=Look out! Someone tried to probe you and strap you to a Player Interface, but they failed! tooltip.actuallyadditions.playerProbe.notice=Look out! Someone tried to probe you and strap you to a Player Interface, but they failed!
tooltip.actuallyadditions.battery.discharge=Charging other items in inventory
tooltip.actuallyadditions.battery.noDischarge=Not charging other items in inventory
tooltip.actuallyadditions.battery.changeMode=Sneak-right-click to toggle.
#Gui Information #Gui Information
info.actuallyadditions.gui.animals=Animals info.actuallyadditions.gui.animals=Animals