mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
waiter! waiter! more lead acid batteries please!
adds OC compat to new battery blocks
This commit is contained in:
parent
f17556a0d6
commit
be93b9cc8c
@ -1,5 +1,6 @@
|
|||||||
package com.hbm.tileentity.machine.storage;
|
package com.hbm.tileentity.machine.storage;
|
||||||
|
|
||||||
|
import com.hbm.handler.CompatHandler;
|
||||||
import com.hbm.interfaces.IControlReceiver;
|
import com.hbm.interfaces.IControlReceiver;
|
||||||
import com.hbm.tileentity.IGUIProvider;
|
import com.hbm.tileentity.IGUIProvider;
|
||||||
import com.hbm.tileentity.TileEntityMachineBase;
|
import com.hbm.tileentity.TileEntityMachineBase;
|
||||||
@ -14,19 +15,25 @@ import api.hbm.energymk2.IEnergyProviderMK2;
|
|||||||
import api.hbm.energymk2.IEnergyReceiverMK2;
|
import api.hbm.energymk2.IEnergyReceiverMK2;
|
||||||
import api.hbm.energymk2.Nodespace;
|
import api.hbm.energymk2.Nodespace;
|
||||||
import api.hbm.energymk2.Nodespace.PowerNode;
|
import api.hbm.energymk2.Nodespace.PowerNode;
|
||||||
|
import cpw.mods.fml.common.Optional;
|
||||||
import cpw.mods.fml.relauncher.Side;
|
import cpw.mods.fml.relauncher.Side;
|
||||||
import cpw.mods.fml.relauncher.SideOnly;
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import li.cil.oc.api.machine.Arguments;
|
||||||
|
import li.cil.oc.api.machine.Callback;
|
||||||
|
import li.cil.oc.api.machine.Context;
|
||||||
|
import li.cil.oc.api.network.SimpleComponent;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.util.MathHelper;
|
import net.minecraft.util.MathHelper;
|
||||||
|
|
||||||
public abstract class TileEntityBatteryBase extends TileEntityMachineBase implements IEnergyConductorMK2, IEnergyProviderMK2, IEnergyReceiverMK2, IControlReceiver, IGUIProvider {
|
@Optional.InterfaceList({@Optional.Interface(iface = "li.cil.oc.api.network.SimpleComponent", modid = "opencomputers")})
|
||||||
|
public abstract class TileEntityBatteryBase extends TileEntityMachineBase implements IEnergyConductorMK2, IEnergyProviderMK2, IEnergyReceiverMK2, IControlReceiver, IGUIProvider, SimpleComponent, CompatHandler.OCComponent {
|
||||||
|
|
||||||
public byte lastRedstone = 0;
|
public byte lastRedstone = 0;
|
||||||
public long prevPowerState = 0;
|
public long prevPowerState = 0;
|
||||||
|
|
||||||
public static final int mode_input = 0;
|
public static final int mode_input = 0;
|
||||||
public static final int mode_buffer = 1;
|
public static final int mode_buffer = 1;
|
||||||
public static final int mode_output = 2;
|
public static final int mode_output = 2;
|
||||||
@ -36,20 +43,20 @@ public abstract class TileEntityBatteryBase extends TileEntityMachineBase implem
|
|||||||
public ConnectionPriority priority = ConnectionPriority.LOW;
|
public ConnectionPriority priority = ConnectionPriority.LOW;
|
||||||
|
|
||||||
protected PowerNode node;
|
protected PowerNode node;
|
||||||
|
|
||||||
public TileEntityBatteryBase(int slotCount) {
|
public TileEntityBatteryBase(int slotCount) {
|
||||||
super(slotCount);
|
super(slotCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateEntity() {
|
public void updateEntity() {
|
||||||
|
|
||||||
if(!worldObj.isRemote) {
|
if(!worldObj.isRemote) {
|
||||||
|
|
||||||
if(priority == null || priority.ordinal() == 0 || priority.ordinal() == 4) {
|
if(priority == null || priority.ordinal() == 0 || priority.ordinal() == 4) {
|
||||||
priority = ConnectionPriority.LOW;
|
priority = ConnectionPriority.LOW;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.node == null || this.node.expired) {
|
if(this.node == null || this.node.expired) {
|
||||||
this.node = (PowerNode) UniNodespace.getNode(worldObj, xCoord, yCoord, zCoord, Nodespace.THE_POWER_PROVIDER);
|
this.node = (PowerNode) UniNodespace.getNode(worldObj, xCoord, yCoord, zCoord, Nodespace.THE_POWER_PROVIDER);
|
||||||
|
|
||||||
@ -58,20 +65,20 @@ public abstract class TileEntityBatteryBase extends TileEntityMachineBase implem
|
|||||||
UniNodespace.createNode(worldObj, this.node);
|
UniNodespace.createNode(worldObj, this.node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.node != null && this.node.hasValidNet()) switch(this.getRelevantMode(false)) {
|
if(this.node != null && this.node.hasValidNet()) switch(this.getRelevantMode(false)) {
|
||||||
case mode_input: this.node.net.removeProvider(this); this.node.net.addReceiver(this); break;
|
case mode_input: this.node.net.removeProvider(this); this.node.net.addReceiver(this); break;
|
||||||
case mode_output: this.node.net.addProvider(this); this.node.net.removeReceiver(this); break;
|
case mode_output: this.node.net.addProvider(this); this.node.net.removeReceiver(this); break;
|
||||||
case mode_buffer: this.node.net.addProvider(this); this.node.net.addReceiver(this); break;
|
case mode_buffer: this.node.net.addProvider(this); this.node.net.addReceiver(this); break;
|
||||||
case mode_none: this.node.net.removeProvider(this); this.node.net.removeReceiver(this); break;
|
case mode_none: this.node.net.removeProvider(this); this.node.net.removeReceiver(this); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
byte comp = this.getComparatorPower();
|
byte comp = this.getComparatorPower();
|
||||||
if(comp != this.lastRedstone) this.markDirty();
|
if(comp != this.lastRedstone) this.markDirty();
|
||||||
this.lastRedstone = comp;
|
this.lastRedstone = comp;
|
||||||
|
|
||||||
prevPowerState = this.getPower();
|
prevPowerState = this.getPower();
|
||||||
|
|
||||||
this.networkPackNT(100);
|
this.networkPackNT(100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -80,7 +87,7 @@ public abstract class TileEntityBatteryBase extends TileEntityMachineBase implem
|
|||||||
double frac = (double) this.getPower() / (double) this.getMaxPower() * 15D;
|
double frac = (double) this.getPower() / (double) this.getMaxPower() * 15D;
|
||||||
return (byte) (MathHelper.clamp_int((int) frac + 1, 0, 15)); //to combat eventual rounding errors with the FEnSU's stupid maxPower
|
return (byte) (MathHelper.clamp_int((int) frac + 1, 0, 15)); //to combat eventual rounding errors with the FEnSU's stupid maxPower
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PowerNode createNode() {
|
public PowerNode createNode() {
|
||||||
return new PowerNode(this.getPortPos()).setConnections(this.getConPos());
|
return new PowerNode(this.getPortPos()).setConnections(this.getConPos());
|
||||||
@ -105,7 +112,7 @@ public abstract class TileEntityBatteryBase extends TileEntityMachineBase implem
|
|||||||
@Override
|
@Override
|
||||||
public void serialize(ByteBuf buf) {
|
public void serialize(ByteBuf buf) {
|
||||||
super.serialize(buf);
|
super.serialize(buf);
|
||||||
|
|
||||||
buf.writeShort(redLow);
|
buf.writeShort(redLow);
|
||||||
buf.writeShort(redHigh);
|
buf.writeShort(redHigh);
|
||||||
buf.writeByte(priority.ordinal());
|
buf.writeByte(priority.ordinal());
|
||||||
@ -147,7 +154,7 @@ public abstract class TileEntityBatteryBase extends TileEntityMachineBase implem
|
|||||||
public abstract DirPos[] getConPos();
|
public abstract DirPos[] getConPos();
|
||||||
|
|
||||||
private short modeCache = 0;
|
private short modeCache = 0;
|
||||||
|
|
||||||
public short getRelevantMode(boolean useCache) {
|
public short getRelevantMode(boolean useCache) {
|
||||||
if(useCache) return this.modeCache;
|
if(useCache) return this.modeCache;
|
||||||
boolean powered = false;
|
boolean powered = false;
|
||||||
@ -155,7 +162,7 @@ public abstract class TileEntityBatteryBase extends TileEntityMachineBase implem
|
|||||||
this.modeCache = powered ? this.redHigh : this.redLow;
|
this.modeCache = powered ? this.redHigh : this.redLow;
|
||||||
return this.modeCache;
|
return this.modeCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean hasPermission(EntityPlayer player) { return this.isUseableByPlayer(player); }
|
@Override public boolean hasPermission(EntityPlayer player) { return this.isUseableByPlayer(player); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -175,10 +182,68 @@ public abstract class TileEntityBatteryBase extends TileEntityMachineBase implem
|
|||||||
this.priority = EnumUtil.grabEnumSafely(ConnectionPriority.class, ordinal);
|
this.priority = EnumUtil.grabEnumSafely(ConnectionPriority.class, ordinal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public double getMaxRenderDistanceSquared() {
|
public double getMaxRenderDistanceSquared() {
|
||||||
return 65536.0D;
|
return 65536.0D;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// do some opencomputer stuff
|
||||||
|
@Override
|
||||||
|
@Optional.Method(modid = "OpenComputers")
|
||||||
|
public String getComponentName() {
|
||||||
|
return "ntm_energy_storage";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Callback(direct = true)
|
||||||
|
@Optional.Method(modid = "OpenComputers")
|
||||||
|
public Object[] getEnergyInfo(Context context, Arguments args) {
|
||||||
|
return new Object[] {getPower(), getMaxPower()};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Callback(direct = true)
|
||||||
|
@Optional.Method(modid = "OpenComputers")
|
||||||
|
public Object[] getModeInfo(Context context, Arguments args) {
|
||||||
|
return new Object[] {redLow, redHigh, getPriority().ordinal()};
|
||||||
|
}
|
||||||
|
@Callback(direct = true)
|
||||||
|
@Optional.Method(modid = "OpenComputers")
|
||||||
|
public Object[] setModeLow(Context context, Arguments args) {
|
||||||
|
short newMode = (short) args.checkInteger(0);
|
||||||
|
if (newMode >= mode_input && newMode <= mode_none) {
|
||||||
|
redLow = newMode;
|
||||||
|
return new Object[] {};
|
||||||
|
} else {
|
||||||
|
return new Object[] {"Invalid mode"};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Callback(direct = true)
|
||||||
|
@Optional.Method(modid = "OpenComputers")
|
||||||
|
public Object[] setModeHigh(Context context, Arguments args) {
|
||||||
|
short newMode = (short) args.checkInteger(0);
|
||||||
|
if (newMode >= mode_input && newMode <= mode_none) {
|
||||||
|
redHigh = newMode;
|
||||||
|
return new Object[] {};
|
||||||
|
} else {
|
||||||
|
return new Object[] {"Invalid mode"};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Callback(direct = true)
|
||||||
|
@Optional.Method(modid = "OpenComputers")
|
||||||
|
public Object[] setPriority(Context context, Arguments args) {
|
||||||
|
int newPriority = args.checkInteger(0);
|
||||||
|
if (newPriority >= 0 && newPriority <= 2) {
|
||||||
|
priority = EnumUtil.grabEnumSafely(ConnectionPriority.class, newPriority+1);
|
||||||
|
return new Object[] {};
|
||||||
|
} else {
|
||||||
|
return new Object[] {"Invalid mode"};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Callback(direct = true)
|
||||||
|
@Optional.Method(modid = "OpenComputers")
|
||||||
|
public Object[] getInfo(Context context, Arguments args) {
|
||||||
|
return new Object[] {getPower(), getMaxPower(), redLow, redHigh, getPriority().ordinal()};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,7 +10,11 @@ import com.hbm.sound.AudioWrapper;
|
|||||||
import com.hbm.util.fauxpointtwelve.BlockPos;
|
import com.hbm.util.fauxpointtwelve.BlockPos;
|
||||||
import com.hbm.util.fauxpointtwelve.DirPos;
|
import com.hbm.util.fauxpointtwelve.DirPos;
|
||||||
|
|
||||||
|
import cpw.mods.fml.common.Optional;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import li.cil.oc.api.machine.Arguments;
|
||||||
|
import li.cil.oc.api.machine.Callback;
|
||||||
|
import li.cil.oc.api.machine.Context;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.inventory.Container;
|
import net.minecraft.inventory.Container;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
@ -25,28 +29,28 @@ public class TileEntityBatteryREDD extends TileEntityBatteryBase {
|
|||||||
|
|
||||||
public BigInteger[] log = new BigInteger[20];
|
public BigInteger[] log = new BigInteger[20];
|
||||||
public BigInteger delta = BigInteger.valueOf(0);
|
public BigInteger delta = BigInteger.valueOf(0);
|
||||||
|
|
||||||
public BigInteger power = BigInteger.valueOf(0);
|
public BigInteger power = BigInteger.valueOf(0);
|
||||||
|
|
||||||
private AudioWrapper audio;
|
private AudioWrapper audio;
|
||||||
|
|
||||||
public TileEntityBatteryREDD() {
|
public TileEntityBatteryREDD() {
|
||||||
super(2);
|
super(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public String getName() { return "container.batteryREDD"; }
|
@Override public String getName() { return "container.batteryREDD"; }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateEntity() {
|
public void updateEntity() {
|
||||||
BigInteger prevPower = new BigInteger(power.toByteArray());
|
BigInteger prevPower = new BigInteger(power.toByteArray());
|
||||||
|
|
||||||
super.updateEntity();
|
super.updateEntity();
|
||||||
|
|
||||||
if(!worldObj.isRemote) {
|
if(!worldObj.isRemote) {
|
||||||
|
|
||||||
long toAdd = Library.chargeTEFromItems(slots, 0, 0, this.getMaxPower());
|
long toAdd = Library.chargeTEFromItems(slots, 0, 0, this.getMaxPower());
|
||||||
if(toAdd > 0) this.power = this.power.add(BigInteger.valueOf(toAdd));
|
if(toAdd > 0) this.power = this.power.add(BigInteger.valueOf(toAdd));
|
||||||
|
|
||||||
long toRemove = this.getPower() - Library.chargeItemsFromTE(slots, 1, this.getPower(), this.getMaxPower());
|
long toRemove = this.getPower() - Library.chargeItemsFromTE(slots, 1, this.getPower(), this.getMaxPower());
|
||||||
if(toRemove > 0)this.power = this.power.subtract(BigInteger.valueOf(toRemove));
|
if(toRemove > 0)this.power = this.power.subtract(BigInteger.valueOf(toRemove));
|
||||||
|
|
||||||
@ -59,16 +63,16 @@ public class TileEntityBatteryREDD extends TileEntityBatteryBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.log[19] = avg;
|
this.log[19] = avg;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
this.prevRotation = this.rotation;
|
this.prevRotation = this.rotation;
|
||||||
this.rotation += this.getSpeed();
|
this.rotation += this.getSpeed();
|
||||||
|
|
||||||
if(rotation >= 360) {
|
if(rotation >= 360) {
|
||||||
rotation -= 360;
|
rotation -= 360;
|
||||||
prevRotation -= 360;
|
prevRotation -= 360;
|
||||||
}
|
}
|
||||||
|
|
||||||
float pitch = 0.5F + this.getSpeed() / 15F * 1.5F;
|
float pitch = 0.5F + this.getSpeed() / 15F * 1.5F;
|
||||||
|
|
||||||
if(this.prevRotation != this.rotation && MainRegistry.proxy.me().getDistanceSq(xCoord + 0.5, yCoord + 5.5, zCoord + 0.5) < 30 * 30) {
|
if(this.prevRotation != this.rotation && MainRegistry.proxy.me().getDistanceSq(xCoord + 0.5, yCoord + 5.5, zCoord + 0.5) < 30 * 30) {
|
||||||
@ -76,11 +80,11 @@ public class TileEntityBatteryREDD extends TileEntityBatteryBase {
|
|||||||
this.audio = MainRegistry.proxy.getLoopedSound("hbm:block.fensuHum", xCoord, yCoord, zCoord, this.getVolume(1.5F), 25F, pitch, 5);
|
this.audio = MainRegistry.proxy.getLoopedSound("hbm:block.fensuHum", xCoord, yCoord, zCoord, this.getVolume(1.5F), 25F, pitch, 5);
|
||||||
this.audio.startSound();
|
this.audio.startSound();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.audio.updateVolume(this.getVolume(1.5F));
|
this.audio.updateVolume(this.getVolume(1.5F));
|
||||||
this.audio.updatePitch(pitch);
|
this.audio.updatePitch(pitch);
|
||||||
this.audio.keepAlive();
|
this.audio.keepAlive();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if(this.audio != null) {
|
if(this.audio != null) {
|
||||||
this.audio.stopSound();
|
this.audio.stopSound();
|
||||||
@ -89,7 +93,7 @@ public class TileEntityBatteryREDD extends TileEntityBatteryBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getSpeed() {
|
public float getSpeed() {
|
||||||
return (float) Math.min(Math.pow(Math.log(this.power.doubleValue() * 0.05 + 1) * 0.05F, 5), 15F);
|
return (float) Math.min(Math.pow(Math.log(this.power.doubleValue() * 0.05 + 1) * 0.05F, 5), 15F);
|
||||||
}
|
}
|
||||||
@ -141,7 +145,7 @@ public class TileEntityBatteryREDD extends TileEntityBatteryBase {
|
|||||||
@Override
|
@Override
|
||||||
public void readFromNBT(NBTTagCompound nbt) {
|
public void readFromNBT(NBTTagCompound nbt) {
|
||||||
super.readFromNBT(nbt);
|
super.readFromNBT(nbt);
|
||||||
|
|
||||||
this.power = new BigInteger(nbt.getByteArray("power"));
|
this.power = new BigInteger(nbt.getByteArray("power"));
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -149,7 +153,7 @@ public class TileEntityBatteryREDD extends TileEntityBatteryBase {
|
|||||||
@Override
|
@Override
|
||||||
public void writeToNBT(NBTTagCompound nbt) {
|
public void writeToNBT(NBTTagCompound nbt) {
|
||||||
super.writeToNBT(nbt);
|
super.writeToNBT(nbt);
|
||||||
|
|
||||||
nbt.setByteArray("power", this.power.toByteArray());
|
nbt.setByteArray("power", this.power.toByteArray());
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -186,7 +190,7 @@ public class TileEntityBatteryREDD extends TileEntityBatteryBase {
|
|||||||
public void usePower(long power) {
|
public void usePower(long power) {
|
||||||
this.power = this.power.subtract(BigInteger.valueOf(power));
|
this.power = this.power.subtract(BigInteger.valueOf(power));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long transferPower(long power) {
|
public long transferPower(long power) {
|
||||||
this.power = this.power.add(BigInteger.valueOf(power));
|
this.power = this.power.add(BigInteger.valueOf(power));
|
||||||
@ -199,12 +203,12 @@ public class TileEntityBatteryREDD extends TileEntityBatteryBase {
|
|||||||
|
|
||||||
@Override public Container provideContainer(int ID, EntityPlayer player, World world, int x, int y, int z) { return new ContainerBatteryREDD(player.inventory, this); }
|
@Override public Container provideContainer(int ID, EntityPlayer player, World world, int x, int y, int z) { return new ContainerBatteryREDD(player.inventory, this); }
|
||||||
@Override public Object provideGUI(int ID, EntityPlayer player, World world, int x, int y, int z) { return new GUIBatteryREDD(player.inventory, this); }
|
@Override public Object provideGUI(int ID, EntityPlayer player, World world, int x, int y, int z) { return new GUIBatteryREDD(player.inventory, this); }
|
||||||
|
|
||||||
AxisAlignedBB bb = null;
|
AxisAlignedBB bb = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AxisAlignedBB getRenderBoundingBox() {
|
public AxisAlignedBB getRenderBoundingBox() {
|
||||||
|
|
||||||
if(bb == null) {
|
if(bb == null) {
|
||||||
bb = AxisAlignedBB.getBoundingBox(
|
bb = AxisAlignedBB.getBoundingBox(
|
||||||
xCoord - 4,
|
xCoord - 4,
|
||||||
@ -215,7 +219,47 @@ public class TileEntityBatteryREDD extends TileEntityBatteryBase {
|
|||||||
zCoord + 5
|
zCoord + 5
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return bb;
|
return bb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// do some opencomputer stuff
|
||||||
|
@Callback(direct = true)
|
||||||
|
@Optional.Method(modid = "OpenComputers")
|
||||||
|
public Object[] getEnergyInfo(Context context, Arguments args) {
|
||||||
|
return new Object[] {this.power.doubleValue(), this.delta.longValue()};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Callback(direct = true)
|
||||||
|
@Optional.Method(modid = "OpenComputers")
|
||||||
|
public Object[] getInfo(Context context, Arguments args) {
|
||||||
|
return new Object[] {this.power.doubleValue(), this.delta.longValue(), redLow, redHigh, getPriority().ordinal()};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Optional.Method(modid = "OpenComputers")
|
||||||
|
public String[] methods() {
|
||||||
|
return new String[] {
|
||||||
|
"getEnergyInfo",
|
||||||
|
"getModeInfo",
|
||||||
|
"setModeLow",
|
||||||
|
"setModeHigh",
|
||||||
|
"setPriority",
|
||||||
|
"getInfo"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Optional.Method(modid = "OpenComputers")
|
||||||
|
public Object[] invoke(String method, Context context, Arguments args) throws Exception {
|
||||||
|
switch (method) {
|
||||||
|
case "getEnergyInfo": return getEnergyInfo(context, args);
|
||||||
|
case "getModeInfo": return getModeInfo(context, args);
|
||||||
|
case "setModeLow": return setModeLow(context, args);
|
||||||
|
case "setModeHigh": return setModeHigh(context, args);
|
||||||
|
case "setPriority": return setPriority(context, args);
|
||||||
|
case "getInfo": return getInfo(context, args);
|
||||||
|
}
|
||||||
|
throw new NoSuchMethodException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,7 +12,11 @@ import api.hbm.energymk2.IBatteryItem;
|
|||||||
import api.hbm.redstoneoverradio.IRORInteractive;
|
import api.hbm.redstoneoverradio.IRORInteractive;
|
||||||
import api.hbm.redstoneoverradio.IRORValueProvider;
|
import api.hbm.redstoneoverradio.IRORValueProvider;
|
||||||
import api.hbm.tile.IInfoProviderEC;
|
import api.hbm.tile.IInfoProviderEC;
|
||||||
|
import cpw.mods.fml.common.Optional;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import li.cil.oc.api.machine.Arguments;
|
||||||
|
import li.cil.oc.api.machine.Callback;
|
||||||
|
import li.cil.oc.api.machine.Context;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.inventory.Container;
|
import net.minecraft.inventory.Container;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
@ -25,21 +29,21 @@ public class TileEntityBatterySocket extends TileEntityBatteryBase implements IR
|
|||||||
|
|
||||||
public long[] log = new long[20];
|
public long[] log = new long[20];
|
||||||
public long delta = 0;
|
public long delta = 0;
|
||||||
|
|
||||||
public int renderPack = -1;
|
public int renderPack = -1;
|
||||||
|
|
||||||
public TileEntityBatterySocket() {
|
public TileEntityBatterySocket() {
|
||||||
super(1);
|
super(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public String getName() { return "container.batterySocket"; }
|
@Override public String getName() { return "container.batterySocket"; }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateEntity() {
|
public void updateEntity() {
|
||||||
long prevPower = this.getPower();
|
long prevPower = this.getPower();
|
||||||
|
|
||||||
super.updateEntity();
|
super.updateEntity();
|
||||||
|
|
||||||
if(!worldObj.isRemote) {
|
if(!worldObj.isRemote) {
|
||||||
|
|
||||||
long avg = (this.getPower() + prevPower) / 2;
|
long avg = (this.getPower() + prevPower) / 2;
|
||||||
@ -56,7 +60,7 @@ public class TileEntityBatterySocket extends TileEntityBatteryBase implements IR
|
|||||||
@Override
|
@Override
|
||||||
public void serialize(ByteBuf buf) {
|
public void serialize(ByteBuf buf) {
|
||||||
super.serialize(buf);
|
super.serialize(buf);
|
||||||
|
|
||||||
int renderPack = -1;
|
int renderPack = -1;
|
||||||
if(slots[0] != null && slots[0].getItem() == ModItems.battery_pack) {
|
if(slots[0] != null && slots[0].getItem() == ModItems.battery_pack) {
|
||||||
renderPack = slots[0].getItemDamage();
|
renderPack = slots[0].getItemDamage();
|
||||||
@ -88,7 +92,7 @@ public class TileEntityBatterySocket extends TileEntityBatteryBase implements IR
|
|||||||
if(slots[0] == null || !(slots[0].getItem() instanceof IBatteryItem)) return 0;
|
if(slots[0] == null || !(slots[0].getItem() instanceof IBatteryItem)) return 0;
|
||||||
return ((IBatteryItem) slots[0].getItem()).getCharge(slots[0]);
|
return ((IBatteryItem) slots[0].getItem()).getCharge(slots[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setPower(long power) {
|
public void setPower(long power) {
|
||||||
if(slots[0] == null || !(slots[0].getItem() instanceof IBatteryItem)) return;
|
if(slots[0] == null || !(slots[0].getItem() instanceof IBatteryItem)) return;
|
||||||
@ -124,7 +128,7 @@ public class TileEntityBatterySocket extends TileEntityBatteryBase implements IR
|
|||||||
new BlockPos(xCoord - dir.offsetX + rot.offsetX, yCoord, zCoord - dir.offsetZ + rot.offsetZ)
|
new BlockPos(xCoord - dir.offsetX + rot.offsetX, yCoord, zCoord - dir.offsetZ + rot.offsetZ)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DirPos[] getConPos() {
|
public DirPos[] getConPos() {
|
||||||
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10);
|
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10);
|
||||||
@ -132,13 +136,13 @@ public class TileEntityBatterySocket extends TileEntityBatteryBase implements IR
|
|||||||
return new DirPos[] {
|
return new DirPos[] {
|
||||||
new DirPos(xCoord + dir.offsetX, yCoord, zCoord + dir.offsetZ, dir),
|
new DirPos(xCoord + dir.offsetX, yCoord, zCoord + dir.offsetZ, dir),
|
||||||
new DirPos(xCoord + dir.offsetX + rot.offsetX, yCoord, zCoord + dir.offsetZ + rot.offsetZ, dir),
|
new DirPos(xCoord + dir.offsetX + rot.offsetX, yCoord, zCoord + dir.offsetZ + rot.offsetZ, dir),
|
||||||
|
|
||||||
new DirPos(xCoord - dir.offsetX * 2, yCoord, zCoord - dir.offsetZ * 2, dir.getOpposite()),
|
new DirPos(xCoord - dir.offsetX * 2, yCoord, zCoord - dir.offsetZ * 2, dir.getOpposite()),
|
||||||
new DirPos(xCoord - dir.offsetX * 2 + rot.offsetX, yCoord, zCoord - dir.offsetZ * 2 + rot.offsetZ, dir.getOpposite()),
|
new DirPos(xCoord - dir.offsetX * 2 + rot.offsetX, yCoord, zCoord - dir.offsetZ * 2 + rot.offsetZ, dir.getOpposite()),
|
||||||
|
|
||||||
new DirPos(xCoord + rot.offsetX * 2, yCoord, zCoord + rot.offsetZ * 2, rot),
|
new DirPos(xCoord + rot.offsetX * 2, yCoord, zCoord + rot.offsetZ * 2, rot),
|
||||||
new DirPos(xCoord + rot.offsetX * 2 - dir.offsetX, yCoord, zCoord + rot.offsetZ * 2 - dir.offsetZ, rot),
|
new DirPos(xCoord + rot.offsetX * 2 - dir.offsetX, yCoord, zCoord + rot.offsetZ * 2 - dir.offsetZ, rot),
|
||||||
|
|
||||||
new DirPos(xCoord - rot.offsetX, yCoord, zCoord - rot.offsetZ, rot.getOpposite()),
|
new DirPos(xCoord - rot.offsetX, yCoord, zCoord - rot.offsetZ, rot.getOpposite()),
|
||||||
new DirPos(xCoord - rot.offsetX - dir.offsetX, yCoord, zCoord - rot.offsetZ - dir.offsetZ, rot.getOpposite())
|
new DirPos(xCoord - rot.offsetX - dir.offsetX, yCoord, zCoord - rot.offsetZ - dir.offsetZ, rot.getOpposite())
|
||||||
};
|
};
|
||||||
@ -146,12 +150,12 @@ public class TileEntityBatterySocket extends TileEntityBatteryBase implements IR
|
|||||||
|
|
||||||
@Override public Container provideContainer(int ID, EntityPlayer player, World world, int x, int y, int z) { return new ContainerBatterySocket(player.inventory, this); }
|
@Override public Container provideContainer(int ID, EntityPlayer player, World world, int x, int y, int z) { return new ContainerBatterySocket(player.inventory, this); }
|
||||||
@Override public Object provideGUI(int ID, EntityPlayer player, World world, int x, int y, int z) { return new GUIBatterySocket(player.inventory, this); }
|
@Override public Object provideGUI(int ID, EntityPlayer player, World world, int x, int y, int z) { return new GUIBatterySocket(player.inventory, this); }
|
||||||
|
|
||||||
AxisAlignedBB bb = null;
|
AxisAlignedBB bb = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AxisAlignedBB getRenderBoundingBox() {
|
public AxisAlignedBB getRenderBoundingBox() {
|
||||||
|
|
||||||
if(bb == null) {
|
if(bb == null) {
|
||||||
bb = AxisAlignedBB.getBoundingBox(
|
bb = AxisAlignedBB.getBoundingBox(
|
||||||
xCoord - 1,
|
xCoord - 1,
|
||||||
@ -162,7 +166,7 @@ public class TileEntityBatterySocket extends TileEntityBatteryBase implements IR
|
|||||||
zCoord + 2
|
zCoord + 2
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return bb;
|
return bb;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,10 +194,10 @@ public class TileEntityBatterySocket extends TileEntityBatteryBase implements IR
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String runRORFunction(String name, String[] params) {
|
public String runRORFunction(String name, String[] params) {
|
||||||
|
|
||||||
if((PREFIX_FUNCTION + "setmode").equals(name) && params.length > 0) {
|
if((PREFIX_FUNCTION + "setmode").equals(name) && params.length > 0) {
|
||||||
int mode = IRORInteractive.parseInt(params[0], 0, 3);
|
int mode = IRORInteractive.parseInt(params[0], 0, 3);
|
||||||
|
|
||||||
if(mode != this.redLow) {
|
if(mode != this.redLow) {
|
||||||
this.redLow = (short) mode;
|
this.redLow = (short) mode;
|
||||||
this.markChanged();
|
this.markChanged();
|
||||||
@ -206,10 +210,10 @@ public class TileEntityBatterySocket extends TileEntityBatteryBase implements IR
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((PREFIX_FUNCTION + "setredmode").equals(name) && params.length > 0) {
|
if((PREFIX_FUNCTION + "setredmode").equals(name) && params.length > 0) {
|
||||||
int mode = IRORInteractive.parseInt(params[0], 0, 3);
|
int mode = IRORInteractive.parseInt(params[0], 0, 3);
|
||||||
|
|
||||||
if(mode != this.redHigh) {
|
if(mode != this.redHigh) {
|
||||||
this.redHigh = (short) mode;
|
this.redHigh = (short) mode;
|
||||||
this.markChanged();
|
this.markChanged();
|
||||||
@ -222,7 +226,7 @@ public class TileEntityBatterySocket extends TileEntityBatteryBase implements IR
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((PREFIX_FUNCTION + "setpriority").equals(name) && params.length > 0) {
|
if((PREFIX_FUNCTION + "setpriority").equals(name) && params.length > 0) {
|
||||||
int priority = IRORInteractive.parseInt(params[0], 0, 2) + 1;
|
int priority = IRORInteractive.parseInt(params[0], 0, 2) + 1;
|
||||||
ConnectionPriority p = EnumUtil.grabEnumSafely(ConnectionPriority.class, priority);
|
ConnectionPriority p = EnumUtil.grabEnumSafely(ConnectionPriority.class, priority);
|
||||||
@ -237,4 +241,57 @@ public class TileEntityBatterySocket extends TileEntityBatteryBase implements IR
|
|||||||
public void provideExtraInfo(NBTTagCompound data) {
|
public void provideExtraInfo(NBTTagCompound data) {
|
||||||
data.setLong(CompatEnergyControl.L_DIFF_HE, (log[0] - log[19]) / 20L);
|
data.setLong(CompatEnergyControl.L_DIFF_HE, (log[0] - log[19]) / 20L);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// do some opencomputer stuff
|
||||||
|
@Callback(direct = true)
|
||||||
|
@Optional.Method(modid = "OpenComputers")
|
||||||
|
public Object[] getEnergyInfo(Context context, Arguments args) {
|
||||||
|
return new Object[] {getPower(), getMaxPower(), this.delta};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Callback(direct = true)
|
||||||
|
@Optional.Method(modid = "OpenComputers")
|
||||||
|
public Object[] getPackInfo(Context context, Arguments args) {
|
||||||
|
if(slots[0] == null || !(slots[0].getItem() instanceof IBatteryItem)) return new Object[] {"", 0, 0};
|
||||||
|
IBatteryItem bat = ((IBatteryItem) slots[0].getItem());
|
||||||
|
return new Object[] {slots[0].getUnlocalizedName(), bat.getChargeRate(slots[0]), bat.getDischargeRate(slots[0])};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Callback(direct = true)
|
||||||
|
@Optional.Method(modid = "OpenComputers")
|
||||||
|
public Object[] getInfo(Context context, Arguments args) {
|
||||||
|
Object[] energyInfo = getEnergyInfo(context, args);
|
||||||
|
Object[] packInfo = getPackInfo(context, args);
|
||||||
|
Object[] modeInfo = getModeInfo(context, args);
|
||||||
|
return new Object[] {energyInfo[0], energyInfo[1], energyInfo[2], modeInfo[0], modeInfo[1], modeInfo[2], packInfo[0], packInfo[1], packInfo[2]};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Optional.Method(modid = "OpenComputers")
|
||||||
|
public String[] methods() {
|
||||||
|
return new String[] {
|
||||||
|
"getEnergyInfo",
|
||||||
|
"getPackInfo",
|
||||||
|
"getModeInfo",
|
||||||
|
"setModeLow",
|
||||||
|
"setModeHigh",
|
||||||
|
"setPriority",
|
||||||
|
"getInfo"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Optional.Method(modid = "OpenComputers")
|
||||||
|
public Object[] invoke(String method, Context context, Arguments args) throws Exception {
|
||||||
|
switch (method) {
|
||||||
|
case "getEnergyInfo": return getEnergyInfo(context, args);
|
||||||
|
case "getPackInfo": return getPackInfo(context, args);
|
||||||
|
case "getModeInfo": return getModeInfo(context, args);
|
||||||
|
case "setModeLow": return setModeLow(context, args);
|
||||||
|
case "setModeHigh": return setModeHigh(context, args);
|
||||||
|
case "setPriority": return setPriority(context, args);
|
||||||
|
case "getInfo": return getInfo(context, args);
|
||||||
|
}
|
||||||
|
throw new NoSuchMethodException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -129,7 +129,7 @@ public class TileEntityMachineBattery extends TileEntityMachineBase implements I
|
|||||||
nbt.setShort("redHigh", redHigh);
|
nbt.setShort("redHigh", redHigh);
|
||||||
nbt.setByte("lastRedstone", lastRedstone);
|
nbt.setByte("lastRedstone", lastRedstone);
|
||||||
nbt.setByte("priority", (byte)this.priority.ordinal());
|
nbt.setByte("priority", (byte)this.priority.ordinal());
|
||||||
|
|
||||||
if (customName != null) {
|
if (customName != null) {
|
||||||
nbt.setString("name", customName);
|
nbt.setString("name", customName);
|
||||||
}
|
}
|
||||||
@ -320,7 +320,7 @@ public class TileEntityMachineBattery extends TileEntityMachineBase implements I
|
|||||||
@Override
|
@Override
|
||||||
@Optional.Method(modid = "OpenComputers")
|
@Optional.Method(modid = "OpenComputers")
|
||||||
public String getComponentName() {
|
public String getComponentName() {
|
||||||
return "ntm_energy_storage"; //ok if someone else can figure out how to do this that'd be nice (change the component name based on the type of storage block)
|
return "ntm_energy_storage_legacy";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Callback(direct = true)
|
@Callback(direct = true)
|
||||||
@ -396,10 +396,10 @@ public class TileEntityMachineBattery extends TileEntityMachineBase implements I
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String runRORFunction(String name, String[] params) {
|
public String runRORFunction(String name, String[] params) {
|
||||||
|
|
||||||
if((PREFIX_FUNCTION + "setmode").equals(name) && params.length > 0) {
|
if((PREFIX_FUNCTION + "setmode").equals(name) && params.length > 0) {
|
||||||
int mode = IRORInteractive.parseInt(params[0], 0, 3);
|
int mode = IRORInteractive.parseInt(params[0], 0, 3);
|
||||||
|
|
||||||
if(mode != this.redLow) {
|
if(mode != this.redLow) {
|
||||||
this.redLow = (short) mode;
|
this.redLow = (short) mode;
|
||||||
this.markChanged();
|
this.markChanged();
|
||||||
@ -412,10 +412,10 @@ public class TileEntityMachineBattery extends TileEntityMachineBase implements I
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((PREFIX_FUNCTION + "setredmode").equals(name) && params.length > 0) {
|
if((PREFIX_FUNCTION + "setredmode").equals(name) && params.length > 0) {
|
||||||
int mode = IRORInteractive.parseInt(params[0], 0, 3);
|
int mode = IRORInteractive.parseInt(params[0], 0, 3);
|
||||||
|
|
||||||
if(mode != this.redHigh) {
|
if(mode != this.redHigh) {
|
||||||
this.redHigh = (short) mode;
|
this.redHigh = (short) mode;
|
||||||
this.markChanged();
|
this.markChanged();
|
||||||
@ -428,7 +428,7 @@ public class TileEntityMachineBattery extends TileEntityMachineBase implements I
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((PREFIX_FUNCTION + "setpriority").equals(name) && params.length > 0) {
|
if((PREFIX_FUNCTION + "setpriority").equals(name) && params.length > 0) {
|
||||||
int priority = IRORInteractive.parseInt(params[0], 0, 2) + 1;
|
int priority = IRORInteractive.parseInt(params[0], 0, 2) + 1;
|
||||||
ConnectionPriority p = EnumUtil.grabEnumSafely(ConnectionPriority.class, priority);
|
ConnectionPriority p = EnumUtil.grabEnumSafely(ConnectionPriority.class, priority);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user