mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-26 15:03:07 +00:00
Added redstone controls to power conduits.
This commit is contained in:
1 parent
f56186dcc5
commit
f9b18b6e2d
5 files changed
+212
-7
No files matched your search
@@ -309,10 +309,13 @@ public class ConduitPacketHandler implements IPacketProcessor {
|
||||
return;
|
||||
}
|
||||
|
||||
if(con instanceof ILiquidConduit) { //TODO: yeah, I know
|
||||
//TODO: yeah, I know
|
||||
if(con instanceof ILiquidConduit) {
|
||||
((ILiquidConduit) con).setExtractionRedstoneMode(mode, dir);
|
||||
} else if(con instanceof IItemConduit) {
|
||||
((IItemConduit) con).setExtractionRedstoneMode(mode, dir);
|
||||
} else if(con instanceof IPowerConduit) {
|
||||
((IPowerConduit) con).setRedstoneMode(mode, dir);
|
||||
}
|
||||
|
||||
world.markBlockForUpdate(conBun.getEntity().xCoord, conBun.getEntity().yCoord, conBun.getEntity().zCoord);
|
||||
@@ -360,12 +363,15 @@ public class ConduitPacketHandler implements IPacketProcessor {
|
||||
|
||||
ConTypeEnum type = ConTypeEnum.values()[data.readShort()];
|
||||
IConduit con = conBun.getConduit(type.baseType);
|
||||
if(con instanceof IInsulatedRedstoneConduit) { //yeah, I know
|
||||
//TODO: yeah, I know
|
||||
if(con instanceof IInsulatedRedstoneConduit) {
|
||||
((IInsulatedRedstoneConduit) con).setSignalColor(dir, col);
|
||||
} else if(con instanceof ILiquidConduit) {
|
||||
((ILiquidConduit) con).setExtractionSignalColor(dir, col);
|
||||
} else if(con instanceof IItemConduit) {
|
||||
((IItemConduit) con).setExtractionSignalColor(dir, col);
|
||||
} else if(con instanceof IPowerConduit) {
|
||||
((IPowerConduit) con).setSignalColor(dir, col);
|
||||
} else {
|
||||
Log.warn("processSignalColorPacket: Could not handle as conduit not found in bundle.");
|
||||
return;
|
||||
|
||||
@@ -61,6 +61,7 @@ public class LiquidSettings extends BaseSettingsPanel {
|
||||
|
||||
x += rsB.getWidth() + gap;
|
||||
colorB = new ColorButton(gui, ID_COLOR_BUTTON, x, y);
|
||||
colorB.setToolTipHeading("Signal Color");
|
||||
colorB.setColorIndex(conduit.getExtractionSignalColor(gui.dir).ordinal());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,82 @@
|
||||
package crazypants.enderio.conduit.gui;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.network.packet.Packet;
|
||||
import cpw.mods.fml.common.network.PacketDispatcher;
|
||||
import crazypants.enderio.ModObject;
|
||||
import crazypants.enderio.conduit.ConduitPacketHandler;
|
||||
import crazypants.enderio.conduit.IConduit;
|
||||
import crazypants.enderio.conduit.power.IPowerConduit;
|
||||
import crazypants.enderio.gui.ColorButton;
|
||||
import crazypants.enderio.gui.IconEIO;
|
||||
import crazypants.enderio.gui.RedstoneModeButton;
|
||||
import crazypants.enderio.machine.IRedstoneModeControlable;
|
||||
import crazypants.enderio.machine.RedstoneControlMode;
|
||||
import crazypants.util.DyeColor;
|
||||
|
||||
public class PowerSettings extends BaseSettingsPanel {
|
||||
|
||||
protected PowerSettings(GuiExternalConnection gui, IConduit con) {
|
||||
private static final int ID_REDSTONE_BUTTON = 796;
|
||||
|
||||
private static final int ID_COLOR_BUTTON = 797;
|
||||
|
||||
private IPowerConduit conduit;
|
||||
private RedstoneModeButton rsB;
|
||||
private ColorButton colorB;
|
||||
|
||||
protected PowerSettings(final GuiExternalConnection gui, IConduit con) {
|
||||
super(IconEIO.WRENCH_OVERLAY_POWER, ModObject.itemPowerConduit.name, gui, con);
|
||||
conduit = (IPowerConduit) con;
|
||||
|
||||
int x = 38;
|
||||
int y = customTop;
|
||||
|
||||
rsB = new RedstoneModeButton(gui, ID_REDSTONE_BUTTON, x, y, new IRedstoneModeControlable() {
|
||||
|
||||
@Override
|
||||
public void setRedstoneControlMode(RedstoneControlMode mode) {
|
||||
RedstoneControlMode curMode = getRedstoneControlMode();
|
||||
conduit.setRedstoneMode(mode, gui.dir);
|
||||
if(curMode != mode) {
|
||||
Packet pkt = ConduitPacketHandler.createExtractionModePacket(conduit, gui.dir, mode);
|
||||
PacketDispatcher.sendPacketToServer(pkt);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedstoneControlMode getRedstoneControlMode() {
|
||||
return conduit.getRedstoneMode(gui.dir);
|
||||
}
|
||||
});
|
||||
|
||||
x += rsB.getWidth() + gap;
|
||||
colorB = new ColorButton(gui, ID_COLOR_BUTTON, x, y);
|
||||
colorB.setToolTipHeading("Signal Color");
|
||||
colorB.setColorIndex(conduit.getSignalColor(gui.dir).ordinal());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(GuiButton guiButton) {
|
||||
super.actionPerformed(guiButton);
|
||||
if(guiButton.id == ID_COLOR_BUTTON) {
|
||||
Packet pkt = ConduitPacketHandler.createSignalColorPacket(conduit, gui.dir, DyeColor.values()[colorB.getColorIndex()]);
|
||||
PacketDispatcher.sendPacketToServer(pkt);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initCustomOptions() {
|
||||
super.initCustomOptions();
|
||||
rsB.onGuiInit();
|
||||
colorB.onGuiInit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deactivate() {
|
||||
super.deactivate();
|
||||
rsB.detach();
|
||||
colorB.detach();
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,12 @@ package crazypants.enderio.conduit.power;
|
||||
|
||||
import net.minecraft.util.Icon;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import buildcraft.api.power.IPowerReceptor;
|
||||
import crazypants.enderio.conduit.IConduit;
|
||||
import crazypants.enderio.machine.RedstoneControlMode;
|
||||
import crazypants.enderio.power.ICapacitor;
|
||||
import crazypants.enderio.power.IInternalPowerReceptor;
|
||||
import crazypants.enderio.power.IPowerInterface;
|
||||
import crazypants.util.DyeColor;
|
||||
|
||||
public interface IPowerConduit extends IConduit, IInternalPowerReceptor {
|
||||
|
||||
@@ -24,6 +25,14 @@ public interface IPowerConduit extends IConduit, IInternalPowerReceptor {
|
||||
|
||||
float getMaxEnergyRecieved(ForgeDirection dir);
|
||||
|
||||
void setRedstoneMode(RedstoneControlMode mode, ForgeDirection dir);
|
||||
|
||||
RedstoneControlMode getRedstoneMode(ForgeDirection dir);
|
||||
|
||||
void setSignalColor(ForgeDirection dir, DyeColor col);
|
||||
|
||||
DyeColor getSignalColor(ForgeDirection dir);
|
||||
|
||||
Icon getTextureForInputMode();
|
||||
|
||||
Icon getTextureForOutputMode();
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package crazypants.enderio.conduit.power;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import net.minecraft.client.renderer.texture.IconRegister;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -24,12 +26,14 @@ import crazypants.enderio.conduit.IConduit;
|
||||
import crazypants.enderio.conduit.IConduitBundle;
|
||||
import crazypants.enderio.conduit.RaytraceResult;
|
||||
import crazypants.enderio.conduit.geom.CollidableComponent;
|
||||
import crazypants.enderio.machine.RedstoneControlMode;
|
||||
import crazypants.enderio.power.BasicCapacitor;
|
||||
import crazypants.enderio.power.ICapacitor;
|
||||
import crazypants.enderio.power.IPowerInterface;
|
||||
import crazypants.enderio.power.PowerHandlerUtil;
|
||||
import crazypants.render.BoundingBox;
|
||||
import crazypants.render.IconUtil;
|
||||
import crazypants.util.DyeColor;
|
||||
import crazypants.vecmath.Vector3d;
|
||||
|
||||
public class PowerConduit extends AbstractConduit implements IPowerConduit {
|
||||
@@ -87,6 +91,13 @@ public class PowerConduit extends AbstractConduit implements IPowerConduit {
|
||||
|
||||
private int subtype;
|
||||
|
||||
protected final EnumMap<ForgeDirection, RedstoneControlMode> rsModes = new EnumMap<ForgeDirection, RedstoneControlMode>(ForgeDirection.class);
|
||||
protected final EnumMap<ForgeDirection, DyeColor> rsColors = new EnumMap<ForgeDirection, DyeColor>(ForgeDirection.class);
|
||||
|
||||
private final Map<ForgeDirection, Integer> externalRedstoneSignals = new HashMap<ForgeDirection, Integer>();
|
||||
|
||||
private boolean redstoneStateDirty = true;
|
||||
|
||||
public PowerConduit() {
|
||||
}
|
||||
|
||||
@@ -127,11 +138,53 @@ public class PowerConduit extends AbstractConduit implements IPowerConduit {
|
||||
return PowerHandlerUtil.createHandler(CAPACITORS[subtype], this, Type.PIPE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRedstoneMode(RedstoneControlMode mode, ForgeDirection dir) {
|
||||
rsModes.put(dir, mode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedstoneControlMode getRedstoneMode(ForgeDirection dir) {
|
||||
RedstoneControlMode res = rsModes.get(dir);
|
||||
if(res == null) {
|
||||
res = RedstoneControlMode.IGNORE;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSignalColor(ForgeDirection dir, DyeColor col) {
|
||||
rsColors.put(dir, col);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DyeColor getSignalColor(ForgeDirection dir) {
|
||||
DyeColor res = rsColors.get(dir);
|
||||
if(res == null) {
|
||||
res = DyeColor.RED;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbtRoot) {
|
||||
super.writeToNBT(nbtRoot);
|
||||
nbtRoot.setShort("subtype", (short) subtype);
|
||||
nbtRoot.setFloat("energyStored", powerHandler.getEnergyStored());
|
||||
|
||||
for (Entry<ForgeDirection, RedstoneControlMode> entry : rsModes.entrySet()) {
|
||||
if(entry.getValue() != null) {
|
||||
short ord = (short) entry.getValue().ordinal();
|
||||
nbtRoot.setShort("pRsMode." + entry.getKey().name(), ord);
|
||||
}
|
||||
}
|
||||
|
||||
for (Entry<ForgeDirection, DyeColor> entry : rsColors.entrySet()) {
|
||||
if(entry.getValue() != null) {
|
||||
short ord = (short) entry.getValue().ordinal();
|
||||
nbtRoot.setShort("pRsCol." + entry.getKey().name(), ord);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -142,12 +195,29 @@ public class PowerConduit extends AbstractConduit implements IPowerConduit {
|
||||
powerHandler = createPowerHandlerForType();
|
||||
}
|
||||
powerHandler.setEnergy(Math.min(powerHandler.getMaxEnergyStored(), nbtRoot.getFloat("energyStored")));
|
||||
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
String key = "pRsMode." + dir.name();
|
||||
if(nbtRoot.hasKey(key)) {
|
||||
short ord = nbtRoot.getShort(key);
|
||||
if(ord >= 0 && ord < RedstoneControlMode.values().length) {
|
||||
rsModes.put(dir, RedstoneControlMode.values()[ord]);
|
||||
}
|
||||
}
|
||||
key = "pRsCol." + dir.name();
|
||||
if(nbtRoot.hasKey(key)) {
|
||||
short ord = nbtRoot.getShort(key);
|
||||
if(ord >= 0 && ord < DyeColor.values().length) {
|
||||
rsColors.put(dir, DyeColor.values()[ord]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PowerReceiver getPowerReceiver(ForgeDirection side) {
|
||||
ConnectionMode mode = getConectionMode(side);
|
||||
if(mode == ConnectionMode.OUTPUT || mode == ConnectionMode.DISABLED) {
|
||||
if(mode == ConnectionMode.OUTPUT || mode == ConnectionMode.DISABLED || !isRedstoneEnabled(side)) {
|
||||
if(noInputPH == null) {
|
||||
noInputPH = new PowerHandler(this, Type.PIPE);
|
||||
noInputPH.configure(0, 0, 0, powerHandler.getMaxEnergyStored());
|
||||
@@ -160,16 +230,59 @@ public class PowerConduit extends AbstractConduit implements IPowerConduit {
|
||||
@Override
|
||||
public float getMaxEnergyExtracted(ForgeDirection dir) {
|
||||
ConnectionMode mode = getConectionMode(dir);
|
||||
if(mode == ConnectionMode.INPUT || mode == ConnectionMode.DISABLED) {
|
||||
if(mode == ConnectionMode.INPUT || mode == ConnectionMode.DISABLED || !isRedstoneEnabled(dir)) {
|
||||
return 0;
|
||||
}
|
||||
return getCapacitor().getMaxEnergyExtracted();
|
||||
}
|
||||
|
||||
private boolean isRedstoneEnabled(ForgeDirection dir) {
|
||||
boolean result;
|
||||
RedstoneControlMode mode = getRedstoneMode(dir);
|
||||
if(mode == RedstoneControlMode.NEVER) {
|
||||
return false;
|
||||
}
|
||||
if(mode == RedstoneControlMode.IGNORE) {
|
||||
return true;
|
||||
}
|
||||
|
||||
DyeColor col = getSignalColor(dir);
|
||||
// internal signal
|
||||
int signal = ConduitUtil.getInternalSignalForColor(getBundle(), col);
|
||||
if(mode.isConditionMet(mode, signal)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// external signal
|
||||
if(col != DyeColor.RED) {
|
||||
//can't get a non-red signal externally at this stage so no go
|
||||
return false;
|
||||
}
|
||||
int val = getExternalRedstoneSignalForDir(dir);
|
||||
return mode.isConditionMet(mode, val);
|
||||
}
|
||||
|
||||
private int getExternalRedstoneSignalForDir(ForgeDirection dir) {
|
||||
if(redstoneStateDirty) {
|
||||
externalRedstoneSignals.clear();
|
||||
redstoneStateDirty = false;
|
||||
}
|
||||
Integer cached = externalRedstoneSignals.get(dir);
|
||||
int result;
|
||||
if(cached == null) {
|
||||
TileEntity te = getBundle().getEntity();
|
||||
result = te.worldObj.getStrongestIndirectPower(te.xCoord, te.yCoord, te.zCoord);
|
||||
externalRedstoneSignals.put(dir, result);
|
||||
} else {
|
||||
result = cached;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMaxEnergyRecieved(ForgeDirection dir) {
|
||||
ConnectionMode mode = getConectionMode(dir);
|
||||
if(mode == ConnectionMode.OUTPUT || mode == ConnectionMode.DISABLED) {
|
||||
if(mode == ConnectionMode.OUTPUT || mode == ConnectionMode.DISABLED || !isRedstoneEnabled(dir)) {
|
||||
return 0;
|
||||
}
|
||||
return getCapacitor().getMaxEnergyReceived();
|
||||
@@ -193,6 +306,12 @@ public class PowerConduit extends AbstractConduit implements IPowerConduit {
|
||||
return getBundle().getEntity().worldObj;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onNeighborBlockChange(int blockId) {
|
||||
redstoneStateDirty = true;
|
||||
return super.onNeighborBlockChange(blockId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate) {
|
||||
if(getMaxEnergyRecieved(from) == 0) {
|
||||
|
||||
Reference in new issue
Block a user