diff --git a/src/main/java/tauri/dev/jsg/block/energy/ZPMBlock.java b/src/main/java/tauri/dev/jsg/block/energy/ZPMBlock.java index 3e7c0a96..973d2d2f 100644 --- a/src/main/java/tauri/dev/jsg/block/energy/ZPMBlock.java +++ b/src/main/java/tauri/dev/jsg/block/energy/ZPMBlock.java @@ -22,6 +22,7 @@ import tauri.dev.jsg.item.energy.ZPMItemBlock; import tauri.dev.jsg.power.zpm.IEnergyStorageZPM; import tauri.dev.jsg.power.zpm.ZPMEnergyStorage; +import tauri.dev.jsg.power.zpm.ZPMItemEnergyStorage; import tauri.dev.jsg.renderer.zpm.ZPMRenderer; import tauri.dev.jsg.tileentity.energy.ZPMTile; @@ -69,7 +70,7 @@ public List getDrops(IBlockAccess world, @Nonnull BlockPos pos, @Nonn ZPMEnergyStorage capacitorEnergyStorage = (ZPMEnergyStorage) world.getTileEntity(pos).getCapability(CapabilityEnergyZPM.ENERGY, null); ItemStack stack = new ItemStack(this); - ((ZPMEnergyStorage) stack.getCapability(CapabilityEnergyZPM.ENERGY, null)).setEnergyStored(capacitorEnergyStorage.getEnergyStored()); + ((ZPMItemEnergyStorage) stack.getCapability(CapabilityEnergyZPM.ENERGY, null)).setEnergyStored(capacitorEnergyStorage.getEnergyStored()); return Collections.singletonList(stack); } 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 e0f3a44d..f43d1f6b 100644 --- a/src/main/java/tauri/dev/jsg/gui/admincontroller/AddressesSection.java +++ b/src/main/java/tauri/dev/jsg/gui/admincontroller/AddressesSection.java @@ -15,7 +15,7 @@ import tauri.dev.jsg.stargate.network.StargateAddress; import tauri.dev.jsg.stargate.network.StargateAddressDynamic; import tauri.dev.jsg.stargate.network.StargatePos; -import tauri.dev.jsg.tileentity.stargate.StargateAbstractBaseTile; +import tauri.dev.jsg.stargate.network.SymbolTypeEnum; import tauri.dev.jsg.util.BlockHelpers; import java.util.*; @@ -52,6 +52,16 @@ public void generateAddressEntries() { e.address = a; entries.add(e); } + + Map> notGeneratedMap = guiBase.stargateNetwork.getMapNotGenerated(); + for (StargatePos pos : notGeneratedMap.keySet()) { + StargateEntry e = new StargateEntry(); + e.pos = pos; + e.address = notGeneratedMap.get(pos).get(Objects.requireNonNull(guiBase.gateTile).getSymbolType()); + e.notGenerated = true; + e.defaultName = "[NOT GENERATED GATE] "; + entries.add(e); + } sortEntries(); } @@ -70,8 +80,13 @@ public void generateAddressEntriesBoxes(boolean reset) { StargatePos p = e.pos; String name = (p.getName() != null && !p.getName().equalsIgnoreCase("") ? p.getName() : BlockHelpers.blockPosToBetterString(p.gatePos)); final int finalIndex = index; - GuiTextField field = new JSGTextField(index, Minecraft.getMinecraft().fontRenderer, guiLeft, 0, 120, 20, name).setActionCallback(() -> renameEntry(finalIndex)); - field.setText(name); + JSGTextField field = new JSGTextField(index, Minecraft.getMinecraft().fontRenderer, guiLeft, 0, 120, 20, e.defaultName + name); + field.setText(e.defaultName + name); + if (!e.notGenerated) { + field.setActionCallback(() -> renameEntry(finalIndex)); + } 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)); if (e.pos.gatePos.equals(Objects.requireNonNull(guiBase.gateTile).getPos()) && e.pos.dimensionID == guiBase.gateTile.world().provider.getDimension()) { btn.setEnabled(false); @@ -87,13 +102,12 @@ public void generateAddressEntriesBoxes(boolean reset) { public void sortEntries() { ArrayList newList = new ArrayList<>(); for (StargateEntry e : entries) { - if (e.pos.getName() != null && !e.pos.getName().equals("")) + if (!e.pos.getName().equals("")) newList.add(e); } for (StargateEntry e : entries) { - if (e.pos.getName() != null && !e.pos.getName().equals("")) - continue; - newList.add(e); + if (e.pos.getName().equals("")) + newList.add(e); } entries = newList; } @@ -103,14 +117,27 @@ public void dialGate(int index) { EnumHand hand = guiBase.getHand(); StargateEntry entry = entries.get(index); StargatePos pos = entry.pos; - StargateAbstractBaseTile tile = pos.getTileEntity(); - if (!tile.getStargateState().idle() && !tile.getStargateState().engaged()) return; + 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()){ + guiBase.notifer.setText("Stargate is busy!", Notifier.EnumAlertType.WARNING, 5); + return; + } + + 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); 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) { - JSG.error(e); + } + catch (Exception e){ + JSG.error("Error ", e); + guiBase.notifer.setText("Unknown error! (" + e.getMessage() + ")", Notifier.EnumAlertType.ERROR, 5); } } @@ -119,9 +146,10 @@ public void renameEntry(int index) { EnumHand hand = guiBase.getHand(); GuiTextField field = entriesTextFields.get(index); JSGPacketHandler.INSTANCE.sendToServer(new EntryActionToServer(hand, field.getText(), entries.get(index).pos)); - //entries.get(index).pos.getTileEntity().renameStargatePos(field.getText()); + guiBase.notifer.setText("Gate renamed to " + field.getText(), Notifier.EnumAlertType.INFO, 5); } catch (Exception e) { JSG.error(e); + guiBase.notifer.setText("Unknown error! (" + e.getMessage() + ")", Notifier.EnumAlertType.ERROR, 5); } } @@ -156,16 +184,16 @@ public void renderFg() { for (GuiTextField f : entriesTextFields) { StargateEntry e = entries.get(f.getId()); if (!canNotRenderEntry(f.y) && GuiHelper.isPointInRegion(f.x, f.y, f.width, f.height, guiBase.mouseX, guiBase.mouseY)) { - guiBase.drawHoveringText(Arrays.asList( + Util.drawHoveringText(Arrays.asList( "Type: " + e.pos.getGateSymbolType().toString(), "Pos: " + e.pos.gatePos.toString(), "Dim: " + e.pos.dimensionID + " (" + DimensionManager.getProviderType(e.pos.dimensionID).getName() + ")" - ), guiBase.mouseX, guiBase.mouseY); + ), guiBase.mouseX, guiBase.mouseY, guiBase.width, guiBase.height, -1, guiBase.mc.fontRenderer); } } for (ArrowButton f : dialButtons) { if (!canNotRenderEntry(f.y) && f.enabled && GuiHelper.isPointInRegion(f.x, f.y, f.width, f.height, guiBase.mouseX, guiBase.mouseY)) { - guiBase.drawHoveringText(Collections.singletonList("Dial this address"), guiBase.mouseX, guiBase.mouseY); + Util.drawHoveringText(Collections.singletonList("Dial this address"), guiBase.mouseX, guiBase.mouseY, guiBase.width, guiBase.height, -1, guiBase.mc.fontRenderer); } } } 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 9d1a6d0d..1bf69da2 100644 --- a/src/main/java/tauri/dev/jsg/gui/admincontroller/GuiAdminController.java +++ b/src/main/java/tauri/dev/jsg/gui/admincontroller/GuiAdminController.java @@ -55,6 +55,8 @@ public class GuiAdminController extends JSGTexturedGui { public int guiRight; public int guiBottom; + public Notifier notifer = new Notifier(); + public GuiAdminController(EntityPlayer player, World world, BlockPos pos, StargateNetwork stargateNetwork) { super(512, 256, 512, 256); this.world = world; @@ -121,7 +123,7 @@ public void renderStargate() { GlStateManager.enableAlpha(); GlStateManager.color(1, 1, 1); - GlStateManager.translate(gateCenter[0], gateCenter[1], 0); + GlStateManager.translate(gateCenter[0], gateCenter[1], 1); GlStateManager.scale(-17, -17, -17); GlStateManager.pushMatrix(); @@ -184,15 +186,21 @@ public void drawForeground(int mouseX, int mouseY, float partialTicks) { renderControlButtons(); renderGateInfo(); + notifer.render(this, 117, 4); + // Render foreground + GlStateManager.pushMatrix(); GlStateManager.enableDepth(); + GlStateManager.pushMatrix(); GlStateManager.translate(0, 0, 180); addressesSection.renderFg(); - GlStateManager.translate(0, 0, -180); + GlStateManager.popMatrix(); // render gate model // Should be last renderStargate(); + GlStateManager.disableDepth(); + GlStateManager.popMatrix(); } @Override diff --git a/src/main/java/tauri/dev/jsg/gui/admincontroller/Notifier.java b/src/main/java/tauri/dev/jsg/gui/admincontroller/Notifier.java new file mode 100644 index 00000000..11f5ddcf --- /dev/null +++ b/src/main/java/tauri/dev/jsg/gui/admincontroller/Notifier.java @@ -0,0 +1,40 @@ +package tauri.dev.jsg.gui.admincontroller; + +import tauri.dev.jsg.util.JSGMinecraftHelper; + +import javax.annotation.Nonnull; + +@SuppressWarnings("all") +public class Notifier { + private String lastText = null; + private int color = 0x202020; + private long lastTextEntered = 0; + private int showSeconds = 0; + + public enum EnumAlertType{ + INFO(0x21CEB7), + WARNING(0xCEA021), + ERROR(0xCE2121); + + private final int color; + EnumAlertType(int color){ + this.color = color; + } + } + + public void clearText(){ + this.lastText = null; + } + + public void setText(@Nonnull String text, @Nonnull EnumAlertType type, int secondsToShow){ + lastTextEntered = JSGMinecraftHelper.getClientTick(); + showSeconds = secondsToShow; + lastText = text; + color = type.color; + } + + public void render(GuiAdminController baseGui, int x, int y){ + if((JSGMinecraftHelper.getClientTick() - lastTextEntered) > (showSeconds * 20L) || lastText == null) return; + baseGui.drawString(baseGui.mc.fontRenderer, lastText, x, y, color); + } +} diff --git a/src/main/java/tauri/dev/jsg/gui/admincontroller/StargateEntry.java b/src/main/java/tauri/dev/jsg/gui/admincontroller/StargateEntry.java index 5fffa3b4..4b6d5caf 100644 --- a/src/main/java/tauri/dev/jsg/gui/admincontroller/StargateEntry.java +++ b/src/main/java/tauri/dev/jsg/gui/admincontroller/StargateEntry.java @@ -6,4 +6,7 @@ public class StargateEntry { public StargatePos pos; public StargateAddress address; + + public boolean notGenerated = false; + public String defaultName = ""; } diff --git a/src/main/java/tauri/dev/jsg/gui/admincontroller/Util.java b/src/main/java/tauri/dev/jsg/gui/admincontroller/Util.java new file mode 100644 index 00000000..7376eb7c --- /dev/null +++ b/src/main/java/tauri/dev/jsg/gui/admincontroller/Util.java @@ -0,0 +1,130 @@ +package tauri.dev.jsg.gui.admincontroller; + +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.RenderHelper; + +import java.util.ArrayList; +import java.util.List; + +import static net.minecraftforge.fml.client.config.GuiUtils.drawGradientRect; + +public class Util { + /** + * Method grabbed from {@link net.minecraftforge.fml.client.config.GuiUtils} + */ + public static void drawHoveringText(List textLines, int mouseX, int mouseY, int screenWidth, int screenHeight, int maxTextWidth, FontRenderer font) { + if (!textLines.isEmpty()) { + GlStateManager.disableRescaleNormal(); + RenderHelper.disableStandardItemLighting(); + GlStateManager.disableLighting(); + int tooltipTextWidth = 0; + + for (String textLine : textLines) { + int textLineWidth = font.getStringWidth(textLine); + + if (textLineWidth > tooltipTextWidth) { + tooltipTextWidth = textLineWidth; + } + } + + boolean needsWrap = false; + + int titleLinesCount = 1; + int tooltipX = mouseX + 12; + if (tooltipX + tooltipTextWidth + 4 > screenWidth) { + tooltipX = mouseX - 16 - tooltipTextWidth; + if (tooltipX < 4) // if the tooltip doesn't fit on the screen + { + if (mouseX > screenWidth / 2) { + tooltipTextWidth = mouseX - 12 - 8; + } else { + tooltipTextWidth = screenWidth - 16 - mouseX; + } + needsWrap = true; + } + } + + if (maxTextWidth > 0 && tooltipTextWidth > maxTextWidth) { + tooltipTextWidth = maxTextWidth; + needsWrap = true; + } + + if (needsWrap) { + int wrappedTooltipWidth = 0; + List wrappedTextLines = new ArrayList<>(); + for (int i = 0; i < textLines.size(); i++) { + String textLine = textLines.get(i); + List wrappedLine = font.listFormattedStringToWidth(textLine, tooltipTextWidth); + if (i == 0) { + titleLinesCount = wrappedLine.size(); + } + + for (String line : wrappedLine) { + int lineWidth = font.getStringWidth(line); + if (lineWidth > wrappedTooltipWidth) { + wrappedTooltipWidth = lineWidth; + } + wrappedTextLines.add(line); + } + } + tooltipTextWidth = wrappedTooltipWidth; + textLines = wrappedTextLines; + + if (mouseX > screenWidth / 2) { + tooltipX = mouseX - 16 - tooltipTextWidth; + } else { + tooltipX = mouseX + 12; + } + } + + int tooltipY = mouseY - 12; + int tooltipHeight = 8; + + if (textLines.size() > 1) { + tooltipHeight += (textLines.size() - 1) * 10; + if (textLines.size() > titleLinesCount) { + tooltipHeight += 2; // gap between title lines and next lines + } + } + + if (tooltipY < 4) { + tooltipY = 4; + } else if (tooltipY + tooltipHeight + 4 > screenHeight) { + tooltipY = screenHeight - tooltipHeight - 4; + } + + final int zLevel = 300; + int backgroundColor = 0xF0100010; + int borderColorStart = 0x505000FF; + int borderColorEnd = (borderColorStart & 0xFEFEFE) >> 1 | borderColorStart & 0xFF000000; + drawGradientRect(zLevel, tooltipX - 3, tooltipY - 4, tooltipX + tooltipTextWidth + 3, tooltipY - 3, backgroundColor, backgroundColor); + drawGradientRect(zLevel, tooltipX - 3, tooltipY + tooltipHeight + 3, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 4, backgroundColor, backgroundColor); + drawGradientRect(zLevel, tooltipX - 3, tooltipY - 3, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3, backgroundColor, backgroundColor); + drawGradientRect(zLevel, tooltipX - 4, tooltipY - 3, tooltipX - 3, tooltipY + tooltipHeight + 3, backgroundColor, backgroundColor); + drawGradientRect(zLevel, tooltipX + tooltipTextWidth + 3, tooltipY - 3, tooltipX + tooltipTextWidth + 4, tooltipY + tooltipHeight + 3, backgroundColor, backgroundColor); + drawGradientRect(zLevel, tooltipX - 3, tooltipY - 3 + 1, tooltipX - 3 + 1, tooltipY + tooltipHeight + 3 - 1, borderColorStart, borderColorEnd); + drawGradientRect(zLevel, tooltipX + tooltipTextWidth + 2, tooltipY - 3 + 1, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3 - 1, borderColorStart, borderColorEnd); + drawGradientRect(zLevel, tooltipX - 3, tooltipY - 3, tooltipX + tooltipTextWidth + 3, tooltipY - 3 + 1, borderColorStart, borderColorStart); + drawGradientRect(zLevel, tooltipX - 3, tooltipY + tooltipHeight + 2, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3, borderColorEnd, borderColorEnd); + + GlStateManager.pushMatrix(); + GlStateManager.translate(0, 0, zLevel + 5); + for (int lineNumber = 0; lineNumber < textLines.size(); ++lineNumber) { + String line = textLines.get(lineNumber); + font.drawStringWithShadow(line, (float) tooltipX, (float) tooltipY, -1); + + if (lineNumber + 1 == titleLinesCount) { + tooltipY += 2; + } + + tooltipY += 10; + } + GlStateManager.popMatrix(); + + GlStateManager.enableLighting(); + RenderHelper.enableStandardItemLighting(); + GlStateManager.enableRescaleNormal(); + } + } +} diff --git a/src/main/java/tauri/dev/jsg/item/linkable/dialer/UniverseDialerItem.java b/src/main/java/tauri/dev/jsg/item/linkable/dialer/UniverseDialerItem.java index 7c988028..e6e33cb8 100644 --- a/src/main/java/tauri/dev/jsg/item/linkable/dialer/UniverseDialerItem.java +++ b/src/main/java/tauri/dev/jsg/item/linkable/dialer/UniverseDialerItem.java @@ -419,7 +419,7 @@ public ActionResult onItemRightClick(World world, @Nonnull EntityPlay int symbolsNeeded = (sameType ? (sameDim ? 6 : 7) : 8); maxSymbols = Math.min(symbolsNeeded, maxSymbols); }*/ - gateTile.dialAddress(address, maxSymbols); + gateTile.dialAddress(address, maxSymbols, false); player.sendStatusMessage(new TextComponentTranslation("item.jsg.universe_dialer.dial_start"), true); if(player instanceof EntityPlayerMP) JSGSoundHelper.playSoundToPlayer(((EntityPlayerMP) player), SoundEventEnum.UNIVERSE_DIALER_START_DIAL, player.getPosition()); diff --git a/src/main/java/tauri/dev/jsg/item/notebook/PageNotebookItem.java b/src/main/java/tauri/dev/jsg/item/notebook/PageNotebookItem.java index e36fd068..ac7c3629 100644 --- a/src/main/java/tauri/dev/jsg/item/notebook/PageNotebookItem.java +++ b/src/main/java/tauri/dev/jsg/item/notebook/PageNotebookItem.java @@ -1,14 +1,5 @@ package tauri.dev.jsg.item.notebook; -import tauri.dev.jsg.JSG; -import tauri.dev.jsg.creativetabs.JSGCreativeTabsHandler; -import tauri.dev.jsg.item.renderer.CustomModel; -import tauri.dev.jsg.item.renderer.CustomModelItemInterface; -import tauri.dev.jsg.stargate.network.StargateAddress; -import tauri.dev.jsg.stargate.network.SymbolMilkyWayEnum; -import tauri.dev.jsg.stargate.network.SymbolTypeEnum; -import tauri.dev.jsg.transportrings.SymbolTypeTransportRingsEnum; -import tauri.dev.jsg.transportrings.TransportRingsAddress; import net.minecraft.client.renderer.block.model.IBakedModel; import net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType; import net.minecraft.client.renderer.block.model.ModelResourceLocation; @@ -24,11 +15,17 @@ import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import tauri.dev.jsg.JSG; +import tauri.dev.jsg.creativetabs.JSGCreativeTabsHandler; +import tauri.dev.jsg.item.renderer.CustomModel; +import tauri.dev.jsg.item.renderer.CustomModelItemInterface; +import tauri.dev.jsg.stargate.network.StargateAddress; +import tauri.dev.jsg.stargate.network.SymbolTypeEnum; +import tauri.dev.jsg.transportrings.SymbolTypeTransportRingsEnum; +import tauri.dev.jsg.transportrings.TransportRingsAddress; import java.util.List; -import static tauri.dev.jsg.tileentity.stargate.StargateClassicBaseTile.ConfigOptions.ORIGIN_MODEL; - public class PageNotebookItem extends Item implements CustomModelItemInterface { public static final String ITEM_NAME = "page_notebook"; @@ -139,12 +136,17 @@ public static String getRegistryPathFromWorld(World world, BlockPos pos) { } public static NBTTagCompound getCompoundFromAddress(StargateAddress address, boolean hasUpgrade, String registryPath, int originId) { + return getCompoundFromAddress(address, hasUpgrade, false, false, registryPath, originId); + } + public static NBTTagCompound getCompoundFromAddress(StargateAddress address, boolean hasUpgrade, boolean hideLastSymbol, boolean hideOrigin, String registryPath, int originId) { NBTTagCompound compound = new NBTTagCompound(); if(address != null) { if (address.getSymbolType() != null) compound.setInteger("symbolType", address.getSymbolType().id); if (address.serializeNBT() != null) compound.setTag("address", address.serializeNBT()); } compound.setBoolean("hasUpgrade", hasUpgrade); + compound.setBoolean("hideLastSymbol", hideLastSymbol); + compound.setBoolean("hideOrigin", hideOrigin); compound.setInteger("color", PageNotebookItem.getColorForBiome(registryPath)); compound.setInteger("originId", originId); diff --git a/src/main/java/tauri/dev/jsg/item/notebook/PageRenderer.java b/src/main/java/tauri/dev/jsg/item/notebook/PageRenderer.java index 8abdfb88..a2cbf252 100644 --- a/src/main/java/tauri/dev/jsg/item/notebook/PageRenderer.java +++ b/src/main/java/tauri/dev/jsg/item/notebook/PageRenderer.java @@ -1,23 +1,21 @@ package tauri.dev.jsg.item.notebook; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumHandSide; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.opengl.GL11; import tauri.dev.jsg.config.JSGConfig; -import tauri.dev.jsg.item.renderer.JSGFontRenderer; import tauri.dev.jsg.item.renderer.ItemRenderHelper; -import tauri.dev.jsg.loader.ElementEnum; +import tauri.dev.jsg.item.renderer.JSGFontRenderer; import tauri.dev.jsg.loader.texture.TextureLoader; -import tauri.dev.jsg.renderer.biomes.BiomeOverlayEnum; import tauri.dev.jsg.stargate.network.StargateAddress; import tauri.dev.jsg.stargate.network.SymbolInterface; import tauri.dev.jsg.stargate.network.SymbolTypeEnum; import tauri.dev.jsg.transportrings.SymbolTypeTransportRingsEnum; import tauri.dev.jsg.transportrings.TransportRingsAddress; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.EnumHandSide; -import net.minecraft.util.ResourceLocation; -import org.lwjgl.opengl.GL11; import java.util.Objects; @@ -84,11 +82,16 @@ public static void renderByCompound(TransformType lastTransform, NBTTagCompound StargateAddress stargateAddress = new StargateAddress(compound.getCompoundTag("address")); int maxSymbols = symbolType.getMaxSymbolsDisplay(compound.getBoolean("hasUpgrade")); + boolean hideLastSymbol = compound.hasKey("hideLastSymbol") && compound.getBoolean("hideLastSymbol"); + boolean hideOrigin = compound.hasKey("hideOrigin") && compound.getBoolean("hideOrigin"); + int originId = 0; if(compound.hasKey("originId")) originId = compound.getInteger("originId"); for (int i=0; i> getMapNotGenerated return notGeneratedStargates; } + @Nullable + public Map.Entry> getRandomNotGeneratedStargate(){ + if (!JSGConfig.WorldGen.otherDimGenerator.generatorEnabled) + return null; + int size = notGeneratedStargates.size(); + if(size < 1) return null; + int index = (int) (Math.random() * size); + int i = 0; + for(Map.Entry> map : notGeneratedStargates.entrySet()){ + if(i == index) return map; + i++; + } + return null; + } + @Nullable public StargatePos getStargatePosFromAddressNotGenerated(StargateAddressDynamic address) { for (StargatePos pos : notGeneratedStargates.keySet()) { @@ -128,6 +143,16 @@ public void checkAndGenerateStargate(StargateAddressDynamic address) { int id = pos.dimensionID; BlockPos bp = pos.gatePos; EnumStructures structure = EnumStructures.INTERNAL_MW; + switch(pos.symbolType){ + default: + break; + case PEGASUS: + structure = EnumStructures.INTERNAL_PG; + break; + case UNIVERSE: + structure = EnumStructures.INTERNAL_UNI; + break; + } GeneratedStargate gs = StargateGenerator.mystPageGeneration(pos.getWorld(), structure, id, bp); if (gs == null) return; Objects.requireNonNull(this.getStargate(gs.address)).getTileEntity().setGateAddress(address.symbolType, notGeneratedStargates.get(pos).get(address.symbolType)); @@ -145,8 +170,18 @@ public void addStargate(StargateAddress gateAddress, StargatePos stargatePos) { public void addNotGeneratedStargate(StargateAddress gateAddress, StargatePos stargatePos) { if (gateAddress == null) return; - notGeneratedStargates.putIfAbsent(stargatePos, new HashMap<>()); - notGeneratedStargates.get(stargatePos).put(gateAddress.symbolType, gateAddress); + Map map = null; + for(StargatePos p : notGeneratedStargates.keySet()){ + if(p.dimensionID == stargatePos.dimensionID){ + map = notGeneratedStargates.get(p); + break; + } + } + if(map == null){ + notGeneratedStargates.put(stargatePos, new HashMap<>()); + map = notGeneratedStargates.get(stargatePos); + } + map.put(gateAddress.symbolType, gateAddress); markDirty(); } @@ -227,7 +262,6 @@ public void readFromNBT(NBTTagCompound compound) { StargateAddress stargateAddress = new StargateAddress(stargateCompound.getCompoundTag("address")); StargatePos stargatePos = new StargatePos(stargateAddress.getSymbolType(), stargateCompound.getCompoundTag("pos")); - stargatePos.setName(stargateCompound.getString("stargateName")); if (JSGConfigUtil.isDimBlacklistedForSGSpawn(stargatePos.dimensionID)) continue; @@ -259,8 +293,6 @@ public NBTTagCompound writeToNBT(@Nonnull NBTTagCompound compound) { NBTTagCompound stargateCompound = new NBTTagCompound(); stargateCompound.setTag("address", stargateEntry.getKey().serializeNBT()); stargateCompound.setTag("pos", stargateEntry.getValue().serializeNBT()); - stargateCompound.setString("stargateName", stargateEntry.getValue().getName()); - JSG.info("Saving " + stargateEntry.getValue().toString()); stargateTagList.appendTag(stargateCompound); } } diff --git a/src/main/java/tauri/dev/jsg/stargate/network/StargatePos.java b/src/main/java/tauri/dev/jsg/stargate/network/StargatePos.java index bdd9d3b1..41f62cc9 100644 --- a/src/main/java/tauri/dev/jsg/stargate/network/StargatePos.java +++ b/src/main/java/tauri/dev/jsg/stargate/network/StargatePos.java @@ -6,7 +6,6 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.common.util.INBTSerializable; -import tauri.dev.jsg.JSG; import tauri.dev.jsg.stargate.teleportation.TeleportHelper; import tauri.dev.jsg.tileentity.stargate.StargateAbstractBaseTile; @@ -15,173 +14,170 @@ import java.util.List; public class StargatePos implements INBTSerializable { - - public int dimensionID; - public BlockPos gatePos; - public SymbolTypeEnum symbolType; - private SymbolTypeEnum gateSymbolType; - public List additionalSymbols; - - private String name; - - public void setName(String name){ - this.name = name; - JSG.info("Changed name: " + name); - } - - public String getName(){ - return (name == null ? "" : name); - } - - public StargatePos(int dimensionID, BlockPos gatePos, StargateAddress stargateAddress, SymbolTypeEnum gateSymbolType) { - this.dimensionID = dimensionID; - this.gatePos = gatePos; - this.gateSymbolType = gateSymbolType; - - this.symbolType = stargateAddress.getSymbolType(); - this.additionalSymbols = new ArrayList<>(2); - this.additionalSymbols.addAll(stargateAddress.getAdditional()); - } - - public StargatePos(SymbolTypeEnum symbolType, NBTTagCompound compound) { - this.symbolType = symbolType; - this.additionalSymbols = new ArrayList<>(2); - - deserializeNBT(compound); - } - - public StargatePos(SymbolTypeEnum symbolType, ByteBuf buf) { - this.symbolType = symbolType; - this.additionalSymbols = new ArrayList<>(2); - - fromBytes(buf); - } - - public SymbolTypeEnum getGateSymbolType(){ - if(gateSymbolType != null) return gateSymbolType; - gateSymbolType = getTileEntity().getSymbolType(); - return gateSymbolType; - } - - public World getWorld() { - return TeleportHelper.getWorld(dimensionID); - } - - public StargateAbstractBaseTile getTileEntity() { - try { - return (StargateAbstractBaseTile) getWorld().getTileEntity(gatePos); - } - - catch (Exception e) { - e.printStackTrace(); - return null; - } - } - - public IBlockState getBlockState() { - return getWorld().getBlockState(gatePos); - } - - @Override - public NBTTagCompound serializeNBT() { - NBTTagCompound compound = new NBTTagCompound(); - - compound.setInteger("dim", dimensionID); - compound.setLong("pos", gatePos.toLong()); - compound.setInteger("last0", additionalSymbols.get(0).getId()); - compound.setInteger("last1", additionalSymbols.get(1).getId()); - compound.setString("stargatePosName", (name == null ? "" : name)); - if(gateSymbolType != null) - compound.setByte("gateSymbolType", (byte) gateSymbolType.id); - - return compound; - } - - @Override - public void deserializeNBT(NBTTagCompound compound) { - dimensionID = compound.getInteger("dim"); - gatePos = BlockPos.fromLong(compound.getLong("pos")); - additionalSymbols.add(symbolType.valueOfSymbol(compound.getInteger("last0"))); - additionalSymbols.add(symbolType.valueOfSymbol(compound.getInteger("last1"))); - name = compound.getString("stargatePosName"); - if(compound.hasKey("gateSymbolType")) - gateSymbolType = SymbolTypeEnum.valueOf(compound.getByte("gateSymbolType")); - else gateSymbolType = symbolType; - } - - public void toBytes(ByteBuf buf){ - buf.writeInt(dimensionID); - buf.writeLong(gatePos.toLong()); - buf.writeInt(additionalSymbols.get(0).getId()); - buf.writeInt(additionalSymbols.get(1).getId()); - if(name != null){ - buf.writeBoolean(true); - buf.writeInt(name.length()); - buf.writeCharSequence(name, StandardCharsets.UTF_8); - }else - buf.writeBoolean(false); - if(gateSymbolType != null){ - buf.writeBoolean(true); - buf.writeInt(gateSymbolType.id); - }else - buf.writeBoolean(false); - } - - public void fromBytes(ByteBuf buf){ - dimensionID = buf.readInt(); - gatePos = BlockPos.fromLong(buf.readLong()); - additionalSymbols.add(symbolType.valueOfSymbol(buf.readInt())); - additionalSymbols.add(symbolType.valueOfSymbol(buf.readInt())); - if(buf.readBoolean()){ - int nameSize = buf.readInt(); - name = buf.readCharSequence(nameSize, StandardCharsets.UTF_8).toString(); - } - if(buf.readBoolean()){ - gateSymbolType = SymbolTypeEnum.valueOf(buf.readInt()); - } - } - - - // --------------------------------------------------------------------------------------------------- - // Hashing - - @Override - public String toString() { - return String.format("[dim=%d, pos=%s, add=%s, name=%s]", dimensionID, gatePos.toString(), additionalSymbols.toString(), getName()); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((additionalSymbols == null) ? 0 : additionalSymbols.hashCode()); - result = prime * result + dimensionID; - result = prime * result + ((gatePos == null) ? 0 : gatePos.hashCode()); - result = prime * result + ((symbolType == null) ? 0 : symbolType.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - StargatePos other = (StargatePos) obj; - if (additionalSymbols == null) { - if (other.additionalSymbols != null) - return false; - } else if (!additionalSymbols.equals(other.additionalSymbols)) - return false; - if (dimensionID != other.dimensionID) - return false; - if (gatePos == null) { - if (other.gatePos != null) - return false; - } else if (!gatePos.equals(other.gatePos)) - return false; - return symbolType == other.symbolType; - } + + public int dimensionID; + public BlockPos gatePos; + public SymbolTypeEnum symbolType; + private SymbolTypeEnum gateSymbolType; + public List additionalSymbols; + + private String name; + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return (name == null ? "" : name); + } + + public StargatePos(int dimensionID, BlockPos gatePos, StargateAddress stargateAddress, SymbolTypeEnum gateSymbolType) { + this.dimensionID = dimensionID; + this.gatePos = gatePos; + this.gateSymbolType = gateSymbolType; + + this.symbolType = stargateAddress.getSymbolType(); + this.additionalSymbols = new ArrayList<>(2); + this.additionalSymbols.addAll(stargateAddress.getAdditional()); + } + + public StargatePos(SymbolTypeEnum symbolType, NBTTagCompound compound) { + this.symbolType = symbolType; + this.additionalSymbols = new ArrayList<>(2); + + deserializeNBT(compound); + } + + public StargatePos(SymbolTypeEnum symbolType, ByteBuf buf) { + this.symbolType = symbolType; + this.additionalSymbols = new ArrayList<>(2); + + fromBytes(buf); + } + + public SymbolTypeEnum getGateSymbolType() { + if (gateSymbolType != null) return gateSymbolType; + gateSymbolType = getTileEntity().getSymbolType(); + return gateSymbolType; + } + + public World getWorld() { + return TeleportHelper.getWorld(dimensionID); + } + + public StargateAbstractBaseTile getTileEntity() { + try { + return (StargateAbstractBaseTile) getWorld().getTileEntity(gatePos); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + public IBlockState getBlockState() { + return getWorld().getBlockState(gatePos); + } + + @Override + public NBTTagCompound serializeNBT() { + NBTTagCompound compound = new NBTTagCompound(); + + compound.setInteger("dim", dimensionID); + compound.setLong("pos", gatePos.toLong()); + compound.setInteger("last0", additionalSymbols.get(0).getId()); + compound.setInteger("last1", additionalSymbols.get(1).getId()); + compound.setString("stargatePosName", (name == null ? "" : name)); + if (gateSymbolType != null) + compound.setByte("gateSymbolType", (byte) gateSymbolType.id); + + return compound; + } + + @Override + public void deserializeNBT(NBTTagCompound compound) { + dimensionID = compound.getInteger("dim"); + gatePos = BlockPos.fromLong(compound.getLong("pos")); + additionalSymbols.add(symbolType.valueOfSymbol(compound.getInteger("last0"))); + additionalSymbols.add(symbolType.valueOfSymbol(compound.getInteger("last1"))); + name = compound.getString("stargatePosName"); + if (compound.hasKey("gateSymbolType")) + gateSymbolType = SymbolTypeEnum.valueOf(compound.getByte("gateSymbolType")); + else gateSymbolType = symbolType; + } + + public void toBytes(ByteBuf buf) { + buf.writeInt(dimensionID); + buf.writeLong(gatePos.toLong()); + buf.writeInt(additionalSymbols.get(0).getId()); + buf.writeInt(additionalSymbols.get(1).getId()); + if (name != null) { + buf.writeBoolean(true); + buf.writeInt(name.length()); + buf.writeCharSequence(name, StandardCharsets.UTF_8); + } else + buf.writeBoolean(false); + if (gateSymbolType != null) { + buf.writeBoolean(true); + buf.writeInt(gateSymbolType.id); + } else + buf.writeBoolean(false); + } + + public void fromBytes(ByteBuf buf) { + dimensionID = buf.readInt(); + gatePos = BlockPos.fromLong(buf.readLong()); + additionalSymbols.add(symbolType.valueOfSymbol(buf.readInt())); + additionalSymbols.add(symbolType.valueOfSymbol(buf.readInt())); + if (buf.readBoolean()) { + int nameSize = buf.readInt(); + name = buf.readCharSequence(nameSize, StandardCharsets.UTF_8).toString(); + } + if (buf.readBoolean()) { + gateSymbolType = SymbolTypeEnum.valueOf(buf.readInt()); + } + } + + + // --------------------------------------------------------------------------------------------------- + // Hashing + + @Override + public String toString() { + return String.format("[dim=%d, pos=%s, add=%s, name=%s]", dimensionID, gatePos.toString(), additionalSymbols.toString(), getName()); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((additionalSymbols == null) ? 0 : additionalSymbols.hashCode()); + result = prime * result + dimensionID; + result = prime * result + ((gatePos == null) ? 0 : gatePos.hashCode()); + result = prime * result + ((symbolType == null) ? 0 : symbolType.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + StargatePos other = (StargatePos) obj; + if (additionalSymbols == null) { + if (other.additionalSymbols != null) + return false; + } else if (!additionalSymbols.equals(other.additionalSymbols)) + return false; + if (dimensionID != other.dimensionID) + return false; + if (gatePos == null) { + if (other.gatePos != null) + return false; + } else if (!gatePos.equals(other.gatePos)) + return false; + return symbolType == other.symbolType; + } } diff --git a/src/main/java/tauri/dev/jsg/stargate/network/SymbolTypeEnum.java b/src/main/java/tauri/dev/jsg/stargate/network/SymbolTypeEnum.java index 5086e033..b459cec7 100644 --- a/src/main/java/tauri/dev/jsg/stargate/network/SymbolTypeEnum.java +++ b/src/main/java/tauri/dev/jsg/stargate/network/SymbolTypeEnum.java @@ -3,6 +3,7 @@ import tauri.dev.jsg.util.EnumKeyInterface; import tauri.dev.jsg.util.EnumKeyMap; +import javax.annotation.Nonnull; import java.util.List; import java.util.Random; @@ -264,4 +265,9 @@ public Integer getKey() { public static SymbolTypeEnum valueOf(int id) { return ID_MAP.valueOf(id); } + + @Nonnull + public static SymbolTypeEnum getRandom(){ + return valueOf((int) (Math.random() * values().length)); + } } diff --git a/src/main/java/tauri/dev/jsg/tileentity/props/DestinyCountDownTile.java b/src/main/java/tauri/dev/jsg/tileentity/props/DestinyCountDownTile.java index bab7175a..9797af3b 100644 --- a/src/main/java/tauri/dev/jsg/tileentity/props/DestinyCountDownTile.java +++ b/src/main/java/tauri/dev/jsg/tileentity/props/DestinyCountDownTile.java @@ -142,7 +142,7 @@ public void update() { StargateAddress foundAddress = found.address; int symbols = (found.symbolsNeeded - 1); if (foundAddress != null) { - gate.dialAddress(foundAddress, symbols); + gate.dialAddress(foundAddress, symbols, false); gateOpenedThisRound = true; markDirty(); } 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 f4a97497..347d12a6 100644 --- a/src/main/java/tauri/dev/jsg/tileentity/stargate/StargateAbstractBaseTile.java +++ b/src/main/java/tauri/dev/jsg/tileentity/stargate/StargateAbstractBaseTile.java @@ -709,6 +709,7 @@ protected void openGate(StargatePos targetGatePos, boolean isInitiating) { * Called either on pressing BRB on open gate or close command from a computer. */ protected void closeGate(StargateClosedReasonEnum reason) { + JSG.error("Test ", new Exception("Test")); stargateState = EnumStargateState.UNSTABLE; energySecondsToClose = 0; resetOpenedSince(); @@ -931,6 +932,13 @@ public boolean getForceUnstable(){ return false; } + public float getSecondsToClose(int energyStored, int morePower){ + if(keepAliveEnergyPerTick <= 0){ + return JSGConfig.Stargate.power.instabilitySeconds + 5; + } + return (energyStored / (float) (keepAliveEnergyPerTick + morePower + shieldKeepAlive) / 20f); + } + @Override public void update() { // Scheduled tasks @@ -1013,11 +1021,10 @@ public void update() { targetGatePos = getNetwork().getStargate(this.getStargateAddress(SymbolTypeEnum.MILKYWAY)); attemptClose(StargateClosedReasonEnum.CONNECTION_LOST); } - int energyStored = getEnergyStorage().getEnergyStored(); // Max Open Time int morePower = doTimeLimitFunc(); - energySecondsToClose = energyStored / (float) (keepAliveEnergyPerTick + morePower + shieldKeepAlive) / 20f; + energySecondsToClose = getSecondsToClose(getEnergyStorage().getEnergyStored(), morePower); if (energySecondsToClose >= 1) { 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 6607a6bc..3451642b 100644 --- a/src/main/java/tauri/dev/jsg/tileentity/stargate/StargateClassicBaseTile.java +++ b/src/main/java/tauri/dev/jsg/tileentity/stargate/StargateClassicBaseTile.java @@ -265,6 +265,8 @@ public void closeGate(StargateClosedReasonEnum reason) { if (world.getTileEntity(beamerPos) != null) ((BeamerTile) Objects.requireNonNull(world.getTileEntity(beamerPos))).gateClosed(); } + dialingWithoutEnergy = false; + markDirty(); } @Override @@ -276,6 +278,9 @@ protected void disconnectGate() { if (codeSender != null) codeSender = null; updateChevronLight(0, false); sendRenderingUpdate(StargateRendererActionState.EnumGateAction.CLEAR_CHEVRONS, dialedAddress.size(), isFinalActive); + + dialingWithoutEnergy = false; + markDirty(); } public boolean isGateBurried() { @@ -298,6 +303,8 @@ protected void failGate() { playPositionedSound(StargateSoundPositionedEnum.GATE_RING_ROLL, false); isFinalActive = false; + dialingWithoutEnergy = false; + markDirty(); if (stargateState != EnumStargateState.INCOMING && !isIncoming) { updateChevronLight(0, false); @@ -325,6 +332,8 @@ public void openGate(StargatePos targetGatePos, boolean isInitiating) { super.openGate(targetGatePos, isInitiating); playPositionedSound(StargateSoundPositionedEnum.GATE_RING_ROLL, false); tryHeatUp(8); + dialingWithoutEnergy = false; + markDirty(); this.isFinalActive = true; } @@ -344,6 +353,7 @@ public boolean abortDialingSequence() { removeTask(lastSpinFinished); failGate(); if (!isIncoming) disconnectGate(); + dialingWithoutEnergy = false; markDirty(); resetTargetIncomingAnimation(); return true; @@ -357,7 +367,19 @@ public void generateIncoming(int entities, int addressSize, int delay) { super.generateIncoming(entities, addressSize, delay); } - public abstract boolean dialAddress(StargateAddress address, int maxSymbols); + public boolean dialingWithoutEnergy = false; + public boolean dialAddress(StargateAddress address, int maxSymbols, boolean withoutEnergy){ + dialingWithoutEnergy = withoutEnergy; + markDirty(); + return true; + } + + @Override + protected EnergyRequiredToOperate getEnergyRequiredToDial(StargatePos targetGatePos) { + if(dialingWithoutEnergy) + return new EnergyRequiredToOperate(0, 0); + return super.getEnergyRequiredToDial(targetGatePos); + } public abstract void addSymbolToAddressDHD(SymbolInterface symbol); diff --git a/src/main/java/tauri/dev/jsg/tileentity/stargate/StargateMilkyWayBaseTile.java b/src/main/java/tauri/dev/jsg/tileentity/stargate/StargateMilkyWayBaseTile.java index 6210ac13..b6be42e8 100644 --- a/src/main/java/tauri/dev/jsg/tileentity/stargate/StargateMilkyWayBaseTile.java +++ b/src/main/java/tauri/dev/jsg/tileentity/stargate/StargateMilkyWayBaseTile.java @@ -149,11 +149,13 @@ public void addSymbolToAddressDHD(SymbolInterface symbol) { @Override protected int getMaxChevrons() { + if(dialingWithoutEnergy) return 9; return isLinkedAndDHDOperational() && stargateState != EnumStargateState.DIALING_COMPUTER && !getLinkedDHD(world).hasUpgrade(DHDUpgradeEnum.CHEVRON_UPGRADE) ? 7 : 9; } - public boolean dialAddress(StargateAddress address, int symbolCount) { + public boolean dialAddress(StargateAddress address, int symbolCount, boolean withoutEnergy) { if (!getStargateState().idle()) return false; + super.dialAddress(address, symbolCount, withoutEnergy); for (int i = 0; i < symbolCount; i++) { addSymbolToAddressUsingList(address.get(i)); } diff --git a/src/main/java/tauri/dev/jsg/tileentity/stargate/StargatePegasusBaseTile.java b/src/main/java/tauri/dev/jsg/tileentity/stargate/StargatePegasusBaseTile.java index 54bbaad6..ad9f21ba 100644 --- a/src/main/java/tauri/dev/jsg/tileentity/stargate/StargatePegasusBaseTile.java +++ b/src/main/java/tauri/dev/jsg/tileentity/stargate/StargatePegasusBaseTile.java @@ -134,6 +134,7 @@ public SymbolTypeEnum getSymbolType() { @Override protected int getMaxChevrons() { + if(dialingWithoutEnergy) return 9; return isLinkedAndDHDOperational() && stargateState != EnumStargateState.DIALING_COMPUTER && !getLinkedDHD(world).hasUpgrade(DHDPegasusTile.DHDUpgradeEnum.CHEVRON_UPGRADE) ? 7 : 9; } @@ -599,8 +600,9 @@ public boolean canAddSymbolToList(SymbolInterface symbol) { } - public boolean dialAddress(StargateAddress address, int symbolCount) { + public boolean dialAddress(StargateAddress address, int symbolCount, boolean withoutEnergy) { if (!getStargateState().idle()) return false; + super.dialAddress(address, symbolCount, withoutEnergy); for (int i = 0; i < symbolCount; i++) { addSymbolToAddressDHD(address.get(i)); } diff --git a/src/main/java/tauri/dev/jsg/tileentity/stargate/StargateUniverseBaseTile.java b/src/main/java/tauri/dev/jsg/tileentity/stargate/StargateUniverseBaseTile.java index 8626f3cc..a1ffe092 100644 --- a/src/main/java/tauri/dev/jsg/tileentity/stargate/StargateUniverseBaseTile.java +++ b/src/main/java/tauri/dev/jsg/tileentity/stargate/StargateUniverseBaseTile.java @@ -159,9 +159,10 @@ public void addSymbolToAddressDHD(SymbolInterface symbol) { * @param address - address to dial * @param symbolCount - symbols to engage */ - public boolean dialAddress(StargateAddress address, int symbolCount) { + public boolean dialAddress(StargateAddress address, int symbolCount, boolean withoutEnergy) { if (!canContinue()) return false; if (!stargateState.idle()) return false; + super.dialAddress(address, symbolCount, withoutEnergy); this.addressToDial = address; this.symbolsToDialCount = symbolCount; diff --git a/src/main/java/tauri/dev/jsg/worldgen/StargateDimensionGenerator.java b/src/main/java/tauri/dev/jsg/worldgen/StargateDimensionGenerator.java index 29636d02..b6d44636 100644 --- a/src/main/java/tauri/dev/jsg/worldgen/StargateDimensionGenerator.java +++ b/src/main/java/tauri/dev/jsg/worldgen/StargateDimensionGenerator.java @@ -11,6 +11,7 @@ import tauri.dev.jsg.stargate.network.StargateNetwork; import tauri.dev.jsg.stargate.network.StargatePos; import tauri.dev.jsg.stargate.network.SymbolTypeEnum; +import tauri.dev.jsg.stargate.teleportation.TeleportHelper; import tauri.dev.jsg.worldgen.util.GeneratedStargate; import javax.annotation.Nonnull; @@ -19,6 +20,7 @@ import java.util.Random; public class StargateDimensionGenerator { + @SuppressWarnings("all") public static void tryGenerate(@Nonnull World worldServer) { if (!JSGConfig.WorldGen.otherDimGenerator.generatorEnabled) { JSG.debug("Skipping dimensions to generate addresses... Disabled in CONFIG"); @@ -26,29 +28,60 @@ public static void tryGenerate(@Nonnull World worldServer) { } JSG.info("Checking dimensions to generate addresses of possible gates there..."); StargateNetwork sgn = StargateNetwork.get(worldServer); - Map> virtualGates = sgn.getMapNotGenerated(); ArrayList dimensionsWithGate = new ArrayList<>(); + Map> virtualGates = sgn.getMapNotGenerated(); + Map sgNetwork = sgn.getMap().get(SymbolTypeEnum.MILKYWAY); for (StargatePos p : virtualGates.keySet()) { dimensionsWithGate.add(p.dimensionID); } + for(StargatePos p : sgNetwork.values()){ + dimensionsWithGate.add(p.dimensionID); + } int i = 0; int y = 0; for (DimensionType t : DimensionManager.getRegisteredDimensions().keySet()) { int id = t.getId(); - if (JSGConfigUtil.isDimBlacklistedForSGSpawn(id)) continue; - if (id == 0 || id == 1 || id == -1) continue; + SymbolTypeEnum symbolType = SymbolTypeEnum.MILKYWAY; + if (JSGConfigUtil.isDimBlacklistedForSGSpawn(id)){ + JSG.debug("Dim " + id + " is blacklisted. Skipping..."); + continue; + } + if (id == 0 || id == 1 || id == -1){ + JSG.debug("Dim " + id + " is internally blacklisted. Skipping..."); + continue; + } i++; - if (dimensionsWithGate.contains(id)) continue; + if (dimensionsWithGate.contains(id)){ + JSG.debug("Dim " + id + " has already gate. Skipping..."); + continue; + } + DimensionType dt = null; try { - DimensionManager.getProviderType(id); + dt = DimensionManager.getProviderType(id); } catch (Exception e) { + JSG.debug("Dim " + id + " has corrupted provider type. Skipping..."); + continue; + } + World world = TeleportHelper.getWorld(id); + if (world == null || world.provider == null){ + JSG.debug("Dim " + id + " has corrupted provider. (Is world null? " + (world == null ? "true" : "false") + ") Skipping..."); continue; } - if (DimensionManager.getWorld(id) == null || DimensionManager.getProvider(id) == null) continue; - if (!DimensionManager.getProvider(id).isSurfaceWorld()) continue; + if (!world.provider.isSurfaceWorld()){ + boolean shouldSkip = true; + if(dt.getName().startsWith("planet")) shouldSkip = false; + if(dt.getName().startsWith("moon")) shouldSkip = false; + + if(dt.getName().contains("asteroids")) shouldSkip = true; + + if(shouldSkip) { + JSG.debug("Dim " + id + " is not surface world. Skipping..."); + continue; + } + } - GeneratedStargate gs = generateAndPutAddresses(sgn, id); + GeneratedStargate gs = generateAndPutAddresses(sgn, id, symbolType); JSG.debug("Found unknown dimension " + id + "! This is it's address:"); JSG.debug(gs.address.toString()); y++; @@ -56,17 +89,19 @@ public static void tryGenerate(@Nonnull World worldServer) { JSG.info("Found " + i + " unknown dimensions. Total " + y + " addresses were added as possible gates!"); } - public static GeneratedStargate generateAndPutAddresses(StargateNetwork sgn, int dim) { + public static GeneratedStargate generateAndPutAddresses(StargateNetwork sgn, int dim, SymbolTypeEnum symbolTypeEnum) { Random random = new Random(new BlockPos(0, 0, 0).hashCode() * 31L + dim); GeneratedStargate gs = null; + StargatePos gatePos = null; for (SymbolTypeEnum symbolType : SymbolTypeEnum.values()) { StargateAddress address = new StargateAddress(symbolType); do { address.generate(random); } while (sgn.isStargateInNetwork(address)); - StargatePos gatePos = new StargatePos(dim, new BlockPos(0, 0, 0), address, SymbolTypeEnum.MILKYWAY); + if(gatePos == null) + gatePos = new StargatePos(dim, new BlockPos(0, 0, 0), address, symbolTypeEnum); sgn.addNotGeneratedStargate(address, gatePos); if (gs == null) diff --git a/src/main/java/tauri/dev/jsg/worldgen/structures/JSGStructure.java b/src/main/java/tauri/dev/jsg/worldgen/structures/JSGStructure.java index e0527820..a30ecdec 100644 --- a/src/main/java/tauri/dev/jsg/worldgen/structures/JSGStructure.java +++ b/src/main/java/tauri/dev/jsg/worldgen/structures/JSGStructure.java @@ -2,6 +2,7 @@ import net.minecraft.block.state.IBlockState; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.server.MinecraftServer; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityChest; @@ -33,10 +34,12 @@ import tauri.dev.jsg.config.stargate.StargateSizeEnum; import tauri.dev.jsg.fluid.JSGFluids; import tauri.dev.jsg.item.JSGItems; +import tauri.dev.jsg.item.notebook.PageNotebookItem; import tauri.dev.jsg.power.general.LargeEnergyStorage; import tauri.dev.jsg.power.zpm.IEnergyStorageZPM; import tauri.dev.jsg.power.zpm.ZPMItemEnergyStorage; import tauri.dev.jsg.stargate.network.StargateAddress; +import tauri.dev.jsg.stargate.network.StargateNetwork; import tauri.dev.jsg.stargate.network.StargatePos; import tauri.dev.jsg.stargate.network.SymbolTypeEnum; import tauri.dev.jsg.tileentity.dialhomedevice.DHDAbstractTile; @@ -313,11 +316,15 @@ public GeneratedStargate generateStructure(World executedInWorld, BlockPos pos, private static void generateLoot(World world, BlockPos chestPos, Random random, String lootTableName) { TileEntity tile = world.getTileEntity(chestPos); if (tile instanceof TileEntityChest) { + StargateNetwork sgn = StargateNetwork.get(world); + TileEntityChest chest = (TileEntityChest) tile; chest.setLootTable(new ResourceLocation(JSG.MOD_ID, lootTableName), random.nextLong()); + chest.fillWithLoot(null); + IItemHandler handler = chest.getSingleChestHandler(); + + // Set ZPM energy if (lootTableName.equalsIgnoreCase("loot_obelisk")) { - chest.fillWithLoot(null); - IItemHandler handler = chest.getSingleChestHandler(); for (int i = 0; i < handler.getSlots(); i++) { ItemStack stack = handler.getStackInSlot(i); if (!stack.isEmpty()) { @@ -329,6 +336,28 @@ private static void generateLoot(World world, BlockPos chestPos, Random random, } } } + + // Set sus page address + for (int i = 0; i < handler.getSlots(); i++) { + ItemStack stack = handler.getStackInSlot(i); + if (!stack.isEmpty() && stack.getItem() == JSGItems.PAGE_NOTEBOOK_ITEM && stack.getMetadata() == 1) { + Map.Entry> gotAddressMap = sgn.getRandomNotGeneratedStargate(); + if(gotAddressMap == null){ + // Got no stargate -> remove page from the chest + stack.setCount(0); + continue; + } + SymbolTypeEnum symbolTypeEnum = SymbolTypeEnum.getRandom(); + StargateAddress address = gotAddressMap.getValue().get(symbolTypeEnum); + StargatePos pos = gotAddressMap.getKey(); + + String biome = ((pos.getWorld() == null || pos.gatePos == null) ? "plains" : PageNotebookItem.getRegistryPathFromWorld(pos.getWorld(), pos.gatePos)); + int origin = StargateClassicBaseTile.getOriginId(null, pos.dimensionID, -1); + + NBTTagCompound sgCompound = PageNotebookItem.getCompoundFromAddress(address, true, true, true, biome, origin); + stack.setTagCompound(sgCompound); + } + } } } } diff --git a/src/main/resources/assets/jsg/loot_tables/end_city_treasure.json b/src/main/resources/assets/jsg/loot_tables/end_city_treasure.json index 0fd21daf..703bc509 100644 --- a/src/main/resources/assets/jsg/loot_tables/end_city_treasure.json +++ b/src/main/resources/assets/jsg/loot_tables/end_city_treasure.json @@ -14,6 +14,22 @@ "weight": 75 } ] + }, + { + "name": "sus_page", + "rolls": 1, + "entries": [ + { + "type": "item", + "name": "jsg:page_notebook", + "data": 1, + "weight": 50 + }, + { + "type": "empty", + "weight": 50 + } + ] } ] } \ No newline at end of file diff --git a/src/main/resources/assets/jsg/loot_tables/loot_nether.json b/src/main/resources/assets/jsg/loot_tables/loot_nether.json index 38eb48da..5ef525cf 100644 --- a/src/main/resources/assets/jsg/loot_tables/loot_nether.json +++ b/src/main/resources/assets/jsg/loot_tables/loot_nether.json @@ -65,6 +65,22 @@ "weight": 4 } ] + }, + { + "name": "sus_page", + "rolls": 1, + "entries": [ + { + "type": "item", + "name": "jsg:page_notebook", + "data": 1, + "weight": 50 + }, + { + "type": "empty", + "weight": 50 + } + ] } ] } \ No newline at end of file diff --git a/src/main/resources/assets/jsg/loot_tables/loot_obelisk.json b/src/main/resources/assets/jsg/loot_tables/loot_obelisk.json index 40f2c27e..3cc8c98c 100644 --- a/src/main/resources/assets/jsg/loot_tables/loot_obelisk.json +++ b/src/main/resources/assets/jsg/loot_tables/loot_obelisk.json @@ -41,6 +41,22 @@ "weight": 15 } ] + }, + { + "name": "sus_page", + "rolls": 1, + "entries": [ + { + "type": "item", + "name": "jsg:page_notebook", + "data": 1, + "weight": 50 + }, + { + "type": "empty", + "weight": 50 + } + ] } ] } \ No newline at end of file diff --git a/src/main/resources/assets/jsg/loot_tables/loot_ov.json b/src/main/resources/assets/jsg/loot_tables/loot_ov.json index 8b648cad..e4e55004 100644 --- a/src/main/resources/assets/jsg/loot_tables/loot_ov.json +++ b/src/main/resources/assets/jsg/loot_tables/loot_ov.json @@ -80,6 +80,22 @@ "weight": 4 } ] + }, + { + "name": "sus_page", + "rolls": 1, + "entries": [ + { + "type": "item", + "name": "jsg:page_notebook", + "data": 1, + "weight": 50 + }, + { + "type": "empty", + "weight": 50 + } + ] } ] } \ No newline at end of file diff --git a/src/main/resources/assets/jsg/loot_tables/loot_zpm.json b/src/main/resources/assets/jsg/loot_tables/loot_zpm.json index 0626bf61..71b6d001 100644 --- a/src/main/resources/assets/jsg/loot_tables/loot_zpm.json +++ b/src/main/resources/assets/jsg/loot_tables/loot_zpm.json @@ -20,6 +20,22 @@ "weight": 15 } ] + }, + { + "name": "sus_page", + "rolls": 1, + "entries": [ + { + "type": "item", + "name": "jsg:page_notebook", + "data": 1, + "weight": 50 + }, + { + "type": "empty", + "weight": 50 + } + ] } ] } \ No newline at end of file diff --git a/src/main/resources/assets/jsg/textures/gui/gui_admin_controller.png b/src/main/resources/assets/jsg/textures/gui/gui_admin_controller.png index 0d5e2bae..4e156fc3 100644 Binary files a/src/main/resources/assets/jsg/textures/gui/gui_admin_controller.png and b/src/main/resources/assets/jsg/textures/gui/gui_admin_controller.png differ