diff --git a/src/main/java/crazypants/enderio/config/Config.java b/src/main/java/crazypants/enderio/config/Config.java index 9f8213ec..2e0b0e24 100644 --- a/src/main/java/crazypants/enderio/config/Config.java +++ b/src/main/java/crazypants/enderio/config/Config.java @@ -74,7 +74,6 @@ public final class Config { public static final Section sectionMobConfig = new Section("Mob Config", "mobconfig"); public static final Section sectionRailConfig = new Section("Rail", "railconfig"); public static final Section sectionEnchantments = new Section("Enchantments", "enchantments"); - public static final Section sectionWeather = new Section("Weather", "weather"); public static final Section sectionTelepad = new Section("Telepad", "telepad"); public static final Section sectionInventoryPanel = new Section("InventoryPanel", "inventorypanel"); public static final Section sectionMisc = new Section("Misc", "misc"); @@ -544,10 +543,6 @@ public final class Config { public static boolean spawnGuardStopAllSlimesDebug = false; public static boolean spawnGuardStopAllSquidSpawning = false; - public static int weatherObeliskClearFluid = 2000; - public static int weatherObeliskRainFluid = 500; - public static int weatherObeliskThunderFluid = 1000; - // Loot Defaults public static boolean lootDarkSteel = true; public static boolean lootItemConduitProbe = true; @@ -2746,22 +2741,6 @@ public final class Config { spawnGuardStopAllSquidSpawning, "When true no squid will be spawned."); - weatherObeliskClearFluid = config.get( - sectionWeather.name, - "weatherObeliskClearFluid", - weatherObeliskClearFluid, - "The fluid required (in mB) to set the world to clear weather").getInt(); - weatherObeliskRainFluid = config.get( - sectionWeather.name, - "weatherObeliskRainFluid", - weatherObeliskRainFluid, - "The fluid required (in mB) to set the world to rainy weather").getInt(); - weatherObeliskThunderFluid = config.get( - sectionWeather.name, - "weatherObeliskThunderFluid", - weatherObeliskThunderFluid, - "The fluid required (in mB) to set the world to thundering weather").getInt(); - // Loot Config lootDarkSteel = config.getBoolean( "lootDarkSteel", diff --git a/src/main/java/crazypants/enderio/machine/obelisk/weather/BlockWeatherObelisk.java b/src/main/java/crazypants/enderio/machine/obelisk/weather/BlockWeatherObelisk.java index 7e63fb78..4f835ce0 100644 --- a/src/main/java/crazypants/enderio/machine/obelisk/weather/BlockWeatherObelisk.java +++ b/src/main/java/crazypants/enderio/machine/obelisk/weather/BlockWeatherObelisk.java @@ -31,6 +31,11 @@ public class BlockWeatherObelisk extends BlockObeliskAbstract { private IconButton buttonStart; + private ToggleButton buttonMode; public GuiWeatherObelisk(InventoryPlayer inventory, TileWeatherObelisk tileEntity) { super(tileEntity, new ContainerWeatherObelisk(inventory, tileEntity), "weatherObelisk"); @@ -50,10 +52,23 @@ public class GuiWeatherObelisk extends GuiPoweredMachineBase public void initGui() { super.initGui(); - int x = (xSize / 2) - (BUTTON_SIZE / 2); + int x_mode = xSize - 5 - BUTTON_SIZE; + int x_start = (xSize / 2) - (BUTTON_SIZE / 2); int y = 58; - addButton(buttonStart = new IconButton(this, 0, x, y, IconEIO.TICK)); + buttonMode = new ToggleButton(this, 1, x_mode, y, IconEIO.ROUND_ROBIN_OFF, IconEIO.REDSTONE_MODE_WITH_SIGNAL); + + buttonMode.setToolTip(EnderIO.lang.localize("gui.machine.weather.control")); + buttonMode.setSelectedToolTip(EnderIO.lang.localize("gui.machine.weather.redstone")); + buttonMode.setUnselectedToolTip(EnderIO.lang.localize("gui.machine.weather.manual")); + buttonMode.setSelected(getTileEntity().getLaunchOnRedstone()); + addButton(buttonMode); + buttonMode.onGuiInit(); + + buttonStart = new IconButton(this, 0, x_start, y, IconEIO.TICK); + buttonStart.setToolTip(EnderIO.lang.localize("gui.machine.weather.run")); + + addButton(buttonStart); buttonStart.onGuiInit(); refreshButtons(); @@ -68,6 +83,9 @@ public class GuiWeatherObelisk extends GuiPoweredMachineBase } private void refreshButtons() { + boolean pulseControl = getTileEntity().getLaunchOnRedstone(); + pulseControlAction(pulseControl); + FluidStack fs = getTileEntity().getInputTank().getFluid(); if (fs == null) { buttonStart.enabled = false; @@ -143,9 +161,22 @@ public class GuiWeatherObelisk extends GuiPoweredMachineBase @Override protected void actionPerformed(GuiButton b) { super.actionPerformed(b); - if (b.id >= 0 && b.id <= 2) { + if (b.id == 0) { + // Start Button getTileEntity().startTask(); - PacketHandler.INSTANCE.sendToServer(new PacketActivateWeather(getTileEntity())); + PacketHandler.INSTANCE.sendToServer(new PacketActivateWeather(getTileEntity(), true)); + } else if (b.id == 1) { + // Control Mode Button + boolean pulseControl = buttonMode.isSelected(); + getTileEntity().setLaunchOnRedstone(pulseControl); + pulseControlAction(pulseControl); + PacketControlModeWeather packet = new PacketControlModeWeather(getTileEntity()); + PacketHandler.INSTANCE.sendToServer(packet); } } + + protected void pulseControlAction(boolean pulseControl) { + redstoneButton.setVisible(!pulseControl); + buttonStart.setVisible(!pulseControl); + } } diff --git a/src/main/java/crazypants/enderio/machine/obelisk/weather/PacketActivateWeather.java b/src/main/java/crazypants/enderio/machine/obelisk/weather/PacketActivateWeather.java index 0599d0ce..179497b7 100644 --- a/src/main/java/crazypants/enderio/machine/obelisk/weather/PacketActivateWeather.java +++ b/src/main/java/crazypants/enderio/machine/obelisk/weather/PacketActivateWeather.java @@ -7,14 +7,30 @@ import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; import cpw.mods.fml.common.network.simpleimpl.MessageContext; import crazypants.enderio.EnderIO; import crazypants.enderio.network.PacketUtil; +import io.netty.buffer.ByteBuf; public class PacketActivateWeather extends MessageTileEntity implements IMessageHandler { + private boolean start; + public PacketActivateWeather() {} - public PacketActivateWeather(TileWeatherObelisk te) { + public PacketActivateWeather(TileWeatherObelisk te, boolean start) { super(te); + this.start = start; + } + + @Override + public void toBytes(ByteBuf buf) { + super.toBytes(buf); + buf.writeBoolean(start); + } + + @Override + public void fromBytes(ByteBuf buf) { + super.fromBytes(buf); + start = buf.readBoolean(); } @Override @@ -24,6 +40,8 @@ public class PacketActivateWeather extends MessageTileEntity if (te != null) { if (ctx.side.isServer()) { if (PacketUtil.isInvalidPacketForGui(ctx, te, getClass())) return null; + } + if (message.start) { te.startTask(); } else { te.stopTask(); diff --git a/src/main/java/crazypants/enderio/machine/obelisk/weather/PacketControlModeWeather.java b/src/main/java/crazypants/enderio/machine/obelisk/weather/PacketControlModeWeather.java new file mode 100644 index 00000000..88f8b0dc --- /dev/null +++ b/src/main/java/crazypants/enderio/machine/obelisk/weather/PacketControlModeWeather.java @@ -0,0 +1,44 @@ +package crazypants.enderio.machine.obelisk.weather; + +import com.enderio.core.common.network.MessageTileEntity; + +import cpw.mods.fml.common.network.simpleimpl.IMessage; +import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; +import cpw.mods.fml.common.network.simpleimpl.MessageContext; +import crazypants.enderio.network.PacketUtil; +import io.netty.buffer.ByteBuf; + +public class PacketControlModeWeather extends MessageTileEntity + implements IMessageHandler { + + private boolean pulse; + + public PacketControlModeWeather() {} + + public PacketControlModeWeather(TileWeatherObelisk te) { + super(te); + this.pulse = te.getLaunchOnRedstone(); + } + + @Override + public void toBytes(ByteBuf buf) { + super.toBytes(buf); + buf.writeBoolean(pulse); + } + + @Override + public void fromBytes(ByteBuf buf) { + super.fromBytes(buf); + pulse = buf.readBoolean(); + } + + @Override + public IMessage onMessage(PacketControlModeWeather message, MessageContext ctx) { + TileWeatherObelisk te = message.getTileEntity(message.getWorld(ctx)); + if (te != null) { + if (PacketUtil.isInvalidPacketForGui(ctx, te, getClass())) return null; + te.setLaunchOnRedstone(message.pulse); + } + return null; + } +} diff --git a/src/main/java/crazypants/enderio/machine/obelisk/weather/TileWeatherObelisk.java b/src/main/java/crazypants/enderio/machine/obelisk/weather/TileWeatherObelisk.java index 8d81ca8c..35be6538 100644 --- a/src/main/java/crazypants/enderio/machine/obelisk/weather/TileWeatherObelisk.java +++ b/src/main/java/crazypants/enderio/machine/obelisk/weather/TileWeatherObelisk.java @@ -24,6 +24,7 @@ import cpw.mods.fml.relauncher.SideOnly; import crazypants.enderio.EnderIO; import crazypants.enderio.ModObject; import crazypants.enderio.machine.AbstractPowerConsumerEntity; +import crazypants.enderio.machine.RedstoneControlMode; import crazypants.enderio.machine.SlotDefinition; import crazypants.enderio.network.PacketHandler; import crazypants.enderio.power.Capacitors; @@ -100,6 +101,9 @@ public class TileWeatherObelisk extends AbstractPowerConsumerEntity private boolean canBeActive = true; private boolean tanksDirty; + private boolean launchOnRedstone = false; + private int cooldown = 0; + private static final ICapacitor cap = Capacitors.BASIC_CAPACITOR.capacitor; private FluidTank inputTank = new FluidTank(8000); @@ -230,7 +234,13 @@ public class TileWeatherObelisk extends AbstractPowerConsumerEntity protected boolean processTasks(boolean redstoneCheckPassed) { boolean res = false; - if (!redstoneCheckPassed) { + if (cooldown > 0) { + cooldown--; + res = true; + return res; + } + + if (!redstoneCheckPassed && !launchOnRedstone) { if (canBeActive) { canBeActive = false; res = true; @@ -254,9 +264,13 @@ public class TileWeatherObelisk extends AbstractPowerConsumerEntity EntityWeatherRocket e = new EntityWeatherRocket(worldObj, activeTask); e.setPosition(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5); worldObj.spawnEntityInWorld(e); + cooldown = 200; stopTask(); res = true; } + } else if (launchOnRedstone && RedstoneControlMode.isConditionMet(RedstoneControlMode.ON, this)) { + startTask(); + res = true; } } @@ -280,20 +294,19 @@ public class TileWeatherObelisk extends AbstractPowerConsumerEntity && inputTank.getFluidAmount() >= 1000; } - /** - * @return If the operation was successful. - */ - public boolean startTask() { + public void startTask() { if (getActiveTask() == null && inputTank.getFluidAmount() > 0) { fluidUsed = 0; WeatherTask task = WeatherTask.fromFluid(inputTank.getFluid().getFluid()); if (canStartTask(task)) { + if (!worldObj.isRemote) { + PacketHandler.INSTANCE + .sendToDimension(new PacketActivateWeather(this, true), worldObj.provider.dimensionId); + } decrStackSize(0, 1); activeTask = task; - return true; } } - return false; } public void stopTask() { @@ -301,7 +314,8 @@ public class TileWeatherObelisk extends AbstractPowerConsumerEntity activeTask = null; fluidUsed = 0; if (!worldObj.isRemote) { - PacketHandler.INSTANCE.sendToDimension(new PacketActivateWeather(this), worldObj.provider.dimensionId); + PacketHandler.INSTANCE + .sendToDimension(new PacketActivateWeather(this, false), worldObj.provider.dimensionId); } else { playedFuse = false; } @@ -312,12 +326,14 @@ public class TileWeatherObelisk extends AbstractPowerConsumerEntity public void writeCommon(NBTTagCompound nbtRoot) { super.writeCommon(nbtRoot); nbtRoot.setTag("tank", inputTank.writeToNBT(new NBTTagCompound())); + nbtRoot.setBoolean("weatherobeliskcontrolmode", launchOnRedstone); } @Override public void readCommon(NBTTagCompound nbtRoot) { super.readCommon(nbtRoot); inputTank.readFromNBT(nbtRoot.getCompoundTag("tank")); + launchOnRedstone = nbtRoot.getBoolean("weatherobeliskcontrolmode"); } private boolean isValidFluid(Fluid f) { @@ -382,4 +398,12 @@ public class TileWeatherObelisk extends AbstractPowerConsumerEntity public FluidTankInfo[] getTankInfo(ForgeDirection from) { return new FluidTankInfo[] { inputTank.getInfo() }; } + + public void setLaunchOnRedstone(boolean launchOnRedstone) { + this.launchOnRedstone = launchOnRedstone; + } + + public boolean getLaunchOnRedstone() { + return this.launchOnRedstone; + } } diff --git a/src/main/resources/assets/enderio/lang/en_US.lang b/src/main/resources/assets/enderio/lang/en_US.lang index 861f0b05..ad4b323b 100644 --- a/src/main/resources/assets/enderio/lang/en_US.lang +++ b/src/main/resources/assets/enderio/lang/en_US.lang @@ -1101,6 +1101,10 @@ enderio.gui.machine.side.west=West enderio.gui.machine.side.east=East enderio.gui.machine.side.up=Up enderio.gui.machine.side.down=Down +enderio.gui.machine.weather.control=Control Mode +enderio.gui.machine.weather.redstone=Launch on Redstone +enderio.gui.machine.weather.manual=Default Control Mode +enderio.gui.machine.weather.run=Launch #Power Monitor