diff --git a/src/main/java/tauri/dev/jsg/gui/JSGTexturedGui.java b/src/main/java/tauri/dev/jsg/gui/JSGTexturedGui.java index 273082b4..4c3b9383 100644 --- a/src/main/java/tauri/dev/jsg/gui/JSGTexturedGui.java +++ b/src/main/java/tauri/dev/jsg/gui/JSGTexturedGui.java @@ -5,11 +5,11 @@ import net.minecraft.util.ResourceLocation; public abstract class JSGTexturedGui extends GuiScreen { - protected int guiLeft; - protected int guiTop; + public int guiLeft; + public int guiTop; - protected final int xSize; - protected final int ySize; + public final int xSize; + public final int ySize; protected final int texW; protected final int texH; diff --git a/src/main/java/tauri/dev/jsg/gui/admincontroller/AddressesSection.java b/src/main/java/tauri/dev/jsg/gui/admincontroller/AddressesSection.java index f43d1f6b..be30a900 100644 --- a/src/main/java/tauri/dev/jsg/gui/admincontroller/AddressesSection.java +++ b/src/main/java/tauri/dev/jsg/gui/admincontroller/AddressesSection.java @@ -2,16 +2,18 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiTextField; -import net.minecraft.client.renderer.GlStateManager; import net.minecraft.util.EnumHand; import net.minecraftforge.common.DimensionManager; import net.minecraftforge.fml.client.config.GuiUtils; import tauri.dev.jsg.JSG; +import tauri.dev.jsg.gui.base.JSGButton; import tauri.dev.jsg.gui.base.JSGTextField; import tauri.dev.jsg.gui.element.ArrowButton; import tauri.dev.jsg.gui.element.GuiHelper; import tauri.dev.jsg.packet.JSGPacketHandler; +import tauri.dev.jsg.packet.gui.entry.EntryActionEnum; import tauri.dev.jsg.packet.gui.entry.EntryActionToServer; +import tauri.dev.jsg.stargate.EnumIrisState; import tauri.dev.jsg.stargate.network.StargateAddress; import tauri.dev.jsg.stargate.network.StargateAddressDynamic; import tauri.dev.jsg.stargate.network.StargatePos; @@ -22,17 +24,20 @@ public class AddressesSection { + public static final int OFFSET = 15; + // ---------------------------------------------------------- + protected static final int SCROLL_AMOUNT = 5; public ArrayList entries = new ArrayList<>(); - public int guiTop; public int height; public int guiLeft; public int width; - - public static final int OFFSET = 15; - public int scrolled = 0; public GuiAdminController guiBase; + public int thisGateEntryIndex = -1; + public ArrayList dialButtons = new ArrayList<>(); + public ArrayList optionButtons = new ArrayList<>(); + public ArrayList entriesTextFields = new ArrayList<>(); public AddressesSection(GuiAdminController baseGui) { this.guiBase = baseGui; @@ -65,10 +70,7 @@ public void generateAddressEntries() { sortEntries(); } - public ArrayList dialButtons = new ArrayList<>(); - public ArrayList entriesTextFields = new ArrayList<>(); - - public void generateAddressEntriesBoxes(boolean reset) { + public void init(boolean reset) { int index = -1; if (!reset && dialButtons.size() > 0) return; if (!reset && entriesTextFields.size() > 0) return; @@ -87,8 +89,9 @@ public void generateAddressEntriesBoxes(boolean reset) { } else { field.setEnabled(false); } - ArrowButton btn = (ArrowButton) new ArrowButton(index, guiLeft + 120 + 5, 0, ArrowButton.ArrowType.RIGHT).setFgColor(GuiUtils.getColorCode('a', true)).setActionCallback(() -> dialGate(finalIndex)); + ArrowButton btn = (ArrowButton) new ArrowButton(index, guiLeft + 125, 0, ArrowButton.ArrowType.RIGHT).setFgColor(GuiUtils.getColorCode('a', true)).setActionCallback(() -> dialGate(finalIndex)); if (e.pos.gatePos.equals(Objects.requireNonNull(guiBase.gateTile).getPos()) && e.pos.dimensionID == guiBase.gateTile.world().provider.getDimension()) { + thisGateEntryIndex = index; btn.setEnabled(false); btn.setActionCallback(() -> { }); @@ -97,6 +100,46 @@ public void generateAddressEntriesBoxes(boolean reset) { entriesTextFields.add(field); dialButtons.add(btn); } + + // Options buttons + optionButtons.clear(); + + // Abort button + String text = "Abort dialing"; + int width = (10 + guiBase.mc.fontRenderer.getStringWidth(text)); + int y = this.guiTop; + int x = guiBase.guiRight - OFFSET - 40 - width; + optionButtons.add(new JSGButton(100, x, y, width, 20, text).setActionCallback(() -> { + if (guiBase.imaginaryGateTile != null && guiBase.imaginaryGateTile.getStargateState().dialing()) { + if (guiBase.imaginaryGateTile.abortDialingSequence()) { + guiBase.notifer.setText("Dialing aborted.", Notifier.EnumAlertType.INFO, 5); + sendPacket(EntryActionEnum.ABORT); + } else + guiBase.notifer.setText("Gate is busy!", Notifier.EnumAlertType.WARNING, 5); + } else if (guiBase.imaginaryGateTile != null) { + guiBase.notifer.setText("Gate is not dialing", Notifier.EnumAlertType.WARNING, 5); + } else { + guiBase.notifer.setText("Gate is NULL!", Notifier.EnumAlertType.ERROR, 5); + } + })); + + // Toggle IRIS + text = "Toggle iris"; + width = (10 + guiBase.mc.fontRenderer.getStringWidth(text)); + x -= (width + 3); + optionButtons.add(new JSGButton(101, x, y, width, 20, text).setActionCallback(() -> { + if (guiBase.imaginaryGateTile != null && guiBase.imaginaryGateTile.hasIris()) { + if (guiBase.imaginaryGateTile.getIrisState() == EnumIrisState.OPENED || guiBase.imaginaryGateTile.getIrisState() == EnumIrisState.CLOSED) { + guiBase.notifer.setText("Toggling iris.", Notifier.EnumAlertType.INFO, 5); + sendPacket(EntryActionEnum.TOGGLE_IRIS); + } else + guiBase.notifer.setText("Gate's iris is busy!", Notifier.EnumAlertType.WARNING, 5); + } else if (guiBase.imaginaryGateTile != null) { + guiBase.notifer.setText("Gate has no iris!", Notifier.EnumAlertType.WARNING, 5); + } else { + guiBase.notifer.setText("Gate is NULL!", Notifier.EnumAlertType.ERROR, 5); + } + })); } public void sortEntries() { @@ -112,21 +155,29 @@ public void sortEntries() { entries = newList; } + public void sendPacket(EntryActionEnum action) { + try { + JSGPacketHandler.INSTANCE.sendToServer(new EntryActionToServer(action, guiBase.pos)); + } catch (Exception e) { + JSG.error("Error", e); + } + } + public void dialGate(int index) { try { EnumHand hand = guiBase.getHand(); StargateEntry entry = entries.get(index); StargatePos pos = entry.pos; - if (guiBase.gateTile == null || guiBase.imaginaryGateTile == null){ + if (guiBase.gateTile == null || guiBase.imaginaryGateTile == null) { guiBase.notifer.setText("Linked gate is NULL!", Notifier.EnumAlertType.ERROR, 5); return; } - if (!guiBase.imaginaryGateTile.getStargateState().idle() && !guiBase.imaginaryGateTile.getStargateState().engaged()){ + if (!guiBase.imaginaryGateTile.getStargateState().idle() && !guiBase.imaginaryGateTile.getStargateState().engaged()) { guiBase.notifer.setText("Stargate is busy!", Notifier.EnumAlertType.WARNING, 5); return; } - if(!guiBase.imaginaryGateTile.getStargateState().engaged()) + if (!guiBase.imaginaryGateTile.getStargateState().engaged()) guiBase.notifer.setText("Dialing gate " + (pos.getName().equals("") ? DimensionManager.getProviderType(pos.dimensionID).getName() : pos.getName()), Notifier.EnumAlertType.INFO, 5); else guiBase.notifer.setText("Closing gate...", Notifier.EnumAlertType.INFO, 5); @@ -134,8 +185,7 @@ public void dialGate(int index) { int symbolsCount = Objects.requireNonNull(guiBase.gateTile).getMinimalSymbolsToDial(pos.getGateSymbolType(), pos); JSGPacketHandler.INSTANCE.sendToServer(new EntryActionToServer(hand, new StargateAddressDynamic(entry.address), symbolsCount, guiBase.gateTile.getPos())); - } - catch (Exception e){ + } catch (Exception e) { JSG.error("Error ", e); guiBase.notifer.setText("Unknown error! (" + e.getMessage() + ")", Notifier.EnumAlertType.ERROR, 5); } @@ -164,19 +214,22 @@ public void updateY() { public void renderEntries() { updateY(); - - GlStateManager.color(1, 1, 1, 1); - - GlStateManager.pushMatrix(); for (GuiTextField f : entriesTextFields) { if (canNotRenderEntry(f.y)) continue; f.drawTextBox(); } + + boolean shouldBeEnabled = (guiBase.imaginaryGateTile != null && (guiBase.imaginaryGateTile.getStargateState().idle() || guiBase.imaginaryGateTile.getStargateState().engaged())); + for (ArrowButton b : dialButtons) { if (canNotRenderEntry(b.y)) continue; + b.setEnabled(shouldBeEnabled && b.id != thisGateEntryIndex); + b.drawButton(Minecraft.getMinecraft(), guiBase.mouseX, guiBase.mouseY, guiBase.partialTicks); + } + + for (JSGButton b : optionButtons) { b.drawButton(Minecraft.getMinecraft(), guiBase.mouseX, guiBase.mouseY, guiBase.partialTicks); } - GlStateManager.popMatrix(); } public void renderFg() { @@ -198,9 +251,6 @@ public void renderFg() { } } - // ---------------------------------------------------------- - protected static final int SCROLL_AMOUNT = 5; - public void scroll(int k) { if (k == 0) return; if (k < 0) k = -1; @@ -211,8 +261,8 @@ public void scroll(int k) { } public boolean canContinueScrolling(int k) { - int top = guiTop + OFFSET; - int bottom = guiTop + height - OFFSET; + int top = guiTop; + int bottom = guiTop + height; if (entriesTextFields.size() < 1 && dialButtons.size() < 1) return false; boolean isTop = ((entriesTextFields.size() > 0 && entriesTextFields.get(0).getId() < dialButtons.get(0).id) ? entriesTextFields.get(0).y > top : dialButtons.get(0).y > top); @@ -222,8 +272,8 @@ public boolean canContinueScrolling(int k) { } public boolean canNotRenderEntry(int y) { - int top = guiTop + OFFSET; - int bottom = guiTop + height - OFFSET; + int top = guiTop; + int bottom = guiTop + height; int height = 23; return y < top || (y + height) > bottom; } diff --git a/src/main/java/tauri/dev/jsg/gui/admincontroller/GuiAdminController.java b/src/main/java/tauri/dev/jsg/gui/admincontroller/GuiAdminController.java index 1bf69da2..6540acde 100644 --- a/src/main/java/tauri/dev/jsg/gui/admincontroller/GuiAdminController.java +++ b/src/main/java/tauri/dev/jsg/gui/admincontroller/GuiAdminController.java @@ -16,7 +16,9 @@ import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; import tauri.dev.jsg.JSG; +import tauri.dev.jsg.config.JSGConfig; import tauri.dev.jsg.gui.JSGTexturedGui; +import tauri.dev.jsg.gui.base.JSGButton; import tauri.dev.jsg.gui.element.ArrowButton; import tauri.dev.jsg.gui.element.GuiHelper; import tauri.dev.jsg.gui.mainmenu.GuiCustomMainMenu; @@ -30,6 +32,7 @@ import tauri.dev.jsg.stargate.network.SymbolTypeEnum; import tauri.dev.jsg.tileentity.stargate.StargateClassicBaseTile; import tauri.dev.jsg.util.JSGTextureLightningHelper; +import tauri.dev.jsg.util.math.TemperatureHelper; import javax.annotation.Nonnull; import java.io.IOException; @@ -157,7 +160,10 @@ public ResourceLocation getBackground() { public void initGui() { super.initGui(); center = getCenterPos(0, 0); - gateCenter = center; + gateCenter = new int[]{ + center[0], + center[1] + OFFSET/2 + }; guiRight = xSize; guiBottom = ySize; @@ -166,7 +172,7 @@ public void initGui() { addressesSection.guiTop = OFFSET; addressesSection.width = 145 + (AddressesSection.OFFSET * 2); addressesSection.height = ySize - OFFSET * 2; - addressesSection.generateAddressEntriesBoxes(true); + addressesSection.init(true); } public static final int OFFSET = 15; @@ -180,7 +186,7 @@ public void drawForeground(int mouseX, int mouseY, float partialTicks) { // render background addressesSection.generateAddressEntries(); - addressesSection.generateAddressEntriesBoxes(false); + addressesSection.init(false); addressesSection.renderEntries(); renderControlButtons(); @@ -217,7 +223,13 @@ public void mouseClicked(int mouseX, int mouseY, int mouseButton) { field.mouseClicked(this.mouseX, this.mouseY, mouseButton); } for (ArrowButton button : addressesSection.dialButtons) { - if (GuiHelper.isPointInRegion(button.x, button.y, button.width, button.height, this.mouseX, this.mouseY)) { + if (button.enabled && GuiHelper.isPointInRegion(button.x, button.y, button.width, button.height, this.mouseX, this.mouseY)) { + button.performAction(); + button.playPressSound(Minecraft.getMinecraft().getSoundHandler()); + } + } + for(JSGButton button : addressesSection.optionButtons){ + if (button.enabled && GuiHelper.isPointInRegion(button.x, button.y, button.width, button.height, this.mouseX, this.mouseY)) { button.performAction(); button.playPressSound(Minecraft.getMinecraft().getSoundHandler()); } @@ -277,6 +289,26 @@ public void renderGateInfo() { renderSymbol(x, y, width, height, symbol, originId); } // ---------------------- + + // Render info + String[] s = new String[]{ + "Gate state: " + imaginaryGateTile.getStargateState(), + "Gate temp: " + JSGConfig.General.visual.temperatureUnit.getTemperatureToDisplay(TemperatureHelper.asKelvins(TemperatureHelper.asCelsius(imaginaryGateTile.gateHeat).toKelvins()), 0), + "Iris temp: " + JSGConfig.General.visual.temperatureUnit.getTemperatureToDisplay(TemperatureHelper.asKelvins(TemperatureHelper.asCelsius(imaginaryGateTile.irisHeat).toKelvins()), 0), + "Installed capacitors: " + (imaginaryGateTile.getPowerTier() - 1), + "Energy: " + String.format("%.0f", (float) imaginaryGateTile.getEnergyStored()) + "RF", + "Time opened: " + imaginaryGateTile.getOpenedSecondsToDisplayAsMinutes(), + "Seconds to close: " + imaginaryGateTile.getEnergySecondsToClose() + }; + + int y = OFFSET + 23; + for(String line : s){ + width = fontRenderer.getStringWidth(line); + int lineX = guiRight - OFFSET - width - 40; + fontRenderer.drawString(line, lineX, y, 0xffffff, true); + y += 10; + } + // ---------------------- } public static void renderSymbol(int x, int y, int w, int h, SymbolInterface symbol, int originId) { @@ -297,4 +329,12 @@ public static void renderSymbol(int x, int y, int w, int h, SymbolInterface symb GlStateManager.popMatrix(); } + + @Override + public void onGuiClosed() { + for(GuiTextField f : addressesSection.entriesTextFields){ + f.setFocused(false); + } + super.onGuiClosed(); + } } diff --git a/src/main/java/tauri/dev/jsg/gui/base/JSGButton.java b/src/main/java/tauri/dev/jsg/gui/base/JSGButton.java index b39d58b6..50636ebc 100644 --- a/src/main/java/tauri/dev/jsg/gui/base/JSGButton.java +++ b/src/main/java/tauri/dev/jsg/gui/base/JSGButton.java @@ -2,35 +2,43 @@ import net.minecraft.client.gui.GuiButton; +import java.util.ArrayList; +import java.util.List; + public class JSGButton extends GuiButton { - private ActionCallback actionCallback; - - public void performAction() { - actionCallback.performAction(); - } - - public JSGButton(int buttonId, int x, int y, int widthIn, int heightIn, String buttonText) { - super(buttonId, x, y, widthIn, heightIn, buttonText); - } - - - public JSGButton setFgColor(int fgColor) { - packedFGColour = fgColor; - return this; - } - - public JSGButton setActionCallback(ActionCallback callback) { - actionCallback = callback; - return this; - } - - public JSGButton setEnabled(boolean enabled) { - this.enabled = enabled; - return this; - } - - public interface ActionCallback { - void performAction(); - } + public List hoverText = new ArrayList<>(); + private ActionCallback actionCallback; + + public JSGButton(int buttonId, int x, int y, int widthIn, int heightIn, String buttonText) { + super(buttonId, x, y, widthIn, heightIn, buttonText); + } + + public void performAction() { + actionCallback.performAction(); + } + + public JSGButton setFgColor(int fgColor) { + packedFGColour = fgColor; + return this; + } + + public JSGButton setActionCallback(ActionCallback callback) { + actionCallback = callback; + return this; + } + + public JSGButton setEnabled(boolean enabled) { + this.enabled = enabled; + return this; + } + + public JSGButton setHoverText(List lines){ + this.hoverText = lines; + return this; + } + + public interface ActionCallback { + void performAction(); + } } \ No newline at end of file diff --git a/src/main/java/tauri/dev/jsg/gui/base/JSGTextField.java b/src/main/java/tauri/dev/jsg/gui/base/JSGTextField.java index 2d6169c0..853a8566 100644 --- a/src/main/java/tauri/dev/jsg/gui/base/JSGTextField.java +++ b/src/main/java/tauri/dev/jsg/gui/base/JSGTextField.java @@ -4,9 +4,11 @@ import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiTextField; +import javax.annotation.ParametersAreNonnullByDefault; + /** * Adds setText that returns this inststance. - * + * * @author MrJake222 * */ @@ -15,7 +17,9 @@ public class JSGTextField extends GuiTextField { private ActionCallback actionCallback; private String originalContent; private boolean numbersOnly; - + + private int borderColor = 0xffffff; + public JSGTextField(int componentId, FontRenderer fontrendererObj, int x, int y, int width, int height, String originalContent) { super(componentId, fontrendererObj, x, y, width, height); this.originalContent = originalContent; @@ -37,26 +41,27 @@ public JSGTextField setMaxStringLengthBetter(int maxNameLength) { super.setMaxStringLength(maxNameLength); return this; } - + public JSGTextField setActionCallback(ActionCallback callback) { actionCallback = callback; return this; } - + public JSGTextField setNumbersOnly() { this.numbersOnly = true; return this; } - + @Override + @ParametersAreNonnullByDefault public void writeText(String textToWrite) { if (numbersOnly) { textToWrite = textToWrite.replaceAll("\\D+",""); } - + super.writeText(textToWrite); } - + @Override public void setFocused(boolean focused) { if (isFocused() && !focused && !originalContent.equals(getText())) { @@ -64,7 +69,7 @@ public void setFocused(boolean focused) { originalContent = getText(); actionCallback.performAction(); } - + super.setFocused(focused); } } diff --git a/src/main/java/tauri/dev/jsg/item/ItemAdminController.java b/src/main/java/tauri/dev/jsg/item/ItemAdminController.java index d578802b..6aa6f36a 100644 --- a/src/main/java/tauri/dev/jsg/item/ItemAdminController.java +++ b/src/main/java/tauri/dev/jsg/item/ItemAdminController.java @@ -10,11 +10,13 @@ import net.minecraft.util.ActionResult; import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumHand; +import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import tauri.dev.jsg.JSG; import tauri.dev.jsg.creativetabs.JSGCreativeTabsHandler; import tauri.dev.jsg.packet.AdminControllerGuiOpenToClient; import tauri.dev.jsg.packet.JSGPacketHandler; +import tauri.dev.jsg.stargate.teleportation.TeleportHelper; import tauri.dev.jsg.tileentity.stargate.StargateClassicBaseTile; import tauri.dev.jsg.tileentity.stargate.StargateClassicMemberTile; import tauri.dev.jsg.util.RayTraceHelper; @@ -39,21 +41,20 @@ public boolean shouldCauseReequipAnimation(@Nonnull ItemStack oldStack, @Nonnull @Override public void onUpdate(@Nonnull ItemStack stack, @Nonnull World world, @Nonnull Entity entity, int itemSlot, boolean isSelected) { if (!world.isRemote) { - if(world.getTotalWorldTime() % 5 != 0) return; - if(!(entity instanceof EntityPlayerMP)) return; + if (world.getTotalWorldTime() % 5 != 0) return; + if (!(entity instanceof EntityPlayerMP)) return; - TileEntity te = RayTraceHelper.rayTraceTileEntity((EntityPlayerMP) entity, 20); + NBTTagCompound compound = stack.getTagCompound(); + if (compound == null) return; - if (te instanceof StargateClassicMemberTile) { - te = ((StargateClassicMemberTile) te).getBaseTile(world); - } + BlockPos tePos = BlockPos.fromLong(compound.getLong("linkedGatePos")); + World w = TeleportHelper.getWorld(compound.getInteger("linkedGateDim")); + if(w == null) return; + TileEntity te = w.getTileEntity(tePos); if (!(te instanceof StargateClassicBaseTile)) return; StargateClassicBaseTile gateTile = (StargateClassicBaseTile) te; - NBTTagCompound compound = stack.getTagCompound(); - if(compound == null) compound = new NBTTagCompound(); - compound.setTag("gateNBT", gateTile.writeToNBT(new NBTTagCompound())); stack.setTagCompound(compound); @@ -71,6 +72,13 @@ public ActionResult onItemRightClick(World world, @Nonnull EntityPlay } if (te instanceof StargateClassicBaseTile && player instanceof EntityPlayerMP) { + ItemStack stack = player.getHeldItem(hand); + NBTTagCompound compound = stack.getTagCompound(); + if (compound == null) compound = new NBTTagCompound(); + + compound.setLong("linkedGatePos", te.getPos().toLong()); + compound.setInteger("linkedGateDim", te.getWorld().provider.getDimension()); + JSGPacketHandler.INSTANCE.sendTo(new AdminControllerGuiOpenToClient(te.getPos(), ((StargateClassicBaseTile) te).getNetwork()), (EntityPlayerMP) player); } } diff --git a/src/main/java/tauri/dev/jsg/packet/gui/entry/EntryActionEnum.java b/src/main/java/tauri/dev/jsg/packet/gui/entry/EntryActionEnum.java index ebd879ef..92aba81c 100644 --- a/src/main/java/tauri/dev/jsg/packet/gui/entry/EntryActionEnum.java +++ b/src/main/java/tauri/dev/jsg/packet/gui/entry/EntryActionEnum.java @@ -5,5 +5,7 @@ public enum EntryActionEnum { MOVE_UP, MOVE_DOWN, REMOVE, - DIAL + DIAL, + ABORT, + TOGGLE_IRIS } diff --git a/src/main/java/tauri/dev/jsg/packet/gui/entry/EntryActionToServer.java b/src/main/java/tauri/dev/jsg/packet/gui/entry/EntryActionToServer.java index 06564cd4..9afcde0f 100644 --- a/src/main/java/tauri/dev/jsg/packet/gui/entry/EntryActionToServer.java +++ b/src/main/java/tauri/dev/jsg/packet/gui/entry/EntryActionToServer.java @@ -20,6 +20,7 @@ import tauri.dev.jsg.item.notebook.NotebookItem; import tauri.dev.jsg.stargate.StargateClosedReasonEnum; import tauri.dev.jsg.stargate.network.*; +import tauri.dev.jsg.tileentity.stargate.StargateAbstractBaseTile; import tauri.dev.jsg.tileentity.stargate.StargateClassicBaseTile; import tauri.dev.jsg.tileentity.stargate.StargateUniverseBaseTile; @@ -63,6 +64,15 @@ public EntryActionToServer(EnumHand hand, String name, StargatePos targetGate) { this.linkedGate = null; } + public EntryActionToServer(EntryActionEnum action, BlockPos linkedGate) { + this.hand = EnumHand.MAIN_HAND; + this.dataType = EntryDataTypeEnum.ADMIN_CONTROLLER; + this.action = action; + this.index = -1; + this.name = ""; + this.linkedGate = linkedGate; + } + public EntryActionToServer(EnumHand hand, EntryDataTypeEnum dataType, EntryActionEnum action, int index, String name) { this.hand = hand; @@ -229,7 +239,7 @@ public IMessage onMessage(EntryActionToServer message, MessageContext ctx) { } else if (message.dataType.admin()) { switch (message.action) { case RENAME: - StargateClassicBaseTile gateTile = (StargateClassicBaseTile) message.targetGatePos.getTileEntity(); + StargateAbstractBaseTile gateTile = message.targetGatePos.getTileEntity(); if (gateTile == null) return; gateTile.renameStargatePos(message.name); break; @@ -240,11 +250,21 @@ public IMessage onMessage(EntryActionToServer message, MessageContext ctx) { gateTile1.attemptClose(StargateClosedReasonEnum.REQUESTED); break; } - if (gateTile1.dialAddress(message.addressToDial, message.maxSymbols - 1, true)) - player.sendStatusMessage(new TextComponentTranslation("item.jsg.universe_dialer.dial_start"), true); - else - player.sendStatusMessage(new TextComponentTranslation("item.jsg.universe_dialer.gate_busy"), true); - + gateTile1.dialAddress(message.addressToDial, message.maxSymbols - 1, true); + break; + case ABORT: + StargateClassicBaseTile gateTile2 = (StargateClassicBaseTile) world.getTileEntity(message.linkedGate); + if(gateTile2 == null) return; + if(gateTile2.getStargateState().dialing()) + gateTile2.abortDialingSequence(); + break; + case TOGGLE_IRIS: + StargateClassicBaseTile gateTile3 = (StargateClassicBaseTile) world.getTileEntity(message.linkedGate); + if(gateTile3 == null) return; + if(gateTile3.hasIris()) + gateTile3.toggleIris(); + break; + default: break; } } diff --git a/src/main/java/tauri/dev/jsg/tileentity/stargate/StargateAbstractBaseTile.java b/src/main/java/tauri/dev/jsg/tileentity/stargate/StargateAbstractBaseTile.java index 24fdd66a..f28f3bfe 100644 --- a/src/main/java/tauri/dev/jsg/tileentity/stargate/StargateAbstractBaseTile.java +++ b/src/main/java/tauri/dev/jsg/tileentity/stargate/StargateAbstractBaseTile.java @@ -1185,6 +1185,7 @@ public long getOpenedSeconds() { public String getOpenedSecondsToDisplayAsMinutes() { long openedSeconds = getOpenedSeconds(); + if(openedSeconds < 1) return "Closed!"; int minutes = ((int) Math.floor((double) openedSeconds / 60)); int seconds = ((int) (openedSeconds - (60 * minutes))); String secondsString = ((seconds < 10) ? "0" + seconds : "" + seconds); @@ -1742,6 +1743,10 @@ public float getEnergySecondsToClose() { protected abstract SmallEnergyStorage getEnergyStorage(); + public int getEnergyStored(){ + return getEnergyStorage().getEnergyStored(); + } + protected EnergyRequiredToOperate getEnergyRequiredToDial(StargatePos targetGatePos) { BlockPos sPos = pos; BlockPos tPos = targetGatePos.gatePos; diff --git a/src/main/java/tauri/dev/jsg/tileentity/stargate/StargateClassicBaseTile.java b/src/main/java/tauri/dev/jsg/tileentity/stargate/StargateClassicBaseTile.java index 3451642b..e046a2ca 100644 --- a/src/main/java/tauri/dev/jsg/tileentity/stargate/StargateClassicBaseTile.java +++ b/src/main/java/tauri/dev/jsg/tileentity/stargate/StargateClassicBaseTile.java @@ -1167,10 +1167,13 @@ public NBTTagCompound writeToNBT(NBTTagCompound compound) { compound.setByte("irisState", irisState.id); compound.setInteger("irisCode", irisCode); compound.setByte("irisMode", irisMode.id); + compound.setByte("irisType", irisType.id); if (codeSender != null && !world.isRemote) { compound.setTag("codeSender", codeSender.serializeNBT()); } + compound.setInteger("powerTier", currentPowerTier); + compound.setInteger("incomingLastChevronLightUp", incomingLastChevronLightUp); compound.setInteger("incomingPeriod", incomingPeriod); compound.setInteger("incomingAddressSize", incomingAddressSize); @@ -1220,11 +1223,14 @@ public void readFromNBT(NBTTagCompound compound) { irisState = EnumIrisState.getValue(compound.getByte("irisState")); irisCode = compound.getInteger("irisCode") != 0 ? compound.getInteger("irisCode") : -1; irisMode = EnumIrisMode.getValue(compound.getByte("irisMode")); + irisType = EnumIrisType.byId(compound.getByte("irisType")); if (compound.hasKey("codeSender") && !world.isRemote) { NBTTagCompound nbt = compound.getCompoundTag("codeSender"); codeSender = codeSenderFromNBT(nbt); } + currentPowerTier = compound.getInteger("powerTier"); + incomingPeriod = compound.getInteger("incomingPeriod"); incomingLastChevronLightUp = compound.getInteger("incomingLastChevronLightUp"); incomingAddressSize = compound.getInteger("incomingAddressSize"); @@ -2161,6 +2167,7 @@ public boolean toggleIris() { } switch (irisState) { case OPENED: + case OPENING: if (hasShieldIris() && getEnergyStorage().getEnergyStored() < shieldKeepAlive * 3) return false; @@ -2172,6 +2179,7 @@ public boolean toggleIris() { if (targetGatePos != null) executeTask(EnumScheduledTask.STARGATE_HORIZON_LIGHT_BLOCK, null); break; case CLOSED: + case CLOSING: irisState = EnumIrisState.OPENING; setIrisBlocks(false); sendRenderingUpdate(StargateRendererActionState.EnumGateAction.IRIS_UPDATE, 0, true, irisType, irisState, irisAnimation); @@ -2330,6 +2338,10 @@ protected SmallEnergyStorage getEnergyStorage() { return energyStorage; } + public int getEnergyStored(){ + return getEnergyStorage().getEnergyStored(); + } + private int currentPowerTier = 1; public int getPowerTier() { diff --git a/src/main/java/tauri/dev/jsg/tileentity/stargate/StargateOrlinBaseTile.java b/src/main/java/tauri/dev/jsg/tileentity/stargate/StargateOrlinBaseTile.java index dee30821..3bc83418 100644 --- a/src/main/java/tauri/dev/jsg/tileentity/stargate/StargateOrlinBaseTile.java +++ b/src/main/java/tauri/dev/jsg/tileentity/stargate/StargateOrlinBaseTile.java @@ -43,479 +43,449 @@ import tauri.dev.jsg.util.main.JSGProps; import tauri.dev.jsg.worldgen.util.GeneratedStargate; -import java.util.Arrays; +import java.util.Collections; import java.util.EnumSet; import java.util.List; import java.util.Random; public class StargateOrlinBaseTile extends StargateAbstractBaseTile { - public void setLinkedDHD(BlockPos dhdPos, int linkId){} - - // ------------------------------------------------------------------------ - // Stargate state - - private int openCount = 0; - - /** - * Checks openCount of ALL members. - * @return True if the gate (or any of it's parts) had been used 2 times (default) - */ - public boolean isBroken() { - if (openCount == JSGConfig.Stargate.mechanics.stargateOrlinMaxOpenCount) - return true; - - if (StargateOrlinMergeHelper.INSTANCE.getMaxOpenCount(world, pos, facing) == JSGConfig.Stargate.mechanics.stargateOrlinMaxOpenCount) - return true; - - return false; - } - - public void addDrops(List drops) { - - if (openCount == JSGConfig.Stargate.mechanics.stargateOrlinMaxOpenCount) { - Random rand = new Random(); - - drops.add(new ItemStack(Items.IRON_INGOT, 2 + rand.nextInt(3))); - } - - else { - NBTTagCompound compound = new NBTTagCompound(); - compound.setInteger("openCount", openCount); - - ItemStack stack = new ItemStack(Item.getItemFromBlock(JSGBlocks.STARGATE_ORLIN_BASE_BLOCK)); - stack.setTagCompound(compound); - - drops.add(stack); - } - } - - public void initializeFromItemStack(ItemStack stack) { - if (stack.hasTagCompound()) { - NBTTagCompound compound = stack.getTagCompound(); - - if (compound.hasKey("openCount")) { - openCount = compound.getInteger("openCount"); - } - } - } - - @Override - public SymbolTypeEnum getSymbolType() { - return SymbolTypeEnum.MILKYWAY; - } - - @Override - public void dialingFailed(StargateOpenResult result) { - super.dialingFailed(result); - - addTask(new ScheduledTask(EnumScheduledTask.STARGATE_FAILED_SOUND, 30)); - } - - @Override - protected void addFailedTaskAndPlaySound() { - addTask(new ScheduledTask(EnumScheduledTask.STARGATE_FAIL, 83)); - playSoundEvent(StargateSoundEventEnum.DIAL_FAILED); - } - - @Override - public void openGate(StargatePos targetGatePos, boolean isInitiating) { - if (world.provider.getDimensionType() == DimensionType.OVERWORLD) - StargateNetwork.get(world).setLastActivatedOrlins(gateAddressMap.get(SymbolTypeEnum.MILKYWAY)); - super.openGate(targetGatePos, isInitiating); - } - - @Override - protected void disconnectGate() { - super.disconnectGate(); - - openCount++; - StargateOrlinMergeHelper.INSTANCE.incrementMembersOpenCount(world, pos, facing); - - if (isBroken()) { - addTask(new ScheduledTask(EnumScheduledTask.STARGATE_ORLIN_BROKE_SOUND, 5)); - } - } - - @Override - public boolean canAcceptConnectionFrom(StargatePos targetGatePos) { - return super.canAcceptConnectionFrom(targetGatePos) && targetGatePos.dimensionID == DimensionType.NETHER.getId() && !isBroken(); - } - - public boolean canNotGenerate = false; - - public void updateNetherAddress() { - dialedAddress.clear(); - if(!network.hasNetherGate() || !network.isStargateInNetwork(network.getNetherGate()) || network.getStargate(network.getNetherGate()) == null){ - if(!world.isRemote && world.provider.getDimensionType() == DimensionType.OVERWORLD) { - JSG.info("Orlin gate requested building of new nether gate... Build started..."); - GeneratedStargate stargate = StargateNetwork.generateNetherGate(network, world, pos); - if(stargate == null){ - canNotGenerate = true; - markDirty(); - } - } - } - if(network.hasNetherGate()) { - dialedAddress.addAll(network.getNetherGate().subList(0, StargateDimensionConfig.netherOverworld8thSymbol() ? 7 : 6)); - dialedAddress.addSymbol(SymbolMilkyWayEnum.ORIGIN); - } - markDirty(); - - JSG.debug("Orlin's dialed address: " + dialedAddress); - } - - public EnergyRequiredToOperate getEnergyRequiredToDial() { - return getEnergyRequiredToDial(network.getStargate(dialedAddress)); - } - - public int getEnergyStored() { - return getEnergyStorage().getEnergyStored(); - } - - // ------------------------------------------------------------------------ - // Ticking - - @Override - public BlockPos getGateCenterPos() { - return pos.offset(EnumFacing.UP, 1); - } - - @Override - public void update() { - super.update(); - - if (world.isRemote) { - if (!world.getBlockState(pos).getValue(JSGProps.RENDER_BLOCK) && rendererStateClient != null) - JSG.proxy.orlinRendererSpawnParticles(world, getRendererStateClient()); - - // Each 2s check for the biome overlay - if (world.getTotalWorldTime() % 40 == 0 && rendererStateClient != null) { - rendererStateClient.setBiomeOverlay(BiomeOverlayEnum.updateBiomeOverlay(world, getMergeHelper().getTopBlock().add(pos), getSupportedOverlays())); - } - } - } - - public static final EnumSet SUPPORTED_OVERLAYS = EnumSet.of( - BiomeOverlayEnum.NORMAL, - BiomeOverlayEnum.FROST, - BiomeOverlayEnum.MOSSY); - - @Override - public EnumSet getSupportedOverlays() { - return SUPPORTED_OVERLAYS; - } - - - // ------------------------------------------------------------------------ - // Redstone - - private boolean isPowered; - - public void redstonePowerUpdate(boolean power) { - if (!isMerged()) - return; - - if ((isPowered && !power) || (!isPowered && power)) { - isPowered = power; - - if (isPowered && stargateState.idle() && !isBroken()) - beginOpening(); - - else if (!isPowered && stargateState.initiating()) { - attemptClose(StargateClosedReasonEnum.REQUESTED); - } - - markDirty(); - } - } - - public void beginOpening(){ - if (world.provider.getDimensionType() != DimensionType.OVERWORLD){ - JSGSoundHelper.playSoundEvent(world, getGateCenterPos(), SoundEventEnum.GATE_ORLIN_FAIL); - return; - } - updateNetherAddress(); - if(isBroken()) return; - switch (checkAddressAndEnergy(dialedAddress)) { - case OK: - stargateState = EnumStargateState.DIALING; - - startSparks(); - JSGSoundHelper.playSoundEvent(world, getGateCenterPos(), SoundEventEnum.GATE_ORLIN_DIAL); - - addTask(new ScheduledTask(EnumScheduledTask.STARGATE_ORLIN_OPEN)); - return; - - case ADDRESS_MALFORMED: - if(!world.isRemote && world.provider.getDimensionType() == DimensionType.OVERWORLD) { - StargateNetwork.generateNetherGate(network, world, pos); - JSG.info("Orlin gate requested building of new nether gate... Build started..."); - } - beginOpening(); - //JSG.error("Orlin's gate: wrong dialed address"); - break; - - case NOT_ENOUGH_POWER: - //JSG.info("Orlin's gate: Not enough power"); - break; - - case ABORTED: - case ABORTED_BY_EVENT: - case CALLER_HUNG_UP: - break; - } - } - - - // ------------------------------------------------------------------------ - // Merging - - @Override - public StargateAbstractMergeHelper getMergeHelper() { - return StargateOrlinMergeHelper.INSTANCE; - } - - // ------------------------------------------------------------------------ - // Killing - - @Override - protected JSGAxisAlignedBB getHorizonKillingBox(boolean server) { - return new JSGAxisAlignedBB(-0.5, 1, -0.5, 0.5, 2, 1.5); - } - - @Override - protected int getHorizonSegmentCount(boolean server) { - return 2; - } - - @Override - protected List getGateVaporizingBoxes(boolean server) { - return Arrays.asList(new JSGAxisAlignedBB(-0.5, 1, -0.5, 0.5, 2, 0.5)); - } - - - // ------------------------------------------------------------------------ - // Rendering - - @Override - protected JSGAxisAlignedBB getHorizonTeleportBox(boolean server) { - return new JSGAxisAlignedBB(-1.0, 0.6, -0.15, 1.0, 2.7, -0.05); - } - -// @Override -// protected StargateAbstractRendererState getRendererStateServer() { -// return StargateAbstractRendererState.builder() -// .setStargateState(stargateState).build(); -// } - - @Override - protected StargateAbstractRendererState createRendererStateClient() { - return new StargateOrlinRendererState(); - } - - @Override - public StargateOrlinRendererState getRendererStateClient() { - return (StargateOrlinRendererState) super.getRendererStateClient(); - } - - - // ------------------------------------------------------------------------ - // Sounds - - @Override - protected SoundPositionedEnum getPositionedSound(StargateSoundPositionedEnum soundEnum) { - return null; - } - - @Override - protected SoundEventEnum getSoundEvent(StargateSoundEventEnum soundEnum) { - switch (soundEnum) { - case OPEN: return SoundEventEnum.GATE_MILKYWAY_OPEN; - case CLOSE: return SoundEventEnum.GATE_MILKYWAY_CLOSE; - case DIAL_FAILED: return SoundEventEnum.GATE_ORLIN_FAIL; - case GATE_BROKE: return SoundEventEnum.GATE_ORLIN_BROKE; - default: return null; - } - } - - - // ------------------------------------------------------------------------ - // States - - @Override - public State createState(StateTypeEnum stateType) { - switch (stateType) { - case SPARK_STATE: - return new StargateOrlinSparkState(); - - default: - return super.createState(stateType); - } - } - - @Override - @SideOnly(Side.CLIENT) - public void setState(StateTypeEnum stateType, State state) { - switch (stateType) { - case SPARK_STATE: - if(getRendererStateClient() == null) break; - StargateOrlinSparkState sparkState = (StargateOrlinSparkState) state; - getRendererStateClient().sparkFrom(sparkState.sparkIndex, sparkState.spartStart); - - break; - - default: - super.setState(stateType, state); - break; - } - } - - - // ------------------------------------------------------------------------ - // Sparks - - private int sparkIndex; - - public void startSparks() { - sparkIndex = 0; - - addTask(new ScheduledTask(EnumScheduledTask.STARGATE_ORLIN_SPARK, 5)); - } - - - // ------------------------------------------------------------------------ - // Scheduled tasks - - @Override - public void executeTask(EnumScheduledTask scheduledTask, NBTTagCompound customData) { - switch (scheduledTask) { - case STARGATE_ORLIN_OPEN: - StargatePos targetGatePos = network.getStargate(dialedAddress); - - if (hasEnergyToDial(targetGatePos)) { - targetGatePos.getTileEntity().incomingWormhole(dialedAddress.size()); - } - - attemptOpenAndFail(); - break; - - case STARGATE_ORLIN_SPARK: - JSGPacketHandler.INSTANCE.sendToAllTracking(new StateUpdatePacketToClient(pos, StateTypeEnum.SPARK_STATE, new StargateOrlinSparkState(sparkIndex, world.getTotalWorldTime())), targetPoint); - - if (sparkIndex < 6 && sparkIndex != -1) - addTask(new ScheduledTask(EnumScheduledTask.STARGATE_ORLIN_SPARK, 24)); - - sparkIndex++; - - break; - - case STARGATE_FAILED_SOUND: - playSoundEvent(StargateSoundEventEnum.DIAL_FAILED); - - break; - - case STARGATE_ORLIN_BROKE_SOUND: - playSoundEvent(StargateSoundEventEnum.GATE_BROKE); - - break; - - default: - super.executeTask(scheduledTask, customData); - break; - } - } - - - // ------------------------------------------------------------------------ - // Power - - private final SmallEnergyStorage energyStorate = new SmallEnergyStorage(); - - @Override - protected SmallEnergyStorage getEnergyStorage() { - return energyStorate; - } - - @Override - protected EnergyRequiredToOperate getEnergyRequiredToDial(StargatePos targetGatePos) { - return super.getEnergyRequiredToDial(targetGatePos).mul(JSGConfig.Stargate.power.stargateOrlinEnergyMul).cap(JSGConfig.Stargate.power.stargateEnergyStorage/4 - 1000000); - } - -// @Override -// protected int getMaxEnergyStorage() { -// return JSGConfig.powerConfig.stargateOrlinEnergyStorage; -// } -// -// @Override -// protected boolean canReceiveEnergy() { -// return !isBroken(); -// } - - public static final JSGAxisAlignedBB RENDER_BOX = new JSGAxisAlignedBB(-1.5, 0, -0.6, 1.5, 3, 1.5); - - @Override - protected JSGAxisAlignedBB getRenderBoundingBoxRaw() { - return RENDER_BOX; - } - - // ------------------------------------------------------------------------ - // NBT - - @Override - public NBTTagCompound writeToNBT(NBTTagCompound compound) { - compound.setBoolean("isPowered", isPowered); - compound.setInteger("openCount", openCount); - compound.setBoolean("canNotGenerate", canNotGenerate); - - return super.writeToNBT(compound); - } - - @Override - public void readFromNBT(NBTTagCompound compound) { - isPowered = compound.getBoolean("isPowered"); - openCount = compound.getInteger("openCount"); - canNotGenerate = compound.getBoolean("canNotGenerate"); - - super.readFromNBT(compound); - } - - @Optional.Method(modid = "opencomputers") - @Callback - public Object[] getGateType(Context context, Arguments args) { - return new Object[] {isMerged() ? "ORLIN" : null}; - } - - @Optional.Method(modid = "opencomputers") - @Callback(doc = "function() -- Tries to open the gate") - public Object[] engageGate(Context context, Arguments args) { - if (!isMerged()) return new Object[]{null, "stargate_failure_not_merged", "Stargate is not merged"}; - - if (stargateState.idle()) { - if(!isBroken()) { - beginOpening(); - return new Object[]{null, "stargate_engage"}; - } - else{ - return new Object[]{null, "stargate_failure_opening", "Stargate is broken"}; - } - } else { - return new Object[]{null, "stargate_failure_busy", "Stargate is busy", stargateState.toString()}; - } - } - - @Optional.Method(modid = "opencomputers") - @Callback(doc = "function() -- Tries to close the gate") - public Object[] disengageGate(Context context, Arguments args) { - if (!isMerged()) return new Object[]{null, "stargate_failure_not_merged", "Stargate is not merged"}; - - if (stargateState.engaged()) { - if (getStargateState().initiating()) { - attemptClose(StargateClosedReasonEnum.REQUESTED); - return new Object[]{"stargate_disengage"}; - } else return new Object[]{null, "stargate_failure_wrong_end", "Unable to close the gate on this end"}; - } else { - return new Object[]{null, "stargate_failure_not_open", "The gate is closed"}; - } - } + public static final EnumSet SUPPORTED_OVERLAYS = EnumSet.of( + BiomeOverlayEnum.NORMAL, + BiomeOverlayEnum.FROST, + BiomeOverlayEnum.MOSSY); + + // ------------------------------------------------------------------------ + // Stargate state + public static final JSGAxisAlignedBB RENDER_BOX = new JSGAxisAlignedBB(-1.5, 0, -0.6, 1.5, 3, 1.5); + private final SmallEnergyStorage energyStorage = new SmallEnergyStorage(); + public boolean canNotGenerate = false; + private int openCount = 0; + private boolean isPowered; + private int sparkIndex; + + public void setLinkedDHD(BlockPos dhdPos, int linkId) { + } + + /** + * Checks openCount of ALL members. + * + * @return True if the gate (or any of it's parts) had been used 2 times (default) + */ + public boolean isBroken() { + if (openCount >= JSGConfig.Stargate.mechanics.stargateOrlinMaxOpenCount) + return true; + + return StargateOrlinMergeHelper.INSTANCE.getMaxOpenCount(world, pos, facing) >= JSGConfig.Stargate.mechanics.stargateOrlinMaxOpenCount; + } + + public void addDrops(List drops) { + + if (openCount >= JSGConfig.Stargate.mechanics.stargateOrlinMaxOpenCount) { + Random rand = new Random(); + + drops.add(new ItemStack(Items.IRON_INGOT, 2 + rand.nextInt(3))); + } else { + NBTTagCompound compound = new NBTTagCompound(); + compound.setInteger("openCount", openCount); + + ItemStack stack = new ItemStack(Item.getItemFromBlock(JSGBlocks.STARGATE_ORLIN_BASE_BLOCK)); + stack.setTagCompound(compound); + + drops.add(stack); + } + } + + public void initializeFromItemStack(ItemStack stack) { + if (stack.hasTagCompound()) { + NBTTagCompound compound = stack.getTagCompound(); + + if (compound != null && compound.hasKey("openCount")) { + openCount = compound.getInteger("openCount"); + } + } + } + + @Override + public SymbolTypeEnum getSymbolType() { + return SymbolTypeEnum.MILKYWAY; + } + + @Override + public void dialingFailed(StargateOpenResult result) { + super.dialingFailed(result); + + addTask(new ScheduledTask(EnumScheduledTask.STARGATE_FAILED_SOUND, 30)); + } + + @Override + protected void addFailedTaskAndPlaySound() { + addTask(new ScheduledTask(EnumScheduledTask.STARGATE_FAIL, 83)); + playSoundEvent(StargateSoundEventEnum.DIAL_FAILED); + } + + // ------------------------------------------------------------------------ + // Ticking + + @Override + public void openGate(StargatePos targetGatePos, boolean isInitiating) { + if (world.provider.getDimensionType() == DimensionType.OVERWORLD) + StargateNetwork.get(world).setLastActivatedOrlins(gateAddressMap.get(SymbolTypeEnum.MILKYWAY)); + super.openGate(targetGatePos, isInitiating); + } + + @Override + protected void disconnectGate() { + super.disconnectGate(); + + openCount++; + StargateOrlinMergeHelper.INSTANCE.incrementMembersOpenCount(world, pos, facing); + + if (isBroken()) { + addTask(new ScheduledTask(EnumScheduledTask.STARGATE_ORLIN_BROKE_SOUND, 5)); + } + } + + @Override + public boolean canAcceptConnectionFrom(StargatePos targetGatePos) { + return super.canAcceptConnectionFrom(targetGatePos) && targetGatePos.dimensionID == DimensionType.NETHER.getId() && !isBroken(); + } + + public void updateNetherAddress() { + dialedAddress.clear(); + if (!network.hasNetherGate() || !network.isStargateInNetwork(network.getNetherGate()) || network.getStargate(network.getNetherGate()) == null) { + if (!world.isRemote && world.provider.getDimensionType() == DimensionType.OVERWORLD) { + JSG.info("Orlin gate requested building of new nether gate... Build started..."); + GeneratedStargate stargate = StargateNetwork.generateNetherGate(network, world, pos); + if (stargate == null) { + canNotGenerate = true; + markDirty(); + } + } + } + if (network.hasNetherGate()) { + dialedAddress.addAll(network.getNetherGate().subList(0, StargateDimensionConfig.netherOverworld8thSymbol() ? 7 : 6)); + dialedAddress.addSymbol(SymbolMilkyWayEnum.ORIGIN); + } + markDirty(); + + JSG.debug("Orlin's dialed address: " + dialedAddress); + } + + + // ------------------------------------------------------------------------ + // Redstone + + public EnergyRequiredToOperate getEnergyRequiredToDial() { + return getEnergyRequiredToDial(network.getStargate(dialedAddress)); + } + + @Override + public BlockPos getGateCenterPos() { + return pos.offset(EnumFacing.UP, 1); + } + + @Override + public void update() { + super.update(); + + if (world.isRemote) { + if (!world.getBlockState(pos).getValue(JSGProps.RENDER_BLOCK) && rendererStateClient != null) + JSG.proxy.orlinRendererSpawnParticles(world, getRendererStateClient()); + + // Each 2s check for the biome overlay + if (world.getTotalWorldTime() % 40 == 0 && rendererStateClient != null) { + rendererStateClient.setBiomeOverlay(BiomeOverlayEnum.updateBiomeOverlay(world, getMergeHelper().getTopBlock().add(pos), getSupportedOverlays())); + } + } + } + + + // ------------------------------------------------------------------------ + // Merging + + @Override + public EnumSet getSupportedOverlays() { + return SUPPORTED_OVERLAYS; + } + + // ------------------------------------------------------------------------ + // Killing + + public void redstonePowerUpdate(boolean power) { + if (!isMerged()) + return; + + if ((isPowered && !power) || (!isPowered && power)) { + isPowered = power; + + if (isPowered && stargateState.idle() && !isBroken()) + beginOpening(); + + else if (!isPowered && stargateState.initiating()) { + attemptClose(StargateClosedReasonEnum.REQUESTED); + } + + markDirty(); + } + } + + public void beginOpening() { + if (world.provider.getDimensionType() != DimensionType.OVERWORLD) { + JSGSoundHelper.playSoundEvent(world, getGateCenterPos(), SoundEventEnum.GATE_ORLIN_FAIL); + return; + } + updateNetherAddress(); + if (isBroken()) return; + switch (checkAddressAndEnergy(dialedAddress)) { + case OK: + stargateState = EnumStargateState.DIALING; + + startSparks(); + JSGSoundHelper.playSoundEvent(world, getGateCenterPos(), SoundEventEnum.GATE_ORLIN_DIAL); + + addTask(new ScheduledTask(EnumScheduledTask.STARGATE_ORLIN_OPEN)); + return; + + case ADDRESS_MALFORMED: + if (!world.isRemote && world.provider.getDimensionType() == DimensionType.OVERWORLD) { + StargateNetwork.generateNetherGate(network, world, pos); + JSG.info("Orlin gate requested building of new nether gate... Build started..."); + } + beginOpening(); + //JSG.error("Orlin's gate: wrong dialed address"); + break; + + case NOT_ENOUGH_POWER: + //JSG.info("Orlin's gate: Not enough power"); + break; + + case ABORTED: + case ABORTED_BY_EVENT: + case CALLER_HUNG_UP: + break; + } + } + + @Override + public StargateAbstractMergeHelper getMergeHelper() { + return StargateOrlinMergeHelper.INSTANCE; + } + + + // ------------------------------------------------------------------------ + // Rendering + + @Override + protected JSGAxisAlignedBB getHorizonKillingBox(boolean server) { + return new JSGAxisAlignedBB(-0.5, 1, -0.5, 0.5, 2, 1.5); + } + + @Override + protected int getHorizonSegmentCount(boolean server) { + return 2; + } + + @Override + protected List getGateVaporizingBoxes(boolean server) { + return Collections.singletonList(new JSGAxisAlignedBB(-0.5, 1, -0.5, 0.5, 2, 0.5)); + } + + + // ------------------------------------------------------------------------ + // Sounds + + @Override + protected JSGAxisAlignedBB getHorizonTeleportBox(boolean server) { + return new JSGAxisAlignedBB(-1.0, 0.6, -0.15, 1.0, 2.7, -0.05); + } + + @Override + protected StargateAbstractRendererState createRendererStateClient() { + return new StargateOrlinRendererState(); + } + + + // ------------------------------------------------------------------------ + // States + + @Override + public StargateOrlinRendererState getRendererStateClient() { + return (StargateOrlinRendererState) super.getRendererStateClient(); + } + + @Override + protected SoundPositionedEnum getPositionedSound(StargateSoundPositionedEnum soundEnum) { + return null; + } + + + // ------------------------------------------------------------------------ + // Sparks + + @Override + protected SoundEventEnum getSoundEvent(StargateSoundEventEnum soundEnum) { + switch (soundEnum) { + case OPEN: + return SoundEventEnum.GATE_MILKYWAY_OPEN; + case CLOSE: + return SoundEventEnum.GATE_MILKYWAY_CLOSE; + case DIAL_FAILED: + return SoundEventEnum.GATE_ORLIN_FAIL; + case GATE_BROKE: + return SoundEventEnum.GATE_ORLIN_BROKE; + default: + return null; + } + } + + @Override + public State createState(StateTypeEnum stateType) { + if (stateType == StateTypeEnum.SPARK_STATE) { + return new StargateOrlinSparkState(); + } + return super.createState(stateType); + } + + + // ------------------------------------------------------------------------ + // Scheduled tasks + + @Override + @SideOnly(Side.CLIENT) + public void setState(StateTypeEnum stateType, State state) { + if (stateType == StateTypeEnum.SPARK_STATE) { + if (getRendererStateClient() == null) return; + StargateOrlinSparkState sparkState = (StargateOrlinSparkState) state; + getRendererStateClient().sparkFrom(sparkState.sparkIndex, sparkState.spartStart); + } else { + super.setState(stateType, state); + } + } + + + // ------------------------------------------------------------------------ + // Power + + public void startSparks() { + sparkIndex = 0; + + addTask(new ScheduledTask(EnumScheduledTask.STARGATE_ORLIN_SPARK, 5)); + } + + @Override + public void executeTask(EnumScheduledTask scheduledTask, NBTTagCompound customData) { + switch (scheduledTask) { + case STARGATE_ORLIN_OPEN: + StargatePos targetGatePos = network.getStargate(dialedAddress); + + if (hasEnergyToDial(targetGatePos) && targetGatePos != null && targetGatePos.getTileEntity() != null) { + targetGatePos.getTileEntity().incomingWormhole(dialedAddress.size()); + } + + attemptOpenAndFail(); + break; + + case STARGATE_ORLIN_SPARK: + JSGPacketHandler.INSTANCE.sendToAllTracking(new StateUpdatePacketToClient(pos, StateTypeEnum.SPARK_STATE, new StargateOrlinSparkState(sparkIndex, world.getTotalWorldTime())), targetPoint); + + if (sparkIndex < 6 && sparkIndex != -1) + addTask(new ScheduledTask(EnumScheduledTask.STARGATE_ORLIN_SPARK, 24)); + + sparkIndex++; + + break; + + case STARGATE_FAILED_SOUND: + playSoundEvent(StargateSoundEventEnum.DIAL_FAILED); + + break; + + case STARGATE_ORLIN_BROKE_SOUND: + playSoundEvent(StargateSoundEventEnum.GATE_BROKE); + + break; + + default: + super.executeTask(scheduledTask, customData); + break; + } + } + + @Override + protected SmallEnergyStorage getEnergyStorage() { + return energyStorage; + } + + @Override + protected EnergyRequiredToOperate getEnergyRequiredToDial(StargatePos targetGatePos) { + return super.getEnergyRequiredToDial(targetGatePos).mul(JSGConfig.Stargate.power.stargateOrlinEnergyMul).cap(JSGConfig.Stargate.power.stargateEnergyStorage / 4 - 1000000); + } + + @Override + protected JSGAxisAlignedBB getRenderBoundingBoxRaw() { + return RENDER_BOX; + } + + // ------------------------------------------------------------------------ + // NBT + + @Override + public NBTTagCompound writeToNBT(NBTTagCompound compound) { + compound.setBoolean("isPowered", isPowered); + compound.setInteger("openCount", openCount); + compound.setBoolean("canNotGenerate", canNotGenerate); + + return super.writeToNBT(compound); + } + + @Override + public void readFromNBT(NBTTagCompound compound) { + isPowered = compound.getBoolean("isPowered"); + openCount = compound.getInteger("openCount"); + canNotGenerate = compound.getBoolean("canNotGenerate"); + + super.readFromNBT(compound); + } + + @Optional.Method(modid = "opencomputers") + @Callback + @SuppressWarnings("unused") + public Object[] getGateType(Context context, Arguments args) { + return new Object[]{isMerged() ? "ORLIN" : null}; + } + + @Optional.Method(modid = "opencomputers") + @Callback(doc = "function() -- Tries to open the gate") + @SuppressWarnings("unused") + public Object[] engageGate(Context context, Arguments args) { + if (!isMerged()) return new Object[]{null, "stargate_failure_not_merged", "Stargate is not merged"}; + + if (stargateState.idle()) { + if (!isBroken()) { + beginOpening(); + return new Object[]{null, "stargate_engage"}; + } else { + return new Object[]{null, "stargate_failure_opening", "Stargate is broken"}; + } + } else { + return new Object[]{null, "stargate_failure_busy", "Stargate is busy", stargateState.toString()}; + } + } + + @Optional.Method(modid = "opencomputers") + @Callback(doc = "function() -- Tries to close the gate") + @SuppressWarnings("unused") + public Object[] disengageGate(Context context, Arguments args) { + if (!isMerged()) return new Object[]{null, "stargate_failure_not_merged", "Stargate is not merged"}; + + if (stargateState.engaged()) { + if (getStargateState().initiating()) { + attemptClose(StargateClosedReasonEnum.REQUESTED); + return new Object[]{"stargate_disengage"}; + } else return new Object[]{null, "stargate_failure_wrong_end", "Unable to close the gate on this end"}; + } else { + return new Object[]{null, "stargate_failure_not_open", "The gate is closed"}; + } + } }