mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-20 12:19:55 +00:00
New capacitor banks added
This commit is contained in:
commit
7288481bf7
67 files changed
+5096
-207
No files matched your search
@@ -64,6 +64,9 @@ import crazypants.enderio.machine.AbstractMachineRenderer;
|
||||
import crazypants.enderio.machine.attractor.AttractorRenderer;
|
||||
import crazypants.enderio.machine.attractor.BlockAttractor;
|
||||
import crazypants.enderio.machine.attractor.TileAttractor;
|
||||
import crazypants.enderio.machine.capbank.BlockCapBank;
|
||||
import crazypants.enderio.machine.capbank.TileCapBank;
|
||||
import crazypants.enderio.machine.capbank.render.CapBankRenderer;
|
||||
import crazypants.enderio.machine.enchanter.EnchanterModelRenderer;
|
||||
import crazypants.enderio.machine.enchanter.TileEnchanter;
|
||||
import crazypants.enderio.machine.farm.BlockFarmStation;
|
||||
@@ -273,6 +276,14 @@ public class ClientProxy extends CommonProxy {
|
||||
BlockElectricLight.renderId = RenderingRegistry.getNextAvailableRenderId();
|
||||
RenderingRegistry.registerBlockHandler(new ElectricLightRenderer());
|
||||
|
||||
if(EnderIO.blockCapBank != null) {
|
||||
BlockCapBank.renderId = RenderingRegistry.getNextAvailableRenderId();
|
||||
CapBankRenderer newCbr = new CapBankRenderer();
|
||||
RenderingRegistry.registerBlockHandler(newCbr);
|
||||
MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(EnderIO.blockCapBank), newCbr);
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileCapBank.class, newCbr);
|
||||
}
|
||||
|
||||
CapacitorBankRenderer capr = new CapacitorBankRenderer();
|
||||
MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(EnderIO.blockCapacitorBank), capr);
|
||||
|
||||
|
||||
@@ -83,6 +83,7 @@ import crazypants.enderio.machine.PacketRedstoneMode;
|
||||
import crazypants.enderio.machine.alloy.AlloyRecipeManager;
|
||||
import crazypants.enderio.machine.alloy.BlockAlloySmelter;
|
||||
import crazypants.enderio.machine.attractor.BlockAttractor;
|
||||
import crazypants.enderio.machine.capbank.BlockCapBank;
|
||||
import crazypants.enderio.machine.crafter.BlockCrafter;
|
||||
import crazypants.enderio.machine.crusher.BlockCrusher;
|
||||
import crazypants.enderio.machine.crusher.CrusherRecipeManager;
|
||||
@@ -220,6 +221,7 @@ public class EnderIO {
|
||||
public static BlockReservoir blockReservoir;
|
||||
public static BlockAlloySmelter blockAlloySmelter;
|
||||
public static BlockCapacitorBank blockCapacitorBank;
|
||||
public static BlockCapBank blockCapBank;
|
||||
public static BlockWirelessCharger blockWirelessCharger;
|
||||
public static BlockCrusher blockCrusher;
|
||||
public static BlockHyperCube blockHyperCube;
|
||||
@@ -308,6 +310,7 @@ public class EnderIO {
|
||||
blockCrusher = BlockCrusher.create();
|
||||
blockAlloySmelter = BlockAlloySmelter.create();
|
||||
blockCapacitorBank = BlockCapacitorBank.create();
|
||||
blockCapBank = BlockCapBank.create();
|
||||
|
||||
blockPainter = BlockPainter.create();
|
||||
blockPaintedFence = BlockPaintedFence.create();
|
||||
|
||||
@@ -51,6 +51,8 @@ public class GuiHandler implements IGuiHandler {
|
||||
public static final int GUI_ID_XP_OBELISK = 98;
|
||||
public static final int GUI_ID_ANVIL = 99;
|
||||
|
||||
public static final int GUI_ID_CAP_BANK = 100;
|
||||
|
||||
protected final Map<Integer, IGuiHandler> guiHandlers = new HashMap<Integer, IGuiHandler>();
|
||||
|
||||
public void registerGuiHandler(int id, IGuiHandler handler) {
|
||||
|
||||
@@ -42,6 +42,7 @@ public enum ModObject {
|
||||
blockAlloySmelter,
|
||||
blockSolarPanel,
|
||||
blockCapacitorBank,
|
||||
blockCapBank,
|
||||
blockSagMill,
|
||||
blockHyperCube,
|
||||
blockPowerMonitor,
|
||||
@@ -103,7 +104,7 @@ public enum ModObject {
|
||||
public final String unlocalisedName;
|
||||
|
||||
private ModObject() {
|
||||
this.unlocalisedName = name();
|
||||
unlocalisedName = name();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,10 +18,8 @@ import crazypants.enderio.conduit.ConduitNetworkTickHandler.TickListener;
|
||||
import crazypants.enderio.conduit.ConnectionMode;
|
||||
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;
|
||||
import crazypants.enderio.power.IPowerStorage;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -73,14 +68,14 @@ public class NetworkPowerManager {
|
||||
return maxEnergyStored;
|
||||
}
|
||||
|
||||
public int getPowerInCapacitorBanks() {
|
||||
public long getPowerInCapacitorBanks() {
|
||||
if(capSupply == null) {
|
||||
return 0;
|
||||
}
|
||||
return capSupply.stored;
|
||||
}
|
||||
|
||||
public int getMaxPowerInCapacitorBanks() {
|
||||
public long getMaxPowerInCapacitorBanks() {
|
||||
if(capSupply == null) {
|
||||
return 0;
|
||||
}
|
||||
@@ -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()) {
|
||||
@@ -327,8 +301,8 @@ public class NetworkPowerManager {
|
||||
storageReceptors.clear();
|
||||
for (ReceptorEntry rec : network.getPowerReceptors()) {
|
||||
if(rec.powerInterface.getDelegate() != null &&
|
||||
rec.powerInterface.getDelegate().getClass() == TileCapacitorBank.class &&
|
||||
!((TileCapacitorBank) rec.powerInterface.getDelegate()).isCreative()) {
|
||||
rec.powerInterface.getDelegate() instanceof IPowerStorage &&
|
||||
!((IPowerStorage) rec.powerInterface.getDelegate()).isCreative()) {
|
||||
storageReceptors.add(rec);
|
||||
} else {
|
||||
receptors.add(rec);
|
||||
@@ -368,11 +342,11 @@ public class NetworkPowerManager {
|
||||
|
||||
int canExtract;
|
||||
int canFill;
|
||||
Set<TileCapacitorBank> capBanks = new HashSet<TileCapacitorBank>();
|
||||
Set<IPowerStorage> capBanks = new HashSet<IPowerStorage>();
|
||||
|
||||
float filledRatio;
|
||||
int stored = 0;
|
||||
int maxCap = 0;
|
||||
double filledRatio;
|
||||
long stored = 0;
|
||||
long maxCap = 0;
|
||||
|
||||
List<CapBankSupplyEntry> enteries = new ArrayList<NetworkPowerManager.CapBankSupplyEntry>();
|
||||
|
||||
@@ -387,44 +361,44 @@ public class NetworkPowerManager {
|
||||
stored = 0;
|
||||
maxCap = 0;
|
||||
|
||||
float toBalance = 0;
|
||||
float maxToBalance = 0;
|
||||
double toBalance = 0;
|
||||
double maxToBalance = 0;
|
||||
|
||||
for (ReceptorEntry rec : storageReceptors) {
|
||||
TileCapacitorBank cb = (TileCapacitorBank) rec.powerInterface.getDelegate();
|
||||
IPowerStorage cb = (IPowerStorage) rec.powerInterface.getDelegate();
|
||||
|
||||
boolean processed = capBanks.contains(cb.getController());
|
||||
|
||||
if(!processed) {
|
||||
stored += cb.getEnergyStored();
|
||||
maxCap += cb.getMaxEnergyStored();
|
||||
stored += cb.getEnergyStoredL();
|
||||
maxCap += cb.getMaxEnergyStoredL();
|
||||
capBanks.add(cb.getController());
|
||||
}
|
||||
|
||||
if(rec.emmiter.getConnectionMode(rec.direction) == ConnectionMode.IN_OUT) {
|
||||
toBalance += cb.getEnergyStored();
|
||||
maxToBalance += cb.getMaxEnergyStored();
|
||||
toBalance += cb.getEnergyStoredL();
|
||||
maxToBalance += cb.getMaxEnergyStoredL();
|
||||
}
|
||||
|
||||
int canGet = 0;
|
||||
long canGet = 0;
|
||||
if(cb.isOutputEnabled(rec.direction.getOpposite())) {
|
||||
canGet = Math.min(cb.getEnergyStored(), cb.getMaxOutput());
|
||||
canGet = Math.min(cb.getEnergyStoredL(), cb.getMaxOutput());
|
||||
canGet = Math.min(canGet, rec.emmiter.getMaxEnergyRecieved(rec.direction));
|
||||
canExtract += canGet;
|
||||
}
|
||||
int canFill = 0;
|
||||
long canFill = 0;
|
||||
if(cb.isInputEnabled(rec.direction.getOpposite())) {
|
||||
canFill = Math.min(cb.getMaxEnergyStored() - cb.getEnergyStored(), cb.getMaxInput());
|
||||
canFill = Math.min(cb.getMaxEnergyStoredL() - cb.getEnergyStoredL(), cb.getMaxInput());
|
||||
canFill = Math.min(canFill, rec.emmiter.getMaxEnergyExtracted(rec.direction));
|
||||
this.canFill += canFill;
|
||||
}
|
||||
enteries.add(new CapBankSupplyEntry(cb, canGet, canFill, rec.emmiter, rec.direction));
|
||||
enteries.add(new CapBankSupplyEntry(cb, (int) canGet, (int) canFill, rec.emmiter, rec.direction));
|
||||
|
||||
}
|
||||
|
||||
filledRatio = 0;
|
||||
if(maxToBalance > 0) {
|
||||
filledRatio = (float) toBalance / maxToBalance;
|
||||
filledRatio = toBalance / maxToBalance;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -478,11 +452,11 @@ public class NetworkPowerManager {
|
||||
double ratio = (double) amount / canExtract;
|
||||
|
||||
for (CapBankSupplyEntry entry : enteries) {
|
||||
int use = (int) Math.ceil(ratio * entry.canExtract);
|
||||
long use = (int) Math.ceil(ratio * entry.canExtract);
|
||||
use = Math.min(use, amount);
|
||||
use = Math.min(use, entry.canExtract);
|
||||
entry.capBank.addEnergy(-use);
|
||||
trackerRecieve(entry.emmiter, use, true);
|
||||
entry.capBank.addEnergy((int) -use);
|
||||
trackerRecieve(entry.emmiter, (int) use, true);
|
||||
amount -= use;
|
||||
if(amount == 0) {
|
||||
return;
|
||||
@@ -497,11 +471,11 @@ public class NetworkPowerManager {
|
||||
double ratio = (double) amount / canFill;
|
||||
|
||||
for (CapBankSupplyEntry entry : enteries) {
|
||||
int add = (int) Math.ceil(ratio * entry.canFill);
|
||||
long add = (int) Math.ceil(ratio * entry.canFill);
|
||||
add = Math.min(add, entry.canFill);
|
||||
add = Math.min(add, amount);
|
||||
entry.capBank.addEnergy(add);
|
||||
trackerSend(entry.emmiter, add, true);
|
||||
entry.capBank.addEnergy((int) add);
|
||||
trackerSend(entry.emmiter, (int) add, true);
|
||||
amount -= add;
|
||||
if(amount == 0) {
|
||||
return;
|
||||
@@ -513,28 +487,28 @@ public class NetworkPowerManager {
|
||||
|
||||
private static class CapBankSupplyEntry {
|
||||
|
||||
final TileCapacitorBank capBank;
|
||||
final IPowerStorage capBank;
|
||||
final int canExtract;
|
||||
final int canFill;
|
||||
int toBalance;
|
||||
IPowerConduit emmiter;
|
||||
ForgeDirection direction;
|
||||
|
||||
private CapBankSupplyEntry(TileCapacitorBank capBank, int available, int canFill, IPowerConduit emmiter, ForgeDirection direction) {
|
||||
private CapBankSupplyEntry(IPowerStorage 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;
|
||||
}
|
||||
|
||||
void calcToBalance(float targetRatio) {
|
||||
int targetAmount = (int) Math.floor(capBank.getMaxEnergyStored() * targetRatio);
|
||||
toBalance = targetAmount - capBank.getEnergyStored();
|
||||
if(toBalance < 0) {
|
||||
toBalance = Math.max(toBalance, -canExtract);
|
||||
void calcToBalance(double targetRatio) {
|
||||
long targetAmount = (long) Math.floor(capBank.getMaxEnergyStoredL() * targetRatio);
|
||||
long b = targetAmount - capBank.getEnergyStoredL();
|
||||
if(b < 0) {
|
||||
toBalance = -canExtract;
|
||||
} else {
|
||||
toBalance = Math.min(toBalance, canFill);
|
||||
toBalance = canFill;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -267,6 +267,15 @@ public final class Config {
|
||||
public static int capacitorBankMaxIoRF = 5000;
|
||||
public static int capacitorBankMaxStorageRF = 5000000;
|
||||
|
||||
public static int capacitorBankTierOneMaxIoRF = 1000;
|
||||
public static int capacitorBankTierOneMaxStorageRF = 1000000;
|
||||
|
||||
public static int capacitorBankTierTwoMaxIoRF = 5000;
|
||||
public static int capacitorBankTierTwoMaxStorageRF = 5000000;
|
||||
|
||||
public static int capacitorBankTierThreeMaxIoRF = 25000;
|
||||
public static int capacitorBankTierThreeMaxStorageRF = 25000000;
|
||||
|
||||
public static int poweredSpawnerMinDelayTicks = 200;
|
||||
public static int poweredSpawnerMaxDelayTicks = 800;
|
||||
public static int poweredSpawnerLevelOnePowerPerTickRF = 160;
|
||||
@@ -386,6 +395,8 @@ public final class Config {
|
||||
public static int enchantmentSoulBoundWeight = 1;
|
||||
public static boolean enchantmentSoulBoundEnabled = true;
|
||||
|
||||
|
||||
|
||||
public static void load(FMLPreInitializationEvent event) {
|
||||
|
||||
FMLCommonHandler.instance().bus().register(new Config());
|
||||
@@ -441,6 +452,27 @@ public final class Config {
|
||||
"The maximum storage for a single capacitor in RF")
|
||||
.getInt(capacitorBankMaxStorageRF);
|
||||
|
||||
capacitorBankTierOneMaxIoRF = config.get(sectionPower.name, "capacitorBankTierOneMaxIoRF", capacitorBankTierOneMaxIoRF,
|
||||
"The maximum IO for a single tier one capacitor in RF/t")
|
||||
.getInt(capacitorBankTierOneMaxIoRF);
|
||||
capacitorBankTierOneMaxStorageRF = config.get(sectionPower.name, "capacitorBankTierOneMaxStorageRF", capacitorBankTierOneMaxStorageRF,
|
||||
"The maximum storage for a single tier one capacitor in RF")
|
||||
.getInt(capacitorBankTierOneMaxStorageRF);
|
||||
|
||||
capacitorBankTierTwoMaxIoRF = config.get(sectionPower.name, "capacitorBankTierTwoMaxIoRF", capacitorBankTierTwoMaxIoRF,
|
||||
"The maximum IO for a single tier two capacitor in RF/t")
|
||||
.getInt(capacitorBankTierTwoMaxIoRF);
|
||||
capacitorBankTierTwoMaxStorageRF = config.get(sectionPower.name, "capacitorBankTierTwoMaxStorageRF", capacitorBankTierTwoMaxStorageRF,
|
||||
"The maximum storage for a single tier two capacitor in RF")
|
||||
.getInt(capacitorBankTierTwoMaxStorageRF);
|
||||
|
||||
capacitorBankTierThreeMaxIoRF = config.get(sectionPower.name, "capacitorBankTierThreeMaxIoRF", capacitorBankTierThreeMaxIoRF,
|
||||
"The maximum IO for a single tier three capacitor in RF/t")
|
||||
.getInt(capacitorBankTierThreeMaxIoRF);
|
||||
capacitorBankTierThreeMaxStorageRF = config.get(sectionPower.name, "capacitorBankTierThreeMaxStorageRF", capacitorBankTierThreeMaxStorageRF,
|
||||
"The maximum storage for a single tier three capacitor in RF")
|
||||
.getInt(capacitorBankTierThreeMaxStorageRF);
|
||||
|
||||
powerConduitTierOneRF = config.get(sectionPower.name, "powerConduitTierOneRF", powerConduitTierOneRF, "The maximum IO for the tier 1 power conduit")
|
||||
.getInt(powerConduitTierOneRF);
|
||||
powerConduitTierTwoRF = config.get(sectionPower.name, "powerConduitTierTwoRF", powerConduitTierTwoRF, "The maximum IO for the tier 2 power conduit")
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -156,6 +156,9 @@ public class ItemDarkSteelSword extends ItemSword implements IEnergyContainerIte
|
||||
}
|
||||
|
||||
private double getSkullDropChance(EntityPlayer player, LivingDropsEvent evt) {
|
||||
|
||||
//TODO: <boni> stack.getTagCompound().getCompoundTag("InfiTool").getInteger("Beheading")
|
||||
|
||||
if(evt.entityLiving instanceof EntitySkeleton && ((EntitySkeleton) evt.entityLiving).getSkeletonType() == 1) {
|
||||
if(isEquippedAndPowered(player, Config.darkSteelSwordPowerUsePerHit)) {
|
||||
return Config.darkSteelSwordWitherSkullChance + (Config.darkSteelSwordWitherSkullLootingModifier * evt.lootingLevel);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package crazypants.enderio.machine;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import crazypants.util.Lang;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -12,8 +10,10 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
|
||||
import net.minecraftforge.oredict.RecipeSorter;
|
||||
import net.minecraftforge.oredict.RecipeSorter.Category;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import crazypants.util.Lang;
|
||||
|
||||
public class ClearConfigRecipe implements IRecipe{
|
||||
public class ClearConfigRecipe implements IRecipe {
|
||||
|
||||
static {
|
||||
RecipeSorter.register("EnderIO:clearConfig", ClearConfigRecipe.class, Category.SHAPELESS, "after:minecraft:shapeless");
|
||||
@@ -39,9 +39,9 @@ public class ClearConfigRecipe implements IRecipe{
|
||||
out.stackTagCompound = new NBTTagCompound();
|
||||
out.stackTagCompound.setBoolean("clearedConfig", true);
|
||||
out.stackSize = 1;
|
||||
this.output = out;
|
||||
output = out;
|
||||
} else {
|
||||
this.output = null;
|
||||
output = null;
|
||||
}
|
||||
|
||||
return count == 1 && output != null;
|
||||
@@ -64,7 +64,7 @@ public class ClearConfigRecipe implements IRecipe{
|
||||
|
||||
@SubscribeEvent
|
||||
public void onTooltip(ItemTooltipEvent event) {
|
||||
if (this.output != null && ItemStack.areItemStacksEqual(output, event.itemStack)) {
|
||||
if (output != null && ItemStack.areItemStacksEqual(output, event.itemStack)) {
|
||||
event.toolTip.add(EnumChatFormatting.RED.toString() + EnumChatFormatting.ITALIC + Lang.localize("machine.tooltip.clearConfig", true));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.config.Config;
|
||||
import crazypants.enderio.item.skull.BlockEndermanSkull;
|
||||
import crazypants.enderio.machine.capbank.CapBankType;
|
||||
import crazypants.enderio.machine.capbank.ConvertOldRecipe;
|
||||
import crazypants.enderio.machine.light.BlockItemElectricLight;
|
||||
import crazypants.enderio.material.Alloy;
|
||||
import crazypants.enderio.material.FrankenSkull;
|
||||
@@ -129,13 +131,22 @@ public class MachineRecipes {
|
||||
GameRegistry.addShapedRecipe(still, "eve", "tmt", "efe", 'v', Items.cauldron, 'm', machineChassi, 'e', electricSteel, 'f', Blocks.furnace, 't', basicTank);
|
||||
|
||||
//capacitor bank
|
||||
ItemStack capacitorBank = new ItemStack(EnderIO.blockCapacitorBank, 1, 0);
|
||||
if(Config.useHardRecipes) {
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(capacitorBank, "rcr", "ccc", "rMr", 'm', electricSteel, 'c', capacitor2, 'r', Blocks.redstone_block, 'M',
|
||||
machineChassi));
|
||||
} else {
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(capacitorBank, "mcm", "crc", "mcm", 'm', electricSteel, 'c', capacitor2, 'r', Blocks.redstone_block));
|
||||
}
|
||||
// ItemStack capacitorBank = new ItemStack(EnderIO.blockCapacitorBank, 1, 0);
|
||||
// if(Config.useHardRecipes) {
|
||||
// GameRegistry.addRecipe(new ShapedOreRecipe(capacitorBank, "rcr", "ccc", "rMr", 'm', electricSteel, 'c', capacitor2, 'r', Blocks.redstone_block, 'M',
|
||||
// machineChassi));
|
||||
// } else {
|
||||
// GameRegistry.addRecipe(new ShapedOreRecipe(capacitorBank, "mcm", "crc", "mcm", 'm', electricSteel, 'c', capacitor2, 'r', Blocks.redstone_block));
|
||||
// }
|
||||
ItemStack capBank = new ItemStack(EnderIO.blockCapBank, 1, CapBankType.getMetaFromType(CapBankType.SIMPLE));
|
||||
GameRegistry.addShapedRecipe(capBank, "bcb", "cmc", "bcb", 'b', Items.iron_ingot, 'c', capacitor, 'm', Blocks.redstone_block);
|
||||
capBank = new ItemStack(EnderIO.blockCapBank, 1, CapBankType.getMetaFromType(CapBankType.ACTIVATED));
|
||||
GameRegistry.addShapedRecipe(capBank, "bcb", "cmc", "bcb", 'b', electricSteel, 'c', capacitor2, 'm', Blocks.redstone_block);
|
||||
capBank = new ItemStack(EnderIO.blockCapBank, 1, CapBankType.getMetaFromType(CapBankType.VIBRANT));
|
||||
GameRegistry.addShapedRecipe(capBank, "bcb", "cmc", "bcb", 'b', electricSteel, 'c', capacitor3, 'm', vibCry);
|
||||
|
||||
ConvertOldRecipe convertRecipe = new ConvertOldRecipe();
|
||||
GameRegistry.addRecipe(convertRecipe);
|
||||
|
||||
//painter
|
||||
ItemStack painter = new ItemStack(EnderIO.blockPainter, 1, 0);
|
||||
|
||||
@@ -0,0 +1,551 @@
|
||||
package crazypants.enderio.machine.capbank;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
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;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import cpw.mods.fml.common.network.IGuiHandler;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import crazypants.enderio.BlockEio;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.GuiHandler;
|
||||
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.ICapBankNetwork;
|
||||
import crazypants.enderio.machine.capbank.network.NetworkUtil;
|
||||
import crazypants.enderio.machine.capbank.packet.PacketGuiChange;
|
||||
import crazypants.enderio.machine.capbank.packet.PacketNetworkEnergyRequest;
|
||||
import crazypants.enderio.machine.capbank.packet.PacketNetworkEnergyResponse;
|
||||
import crazypants.enderio.machine.capbank.packet.PacketNetworkIdRequest;
|
||||
import crazypants.enderio.machine.capbank.packet.PacketNetworkIdResponse;
|
||||
import crazypants.enderio.machine.capbank.packet.PacketNetworkStateRequest;
|
||||
import crazypants.enderio.machine.capbank.packet.PacketNetworkStateResponse;
|
||||
import crazypants.enderio.machine.power.PowerDisplayUtil;
|
||||
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 {
|
||||
|
||||
public static int renderId = -1;
|
||||
|
||||
public static BlockCapBank create() {
|
||||
|
||||
PacketHandler.INSTANCE.registerMessage(PacketNetworkStateResponse.class, PacketNetworkStateResponse.class, PacketHandler.nextID(), Side.CLIENT);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketNetworkStateRequest.class, PacketNetworkStateRequest.class, PacketHandler.nextID(), Side.SERVER);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketNetworkIdRequest.class, PacketNetworkIdRequest.class, PacketHandler.nextID(), Side.SERVER);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketNetworkIdResponse.class, PacketNetworkIdResponse.class, PacketHandler.nextID(), Side.CLIENT);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketNetworkEnergyRequest.class, PacketNetworkEnergyRequest.class, PacketHandler.nextID(), Side.SERVER);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketNetworkEnergyResponse.class, PacketNetworkEnergyResponse.class, PacketHandler.nextID(), Side.CLIENT);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketGuiChange.class, PacketGuiChange.class, PacketHandler.nextID(), Side.SERVER);
|
||||
|
||||
BlockCapBank res = new BlockCapBank();
|
||||
res.init();
|
||||
return res;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private IIcon gaugeIcon;
|
||||
@SideOnly(Side.CLIENT)
|
||||
private IIcon fillBarIcon;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private IIcon[] blockIcons;
|
||||
@SideOnly(Side.CLIENT)
|
||||
private IIcon[] borderIcons;
|
||||
@SideOnly(Side.CLIENT)
|
||||
private IIcon[] inputIcons;
|
||||
@SideOnly(Side.CLIENT)
|
||||
private IIcon[] outputIcons;
|
||||
@SideOnly(Side.CLIENT)
|
||||
private IIcon[] lockedIcons;
|
||||
@SideOnly(Side.CLIENT)
|
||||
private IIcon infoPanelIcon;
|
||||
|
||||
protected BlockCapBank() {
|
||||
super(ModObject.blockCapBank.unlocalisedName, TileCapBank.class);
|
||||
setHardness(2.0F);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
GameRegistry.registerBlock(this, BlockItemCapBank.class, name);
|
||||
if(teClass != null) {
|
||||
GameRegistry.registerTileEntity(teClass, name + "TileEntity");
|
||||
}
|
||||
|
||||
EnderIO.guiHandler.registerGuiHandler(GuiHandler.GUI_ID_CAP_BANK, this);
|
||||
setLightOpacity(255);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void getSubBlocks(Item p_149666_1_, CreativeTabs p_149666_2_, List list) {
|
||||
int meta = 0;
|
||||
for (CapBankType type : CapBankType.types()) {
|
||||
if(type.isCreative()) {
|
||||
list.add(BlockItemCapBank.createItemStackWithPower(meta, type.getMaxEnergyStored() / 2));
|
||||
} else {
|
||||
list.add(BlockItemCapBank.createItemStackWithPower(meta, 0));
|
||||
list.add(BlockItemCapBank.createItemStackWithPower(meta, type.getMaxEnergyStored()));
|
||||
}
|
||||
meta++;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int damageDropped(int par1) {
|
||||
return par1;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addCommonEntries(ItemStack itemstack, EntityPlayer entityplayer, List list, boolean flag) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addBasicEntries(ItemStack itemstack, EntityPlayer entityplayer, List list, boolean flag) {
|
||||
list.add(PowerDisplayUtil.formatStoredPower(PowerHandlerUtil.getStoredEnergyForItem(itemstack), CapBankType.getTypeFromMeta(itemstack.getItemDamage())
|
||||
.getMaxEnergyStored()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addDetailedEntries(ItemStack itemstack, EntityPlayer entityplayer, List list, boolean flag) {
|
||||
TooltipAddera.addDetailedTooltipFromResources(list, itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float par7, float par8, float par9) {
|
||||
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
if(!(te instanceof TileCapBank)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(ToolUtil.breakBlockWithTool(this, world, x, y, z, entityPlayer)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
TileCapBank tcb = (TileCapBank) te;
|
||||
ForgeDirection faceHit = ForgeDirection.getOrientation(side);
|
||||
|
||||
if(entityPlayer.isSneaking() && entityPlayer.getCurrentEquippedItem() == null && faceHit.offsetY == 0) {
|
||||
InfoDisplayType newDisplayType = tcb.getDisplayType(faceHit).next();
|
||||
if(newDisplayType == InfoDisplayType.NONE) {
|
||||
tcb.setDefaultIoMode(faceHit);
|
||||
} else {
|
||||
tcb.setIoMode(faceHit, IoMode.DISABLED);
|
||||
}
|
||||
tcb.setDisplayType(faceHit, newDisplayType);
|
||||
return true;
|
||||
}
|
||||
|
||||
if(entityPlayer.isSneaking()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(ToolUtil.isToolEquipped(entityPlayer)) {
|
||||
|
||||
IoMode ioMode = tcb.getIoMode(faceHit);
|
||||
if(faceHit.offsetY == 0) {
|
||||
if(ioMode == IoMode.DISABLED) {
|
||||
InfoDisplayType newDisplayType = tcb.getDisplayType(faceHit).next();
|
||||
tcb.setDisplayType(faceHit, newDisplayType);
|
||||
if(newDisplayType == InfoDisplayType.NONE) {
|
||||
tcb.setDefaultIoMode(faceHit);
|
||||
}
|
||||
} else {
|
||||
tcb.toggleIoModeForFace(faceHit);
|
||||
}
|
||||
} else {
|
||||
tcb.toggleIoModeForFace(faceHit);
|
||||
}
|
||||
|
||||
if(world.isRemote) {
|
||||
world.markBlockForUpdate(x, y, z);
|
||||
} else {
|
||||
world.notifyBlocksOfNeighborChange(x, y, z, EnderIO.blockCapBank);
|
||||
world.markBlockForUpdate(x, y, z);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if(!world.isRemote) {
|
||||
entityPlayer.openGui(EnderIO.instance, GuiHandler.GUI_ID_CAP_BANK, world, x, y, z);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
if(te instanceof TileCapBank) {
|
||||
return new ContainerCapBank(player, player.inventory, (TileCapBank) te);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
if(te instanceof TileCapBank) {
|
||||
return new GuiCapBank(player, player.inventory, (TileCapBank) te);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void registerBlockIcons(IIconRegister IIconRegister) {
|
||||
blockIcon = IIconRegister.registerIcon("enderio:capacitorBank");
|
||||
gaugeIcon = IIconRegister.registerIcon("enderio:capacitorBankOverlays");
|
||||
fillBarIcon = IIconRegister.registerIcon("enderio:capacitorBankFillBar");
|
||||
infoPanelIcon = IIconRegister.registerIcon("enderio:capBankInfoPanel");
|
||||
|
||||
blockIcons = new IIcon[CapBankType.types().size()];
|
||||
borderIcons = new IIcon[CapBankType.types().size()];
|
||||
inputIcons = new IIcon[CapBankType.types().size()];
|
||||
outputIcons = new IIcon[CapBankType.types().size()];
|
||||
lockedIcons = new IIcon[CapBankType.types().size()];
|
||||
int index = 0;
|
||||
for (CapBankType type : CapBankType.types()) {
|
||||
blockIcons[index] = IIconRegister.registerIcon(type.getIcon());
|
||||
borderIcons[index] = IIconRegister.registerIcon(type.getBorderIcon());
|
||||
inputIcons[index] = IIconRegister.registerIcon(type.getInputIcon());
|
||||
outputIcons[index] = IIconRegister.registerIcon(type.getOutputIcon());
|
||||
lockedIcons[index] = IIconRegister.registerIcon(type.getLockedIcon());
|
||||
++index;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRenderType() {
|
||||
return renderId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSideSolid(IBlockAccess world, int x, int y, int z, ForgeDirection side) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpaqueCube() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean renderAsNormalBlock() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldSideBeRendered(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5) {
|
||||
Block i1 = par1IBlockAccess.getBlock(par2, par3, par4);
|
||||
return i1 == this ? false : super.shouldSideBeRendered(par1IBlockAccess, par2, par3, par4, par5);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getIcon(int side, int meta) {
|
||||
meta = MathHelper.clamp_int(meta, 0, blockIcons.length - 1);
|
||||
return blockIcons[meta];
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getBorderIcon(int side, int meta) {
|
||||
meta = MathHelper.clamp_int(meta, 0, blockIcons.length - 1);
|
||||
return borderIcons[meta];
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getIcon(IBlockAccess ba, int x, int y, int z, int side) {
|
||||
TileEntity te = ba.getTileEntity(x, y, z);
|
||||
if(!(te instanceof TileCapBank)) {
|
||||
return blockIcons[0];
|
||||
}
|
||||
|
||||
// if(true) {
|
||||
// return IconUtil.blankTexture;
|
||||
// }
|
||||
|
||||
TileCapBank cb = (TileCapBank) te;
|
||||
ForgeDirection face = ForgeDirection.values()[side];
|
||||
|
||||
int meta = ba.getBlockMetadata(x, y, z);
|
||||
meta = MathHelper.clamp_int(meta, 0, CapBankType.types().size() - 1);
|
||||
|
||||
IoMode mode = cb.getIoMode(face);
|
||||
if(mode == null || mode == IoMode.NONE || cb.getDisplayType(face) != InfoDisplayType.NONE) {
|
||||
return blockIcons[meta];
|
||||
}
|
||||
if(mode == IoMode.PULL) {
|
||||
return inputIcons[meta];
|
||||
}
|
||||
if(mode == IoMode.PUSH) {
|
||||
return outputIcons[meta];
|
||||
}
|
||||
return lockedIcons[meta];
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getGaugeIcon() {
|
||||
return gaugeIcon;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getFillBarIcon() {
|
||||
return fillBarIcon;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getInfoPanelIcon() {
|
||||
return infoPanelIcon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborBlockChange(World world, int x, int y, int z, Block blockId) {
|
||||
if(world.isRemote) {
|
||||
return;
|
||||
}
|
||||
TileEntity tile = world.getTileEntity(x, y, z);
|
||||
if(tile instanceof TileCapBank) {
|
||||
TileCapBank te = (TileCapBank) tile;
|
||||
te.onNeighborBlockChange(blockId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int quantityDropped(Random r) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack stack) {
|
||||
super.onBlockPlacedBy(world, x, y, z, player, stack);
|
||||
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
if(!(te instanceof TileCapBank)) {
|
||||
return;
|
||||
}
|
||||
|
||||
TileCapBank cb = (TileCapBank) te;
|
||||
if(stack.stackTagCompound != null) {
|
||||
cb.readCommonNBT(stack.stackTagCompound);
|
||||
}
|
||||
|
||||
Collection<TileCapBank> neigbours = NetworkUtil.getNeigbours(cb);
|
||||
if(neigbours.isEmpty()) {
|
||||
int heading = MathHelper.floor_double(player.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;
|
||||
ForgeDirection dir = getDirForHeading(heading);
|
||||
cb.setDisplayType(dir, InfoDisplayType.LEVEL_BAR);
|
||||
}
|
||||
|
||||
if(world.isRemote) {
|
||||
return;
|
||||
}
|
||||
world.markBlockForUpdate(x, y, z);
|
||||
}
|
||||
|
||||
protected ForgeDirection getDirForHeading(int heading) {
|
||||
switch (heading) {
|
||||
case 0:
|
||||
return ForgeDirection.values()[2];
|
||||
case 1:
|
||||
return ForgeDirection.values()[5];
|
||||
case 2:
|
||||
return ForgeDirection.values()[3];
|
||||
case 3:
|
||||
default:
|
||||
return ForgeDirection.values()[4];
|
||||
}
|
||||
}
|
||||
|
||||
@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;
|
||||
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) {
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int x, int y, int z) {
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
if(!(te instanceof TileCapBank)) {
|
||||
return super.getSelectedBoundingBoxFromPool(world, x, y, z);
|
||||
}
|
||||
TileCapBank tr = (TileCapBank) te;
|
||||
ICapBankNetwork network = tr.getNetwork();
|
||||
|
||||
if(!tr.getType().isMultiblock() || network == null) {
|
||||
return super.getSelectedBoundingBoxFromPool(world, x, y, z);
|
||||
}
|
||||
|
||||
Vector3d min = new Vector3d(Double.MAX_VALUE, Double.MAX_VALUE, Double.MAX_VALUE);
|
||||
Vector3d max = new Vector3d(-Double.MAX_VALUE, -Double.MAX_VALUE, -Double.MAX_VALUE);
|
||||
for (TileCapBank bc : network.getMembers()) {
|
||||
min.x = Math.min(min.x, bc.xCoord);
|
||||
max.x = Math.max(max.x, bc.xCoord + 1);
|
||||
min.y = Math.min(min.y, bc.yCoord);
|
||||
max.y = Math.max(max.y, bc.yCoord + 1);
|
||||
min.z = Math.min(min.z, bc.zCoord);
|
||||
max.z = Math.max(max.z, bc.zCoord + 1);
|
||||
}
|
||||
return AxisAlignedBB.getBoundingBox(min.x, min.y, min.z, max.x, max.y, max.z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasComparatorInputOverride() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getComparatorInputOverride(World w, int x, int y, int z, int side) {
|
||||
TileEntity te = w.getTileEntity(x, y, z);
|
||||
if(te instanceof TileCapBank) {
|
||||
return ((TileCapBank) te).getComparatorOutput();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@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;
|
||||
if(cap.getNetwork() != null) {
|
||||
if(world.isRemote && world.getTotalWorldTime() % 20 == 0) {
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketNetworkStateRequest(cap));
|
||||
}
|
||||
ICapBankNetwork nw = cap.getNetwork();
|
||||
if(world.isRemote) {
|
||||
((CapBankClientNetwork) nw).requestPowerUpdate(cap, 2);
|
||||
}
|
||||
|
||||
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.getMaxInput()), Util.TAB + Util.ALIGNRIGHT));
|
||||
tooltip
|
||||
.add(String.format("%s : %s%s%sRF/t ", Lang.localize("capbank.maxOut"), format, fmt.format(nw.getMaxOutput()), Util.TAB + Util.ALIGNRIGHT));
|
||||
|
||||
tooltip.add("");
|
||||
}
|
||||
|
||||
long stored = nw.getEnergyStoredL();
|
||||
long max = nw.getMaxEnergyStoredL();
|
||||
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));
|
||||
|
||||
int change = Math.round(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
|
||||
public int getDefaultDisplayMask(World world, int x, int y, int z) {
|
||||
return IWailaInfoProvider.BIT_DETAILED;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package crazypants.enderio.machine.capbank;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import cofh.api.energy.IEnergyContainerItem;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.EnderIOTab;
|
||||
import crazypants.enderio.power.PowerHandlerUtil;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public BlockItemCapBank() {
|
||||
super(EnderIO.blockCapBank);
|
||||
setHasSubtypes(true);
|
||||
}
|
||||
|
||||
public BlockItemCapBank(Block block) {
|
||||
super(block);
|
||||
setHasSubtypes(true);
|
||||
setCreativeTab(EnderIOTab.tabEnderIO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetadata(int par1) {
|
||||
return par1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName(ItemStack par1ItemStack) {
|
||||
return CapBankType.getTypeFromMeta(par1ItemStack.getItemDamage()).getUnlocalizedName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean showDurabilityBar(ItemStack itemStack) {
|
||||
return !CapBankType.getTypeFromMeta(itemStack.getItemDamage()).isCreative();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDurabilityForDisplay(ItemStack itemStack) {
|
||||
int maxStored = CapBankType.getTypeFromMeta(itemStack.getItemDamage()).getMaxEnergyStored();
|
||||
double stored = maxStored - getEnergyStored(itemStack) + 1;
|
||||
double max = maxStored + 1;
|
||||
return stored / max;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int receiveEnergy(ItemStack container, int maxReceive, boolean simulate) {
|
||||
CapBankType type = CapBankType.getTypeFromMeta(container.getItemDamage());
|
||||
int energy = getEnergyStored(container);
|
||||
int maxInput = type.getMaxIO();
|
||||
int energyReceived = Math.min(type.getMaxEnergyStored() - energy, Math.min(maxReceive, maxInput));
|
||||
|
||||
if(!simulate && !type.isCreative()) {
|
||||
energy += energyReceived;
|
||||
PowerHandlerUtil.setStoredEnergyForItem(container, energy);
|
||||
}
|
||||
return energyReceived;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int extractEnergy(ItemStack container, int maxExtract, boolean simulate) {
|
||||
CapBankType type = CapBankType.getTypeFromMeta(container.getItemDamage());
|
||||
int energy = getEnergyStored(container);
|
||||
int maxOutput = type.getMaxIO();
|
||||
int energyExtracted = Math.min(energy, Math.min(maxExtract, maxOutput));
|
||||
|
||||
if(!simulate && !type.isCreative()) {
|
||||
energy -= energyExtracted;
|
||||
PowerHandlerUtil.setStoredEnergyForItem(container, energy);
|
||||
}
|
||||
return energyExtracted;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyStored(ItemStack container) {
|
||||
return PowerHandlerUtil.getStoredEnergyForItem(container);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored(ItemStack container) {
|
||||
return CapBankType.getTypeFromMeta(container.getItemDamage()).getMaxEnergyStored();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
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;
|
||||
|
||||
public class CapBankType {
|
||||
|
||||
public static final CapBankType CREATIVE = new CapBankType("CREATIVE", "tile.blockCapBank.creative", 500000, Config.capacitorBankTierTwoMaxStorageRF, false,
|
||||
true,
|
||||
"enderio:capacitorBank", "enderio:capacitorBankCreativeBorder", "enderio:capacitorBankInput", "enderio:capacitorBankOutput",
|
||||
"enderio:capacitorBankLocked");
|
||||
|
||||
public static final CapBankType SIMPLE = new CapBankType("SIMPLE", "tile.blockCapBank.simple", Config.capacitorBankTierOneMaxIoRF,
|
||||
Config.capacitorBankTierOneMaxStorageRF,
|
||||
true,
|
||||
false, "enderio:capacitorBank", "enderio:capacitorBankSimpleBorder", "enderio:capacitorBankInput", "enderio:capacitorBankOutput",
|
||||
"enderio:capacitorBankLocked");
|
||||
|
||||
public static final CapBankType ACTIVATED = new CapBankType("ACTIVATED", "tile.blockCapBank.activated", Config.capacitorBankTierTwoMaxIoRF,
|
||||
Config.capacitorBankTierTwoMaxStorageRF,
|
||||
true,
|
||||
false, "enderio:capacitorBank", "enderio:capacitorBankActivatedBorder", "enderio:capacitorBankInput", "enderio:capacitorBankOutput",
|
||||
"enderio:capacitorBankLocked");
|
||||
|
||||
public static final CapBankType VIBRANT = new CapBankType("VIBRANT", "tile.blockCapBank.vibrant", Config.capacitorBankTierThreeMaxIoRF,
|
||||
Config.capacitorBankTierThreeMaxStorageRF,
|
||||
true, false, "enderio:capacitorBank", "enderio:capacitorBankVibrantBorder", "enderio:capacitorBankInput", "enderio:capacitorBankOutput",
|
||||
"enderio:capacitorBankLocked");
|
||||
|
||||
private static final List<CapBankType> TYPES = new ArrayList<CapBankType>();
|
||||
|
||||
static {
|
||||
TYPES.add(CREATIVE);
|
||||
TYPES.add(SIMPLE);
|
||||
TYPES.add(ACTIVATED);
|
||||
TYPES.add(VIBRANT);
|
||||
}
|
||||
|
||||
public static List<CapBankType> types() {
|
||||
return TYPES;
|
||||
}
|
||||
|
||||
public static int getMetaFromType(CapBankType type) {
|
||||
for (int i = 0; i < TYPES.size(); i++) {
|
||||
if(TYPES.get(i) == type) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static CapBankType getTypeFromMeta(int meta) {
|
||||
meta = MathHelper.clamp_int(meta, 0, TYPES.size() - 1);
|
||||
return types().get(meta);
|
||||
}
|
||||
|
||||
public static CapBankType getTypeFromUID(String uid) {
|
||||
for (CapBankType type : TYPES) {
|
||||
if(type.uid.equals(uid)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return ACTIVATED;
|
||||
}
|
||||
|
||||
private final String uid;
|
||||
private final String unlocalizedName;
|
||||
private final int maxIO;
|
||||
private final int maxStored;
|
||||
private final boolean isMultiblock;
|
||||
private final boolean isCreative;
|
||||
private final String icon;
|
||||
private final String borderIcon;
|
||||
private final String inputIcon;
|
||||
private final String outputIcon;
|
||||
private final String lockedIcon;
|
||||
|
||||
public CapBankType(String uid, String unlocalizedName, int maxIO, int maxStored, boolean isMultiblock, boolean isCreative, String icon, String borderIcon,
|
||||
String inputIcon, String outputIcon, String lockedIcon) {
|
||||
this.uid = uid;
|
||||
this.unlocalizedName = unlocalizedName;
|
||||
this.maxIO = maxIO;
|
||||
this.maxStored = maxStored;
|
||||
this.isMultiblock = isMultiblock;
|
||||
this.isCreative = isCreative;
|
||||
this.icon = icon;
|
||||
this.borderIcon = borderIcon;
|
||||
this.inputIcon = inputIcon;
|
||||
this.outputIcon = outputIcon;
|
||||
this.lockedIcon = lockedIcon;
|
||||
}
|
||||
|
||||
public int getMaxIO() {
|
||||
return maxIO;
|
||||
}
|
||||
|
||||
public int getMaxEnergyStored() {
|
||||
return maxStored;
|
||||
}
|
||||
|
||||
public boolean isMultiblock() {
|
||||
return isMultiblock;
|
||||
}
|
||||
|
||||
public boolean isCreative() {
|
||||
return isCreative;
|
||||
}
|
||||
|
||||
public String getUnlocalizedName() {
|
||||
return unlocalizedName;
|
||||
}
|
||||
|
||||
public String getIcon() {
|
||||
return icon;
|
||||
}
|
||||
|
||||
public String getBorderIcon() {
|
||||
return borderIcon;
|
||||
}
|
||||
|
||||
public String getInputIcon() {
|
||||
return inputIcon;
|
||||
}
|
||||
|
||||
public String getOutputIcon() {
|
||||
return outputIcon;
|
||||
}
|
||||
|
||||
public String getLockedIcon() {
|
||||
return lockedIcon;
|
||||
}
|
||||
|
||||
public String getUid() {
|
||||
return uid;
|
||||
}
|
||||
|
||||
public void writeTypeToNBT(NBTTagCompound nbtRoot) {
|
||||
nbtRoot.setString("type", getUid());
|
||||
}
|
||||
|
||||
public static CapBankType readTypeFromNBT(NBTTagCompound nbtRoot) {
|
||||
if(nbtRoot == null || !nbtRoot.hasKey("type")) {
|
||||
return ACTIVATED;
|
||||
}
|
||||
return getTypeFromUID(nbtRoot.getString("type"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
package crazypants.enderio.machine.capbank;
|
||||
|
||||
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 {
|
||||
|
||||
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
|
||||
public boolean canInteractWith(EntityPlayer p_75145_1_) {
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package crazypants.enderio.machine.capbank;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.oredict.RecipeSorter;
|
||||
import net.minecraftforge.oredict.RecipeSorter.Category;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.power.PowerHandlerUtil;
|
||||
|
||||
public class ConvertOldRecipe implements IRecipe {
|
||||
|
||||
static {
|
||||
RecipeSorter.register("EnderIO:convertOldCapBankRecipe", ConvertOldRecipe.class, Category.SHAPELESS, "after:minecraft:shapeless");
|
||||
}
|
||||
|
||||
private ItemStack output;
|
||||
|
||||
@Override
|
||||
public boolean matches(InventoryCrafting inv, World world) {
|
||||
ItemStack input = null;
|
||||
for (int i = 0; i < inv.getSizeInventory(); i++) {
|
||||
ItemStack checkStack = inv.getStackInSlot(i);
|
||||
if(checkStack != null) {
|
||||
if(input != null) {
|
||||
return false;
|
||||
}
|
||||
if(Block.getBlockFromItem(checkStack.getItem()) == EnderIO.blockCapacitorBank) {
|
||||
input = checkStack;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(input == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
output = new ItemStack(EnderIO.blockCapBank, 1, CapBankType.getMetaFromType(CapBankType.ACTIVATED));
|
||||
PowerHandlerUtil.setStoredEnergyForItem(output, PowerHandlerUtil.getStoredEnergyForItem(input));
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getCraftingResult(InventoryCrafting inv) {
|
||||
return output.copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRecipeSize() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getRecipeOutput() {
|
||||
return output;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,423 @@
|
||||
package crazypants.enderio.machine.capbank;
|
||||
|
||||
import java.awt.Rectangle;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.gui.IconButtonEIO;
|
||||
import crazypants.enderio.gui.IconEIO;
|
||||
import crazypants.enderio.gui.RedstoneModeButton;
|
||||
import crazypants.enderio.machine.GuiMachineBase;
|
||||
import crazypants.enderio.machine.GuiOverlayIoConfig;
|
||||
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.NetworkState;
|
||||
import crazypants.enderio.machine.capbank.packet.PacketGuiChange;
|
||||
import crazypants.enderio.machine.capbank.packet.PacketNetworkStateRequest;
|
||||
import crazypants.enderio.machine.power.PowerDisplayUtil;
|
||||
import crazypants.enderio.network.PacketHandler;
|
||||
import crazypants.gui.GuiContainerBase;
|
||||
import crazypants.gui.GuiToolTip;
|
||||
import crazypants.render.RenderUtil;
|
||||
import crazypants.util.BlockCoord;
|
||||
import crazypants.util.Lang;
|
||||
import crazypants.vecmath.VecmathUtil;
|
||||
|
||||
public class GuiCapBank extends GuiContainerBase {
|
||||
|
||||
private static final NetworkState EMPTY_STATE = new NetworkState();
|
||||
|
||||
private static final CapBankClientNetwork NULL_NETWORK = new CapBankClientNetwork(-1);
|
||||
|
||||
protected static final int INPUT_BUTTON_ID = 18;
|
||||
protected static final int OUTPUT_BUTTON_ID = 37;
|
||||
|
||||
protected static final int CONFIG_ID = 377996104;
|
||||
|
||||
private static final int POWER_X = 11 + 18;
|
||||
private static final int POWER_Y = 9;
|
||||
private static final int POWER_WIDTH = 10;
|
||||
private static final int POWER_HEIGHT = 68;
|
||||
protected static final int BOTTOM_POWER_Y = POWER_Y + POWER_HEIGHT;
|
||||
|
||||
private int inputX = 78 + 24;
|
||||
private int inputY = 18;
|
||||
|
||||
private int outputX = 78 + 24;
|
||||
private int outputY = 36;
|
||||
|
||||
private int rightMargin = 8 + 24;
|
||||
|
||||
private final TileCapBank capBank;
|
||||
|
||||
private RedstoneModeButton inputRsButton;
|
||||
private RedstoneModeButton outputRsButton;
|
||||
|
||||
private GuiTextField maxInputTF;
|
||||
private GuiTextField maxOutputTF;
|
||||
|
||||
private GuiOverlayIoConfig configOverlay;
|
||||
private IconButtonEIO configB;
|
||||
|
||||
private CapBankClientNetwork network;
|
||||
|
||||
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();
|
||||
|
||||
xSize = 176 + 42;
|
||||
|
||||
addToolTip(new GuiToolTip(new Rectangle(5, POWER_Y, POWER_WIDTH, POWER_HEIGHT), "") {
|
||||
|
||||
@Override
|
||||
protected void updateText() {
|
||||
text.clear();
|
||||
text.add(PowerDisplayUtil.formatPower(network.getEnergyStoredL()) + " " + PowerDisplayUtil.ofStr());
|
||||
text.add(EnumChatFormatting.WHITE + PowerDisplayUtil.formatPower(network.getMaxEnergyStoredL()) + " " + EnumChatFormatting.GRAY
|
||||
+ PowerDisplayUtil.abrevation());
|
||||
|
||||
float change = network.getAverageChangePerTick();
|
||||
String color = EnumChatFormatting.WHITE.toString();
|
||||
if(change > 0) {
|
||||
color = EnumChatFormatting.GREEN.toString() + "+";
|
||||
} else if(change < 0) {
|
||||
color = EnumChatFormatting.RED.toString();
|
||||
}
|
||||
text.add(String.format("%s%s%s" + PowerDisplayUtil.abrevation() + PowerDisplayUtil.perTickStr(), color,
|
||||
PowerDisplayUtil.formatPower(Math.round(change)), " "
|
||||
+ EnumChatFormatting.GRAY.toString()));
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
int x = xSize - rightMargin - GuiMachineBase.BUTTON_SIZE - 21;
|
||||
int y = inputY;
|
||||
inputRsButton = new RedstoneModeButton(this, -1, x, y, new IRedstoneModeControlable() {
|
||||
|
||||
@Override
|
||||
public void setRedstoneControlMode(RedstoneControlMode mode) {
|
||||
network.setInputControlMode(mode);
|
||||
sendUpdateToServer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedstoneControlMode getRedstoneControlMode() {
|
||||
return network.getInputControlMode();
|
||||
}
|
||||
});
|
||||
inputRsButton.setTooltipKey("enderio.gui.capBank.inputRs");
|
||||
|
||||
y += 18;
|
||||
outputRsButton = new RedstoneModeButton(this, -1, x, y, new IRedstoneModeControlable() {
|
||||
|
||||
@Override
|
||||
public void setRedstoneControlMode(RedstoneControlMode mode) {
|
||||
network.setOutputControlMode(mode);
|
||||
sendUpdateToServer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedstoneControlMode getRedstoneControlMode() {
|
||||
return network.getOutputControlMode();
|
||||
}
|
||||
});
|
||||
outputRsButton.setTooltipKey("enderio.gui.capBank.outputRs");
|
||||
|
||||
y += 20;
|
||||
configB = new IconButtonEIO(this, CONFIG_ID, x, y, IconEIO.IO_CONFIG_UP);
|
||||
configB.setToolTip(Lang.localize("gui.machine.ioMode.overlay.tooltip"));
|
||||
|
||||
List<BlockCoord> coords = new ArrayList<BlockCoord>();
|
||||
if(network != null && network.getMembers().size() < 200) {
|
||||
for (TileCapBank cb : network.getMembers()) {
|
||||
coords.add(cb.getLocation());
|
||||
}
|
||||
}
|
||||
if(coords.isEmpty()) {
|
||||
coords.add(te.getLocation());
|
||||
}
|
||||
|
||||
|
||||
configOverlay = new GuiOverlayIoConfig(coords) {
|
||||
|
||||
@Override
|
||||
public void setVisible(boolean visible) {
|
||||
super.setVisible(visible);
|
||||
configB.setIcon(visible ? IconEIO.IO_CONFIG_DOWN : IconEIO.IO_CONFIG_UP);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLabelForMode(IoMode mode) {
|
||||
if(mode == IoMode.PUSH) {
|
||||
return Lang.localize("gui.capBank.outputMode");
|
||||
} else if(mode == IoMode.PULL) {
|
||||
return Lang.localize("gui.capBank.inputMode");
|
||||
}
|
||||
return super.getLabelForMode(mode);
|
||||
}
|
||||
|
||||
};
|
||||
addOverlay(configOverlay);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton b) {
|
||||
super.actionPerformed(b);
|
||||
if(b.id == CONFIG_ID) {
|
||||
boolean vis = !configOverlay.isVisible();
|
||||
configOverlay.setVisible(vis);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
configB.onGuiInit();
|
||||
|
||||
int x = guiLeft + xSize - rightMargin - GuiMachineBase.BUTTON_SIZE;
|
||||
int y = guiTop + inputY;
|
||||
|
||||
FontRenderer fontRenderer = getFontRenderer();
|
||||
|
||||
inputRsButton.onGuiInit();
|
||||
outputRsButton.onGuiInit();
|
||||
|
||||
x = guiLeft + inputX;
|
||||
y = guiTop + inputY;
|
||||
maxInputTF = new GuiTextField(fontRenderer, x, y, 68, 16);
|
||||
maxInputTF.setCanLoseFocus(true);
|
||||
maxInputTF.setMaxStringLength(10);
|
||||
maxInputTF.setFocused(false);
|
||||
|
||||
x = guiLeft + outputX;
|
||||
y = guiTop + outputY;
|
||||
maxOutputTF = new GuiTextField(fontRenderer, x, y, 68, 16);
|
||||
maxOutputTF.setCanLoseFocus(true);
|
||||
maxOutputTF.setMaxStringLength(10);
|
||||
maxOutputTF.setFocused(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char par1, int par2) {
|
||||
super.keyTyped(par1, par2);
|
||||
if(par1 == 'e') {
|
||||
super.keyTyped(par1, 1);
|
||||
}
|
||||
maxInputTF.textboxKeyTyped(par1, par2);
|
||||
maxOutputTF.textboxKeyTyped(par1, par2);
|
||||
updateInputOutput();
|
||||
}
|
||||
|
||||
private void updateInputOutput() {
|
||||
int input = parsePower(maxInputTF);
|
||||
if(input >= 0 && network.getMaxInput() != input) {
|
||||
setMaxInput(input);
|
||||
}
|
||||
int output = parsePower(maxOutputTF);
|
||||
if(output >= 0 && network.getMaxOutput() != output) {
|
||||
setMaxOutput(output);
|
||||
}
|
||||
}
|
||||
|
||||
private void setMaxOutput(int output) {
|
||||
if(output != network.getMaxOutput()) {
|
||||
network.setMaxOutput(output);
|
||||
maxOutputTF.setText(PowerDisplayUtil.formatPower(network.getMaxOutput()));
|
||||
sendUpdateToServer();
|
||||
}
|
||||
}
|
||||
|
||||
private void setMaxInput(int input) {
|
||||
if(input != network.getMaxInput()) {
|
||||
network.setMaxInput(input);
|
||||
maxInputTF.setText(PowerDisplayUtil.formatPower(network.getMaxInput()));
|
||||
sendUpdateToServer();
|
||||
}
|
||||
}
|
||||
|
||||
protected void sendUpdateToServer() {
|
||||
if(network != NULL_NETWORK) {
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketGuiChange(capBank));
|
||||
}
|
||||
}
|
||||
|
||||
private int parsePower(GuiTextField tf) {
|
||||
String txt = tf.getText();
|
||||
try {
|
||||
Integer power = PowerDisplayUtil.parsePower(txt);
|
||||
if(power == null) {
|
||||
return -1;
|
||||
}
|
||||
return power.intValue();
|
||||
} catch (Exception e) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int par1, int par2, int par3) {
|
||||
super.mouseClicked(par1, par2, par3);
|
||||
maxInputTF.mouseClicked(par1, par2, par3);
|
||||
maxOutputTF.mouseClicked(par1, par2, par3);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
maxInputTF.updateCursorCounter();
|
||||
maxOutputTF.updateCursorCounter();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) {
|
||||
|
||||
requestStateUpdate();
|
||||
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
RenderUtil.bindTexture("enderio:textures/gui/capacitorBank.png");
|
||||
int sx = (width - xSize) / 2;
|
||||
int sy = (height - ySize) / 2;
|
||||
|
||||
drawTexturedModalRect(sx, sy, 0, 0, xSize - 21, ySize);
|
||||
|
||||
int i1 = getEnergyStoredScaled(POWER_HEIGHT);
|
||||
drawTexturedModalRect(sx + POWER_X, sy + BOTTOM_POWER_Y - i1, 176 + 21, 0, POWER_WIDTH, i1);
|
||||
|
||||
for (int i = 0; i < buttonList.size(); ++i) {
|
||||
GuiButton guibutton = (GuiButton) buttonList.get(i);
|
||||
guibutton.drawButton(mc, 0, 0);
|
||||
}
|
||||
|
||||
maxInputTF.drawTextBox();
|
||||
maxOutputTF.drawTextBox();
|
||||
|
||||
int midX = sx + xSize / 2;
|
||||
|
||||
String str = Lang.localize("gui.capBank.maxIo") + " " + PowerDisplayUtil.formatPower(network.getMaxIO()) +
|
||||
" " + PowerDisplayUtil.abrevation() + PowerDisplayUtil.perTickStr();
|
||||
FontRenderer fontRenderer = getFontRenderer();
|
||||
int swid = fontRenderer.getStringWidth(str);
|
||||
int x = midX - swid / 2;
|
||||
int y = guiTop + 5;
|
||||
|
||||
drawString(fontRenderer, str, x, y, -1);
|
||||
|
||||
str = Lang.localize("gui.capBank.maxInput") + ":";
|
||||
swid = fontRenderer.getStringWidth(str);
|
||||
x = guiLeft + inputX - swid - 3;
|
||||
y = guiTop + inputY + 2;
|
||||
drawString(fontRenderer, str, x, y, -1);
|
||||
|
||||
str = Lang.localize("gui.capBank.maxOutput") + ":";
|
||||
swid = fontRenderer.getStringWidth(str);
|
||||
x = guiLeft + outputX - swid - 3;
|
||||
y = guiTop + outputY + 2;
|
||||
drawString(fontRenderer, str, x, y, -1);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawHoveringText(List par1List, int par2, int par3, FontRenderer font) {
|
||||
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
|
||||
GL11.glPushAttrib(GL11.GL_LIGHTING_BIT);
|
||||
super.drawHoveringText(par1List, par2 + 24, par3, font);
|
||||
GL11.glPopAttrib();
|
||||
GL11.glPopAttrib();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGuiLeft() {
|
||||
return guiLeft + 24;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGuiTop() {
|
||||
return guiTop;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getXSize() {
|
||||
return xSize - 42;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOverlayOffsetX() {
|
||||
return 21;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FontRenderer getFontRenderer() {
|
||||
return Minecraft.getMinecraft().fontRenderer;
|
||||
}
|
||||
|
||||
private int getEnergyStoredScaled(int scale) {
|
||||
return (int) VecmathUtil.clamp(Math.round(scale * network.getEnergyStoredRatio()), 0, scale);
|
||||
}
|
||||
|
||||
private void requestStateUpdate() {
|
||||
if(EnderIO.proxy.getTickCount() % 2 == 0) {
|
||||
if(!updateState()) {
|
||||
network.requestPowerUpdate(capBank, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean updateState() {
|
||||
if(!initState) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(capBank.getNetwork() == null) {
|
||||
network = NULL_NETWORK;
|
||||
return true;
|
||||
}
|
||||
if(network == null || network == NULL_NETWORK) {
|
||||
network = (CapBankClientNetwork) capBank.getNetwork();
|
||||
initialStateCount = network.getStateUpdateCount();
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketNetworkStateRequest(capBank));
|
||||
return true;
|
||||
}
|
||||
if(network.getStateUpdateCount() == initialStateCount) {
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketNetworkStateRequest(capBank));
|
||||
return true;
|
||||
}
|
||||
if(network.getStateUpdateCount() > initialStateCount) {
|
||||
container.updateInventory();
|
||||
updateFieldsFromState();
|
||||
initState = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void updateFieldsFromState() {
|
||||
maxInputTF.setText(PowerDisplayUtil.formatPower(network.getMaxInput()));
|
||||
maxOutputTF.setText(PowerDisplayUtil.formatPower(network.getMaxOutput()));
|
||||
inputRsButton.setMode(network.getInputControlMode());
|
||||
outputRsButton.setMode(network.getOutputControlMode());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package crazypants.enderio.machine.capbank;
|
||||
|
||||
|
||||
public enum InfoDisplayType {
|
||||
|
||||
NONE,
|
||||
LEVEL_BAR,
|
||||
IO;
|
||||
|
||||
public InfoDisplayType next() {
|
||||
int ord = ordinal();
|
||||
++ord;
|
||||
if(ord >= values().length) {
|
||||
ord = 0;
|
||||
}
|
||||
return values()[ord];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,845 @@
|
||||
package crazypants.enderio.machine.capbank;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
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.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;
|
||||
import crazypants.enderio.power.IInternalPowerReceptor;
|
||||
import crazypants.enderio.power.IPowerInterface;
|
||||
import crazypants.enderio.power.IPowerStorage;
|
||||
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, IPowerStorage {
|
||||
|
||||
private Map<ForgeDirection, IoMode> faceModes;
|
||||
private Map<ForgeDirection, InfoDisplayType> faceDisplayTypes;
|
||||
|
||||
private CapBankType type;
|
||||
|
||||
private int energyStored;
|
||||
private int maxInput = -1;
|
||||
private int maxOutput = -1;
|
||||
|
||||
private RedstoneControlMode inputControlMode = RedstoneControlMode.IGNORE;
|
||||
private RedstoneControlMode outputControlMode = RedstoneControlMode.IGNORE;
|
||||
|
||||
private boolean redstoneStateDirty = true;
|
||||
private boolean isRecievingRedstoneSignal;
|
||||
|
||||
private final List<EnergyReceptor> receptors = new ArrayList<EnergyReceptor>();
|
||||
private boolean receptorsDirty = true;
|
||||
|
||||
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;
|
||||
private boolean displayTypesDirty;
|
||||
private boolean revalidateDisplayTypes;
|
||||
private int lastComparatorState;
|
||||
|
||||
@Override
|
||||
public BlockCoord getLocation() {
|
||||
return new BlockCoord(this);
|
||||
}
|
||||
|
||||
public CapBankType getType() {
|
||||
if(type == null) {
|
||||
type = CapBankType.getTypeFromMeta(getBlockMetadata());
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
public void onNeighborBlockChange(Block blockId) {
|
||||
redstoneStateDirty = true;
|
||||
receptorsDirty = true;
|
||||
revalidateDisplayTypes = true;
|
||||
}
|
||||
|
||||
//---------- Multiblock
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void setNetworkId(int networkId) {
|
||||
this.networkId = networkId;
|
||||
if(networkId != -1) {
|
||||
ClientNetworkManager.getInstance().addToNetwork(networkId, this);
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public int getNetworkId() {
|
||||
return networkId;
|
||||
}
|
||||
|
||||
public ICapBankNetwork getNetwork() {
|
||||
return network;
|
||||
}
|
||||
|
||||
public boolean setNetwork(ICapBankNetwork network) {
|
||||
this.network = network;
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean canConnectTo(TileCapBank cap) {
|
||||
CapBankType t = getType();
|
||||
return t.isMultiblock() && t.getUid().equals(cap.getType().getUid());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkUnload() {
|
||||
if(network != null) {
|
||||
network.destroyNetwork();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate() {
|
||||
super.invalidate();
|
||||
if(network != null) {
|
||||
network.destroyNetwork();
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
if(networkId == -1) {
|
||||
if(idRequestTimer <= 0) {
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketNetworkIdRequest(this));
|
||||
idRequestTimer = 5;
|
||||
} else {
|
||||
--idRequestTimer;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
updateNetwork(worldObj);
|
||||
if(network == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(redstoneStateDirty) {
|
||||
int sig = worldObj.getStrongestIndirectPower(xCoord, yCoord, zCoord);
|
||||
boolean recievingSignal = sig > 0;
|
||||
network.updateRedstoneSignal(this, recievingSignal);
|
||||
redstoneStateDirty = false;
|
||||
}
|
||||
|
||||
if(receptorsDirty) {
|
||||
updateReceptors();
|
||||
}
|
||||
if(revalidateDisplayTypes) {
|
||||
checkDisplayTypesValid();
|
||||
revalidateDisplayTypes = false;
|
||||
}
|
||||
if(displayTypesDirty) {
|
||||
displayTypesDirty = false;
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
// update any comparators, since they don't check themselves
|
||||
int comparatorState = getComparatorOutput();
|
||||
if(lastComparatorState != comparatorState) {
|
||||
worldObj.func_147453_f(xCoord, yCoord, zCoord, getBlockType());
|
||||
lastComparatorState = comparatorState;
|
||||
}
|
||||
|
||||
doDropItems();
|
||||
}
|
||||
|
||||
private void updateNetwork(World world) {
|
||||
if(getNetwork() == null) {
|
||||
NetworkUtil.ensureValidNetwork(this);
|
||||
}
|
||||
if(getNetwork() != null) {
|
||||
getNetwork().onUpdateEntity(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//---------- IO
|
||||
|
||||
@Override
|
||||
public IoMode toggleIoModeForFace(ForgeDirection faceHit) {
|
||||
IPowerInterface rec = getReceptorForFace(faceHit);
|
||||
IoMode curMode = getIoMode(faceHit);
|
||||
if(curMode == IoMode.PULL) {
|
||||
setIoMode(faceHit, IoMode.PUSH, true);
|
||||
return IoMode.PUSH;
|
||||
}
|
||||
if(curMode == IoMode.PUSH) {
|
||||
setIoMode(faceHit, IoMode.DISABLED, true);
|
||||
return IoMode.DISABLED;
|
||||
}
|
||||
if(curMode == IoMode.DISABLED) {
|
||||
if(rec == null || rec.getDelegate() instanceof IConduitBundle) {
|
||||
setIoMode(faceHit, IoMode.NONE, true);
|
||||
return IoMode.NONE;
|
||||
}
|
||||
}
|
||||
setIoMode(faceHit, IoMode.PULL, true);
|
||||
return IoMode.PULL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsMode(ForgeDirection faceHit, IoMode mode) {
|
||||
IPowerInterface rec = getReceptorForFace(faceHit);
|
||||
if(mode == IoMode.NONE) {
|
||||
return rec == null || rec.getDelegate() instanceof IConduitBundle;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIoMode(ForgeDirection faceHit, IoMode mode) {
|
||||
setIoMode(faceHit, mode, true);
|
||||
}
|
||||
|
||||
public void setIoMode(ForgeDirection faceHit, IoMode mode, boolean updateReceptors) {
|
||||
if(mode == IoMode.NONE && faceModes == null) {
|
||||
return;
|
||||
}
|
||||
if(faceModes == null) {
|
||||
faceModes = new EnumMap<ForgeDirection, IoMode>(ForgeDirection.class);
|
||||
}
|
||||
faceModes.put(faceHit, mode);
|
||||
if(updateReceptors) {
|
||||
receptorsDirty = true;
|
||||
}
|
||||
if(worldObj != null) {
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, blockType);
|
||||
}
|
||||
}
|
||||
|
||||
public void setDefaultIoMode(ForgeDirection faceHit) {
|
||||
EnergyReceptor er = getEnergyReceptorForFace(faceHit);
|
||||
if(er == null || er.getConduit() != null) {
|
||||
setIoMode(faceHit, IoMode.NONE);
|
||||
} else if(er.getReceptor().isInputOnly()) {
|
||||
setIoMode(faceHit, IoMode.PUSH);
|
||||
} else if(er.getReceptor().isOutputOnly()) {
|
||||
setIoMode(faceHit, IoMode.PULL);
|
||||
} else {
|
||||
setIoMode(faceHit, IoMode.PUSH);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IoMode getIoMode(ForgeDirection face) {
|
||||
if(faceModes == null) {
|
||||
return IoMode.NONE;
|
||||
}
|
||||
IoMode res = faceModes.get(face);
|
||||
if(res == null) {
|
||||
return IoMode.NONE;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
//----- Info Display
|
||||
|
||||
public InfoDisplayType getDisplayType(ForgeDirection face) {
|
||||
if(faceDisplayTypes == null) {
|
||||
return InfoDisplayType.NONE;
|
||||
}
|
||||
InfoDisplayType res = faceDisplayTypes.get(face);
|
||||
return res == null ? InfoDisplayType.NONE : res;
|
||||
}
|
||||
|
||||
public void setDisplayType(ForgeDirection face, InfoDisplayType type) {
|
||||
setDisplayType(face, type, true);
|
||||
}
|
||||
|
||||
public void setDisplayType(ForgeDirection face, InfoDisplayType type, boolean markDirty) {
|
||||
if(type == null) {
|
||||
type = InfoDisplayType.NONE;
|
||||
}
|
||||
if(faceDisplayTypes == null && type == InfoDisplayType.NONE) {
|
||||
return;
|
||||
}
|
||||
InfoDisplayType cur = getDisplayType(face);
|
||||
if(cur == type) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(faceDisplayTypes == null) {
|
||||
faceDisplayTypes = new HashMap<ForgeDirection, InfoDisplayType>();
|
||||
}
|
||||
|
||||
if(type == InfoDisplayType.NONE) {
|
||||
faceDisplayTypes.remove(face);
|
||||
} else {
|
||||
faceDisplayTypes.put(face, type);
|
||||
}
|
||||
|
||||
if(faceDisplayTypes.isEmpty()) {
|
||||
faceDisplayTypes = null;
|
||||
}
|
||||
displayTypesDirty = markDirty;
|
||||
}
|
||||
|
||||
private void checkDisplayTypesValid() {
|
||||
if(faceDisplayTypes == null) {
|
||||
return;
|
||||
}
|
||||
List<ForgeDirection> reset = new ArrayList<ForgeDirection>();
|
||||
for (Entry<ForgeDirection, InfoDisplayType> entry : faceDisplayTypes.entrySet()) {
|
||||
BlockCoord bc = getLocation().getLocation(entry.getKey());
|
||||
Block block = worldObj.getBlock(bc.x, bc.y, bc.z);
|
||||
if(block != null && (block.isOpaqueCube() || block == EnderIO.blockCapBank)) {
|
||||
reset.add(entry.getKey());
|
||||
}
|
||||
}
|
||||
for (ForgeDirection dir : reset) {
|
||||
setDisplayType(dir, InfoDisplayType.NONE);
|
||||
setDefaultIoMode(dir);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//----------- Redstone
|
||||
|
||||
@Override
|
||||
public boolean shouldRenderInPass(int pass) {
|
||||
if(faceDisplayTypes == null) {
|
||||
return false;
|
||||
}
|
||||
return pass == 0;
|
||||
}
|
||||
|
||||
public RedstoneControlMode getInputControlMode() {
|
||||
return inputControlMode;
|
||||
}
|
||||
|
||||
public void setInputControlMode(RedstoneControlMode inputControlMode) {
|
||||
this.inputControlMode = inputControlMode;
|
||||
}
|
||||
|
||||
public RedstoneControlMode getOutputControlMode() {
|
||||
return outputControlMode;
|
||||
}
|
||||
|
||||
public void setOutputControlMode(RedstoneControlMode outputControlMode) {
|
||||
this.outputControlMode = outputControlMode;
|
||||
}
|
||||
|
||||
//----------- Power
|
||||
|
||||
@Override
|
||||
public IPowerStorage getController() {
|
||||
return network;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getEnergyStoredL() {
|
||||
if(network == null) {
|
||||
return getEnergyStored();
|
||||
}
|
||||
return network.getEnergyStoredL();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getMaxEnergyStoredL() {
|
||||
if(network == null) {
|
||||
return getMaxEnergyStored();
|
||||
}
|
||||
return network.getMaxEnergyStoredL();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOutputEnabled(ForgeDirection direction) {
|
||||
IoMode mode = getIoMode(direction);
|
||||
return mode == IoMode.PUSH || mode == IoMode.NONE && isOutputEnabled();
|
||||
}
|
||||
|
||||
private boolean isOutputEnabled() {
|
||||
if(network == null) {
|
||||
return true;
|
||||
}
|
||||
return network.isOutputEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInputEnabled(ForgeDirection direction) {
|
||||
IoMode mode = getIoMode(direction);
|
||||
return mode == IoMode.PULL || mode == IoMode.NONE && isInputEnabled();
|
||||
}
|
||||
|
||||
private boolean isInputEnabled() {
|
||||
if(network == null) {
|
||||
return true;
|
||||
}
|
||||
return network.isInputEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCreative() {
|
||||
return getType().isCreative();
|
||||
}
|
||||
|
||||
public List<EnergyReceptor> getReceptors() {
|
||||
if(receptorsDirty) {
|
||||
updateReceptors();
|
||||
}
|
||||
return receptors;
|
||||
}
|
||||
|
||||
private void updateReceptors() {
|
||||
|
||||
if(network == null) {
|
||||
return;
|
||||
}
|
||||
network.removeReceptors(receptors);
|
||||
|
||||
receptors.clear();
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
network.addReceptors(receptors);
|
||||
|
||||
receptorsDirty = false;
|
||||
}
|
||||
|
||||
private IPowerInterface getReceptorForFace(ForgeDirection faceHit) {
|
||||
BlockCoord checkLoc = new BlockCoord(this).getLocation(faceHit);
|
||||
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;
|
||||
}
|
||||
|
||||
private EnergyReceptor getEnergyReceptorForFace(ForgeDirection dir) {
|
||||
IPowerInterface pi = getReceptorForFace(dir);
|
||||
if(pi == null || pi.getDelegate() instanceof TileCapBank) {
|
||||
return null;
|
||||
}
|
||||
return new EnergyReceptor(this, pi, dir);
|
||||
}
|
||||
|
||||
private void validateModeForReceptor(EnergyReceptor er) {
|
||||
IoMode ioMode = getIoMode(er.getDir());
|
||||
if((ioMode == IoMode.PUSH_PULL || ioMode == IoMode.NONE) && 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addEnergy(int energy) {
|
||||
if(network == null) {
|
||||
setEnergyStored(getEnergyStored() + energy);
|
||||
} else {
|
||||
network.addEnergy(energy);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnergyStored(int stored) {
|
||||
energyStored = MathHelper.clamp_int(stored, 0, getMaxEnergyStored());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyStored() {
|
||||
return energyStored;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyStored(ForgeDirection from) {
|
||||
return getEnergyStored();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored() {
|
||||
return getType().getMaxEnergyStored();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyRecieved(ForgeDirection dir) {
|
||||
return getMaxInput();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxInput() {
|
||||
if(network == null) {
|
||||
return getType().getMaxIO();
|
||||
}
|
||||
return network.getMaxInput();
|
||||
}
|
||||
|
||||
public void setMaxInput(int maxInput) {
|
||||
this.maxInput = maxInput;
|
||||
}
|
||||
|
||||
public int getMaxInputOverride() {
|
||||
return maxInput;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxOutput() {
|
||||
if(network == null) {
|
||||
return getType().getMaxIO();
|
||||
}
|
||||
return network.getMaxOutput();
|
||||
}
|
||||
|
||||
public void setMaxOutput(int maxOutput) {
|
||||
this.maxOutput = maxOutput;
|
||||
}
|
||||
|
||||
public int getMaxOutputOverride() {
|
||||
return maxOutput;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate) {
|
||||
if(network == null) {
|
||||
return 0;
|
||||
}
|
||||
IoMode mode = getIoMode(from);
|
||||
if(mode == IoMode.DISABLED || mode == IoMode.PUSH) {
|
||||
return 0;
|
||||
}
|
||||
return network.recieveEnergy(maxReceive, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored(ForgeDirection from) {
|
||||
return getType().getMaxEnergyStored();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnectEnergy(ForgeDirection from) {
|
||||
return getIoMode(from) != IoMode.DISABLED;
|
||||
}
|
||||
|
||||
public int getComparatorOutput() {
|
||||
return (int) (((double) getEnergyStored() / (double) getMaxEnergyStored()) * 15);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean displayPower() {
|
||||
return true;
|
||||
}
|
||||
|
||||
//------------------- Inventory
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slot) {
|
||||
if(network == null) {
|
||||
return null;
|
||||
}
|
||||
return network.getInventory().getStackInSlot(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int fromSlot, int amount) {
|
||||
if(network == null) {
|
||||
return null;
|
||||
}
|
||||
return network.getInventory().decrStackSize(fromSlot, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int slot, ItemStack itemstack) {
|
||||
if(network == null) {
|
||||
return;
|
||||
}
|
||||
network.getInventory().setInventorySlotContents(slot, itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int p_70304_1_) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName() {
|
||||
return EnderIO.blockCapacitorBank.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 void openInventory() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory() {
|
||||
}
|
||||
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
|
||||
//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);
|
||||
}
|
||||
if(maxOutput != -1) {
|
||||
nbtRoot.setInteger("maxOutput", maxOutput);
|
||||
}
|
||||
if(inputControlMode != RedstoneControlMode.IGNORE) {
|
||||
nbtRoot.setShort("inputControlMode", (short) inputControlMode.ordinal());
|
||||
}
|
||||
if(outputControlMode != RedstoneControlMode.IGNORE) {
|
||||
nbtRoot.setShort("outputControlMode", (short) outputControlMode.ordinal());
|
||||
}
|
||||
|
||||
//face modes
|
||||
if(faceModes != null) {
|
||||
nbtRoot.setByte("hasFaces", (byte) 1);
|
||||
for (Entry<ForgeDirection, IoMode> e : faceModes.entrySet()) {
|
||||
nbtRoot.setShort("face" + e.getKey().ordinal(), (short) e.getValue().ordinal());
|
||||
}
|
||||
}
|
||||
|
||||
//display type
|
||||
if(faceDisplayTypes != null) {
|
||||
nbtRoot.setByte("hasDisplayTypes", (byte) 1);
|
||||
for (Entry<ForgeDirection, InfoDisplayType> e : faceDisplayTypes.entrySet()) {
|
||||
if(e.getValue() != InfoDisplayType.NONE) {
|
||||
nbtRoot.setShort("faceDisplay" + e.getKey().ordinal(), (short) e.getValue().ordinal());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boolean hasItems = false;
|
||||
NBTTagList itemList = new NBTTagList();
|
||||
for (int i = 0; i < inventory.length; i++) {
|
||||
if(inventory[i] != null) {
|
||||
hasItems = true;
|
||||
NBTTagCompound itemStackNBT = new NBTTagCompound();
|
||||
itemStackNBT.setByte("Slot", (byte) i);
|
||||
inventory[i].writeToNBT(itemStackNBT);
|
||||
itemList.appendTag(itemStackNBT);
|
||||
}
|
||||
}
|
||||
if(hasItems) {
|
||||
nbtRoot.setTag("Items", itemList);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readCustomNBT(NBTTagCompound nbtRoot) {
|
||||
readCommonNBT(nbtRoot);
|
||||
}
|
||||
|
||||
//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);
|
||||
setEnergyStored(energyStored); //Call this to clamp values in case config changed
|
||||
|
||||
if(nbtRoot.hasKey("maxInput")) {
|
||||
maxInput = nbtRoot.getInteger("maxInput");
|
||||
} else {
|
||||
maxInput = -1;
|
||||
}
|
||||
if(nbtRoot.hasKey("maxOutput")) {
|
||||
maxOutput = nbtRoot.getInteger("maxOutput");
|
||||
} else {
|
||||
maxOutput = -1;
|
||||
}
|
||||
|
||||
if(nbtRoot.hasKey("inputControlMode")) {
|
||||
inputControlMode = RedstoneControlMode.values()[nbtRoot.getShort("inputControlMode")];
|
||||
} else {
|
||||
inputControlMode = RedstoneControlMode.IGNORE;
|
||||
}
|
||||
if(nbtRoot.hasKey("outputControlMode")) {
|
||||
outputControlMode = RedstoneControlMode.values()[nbtRoot.getShort("outputControlMode")];
|
||||
} else {
|
||||
outputControlMode = RedstoneControlMode.IGNORE;
|
||||
}
|
||||
|
||||
if(nbtRoot.hasKey("hasFaces")) {
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
String key = "face" + dir.ordinal();
|
||||
if(nbtRoot.hasKey(key)) {
|
||||
setIoMode(dir, IoMode.values()[nbtRoot.getShort(key)], false);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
faceModes = null;
|
||||
}
|
||||
|
||||
if(nbtRoot.hasKey("hasDisplayTypes")) {
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
String key = "faceDisplay" + dir.ordinal();
|
||||
if(nbtRoot.hasKey(key)) {
|
||||
setDisplayType(dir, InfoDisplayType.values()[nbtRoot.getShort(key)], false);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
faceDisplayTypes = null;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,250 @@
|
||||
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 net.minecraftforge.common.util.ForgeDirection;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.machine.RedstoneControlMode;
|
||||
import crazypants.enderio.machine.capbank.TileCapBank;
|
||||
import crazypants.enderio.machine.capbank.packet.PacketNetworkEnergyRequest;
|
||||
import crazypants.enderio.network.PacketHandler;
|
||||
import crazypants.enderio.power.IPowerStorage;
|
||||
import crazypants.util.BlockCoord;
|
||||
|
||||
public class CapBankClientNetwork implements ICapBankNetwork {
|
||||
|
||||
private final int id;
|
||||
private final List<TileCapBank> members = new ArrayList<TileCapBank>();
|
||||
private int maxEnergySent;
|
||||
private int maxEnergyRecieved;
|
||||
|
||||
private int stateUpdateCount;
|
||||
private int maxIO;
|
||||
private long maxEnergyStored;
|
||||
private long energyStored;
|
||||
|
||||
private RedstoneControlMode inputControlMode = RedstoneControlMode.IGNORE;
|
||||
private RedstoneControlMode outputControlMode = RedstoneControlMode.IGNORE;
|
||||
|
||||
private final InventoryImpl inventory = new InventoryImpl();
|
||||
|
||||
private float aveChange;
|
||||
|
||||
private long lastPowerRequestTick = -1;
|
||||
|
||||
public CapBankClientNetwork(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void requestPowerUpdate(TileCapBank capBank, int interval) {
|
||||
long curTick = EnderIO.proxy.getTickCount();
|
||||
if(lastPowerRequestTick == -1 || curTick - lastPowerRequestTick >= interval) {
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketNetworkEnergyRequest(capBank));
|
||||
lastPowerRequestTick = curTick;
|
||||
}
|
||||
}
|
||||
|
||||
public void setState(World world, NetworkState state) {
|
||||
maxEnergyRecieved = state.getMaxInput();
|
||||
maxEnergySent = state.getMaxOutput();
|
||||
maxIO = state.getMaxIO();
|
||||
maxEnergyStored = state.getMaxEnergyStored();
|
||||
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++;
|
||||
}
|
||||
|
||||
public int getStateUpdateCount() {
|
||||
return stateUpdateCount;
|
||||
}
|
||||
|
||||
public void setStateUpdateCount(int stateUpdateCount) {
|
||||
this.stateUpdateCount = stateUpdateCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addMember(TileCapBank capBank) {
|
||||
members.add(capBank);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TileCapBank> getMembers() {
|
||||
return members;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyNetwork() {
|
||||
for (TileCapBank cb : members) {
|
||||
cb.setNetworkId(-1);
|
||||
cb.setNetwork(null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxIO() {
|
||||
return maxIO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getMaxEnergyStoredL() {
|
||||
return maxEnergyStored;
|
||||
}
|
||||
|
||||
public void setMaxEnergyStoredL(long maxEnergyStored) {
|
||||
this.maxEnergyStored = maxEnergyStored;
|
||||
}
|
||||
|
||||
public void setEnergyStored(long energyStored) {
|
||||
this.energyStored = energyStored;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getEnergyStoredL() {
|
||||
return energyStored;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxOutput() {
|
||||
return maxEnergySent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxOutput(int max) {
|
||||
maxEnergySent = MathHelper.clamp_int(max, 0, maxIO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxInput() {
|
||||
return maxEnergyRecieved;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxInput(int max) {
|
||||
maxEnergyRecieved = MathHelper.clamp_int(max, 0, maxIO);
|
||||
}
|
||||
|
||||
public double getEnergyStoredRatio() {
|
||||
if(getMaxEnergyStoredL() <= 0) {
|
||||
return 0;
|
||||
}
|
||||
return (double) getEnergyStoredL() / getMaxEnergyStoredL();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedstoneControlMode getInputControlMode() {
|
||||
return inputControlMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInputControlMode(RedstoneControlMode inputControlMode) {
|
||||
this.inputControlMode = inputControlMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedstoneControlMode getOutputControlMode() {
|
||||
return outputControlMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOutputControlMode(RedstoneControlMode outputControlMode) {
|
||||
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) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOutputEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInputEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPowerStorage getController() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOutputEnabled(ForgeDirection direction) {
|
||||
return isOutputEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInputEnabled(ForgeDirection direction) {
|
||||
return isInputEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCreative() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,558 @@
|
||||
package crazypants.enderio.machine.capbank.network;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import cofh.api.energy.IEnergyContainerItem;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent.ServerTickEvent;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.conduit.ConduitNetworkTickHandler;
|
||||
import crazypants.enderio.conduit.ConduitNetworkTickHandler.TickListener;
|
||||
import crazypants.enderio.conduit.ConnectionMode;
|
||||
import crazypants.enderio.conduit.power.IPowerConduit;
|
||||
import crazypants.enderio.machine.IoMode;
|
||||
import crazypants.enderio.machine.RedstoneControlMode;
|
||||
import crazypants.enderio.machine.capbank.CapBankType;
|
||||
import crazypants.enderio.machine.capbank.TileCapBank;
|
||||
import crazypants.enderio.machine.capbank.packet.PacketNetworkEnergyResponse;
|
||||
import crazypants.enderio.machine.capbank.packet.PacketNetworkStateResponse;
|
||||
import crazypants.enderio.power.IPowerInterface;
|
||||
import crazypants.enderio.power.IPowerStorage;
|
||||
import crazypants.enderio.power.PerTickIntAverageCalculator;
|
||||
import crazypants.util.BlockCoord;
|
||||
import crazypants.util.RoundRobinIterator;
|
||||
|
||||
public class CapBankNetwork implements ICapBankNetwork {
|
||||
|
||||
private static final int IO_CAP = 2000000000;
|
||||
|
||||
private final List<TileCapBank> capBanks = new ArrayList<TileCapBank>();
|
||||
|
||||
private final Set<EnergyReceptor> receptors = new HashSet<EnergyReceptor>();
|
||||
private RoundRobinIterator<EnergyReceptor> receptorIterator;
|
||||
|
||||
private final int id;
|
||||
|
||||
private int maxIO;
|
||||
|
||||
private int maxInput = -1;
|
||||
|
||||
private int maxOutput = -1;
|
||||
|
||||
private long timeAtLastApply;
|
||||
|
||||
private long energyStored;
|
||||
private long prevEnergyStored = -1;
|
||||
|
||||
private long maxEnergyStored;
|
||||
|
||||
private CapBankType type;
|
||||
|
||||
private Set<BlockCoord> redstoneRecievers = new HashSet<BlockCoord>();
|
||||
|
||||
private RedstoneControlMode inputControlMode = RedstoneControlMode.IGNORE;
|
||||
private RedstoneControlMode outputControlMode = RedstoneControlMode.IGNORE;
|
||||
|
||||
private boolean inputRedstoneConditionMet = true;
|
||||
private boolean outputRedstoneConditionMet = true;
|
||||
|
||||
private TickListener tickListener;
|
||||
|
||||
private PerTickIntAverageCalculator powerTracker = new PerTickIntAverageCalculator(2);
|
||||
|
||||
private final InventoryImpl inventory = new InventoryImpl();
|
||||
|
||||
private boolean firstUpate = true;
|
||||
|
||||
public CapBankNetwork(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
//--------- Network Management
|
||||
|
||||
public void init(TileCapBank cap, Collection<TileCapBank> neighbours, World world) {
|
||||
if(world.isRemote) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
tickListener = new TickReciever();
|
||||
|
||||
type = cap.getType();
|
||||
inputControlMode = cap.getInputControlMode();
|
||||
outputControlMode = cap.getOutputControlMode();
|
||||
for (TileCapBank con : neighbours) {
|
||||
ICapBankNetwork network = con.getNetwork();
|
||||
if(network != null) {
|
||||
network.destroyNetwork();
|
||||
}
|
||||
}
|
||||
setNetwork(world, cap);
|
||||
}
|
||||
|
||||
|
||||
protected void setNetwork(World world, TileCapBank cap) {
|
||||
if(cap != null && cap.setNetwork(this)) {
|
||||
addMember(cap);
|
||||
Collection<TileCapBank> neighbours = NetworkUtil.getNeigbours(cap);
|
||||
for (TileCapBank neighbour : neighbours) {
|
||||
if(neighbour.getNetwork() == null) {
|
||||
setNetwork(world, neighbour);
|
||||
} else if(neighbour.getNetwork() != this) {
|
||||
neighbour.getNetwork().destroyNetwork();
|
||||
setNetwork(world, neighbour);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyNetwork() {
|
||||
distributeEnergyToBanks();
|
||||
TileCapBank cap = null;
|
||||
for (TileCapBank cb : capBanks) {
|
||||
cb.setNetwork(null);
|
||||
if(cap == null) {
|
||||
cap = cb;
|
||||
}
|
||||
}
|
||||
capBanks.clear();
|
||||
if(cap != null) {
|
||||
EnderIO.packetPipeline.INSTANCE.sendToAll(new PacketNetworkStateResponse(this, true));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TileCapBank> getMembers() {
|
||||
return capBanks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addMember(TileCapBank cap) {
|
||||
if(!capBanks.contains(cap)) {
|
||||
capBanks.add(cap);
|
||||
long newIO = maxIO + cap.getType().getMaxIO();
|
||||
if(newIO > IO_CAP) {
|
||||
newIO = IO_CAP;
|
||||
}
|
||||
maxIO = (int) newIO;
|
||||
|
||||
energyStored += cap.getEnergyStored();
|
||||
maxEnergyStored += cap.getMaxEnergyStored();
|
||||
if(maxInput == -1) {
|
||||
maxInput = cap.getMaxInputOverride();
|
||||
}
|
||||
if(maxOutput == -1) {
|
||||
maxOutput = cap.getMaxOutputOverride();
|
||||
}
|
||||
cap.setInputControlMode(inputControlMode);
|
||||
cap.setOutputControlMode(outputControlMode);
|
||||
|
||||
List<EnergyReceptor> recs = cap.getReceptors();
|
||||
if(!recs.isEmpty()) {
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkState getState() {
|
||||
return new NetworkState(this);
|
||||
}
|
||||
|
||||
//--------- Tick Handling
|
||||
|
||||
@Override
|
||||
public void onUpdateEntity(TileCapBank tileCapBank) {
|
||||
World world = tileCapBank.getWorldObj();
|
||||
if(world == null) {
|
||||
return;
|
||||
}
|
||||
if(world.isRemote) {
|
||||
return;
|
||||
}
|
||||
long curTime = world.getTotalWorldTime();
|
||||
if(curTime != timeAtLastApply) {
|
||||
timeAtLastApply = curTime;
|
||||
ConduitNetworkTickHandler.instance.addListener(tickListener);
|
||||
}
|
||||
}
|
||||
|
||||
private void doNetworkTick() {
|
||||
|
||||
chargeItems(inventory.getStacks());
|
||||
transmitEnergy();
|
||||
|
||||
if(energyStored != prevEnergyStored) {
|
||||
distributeEnergyToBanks();
|
||||
}
|
||||
if(prevEnergyStored != -1) {
|
||||
powerTracker.tick((int) (energyStored - prevEnergyStored));
|
||||
}
|
||||
prevEnergyStored = energyStored;
|
||||
|
||||
if(firstUpate) {
|
||||
if(!capBanks.isEmpty()) {
|
||||
EnderIO.packetPipeline.sendToAllAround(new PacketNetworkStateResponse(this), capBanks.get(0));
|
||||
EnderIO.packetPipeline.sendToAllAround(new PacketNetworkEnergyResponse(this), capBanks.get(0));
|
||||
}
|
||||
firstUpate = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void transmitEnergy() {
|
||||
|
||||
if(!outputRedstoneConditionMet) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(receptors.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int available = getEnergyAvailableForTick(getMaxOutput());
|
||||
if(available <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(receptorIterator == null) {
|
||||
List<EnergyReceptor> rl = new ArrayList<EnergyReceptor>(receptors);
|
||||
receptorIterator = new RoundRobinIterator<EnergyReceptor>(rl);
|
||||
}
|
||||
|
||||
int totalSent = 0;
|
||||
Iterator<EnergyReceptor> iter = receptorIterator.iterator();
|
||||
while (available > 0 && iter.hasNext()) {
|
||||
int sent = sendPowerTo(iter.next(), available);
|
||||
totalSent += sent;
|
||||
available -= sent;
|
||||
}
|
||||
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) {
|
||||
//Can only send to power conduits if we are in push mode or the conduit is in pull mode
|
||||
//With default setting interaction between conduits and Cap Banks is handled by NetworkPowerManager
|
||||
IPowerConduit con = next.getConduit();
|
||||
if(con != null && next.getMode() == IoMode.NONE && con.getConnectionMode(next.getDir().getOpposite()) == ConnectionMode.IN_OUT) {
|
||||
return 0;
|
||||
}
|
||||
IPowerInterface inf = next.getReceptor();
|
||||
int result = inf.recieveEnergy(next.getDir().getOpposite(), available);
|
||||
if(result < 0) {
|
||||
result = 0;
|
||||
}
|
||||
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;
|
||||
}
|
||||
int energyPerCapBank = (int) (energyStored / capBanks.size());
|
||||
int remaining = (int) (energyStored % capBanks.size());
|
||||
for (TileCapBank cb : capBanks) {
|
||||
cb.setEnergyStored(energyPerCapBank);
|
||||
}
|
||||
TileCapBank cb = capBanks.get(0);
|
||||
cb.setEnergyStored(cb.getEnergyStored() + remaining);
|
||||
}
|
||||
|
||||
//------ Power
|
||||
|
||||
@Override
|
||||
public float getAverageChangePerTick() {
|
||||
return powerTracker.getAverage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int recieveEnergy(int maxReceive, boolean simulate) {
|
||||
if(maxReceive <= 0 || !inputRedstoneConditionMet) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
long spaceAvailable = maxEnergyStored - energyStored;
|
||||
if(spaceAvailable > Integer.MAX_VALUE) {
|
||||
spaceAvailable = Integer.MAX_VALUE;
|
||||
}
|
||||
int res = Math.min(maxReceive, (int) spaceAvailable);
|
||||
res = Math.min(maxReceive, getMaxInput());
|
||||
if(!simulate) {
|
||||
if(!type.isCreative()) {
|
||||
addEnergy(res);
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addEnergy(int energy) {
|
||||
energyStored += energy;
|
||||
if(energyStored > maxEnergyStored) {
|
||||
energyStored = maxEnergyStored;
|
||||
} else if(energyStored < 0) {
|
||||
energyStored = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void addEnergyReceptor(EnergyReceptor rec) {
|
||||
receptors.add(rec);
|
||||
receptorIterator = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addReceptors(Collection<EnergyReceptor> rec) {
|
||||
if(rec.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
receptors.addAll(rec);
|
||||
receptorIterator = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeReceptors(Collection<EnergyReceptor> rec) {
|
||||
if(rec.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
receptors.removeAll(rec);
|
||||
receptorIterator = null;
|
||||
}
|
||||
|
||||
public void removeReceptor(EnergyReceptor rec) {
|
||||
receptors.remove(rec);
|
||||
receptorIterator = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getEnergyStoredL() {
|
||||
return energyStored;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getMaxEnergyStoredL() {
|
||||
return maxEnergyStored;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxIO() {
|
||||
return maxIO;
|
||||
}
|
||||
|
||||
//----- IO overrides
|
||||
|
||||
@Override
|
||||
public int getMaxInput() {
|
||||
if(maxInput == -1) {
|
||||
return maxIO;
|
||||
}
|
||||
return Math.min(maxInput, maxIO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxOutput() {
|
||||
if(maxOutput == -1) {
|
||||
return maxIO;
|
||||
}
|
||||
return Math.min(maxOutput, maxIO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxInput(int max) {
|
||||
if(max >= maxIO) {
|
||||
maxInput = -1;
|
||||
} else if(max < 0) {
|
||||
maxInput = 0;
|
||||
} else {
|
||||
maxInput = max;
|
||||
}
|
||||
for (TileCapBank cb : capBanks) {
|
||||
cb.setMaxInput(maxInput);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxOutput(int max) {
|
||||
if(max >= maxIO) {
|
||||
maxOutput = -1;
|
||||
} else if(max < 0) {
|
||||
maxOutput = 0;
|
||||
} else {
|
||||
maxOutput = max;
|
||||
}
|
||||
for (TileCapBank cb : capBanks) {
|
||||
cb.setMaxOutput(maxOutput);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//----------- Redstone
|
||||
|
||||
@Override
|
||||
public RedstoneControlMode getInputControlMode() {
|
||||
return inputControlMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInputControlMode(RedstoneControlMode inputControlMode) {
|
||||
if(this.inputControlMode == inputControlMode) {
|
||||
return;
|
||||
}
|
||||
this.inputControlMode = inputControlMode;
|
||||
for (TileCapBank capBank : capBanks) {
|
||||
capBank.setInputControlMode(inputControlMode);
|
||||
}
|
||||
updateRedstoneConditions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedstoneControlMode getOutputControlMode() {
|
||||
return outputControlMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOutputControlMode(RedstoneControlMode outputControlMode) {
|
||||
if(this.outputControlMode == outputControlMode) {
|
||||
return;
|
||||
}
|
||||
this.outputControlMode = outputControlMode;
|
||||
for (TileCapBank capBank : capBanks) {
|
||||
capBank.setOutputControlMode(outputControlMode);
|
||||
}
|
||||
updateRedstoneConditions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateRedstoneSignal(TileCapBank tileCapBank, boolean recievingSignal) {
|
||||
if(recievingSignal) {
|
||||
redstoneRecievers.add(tileCapBank.getLocation());
|
||||
} else {
|
||||
redstoneRecievers.remove(tileCapBank.getLocation());
|
||||
}
|
||||
updateRedstoneConditions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInputEnabled() {
|
||||
return inputRedstoneConditionMet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOutputEnabled() {
|
||||
return outputRedstoneConditionMet;
|
||||
}
|
||||
|
||||
private void updateRedstoneConditions() {
|
||||
int powerLevel = redstoneRecievers.isEmpty() ? 0 : 15;
|
||||
inputRedstoneConditionMet = RedstoneControlMode.isConditionMet(inputControlMode, powerLevel);
|
||||
outputRedstoneConditionMet = RedstoneControlMode.isConditionMet(outputControlMode, powerLevel);
|
||||
|
||||
}
|
||||
|
||||
private class TickReciever implements TickListener {
|
||||
|
||||
@Override
|
||||
public void tickStart(ServerTickEvent evt) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tickEnd(ServerTickEvent evt) {
|
||||
doNetworkTick();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPowerStorage getController() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOutputEnabled(ForgeDirection direction) {
|
||||
return isOutputEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInputEnabled(ForgeDirection direction) {
|
||||
return isInputEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCreative() {
|
||||
return type.isCreative();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
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 {
|
||||
|
||||
private static final ClientNetworkManager instance = new ClientNetworkManager();
|
||||
|
||||
public static ClientNetworkManager getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
private Map<Integer, CapBankClientNetwork> networks = new HashMap<Integer, CapBankClientNetwork>();
|
||||
|
||||
ClientNetworkManager() {
|
||||
}
|
||||
|
||||
public void destroyNetwork(int id) {
|
||||
CapBankClientNetwork res = networks.get(id);
|
||||
if(res != null) {
|
||||
res.destroyNetwork();
|
||||
networks.remove(res);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateState(World world, int id, NetworkState state) {
|
||||
CapBankClientNetwork network = getOrCreateNetwork(id);
|
||||
network.setState(world, state);
|
||||
}
|
||||
|
||||
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) {
|
||||
CapBankClientNetwork res = networks.get(id);
|
||||
if(res == null) {
|
||||
res = new CapBankClientNetwork(id);
|
||||
networks.put(id, res);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public void addToNetwork(int id, TileCapBank tileCapBank) {
|
||||
CapBankClientNetwork network = getOrCreateNetwork(id);
|
||||
network.addMember(tileCapBank);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package crazypants.enderio.machine.capbank.network;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import crazypants.enderio.conduit.IConduitBundle;
|
||||
import crazypants.enderio.conduit.power.IPowerConduit;
|
||||
import crazypants.enderio.machine.IoMode;
|
||||
import crazypants.enderio.machine.capbank.TileCapBank;
|
||||
import crazypants.enderio.power.IPowerInterface;
|
||||
import crazypants.util.BlockCoord;
|
||||
|
||||
public class EnergyReceptor {
|
||||
|
||||
private final IPowerInterface receptor;
|
||||
private final ForgeDirection fromDir;
|
||||
private final IoMode mode;
|
||||
private final BlockCoord location;
|
||||
|
||||
private final IPowerConduit conduit;
|
||||
|
||||
public EnergyReceptor(TileCapBank cb, IPowerInterface receptor, ForgeDirection dir) {
|
||||
this.receptor = receptor;
|
||||
fromDir = dir;
|
||||
mode = cb.getIoMode(dir);
|
||||
if(receptor.getDelegate() instanceof IConduitBundle) {
|
||||
conduit = ((IConduitBundle) receptor.getDelegate()).getConduit(IPowerConduit.class);
|
||||
} else {
|
||||
conduit = null;
|
||||
}
|
||||
location = cb.getLocation();
|
||||
}
|
||||
|
||||
public IPowerConduit getConduit() {
|
||||
return conduit;
|
||||
}
|
||||
|
||||
public IPowerInterface getReceptor() {
|
||||
return receptor;
|
||||
}
|
||||
|
||||
public ForgeDirection getDir() {
|
||||
return fromDir;
|
||||
}
|
||||
|
||||
public IoMode getMode() {
|
||||
return mode;
|
||||
}
|
||||
|
||||
//NB: Special impl of equals and hash code based solely on the location and dir
|
||||
//This is done to ensure the receptors in the Networks Set are added / removed correctly
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((fromDir == null) ? 0 : fromDir.hashCode());
|
||||
result = prime * result + ((location == null) ? 0 : location.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(this == obj) {
|
||||
return true;
|
||||
}
|
||||
if(obj == null) {
|
||||
return false;
|
||||
}
|
||||
if(getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
EnergyReceptor other = (EnergyReceptor) obj;
|
||||
if(fromDir != other.fromDir) {
|
||||
return false;
|
||||
}
|
||||
if(location == null) {
|
||||
if(other.location != null) {
|
||||
return false;
|
||||
}
|
||||
} else if(!location.equals(other.location)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "EnergyReceptor [receptor=" + receptor + ", fromDir=" + fromDir + ", mode=" + mode + ", conduit=" + conduit + "]";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package crazypants.enderio.machine.capbank.network;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import crazypants.enderio.machine.RedstoneControlMode;
|
||||
import crazypants.enderio.machine.capbank.TileCapBank;
|
||||
import crazypants.enderio.power.IPowerStorage;
|
||||
|
||||
public interface ICapBankNetwork extends IPowerStorage {
|
||||
|
||||
//------ Network
|
||||
|
||||
int getId();
|
||||
|
||||
void addMember(TileCapBank cap);
|
||||
|
||||
List<TileCapBank> getMembers();
|
||||
|
||||
void destroyNetwork();
|
||||
|
||||
NetworkState getState();
|
||||
|
||||
void onUpdateEntity(TileCapBank tileCapBank);
|
||||
|
||||
|
||||
//------ Energy
|
||||
|
||||
@Override
|
||||
long getEnergyStoredL();
|
||||
|
||||
@Override
|
||||
void addEnergy(int energy);
|
||||
|
||||
int recieveEnergy(int maxReceive, boolean simulate);
|
||||
|
||||
@Override
|
||||
long getMaxEnergyStoredL();
|
||||
|
||||
int getMaxIO();
|
||||
|
||||
@Override
|
||||
int getMaxOutput();
|
||||
|
||||
void setMaxOutput(int max);
|
||||
|
||||
@Override
|
||||
int getMaxInput();
|
||||
|
||||
void setMaxInput(int max);
|
||||
|
||||
float getAverageChangePerTick();
|
||||
|
||||
void removeReceptors(Collection<EnergyReceptor> receptors);
|
||||
|
||||
void addReceptors(Collection<EnergyReceptor> receptors);
|
||||
|
||||
|
||||
//------ Inventory
|
||||
|
||||
InventoryImpl getInventory();
|
||||
|
||||
|
||||
//------ Redstone
|
||||
|
||||
void setOutputControlMode(RedstoneControlMode outputControlMode);
|
||||
|
||||
RedstoneControlMode getOutputControlMode();
|
||||
|
||||
void setInputControlMode(RedstoneControlMode inputControlMode);
|
||||
|
||||
RedstoneControlMode getInputControlMode();
|
||||
|
||||
void updateRedstoneSignal(TileCapBank tileCapBank, boolean recievingSignal);
|
||||
|
||||
boolean isOutputEnabled();
|
||||
|
||||
boolean isInputEnabled();
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -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() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
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 {
|
||||
|
||||
private final long energyStored;
|
||||
private final long maxEnergyStored;
|
||||
private final int maxIO;
|
||||
private final int maxInput;
|
||||
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, null, 0);
|
||||
}
|
||||
|
||||
public NetworkState(long energyStored, long maxEnergyStored, int maxIO, int maxInput, int maxOutput, RedstoneControlMode inputMode,
|
||||
RedstoneControlMode outputMode, BlockCoord invImplLoc, float averageChange) {
|
||||
this.energyStored = energyStored;
|
||||
this.maxEnergyStored = maxEnergyStored;
|
||||
this.maxIO = maxIO;
|
||||
this.maxInput = maxInput;
|
||||
this.maxOutput = maxOutput;
|
||||
this.inputMode = inputMode;
|
||||
this.outputMode = outputMode;
|
||||
this.invImplLoc = invImplLoc;
|
||||
this.averageChange = averageChange;
|
||||
}
|
||||
|
||||
public NetworkState(ICapBankNetwork network) {
|
||||
energyStored = network.getEnergyStoredL();
|
||||
maxEnergyStored = network.getMaxEnergyStoredL();
|
||||
maxIO = network.getMaxIO();
|
||||
maxInput = network.getMaxInput();
|
||||
maxOutput = network.getMaxOutput();
|
||||
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() {
|
||||
return energyStored;
|
||||
}
|
||||
|
||||
public long getMaxEnergyStored() {
|
||||
return maxEnergyStored;
|
||||
}
|
||||
|
||||
public int getMaxOutput() {
|
||||
return maxOutput;
|
||||
}
|
||||
|
||||
public int getMaxInput() {
|
||||
return maxInput;
|
||||
}
|
||||
|
||||
public int getMaxIO() {
|
||||
return maxIO;
|
||||
}
|
||||
|
||||
public RedstoneControlMode getInputMode() {
|
||||
return inputMode;
|
||||
}
|
||||
|
||||
public RedstoneControlMode getOutputMode() {
|
||||
return outputMode;
|
||||
}
|
||||
|
||||
public BlockCoord getInventoryImplLocation() {
|
||||
return invImplLoc;
|
||||
}
|
||||
|
||||
public float getAverageChange() {
|
||||
return averageChange;
|
||||
}
|
||||
|
||||
public void writeToBuf(ByteBuf buf) {
|
||||
buf.writeLong(energyStored);
|
||||
buf.writeLong(maxEnergyStored);
|
||||
buf.writeInt(maxIO);
|
||||
buf.writeInt(maxInput);
|
||||
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()],
|
||||
buf.readBoolean() ? BlockCoord.readFromBuf(buf) : null, buf.readFloat());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "NetworkClientState [energyStored=" + energyStored + ", maxEnergyStored=" + maxEnergyStored + ", maxIO=" + maxIO + ", maxInput=" + maxInput
|
||||
+ ", maxOutput=" + maxOutput + "]";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package crazypants.enderio.machine.capbank.network;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import crazypants.enderio.machine.capbank.TileCapBank;
|
||||
import crazypants.util.BlockCoord;
|
||||
|
||||
public class NetworkUtil {
|
||||
|
||||
private static AtomicInteger nextID = new AtomicInteger(0);
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public static void ensureValidNetwork(TileCapBank cap) {
|
||||
World world = cap.getWorldObj();
|
||||
Collection<TileCapBank> neighbours = getNeigbours(cap);
|
||||
if(reuseNetwork(cap, neighbours, world)) {
|
||||
return;
|
||||
}
|
||||
CapBankNetwork network = new CapBankNetwork(nextID.getAndIncrement());
|
||||
network.init(cap, neighbours, world);
|
||||
return;
|
||||
}
|
||||
|
||||
public static Collection<TileCapBank> getNeigbours(TileCapBank cap) {
|
||||
if(!cap.getType().isMultiblock()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<TileCapBank> res = new ArrayList<TileCapBank>();
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
BlockCoord bc = cap.getLocation().getLocation(dir);
|
||||
TileEntity te = cap.getWorldObj().getTileEntity(bc.x, bc.y, bc.z);
|
||||
if(te instanceof TileCapBank) {
|
||||
TileCapBank neighbour = (TileCapBank) te;
|
||||
if(neighbour.canConnectTo(cap)) {
|
||||
res.add(neighbour);
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
private static boolean reuseNetwork(TileCapBank cap, Collection<TileCapBank> neighbours, World world) {
|
||||
ICapBankNetwork network = null;
|
||||
for (TileCapBank conduit : neighbours) {
|
||||
if(network == null) {
|
||||
network = conduit.getNetwork();
|
||||
} else if(network != conduit.getNetwork()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(network == null) {
|
||||
return false;
|
||||
}
|
||||
if(cap.setNetwork(network)) {
|
||||
network.addMember(cap);
|
||||
//network.notifyNetworkOfUpdate();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package crazypants.enderio.machine.capbank.packet;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
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 cpw.mods.fml.relauncher.Side;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.machine.capbank.TileCapBank;
|
||||
|
||||
public abstract class PacketCapBank<T extends PacketCapBank, Q extends IMessage> implements IMessage, IMessageHandler<T, Q> {
|
||||
|
||||
private int x;
|
||||
private int y;
|
||||
private int z;
|
||||
|
||||
public PacketCapBank() {
|
||||
}
|
||||
|
||||
public PacketCapBank(TileCapBank capBank) {
|
||||
x = capBank.xCoord;
|
||||
y = capBank.yCoord;
|
||||
z = capBank.zCoord;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeInt(x);
|
||||
buf.writeInt(y);
|
||||
buf.writeInt(z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
x = buf.readInt();
|
||||
y = buf.readInt();
|
||||
z = buf.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Q onMessage(T message, MessageContext ctx) {
|
||||
|
||||
TileCapBank te = getTileEntity(message, ctx);
|
||||
if(te == null) {
|
||||
|
||||
return null;
|
||||
}
|
||||
return handleMessage(te, message, ctx);
|
||||
}
|
||||
|
||||
protected abstract Q handleMessage(TileCapBank te, T message, MessageContext ctx);
|
||||
|
||||
protected TileCapBank getTileEntity(T message, MessageContext ctx) {
|
||||
World worldObj = getWorld(ctx);
|
||||
if(worldObj == null) {
|
||||
return null;
|
||||
}
|
||||
TileEntity te = worldObj.getTileEntity(message.x, message.y, message.z);
|
||||
if(te == null) {
|
||||
return null;
|
||||
}
|
||||
if(te instanceof TileCapBank) {
|
||||
return (TileCapBank) te;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected World getWorld(MessageContext ctx) {
|
||||
if(ctx.side == Side.SERVER) {
|
||||
return ctx.getServerHandler().playerEntity.worldObj;
|
||||
} else {
|
||||
return EnderIO.proxy.getClientWorld();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package crazypants.enderio.machine.capbank.packet;
|
||||
|
||||
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.RedstoneControlMode;
|
||||
import crazypants.enderio.machine.capbank.TileCapBank;
|
||||
import crazypants.enderio.machine.capbank.network.ICapBankNetwork;
|
||||
|
||||
public class PacketGuiChange extends PacketCapBank<PacketGuiChange, IMessage> {
|
||||
|
||||
private int maxSend;
|
||||
private int maxRec;
|
||||
private RedstoneControlMode inputMode;
|
||||
private RedstoneControlMode outputMode;
|
||||
|
||||
public PacketGuiChange() {
|
||||
}
|
||||
|
||||
public PacketGuiChange(TileCapBank capBank) {
|
||||
super(capBank);
|
||||
ICapBankNetwork network = capBank.getNetwork();
|
||||
maxSend = network.getMaxOutput();
|
||||
maxRec = network.getMaxInput();
|
||||
inputMode = network.getInputControlMode();
|
||||
outputMode = network.getOutputControlMode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
super.toBytes(buf);
|
||||
buf.writeInt(maxSend);
|
||||
buf.writeInt(maxRec);
|
||||
buf.writeShort(inputMode.ordinal());
|
||||
buf.writeShort(outputMode.ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
super.fromBytes(buf);
|
||||
maxSend = buf.readInt();
|
||||
maxRec = buf.readInt();
|
||||
inputMode = RedstoneControlMode.values()[buf.readShort()];
|
||||
outputMode = RedstoneControlMode.values()[buf.readShort()];
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IMessage handleMessage(TileCapBank te, PacketGuiChange message, MessageContext ctx) {
|
||||
ICapBankNetwork net = te.getNetwork();
|
||||
if(net == null) {
|
||||
return null;
|
||||
}
|
||||
net.setMaxOutput(message.maxSend);
|
||||
net.setMaxInput(message.maxRec);
|
||||
net.setInputControlMode(message.inputMode);
|
||||
net.setOutputControlMode(message.outputMode);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package crazypants.enderio.machine.capbank.packet;
|
||||
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import crazypants.enderio.machine.capbank.TileCapBank;
|
||||
|
||||
public class PacketNetworkEnergyRequest extends PacketCapBank<PacketNetworkEnergyRequest, PacketNetworkEnergyResponse> {
|
||||
|
||||
public PacketNetworkEnergyRequest() {
|
||||
}
|
||||
|
||||
public PacketNetworkEnergyRequest(TileCapBank capBank) {
|
||||
super(capBank);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PacketNetworkEnergyResponse handleMessage(TileCapBank te, PacketNetworkEnergyRequest message, MessageContext ctx) {
|
||||
if(te.getNetwork() != null) {
|
||||
return new PacketNetworkEnergyResponse(te.getNetwork());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
package crazypants.enderio.machine.capbank.packet;
|
||||
|
||||
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.ClientNetworkManager;
|
||||
import crazypants.enderio.machine.capbank.network.ICapBankNetwork;
|
||||
|
||||
public class PacketNetworkEnergyResponse implements IMessage, IMessageHandler<PacketNetworkEnergyResponse, IMessage> {
|
||||
|
||||
private int id;
|
||||
private long energyStored;
|
||||
private float avChange;
|
||||
|
||||
public PacketNetworkEnergyResponse() {
|
||||
}
|
||||
|
||||
public PacketNetworkEnergyResponse(ICapBankNetwork network) {
|
||||
id = network.getId();
|
||||
energyStored = network.getEnergyStoredL();
|
||||
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().updateEnergy(message.id, message.energyStored, message.avChange);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package crazypants.enderio.machine.capbank.packet;
|
||||
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import crazypants.enderio.machine.capbank.TileCapBank;
|
||||
|
||||
public class PacketNetworkIdRequest extends PacketCapBank<PacketNetworkIdRequest, PacketNetworkIdResponse> {
|
||||
|
||||
public PacketNetworkIdRequest() {
|
||||
}
|
||||
|
||||
public PacketNetworkIdRequest(TileCapBank capBank) {
|
||||
super(capBank);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PacketNetworkIdResponse handleMessage(TileCapBank te, PacketNetworkIdRequest message, MessageContext ctx) {
|
||||
if(te.getNetwork() != null) {
|
||||
return new PacketNetworkIdResponse(te);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package crazypants.enderio.machine.capbank.packet;
|
||||
|
||||
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> {
|
||||
|
||||
private int id;
|
||||
|
||||
public PacketNetworkIdResponse() {
|
||||
}
|
||||
|
||||
PacketNetworkIdResponse(TileCapBank capBank) {
|
||||
super(capBank);
|
||||
if(capBank != null && capBank.getNetwork() != null) {
|
||||
id = capBank.getNetwork().getId();
|
||||
} else {
|
||||
id = -1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
super.toBytes(buf);
|
||||
buf.writeInt(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
super.fromBytes(buf);
|
||||
id = buf.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IMessage handleMessage(TileCapBank te, PacketNetworkIdResponse message, MessageContext ctx) {
|
||||
te.setNetworkId(message.id);
|
||||
te.setNetwork(ClientNetworkManager.getInstance().getOrCreateNetwork(message.id));
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package crazypants.enderio.machine.capbank.packet;
|
||||
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import crazypants.enderio.machine.capbank.TileCapBank;
|
||||
|
||||
public class PacketNetworkStateRequest extends PacketCapBank<PacketNetworkStateRequest, PacketNetworkStateResponse> {
|
||||
|
||||
public PacketNetworkStateRequest() {
|
||||
}
|
||||
|
||||
public PacketNetworkStateRequest(TileCapBank capBank) {
|
||||
super(capBank);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PacketNetworkStateResponse handleMessage(TileCapBank te, PacketNetworkStateRequest message, MessageContext ctx) {
|
||||
return new PacketNetworkStateResponse(te.getNetwork());
|
||||
}
|
||||
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
package crazypants.enderio.machine.capbank.packet;
|
||||
|
||||
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.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> {
|
||||
|
||||
private int id;
|
||||
private NetworkState state;
|
||||
|
||||
public PacketNetworkStateResponse() {
|
||||
}
|
||||
|
||||
public PacketNetworkStateResponse(ICapBankNetwork network) {
|
||||
this(network, false);
|
||||
}
|
||||
|
||||
public PacketNetworkStateResponse(ICapBankNetwork network, boolean remove) {
|
||||
id = network.getId();
|
||||
if(!remove) {
|
||||
state = network.getState();
|
||||
} else {
|
||||
state = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeInt(id);
|
||||
buf.writeBoolean(state != null);
|
||||
if(state != null) {
|
||||
state.writeToBuf(buf);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
id = buf.readInt();
|
||||
boolean hasState = buf.readBoolean();
|
||||
if(hasState) {
|
||||
state = NetworkState.readFromBuf(buf);
|
||||
} else {
|
||||
state = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketNetworkStateResponse message, MessageContext ctx) {
|
||||
if(message.state != null) {
|
||||
ClientNetworkManager.getInstance().updateState(EnderIO.proxy.getClientWorld(), message.id, message.state);
|
||||
} else {
|
||||
ClientNetworkManager.getInstance().destroyNetwork(message.id);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
package crazypants.enderio.machine.capbank.render;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.client.IItemRenderer;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.machine.capbank.BlockCapBank;
|
||||
import crazypants.enderio.machine.capbank.CapBankType;
|
||||
import crazypants.enderio.machine.capbank.InfoDisplayType;
|
||||
import crazypants.enderio.machine.capbank.TileCapBank;
|
||||
import crazypants.enderio.machine.capbank.network.CapBankClientNetwork;
|
||||
import crazypants.enderio.machine.capbank.render.FillGauge.GaugeInfo;
|
||||
import crazypants.enderio.machine.capbank.render.FillGauge.GaugeKey;
|
||||
import crazypants.enderio.power.PowerHandlerUtil;
|
||||
import crazypants.render.ConnectedTextureRenderer;
|
||||
import crazypants.render.CubeRenderer;
|
||||
import crazypants.render.CustomCubeRenderer;
|
||||
import crazypants.render.RenderUtil;
|
||||
|
||||
public class CapBankRenderer extends TileEntitySpecialRenderer implements ISimpleBlockRenderingHandler, IItemRenderer {
|
||||
|
||||
private ConnectedTextureRenderer connectedTexRenderer;
|
||||
|
||||
private Map<InfoDisplayType, IInfoRenderer> infoRenderers;
|
||||
private FillGauge fillGaugeRenderer;
|
||||
|
||||
public CapBankRenderer() {
|
||||
connectedTexRenderer = new ConnectedTextureRenderer();
|
||||
connectedTexRenderer.setMatchMeta(true);
|
||||
fillGaugeRenderer = new FillGauge();
|
||||
infoRenderers = new HashMap<InfoDisplayType, IInfoRenderer>();
|
||||
infoRenderers.put(InfoDisplayType.LEVEL_BAR, fillGaugeRenderer);
|
||||
infoRenderers.put(InfoDisplayType.IO, new IoDisplay());
|
||||
|
||||
}
|
||||
|
||||
//------- Block
|
||||
|
||||
@Override
|
||||
public void renderInventoryBlock(Block block, int metadata, int modelId, RenderBlocks renderer) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
|
||||
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
meta = MathHelper.clamp_int(meta, 0, CapBankType.types().size() - 1);
|
||||
CapBankType type = CapBankType.getTypeFromMeta(meta);
|
||||
if(!type.isMultiblock()) {
|
||||
connectedTexRenderer.setForceAllEdges(true);
|
||||
} else {
|
||||
connectedTexRenderer.setForceAllEdges(false);
|
||||
}
|
||||
connectedTexRenderer.setEdgeTexture(EnderIO.blockCapBank.getBorderIcon(0, meta));
|
||||
CustomCubeRenderer.instance.renderBlock(world, block, x, y, z, connectedTexRenderer);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRender3DInInventory(int modelId) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRenderId() {
|
||||
return BlockCapBank.renderId;
|
||||
}
|
||||
|
||||
//------- Item
|
||||
@Override
|
||||
public boolean handleRenderType(ItemStack item, ItemRenderType type) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
|
||||
|
||||
RenderUtil.bindBlockTexture();
|
||||
Tessellator tes = Tessellator.instance;
|
||||
|
||||
tes.startDrawingQuads();
|
||||
CubeRenderer.render(EnderIO.blockCapBank, item.getItemDamage());
|
||||
tes.draw();
|
||||
|
||||
GL11.glEnable(GL11.GL_POLYGON_OFFSET_FILL);
|
||||
GL11.glPolygonOffset(-1.0f, -1.0f);
|
||||
|
||||
tes.startDrawingQuads();
|
||||
tes.setColorRGBA_F(1, 1, 1, 1);
|
||||
renderBorder(null, 0, 0, 0, item.getItemDamage());
|
||||
tes.draw();
|
||||
|
||||
GL11.glDisable(GL11.GL_POLYGON_OFFSET_FILL);
|
||||
|
||||
|
||||
CapBankClientNetwork nw = new CapBankClientNetwork(-1);
|
||||
nw.setMaxEnergyStoredL(CapBankType.getTypeFromMeta(item.getItemDamage()).getMaxEnergyStored());
|
||||
nw.setEnergyStored(PowerHandlerUtil.getStoredEnergyForItem(item));
|
||||
|
||||
GaugeInfo gi = new GaugeInfo(1, 0);
|
||||
GaugeKey key = new GaugeKey(ForgeDirection.SOUTH, FillGauge.Type.SINGLE);
|
||||
fillGaugeRenderer.doRender(nw, RenderUtil.BRIGHTNESS_MAX, gi, key);
|
||||
// key = new GaugeKey(ForgeDirection.EAST, FillGauge.Type.SINGLE);
|
||||
// fillGaugeRenderer.doRender(nw, RenderUtil.BRIGHTNESS_MAX, gi, key);
|
||||
|
||||
}
|
||||
|
||||
private void renderBorder(IBlockAccess blockAccess, int x, int y, int z, int meta) {
|
||||
IIcon texture = EnderIO.blockCapBank.getBorderIcon(0, meta);
|
||||
for (ForgeDirection face : ForgeDirection.VALID_DIRECTIONS) {
|
||||
RenderUtil.renderConnectedTextureFace(blockAccess, x, y, z, face, texture,
|
||||
blockAccess == null, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
//---- Info Display
|
||||
|
||||
@Override
|
||||
public void renderTileEntityAt(TileEntity te, double x, double y, double z, float partialTick) {
|
||||
|
||||
TileCapBank cb = (TileCapBank) te;
|
||||
|
||||
|
||||
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
|
||||
GL11.glEnable(GL11.GL_POLYGON_OFFSET_FILL);
|
||||
GL11.glPolygonOffset(-1.0f, -1.0f);
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef((float) x, (float) y, (float) z);
|
||||
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
InfoDisplayType type = cb.getDisplayType(dir);
|
||||
if(type != InfoDisplayType.NONE) {
|
||||
IInfoRenderer rend = infoRenderers.get(type);
|
||||
if(rend != null) {
|
||||
rend.render(cb, dir, x, y, z, partialTick);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GL11.glPopMatrix();
|
||||
GL11.glPopAttrib();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,294 @@
|
||||
package crazypants.enderio.machine.capbank.render;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.machine.capbank.CapBankType;
|
||||
import crazypants.enderio.machine.capbank.InfoDisplayType;
|
||||
import crazypants.enderio.machine.capbank.TileCapBank;
|
||||
import crazypants.enderio.machine.capbank.network.CapBankClientNetwork;
|
||||
import crazypants.render.BoundingBox;
|
||||
import crazypants.render.RenderUtil;
|
||||
import crazypants.util.BlockCoord;
|
||||
import crazypants.util.ForgeDirectionOffsets;
|
||||
import crazypants.vecmath.Vector3d;
|
||||
import crazypants.vecmath.Vector4f;
|
||||
import crazypants.vecmath.Vertex;
|
||||
|
||||
public class FillGauge implements IInfoRenderer {
|
||||
|
||||
private static final double HEIGHT = 0.75;
|
||||
private static final double VERT_BORDER = (1 - HEIGHT) / 2;
|
||||
private static final double WIDTH = 0.25;
|
||||
|
||||
enum Type {
|
||||
SINGLE,
|
||||
TOP,
|
||||
BOTTOM,
|
||||
MIDDLE
|
||||
}
|
||||
|
||||
private IIcon barIcon;
|
||||
private IIcon gaugeIcon;
|
||||
|
||||
private float barHeightV;
|
||||
|
||||
private Map<GaugeKey, List<Vertex>> gaugeVertexCache;
|
||||
private Map<GaugeKey, List<Vertex>> levelVertexCache;
|
||||
private float barMinV;
|
||||
|
||||
FillGauge() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(TileCapBank cb, ForgeDirection dir, double x, double y, double z, float partialTick) {
|
||||
|
||||
CapBankClientNetwork nw = null;
|
||||
if(cb.getNetwork() != null) {
|
||||
nw = (CapBankClientNetwork) cb.getNetwork();
|
||||
nw.requestPowerUpdate(cb, 20);
|
||||
}
|
||||
|
||||
int brightness = cb.getWorldObj().getLightBrightnessForSkyBlocks(cb.xCoord + dir.offsetX, cb.yCoord + dir.offsetY, cb.zCoord + dir.offsetZ, 0);
|
||||
GaugeInfo info = getGaugeInfo(cb, dir);
|
||||
GaugeKey key = new GaugeKey(dir, info.type);
|
||||
doRender(nw, brightness, info, key);
|
||||
|
||||
}
|
||||
|
||||
public void doRender(CapBankClientNetwork nw, int brightness, GaugeInfo info, GaugeKey key) {
|
||||
if(gaugeVertexCache == null) {
|
||||
createVertexCache();
|
||||
}
|
||||
RenderUtil.bindBlockTexture();
|
||||
Tessellator tes = Tessellator.instance;
|
||||
tes.startDrawingQuads();
|
||||
tes.setBrightness(brightness);
|
||||
tes.setColorOpaque_F(1, 1, 1);
|
||||
List<Vertex> verts = gaugeVertexCache.get(key);
|
||||
RenderUtil.addVerticesToTessellator(verts, Tessellator.instance);
|
||||
renderFillBar(key, nw, info);
|
||||
tes.draw();
|
||||
}
|
||||
|
||||
private void renderFillBar(GaugeKey key, CapBankClientNetwork nw, GaugeInfo info) {
|
||||
double ratio = 0;
|
||||
if(nw != null) {
|
||||
ratio = nw.getEnergyStoredRatio();
|
||||
}
|
||||
if(ratio <= 0) {
|
||||
return;
|
||||
}
|
||||
double maxY = ratio * info.height;
|
||||
if(maxY <= info.yPosition) {
|
||||
//empty
|
||||
return;
|
||||
}
|
||||
|
||||
Vector3d offset = ForgeDirectionOffsets.offsetScaled(key.dir, 0.005);
|
||||
Tessellator.instance.addTranslation((float) offset.x, (float) offset.y, (float) offset.z);
|
||||
|
||||
List<Vertex> verts = levelVertexCache.get(key);
|
||||
if(maxY >= info.yPosition + 1) {
|
||||
//full bar
|
||||
RenderUtil.addVerticesToTessellator(verts, Tessellator.instance);
|
||||
|
||||
} else {
|
||||
//need to render partial bar
|
||||
double myMaxY = maxY - info.yPosition;
|
||||
|
||||
if(info.type == Type.BOTTOM || info.type == Type.SINGLE) {
|
||||
//If we have some power and we are the bottom bit of the display,
|
||||
//always show at least a little bit in the bar
|
||||
myMaxY = Math.max(0.2, myMaxY);
|
||||
}
|
||||
List<Vertex> newVerts = new ArrayList<Vertex>();
|
||||
for (Vertex v : verts) {
|
||||
v = new Vertex(v);
|
||||
newVerts.add(v);
|
||||
if(v.y() > myMaxY) {
|
||||
v.setXYZ(v.x(), myMaxY, v.z());
|
||||
v.setUV(v.u(), barMinV + (float) (myMaxY * barHeightV));
|
||||
}
|
||||
}
|
||||
RenderUtil.addVerticesToTessellator(newVerts, Tessellator.instance);
|
||||
}
|
||||
offset.scale(-1);
|
||||
Tessellator.instance.addTranslation((float) offset.x, (float) offset.y, (float) offset.z);
|
||||
|
||||
}
|
||||
|
||||
private GaugeInfo getGaugeInfo(TileCapBank cb, ForgeDirection dir) {
|
||||
int height = 1;
|
||||
int yPos = 0;
|
||||
BlockCoord loc = cb.getLocation();
|
||||
boolean found = true;
|
||||
while (found) {
|
||||
loc = loc.getLocation(ForgeDirection.UP);
|
||||
if(isGaugeType(cb.getWorldObj(), loc, dir, cb.getType())) {
|
||||
height++;
|
||||
} else {
|
||||
found = false;
|
||||
}
|
||||
}
|
||||
|
||||
loc = cb.getLocation();
|
||||
found = true;
|
||||
while (found) {
|
||||
loc = loc.getLocation(ForgeDirection.DOWN);
|
||||
if(isGaugeType(cb.getWorldObj(), loc, dir, cb.getType())) {
|
||||
height++;
|
||||
yPos++;
|
||||
} else {
|
||||
found = false;
|
||||
}
|
||||
}
|
||||
|
||||
return new GaugeInfo(height, yPos);
|
||||
|
||||
}
|
||||
|
||||
private boolean isGaugeType(World worldObj, BlockCoord bc, ForgeDirection face, CapBankType type) {
|
||||
TileEntity te = worldObj.getTileEntity(bc.x, bc.y, bc.z);
|
||||
if(te instanceof TileCapBank) {
|
||||
TileCapBank cb = (TileCapBank) te;
|
||||
return type == cb.getType() && cb.getDisplayType(face) == InfoDisplayType.LEVEL_BAR;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void createVertexCache() {
|
||||
barIcon = EnderIO.blockCapBank.getFillBarIcon();
|
||||
barMinV = barIcon.getMinV();
|
||||
barHeightV = barIcon.getMaxV() - barIcon.getMinV();
|
||||
gaugeIcon = EnderIO.blockCapBank.getGaugeIcon();
|
||||
|
||||
gaugeVertexCache = new HashMap<FillGauge.GaugeKey, List<Vertex>>();
|
||||
levelVertexCache = new HashMap<FillGauge.GaugeKey, List<Vertex>>();
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
if(dir.offsetY == 0) {
|
||||
for (Type type : Type.values()) {
|
||||
GaugeKey key = new GaugeKey(dir, type);
|
||||
gaugeVertexCache.put(key, createGaugeBoundForFace(key, gaugeIcon));
|
||||
levelVertexCache.put(key, createGaugeBoundForFace(key, barIcon));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected List<Vertex> createGaugeBoundForFace(GaugeKey key, IIcon icon) {
|
||||
|
||||
ForgeDirection dir = key.dir;
|
||||
Type type = key.type;
|
||||
|
||||
double widthScale = 0.25;
|
||||
double heightScale = 0.8;
|
||||
|
||||
double xScale = dir.offsetX == 0 ? widthScale : 1;
|
||||
double yScale = 1;
|
||||
double zScale = dir.offsetZ == 0 ? widthScale : 1;
|
||||
|
||||
BoundingBox bb = BoundingBox.UNIT_CUBE;
|
||||
Vector3d off = ForgeDirectionOffsets.forDirCopy(dir);
|
||||
off.scale(-1);
|
||||
bb = bb.translate(off);
|
||||
bb = bb.scale(xScale, yScale, zScale);
|
||||
off.scale(-1);
|
||||
bb = bb.translate(off);
|
||||
|
||||
Vector4f uv = getUvForType(key.type, icon);
|
||||
|
||||
List<Vertex> result = bb.getCornersWithUvForFace(dir, uv.x, uv.y, uv.z, uv.w);
|
||||
return result;
|
||||
}
|
||||
|
||||
private Vector4f getUvForType(Type type, IIcon icon) {
|
||||
double uWidth = (icon.getMaxU() - icon.getMinU()) / 4;
|
||||
|
||||
Vector4f res = new Vector4f();
|
||||
res.x = (float) (icon.getMinU() + type.ordinal() * uWidth);
|
||||
res.y = (float) (res.x + uWidth);
|
||||
|
||||
res.z = icon.getMinV();
|
||||
res.w = icon.getMaxV();
|
||||
return res;
|
||||
}
|
||||
|
||||
static class GaugeInfo {
|
||||
|
||||
int height;
|
||||
int yPosition;
|
||||
Type type;
|
||||
|
||||
GaugeInfo(int height, int position) {
|
||||
this.height = height;
|
||||
yPosition = position;
|
||||
type = calcType();
|
||||
}
|
||||
|
||||
Type calcType() {
|
||||
if(height == 1) {
|
||||
return Type.SINGLE;
|
||||
}
|
||||
if(yPosition == 0) {
|
||||
return Type.BOTTOM;
|
||||
}
|
||||
if(yPosition == height - 1) {
|
||||
return Type.TOP;
|
||||
}
|
||||
return Type.MIDDLE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class GaugeKey {
|
||||
|
||||
ForgeDirection dir;
|
||||
Type type;
|
||||
|
||||
GaugeKey(ForgeDirection dir, Type type) {
|
||||
this.dir = dir;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((dir == null) ? 0 : dir.hashCode());
|
||||
result = prime * result + ((type == null) ? 0 : type.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(this == obj) {
|
||||
return true;
|
||||
}
|
||||
if(obj == null) {
|
||||
return false;
|
||||
}
|
||||
if(getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
GaugeKey other = (GaugeKey) obj;
|
||||
if(dir != other.dir) {
|
||||
return false;
|
||||
}
|
||||
if(type != other.type) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package crazypants.enderio.machine.capbank.render;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import crazypants.enderio.machine.capbank.TileCapBank;
|
||||
|
||||
public interface IInfoRenderer {
|
||||
|
||||
void render(TileCapBank cb, ForgeDirection dir, double x, double y, double z, float partialTick);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
package crazypants.enderio.machine.capbank.render;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.machine.capbank.TileCapBank;
|
||||
import crazypants.enderio.machine.capbank.network.CapBankClientNetwork;
|
||||
import crazypants.enderio.machine.power.PowerDisplayUtil;
|
||||
import crazypants.render.BoundingBox;
|
||||
import crazypants.render.ColorUtil;
|
||||
import crazypants.render.RenderUtil;
|
||||
import crazypants.vecmath.Vector3f;
|
||||
import crazypants.vecmath.Vertex;
|
||||
|
||||
public class IoDisplay implements IInfoRenderer {
|
||||
|
||||
@Override
|
||||
public void render(TileCapBank cb, ForgeDirection dir, double x, double y, double z, float partialTick) {
|
||||
|
||||
boolean selfIlum = true;
|
||||
int brightness = 0;
|
||||
if(!selfIlum) {
|
||||
brightness = cb.getWorldObj().getLightBrightnessForSkyBlocks(cb.xCoord + dir.offsetX, cb.yCoord + dir.offsetY, cb.zCoord + dir.offsetZ, 0);
|
||||
int l1 = brightness % 65536;
|
||||
int l2 = brightness / 65536;
|
||||
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, l1, l2);
|
||||
} else {
|
||||
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240);
|
||||
}
|
||||
|
||||
boolean drawBackground = true;
|
||||
if(drawBackground) {
|
||||
RenderUtil.bindBlockTexture();
|
||||
|
||||
Tessellator tes = Tessellator.instance;
|
||||
tes.startDrawingQuads();
|
||||
if(!selfIlum) {
|
||||
tes.setBrightness(brightness);
|
||||
}
|
||||
tes.setColorOpaque_F(1, 1, 1);
|
||||
|
||||
double scale = 0.85;
|
||||
BoundingBox bb = BoundingBox.UNIT_CUBE;
|
||||
double xScale = dir.offsetX == 0 ? scale : 1;
|
||||
double yScale = scale;
|
||||
double zScale = dir.offsetZ == 0 ? scale : 1;
|
||||
bb = bb.scale(xScale, yScale, zScale);
|
||||
|
||||
IIcon icon = EnderIO.blockCapBank.getInfoPanelIcon();
|
||||
List<Vertex> verts = bb.getCornersWithUvForFace(dir, icon.getMinU(), icon.getMaxU(), icon.getMinV(), icon.getMaxV());
|
||||
RenderUtil.addVerticesToTesselator(verts);
|
||||
|
||||
tes.draw();
|
||||
}
|
||||
|
||||
CapBankClientNetwork nw = null;
|
||||
if(cb.getNetwork() != null) {
|
||||
nw = (CapBankClientNetwork) cb.getNetwork();
|
||||
nw.requestPowerUpdate(cb, 20);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
int change = Math.round(nw.getAverageChangePerTick());
|
||||
//change = 0;
|
||||
Vector3f col = new Vector3f(0, 0, 0);
|
||||
if(change > 0) {
|
||||
col = new Vector3f(0, 0.025, 0);
|
||||
} else if(change < 0) {
|
||||
col = new Vector3f(0.05, 0, 0);
|
||||
}
|
||||
|
||||
FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
|
||||
String changeText = getChangeText(change, fr);
|
||||
|
||||
String HeadingText = change > 0 ? "In" : change < 0 ? "Out" : "I/O";
|
||||
float size = 0.15f;
|
||||
float scale = size / fr.FONT_HEIGHT;
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(0.5f, 0.5f + (size / 2), 0.5f);
|
||||
GL11.glTranslatef((float) (dir.offsetX * 1.01) / 2, 0, (float) (dir.offsetZ * 1.01) / 2);
|
||||
GL11.glRotatef(-180, 1, 0, 0);
|
||||
if(dir == ForgeDirection.NORTH) {
|
||||
GL11.glRotatef(-180, 0, 1, 0);
|
||||
} else if(dir == ForgeDirection.EAST) {
|
||||
GL11.glRotatef(-90, 0, 1, 0);
|
||||
} else if(dir == ForgeDirection.WEST) {
|
||||
GL11.glRotatef(90, 0, 1, 0);
|
||||
}
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(0, -size, 0);
|
||||
GL11.glScalef(scale, scale, scale);
|
||||
fr.drawString(HeadingText, -fr.getStringWidth(HeadingText) / 2, 0, ColorUtil.getRGB(col));
|
||||
GL11.glPopMatrix();
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(0, size / 2, 0);
|
||||
GL11.glScalef(scale, scale, scale);
|
||||
fr.drawString(changeText, -fr.getStringWidth(changeText) / 2, 0, ColorUtil.getRGB(col));
|
||||
GL11.glPopMatrix();
|
||||
|
||||
GL11.glPopMatrix();
|
||||
|
||||
}
|
||||
|
||||
protected String getChangeText(int change, FontRenderer fr) {
|
||||
change = Math.abs(change);
|
||||
String txt = PowerDisplayUtil.INT_NF.format(change);
|
||||
int width = fr.getStringWidth(txt);
|
||||
if(width > 38 && change > 1000) {
|
||||
change = change / 1000;
|
||||
txt = PowerDisplayUtil.INT_NF.format(change) + "K";
|
||||
}
|
||||
return txt;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,26 +1,19 @@
|
||||
package crazypants.enderio.machine.farm;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.GL_LIGHTING;
|
||||
import static org.lwjgl.opengl.GL11.glDisable;
|
||||
import static org.lwjgl.opengl.GL11.glEnable;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import crazypants.enderio.config.Config;
|
||||
import crazypants.render.RenderUtil;
|
||||
import crazypants.vecmath.Vector3f;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.entity.RenderManager;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
public class FarmingStationSpecialRenderer extends TileEntitySpecialRenderer{
|
||||
|
||||
private void renderFarmStationAt(TileFarmStation tile, double x, double y, double z, float partialTickTime) {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
FontRenderer fnt = mc.fontRenderer;
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
String toRender = tile.notification;
|
||||
|
||||
String toRender = tile.notification;
|
||||
if ("".equals(toRender) || Config.disableFarmNotification) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -25,8 +25,8 @@ public class TilePowerMonitor extends AbstractMachineEntity implements IInternal
|
||||
|
||||
int powerInConduits;
|
||||
int maxPowerInCoduits;
|
||||
int powerInCapBanks;
|
||||
int maxPowerInCapBanks;
|
||||
long powerInCapBanks;
|
||||
long maxPowerInCapBanks;
|
||||
int powerInMachines;
|
||||
int maxPowerInMachines;
|
||||
float aveRfSent;
|
||||
@@ -216,8 +216,13 @@ public class TilePowerMonitor extends AbstractMachineEntity implements IInternal
|
||||
public void readPowerInfoFromNBT(NBTTagCompound nbtRoot) {
|
||||
powerInConduits = nbtRoot.getInteger("powerInConduits");
|
||||
maxPowerInCoduits = nbtRoot.getInteger("maxPowerInCoduits");
|
||||
powerInCapBanks = nbtRoot.getInteger("powerInCapBanks");
|
||||
maxPowerInCapBanks = nbtRoot.getInteger("maxPowerInCapBanks");
|
||||
if(nbtRoot.hasKey("powerInCapBanks")) {
|
||||
powerInCapBanks = nbtRoot.getInteger("powerInCapBanks");
|
||||
maxPowerInCapBanks = nbtRoot.getInteger("maxPowerInCapBanks");
|
||||
} else {
|
||||
powerInCapBanks = nbtRoot.getLong("powerInCapBanksL");
|
||||
maxPowerInCapBanks = nbtRoot.getLong("maxPowerInCapBanksL");
|
||||
}
|
||||
powerInMachines = nbtRoot.getInteger("powerInMachines");
|
||||
maxPowerInMachines = nbtRoot.getInteger("maxPowerInMachines");
|
||||
aveRfSent = nbtRoot.getFloat("aveRfSent");
|
||||
@@ -237,8 +242,8 @@ public class TilePowerMonitor extends AbstractMachineEntity implements IInternal
|
||||
public void writePowerInfoToNBT(NBTTagCompound nbtRoot) {
|
||||
nbtRoot.setInteger("powerInConduits", powerInConduits);
|
||||
nbtRoot.setInteger("maxPowerInCoduits", maxPowerInCoduits);
|
||||
nbtRoot.setInteger("powerInCapBanks", powerInCapBanks);
|
||||
nbtRoot.setInteger("maxPowerInCapBanks", maxPowerInCapBanks);
|
||||
nbtRoot.setLong("powerInCapBanksL", powerInCapBanks);
|
||||
nbtRoot.setLong("maxPowerInCapBanksL", maxPowerInCapBanks);
|
||||
nbtRoot.setInteger("powerInMachines", powerInMachines);
|
||||
nbtRoot.setInteger("maxPowerInMachines", maxPowerInMachines);
|
||||
nbtRoot.setFloat("aveRfSent", aveRfSent);
|
||||
|
||||
@@ -63,11 +63,11 @@ public class BlockCapacitorBank extends BlockEio implements IGuiHandler, IAdvanc
|
||||
protected BlockCapacitorBank() {
|
||||
super(ModObject.blockCapacitorBank.unlocalisedName, TileCapacitorBank.class);
|
||||
setHardness(2.0F);
|
||||
setCreativeTab(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
//super.init();
|
||||
|
||||
GameRegistry.registerBlock(this, BlockItemCapacitorBank.class, name);
|
||||
if(teClass != null) {
|
||||
@@ -398,6 +398,7 @@ public class BlockCapacitorBank extends BlockEio implements IGuiHandler, IAdvanc
|
||||
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));
|
||||
tooltip.add("Deprecated. Convert by placing in crafting grid");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,13 +6,12 @@ import java.text.NumberFormat;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import cofh.api.energy.IEnergyContainerItem;
|
||||
import crazypants.enderio.config.Config;
|
||||
import crazypants.util.Lang;
|
||||
|
||||
public class PowerDisplayUtil {
|
||||
|
||||
private static final NumberFormat INT_NF = NumberFormat.getIntegerInstance();
|
||||
private static final NumberFormat FLOAT_NF = NumberFormat.getInstance();
|
||||
public static final NumberFormat INT_NF = NumberFormat.getIntegerInstance();
|
||||
public static final NumberFormat FLOAT_NF = NumberFormat.getInstance();
|
||||
|
||||
//Handle french local 'non breaking space' character used to separate thousands.
|
||||
//This is not rendered correctly and cannot be parsed by minecraft so replace it with a regular space
|
||||
@@ -64,13 +63,20 @@ public class PowerDisplayUtil {
|
||||
return formatPower(amount) + "/" + formatPower(capacity) + " " + PowerDisplayUtil.abrevation();
|
||||
}
|
||||
|
||||
public static String formatPower(long amount) {
|
||||
String str = INT_NF.format(amount);
|
||||
if(REPLACE_NBSP) {
|
||||
str = str.replace(NBSP, ' ');
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
public static String formatPower(int powerRF) {
|
||||
String str = INT_NF.format(powerRF);
|
||||
if(REPLACE_NBSP) {
|
||||
str = str.replace(NBSP, ' ');
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,12 +30,13 @@ import crazypants.enderio.network.PacketHandler;
|
||||
import crazypants.enderio.power.BasicCapacitor;
|
||||
import crazypants.enderio.power.IInternalPowerReceptor;
|
||||
import crazypants.enderio.power.IPowerInterface;
|
||||
import crazypants.enderio.power.IPowerStorage;
|
||||
import crazypants.enderio.power.PowerHandlerUtil;
|
||||
import crazypants.util.BlockCoord;
|
||||
import crazypants.util.Util;
|
||||
import crazypants.vecmath.VecmathUtil;
|
||||
|
||||
public class TileCapacitorBank extends TileEntityEio implements IInternalPowerReceptor, IInventory, IIoConfigurable {
|
||||
public class TileCapacitorBank extends TileEntityEio implements IInternalPowerReceptor, IInventory, IIoConfigurable, IPowerStorage {
|
||||
|
||||
static final BasicCapacitor BASE_CAP = new BasicCapacitor(Config.capacitorBankMaxIoRF, Config.capacitorBankMaxStorageRF);
|
||||
|
||||
@@ -285,7 +286,7 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerRe
|
||||
int cur = chargable.getEnergyStored(item);
|
||||
int canUse = Math.min(available, max - cur);
|
||||
if(cur < max) {
|
||||
used = chargable.receiveEnergy(item, (int) canUse, false);
|
||||
used = chargable.receiveEnergy(item, canUse, false);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -310,6 +311,7 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerRe
|
||||
return getController().outputEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOutputEnabled(ForgeDirection direction) {
|
||||
IoMode mode = getIoMode(direction);
|
||||
return mode == IoMode.PUSH || mode == IoMode.NONE && isOutputEnabled();
|
||||
@@ -319,6 +321,7 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerRe
|
||||
return getController().inputEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInputEnabled(ForgeDirection direction) {
|
||||
IoMode mode = getIoMode(direction);
|
||||
return mode == IoMode.PULL || mode == IoMode.NONE && isInputEnabled();
|
||||
@@ -454,6 +457,7 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerRe
|
||||
return getController().doGetEnergyStoredScaled(scale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxInput() {
|
||||
return maxInput;
|
||||
}
|
||||
@@ -463,6 +467,7 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerRe
|
||||
updateBlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxOutput() {
|
||||
return maxOutput;
|
||||
}
|
||||
@@ -477,6 +482,11 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerRe
|
||||
return getController().doGetEnergyStored();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getEnergyStoredL() {
|
||||
return getEnergyStored();
|
||||
}
|
||||
|
||||
public double getEnergyStoredRatio() {
|
||||
return getController().doGetEnergyStoredRatio();
|
||||
}
|
||||
@@ -486,6 +496,11 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerRe
|
||||
return getController().doGetMaxEnergyStored();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getMaxEnergyStoredL() {
|
||||
return getMaxEnergyStored();
|
||||
}
|
||||
|
||||
public int getMaxIO() {
|
||||
return getController().doGetMaxIO();
|
||||
}
|
||||
@@ -545,6 +560,7 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerRe
|
||||
|
||||
// end rf power
|
||||
|
||||
@Override
|
||||
public void addEnergy(int add) {
|
||||
getController().doAddEnergy(add);
|
||||
}
|
||||
@@ -824,6 +840,7 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerRe
|
||||
render = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileCapacitorBank getController() {
|
||||
if(isMaster() || !isMultiblock()) {
|
||||
return this;
|
||||
@@ -983,7 +1000,7 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerRe
|
||||
doSetEnergyStored(nbtRoot.getInteger("storedEnergyRF"));
|
||||
|
||||
double newEnergy = storedEnergyRF;
|
||||
if(maxStoredEnergy != 0 && Math.abs(oldEnergy - newEnergy) / (double) maxStoredEnergy > 0.05 || nbtRoot.hasKey("render")) {
|
||||
if(maxStoredEnergy != 0 && Math.abs(oldEnergy - newEnergy) / maxStoredEnergy > 0.05 || nbtRoot.hasKey("render")) {
|
||||
render = true;
|
||||
}
|
||||
if(energyAtLastRender != -1 && maxStoredEnergy != 0) {
|
||||
@@ -1110,7 +1127,7 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerRe
|
||||
IoMode mode;
|
||||
|
||||
private Receptor(IPowerInterface rec, ForgeDirection fromDir, IoMode mode) {
|
||||
this.receptor = rec;
|
||||
receptor = rec;
|
||||
this.fromDir = fromDir;
|
||||
this.mode = mode;
|
||||
}
|
||||
@@ -1129,12 +1146,13 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerRe
|
||||
}
|
||||
|
||||
public void setCreativeMode() {
|
||||
this.isCreative = true;
|
||||
isCreative = true;
|
||||
maxIO = maxIO * 1000;
|
||||
maxInput = maxIO;
|
||||
maxOutput = maxIO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCreative() {
|
||||
return isCreative;
|
||||
}
|
||||
|
||||
+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,25 @@
|
||||
package crazypants.enderio.power;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public interface IPowerStorage {
|
||||
|
||||
IPowerStorage getController();
|
||||
|
||||
long getEnergyStoredL();
|
||||
|
||||
long getMaxEnergyStoredL();
|
||||
|
||||
boolean isOutputEnabled(ForgeDirection direction);
|
||||
|
||||
boolean isInputEnabled(ForgeDirection direction);
|
||||
|
||||
int getMaxOutput();
|
||||
|
||||
int getMaxInput();
|
||||
|
||||
void addEnergy(int amount);
|
||||
|
||||
boolean isCreative();
|
||||
|
||||
}
|
||||
@@ -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()) {
|
||||
|
||||
@@ -34,6 +34,7 @@ public class IconUtil {
|
||||
public void registerIcons(IIconRegister register) {
|
||||
whiteTexture = register.registerIcon("enderio:white");
|
||||
errorTexture = register.registerIcon("enderio:error");
|
||||
blankTexture = register.registerIcon("enderio:blank");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,7 +1,29 @@
|
||||
package crazypants.render;
|
||||
|
||||
import static net.minecraftforge.common.util.ForgeDirection.*;
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
import static net.minecraftforge.common.util.ForgeDirection.DOWN;
|
||||
import static net.minecraftforge.common.util.ForgeDirection.EAST;
|
||||
import static net.minecraftforge.common.util.ForgeDirection.NORTH;
|
||||
import static net.minecraftforge.common.util.ForgeDirection.SOUTH;
|
||||
import static net.minecraftforge.common.util.ForgeDirection.UP;
|
||||
import static net.minecraftforge.common.util.ForgeDirection.WEST;
|
||||
import static org.lwjgl.opengl.GL11.GL_ALL_ATTRIB_BITS;
|
||||
import static org.lwjgl.opengl.GL11.GL_ALPHA_TEST;
|
||||
import static org.lwjgl.opengl.GL11.GL_BLEND;
|
||||
import static org.lwjgl.opengl.GL11.GL_CULL_FACE;
|
||||
import static org.lwjgl.opengl.GL11.GL_ONE;
|
||||
import static org.lwjgl.opengl.GL11.GL_ONE_MINUS_SRC_ALPHA;
|
||||
import static org.lwjgl.opengl.GL11.GL_SMOOTH;
|
||||
import static org.lwjgl.opengl.GL11.GL_SRC_ALPHA;
|
||||
import static org.lwjgl.opengl.GL11.GL_TEXTURE_2D;
|
||||
import static org.lwjgl.opengl.GL11.GL_ZERO;
|
||||
import static org.lwjgl.opengl.GL11.glDepthMask;
|
||||
import static org.lwjgl.opengl.GL11.glDisable;
|
||||
import static org.lwjgl.opengl.GL11.glEnable;
|
||||
import static org.lwjgl.opengl.GL11.glPopAttrib;
|
||||
import static org.lwjgl.opengl.GL11.glPushAttrib;
|
||||
import static org.lwjgl.opengl.GL11.glRotatef;
|
||||
import static org.lwjgl.opengl.GL11.glShadeModel;
|
||||
import static org.lwjgl.opengl.GL11.glTranslatef;
|
||||
|
||||
import java.nio.FloatBuffer;
|
||||
import java.util.ArrayList;
|
||||
@@ -61,6 +83,8 @@ public class RenderUtil {
|
||||
|
||||
public static final ResourceLocation GLINT_TEX = new ResourceLocation("textures/misc/enchanted_item_glint.png");
|
||||
|
||||
public static int BRIGHTNESS_MAX = 15 << 20 | 15 << 4;
|
||||
|
||||
public static void loadMatrix(Matrix4d mat) {
|
||||
MATRIX_BUFFER.rewind();
|
||||
MATRIX_BUFFER.put((float) mat.m00);
|
||||
@@ -598,8 +622,8 @@ public class RenderUtil {
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
OpenGlHelper.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO); // stop random disappearing
|
||||
|
||||
float width = (float) fnt.getStringWidth(toRender);
|
||||
float height = (float) fnt.FONT_HEIGHT;
|
||||
float width = fnt.getStringWidth(toRender);
|
||||
float height = fnt.FONT_HEIGHT;
|
||||
float padding = 2f;
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
tessellator.startDrawingQuads();
|
||||
|
||||
@@ -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