mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
Merge pull request #2630 from Voxelstice/oc-bat-rework
OC compat for new batteries
This commit is contained in:
commit
8aa9ff2895
@ -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;
|
||||||
@ -15,20 +16,26 @@ 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.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
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;
|
||||||
@ -38,20 +45,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);
|
||||||
|
|
||||||
@ -60,14 +67,14 @@ 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) {
|
if(comp != this.lastRedstone) {
|
||||||
System.out.println(comp);
|
System.out.println(comp);
|
||||||
@ -79,7 +86,7 @@ public abstract class TileEntityBatteryBase extends TileEntityMachineBase implem
|
|||||||
this.lastRedstone = comp;
|
this.lastRedstone = comp;
|
||||||
|
|
||||||
prevPowerState = this.getPower();
|
prevPowerState = this.getPower();
|
||||||
|
|
||||||
this.networkPackNT(100);
|
this.networkPackNT(100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -88,7 +95,7 @@ public abstract class TileEntityBatteryBase extends TileEntityMachineBase implem
|
|||||||
double frac = (double) this.getPower() / (double) Math.max(this.getMaxPower(), 1) * 15D;
|
double frac = (double) this.getPower() / (double) Math.max(this.getMaxPower(), 1) * 15D;
|
||||||
return (byte) (MathHelper.clamp_int((int) Math.round(frac), 0, 15)); //to combat eventual rounding errors with the FEnSU's stupid maxPower
|
return (byte) (MathHelper.clamp_int((int) Math.round(frac), 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());
|
||||||
@ -113,7 +120,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());
|
||||||
@ -155,7 +162,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;
|
||||||
@ -163,7 +170,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
|
||||||
@ -183,10 +190,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()-1};
|
||||||
|
}
|
||||||
|
@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()-1};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,7 +11,11 @@ import com.hbm.tileentity.IPersistentNBT;
|
|||||||
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;
|
||||||
@ -26,28 +30,28 @@ public class TileEntityBatteryREDD extends TileEntityBatteryBase implements IPer
|
|||||||
|
|
||||||
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));
|
||||||
|
|
||||||
@ -60,16 +64,16 @@ public class TileEntityBatteryREDD extends TileEntityBatteryBase implements IPer
|
|||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
@ -77,11 +81,11 @@ public class TileEntityBatteryREDD extends TileEntityBatteryBase implements IPer
|
|||||||
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();
|
||||||
@ -90,7 +94,7 @@ public class TileEntityBatteryREDD extends TileEntityBatteryBase implements IPer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
@ -142,7 +146,7 @@ public class TileEntityBatteryREDD extends TileEntityBatteryBase implements IPer
|
|||||||
@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"));
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -150,7 +154,7 @@ public class TileEntityBatteryREDD extends TileEntityBatteryBase implements IPer
|
|||||||
@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 implements IPer
|
|||||||
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 implements IPer
|
|||||||
|
|
||||||
@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,10 +219,50 @@ public class TileEntityBatteryREDD extends TileEntityBatteryBase implements IPer
|
|||||||
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()-1};
|
||||||
|
}
|
||||||
|
|
||||||
|
@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();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeNBT(NBTTagCompound nbt) {
|
public void writeNBT(NBTTagCompound nbt) {
|
||||||
NBTTagCompound data = new NBTTagCompound();
|
NBTTagCompound data = new NBTTagCompound();
|
||||||
|
|||||||
@ -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;
|
||||||
@ -31,15 +35,15 @@ public class TileEntityBatterySocket extends TileEntityBatteryBase implements IR
|
|||||||
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;
|
||||||
@ -120,7 +124,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);
|
||||||
@ -128,13 +132,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())
|
||||||
};
|
};
|
||||||
@ -142,12 +146,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,
|
||||||
@ -158,7 +162,7 @@ public class TileEntityBatterySocket extends TileEntityBatteryBase implements IR
|
|||||||
zCoord + 2
|
zCoord + 2
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return bb;
|
return bb;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,10 +190,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();
|
||||||
@ -202,10 +206,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();
|
||||||
@ -218,7 +222,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);
|
||||||
@ -233,4 +237,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