mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-27 23:45:55 +00:00
Inventory, WAILA and item state done.
This commit is contained in:
1 parent
0a41647899
commit
d1c9895494
32 files changed
+1082
-302
No files matched your search
@@ -20,8 +20,6 @@ import crazypants.enderio.conduit.power.PowerConduitNetwork.ReceptorEntry;
|
||||
import crazypants.enderio.config.Config;
|
||||
import crazypants.enderio.machine.power.TileCapacitorBank;
|
||||
import crazypants.enderio.power.IPowerInterface;
|
||||
import crazypants.enderio.power.PowerInterfaceRF;
|
||||
import crazypants.util.BlockCoord;
|
||||
|
||||
public class NetworkPowerManager {
|
||||
|
||||
@@ -41,9 +39,6 @@ public class NetworkPowerManager {
|
||||
|
||||
private boolean receptorsDirty = true;
|
||||
|
||||
private boolean lastActiveValue = false;
|
||||
private int ticksWithNoPower = 0;
|
||||
|
||||
private final Map<IPowerConduit, PowerTracker> powerTrackers = new HashMap<IPowerConduit, PowerTracker>();
|
||||
|
||||
private PowerTracker networkPowerTracker = new PowerTracker();
|
||||
@@ -53,7 +48,7 @@ public class NetworkPowerManager {
|
||||
private InnerTickHandler applyPowerCallback = new InnerTickHandler();
|
||||
|
||||
public NetworkPowerManager(PowerConduitNetwork netowrk, World world) {
|
||||
this.network = netowrk;
|
||||
network = netowrk;
|
||||
maxEnergyStored = 64;
|
||||
}
|
||||
|
||||
@@ -132,8 +127,6 @@ public class NetworkPowerManager {
|
||||
updateNetorkStorage();
|
||||
networkPowerTracker.tickStart(energyStored);
|
||||
|
||||
updateActiveState();
|
||||
|
||||
capSupply.init();
|
||||
|
||||
int appliedCount = 0;
|
||||
@@ -252,25 +245,6 @@ public class NetworkPowerManager {
|
||||
return result;
|
||||
}
|
||||
|
||||
private void updateActiveState() {
|
||||
boolean active;
|
||||
if(energyStored > 0) {
|
||||
ticksWithNoPower = 0;
|
||||
active = true;
|
||||
} else {
|
||||
ticksWithNoPower++;
|
||||
active = false;
|
||||
}
|
||||
|
||||
boolean doRender = active != lastActiveValue && (active || (!active && ticksWithNoPower > updateRenderTicks));
|
||||
if(doRender) {
|
||||
lastActiveValue = active;
|
||||
//for (IPowerConduit con : network.getConduits()) {
|
||||
//con.setActive(active);
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
private void distributeStorageToConduits() {
|
||||
if(maxEnergyStored <= 0 || energyStored <= 0) {
|
||||
for (IPowerConduit con : network.getConduits()) {
|
||||
@@ -424,7 +398,7 @@ public class NetworkPowerManager {
|
||||
|
||||
filledRatio = 0;
|
||||
if(maxToBalance > 0) {
|
||||
filledRatio = (float) toBalance / maxToBalance;
|
||||
filledRatio = toBalance / maxToBalance;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -522,7 +496,7 @@ public class NetworkPowerManager {
|
||||
|
||||
private CapBankSupplyEntry(TileCapacitorBank capBank, int available, int canFill, IPowerConduit emmiter, ForgeDirection direction) {
|
||||
this.capBank = capBank;
|
||||
this.canExtract = available;
|
||||
canExtract = available;
|
||||
this.canFill = canFill;
|
||||
this.emmiter = emmiter;
|
||||
this.direction = direction;
|
||||
|
||||
@@ -1,24 +1,25 @@
|
||||
package crazypants.enderio.conduit.power;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import crazypants.enderio.power.PerTickIntAverageCalculator;
|
||||
|
||||
|
||||
public class PowerTracker {
|
||||
|
||||
private float previousStorageLevel = -1;
|
||||
private long previousStorageLevel = -1;
|
||||
|
||||
private final TickTracker recTracker = new TickTracker();
|
||||
private final PerTickIntAverageCalculator recTracker = new PerTickIntAverageCalculator();
|
||||
|
||||
private final TickTracker sentTracker = new TickTracker();
|
||||
private final PerTickIntAverageCalculator sentTracker = new PerTickIntAverageCalculator();
|
||||
|
||||
private int sentThisTick = 0;
|
||||
|
||||
private int recievedThisTick = 0;
|
||||
|
||||
public void tickStart(float storedEnergy) {
|
||||
double curStorage = storedEnergy;
|
||||
public void tickStart(long storedEnergy) {
|
||||
long curStorage = storedEnergy;
|
||||
|
||||
if(previousStorageLevel > -1) {
|
||||
double recieved = curStorage - previousStorageLevel;
|
||||
long recieved = curStorage - previousStorageLevel;
|
||||
recieved = Math.max(0, recieved);
|
||||
recievedThisTick += recieved;
|
||||
}
|
||||
@@ -32,7 +33,7 @@ public class PowerTracker {
|
||||
sentThisTick += power;
|
||||
}
|
||||
|
||||
public void tickEnd(int storedEnergy) {
|
||||
public void tickEnd(long storedEnergy) {
|
||||
previousStorageLevel = storedEnergy;
|
||||
sentTracker.tick(sentThisTick);
|
||||
recTracker.tick(recievedThisTick);
|
||||
@@ -41,59 +42,11 @@ public class PowerTracker {
|
||||
}
|
||||
|
||||
public float getAverageRfTickRecieved() {
|
||||
return recTracker.getRFT();
|
||||
return recTracker.getAverage();
|
||||
}
|
||||
|
||||
public float getAverageRfTickSent() {
|
||||
return sentTracker.getRFT();
|
||||
}
|
||||
|
||||
private static class TickTracker {
|
||||
|
||||
private float lastSecondTotal = 0;
|
||||
private int index = 0;
|
||||
private LimitedQueue<Float> lastFiveSeconds = new LimitedQueue<Float>(5);
|
||||
|
||||
float getRFT() {
|
||||
int numTicks = index + (lastFiveSeconds.size() * 20);
|
||||
if(numTicks == 0) {
|
||||
return 0;
|
||||
}
|
||||
float totalPower = lastSecondTotal;
|
||||
for (Float fl : lastFiveSeconds) {
|
||||
totalPower += fl;
|
||||
}
|
||||
return totalPower / numTicks;
|
||||
}
|
||||
|
||||
void tick(int power) {
|
||||
lastSecondTotal += power;
|
||||
index++;
|
||||
if(index == 20) {
|
||||
lastFiveSeconds.add(lastSecondTotal);
|
||||
lastSecondTotal = 0;
|
||||
index = 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class LimitedQueue<E> extends LinkedList<E> {
|
||||
|
||||
private final int limit;
|
||||
|
||||
public LimitedQueue(int limit) {
|
||||
this.limit = limit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(E o) {
|
||||
super.add(o);
|
||||
while (size() > limit) {
|
||||
super.remove();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return sentTracker.getAverage();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,7 +25,7 @@ import crazypants.enderio.conduit.power.PowerConduitNetwork;
|
||||
import crazypants.enderio.conduit.power.PowerTracker;
|
||||
import crazypants.enderio.machine.power.PowerDisplayUtil;
|
||||
import crazypants.enderio.power.IInternalPowerReceptor;
|
||||
import crazypants.enderio.power.PowerInterfaceRF;
|
||||
import crazypants.enderio.power.EnergyHandlerPI;
|
||||
import crazypants.util.Lang;
|
||||
|
||||
public class PacketConduitProbe implements IMessage, IMessageHandler<PacketConduitProbe, IMessage> {
|
||||
@@ -120,7 +120,7 @@ public class PacketConduitProbe implements IMessage, IMessageHandler<PacketCondu
|
||||
} else if(te instanceof IInternalPowerReceptor) {
|
||||
IInternalPowerReceptor pr = (IInternalPowerReceptor) te;
|
||||
sendPowerReciptorInfo(player, block, pr.getEnergyStored(null), pr.getMaxEnergyStored(null), 0,
|
||||
0, PowerInterfaceRF.getPowerRequest(ForgeDirection.NORTH, pr));
|
||||
0, EnergyHandlerPI.getPowerRequest(ForgeDirection.NORTH, pr));
|
||||
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -540,7 +540,7 @@ public abstract class AbstractMachineEntity extends TileEntityEio implements ISi
|
||||
float storedEnergyMJ = nbtRoot.getFloat("storedEnergy");
|
||||
energy = (int)(storedEnergyMJ * 10);
|
||||
} else {
|
||||
energy = nbtRoot.getInteger("storedEnergyRF");
|
||||
energy = nbtRoot.getInteger(PowerHandlerUtil.STORED_ENERGY_NBT_KEY);
|
||||
}
|
||||
setEnergyStored(energy);
|
||||
|
||||
@@ -600,7 +600,7 @@ public abstract class AbstractMachineEntity extends TileEntityEio implements ISi
|
||||
* Write state common to both block and item
|
||||
*/
|
||||
public void writeCommon(NBTTagCompound nbtRoot) {
|
||||
nbtRoot.setInteger("storedEnergyRF", storedEnergyRF);
|
||||
nbtRoot.setInteger(PowerHandlerUtil.STORED_ENERGY_NBT_KEY, storedEnergyRF);
|
||||
nbtRoot.setShort("capacitorType", (short) capacitorType.ordinal());
|
||||
|
||||
// write inventory list
|
||||
|
||||
@@ -8,11 +8,14 @@ import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
@@ -29,8 +32,7 @@ import crazypants.enderio.ModObject;
|
||||
import crazypants.enderio.gui.IAdvancedTooltipProvider;
|
||||
import crazypants.enderio.gui.TooltipAddera;
|
||||
import crazypants.enderio.machine.IoMode;
|
||||
import crazypants.enderio.machine.capbank.network.CapBankClientNetwork;
|
||||
import crazypants.enderio.machine.capbank.network.ClientNetworkManager;
|
||||
import crazypants.enderio.machine.capbank.network.ICapBankNetwork;
|
||||
import crazypants.enderio.machine.capbank.packet.PacketGuiChange;
|
||||
import crazypants.enderio.machine.capbank.packet.PacketNetworkEnergyRequest;
|
||||
import crazypants.enderio.machine.capbank.packet.PacketNetworkEnergyResponse;
|
||||
@@ -43,6 +45,8 @@ import crazypants.enderio.network.PacketHandler;
|
||||
import crazypants.enderio.power.PowerHandlerUtil;
|
||||
import crazypants.enderio.tool.ToolUtil;
|
||||
import crazypants.enderio.waila.IWailaInfoProvider;
|
||||
import crazypants.util.Lang;
|
||||
import crazypants.util.Util;
|
||||
import crazypants.vecmath.Vector3d;
|
||||
|
||||
public class BlockCapBank extends BlockEio implements IGuiHandler, IAdvancedTooltipProvider, IWailaInfoProvider {
|
||||
@@ -123,7 +127,7 @@ public class BlockCapBank extends BlockEio implements IGuiHandler, IAdvancedTool
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addBasicEntries(ItemStack itemstack, EntityPlayer entityplayer, List list, boolean flag) {
|
||||
public void addBasicEntries(ItemStack itemstack, EntityPlayer entityplayer, List list, boolean flag) {
|
||||
list.add(PowerDisplayUtil.formatStoredPower(PowerHandlerUtil.getStoredEnergyForItem(itemstack), CapBankType.getTypeFromMeta(itemstack.getItemDamage())
|
||||
.getMaxEnergyStored()));
|
||||
}
|
||||
@@ -277,22 +281,6 @@ public class BlockCapBank extends BlockEio implements IGuiHandler, IAdvancedTool
|
||||
return lockedIcons[meta];
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void onBlockAdded(World world, int x, int y, int z) {
|
||||
// if(world.isRemote) {
|
||||
// return;
|
||||
// }
|
||||
// TileEntity te = world.getTileEntity(x, y, z);
|
||||
// if(te instanceof TileCapacitorBank) {
|
||||
// TileCapacitorBank tr = (TileCapacitorBank) te;
|
||||
// int meta = world.getBlockMetadata(x, y, z);
|
||||
// if(meta == 1) {
|
||||
// tr.setCreativeMode();
|
||||
// }
|
||||
// tr.onBlockAdded();
|
||||
// }
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void onNeighborBlockChange(World world, int x, int y, int z, Block blockId) {
|
||||
if(world.isRemote) {
|
||||
@@ -306,83 +294,107 @@ public class BlockCapBank extends BlockEio implements IGuiHandler, IAdvancedTool
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) {
|
||||
ArrayList<ItemStack> ret = new ArrayList<ItemStack>();
|
||||
// if(!world.isRemote) {
|
||||
// TileEntity te = world.getTileEntity(x, y, z);
|
||||
// if(te instanceof TileCapBank) {
|
||||
// TileCapBank cb = (TileCapBank) te;
|
||||
// cb.onBreakBlock();
|
||||
//
|
||||
// ItemStack itemStack =
|
||||
// BlockItemCapacitorBank.createItemStackWithPower(cb.doGetEnergyStored());
|
||||
// ret.add(itemStack);
|
||||
// }
|
||||
// }
|
||||
return ret;
|
||||
public int quantityDropped(Random r) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z) {
|
||||
if(!world.isRemote) {
|
||||
// TileEntity te = world.getTileEntity(x, y, z);
|
||||
// if(te instanceof TileCapBank) {
|
||||
// TileCapBank cb = (TileCapBank) te;
|
||||
// cb.onBreakBlock();
|
||||
//
|
||||
// // If we are not in Creative or blockCapBankAllwaysDrop is set to true, allow the item drop.
|
||||
// // This option allows creative players to pick up broken capacitor banks
|
||||
//
|
||||
// if(!player.capabilities.isCreativeMode || "true".equalsIgnoreCase(System.getProperty("blockCapBankAllwaysDrop"))) {
|
||||
// ItemStack itemStack =
|
||||
// BlockItemCapacitorBank.createItemStackWithPower(cb.doGetEnergyStored());
|
||||
// if(cb.isCreative()) {
|
||||
// itemStack.setItemDamage(1);
|
||||
// }
|
||||
// float f = 0.7F;
|
||||
// double d0 = world.rand.nextFloat() * f + (1.0F - f) * 0.5D;
|
||||
// double d1 = world.rand.nextFloat() * f + (1.0F - f) * 0.5D;
|
||||
// double d2 = world.rand.nextFloat() * f + (1.0F - f) * 0.5D;
|
||||
// EntityItem entityitem = new EntityItem(world, x + d0, y + d1, z + d2, itemStack);
|
||||
// entityitem.delayBeforeCanPickup = 10;
|
||||
// world.spawnEntityInWorld(entityitem);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
return super.removedByPlayer(world, player, x, y, z);
|
||||
}
|
||||
// @Override
|
||||
// public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack stack) {
|
||||
// if(world.isRemote) {
|
||||
// return;
|
||||
// }
|
||||
// TileEntity te = world.getTileEntity(x, y, z);
|
||||
// if(!(te instanceof TileCapBank)) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// TileCapBank cb = (TileCapBank) te;
|
||||
// cb.addEnergy(PowerHandlerUtil.getStoredEnergyForItem(stack));
|
||||
//
|
||||
// world.markBlockForUpdate(x, y, z);
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack stack) {
|
||||
if(world.isRemote) {
|
||||
return;
|
||||
}
|
||||
super.onBlockPlacedBy(world, x, y, z, player, stack);
|
||||
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
if(!(te instanceof TileCapBank)) {
|
||||
return;
|
||||
}
|
||||
|
||||
TileCapBank cb = (TileCapBank) te;
|
||||
cb.addEnergy(PowerHandlerUtil.getStoredEnergyForItem(stack));
|
||||
|
||||
if(stack.stackTagCompound != null) {
|
||||
cb.readCommonNBT(stack.stackTagCompound);
|
||||
}
|
||||
if(world.isRemote) {
|
||||
return;
|
||||
}
|
||||
world.markBlockForUpdate(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int quantityDropped(Random r) {
|
||||
return 0;
|
||||
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) {
|
||||
ArrayList<ItemStack> ret = new ArrayList<ItemStack>();
|
||||
if(!world.isRemote) {
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
if(te instanceof TileCapBank) {
|
||||
TileCapBank cb = (TileCapBank) te;
|
||||
ret.add(createItemStack(world, x, y, z, cb));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z) {
|
||||
if(!world.isRemote && (!player.capabilities.isCreativeMode)) {
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
if(te instanceof TileCapBank) {
|
||||
TileCapBank cb = (TileCapBank) te;
|
||||
cb.moveInventoryToNetwork();
|
||||
|
||||
ItemStack itemStack = createItemStack(world, x, y, z, cb);
|
||||
|
||||
//Clear in the inventory as its now in the item stack
|
||||
for (int i = 0; i < cb.getInventory().length; i++) {
|
||||
cb.getInventory()[i] = null;
|
||||
}
|
||||
|
||||
float f = 0.7F;
|
||||
double d0 = world.rand.nextFloat() * f + (1.0F - f) * 0.5D;
|
||||
double d1 = world.rand.nextFloat() * f + (1.0F - f) * 0.5D;
|
||||
double d2 = world.rand.nextFloat() * f + (1.0F - f) * 0.5D;
|
||||
EntityItem entityitem = new EntityItem(world, x + d0, y + d1, z + d2, itemStack);
|
||||
entityitem.delayBeforeCanPickup = 10;
|
||||
|
||||
world.spawnEntityInWorld(entityitem);
|
||||
}
|
||||
}
|
||||
return super.removedByPlayer(world, player, x, y, z);
|
||||
}
|
||||
|
||||
protected ItemStack createItemStack(World world, int x, int y, int z, TileCapBank cb) {
|
||||
int meta = damageDropped(world.getBlockMetadata(x, y, z));
|
||||
ItemStack itemStack = new ItemStack(this, 1, meta);
|
||||
itemStack.stackTagCompound = new NBTTagCompound();
|
||||
cb.writeCommonNBT(itemStack.stackTagCompound);
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breakBlock(World world, int x, int y, int z, Block par5, int par6) {
|
||||
if(!world.isRemote && world.getGameRules().getGameRuleBooleanValue("doTileDrops")) {
|
||||
// TileEntity te = world.getTileEntity(x, y, z);
|
||||
// if(!(te instanceof TileCapacitorBank)) {
|
||||
// super.breakBlock(world, x, y, z, par5, par6);
|
||||
// return;
|
||||
// }
|
||||
// TileCapacitorBank cb = (TileCapacitorBank) te;
|
||||
// Util.dropItems(world, cb, x, y, z, true);
|
||||
if(!world.isRemote) {
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
if(!(te instanceof TileCapBank)) {
|
||||
super.breakBlock(world, x, y, z, par5, par6);
|
||||
return;
|
||||
}
|
||||
TileCapBank cb = (TileCapBank) te;
|
||||
cb.onBreakBlock();
|
||||
if(world.getGameRules().getGameRuleBooleanValue("doTileDrops")) {
|
||||
Util.dropItems(world, cb.getInventory(), x, y, z, true);
|
||||
}
|
||||
}
|
||||
world.removeTileEntity(x, y, z);
|
||||
}
|
||||
@@ -395,7 +407,7 @@ public class BlockCapBank extends BlockEio implements IGuiHandler, IAdvancedTool
|
||||
return super.getSelectedBoundingBoxFromPool(world, x, y, z);
|
||||
}
|
||||
TileCapBank tr = (TileCapBank) te;
|
||||
CapBankClientNetwork network = ClientNetworkManager.getInstance().getNetwork(tr);
|
||||
ICapBankNetwork network = tr.getNetwork();
|
||||
|
||||
if(!tr.getType().isMultiblock() || network == null) {
|
||||
return super.getSelectedBoundingBoxFromPool(world, x, y, z);
|
||||
@@ -430,15 +442,48 @@ public class BlockCapBank extends BlockEio implements IGuiHandler, IAdvancedTool
|
||||
|
||||
@Override
|
||||
public void getWailaInfo(List<String> tooltip, EntityPlayer player, World world, int x, int y, int z) {
|
||||
// TileEntity te = world.getTileEntity(x, y, z);
|
||||
// if (te instanceof TileCapBank) {
|
||||
// TileCapBank cap = (TileCapBank) te;
|
||||
// String format = Util.TAB + Util.ALIGNRIGHT + EnumChatFormatting.WHITE;
|
||||
//
|
||||
// tooltip.add(String.format("%s : %s%s%sRF/t ", Lang.localize("capbank.maxIO"), format, fmt.format(cap.getMaxIO()), Util.TAB + Util.ALIGNRIGHT));
|
||||
// tooltip.add(String.format("%s : %s%s%sRF/t ", Lang.localize("capbank.maxIn"), format, fmt.format(cap.getMaxInput()), Util.TAB + Util.ALIGNRIGHT));
|
||||
// tooltip.add(String.format("%s : %s%s%sRF/t ", Lang.localize("capbank.maxOut"), format, fmt.format(cap.getMaxOutput()), Util.TAB + Util.ALIGNRIGHT));
|
||||
// }
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
if(te instanceof TileCapBank) {
|
||||
TileCapBank cap = (TileCapBank) te;
|
||||
if(cap.getNetwork() != null) {
|
||||
if(world.isRemote && world.getTotalWorldTime() % 20 == 0) {
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketNetworkStateRequest(cap));
|
||||
} else if(world.isRemote && world.getTotalWorldTime() % 2 == 0) {
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketNetworkEnergyRequest(cap));
|
||||
}
|
||||
ICapBankNetwork nw = cap.getNetwork();
|
||||
|
||||
String format = Util.TAB + Util.ALIGNRIGHT + EnumChatFormatting.WHITE;
|
||||
if(TooltipAddera.showAdvancedTooltips()) {
|
||||
tooltip.add(String.format("%s : %s%s%sRF/t ", Lang.localize("capbank.maxIO"), format, fmt.format(nw.getMaxIO()), Util.TAB + Util.ALIGNRIGHT));
|
||||
tooltip
|
||||
.add(String.format("%s : %s%s%sRF/t ", Lang.localize("capbank.maxIn"), format, fmt.format(nw.getMaxEnergyRecieved()), Util.TAB + Util.ALIGNRIGHT));
|
||||
tooltip
|
||||
.add(String.format("%s : %s%s%sRF/t ", Lang.localize("capbank.maxOut"), format, fmt.format(nw.getMaxEnergySent()), Util.TAB + Util.ALIGNRIGHT));
|
||||
|
||||
tooltip.add("");
|
||||
}
|
||||
|
||||
long stored = nw.getEnergyStored();
|
||||
long max = nw.getMaxEnergyStored();
|
||||
tooltip.add(String.format("%s%s%s / %s%s%s RF", EnumChatFormatting.WHITE, fmt.format(stored), EnumChatFormatting.RESET, EnumChatFormatting.WHITE,
|
||||
fmt.format(max),
|
||||
EnumChatFormatting.RESET));
|
||||
|
||||
float change = nw.getAverageChangePerTick();
|
||||
String color = EnumChatFormatting.WHITE.toString();
|
||||
if(change > 0) {
|
||||
color = EnumChatFormatting.GREEN.toString() + "+";
|
||||
} else if(change < 0) {
|
||||
color = EnumChatFormatting.RED.toString();
|
||||
}
|
||||
tooltip
|
||||
.add(String.format("%s%s%sRF/t ", color, fmt.format(change), " " + EnumChatFormatting.RESET.toString()));
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -13,6 +13,8 @@ public class BlockItemCapBank extends ItemBlock implements IEnergyContainerItem
|
||||
public static ItemStack createItemStackWithPower(int meta, int storedEnergy) {
|
||||
ItemStack res = new ItemStack(EnderIO.blockCapBank, 1, meta);
|
||||
PowerHandlerUtil.setStoredEnergyForItem(res, storedEnergy);
|
||||
CapBankType type = CapBankType.getTypeFromMeta(meta);
|
||||
type.writeTypeToNBT(res.stackTagCompound);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package crazypants.enderio.machine.capbank;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import crazypants.enderio.config.Config;
|
||||
|
||||
@@ -117,4 +118,15 @@ public class CapBankType {
|
||||
return uid;
|
||||
}
|
||||
|
||||
public void writeTypeToNBT(NBTTagCompound nbtRoot) {
|
||||
nbtRoot.setString("type", getUid());
|
||||
}
|
||||
|
||||
public static CapBankType readTypeFromNBT(NBTTagCompound nbtRoot) {
|
||||
if(nbtRoot == null || !nbtRoot.hasKey("type")) {
|
||||
return BASIC;
|
||||
}
|
||||
return getTypeFromUID(nbtRoot.getString("type"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,10 +4,99 @@ import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemArmor;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import crazypants.enderio.machine.capbank.network.InventoryImpl;
|
||||
|
||||
public class ContainerCapBank extends Container {
|
||||
|
||||
public ContainerCapBank(Entity player, InventoryPlayer inventory, TileCapBank cb) {
|
||||
private final TileCapBank tileEntity;
|
||||
private final InventoryImpl inv;
|
||||
|
||||
public ContainerCapBank(final Entity player, InventoryPlayer playerInv, TileCapBank cb) {
|
||||
tileEntity = cb;
|
||||
if(tileEntity.getNetwork() != null && tileEntity.getNetwork().getInventory() != null) {
|
||||
inv = cb.getNetwork().getInventory();
|
||||
} else {
|
||||
inv = new InventoryImpl();
|
||||
}
|
||||
|
||||
int armorOffset = 21;
|
||||
addSlotToContainer(new Slot(inv, 0, 59 + armorOffset, 59) {
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack itemStack) {
|
||||
return inv.isItemValidForSlot(0, itemStack);
|
||||
}
|
||||
});
|
||||
|
||||
addSlotToContainer(new Slot(inv, 1, 79 + armorOffset, 59) {
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack itemStack) {
|
||||
return inv.isItemValidForSlot(1, itemStack);
|
||||
}
|
||||
});
|
||||
|
||||
addSlotToContainer(new Slot(inv, 2, 99 + armorOffset, 59) {
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack itemStack) {
|
||||
return inv.isItemValidForSlot(2, itemStack);
|
||||
}
|
||||
});
|
||||
|
||||
addSlotToContainer(new Slot(inv, 3, 119 + armorOffset, 59) {
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack itemStack) {
|
||||
return inv.isItemValidForSlot(3, itemStack);
|
||||
}
|
||||
});
|
||||
|
||||
// add players inventory
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
for (int j = 0; j < 9; ++j) {
|
||||
addSlotToContainer(new Slot(playerInv, j + i * 9 + 9, +armorOffset + 8 + j * 18, 84 + i * 18));
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < 9; ++i) {
|
||||
addSlotToContainer(new Slot(playerInv, i, +armorOffset + 8 + i * 18, 142));
|
||||
}
|
||||
|
||||
//armor slots
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
final int k = i;
|
||||
addSlotToContainer(new Slot(playerInv, playerInv.getSizeInventory() - 1 - i, -15 + armorOffset, 30 + i * 18) {
|
||||
|
||||
@Override
|
||||
public int getSlotStackLimit() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack par1ItemStack) {
|
||||
if(par1ItemStack == null) {
|
||||
return false;
|
||||
}
|
||||
return par1ItemStack.getItem().isValidArmor(par1ItemStack, k, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getBackgroundIconIndex() {
|
||||
return ItemArmor.func_94602_b(k);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void updateInventory() {
|
||||
if(tileEntity.getNetwork() != null && tileEntity.getNetwork().getInventory() != null) {
|
||||
inv.setCapBank(tileEntity.getNetwork().getInventory().getCapBank());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -15,4 +104,79 @@ public class ContainerCapBank extends Container {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer entityPlayer, int slotIndex) {
|
||||
|
||||
int startPlayerSlot = 4;
|
||||
int endPlayerSlot = startPlayerSlot + 26;
|
||||
int startHotBarSlot = endPlayerSlot + 1;
|
||||
int endHotBarSlot = startHotBarSlot + 9;
|
||||
|
||||
ItemStack copystack = null;
|
||||
Slot slot = (Slot) inventorySlots.get(slotIndex);
|
||||
if(slot != null && slot.getHasStack()) {
|
||||
|
||||
ItemStack origStack = slot.getStack();
|
||||
copystack = origStack.copy();
|
||||
|
||||
if(slotIndex < 4) {
|
||||
// merge from machine input slots to inventory
|
||||
if(!mergeItemStackIntoArmor(entityPlayer, origStack, slotIndex)) {
|
||||
if(!mergeItemStack(origStack, startPlayerSlot, endHotBarSlot, false)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
//Check from inv-> charge then inv->hotbar or hotbar->inv
|
||||
if(slotIndex >= startPlayerSlot) {
|
||||
if(!inv.isItemValidForSlot(0, origStack) || !mergeItemStack(origStack, 0, 4, false)) {
|
||||
|
||||
if(slotIndex <= endPlayerSlot) {
|
||||
if(!mergeItemStack(origStack, startHotBarSlot, endHotBarSlot, false)) {
|
||||
return null;
|
||||
}
|
||||
} else if(slotIndex >= startHotBarSlot && slotIndex <= endHotBarSlot) {
|
||||
if(!mergeItemStack(origStack, startPlayerSlot, endPlayerSlot, false)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(origStack.stackSize == 0) {
|
||||
slot.putStack((ItemStack) null);
|
||||
} else {
|
||||
slot.onSlotChanged();
|
||||
}
|
||||
|
||||
slot.onSlotChanged();
|
||||
|
||||
if(origStack.stackSize == copystack.stackSize) {
|
||||
return null;
|
||||
}
|
||||
|
||||
slot.onPickupFromSlot(entityPlayer, origStack);
|
||||
}
|
||||
|
||||
return copystack;
|
||||
}
|
||||
|
||||
private boolean mergeItemStackIntoArmor(EntityPlayer entityPlayer, ItemStack origStack, int slotIndex) {
|
||||
if(origStack == null || !(origStack.getItem() instanceof ItemArmor)) {
|
||||
return false;
|
||||
}
|
||||
ItemArmor armor = (ItemArmor) origStack.getItem();
|
||||
int index = 3 - armor.armorType;
|
||||
ItemStack[] ai = entityPlayer.inventory.armorInventory;
|
||||
if(ai[index] == null) {
|
||||
ai[index] = origStack.copy();
|
||||
origStack.stackSize = 0;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,7 +23,6 @@ import crazypants.enderio.machine.IRedstoneModeControlable;
|
||||
import crazypants.enderio.machine.IoMode;
|
||||
import crazypants.enderio.machine.RedstoneControlMode;
|
||||
import crazypants.enderio.machine.capbank.network.CapBankClientNetwork;
|
||||
import crazypants.enderio.machine.capbank.network.ClientNetworkManager;
|
||||
import crazypants.enderio.machine.capbank.network.NetworkState;
|
||||
import crazypants.enderio.machine.capbank.packet.PacketGuiChange;
|
||||
import crazypants.enderio.machine.capbank.packet.PacketNetworkEnergyRequest;
|
||||
@@ -78,9 +77,12 @@ public class GuiCapBank extends GuiContainerBase {
|
||||
private int initialStateCount = -1;
|
||||
private boolean initState = true;
|
||||
|
||||
private final ContainerCapBank container;
|
||||
|
||||
public GuiCapBank(Entity player, InventoryPlayer playerInv, TileCapBank te) {
|
||||
super(new ContainerCapBank(player, playerInv, te));
|
||||
capBank = te;
|
||||
container = (ContainerCapBank) inventorySlots;
|
||||
|
||||
updateState();
|
||||
|
||||
@@ -135,7 +137,6 @@ public class GuiCapBank extends GuiContainerBase {
|
||||
configB.setToolTip(Lang.localize("gui.machine.ioMode.overlay.tooltip"));
|
||||
|
||||
List<BlockCoord> coords = new ArrayList<BlockCoord>();
|
||||
CapBankClientNetwork network = ClientNetworkManager.getInstance().getNetwork(capBank);
|
||||
if(network != null && network.getMembers().size() < 200) {
|
||||
for (TileCapBank cb : network.getMembers()) {
|
||||
coords.add(cb.getLocation());
|
||||
@@ -247,7 +248,7 @@ public class GuiCapBank extends GuiContainerBase {
|
||||
|
||||
protected void sendUpdateToServer() {
|
||||
if(network != NULL_NETWORK) {
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketGuiChange(capBank, network));
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketGuiChange(capBank));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -376,12 +377,12 @@ public class GuiCapBank extends GuiContainerBase {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(capBank.getNetworkId() == -1) {
|
||||
if(capBank.getNetwork() == null) {
|
||||
network = NULL_NETWORK;
|
||||
return true;
|
||||
}
|
||||
if(network == null || network == NULL_NETWORK) {
|
||||
network = ClientNetworkManager.getInstance().getOrCreateNetwork(capBank.getNetworkId());
|
||||
network = (CapBankClientNetwork) capBank.getNetwork();
|
||||
initialStateCount = network.getStateUpdateCount();
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketNetworkStateRequest(capBank));
|
||||
return true;
|
||||
@@ -391,6 +392,7 @@ public class GuiCapBank extends GuiContainerBase {
|
||||
return true;
|
||||
}
|
||||
if(network.getStateUpdateCount() > initialStateCount) {
|
||||
container.updateInventory();
|
||||
updateFieldsFromState();
|
||||
initState = false;
|
||||
return true;
|
||||
|
||||
@@ -11,20 +11,24 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import cofh.api.energy.IEnergyContainerItem;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.TileEntityEio;
|
||||
import crazypants.enderio.conduit.IConduitBundle;
|
||||
import crazypants.enderio.machine.IIoConfigurable;
|
||||
import crazypants.enderio.machine.IoMode;
|
||||
import crazypants.enderio.machine.RedstoneControlMode;
|
||||
import crazypants.enderio.machine.capbank.network.CapBankNetwork;
|
||||
import crazypants.enderio.machine.capbank.network.ClientNetworkManager;
|
||||
import crazypants.enderio.machine.capbank.network.EnergyReceptor;
|
||||
import crazypants.enderio.machine.capbank.network.ICapBankNetwork;
|
||||
import crazypants.enderio.machine.capbank.network.InventoryImpl;
|
||||
import crazypants.enderio.machine.capbank.network.NetworkUtil;
|
||||
import crazypants.enderio.machine.capbank.packet.PacketNetworkIdRequest;
|
||||
import crazypants.enderio.network.PacketHandler;
|
||||
@@ -32,6 +36,9 @@ import crazypants.enderio.power.IInternalPowerReceptor;
|
||||
import crazypants.enderio.power.IPowerInterface;
|
||||
import crazypants.enderio.power.PowerHandlerUtil;
|
||||
import crazypants.util.BlockCoord;
|
||||
import crazypants.util.EntityUtil;
|
||||
import crazypants.util.Util;
|
||||
import crazypants.vecmath.Vector3d;
|
||||
|
||||
public class TileCapBank extends TileEntityEio implements IInternalPowerReceptor, IInventory, IIoConfigurable {
|
||||
|
||||
@@ -52,12 +59,20 @@ public class TileCapBank extends TileEntityEio implements IInternalPowerReceptor
|
||||
private final List<EnergyReceptor> receptors = new ArrayList<EnergyReceptor>();
|
||||
private boolean receptorsDirty = true;
|
||||
|
||||
private CapBankNetwork network;
|
||||
private ICapBankNetwork network;
|
||||
|
||||
private final ItemStack[] inventory;
|
||||
|
||||
public TileCapBank() {
|
||||
inventory = new ItemStack[4];
|
||||
}
|
||||
|
||||
//Client side refernce to look up network state
|
||||
private int networkId = -1;
|
||||
private int idRequestTimer = 0;
|
||||
|
||||
private boolean dropItems;
|
||||
|
||||
@Override
|
||||
public BlockCoord getLocation() {
|
||||
return new BlockCoord(this);
|
||||
@@ -90,11 +105,11 @@ public class TileCapBank extends TileEntityEio implements IInternalPowerReceptor
|
||||
return networkId;
|
||||
}
|
||||
|
||||
public CapBankNetwork getNetwork() {
|
||||
public ICapBankNetwork getNetwork() {
|
||||
return network;
|
||||
}
|
||||
|
||||
public boolean setNetwork(CapBankNetwork network) {
|
||||
public boolean setNetwork(ICapBankNetwork network) {
|
||||
this.network = network;
|
||||
return true;
|
||||
}
|
||||
@@ -119,6 +134,29 @@ public class TileCapBank extends TileEntityEio implements IInternalPowerReceptor
|
||||
}
|
||||
}
|
||||
|
||||
public void moveInventoryToNetwork() {
|
||||
if(network == null) {
|
||||
return;
|
||||
}
|
||||
if(network.getInventory().getCapBank() == this && !InventoryImpl.isInventoryEmtpy(inventory)) {
|
||||
for (TileCapBank cb : network.getMembers()) {
|
||||
if(cb != this) {
|
||||
for (int i = 0; i < inventory.length; i++) {
|
||||
cb.inventory[i] = inventory[i];
|
||||
inventory[i] = null;
|
||||
}
|
||||
network.getInventory().setCapBank(cb);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onBreakBlock() {
|
||||
//If we are holding the networks inventory when we care broken, tranfer it to another member of the network
|
||||
moveInventoryToNetwork();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
if(worldObj.isRemote) {
|
||||
@@ -147,6 +185,8 @@ public class TileCapBank extends TileEntityEio implements IInternalPowerReceptor
|
||||
if(receptorsDirty) {
|
||||
updateReceptors();
|
||||
}
|
||||
|
||||
doDropItems();
|
||||
}
|
||||
|
||||
private void updateNetwork(World world) {
|
||||
@@ -231,6 +271,11 @@ public class TileCapBank extends TileEntityEio implements IInternalPowerReceptor
|
||||
TileEntity te = worldObj.getTileEntity(checkLoc.x, checkLoc.y, checkLoc.z);
|
||||
if(!(te instanceof TileCapBank)) {
|
||||
return PowerHandlerUtil.create(te);
|
||||
} else {
|
||||
TileCapBank other = (TileCapBank) te;
|
||||
if(other.getType() != getType()) {
|
||||
return PowerHandlerUtil.create(te);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -271,11 +316,12 @@ public class TileCapBank extends TileEntityEio implements IInternalPowerReceptor
|
||||
|
||||
receptors.clear();
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
IoMode ioMode = getIoMode(dir);
|
||||
if(ioMode != IoMode.DISABLED && ioMode != IoMode.PULL) {
|
||||
IPowerInterface pi = getReceptorForFace(dir);
|
||||
if(pi != null) {
|
||||
EnergyReceptor er = new EnergyReceptor(this, pi, dir);
|
||||
IPowerInterface pi = getReceptorForFace(dir);
|
||||
if(pi != null) {
|
||||
EnergyReceptor er = new EnergyReceptor(this, pi, dir);
|
||||
validateModeForReceptor(er);
|
||||
IoMode ioMode = getIoMode(dir);
|
||||
if(ioMode != IoMode.DISABLED && ioMode != IoMode.PULL) {
|
||||
receptors.add(er);
|
||||
}
|
||||
}
|
||||
@@ -285,6 +331,23 @@ public class TileCapBank extends TileEntityEio implements IInternalPowerReceptor
|
||||
receptorsDirty = false;
|
||||
}
|
||||
|
||||
private void validateModeForReceptor(EnergyReceptor er) {
|
||||
IoMode ioMode = getIoMode(er.getDir());
|
||||
if(ioMode == IoMode.PUSH_PULL && er.getConduit() == null) {
|
||||
if(er.getReceptor().isOutputOnly()) {
|
||||
setIoMode(er.getDir(), IoMode.PULL, false);
|
||||
} else {
|
||||
setIoMode(er.getDir(), IoMode.PUSH, false);
|
||||
}
|
||||
}
|
||||
if(ioMode == IoMode.PULL && er.getReceptor().isInputOnly()) {
|
||||
setIoMode(er.getDir(), IoMode.PUSH, false);
|
||||
} else if(ioMode == IoMode.PUSH && er.getReceptor().isOutputOnly()) {
|
||||
setIoMode(er.getDir(), IoMode.PULL, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void addEnergy(int energy) {
|
||||
if(network == null) {
|
||||
setEnergyStored(getEnergyStored() + energy);
|
||||
@@ -383,57 +446,57 @@ public class TileCapBank extends TileEntityEio implements IInternalPowerReceptor
|
||||
//------------------- Inventory
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
public ItemStack getStackInSlot(int slot) {
|
||||
if(network == null) {
|
||||
return null;
|
||||
}
|
||||
return network.getInventory().getStackInSlot(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int p_70301_1_) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
public ItemStack decrStackSize(int fromSlot, int amount) {
|
||||
if(network == null) {
|
||||
return null;
|
||||
}
|
||||
return network.getInventory().decrStackSize(fromSlot, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int p_70298_1_, int p_70298_2_) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
public void setInventorySlotContents(int slot, ItemStack itemstack) {
|
||||
if(network == null) {
|
||||
return;
|
||||
}
|
||||
network.getInventory().setInventorySlotContents(slot, itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int p_70304_1_) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int p_70299_1_, ItemStack p_70299_2_) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
public int getSizeInventory() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return EnderIO.blockCapacitorBank.getUnlocalizedName() + ".name";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer p_70300_1_) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -445,18 +508,50 @@ public class TileCapBank extends TileEntityEio implements IInternalPowerReceptor
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int p_94041_1_, ItemStack p_94041_2_) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
public boolean isItemValidForSlot(int slot, ItemStack itemstack) {
|
||||
if(itemstack == null) {
|
||||
return false;
|
||||
}
|
||||
return itemstack.getItem() instanceof IEnergyContainerItem;
|
||||
}
|
||||
|
||||
public ItemStack[] getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
public void dropItems() {
|
||||
dropItems = true;
|
||||
}
|
||||
|
||||
public void doDropItems() {
|
||||
if(!dropItems) {
|
||||
return;
|
||||
}
|
||||
Vector3d dropLocation;
|
||||
EntityPlayer player = worldObj.getClosestPlayer(xCoord, yCoord, zCoord, 32);
|
||||
if(player != null) {
|
||||
dropLocation = EntityUtil.getEntityPosition(player);
|
||||
} else {
|
||||
dropLocation = new Vector3d(xCoord, yCoord, zCoord);
|
||||
}
|
||||
Util.dropItems(worldObj, inventory, (int) dropLocation.x, (int) dropLocation.y, (int) dropLocation.z, false);
|
||||
for (int i = 0; i < inventory.length; i++) {
|
||||
inventory[i] = null;
|
||||
}
|
||||
dropItems = false;
|
||||
}
|
||||
|
||||
//---------------- NBT
|
||||
|
||||
@Override
|
||||
protected void writeCustomNBT(NBTTagCompound nbtRoot) {
|
||||
writeCommonNBT(nbtRoot);
|
||||
}
|
||||
|
||||
nbtRoot.setString("type", getType().getUid());
|
||||
nbtRoot.setInteger("energyStored", energyStored);
|
||||
//Values common to both item and block form
|
||||
public void writeCommonNBT(NBTTagCompound nbtRoot) {
|
||||
getType().writeTypeToNBT(nbtRoot);
|
||||
nbtRoot.setInteger(PowerHandlerUtil.STORED_ENERGY_NBT_KEY, energyStored);
|
||||
|
||||
if(maxInput != -1) {
|
||||
nbtRoot.setInteger("maxInput", maxInput);
|
||||
@@ -478,13 +573,28 @@ public class TileCapBank extends TileEntityEio implements IInternalPowerReceptor
|
||||
nbtRoot.setShort("face" + e.getKey().ordinal(), (short) e.getValue().ordinal());
|
||||
}
|
||||
}
|
||||
|
||||
NBTTagList itemList = new NBTTagList();
|
||||
for (int i = 0; i < inventory.length; i++) {
|
||||
if(inventory[i] != null) {
|
||||
NBTTagCompound itemStackNBT = new NBTTagCompound();
|
||||
itemStackNBT.setByte("Slot", (byte) i);
|
||||
inventory[i].writeToNBT(itemStackNBT);
|
||||
itemList.appendTag(itemStackNBT);
|
||||
}
|
||||
}
|
||||
nbtRoot.setTag("Items", itemList);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readCustomNBT(NBTTagCompound nbtRoot) {
|
||||
readCommonNBT(nbtRoot);
|
||||
}
|
||||
|
||||
type = CapBankType.getTypeFromUID(nbtRoot.getString("type"));
|
||||
energyStored = nbtRoot.getInteger("energyStored");
|
||||
//Values common to both item and block form
|
||||
public void readCommonNBT(NBTTagCompound nbtRoot) {
|
||||
type = CapBankType.readTypeFromNBT(nbtRoot);
|
||||
energyStored = nbtRoot.getInteger(PowerHandlerUtil.STORED_ENERGY_NBT_KEY);
|
||||
|
||||
if(nbtRoot.hasKey("maxInput")) {
|
||||
maxInput = nbtRoot.getInteger("maxInput");
|
||||
@@ -516,6 +626,20 @@ public class TileCapBank extends TileEntityEio implements IInternalPowerReceptor
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < inventory.length; i++) {
|
||||
inventory[i] = null;
|
||||
}
|
||||
|
||||
if(nbtRoot.hasKey("Items")) {
|
||||
NBTTagList itemList = (NBTTagList) nbtRoot.getTag("Items");
|
||||
for (int i = 0; i < itemList.tagCount(); i++) {
|
||||
NBTTagCompound itemStack = itemList.getCompoundTagAt(i);
|
||||
byte slot = itemStack.getByte("Slot");
|
||||
if(slot >= 0 && slot < inventory.length) {
|
||||
inventory[slot] = ItemStack.loadItemStackFromNBT(itemStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,11 +1,15 @@
|
||||
package crazypants.enderio.machine.capbank.network;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
import crazypants.enderio.machine.RedstoneControlMode;
|
||||
import crazypants.enderio.machine.capbank.TileCapBank;
|
||||
import crazypants.util.BlockCoord;
|
||||
|
||||
public class CapBankClientNetwork implements ICapBankNetwork {
|
||||
|
||||
@@ -14,7 +18,7 @@ public class CapBankClientNetwork implements ICapBankNetwork {
|
||||
private int maxEnergySent;
|
||||
private int maxEnergyRecieved;
|
||||
|
||||
private int stateUpdateCount = 0;
|
||||
private int stateUpdateCount;
|
||||
private int maxIO;
|
||||
private long maxEnergyStored;
|
||||
private long energyStored;
|
||||
@@ -22,6 +26,10 @@ public class CapBankClientNetwork implements ICapBankNetwork {
|
||||
private RedstoneControlMode inputControlMode = RedstoneControlMode.IGNORE;
|
||||
private RedstoneControlMode outputControlMode = RedstoneControlMode.IGNORE;
|
||||
|
||||
private final InventoryImpl inventory = new InventoryImpl();
|
||||
|
||||
private float aveChange;
|
||||
|
||||
public CapBankClientNetwork(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
@@ -31,7 +39,7 @@ public class CapBankClientNetwork implements ICapBankNetwork {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setState(NetworkState state) {
|
||||
public void setState(World world, NetworkState state) {
|
||||
maxEnergyRecieved = state.getMaxInput();
|
||||
maxEnergySent = state.getMaxOutput();
|
||||
maxIO = state.getMaxIO();
|
||||
@@ -39,6 +47,18 @@ public class CapBankClientNetwork implements ICapBankNetwork {
|
||||
energyStored = state.getEnergyStored();
|
||||
inputControlMode = state.getInputMode();
|
||||
outputControlMode = state.getOutputMode();
|
||||
|
||||
BlockCoord bc = state.getInventoryImplLocation();
|
||||
if(bc == null) {
|
||||
inventory.setCapBank(null);
|
||||
} else {
|
||||
TileEntity te = world.getTileEntity(bc.x, bc.y, bc.z);
|
||||
if(te instanceof TileCapBank) {
|
||||
inventory.setCapBank((TileCapBank) te);
|
||||
}
|
||||
}
|
||||
aveChange = state.getAverageChange();
|
||||
|
||||
stateUpdateCount++;
|
||||
}
|
||||
|
||||
@@ -50,6 +70,7 @@ public class CapBankClientNetwork implements ICapBankNetwork {
|
||||
this.stateUpdateCount = stateUpdateCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addMember(TileCapBank capBank) {
|
||||
members.add(capBank);
|
||||
}
|
||||
@@ -63,6 +84,7 @@ public class CapBankClientNetwork implements ICapBankNetwork {
|
||||
public void destroyNetwork() {
|
||||
for (TileCapBank cb : members) {
|
||||
cb.setNetworkId(-1);
|
||||
cb.setNetwork(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,4 +154,48 @@ public class CapBankClientNetwork implements ICapBankNetwork {
|
||||
this.outputControlMode = outputControlMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryImpl getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getAverageChangePerTick() {
|
||||
return aveChange;
|
||||
}
|
||||
|
||||
public void setAverageChangePerTick(float aveChange) {
|
||||
this.aveChange = aveChange;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkState getState() {
|
||||
return new NetworkState(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdateEntity(TileCapBank tileCapBank) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addEnergy(int energy) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int recieveEnergy(int maxReceive, boolean simulate) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeReceptors(Collection<EnergyReceptor> receptors) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addReceptors(Collection<EnergyReceptor> receptors) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateRedstoneSignal(TileCapBank tileCapBank, boolean recievingSignal) {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,7 +7,9 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import cofh.api.energy.IEnergyContainerItem;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent.ServerTickEvent;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.conduit.ConduitNetworkTickHandler;
|
||||
@@ -20,6 +22,7 @@ import crazypants.enderio.machine.capbank.CapBankType;
|
||||
import crazypants.enderio.machine.capbank.TileCapBank;
|
||||
import crazypants.enderio.machine.capbank.packet.PacketNetworkStateResponse;
|
||||
import crazypants.enderio.power.IPowerInterface;
|
||||
import crazypants.enderio.power.PerTickIntAverageCalculator;
|
||||
import crazypants.util.BlockCoord;
|
||||
import crazypants.util.RoundRobinIterator;
|
||||
|
||||
@@ -59,6 +62,10 @@ public class CapBankNetwork implements ICapBankNetwork {
|
||||
|
||||
private TickListener tickListener;
|
||||
|
||||
private PerTickIntAverageCalculator powerTracker = new PerTickIntAverageCalculator();
|
||||
|
||||
private final InventoryImpl inventory = new InventoryImpl();
|
||||
|
||||
public CapBankNetwork(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
@@ -82,19 +89,13 @@ public class CapBankNetwork implements ICapBankNetwork {
|
||||
}
|
||||
}
|
||||
setNetwork(world, cap);
|
||||
//notifyNetworkOfUpdate();
|
||||
EnderIO.packetPipeline.sendToAllAround(new PacketNetworkStateResponse(this), cap);
|
||||
}
|
||||
|
||||
//public void notifyNetworkOfUpdate() {
|
||||
// for (TileCapBank cb : capBanks) {
|
||||
// cb.getWorldObj().markBlockForUpdate(cb.xCoord, cb.yCoord, cb.zCoord);
|
||||
// }
|
||||
// }
|
||||
|
||||
protected void setNetwork(World world, TileCapBank cap) {
|
||||
if(cap != null && cap.setNetwork(this)) {
|
||||
addCapBank(cap);
|
||||
addMember(cap);
|
||||
Collection<TileCapBank> neighbours = NetworkUtil.getNeigbours(cap);
|
||||
for (TileCapBank neighbour : neighbours) {
|
||||
if(neighbour.getNetwork() == null) {
|
||||
@@ -128,7 +129,8 @@ public class CapBankNetwork implements ICapBankNetwork {
|
||||
return capBanks;
|
||||
}
|
||||
|
||||
public void addCapBank(TileCapBank cap) {
|
||||
@Override
|
||||
public void addMember(TileCapBank cap) {
|
||||
if(!capBanks.contains(cap)) {
|
||||
capBanks.add(cap);
|
||||
long newIO = maxIO + cap.getType().getMaxIO();
|
||||
@@ -153,20 +155,37 @@ public class CapBankNetwork implements ICapBankNetwork {
|
||||
addReceptors(recs);
|
||||
}
|
||||
|
||||
if(inventory.isEmtpy()) {
|
||||
inventory.setCapBank(cap);
|
||||
} else if(!InventoryImpl.isInventoryEmtpy(cap)) {
|
||||
if(inventory.isEmtpy()) {
|
||||
inventory.setCapBank(cap);
|
||||
} else {
|
||||
cap.dropItems();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryImpl getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public NetworkState getClientState() {
|
||||
@Override
|
||||
public NetworkState getState() {
|
||||
return new NetworkState(this);
|
||||
}
|
||||
|
||||
//--------- Tick Handling
|
||||
|
||||
@Override
|
||||
public void onUpdateEntity(TileCapBank tileCapBank) {
|
||||
World world = tileCapBank.getWorldObj();
|
||||
if(world == null) {
|
||||
@@ -183,12 +202,18 @@ public class CapBankNetwork implements ICapBankNetwork {
|
||||
}
|
||||
|
||||
private void doNetworkTick() {
|
||||
|
||||
chargeItems(inventory.getStacks());
|
||||
transmitEnergy();
|
||||
|
||||
if(energyStored != prevEnergyStored) {
|
||||
distributeEnergyToBanks();
|
||||
}
|
||||
if(prevEnergyStored != -1) {
|
||||
powerTracker.tick((int) (energyStored - prevEnergyStored));
|
||||
}
|
||||
prevEnergyStored = energyStored;
|
||||
|
||||
}
|
||||
|
||||
private void transmitEnergy() {
|
||||
@@ -201,12 +226,7 @@ public class CapBankNetwork implements ICapBankNetwork {
|
||||
return;
|
||||
}
|
||||
|
||||
int available;
|
||||
if(energyStored > getMaxEnergySent()) {
|
||||
available = getMaxEnergySent();
|
||||
} else {
|
||||
available = (int) energyStored;
|
||||
}
|
||||
int available = getEnergyAvailableForTick(getMaxEnergySent());
|
||||
if(available <= 0) {
|
||||
return;
|
||||
}
|
||||
@@ -223,8 +243,19 @@ public class CapBankNetwork implements ICapBankNetwork {
|
||||
totalSent += sent;
|
||||
available -= sent;
|
||||
}
|
||||
addEnergy(-totalSent);
|
||||
if(!type.isCreative()) {
|
||||
addEnergy(-totalSent);
|
||||
}
|
||||
}
|
||||
|
||||
protected int getEnergyAvailableForTick(int limit) {
|
||||
int available;
|
||||
if(energyStored > limit) {
|
||||
available = limit;
|
||||
} else {
|
||||
available = (int) energyStored;
|
||||
}
|
||||
return available;
|
||||
}
|
||||
|
||||
private int sendPowerTo(EnergyReceptor next, int available) {
|
||||
@@ -242,6 +273,38 @@ public class CapBankNetwork implements ICapBankNetwork {
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean chargeItems(ItemStack[] items) {
|
||||
if(items == null) {
|
||||
return false;
|
||||
}
|
||||
boolean chargedItem = false;
|
||||
int available = getEnergyAvailableForTick(getMaxIO());
|
||||
for (ItemStack item : items) {
|
||||
if(item != null && available > 0) {
|
||||
int used = 0;
|
||||
if(item.getItem() instanceof IEnergyContainerItem) {
|
||||
IEnergyContainerItem chargable = (IEnergyContainerItem) item.getItem();
|
||||
|
||||
int max = chargable.getMaxEnergyStored(item);
|
||||
int cur = chargable.getEnergyStored(item);
|
||||
int canUse = Math.min(available, max - cur);
|
||||
if(cur < max) {
|
||||
used = chargable.receiveEnergy(item, canUse, false);
|
||||
}
|
||||
|
||||
}
|
||||
if(used > 0) {
|
||||
if(!type.isCreative()) {
|
||||
addEnergy(-used);
|
||||
}
|
||||
chargedItem = true;
|
||||
available -= used;
|
||||
}
|
||||
}
|
||||
}
|
||||
return chargedItem;
|
||||
}
|
||||
|
||||
private void distributeEnergyToBanks() {
|
||||
if(capBanks.isEmpty()) {
|
||||
return;
|
||||
@@ -257,6 +320,12 @@ public class CapBankNetwork implements ICapBankNetwork {
|
||||
|
||||
//------ Power
|
||||
|
||||
@Override
|
||||
public float getAverageChangePerTick() {
|
||||
return powerTracker.getAverage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int recieveEnergy(int maxReceive, boolean simulate) {
|
||||
if(maxReceive <= 0 || !inputRedstoneConditionMet) {
|
||||
return 0;
|
||||
@@ -268,12 +337,16 @@ public class CapBankNetwork implements ICapBankNetwork {
|
||||
}
|
||||
int res = Math.min(maxReceive, (int) spaceAvailable);
|
||||
res = Math.min(maxReceive, getMaxEnergyRecieved());
|
||||
if(!simulate && !type.isCreative()) {
|
||||
addEnergy(res);
|
||||
if(!simulate) {
|
||||
if(!type.isCreative()) {
|
||||
addEnergy(res);
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addEnergy(int energy) {
|
||||
energyStored += energy;
|
||||
if(energyStored > maxEnergyStored) {
|
||||
@@ -288,6 +361,7 @@ public class CapBankNetwork implements ICapBankNetwork {
|
||||
receptorIterator = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addReceptors(Collection<EnergyReceptor> rec) {
|
||||
if(rec.isEmpty()) {
|
||||
return;
|
||||
@@ -296,6 +370,7 @@ public class CapBankNetwork implements ICapBankNetwork {
|
||||
receptorIterator = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeReceptors(Collection<EnergyReceptor> rec) {
|
||||
if(rec.isEmpty()) {
|
||||
return;
|
||||
@@ -408,6 +483,7 @@ public class CapBankNetwork implements ICapBankNetwork {
|
||||
updateRedstoneConditions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateRedstoneSignal(TileCapBank tileCapBank, boolean recievingSignal) {
|
||||
if(recievingSignal) {
|
||||
redstoneRecievers.add(tileCapBank.getLocation());
|
||||
|
||||
@@ -3,6 +3,7 @@ package crazypants.enderio.machine.capbank.network;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
import crazypants.enderio.machine.capbank.TileCapBank;
|
||||
|
||||
public class ClientNetworkManager {
|
||||
@@ -22,20 +23,22 @@ public class ClientNetworkManager {
|
||||
CapBankClientNetwork res = networks.get(id);
|
||||
if(res != null) {
|
||||
res.destroyNetwork();
|
||||
networks.remove(res);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateState(int id, NetworkState state) {
|
||||
public void updateState(World world, int id, NetworkState state) {
|
||||
CapBankClientNetwork network = getOrCreateNetwork(id);
|
||||
network.setState(state);
|
||||
network.setState(world, state);
|
||||
}
|
||||
|
||||
public void updateEnergyStored(int id, long energyStored) {
|
||||
public void updateEnergy(int id, long energyStored, float avChange) {
|
||||
CapBankClientNetwork res = networks.get(id);
|
||||
if(res == null) {
|
||||
return;
|
||||
}
|
||||
res.setEnergyStored(energyStored);
|
||||
res.setAverageChangePerTick(avChange);
|
||||
}
|
||||
|
||||
public CapBankClientNetwork getOrCreateNetwork(int id) {
|
||||
@@ -52,11 +55,4 @@ public class ClientNetworkManager {
|
||||
network.addMember(tileCapBank);
|
||||
}
|
||||
|
||||
public CapBankClientNetwork getNetwork(TileCapBank tr) {
|
||||
if(tr == null) {
|
||||
return null;
|
||||
}
|
||||
return networks.get(tr.getNetworkId());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package crazypants.enderio.machine.capbank.network;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import crazypants.enderio.machine.RedstoneControlMode;
|
||||
@@ -7,13 +8,32 @@ import crazypants.enderio.machine.capbank.TileCapBank;
|
||||
|
||||
public interface ICapBankNetwork {
|
||||
|
||||
//------ Network
|
||||
|
||||
int getId();
|
||||
|
||||
int getMaxIO();
|
||||
void addMember(TileCapBank cap);
|
||||
|
||||
List<TileCapBank> getMembers();
|
||||
|
||||
void destroyNetwork();
|
||||
|
||||
NetworkState getState();
|
||||
|
||||
void onUpdateEntity(TileCapBank tileCapBank);
|
||||
|
||||
|
||||
//------ Energy
|
||||
|
||||
long getEnergyStored();
|
||||
|
||||
void addEnergy(int energy);
|
||||
|
||||
int recieveEnergy(int maxReceive, boolean simulate);
|
||||
|
||||
long getMaxEnergyStored();
|
||||
|
||||
long getEnergyStored();
|
||||
int getMaxIO();
|
||||
|
||||
int getMaxEnergySent();
|
||||
|
||||
@@ -23,16 +43,30 @@ public interface ICapBankNetwork {
|
||||
|
||||
void setMaxEnergyReccieved(int max);
|
||||
|
||||
void destroyNetwork();
|
||||
void removeReceptors(Collection<EnergyReceptor> receptors);
|
||||
|
||||
List<TileCapBank> getMembers();
|
||||
void addReceptors(Collection<EnergyReceptor> receptors);
|
||||
|
||||
public abstract void setOutputControlMode(RedstoneControlMode outputControlMode);
|
||||
|
||||
public abstract RedstoneControlMode getOutputControlMode();
|
||||
//------ Inventory
|
||||
|
||||
InventoryImpl getInventory();
|
||||
|
||||
|
||||
//------ Redstone
|
||||
|
||||
void setOutputControlMode(RedstoneControlMode outputControlMode);
|
||||
|
||||
RedstoneControlMode getOutputControlMode();
|
||||
|
||||
void setInputControlMode(RedstoneControlMode inputControlMode);
|
||||
|
||||
RedstoneControlMode getInputControlMode();
|
||||
|
||||
void updateRedstoneSignal(TileCapBank tileCapBank, boolean recievingSignal);
|
||||
|
||||
public abstract float getAverageChangePerTick();
|
||||
|
||||
public abstract void setInputControlMode(RedstoneControlMode inputControlMode);
|
||||
|
||||
public abstract RedstoneControlMode getInputControlMode();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
package crazypants.enderio.machine.capbank.network;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import cofh.api.energy.IEnergyContainerItem;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.machine.capbank.TileCapBank;
|
||||
|
||||
public class InventoryImpl implements IInventory {
|
||||
|
||||
public static boolean isInventoryEmtpy(TileCapBank cap) {
|
||||
for (ItemStack st : cap.getInventory()) {
|
||||
if(st != null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isInventoryEmtpy(ItemStack[] inv) {
|
||||
if(inv == null) {
|
||||
return true;
|
||||
}
|
||||
for (ItemStack st : inv) {
|
||||
if(st != null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private ItemStack[] inventory;
|
||||
|
||||
private TileCapBank capBank;
|
||||
|
||||
public InventoryImpl() {
|
||||
}
|
||||
|
||||
public TileCapBank getCapBank() {
|
||||
return capBank;
|
||||
}
|
||||
|
||||
public void setCapBank(TileCapBank cap) {
|
||||
capBank = cap;
|
||||
if(cap == null) {
|
||||
inventory = null;
|
||||
return;
|
||||
}
|
||||
inventory = cap.getInventory();
|
||||
}
|
||||
|
||||
public boolean isEmtpy() {
|
||||
return isInventoryEmtpy(inventory);
|
||||
}
|
||||
|
||||
public ItemStack[] getStacks() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slot) {
|
||||
if(inventory == null) {
|
||||
return null;
|
||||
}
|
||||
if(slot < 0 || slot >= inventory.length) {
|
||||
return null;
|
||||
}
|
||||
return inventory[slot];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int fromSlot, int amount) {
|
||||
if(inventory == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if(fromSlot < 0 || fromSlot >= inventory.length) {
|
||||
return null;
|
||||
}
|
||||
ItemStack item = inventory[fromSlot];
|
||||
if(item == null) {
|
||||
return null;
|
||||
}
|
||||
if(item.stackSize <= amount) {
|
||||
ItemStack result = item.copy();
|
||||
inventory[fromSlot] = null;
|
||||
return result;
|
||||
}
|
||||
item.stackSize -= amount;
|
||||
return item.copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int slot, ItemStack itemstack) {
|
||||
if(inventory == null) {
|
||||
return;
|
||||
}
|
||||
if(slot < 0 || slot >= inventory.length) {
|
||||
return;
|
||||
}
|
||||
inventory[slot] = itemstack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
//--- constant values
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int p_70304_1_) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName() {
|
||||
return EnderIO.blockCapBank.getUnlocalizedName() + ".name";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer p_70300_1_) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slot, ItemStack itemstack) {
|
||||
if(itemstack == null) {
|
||||
return false;
|
||||
}
|
||||
return itemstack.getItem() instanceof IEnergyContainerItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,6 +2,8 @@ package crazypants.enderio.machine.capbank.network;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import crazypants.enderio.machine.RedstoneControlMode;
|
||||
import crazypants.enderio.machine.capbank.TileCapBank;
|
||||
import crazypants.util.BlockCoord;
|
||||
|
||||
public class NetworkState {
|
||||
|
||||
@@ -12,20 +14,24 @@ public class NetworkState {
|
||||
private final int maxOutput;
|
||||
private final RedstoneControlMode inputMode;
|
||||
private final RedstoneControlMode outputMode;
|
||||
private final BlockCoord invImplLoc;
|
||||
private final float averageChange;
|
||||
|
||||
public NetworkState() {
|
||||
this(0, 0, 0, 0, 0, RedstoneControlMode.IGNORE, RedstoneControlMode.IGNORE);
|
||||
this(0, 0, 0, 0, 0, RedstoneControlMode.IGNORE, RedstoneControlMode.IGNORE, null, 0);
|
||||
}
|
||||
|
||||
public NetworkState(long energyStored, long maxEnergyStored, int maxIO, int maxInput, int maxOutput, RedstoneControlMode inputMode,
|
||||
RedstoneControlMode ouputMode) {
|
||||
RedstoneControlMode outputMode, BlockCoord invImplLoc, float averageChange) {
|
||||
this.energyStored = energyStored;
|
||||
this.maxEnergyStored = maxEnergyStored;
|
||||
this.maxIO = maxIO;
|
||||
this.maxInput = maxInput;
|
||||
this.maxOutput = maxOutput;
|
||||
this.inputMode = inputMode;
|
||||
outputMode = ouputMode;
|
||||
this.outputMode = outputMode;
|
||||
this.invImplLoc = invImplLoc;
|
||||
this.averageChange = averageChange;
|
||||
}
|
||||
|
||||
public NetworkState(ICapBankNetwork network) {
|
||||
@@ -36,6 +42,13 @@ public class NetworkState {
|
||||
maxOutput = network.getMaxEnergySent();
|
||||
inputMode = network.getInputControlMode();
|
||||
outputMode = network.getOutputControlMode();
|
||||
TileCapBank cb = network.getInventory().getCapBank();
|
||||
if(cb != null) {
|
||||
invImplLoc = cb.getLocation();
|
||||
} else {
|
||||
invImplLoc = null;
|
||||
}
|
||||
averageChange = network.getAverageChangePerTick();
|
||||
}
|
||||
|
||||
public long getEnergyStored() {
|
||||
@@ -66,6 +79,14 @@ public class NetworkState {
|
||||
return outputMode;
|
||||
}
|
||||
|
||||
public BlockCoord getInventoryImplLocation() {
|
||||
return invImplLoc;
|
||||
}
|
||||
|
||||
public float getAverageChange() {
|
||||
return averageChange;
|
||||
}
|
||||
|
||||
public void writeToBuf(ByteBuf buf) {
|
||||
buf.writeLong(energyStored);
|
||||
buf.writeLong(maxEnergyStored);
|
||||
@@ -74,11 +95,17 @@ public class NetworkState {
|
||||
buf.writeInt(maxOutput);
|
||||
buf.writeShort(inputMode.ordinal());
|
||||
buf.writeShort(outputMode.ordinal());
|
||||
buf.writeBoolean(invImplLoc != null);
|
||||
if(invImplLoc != null) {
|
||||
invImplLoc.writeToBuf(buf);
|
||||
}
|
||||
buf.writeFloat(averageChange);
|
||||
}
|
||||
|
||||
public static NetworkState readFromBuf(ByteBuf buf) {
|
||||
return new NetworkState(buf.readLong(), buf.readLong(), buf.readInt(), buf.readInt(), buf.readInt(),
|
||||
RedstoneControlMode.values()[buf.readShort()], RedstoneControlMode.values()[buf.readShort()]);
|
||||
RedstoneControlMode.values()[buf.readShort()], RedstoneControlMode.values()[buf.readShort()],
|
||||
buf.readBoolean() ? BlockCoord.readFromBuf(buf) : null, buf.readFloat());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -47,7 +47,7 @@ public class NetworkUtil {
|
||||
}
|
||||
|
||||
private static boolean reuseNetwork(TileCapBank cap, Collection<TileCapBank> neighbours, World world) {
|
||||
CapBankNetwork network = null;
|
||||
ICapBankNetwork network = null;
|
||||
for (TileCapBank conduit : neighbours) {
|
||||
if(network == null) {
|
||||
network = conduit.getNetwork();
|
||||
@@ -59,7 +59,7 @@ public class NetworkUtil {
|
||||
return false;
|
||||
}
|
||||
if(cap.setNetwork(network)) {
|
||||
network.addCapBank(cap);
|
||||
network.addMember(cap);
|
||||
//network.notifyNetworkOfUpdate();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import crazypants.enderio.machine.RedstoneControlMode;
|
||||
import crazypants.enderio.machine.capbank.TileCapBank;
|
||||
import crazypants.enderio.machine.capbank.network.CapBankClientNetwork;
|
||||
import crazypants.enderio.machine.capbank.network.ICapBankNetwork;
|
||||
|
||||
public class PacketGuiChange extends PacketCapBank<PacketGuiChange, IMessage> {
|
||||
@@ -18,8 +17,9 @@ public class PacketGuiChange extends PacketCapBank<PacketGuiChange, IMessage> {
|
||||
public PacketGuiChange() {
|
||||
}
|
||||
|
||||
public PacketGuiChange(TileCapBank capBank, CapBankClientNetwork network) {
|
||||
public PacketGuiChange(TileCapBank capBank) {
|
||||
super(capBank);
|
||||
ICapBankNetwork network = capBank.getNetwork();
|
||||
maxSend = network.getMaxEnergySent();
|
||||
maxRec = network.getMaxEnergyRecieved();
|
||||
inputMode = network.getInputControlMode();
|
||||
|
||||
+5
-1
@@ -11,6 +11,7 @@ public class PacketNetworkEnergyResponse implements IMessage, IMessageHandler<Pa
|
||||
|
||||
private int id;
|
||||
private long energyStored;
|
||||
private float avChange;
|
||||
|
||||
public PacketNetworkEnergyResponse() {
|
||||
}
|
||||
@@ -18,23 +19,26 @@ public class PacketNetworkEnergyResponse implements IMessage, IMessageHandler<Pa
|
||||
public PacketNetworkEnergyResponse(ICapBankNetwork network) {
|
||||
id = network.getId();
|
||||
energyStored = network.getEnergyStored();
|
||||
avChange = network.getAverageChangePerTick();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeInt(id);
|
||||
buf.writeLong(energyStored);
|
||||
buf.writeFloat(avChange);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
id = buf.readInt();
|
||||
energyStored = buf.readLong();
|
||||
avChange = buf.readFloat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketNetworkEnergyResponse message, MessageContext ctx) {
|
||||
ClientNetworkManager.getInstance().updateEnergyStored(message.id, message.energyStored);
|
||||
ClientNetworkManager.getInstance().updateEnergy(message.id, message.energyStored, message.avChange);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import io.netty.buffer.ByteBuf;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import crazypants.enderio.machine.capbank.TileCapBank;
|
||||
import crazypants.enderio.machine.capbank.network.ClientNetworkManager;
|
||||
|
||||
public class PacketNetworkIdResponse extends PacketCapBank<PacketNetworkIdResponse, IMessage> {
|
||||
|
||||
@@ -36,6 +37,7 @@ public class PacketNetworkIdResponse extends PacketCapBank<PacketNetworkIdRespon
|
||||
@Override
|
||||
protected IMessage handleMessage(TileCapBank te, PacketNetworkIdResponse message, MessageContext ctx) {
|
||||
te.setNetworkId(message.id);
|
||||
te.setNetwork(ClientNetworkManager.getInstance().getOrCreateNetwork(message.id));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
+6
-5
@@ -4,8 +4,9 @@ import io.netty.buffer.ByteBuf;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import crazypants.enderio.machine.capbank.network.CapBankNetwork;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.machine.capbank.network.ClientNetworkManager;
|
||||
import crazypants.enderio.machine.capbank.network.ICapBankNetwork;
|
||||
import crazypants.enderio.machine.capbank.network.NetworkState;
|
||||
|
||||
public class PacketNetworkStateResponse implements IMessage, IMessageHandler<PacketNetworkStateResponse, IMessage> {
|
||||
@@ -16,14 +17,14 @@ public class PacketNetworkStateResponse implements IMessage, IMessageHandler<Pac
|
||||
public PacketNetworkStateResponse() {
|
||||
}
|
||||
|
||||
public PacketNetworkStateResponse(CapBankNetwork network) {
|
||||
public PacketNetworkStateResponse(ICapBankNetwork network) {
|
||||
this(network, false);
|
||||
}
|
||||
|
||||
public PacketNetworkStateResponse(CapBankNetwork network, boolean remove) {
|
||||
public PacketNetworkStateResponse(ICapBankNetwork network, boolean remove) {
|
||||
id = network.getId();
|
||||
if(!remove) {
|
||||
state = network.getClientState();
|
||||
state = network.getState();
|
||||
} else {
|
||||
state = null;
|
||||
}
|
||||
@@ -52,7 +53,7 @@ public class PacketNetworkStateResponse implements IMessage, IMessageHandler<Pac
|
||||
@Override
|
||||
public IMessage onMessage(PacketNetworkStateResponse message, MessageContext ctx) {
|
||||
if(message.state != null) {
|
||||
ClientNetworkManager.getInstance().updateState(message.id, message.state);
|
||||
ClientNetworkManager.getInstance().updateState(EnderIO.proxy.getClientWorld(), message.id, message.state);
|
||||
} else {
|
||||
ClientNetworkManager.getInstance().destroyNetwork(message.id);
|
||||
}
|
||||
|
||||
+12
-2
@@ -3,11 +3,11 @@ package crazypants.enderio.power;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import cofh.api.energy.IEnergyConnection;
|
||||
|
||||
public class PowerInterfaceConnectionRF implements IPowerInterface {
|
||||
public class EnergyConnectionPI implements IPowerInterface {
|
||||
|
||||
private IEnergyConnection delegate;
|
||||
|
||||
public PowerInterfaceConnectionRF(IEnergyConnection delegate) {
|
||||
public EnergyConnectionPI(IEnergyConnection delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@@ -49,4 +49,14 @@ public class PowerInterfaceConnectionRF implements IPowerInterface {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOutputOnly() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInputOnly() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package crazypants.enderio.power;
|
||||
|
||||
import cofh.api.energy.IEnergyHandler;
|
||||
|
||||
public class EnergyHandlerPI extends EnergyReceiverPI {
|
||||
|
||||
private IEnergyHandler rfPower;
|
||||
|
||||
public EnergyHandlerPI(IEnergyHandler powerReceptor) {
|
||||
super(powerReceptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInputOnly() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
+16
-4
@@ -2,11 +2,13 @@ package crazypants.enderio.power;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import cofh.api.energy.IEnergyHandler;
|
||||
import cofh.api.energy.IEnergyReceiver;
|
||||
|
||||
public class PowerInterfaceRF implements IPowerInterface {
|
||||
private IEnergyHandler rfPower;
|
||||
public class EnergyReceiverPI implements IPowerInterface {
|
||||
|
||||
private IEnergyReceiver rfPower;
|
||||
|
||||
public PowerInterfaceRF(IEnergyHandler powerReceptor) {
|
||||
public EnergyReceiverPI(IEnergyReceiver powerReceptor) {
|
||||
rfPower = powerReceptor;
|
||||
}
|
||||
|
||||
@@ -47,7 +49,6 @@ public class PowerInterfaceRF implements IPowerInterface {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
public static int getPowerRequest(ForgeDirection dir, IEnergyHandler handler) {
|
||||
if(handler != null && dir != null && handler.canConnectEnergy(dir)) {
|
||||
return handler.receiveEnergy(dir, 99999999, true);
|
||||
@@ -67,4 +68,15 @@ public class PowerInterfaceRF implements IPowerInterface {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOutputOnly() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInputOnly() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,4 +18,8 @@ public interface IPowerInterface {
|
||||
|
||||
int recieveEnergy(ForgeDirection opposite, int canOffer);
|
||||
|
||||
boolean isOutputOnly();
|
||||
|
||||
boolean isInputOnly();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package crazypants.enderio.power;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class PerTickIntAverageCalculator {
|
||||
|
||||
private float lastSecondTotal = 0;
|
||||
private int index = 0;
|
||||
private final LimitedQueue<Float> secondsCache;
|
||||
|
||||
public PerTickIntAverageCalculator() {
|
||||
this(5);
|
||||
}
|
||||
|
||||
public PerTickIntAverageCalculator(int numSeconds) {
|
||||
secondsCache = new LimitedQueue<Float>(numSeconds);
|
||||
}
|
||||
|
||||
public float getAverage() {
|
||||
int numTicks = index + (secondsCache.size() * 20);
|
||||
if(numTicks == 0) {
|
||||
return 0;
|
||||
}
|
||||
float totalPower = lastSecondTotal;
|
||||
for (Float fl : secondsCache) {
|
||||
totalPower += fl;
|
||||
}
|
||||
return totalPower / numTicks;
|
||||
}
|
||||
|
||||
public void tick(int value) {
|
||||
lastSecondTotal += value;
|
||||
index++;
|
||||
if(index == 20) {
|
||||
secondsCache.add(lastSecondTotal);
|
||||
lastSecondTotal = 0;
|
||||
index = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private static class LimitedQueue<E> extends LinkedList<E> {
|
||||
|
||||
private final int limit;
|
||||
|
||||
public LimitedQueue(int limit) {
|
||||
this.limit = limit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(E o) {
|
||||
super.add(o);
|
||||
while (size() > limit) {
|
||||
super.remove();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,14 +5,19 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import cofh.api.energy.IEnergyConnection;
|
||||
import cofh.api.energy.IEnergyHandler;
|
||||
import cofh.api.energy.IEnergyReceiver;
|
||||
|
||||
public class PowerHandlerUtil {
|
||||
|
||||
public static final String STORED_ENERGY_NBT_KEY = "storedEnergyRF";
|
||||
|
||||
public static IPowerInterface create(Object o) {
|
||||
if(o instanceof IEnergyHandler) {
|
||||
return new PowerInterfaceRF((IEnergyHandler) o);
|
||||
return new EnergyHandlerPI((IEnergyHandler) o);
|
||||
} else if(o instanceof IEnergyReceiver) {
|
||||
return new EnergyReceiverPI((IEnergyReceiver) o);
|
||||
} else if(o instanceof IEnergyConnection) {
|
||||
return new PowerInterfaceConnectionRF((IEnergyConnection) o);
|
||||
return new EnergyConnectionPI((IEnergyConnection) o);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -28,7 +33,7 @@ public class PowerHandlerUtil {
|
||||
return (int) (storedMj * 10);
|
||||
}
|
||||
|
||||
return tag.getInteger("storedEnergyRF");
|
||||
return tag.getInteger(STORED_ENERGY_NBT_KEY);
|
||||
}
|
||||
|
||||
public static void setStoredEnergyForItem(ItemStack item, int storedEnergy) {
|
||||
@@ -36,7 +41,7 @@ public class PowerHandlerUtil {
|
||||
if(tag == null) {
|
||||
tag = new NBTTagCompound();
|
||||
}
|
||||
tag.setInteger("storedEnergyRF", storedEnergy);
|
||||
tag.setInteger(STORED_ENERGY_NBT_KEY, storedEnergy);
|
||||
item.setTagCompound(tag);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,9 +3,9 @@ package crazypants.enderio.waila;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.List;
|
||||
|
||||
import crazypants.enderio.gui.IAdvancedTooltipProvider;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.world.World;
|
||||
import crazypants.enderio.gui.IAdvancedTooltipProvider;
|
||||
|
||||
public interface IWailaInfoProvider {
|
||||
|
||||
@@ -16,6 +16,7 @@ public interface IWailaInfoProvider {
|
||||
|
||||
public static final NumberFormat fmt = NumberFormat.getNumberInstance();
|
||||
|
||||
|
||||
/**
|
||||
* Adds the block's info to the WAILA information
|
||||
* @param tooltip - current list of strings in the WAILA body
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package crazypants.enderio.waila;
|
||||
|
||||
import static crazypants.enderio.waila.IWailaInfoProvider.*;
|
||||
import static crazypants.enderio.waila.IWailaInfoProvider.BIT_BASIC;
|
||||
import static crazypants.enderio.waila.IWailaInfoProvider.BIT_COMMON;
|
||||
import static crazypants.enderio.waila.IWailaInfoProvider.BIT_DETAILED;
|
||||
import static crazypants.enderio.waila.IWailaInfoProvider.fmt;
|
||||
import info.jbcs.minecraft.chisel.api.IFacade;
|
||||
|
||||
import java.util.List;
|
||||
@@ -32,6 +35,7 @@ import crazypants.enderio.gui.IResourceTooltipProvider;
|
||||
import crazypants.enderio.gui.TooltipAddera;
|
||||
import crazypants.enderio.machine.IIoConfigurable;
|
||||
import crazypants.enderio.machine.IoMode;
|
||||
import crazypants.enderio.machine.capbank.TileCapBank;
|
||||
import crazypants.enderio.machine.power.TileCapacitorBank;
|
||||
import crazypants.enderio.power.IInternalPowerReceptor;
|
||||
import crazypants.util.Lang;
|
||||
@@ -56,6 +60,7 @@ public class WailaCompat implements IWailaDataProvider {
|
||||
// registrar.registerSyncedNBTKey("*", IInternalPowerReceptor.class);
|
||||
|
||||
ConfigHandler.instance().addConfig(EnderIO.MOD_NAME, "facades.hidden", "Sneaky Facades");
|
||||
IWailaInfoProvider.fmt.setMaximumFractionDigits(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -149,7 +154,7 @@ public class WailaCompat implements IWailaDataProvider {
|
||||
}
|
||||
}
|
||||
|
||||
if(te instanceof IInternalPowerReceptor && accessor.getNBTData().hasKey("storedEnergyRF")) {
|
||||
if(te instanceof IInternalPowerReceptor && accessor.getNBTData().hasKey("storedEnergyRF") && !(te instanceof TileCapBank)) {
|
||||
IInternalPowerReceptor power = (IInternalPowerReceptor) te;
|
||||
|
||||
if(power.displayPower()) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package crazypants.util;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
@@ -64,19 +65,25 @@ public final class BlockCoord {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(this == obj)
|
||||
if(this == obj) {
|
||||
return true;
|
||||
if(obj == null)
|
||||
}
|
||||
if(obj == null) {
|
||||
return false;
|
||||
if(getClass() != obj.getClass())
|
||||
}
|
||||
if(getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
BlockCoord other = (BlockCoord) obj;
|
||||
if(x != other.x)
|
||||
if(x != other.x) {
|
||||
return false;
|
||||
if(y != other.y)
|
||||
}
|
||||
if(y != other.y) {
|
||||
return false;
|
||||
if(z != other.z)
|
||||
}
|
||||
if(z != other.z) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -88,4 +95,14 @@ public final class BlockCoord {
|
||||
public boolean equals(int xCoord, int yCoord, int zCoord) {
|
||||
return x == xCoord && y == yCoord && z == zCoord;
|
||||
}
|
||||
|
||||
public void writeToBuf(ByteBuf buf) {
|
||||
buf.writeInt(x);
|
||||
buf.writeInt(y);
|
||||
buf.writeInt(z);
|
||||
}
|
||||
|
||||
public static BlockCoord readFromBuf(ByteBuf buf) {
|
||||
return new BlockCoord(buf.readInt(), buf.readInt(), buf.readInt());
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
@@ -18,7 +17,6 @@ import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemPotion;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.util.Vec3;
|
||||
@@ -191,6 +189,17 @@ public class Util {
|
||||
|
||||
}
|
||||
|
||||
public static void dropItems(World world, ItemStack[] inventory, int x, int y, int z, boolean doRandomSpread) {
|
||||
if(inventory == null) {
|
||||
return;
|
||||
}
|
||||
for (ItemStack stack : inventory) {
|
||||
if(stack != null && stack.stackSize > 0) {
|
||||
dropItems(world, stack.copy(), x, y, z, doRandomSpread);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void dropItems(World world, IInventory inventory, int x, int y, int z, boolean doRandomSpread) {
|
||||
for (int l = 0; l < inventory.getSizeInventory(); ++l) {
|
||||
ItemStack items = inventory.getStackInSlot(l);
|
||||
@@ -357,25 +366,25 @@ public class Util {
|
||||
double d2 = 999.0D;
|
||||
|
||||
if(i > l) {
|
||||
d0 = (double) l + 1.0D;
|
||||
d0 = l + 1.0D;
|
||||
} else if(i < l) {
|
||||
d0 = (double) l + 0.0D;
|
||||
d0 = l + 0.0D;
|
||||
} else {
|
||||
flag6 = false;
|
||||
}
|
||||
|
||||
if(j > i1) {
|
||||
d1 = (double) i1 + 1.0D;
|
||||
d1 = i1 + 1.0D;
|
||||
} else if(j < i1) {
|
||||
d1 = (double) i1 + 0.0D;
|
||||
d1 = i1 + 0.0D;
|
||||
} else {
|
||||
flag3 = false;
|
||||
}
|
||||
|
||||
if(k > j1) {
|
||||
d2 = (double) j1 + 1.0D;
|
||||
d2 = j1 + 1.0D;
|
||||
} else if(k < j1) {
|
||||
d2 = (double) j1 + 0.0D;
|
||||
d2 = j1 + 0.0D;
|
||||
} else {
|
||||
flag4 = false;
|
||||
}
|
||||
@@ -433,20 +442,20 @@ public class Util {
|
||||
}
|
||||
|
||||
Vec3 vec32 = Vec3.createVectorHelper(startVec.xCoord, startVec.yCoord, startVec.zCoord);
|
||||
l = (int) (vec32.xCoord = (double) MathHelper.floor_double(startVec.xCoord));
|
||||
l = (int) (vec32.xCoord = MathHelper.floor_double(startVec.xCoord));
|
||||
if(b0 == 5) {
|
||||
--l;
|
||||
++vec32.xCoord;
|
||||
}
|
||||
|
||||
i1 = (int) (vec32.yCoord = (double) MathHelper.floor_double(startVec.yCoord));
|
||||
i1 = (int) (vec32.yCoord = MathHelper.floor_double(startVec.yCoord));
|
||||
|
||||
if(b0 == 1) {
|
||||
--i1;
|
||||
++vec32.yCoord;
|
||||
}
|
||||
|
||||
j1 = (int) (vec32.zCoord = (double) MathHelper.floor_double(startVec.zCoord));
|
||||
j1 = (int) (vec32.zCoord = MathHelper.floor_double(startVec.zCoord));
|
||||
|
||||
if(b0 == 3) {
|
||||
--j1;
|
||||
|
||||
Reference in new issue
Block a user