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,15 +15,21 @@ 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;
|
||||||
@ -181,4 +188,62 @@ public abstract class TileEntityBatteryBase extends TileEntityMachineBase implem
|
|||||||
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;
|
||||||
@ -218,4 +222,44 @@ public class TileEntityBatteryREDD extends TileEntityBatteryBase {
|
|||||||
|
|
||||||
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;
|
||||||
@ -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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user