mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-20 04:09:43 +00:00
Feature: Automatable weather obelisk (#193)
Co-authored-by: Martin Robertz <[email protected]> Co-authored-by: koolkrafter5 <[email protected]>
This commit is contained in:
18 files changed
+183
-60
No files matched your search
@@ -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",
|
||||
|
||||
@@ -31,6 +31,11 @@ public class BlockWeatherObelisk extends BlockObeliskAbstract<TileWeatherObelisk
|
||||
Side.CLIENT);
|
||||
PacketHandler.INSTANCE
|
||||
.registerMessage(PacketWeatherTank.class, PacketWeatherTank.class, PacketHandler.nextID(), Side.CLIENT);
|
||||
PacketHandler.INSTANCE.registerMessage(
|
||||
PacketControlModeWeather.class,
|
||||
PacketControlModeWeather.class,
|
||||
PacketHandler.nextID(),
|
||||
Side.SERVER);
|
||||
|
||||
EntityRegistry
|
||||
.registerModEntity(EntityWeatherRocket.class, "weather_rocket", 33, EnderIO.instance, 64, 3, false);
|
||||
|
||||
@@ -11,6 +11,7 @@ import net.minecraftforge.fluids.FluidTank;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.enderio.core.client.gui.button.IconButton;
|
||||
import com.enderio.core.client.gui.button.ToggleButton;
|
||||
import com.enderio.core.client.gui.widget.GuiToolTip;
|
||||
import com.enderio.core.client.render.RenderUtil;
|
||||
|
||||
@@ -24,6 +25,7 @@ import crazypants.enderio.network.PacketHandler;
|
||||
public class GuiWeatherObelisk extends GuiPoweredMachineBase<TileWeatherObelisk> {
|
||||
|
||||
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<TileWeatherObelisk>
|
||||
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.TICK, 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.MINUS);
|
||||
buttonStart.setToolTip(EnderIO.lang.localize("gui.machine.weather.run"));
|
||||
|
||||
addButton(buttonStart);
|
||||
buttonStart.onGuiInit();
|
||||
|
||||
refreshButtons();
|
||||
@@ -68,13 +83,34 @@ public class GuiWeatherObelisk extends GuiPoweredMachineBase<TileWeatherObelisk>
|
||||
}
|
||||
|
||||
private void refreshButtons() {
|
||||
FluidStack fs = getTileEntity().getInputTank().getFluid();
|
||||
if (fs == null) {
|
||||
boolean pulseControl = getTileEntity().getLaunchOnRedstone();
|
||||
pulseControlAction(pulseControl);
|
||||
|
||||
WeatherTask task = getCurrentTask();
|
||||
if (task == null) {
|
||||
buttonStart.setIcon(IconEIO.MINUS);
|
||||
buttonStart.enabled = false;
|
||||
return;
|
||||
}
|
||||
WeatherTask task = WeatherTask.fromFluid(fs.getFluid());
|
||||
buttonStart.enabled = getTileEntity().canStartTask(task);
|
||||
switch (task) {
|
||||
case CLEAR:
|
||||
buttonStart.setIcon(IconEIO.SUN);
|
||||
break;
|
||||
case RAIN:
|
||||
buttonStart.setIcon(IconEIO.RAIN);
|
||||
break;
|
||||
case STORM:
|
||||
buttonStart.setIcon(IconEIO.THUNDER);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected WeatherTask getCurrentTask() {
|
||||
FluidStack fs = getTileEntity().getInputTank().getFluid();
|
||||
if (fs == null) {
|
||||
return null;
|
||||
}
|
||||
return WeatherTask.fromFluid(fs.getFluid());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -143,9 +179,23 @@ public class GuiWeatherObelisk extends GuiPoweredMachineBase<TileWeatherObelisk>
|
||||
@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));
|
||||
buttonStart.setEnabled(false);
|
||||
} 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.setEnabled(!pulseControl && getTileEntity().canStartTask(getCurrentTask()));
|
||||
}
|
||||
}
|
||||
+19
-1
@@ -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<TileWeatherObelisk>
|
||||
implements IMessageHandler<PacketActivateWeather, IMessage> {
|
||||
|
||||
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<TileWeatherObelisk>
|
||||
if (te != null) {
|
||||
if (ctx.side.isServer()) {
|
||||
if (PacketUtil.isInvalidPacketForGui(ctx, te, getClass())) return null;
|
||||
}
|
||||
if (message.start) {
|
||||
te.startTask();
|
||||
} else {
|
||||
te.stopTask();
|
||||
|
||||
+44
@@ -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<TileWeatherObelisk>
|
||||
implements IMessageHandler<PacketControlModeWeather, IMessage> {
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
@@ -164,6 +168,9 @@ public class TileWeatherObelisk extends AbstractPowerConsumerEntity
|
||||
@Override
|
||||
public void doUpdate() {
|
||||
super.doUpdate();
|
||||
if (cooldown > 0) {
|
||||
cooldown--;
|
||||
}
|
||||
if (worldObj.isRemote && isActive() && worldObj.getTotalWorldTime() % 2 == 0) {
|
||||
doLoadingParticles();
|
||||
}
|
||||
@@ -228,14 +235,18 @@ public class TileWeatherObelisk extends AbstractPowerConsumerEntity
|
||||
|
||||
@Override
|
||||
protected boolean processTasks(boolean redstoneCheckPassed) {
|
||||
if (cooldown > 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean res = false;
|
||||
|
||||
if (!redstoneCheckPassed) {
|
||||
if (!redstoneCheckPassed && !launchOnRedstone) {
|
||||
if (canBeActive) {
|
||||
canBeActive = false;
|
||||
res = true;
|
||||
return true;
|
||||
}
|
||||
return res;
|
||||
return false;
|
||||
} else {
|
||||
canBeActive = true;
|
||||
|
||||
@@ -254,9 +265,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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -277,31 +292,33 @@ public class TileWeatherObelisk extends AbstractPowerConsumerEntity
|
||||
public boolean canStartTask(WeatherTask task) {
|
||||
return getActiveTask() == null && !WeatherTask.worldIsState(task, worldObj)
|
||||
&& getStackInSlot(0) != null
|
||||
&& inputTank.getFluidAmount() >= 1000;
|
||||
&& inputTank.getFluidAmount() >= 1000
|
||||
&& cooldown <= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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() {
|
||||
if (getActiveTask() != null) {
|
||||
activeTask = null;
|
||||
fluidUsed = 0;
|
||||
cooldown = 200;
|
||||
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 +329,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 +401,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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user