diff --git a/src/main/java/mrjake/aunis/config/AunisConfig.java b/src/main/java/mrjake/aunis/config/AunisConfig.java index 30f20ac9..cee8d04e 100644 --- a/src/main/java/mrjake/aunis/config/AunisConfig.java +++ b/src/main/java/mrjake/aunis/config/AunisConfig.java @@ -1,7 +1,11 @@ package mrjake.aunis.config; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import mrjake.aunis.renderer.biomes.BiomeOverlayEnum; +import mrjake.aunis.util.ItemMetaPair; import net.minecraft.block.state.IBlockState; import net.minecraft.world.biome.Biome; import net.minecraftforge.common.config.Config; @@ -101,7 +105,7 @@ public boolean canKawooshDestroyBlock(IBlockState state) { // --------------------------------------------------------------------------------------- // Jungle biomes - @Name("Biomes in which blocks should be mossy") + @Name("Biomes in which Stargates should be mossy") @Comment({ "Format: \"modid:biomename\", for example: ", "\"minecraft:dark_forest\"", @@ -118,6 +122,63 @@ public boolean isJungleBiome(Biome biome) { return cachedJungleBiomes.contains(biome); } + + + // --------------------------------------------------------------------------------------- + // Biome overlay override blocks + + @Name("Biome overlay override blocks") + @SuppressWarnings("serial") + @Comment({ + "Format: \"modid:blockid[:meta]\", for example: ", + "\"minecraft:wool:7\"", + "\"minecraft:stone\"" + }) + public Map biomeOverrideBlocks = new HashMap() { + { + put(BiomeOverlayEnum.NORMAL.toString(), new String[] {"minecraft:stone"}); + put(BiomeOverlayEnum.FROST.toString(), new String[] {"minecraft:ice"}); + put(BiomeOverlayEnum.MOSSY.toString(), new String[] {"minecraft:vine"}); + put(BiomeOverlayEnum.AGED.toString(), new String[] {"minecraft:cobblestone"}); + put(BiomeOverlayEnum.SOOTY.toString(), new String[] {"minecraft:coal_block"}); + } + }; + + private Map> cachedBiomeOverrideBlocks = null; + private Map cachedBiomeOverrideBlocksReverse = null; + + private void genBiomeOverrideCache() { + cachedBiomeOverrideBlocks = new HashMap<>(); + cachedBiomeOverrideBlocksReverse = new HashMap<>(); + + for (Map.Entry entry : biomeOverrideBlocks.entrySet()) { + List parsedList = ItemMetaParser.parseConfig(entry.getValue()); + BiomeOverlayEnum biomeOverlay = BiomeOverlayEnum.fromString(entry.getKey()); + + cachedBiomeOverrideBlocks.put(biomeOverlay, parsedList); + + for (ItemMetaPair stack : parsedList) { + cachedBiomeOverrideBlocksReverse.put(stack, biomeOverlay); + } + } + } + + public Map> getBiomeOverrideBlocks() { + if (cachedBiomeOverrideBlocks == null) { + genBiomeOverrideCache(); + } + + return cachedBiomeOverrideBlocks; + } + + public Map getBiomeOverrideItemMetaPairs() { + if (cachedBiomeOverrideBlocksReverse == null) { + genBiomeOverrideCache(); + } + + return cachedBiomeOverrideBlocksReverse; + } + } public static class PowerConfig { @@ -300,5 +361,7 @@ public static class WorldGenConfig { public static void resetCache() { stargateConfig.cachedInvincibleBlocks = null; stargateConfig.cachedJungleBiomes = null; + stargateConfig.cachedBiomeOverrideBlocks = null; + stargateConfig.cachedBiomeOverrideBlocksReverse = null; } } diff --git a/src/main/java/mrjake/aunis/config/ItemMetaParser.java b/src/main/java/mrjake/aunis/config/ItemMetaParser.java new file mode 100644 index 00000000..6764fa37 --- /dev/null +++ b/src/main/java/mrjake/aunis/config/ItemMetaParser.java @@ -0,0 +1,64 @@ +package mrjake.aunis.config; + +import java.util.ArrayList; +import java.util.List; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import mrjake.aunis.util.ItemMetaPair; +import net.minecraft.block.state.IBlockState; +import net.minecraft.item.Item; +import net.minecraft.util.ResourceLocation; + +public class ItemMetaParser { + + /** + * Parses array of configured items/blocks. For format see {@link ItemMetaParser#getBlockStateFromString(String)} + * + * @param config Array of single lines + * @return List of {@link IBlockState}s or empty list. + */ + @Nonnull + static List parseConfig(String[] config) { + List list = new ArrayList<>(); + + for (String line : config) { + ItemMetaPair stack = getItemMetaPairFromString(line); + + if(stack != null) { + list.add(stack); + } + } + + return list; + } + + /** + * Parses single line of the config. + * + * @param line Consists of modid:blockid[:meta] + * @return {@link IBlockState} when valid block, {@code null} otherwise. + */ + @Nullable + static ItemMetaPair getItemMetaPairFromString(String line) { + String[] parts = line.trim().split(":", 3); + + Item item = Item.REGISTRY.getObject(new ResourceLocation(parts[0], parts[1])); + + if (item != null) { + if (parts.length == 2 || parts[2].equals("*")) + return new ItemMetaPair(item, 0); + + try { + return new ItemMetaPair(item, Integer.parseInt(parts[2])); + } + + catch (NumberFormatException e) { + return null; + } + } + + return null; + } +} diff --git a/src/main/java/mrjake/aunis/gui/container/BeamerContainerGui.java b/src/main/java/mrjake/aunis/gui/container/BeamerContainerGui.java index afd9efff..677da6f7 100644 --- a/src/main/java/mrjake/aunis/gui/container/BeamerContainerGui.java +++ b/src/main/java/mrjake/aunis/gui/container/BeamerContainerGui.java @@ -1,9 +1,11 @@ package mrjake.aunis.gui.container; +import java.awt.Rectangle; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.stream.Collectors; import mrjake.aunis.Aunis; import mrjake.aunis.beamer.BeamerModeEnum; @@ -13,6 +15,8 @@ import mrjake.aunis.gui.element.FluidTankElement; import mrjake.aunis.gui.element.Tab; import mrjake.aunis.gui.element.TabRedstone; +import mrjake.aunis.gui.element.TabSideEnum; +import mrjake.aunis.gui.element.TabbedContainerInterface; import mrjake.aunis.packet.AunisPacketHandler; import mrjake.aunis.packet.BeamerChangeRoleToServer; import mrjake.aunis.stargate.power.StargateAbstractEnergyStorage; @@ -25,7 +29,7 @@ import net.minecraftforge.energy.CapabilityEnergy; import net.minecraftforge.items.SlotItemHandler; -public class BeamerContainerGui extends GuiContainer { +public class BeamerContainerGui extends GuiContainer implements TabbedContainerInterface { private static final ResourceLocation BACKGROUND_TEXTURE = new ResourceLocation(Aunis.ModID, "textures/gui/container_beamer.png"); @@ -183,16 +187,18 @@ public void initGui() { .setRedstoneModeGetter(() -> container.beamerTile.getRedstoneMode()) .setBeamerModeGetter(() -> container.beamerTile.getMode()) .setBlockPos(container.pos) + .setGuiSize(xSize, ySize) .setGuiPosition(guiLeft, guiTop) .setTabPosition(-21, 2) - .setOpenPosition(-128) + .setOpenX(-128) .setTabSize(128, 80) .setTabTitle(I18n.format("gui.beamer.activation")) + .setTabSide(TabSideEnum.LEFT) .setTexture(BACKGROUND_TEXTURE, 256) .setBackgroundTextureLocation(0, 176) .setIconRenderPos(1, 7) .setIconSize(20, 18) - .setIconTextureLocation(128, 0).build(); + .setIconTextureLocation(128, 176).build(); updated = false; @@ -373,6 +379,13 @@ protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOEx tabRedstone.mouseClicked(mouseX, mouseY, mouseButton); } + @Override + public List getGuiExtraAreas() { + return tabs.stream() + .map(tab -> tab.getArea()) + .collect(Collectors.toList()); + } + private class BeamerSlot extends SlotItemHandler { public BeamerSlot(SlotItemHandler slot) { diff --git a/src/main/java/mrjake/aunis/gui/container/DHDContainer.java b/src/main/java/mrjake/aunis/gui/container/DHDContainer.java index 2150832a..473d43b0 100644 --- a/src/main/java/mrjake/aunis/gui/container/DHDContainer.java +++ b/src/main/java/mrjake/aunis/gui/container/DHDContainer.java @@ -22,33 +22,49 @@ import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.SlotItemHandler; -public class DHDContainer extends Container { +public class DHDContainer extends Container implements OpenTabHolderInterface { public Slot slotCrystal; public FluidTank tankNaquadah; public DHDTile dhdTile; - + private BlockPos pos; private int tankLastAmount; private ReactorStateEnum lastReactorState; private boolean lastLinked; + private int openTabId = -1; + + @Override + public int getOpenTabId() { + return openTabId; + } + + @Override + public void setOpenTabId(int tabId) { + openTabId = tabId; + } public DHDContainer(IInventory playerInventory, World world, int x, int y, int z) { pos = new BlockPos(x, y, z); dhdTile = (DHDTile) world.getTileEntity(pos); IItemHandler itemHandler = dhdTile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); + // Crystal slot (index 0) slotCrystal = new SlotItemHandler(itemHandler, 0, 80, 35); addSlotToContainer(slotCrystal); tankNaquadah = (FluidTank) dhdTile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null); + // Upgrades (index 1-4) for (int row=0; row<2; row++) { for (int col=0; col<2; col++) { addSlotToContainer(new SlotItemHandler(itemHandler, row*2+col+1, 9+18*col, 18+18*row)); } } + // Biome overlay slot (index 5) + addSlotToContainer(new SlotItemHandler(itemHandler, 5, 0, 0)); + for (Slot slot : ContainerHelper.generatePlayerSlots(playerInventory, 86)) addSlotToContainer(slot); } @@ -63,7 +79,7 @@ public ItemStack transferStackInSlot(EntityPlayer player, int index) { ItemStack stack = getSlot(index).getStack(); // Transfering from DHD to player's inventory - if (index < 5) { + if (index < 6) { if (!mergeItemStack(stack, 5, inventorySlots.size(), false)) { return ItemStack.EMPTY; } @@ -99,6 +115,19 @@ else if (DHDTile.SUPPORTED_UPGRADES.contains(stack.getItem()) && dhdTile.upgrade } } + // Biome override blocks + else if (openTabId == 0 && getSlot(5).isItemValid(stack)) { + if (!getSlot(5).getHasStack()) { + ItemStack stack1 = stack.copy(); + stack1.setCount(1); + + putStackInSlot(5, stack1); + stack.shrink(1); + + return ItemStack.EMPTY; + } + } + return ItemStack.EMPTY; } diff --git a/src/main/java/mrjake/aunis/gui/container/DHDContainerGui.java b/src/main/java/mrjake/aunis/gui/container/DHDContainerGui.java index 8e14f8b8..232b5526 100644 --- a/src/main/java/mrjake/aunis/gui/container/DHDContainerGui.java +++ b/src/main/java/mrjake/aunis/gui/container/DHDContainerGui.java @@ -1,15 +1,26 @@ package mrjake.aunis.gui.container; +import java.awt.Rectangle; +import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; import mrjake.aunis.Aunis; import mrjake.aunis.fluid.AunisFluids; import mrjake.aunis.gui.element.Diode; import mrjake.aunis.gui.element.Diode.DiodeStatus; +import mrjake.aunis.gui.element.Tab.SlotTab; +import mrjake.aunis.packet.AunisPacketHandler; +import mrjake.aunis.packet.SetOpenTabToServer; +import mrjake.aunis.tileentity.DHDTile; import mrjake.aunis.tileentity.util.ReactorStateEnum; import mrjake.aunis.gui.element.FluidTankElement; import mrjake.aunis.gui.element.GuiHelper; +import mrjake.aunis.gui.element.Tab; +import mrjake.aunis.gui.element.TabBiomeOverlay; +import mrjake.aunis.gui.element.TabSideEnum; +import mrjake.aunis.gui.element.TabbedContainerInterface; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.renderer.GlStateManager; @@ -18,8 +29,9 @@ import net.minecraft.client.resources.I18n; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.items.SlotItemHandler; -public class DHDContainerGui extends GuiContainer { +public class DHDContainerGui extends GuiContainer implements TabbedContainerInterface { private static final ResourceLocation BACKGROUND_TEXTURE = new ResourceLocation(Aunis.ModID, "textures/gui/container_dhd.png"); @@ -28,6 +40,9 @@ public class DHDContainerGui extends GuiContainer { private List diodes = new ArrayList(3); + private List tabs = new ArrayList<>(); + private TabBiomeOverlay overlayTab; + public DHDContainerGui(DHDContainer container) { super(container); @@ -81,17 +96,54 @@ public DHDContainerGui(DHDContainer container) { } })); } + + @SuppressWarnings("static-access") + @Override + public void initGui() { + super.initGui(); + + tabs.clear(); + + overlayTab = (TabBiomeOverlay) TabBiomeOverlay.builder() + .setSupportedOverlays(container.dhdTile.getSupportedOverlays()) + .setSlotTexture(176, 86) + .setGuiSize(xSize, ySize) + .setGuiPosition(guiLeft, guiTop) + .setTabPosition(176-107, 2) + .setOpenX(176) + .setHiddenX(54) + .setTabSize(128, 51) + .setTabTitle(I18n.format("gui.stargate.biome_overlay")) + .setTabSide(TabSideEnum.RIGHT) + .setTexture(BACKGROUND_TEXTURE, 256) + .setBackgroundTextureLocation(0, 194) + .setIconRenderPos(107, 7) + .setIconSize(20, 18) + .setIconTextureLocation(176, 104).build(); + + tabs.add(overlayTab); + + container.inventorySlots.set(DHDTile.BIOME_OVERRIDE_SLOT, overlayTab.createAndSaveSlot((SlotItemHandler) container.getSlot(DHDTile.BIOME_OVERRIDE_SLOT))); + } @Override public void drawScreen(int mouseX, int mouseY, float partialTicks) { drawDefaultBackground(); - + + Tab.updatePositions(tabs); + + ((SlotTab) container.getSlot(5)).updatePos(); + super.drawScreen(mouseX, mouseY, partialTicks); renderHoveredToolTip(mouseX, mouseY); } @Override protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { + for (Tab tab : tabs) { + tab.render(fontRenderer, mouseX, mouseY); + } + mc.getTextureManager().bindTexture(BACKGROUND_TEXTURE); drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize); @@ -152,5 +204,36 @@ protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { } tank.renderTooltip(mouseX, mouseY); + + for (Tab tab : tabs) { + tab.renderFg(this, fontRenderer, mouseX, mouseY); + } + } + + @Override + protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { + super.mouseClicked(mouseX, mouseY, mouseButton); + + for (int i=0; i getGuiExtraAreas() { + return tabs.stream() + .map(tab -> tab.getArea()) + .collect(Collectors.toList()); } } diff --git a/src/main/java/mrjake/aunis/gui/container/OpenTabHolderInterface.java b/src/main/java/mrjake/aunis/gui/container/OpenTabHolderInterface.java new file mode 100644 index 00000000..03ceb6e3 --- /dev/null +++ b/src/main/java/mrjake/aunis/gui/container/OpenTabHolderInterface.java @@ -0,0 +1,6 @@ +package mrjake.aunis.gui.container; + +public interface OpenTabHolderInterface { + public int getOpenTabId(); + public void setOpenTabId(int tabId); +} diff --git a/src/main/java/mrjake/aunis/gui/container/StargateContainer.java b/src/main/java/mrjake/aunis/gui/container/StargateContainer.java index e058f4d7..30026ba7 100644 --- a/src/main/java/mrjake/aunis/gui/container/StargateContainer.java +++ b/src/main/java/mrjake/aunis/gui/container/StargateContainer.java @@ -2,7 +2,6 @@ import mrjake.aunis.block.AunisBlocks; import mrjake.aunis.gui.util.ContainerHelper; -import mrjake.aunis.item.AunisItems; import mrjake.aunis.packet.AunisPacketHandler; import mrjake.aunis.packet.StateUpdatePacketToClient; import mrjake.aunis.stargate.power.StargateClassicEnergyStorage; @@ -24,16 +23,26 @@ import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.SlotItemHandler; -public class StargateContainer extends Container { +public class StargateContainer extends Container implements OpenTabHolderInterface { public StargateClassicBaseTile gateTile; - public int openTabId = -1; private BlockPos pos; private int lastEnergyStored; private int energyTransferedLastTick; private float lastEnergySecondsToClose; private int lastProgress; + private int openTabId = -1; + + @Override + public int getOpenTabId() { + return openTabId; + } + + @Override + public void setOpenTabId(int tabId) { + openTabId = tabId; + } public StargateContainer(IInventory playerInventory, World world, int x, int y, int z) { pos = new BlockPos(x, y, z); @@ -52,8 +61,13 @@ public StargateContainer(IInventory playerInventory, World world, int x, int y, addSlotToContainer(new SlotItemHandler(itemHandler, col+4, 115+18*col, 40)); } - for (int i=0; i<3; i++) + // Page slots (index 7-9) + for (int i=0; i<3; i++) { addSlotToContainer(new SlotItemHandler(itemHandler, i+7, -22, 89+22*i)); + } + + // Biome overlay slot (index 10) + addSlotToContainer(new SlotItemHandler(itemHandler, 10, 0, 0)); for (Slot slot : ContainerHelper.generatePlayerSlots(playerInventory, 86)) addSlotToContainer(slot); @@ -74,8 +88,8 @@ public ItemStack transferStackInSlot(EntityPlayer player, int index) { ItemStack stack = getSlot(index).getStack(); // Transfering from Stargate to player's inventory - if (index < 10) { - if (!mergeItemStack(stack, 10, inventorySlots.size(), false)) { + if (index < 11) { + if (!mergeItemStack(stack, 11, inventorySlots.size(), false)) { return ItemStack.EMPTY; } @@ -113,7 +127,7 @@ else if (StargateUpgradeEnum.contains(stack.getItem()) && !gateTile.hasUpgradeIn } } - else if ((stack.getItem() == AunisItems.PAGE_NOTEBOOK_ITEM && openTabId != -1) || (stack.getItem() == AunisItems.UNIVERSE_DIALER && openTabId == 2)) { + else if (openTabId >= 0 && openTabId <= 2 && getSlot(7+openTabId).isItemValid(stack)) { if (!getSlot(7+openTabId).getHasStack()) { ItemStack stack1 = stack.copy(); stack1.setCount(1); @@ -125,6 +139,19 @@ else if ((stack.getItem() == AunisItems.PAGE_NOTEBOOK_ITEM && openTabId != -1) | } } + // Biome override blocks + else if (openTabId == 3 && getSlot(10).isItemValid(stack)) { + if (!getSlot(10).getHasStack()) { + ItemStack stack1 = stack.copy(); + stack1.setCount(1); + + putStackInSlot(10, stack1); + stack.shrink(1); + + return ItemStack.EMPTY; + } + } + return ItemStack.EMPTY; } diff --git a/src/main/java/mrjake/aunis/gui/container/StargateContainerGui.java b/src/main/java/mrjake/aunis/gui/container/StargateContainerGui.java index ed94d81a..eb2ff3f5 100644 --- a/src/main/java/mrjake/aunis/gui/container/StargateContainerGui.java +++ b/src/main/java/mrjake/aunis/gui/container/StargateContainerGui.java @@ -1,15 +1,20 @@ package mrjake.aunis.gui.container; +import java.awt.Rectangle; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.stream.Collectors; import mrjake.aunis.Aunis; import mrjake.aunis.config.AunisConfig; import mrjake.aunis.gui.element.Tab; import mrjake.aunis.gui.element.Tab.SlotTab; import mrjake.aunis.gui.element.TabAddress; +import mrjake.aunis.gui.element.TabBiomeOverlay; +import mrjake.aunis.gui.element.TabSideEnum; +import mrjake.aunis.gui.element.TabbedContainerInterface; import mrjake.aunis.packet.AunisPacketHandler; import mrjake.aunis.packet.SetOpenTabToServer; import mrjake.aunis.stargate.network.SymbolMilkyWayEnum; @@ -28,7 +33,7 @@ import net.minecraftforge.energy.IEnergyStorage; import net.minecraftforge.items.SlotItemHandler; -public class StargateContainerGui extends GuiContainer { +public class StargateContainerGui extends GuiContainer implements TabbedContainerInterface { private static final ResourceLocation BACKGROUND_TEXTURE = new ResourceLocation(Aunis.ModID, "textures/gui/container_stargate.png"); @@ -38,6 +43,7 @@ public class StargateContainerGui extends GuiContainer { private TabAddress milkyWayAddressTab; private TabAddress pegasusAddressTab; private TabAddress universeAddressTab; + private TabBiomeOverlay overlayTab; private int energyStored; private int maxEnergyStored; @@ -59,52 +65,80 @@ public void initGui() { milkyWayAddressTab = (TabAddress) TabAddress.builder() .setGateTile(container.gateTile) .setSymbolType(SymbolTypeEnum.MILKYWAY) + .setGuiSize(xSize, ySize) .setGuiPosition(guiLeft, guiTop) .setTabPosition(-21, 2) - .setOpenPosition(-128) + .setOpenX(-128) + .setHiddenX(-6) .setTabSize(128, 113) .setTabTitle(I18n.format("gui.stargate.milky_way_address")) + .setTabSide(TabSideEnum.LEFT) .setTexture(BACKGROUND_TEXTURE, 512) .setBackgroundTextureLocation(176, 0) .setIconRenderPos(1, 7) .setIconSize(20, 18) - .setIconTextureLocation(128, 0).build(); + .setIconTextureLocation(304, 0).build(); pegasusAddressTab = (TabAddress) TabAddress.builder() .setGateTile(container.gateTile) .setSymbolType(SymbolTypeEnum.PEGASUS) + .setGuiSize(xSize, ySize) .setGuiPosition(guiLeft, guiTop) .setTabPosition(-21, 2+22) - .setOpenPosition(-128) + .setOpenX(-128) + .setHiddenX(-6) .setTabSize(128, 113) .setTabTitle(I18n.format("gui.stargate.pegasus_address")) + .setTabSide(TabSideEnum.LEFT) .setTexture(BACKGROUND_TEXTURE, 512) .setBackgroundTextureLocation(176, 0) .setIconRenderPos(1, 7) .setIconSize(20, 18) - .setIconTextureLocation(128, 18).build(); + .setIconTextureLocation(304, 18).build(); universeAddressTab = (TabAddress) TabAddress.builder() .setGateTile(container.gateTile) .setSymbolType(SymbolTypeEnum.UNIVERSE) + .setGuiSize(xSize, ySize) .setGuiPosition(guiLeft, guiTop) .setTabPosition(-21, 2+22*2) - .setOpenPosition(-128) + .setOpenX(-128) + .setHiddenX(-6) .setTabSize(128, 113) .setTabTitle(I18n.format("gui.stargate.universe_address")) + .setTabSide(TabSideEnum.LEFT) .setTexture(BACKGROUND_TEXTURE, 512) .setBackgroundTextureLocation(176, 0) .setIconRenderPos(1, 7) .setIconSize(20, 18) - .setIconTextureLocation(128, 18*2).build(); + .setIconTextureLocation(304, 18*2).build(); + + overlayTab = (TabBiomeOverlay) TabBiomeOverlay.builder() + .setSupportedOverlays(container.gateTile.getSupportedOverlays()) + .setSlotTexture(6, 174) + .setGuiSize(xSize, ySize) + .setGuiPosition(guiLeft, guiTop) + .setTabPosition(176-107, 2) + .setOpenX(176) + .setHiddenX(54) + .setTabSize(128, 51) + .setTabTitle(I18n.format("gui.stargate.biome_overlay")) + .setTabSide(TabSideEnum.RIGHT) + .setTexture(BACKGROUND_TEXTURE, 512) + .setBackgroundTextureLocation(176, 113) + .setIconRenderPos(107, 7) + .setIconSize(20, 18) + .setIconTextureLocation(304, 54).build(); tabs.add(milkyWayAddressTab); tabs.add(pegasusAddressTab); tabs.add(universeAddressTab); + tabs.add(overlayTab); - container.inventorySlots.set(7, milkyWayAddressTab.new SlotTab((SlotItemHandler) container.getSlot(7))); - container.inventorySlots.set(8, pegasusAddressTab.new SlotTab((SlotItemHandler) container.getSlot(8))); - container.inventorySlots.set(9, universeAddressTab.new SlotTab((SlotItemHandler) container.getSlot(9))); + container.inventorySlots.set(7, milkyWayAddressTab.createSlot((SlotItemHandler) container.getSlot(7))); + container.inventorySlots.set(8, pegasusAddressTab.createSlot((SlotItemHandler) container.getSlot(8))); + container.inventorySlots.set(9, universeAddressTab.createSlot((SlotItemHandler) container.getSlot(9))); + container.inventorySlots.set(10, overlayTab.createAndSaveSlot((SlotItemHandler) container.getSlot(10))); } @Override @@ -164,7 +198,7 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) { maxEnergyStored += energyStorage.getMaxEnergyStored(); } - for (int i=7; i<10; i++) + for (int i=7; i<11; i++) ((SlotTab) container.getSlot(i)).updatePos(); super.drawScreen(mouseX, mouseY, partialTicks); @@ -243,14 +277,21 @@ protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOEx if (tab.isCursorOnTab(mouseX, mouseY)) { if (Tab.tabsInteract(tabs, i)) - container.openTabId = i; + container.setOpenTabId(i); else - container.openTabId = -1; + container.setOpenTabId(-1); - AunisPacketHandler.INSTANCE.sendToServer(new SetOpenTabToServer(container.openTabId)); + AunisPacketHandler.INSTANCE.sendToServer(new SetOpenTabToServer(container.getOpenTabId())); break; } } } + + @Override + public List getGuiExtraAreas() { + return tabs.stream() + .map(tab -> tab.getArea()) + .collect(Collectors.toList()); + } } diff --git a/src/main/java/mrjake/aunis/gui/element/Tab.java b/src/main/java/mrjake/aunis/gui/element/Tab.java index 2c3b9d3a..18a74367 100644 --- a/src/main/java/mrjake/aunis/gui/element/Tab.java +++ b/src/main/java/mrjake/aunis/gui/element/Tab.java @@ -1,5 +1,6 @@ package mrjake.aunis.gui.element; +import java.awt.Rectangle; import java.util.List; import net.minecraft.client.Minecraft; @@ -10,19 +11,23 @@ import net.minecraft.util.ResourceLocation; import net.minecraftforge.items.SlotItemHandler; -public class Tab { +public abstract class Tab { - // Container info (position) and ID + // Container info (position and size) protected int guiLeft; protected int guiTop; + protected int xSize; + protected int ySize; // Tab info (location & position) protected int defaultX; protected int defaultY; private int openX; + private int hiddenX; protected int width; protected int height; protected String tabTitle; + protected TabSideEnum side; // Background texture protected ResourceLocation bgTexLocation; @@ -41,13 +46,17 @@ public class Tab { protected Tab(TabBuilder builder) { this.guiLeft = builder.guiLeft; this.guiTop = builder.guiTop; + this.xSize = builder.xSize; + this.ySize = builder.ySize; this.defaultX = builder.defaultX; this.defaultY = builder.defaultY; this.openX = builder.openX; + this.hiddenX = builder.hiddenX; this.width = builder.width; this.height = builder.height; this.tabTitle = builder.tabTitle; + this.side = builder.side; this.bgTexLocation = builder.bgTexLocation; this.textureSize = builder.textureSize; @@ -70,10 +79,6 @@ public void setVisible(boolean isVisible) { this.isVisible = isVisible; } - public void setPositionY(int y) { - this.defaultY = y; - } - private boolean animate = false; private int startingOffsetX = 0; private boolean isTabOpen = false; @@ -109,9 +114,9 @@ public void render(FontRenderer fontRenderer, int mouseX, int mouseY) { mc.getTextureManager().bindTexture(bgTexLocation); Gui.drawModalRectWithCustomSizedTexture(guiLeft+currentOffsetX, guiTop+defaultY, bgTexX, bgTexY, width, height, textureSize, textureSize); - Gui.drawModalRectWithCustomSizedTexture(guiLeft+iconX+currentOffsetX, guiTop+defaultY+iconY, bgTexX+iconTexX, bgTexY+iconTexY, iconWidth, iconHeight, textureSize, textureSize); + Gui.drawModalRectWithCustomSizedTexture(guiLeft+iconX+currentOffsetX, guiTop+defaultY+iconY, iconTexX, iconTexY, iconWidth, iconHeight, textureSize, textureSize); - fontRenderer.drawString(tabTitle, guiLeft+currentOffsetX+28, guiTop+defaultY+10, 4210752); + fontRenderer.drawString(tabTitle, guiLeft+currentOffsetX+(side.left() ? 24 : 0)+4, guiTop+defaultY+10, 4210752); GlStateManager.disableBlend(); } @@ -126,7 +131,13 @@ public void renderFg(GuiScreen screen, FontRenderer fontRenderer, int mouseX, in } public boolean isCursorOnTab(int mouseX, int mouseY) { - return isVisible && GuiHelper.isPointInRegion(guiLeft+iconX+currentOffsetX, guiTop+defaultY+iconY, iconWidth - (isTabHidden ? 15 : 0), iconHeight, mouseX, mouseY); + int xOffset = 0; + if (isTabHidden && hiddenX < defaultX) { + // hide - slides to the left + xOffset = 15; + } + + return isVisible && GuiHelper.isPointInRegion(guiLeft+iconX+currentOffsetX+xOffset, guiTop+defaultY+iconY, iconWidth - (isTabHidden ? 15 : 0), iconHeight, mouseX, mouseY); } public void openTab() { @@ -144,7 +155,7 @@ public void closeTab() { } public void hideTab() { - animateTo(-6, isTabOpen ? 10 : 5); + animateTo(hiddenX, isTabOpen ? 10 : 5); isTabHidden = true; isTabOpen = false; @@ -176,24 +187,43 @@ public void updateAnimation(Minecraft mc) { } } - + public Rectangle getArea() { + int tabHeight = (isTabOpen | animate) ? height : 34; + + if (side.left()) { + return new Rectangle(guiLeft+currentOffsetX, guiTop+defaultY, Math.abs(currentOffsetX), tabHeight); + } + + // right + return new Rectangle(guiLeft+xSize, guiTop+defaultY, width+currentOffsetX-xSize, tabHeight); + } + // ------------------------------------------------------------------------------------------------ // Interaction + /** + * Interact with tab (clicked). + * + * @return {@code true} if the Tab will be opening, {@code false} if closing. + */ public static boolean tabsInteract(List tabs, int tabIndex) { Tab tab = tabs.get(tabIndex); // Tabs higher than clicked one for (Tab tab2 : tabs.subList(0, tabIndex)) { - tab2.closeTab(); + if (tab.side == tab2.side) { + tab2.closeTab(); + } } // Tabs lower than clicked one for (Tab tab2 : tabs.subList(tabIndex+1, tabs.size())) { - if (tab.isOpen()) - tab2.closeTab(); - else - tab2.hideTab(); + if (tab.side == tab2.side) { + if (tab.isOpen()) + tab2.closeTab(); + else + tab2.hideTab(); + } } if (tab.isOpen()) { @@ -205,13 +235,25 @@ public static boolean tabsInteract(List tabs, int tabIndex) { } } + /** + * Sorts tabs so only visible (enabled by some upgrade) occupy space. + */ public static void updatePositions(List tabs) { - int yOffset = 2; + int yPosLeft = 2; + int yPosRight = 2; for (Tab tab : tabs) { if (tab.isVisible()) { - tab.setPositionY(yOffset); - yOffset += 22; + if (tab.side.left()) { + tab.defaultY = yPosLeft; + yPosLeft += 22; + } + + else { + // right side + tab.defaultY = yPosRight; + yPosRight += 22; + } } } } @@ -219,24 +261,24 @@ public static void updatePositions(List tabs) { // ------------------------------------------------------------------------------------------------ // Builder - - public static TabBuilder builder() { - return new TabBuilder(); - } - - public static class TabBuilder { + + public static abstract class TabBuilder { // Container info (position) and ID private int guiLeft; private int guiTop; + private int xSize; + private int ySize; // Tab info (location & position) private int defaultX; private int defaultY; private int openX; + private int hiddenX; private int width; private int height; private String tabTitle; + private TabSideEnum side; // Background texture private ResourceLocation bgTexLocation; @@ -252,6 +294,13 @@ public static class TabBuilder { private int iconTexX; private int iconTexY; + public TabBuilder setGuiSize(int xSize, int ySize) { + this.xSize = xSize; + this.ySize = ySize; + + return this; + } + public TabBuilder setGuiPosition(int guiLeft, int guiTop) { this.guiLeft = guiLeft; this.guiTop = guiTop; @@ -266,11 +315,17 @@ public TabBuilder setTabPosition(int defaultX, int defaultY) { return this; } - public TabBuilder setOpenPosition(int openX) { + public TabBuilder setOpenX(int openX) { this.openX = openX; return this; } + + public TabBuilder setHiddenX(int hiddenX) { + this.hiddenX = hiddenX; + + return this; + } public TabBuilder setTabSize(int width, int height) { this.width = width; @@ -284,6 +339,12 @@ public TabBuilder setTabTitle(String tabTitle) { return this; } + + public TabBuilder setTabSide(TabSideEnum side) { + this.side = side; + + return this; + } public TabBuilder setTexture(ResourceLocation bgTexLocation, int texureSize) { this.bgTexLocation = bgTexLocation; @@ -320,9 +381,7 @@ public TabBuilder setIconTextureLocation(int iconTexX, int iconTexY) { return this; } - public Tab build() { - return new Tab(this); - } + public abstract Tab build(); } @@ -331,9 +390,13 @@ public Tab build() { public class SlotTab extends SlotItemHandler { - public SlotTab(SlotItemHandler slot) { + private UpdateSlotPositionInterface updateSlotPosition; + + public SlotTab(SlotItemHandler slot, UpdateSlotPositionInterface updateSlotPosition) { super(slot.getItemHandler(), slot.getSlotIndex(), slot.xPos, slot.yPos); this.slotNumber = slot.slotNumber; + + this.updateSlotPosition = updateSlotPosition; } @Override @@ -342,8 +405,13 @@ public boolean isEnabled() { } public void updatePos() { - this.xPos = currentOffsetX + 106; - this.yPos = defaultY + 87; +// this.xPos = currentOffsetX + 106; +// this.yPos = defaultY + 87; + updateSlotPosition.updatePos(this); } } + + public static interface UpdateSlotPositionInterface { + public void updatePos(SlotTab slotTab); + } } diff --git a/src/main/java/mrjake/aunis/gui/element/TabAddress.java b/src/main/java/mrjake/aunis/gui/element/TabAddress.java index 4b1601eb..51677ad4 100644 --- a/src/main/java/mrjake/aunis/gui/element/TabAddress.java +++ b/src/main/java/mrjake/aunis/gui/element/TabAddress.java @@ -7,6 +7,7 @@ import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.renderer.GlStateManager; +import net.minecraftforge.items.SlotItemHandler; public class TabAddress extends Tab { @@ -31,6 +32,11 @@ public void setMaxSymbols(int maxSymbols) { public void render(FontRenderer fontRenderer, int mouseX, int mouseY) { super.render(fontRenderer, mouseX, mouseY); + // Draw page slot + Minecraft.getMinecraft().getTextureManager().bindTexture(bgTexLocation); + GlStateManager.color(1, 1, 1, 1); + Gui.drawModalRectWithCustomSizedTexture(guiLeft+currentOffsetX+105, guiTop+defaultY+86, 6, 174, 18, 18, textureSize, textureSize); + int shadow = 2; float color = 1.0f; @@ -76,6 +82,13 @@ public void renderFg(GuiScreen screen, FontRenderer fontRenderer, int mouseX, in } } + public SlotTab createSlot(SlotItemHandler slot) { + return new SlotTab(slot, (slotTab) -> { + slotTab.xPos = currentOffsetX + 106; + slotTab.yPos = defaultY + 87; + }); + } + public SymbolCoords getSymbolCoords(int symbol) { switch (symbolType) { case UNIVERSE: diff --git a/src/main/java/mrjake/aunis/gui/element/TabBiomeOverlay.java b/src/main/java/mrjake/aunis/gui/element/TabBiomeOverlay.java new file mode 100644 index 00000000..c56f400d --- /dev/null +++ b/src/main/java/mrjake/aunis/gui/element/TabBiomeOverlay.java @@ -0,0 +1,117 @@ +package mrjake.aunis.gui.element; + +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.List; + +import mrjake.aunis.config.AunisConfig; +import mrjake.aunis.renderer.biomes.BiomeOverlayEnum; +import mrjake.aunis.util.ItemMetaPair; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.resources.I18n; +import net.minecraft.util.text.TextFormatting; +import net.minecraftforge.items.SlotItemHandler; + +public class TabBiomeOverlay extends Tab { + + private EnumSet supportedOverlays; + private SlotTab slot; + + private int slotTexX; + private int slotTexY; + + protected TabBiomeOverlay(TabBiomeOverlayBuilder builder) { + super(builder); + + supportedOverlays = builder.supportedOverlays; + slotTexX = builder.slotTexX; + slotTexY = builder.slotTexY; + } + + @Override + public void render(FontRenderer fontRenderer, int mouseX, int mouseY) { + super.render(fontRenderer, mouseX, mouseY); + + // Draw page slot + Minecraft.getMinecraft().getTextureManager().bindTexture(bgTexLocation); + GlStateManager.color(1, 1, 1, 1); + Gui.drawModalRectWithCustomSizedTexture(guiLeft+currentOffsetX+5, guiTop+defaultY+24, slotTexX, slotTexY, 18, 18, textureSize, textureSize); + + + if (isVisible()) { + // TODO code + } + } + + @Override + public void renderFg(GuiScreen screen, FontRenderer fontRenderer, int mouseX, int mouseY) { + super.renderFg(screen, fontRenderer, mouseX, mouseY); + + if (isVisible() && isOpen()) { + if (GuiHelper.isPointInRegion(guiLeft+currentOffsetX+6, guiTop+defaultY+25, 16, 16, mouseX, mouseY) && !slot.getHasStack()) { + List text = new ArrayList<>(); + text.add(I18n.format("gui.stargate.biome_overlay.help")); + + for (BiomeOverlayEnum biomeOverlay : BiomeOverlayEnum.values()) { + if (!supportedOverlays.contains(biomeOverlay)) + continue; + + String line = ""; + line += biomeOverlay.color + biomeOverlay.name() + ": " + TextFormatting.ITALIC; + + for (ItemMetaPair itemMeta : AunisConfig.stargateConfig.getBiomeOverrideBlocks().get(biomeOverlay)) { + line += itemMeta.getDisplayName() + ", "; + } + + text.add(line); + } + + screen.drawHoveringText(text, mouseX-guiLeft, mouseY-guiTop); + } + } + } + + public SlotTab createAndSaveSlot(SlotItemHandler slot) { + this.slot = new SlotTab(slot, (slotTab) -> { + slotTab.xPos = currentOffsetX + 6; + slotTab.yPos = defaultY + 25; + }); + + return this.slot; + } + + // ------------------------------------------------------------------------------------------------ + // Builder + + public static TabBiomeOverlayBuilder builder() { + return new TabBiomeOverlayBuilder(); + } + + public static class TabBiomeOverlayBuilder extends TabBuilder { + + private EnumSet supportedOverlays; + private int slotTexX; + private int slotTexY; + + public TabBiomeOverlayBuilder setSupportedOverlays(EnumSet supportedOverlays) { + this.supportedOverlays = supportedOverlays; + return this; + } + + public TabBiomeOverlayBuilder setSlotTexture(int x, int y) { + slotTexX = x; + slotTexY = y; + + return this; + } + + @Override + public TabBiomeOverlay build() { + return new TabBiomeOverlay(this); + } + } +} diff --git a/src/main/java/mrjake/aunis/gui/element/TabSideEnum.java b/src/main/java/mrjake/aunis/gui/element/TabSideEnum.java new file mode 100644 index 00000000..5c2e7604 --- /dev/null +++ b/src/main/java/mrjake/aunis/gui/element/TabSideEnum.java @@ -0,0 +1,20 @@ +package mrjake.aunis.gui.element; + +/** + * Describes on which side the tab is. + * + * @author MrJake222 + * + */ +public enum TabSideEnum { + LEFT, + RIGHT; + + public boolean right() { + return this == RIGHT; + } + + public boolean left() { + return this == LEFT; + } +} diff --git a/src/main/java/mrjake/aunis/gui/element/TabbedContainerInterface.java b/src/main/java/mrjake/aunis/gui/element/TabbedContainerInterface.java new file mode 100644 index 00000000..ce58e223 --- /dev/null +++ b/src/main/java/mrjake/aunis/gui/element/TabbedContainerInterface.java @@ -0,0 +1,8 @@ +package mrjake.aunis.gui.element; + +import java.awt.Rectangle; +import java.util.List; + +public interface TabbedContainerInterface { + public List getGuiExtraAreas(); +} diff --git a/src/main/java/mrjake/aunis/integration/JEIAdvancedGuiHandler.java b/src/main/java/mrjake/aunis/integration/JEIAdvancedGuiHandler.java new file mode 100644 index 00000000..9ac0a66f --- /dev/null +++ b/src/main/java/mrjake/aunis/integration/JEIAdvancedGuiHandler.java @@ -0,0 +1,25 @@ +package mrjake.aunis.integration; + +import java.awt.Rectangle; +import java.util.List; + +import mezz.jei.api.gui.IAdvancedGuiHandler; +import mrjake.aunis.gui.element.TabbedContainerInterface; +import net.minecraft.client.gui.inventory.GuiContainer; + +public class JEIAdvancedGuiHandler implements IAdvancedGuiHandler { + + @Override + public Class getGuiContainerClass() { + return GuiContainer.class; + } + + @Override + public List getGuiExtraAreas(GuiContainer guiContainer) { + if (guiContainer instanceof TabbedContainerInterface) { + return ((TabbedContainerInterface) guiContainer).getGuiExtraAreas(); + } + + return null; + } +} diff --git a/src/main/java/mrjake/aunis/integration/JEIIntegration.java b/src/main/java/mrjake/aunis/integration/JEIIntegration.java index 3f889bd8..6d130e7c 100644 --- a/src/main/java/mrjake/aunis/integration/JEIIntegration.java +++ b/src/main/java/mrjake/aunis/integration/JEIIntegration.java @@ -19,6 +19,9 @@ public JEIIntegration(){} public void register(IModRegistry registry) { // Hide invisible block in JEI registry.getJeiHelpers().getIngredientBlacklist().addIngredientToBlacklist(new ItemStack(AunisBlocks.INVISIBLE_BLOCK, 1, OreDictionary.WILDCARD_VALUE)); + + // Tab handling + registry.addAdvancedGuiHandlers(new JEIAdvancedGuiHandler()); } @Override diff --git a/src/main/java/mrjake/aunis/packet/SetOpenTabToServer.java b/src/main/java/mrjake/aunis/packet/SetOpenTabToServer.java index 0b1a0968..3f3abef8 100644 --- a/src/main/java/mrjake/aunis/packet/SetOpenTabToServer.java +++ b/src/main/java/mrjake/aunis/packet/SetOpenTabToServer.java @@ -1,7 +1,7 @@ package mrjake.aunis.packet; import io.netty.buffer.ByteBuf; -import mrjake.aunis.gui.container.StargateContainer; +import mrjake.aunis.gui.container.OpenTabHolderInterface; import net.minecraft.inventory.Container; import net.minecraftforge.fml.common.network.simpleimpl.IMessage; import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; @@ -33,8 +33,8 @@ public static class SetOpenTabServerHandler implements IMessageHandler= AunisConfig.dhdConfig.deactivationLevel) // Client // Each 2s check for the sky - if (world.getTotalWorldTime() % 40 == 0 && rendererStateClient != null) { - rendererStateClient.biomeOverlay = BiomeOverlayEnum.updateBiomeOverlay(world, pos, SUPPORTED_OVERLAYS); + if (world.getTotalWorldTime() % 40 == 0 && rendererStateClient != null && getRendererStateClient().biomeOverride == null) { + rendererStateClient.setBiomeOverlay(BiomeOverlayEnum.updateBiomeOverlay(world, pos, SUPPORTED_OVERLAYS)); } } } + // Server + private BiomeOverlayEnum determineBiomeOverride() { + ItemStack stack = itemStackHandler.getStackInSlot(BIOME_OVERRIDE_SLOT); + + if (stack.isEmpty()) { + return null; + } + + BiomeOverlayEnum biomeOverlay = AunisConfig.stargateConfig.getBiomeOverrideItemMetaPairs().get(new ItemMetaPair(stack)); + + if (getSupportedOverlays().contains(biomeOverlay)) { + return biomeOverlay; + } + + return null; + } + public static final EnumSet SUPPORTED_OVERLAYS = EnumSet.of( BiomeOverlayEnum.NORMAL, BiomeOverlayEnum.FROST, BiomeOverlayEnum.MOSSY, BiomeOverlayEnum.SOOTY); + public static EnumSet getSupportedOverlays() { + return SUPPORTED_OVERLAYS; + } + private boolean hadControlCrystal; public boolean hasControlCrystal() { @@ -203,9 +227,7 @@ private void updateCrystal() { if (hadControlCrystal != hasControlCrystal) { if (hasControlCrystal) { - if (targetPoint != null) { - AunisPacketHandler.INSTANCE.sendToAllTracking(new StateUpdatePacketToClient(pos, StateTypeEnum.RENDERER_STATE, getState(StateTypeEnum.RENDERER_STATE)), targetPoint); - } + sendState(StateTypeEnum.RENDERER_STATE, getState(StateTypeEnum.RENDERER_STATE)); } else { @@ -234,23 +256,29 @@ public void activateSymbol(SymbolMilkyWayEnum symbol) { world.notifyNeighborsOfStateChange(pos, AunisBlocks.DHD_BLOCK, true); - if (targetPoint != null) { - AunisPacketHandler.INSTANCE.sendToAllTracking(new StateUpdatePacketToClient(pos, StateTypeEnum.DHD_ACTIVATE_BUTTON, new DHDActivateButtonState(symbol)), targetPoint); - } + sendState(StateTypeEnum.DHD_ACTIVATE_BUTTON, new DHDActivateButtonState(symbol)); } public void clearSymbols() { world.notifyNeighborsOfStateChange(pos, AunisBlocks.DHD_BLOCK, true); - - if (targetPoint != null) { - AunisPacketHandler.INSTANCE.sendToAllTracking(new StateUpdatePacketToClient(pos, StateTypeEnum.DHD_ACTIVATE_BUTTON, new DHDActivateButtonState(true)), targetPoint); - } + + sendState(StateTypeEnum.DHD_ACTIVATE_BUTTON, new DHDActivateButtonState(true)); } // ----------------------------------------------------------------------------- // States + protected void sendState(StateTypeEnum type, State state) { + if (targetPoint != null) { + AunisPacketHandler.INSTANCE.sendToAllTracking(new StateUpdatePacketToClient(pos, type, state), targetPoint); + } + + else { + Aunis.logger.debug("targetPoint was null trying to send " + type + " from " + this.getClass().getCanonicalName()); + } + } + @Override public State getState(StateTypeEnum stateType) { switch (stateType) { @@ -277,10 +305,10 @@ public State getState(StateTypeEnum stateType) { break; } - return new DHDRendererState(address, brbActive); + return new DHDRendererState(address, brbActive, determineBiomeOverride()); } - return new DHDRendererState(address, false); + return new DHDRendererState(address, false, determineBiomeOverride()); default: throw new UnsupportedOperationException("EnumStateType."+stateType.name()+" not implemented on "+this.getClass().getName()); @@ -299,6 +327,9 @@ public State createState(StateTypeEnum stateType) { case GUI_UPDATE: return new DHDContainerGuiUpdate(); + case BIOME_OVERRIDE_STATE: + return new StargateBiomeOverrideState(); + default: throw new UnsupportedOperationException("EnumStateType."+stateType.name()+" not implemented on "+this.getClass().getName()); } @@ -311,8 +342,7 @@ public void setState(StateTypeEnum stateType, State state) { switch (stateType) { case RENDERER_STATE: float horizontalRotation = world.getBlockState(pos).getValue(AunisProps.ROTATION_HORIZONTAL) * -22.5f; - rendererStateClient = ((DHDRendererState) state).initClient(pos, horizontalRotation); - rendererStateClient.biomeOverlay = BiomeOverlayEnum.updateBiomeOverlay(world, pos, SUPPORTED_OVERLAYS); + rendererStateClient = ((DHDRendererState) state).initClient(pos, horizontalRotation, BiomeOverlayEnum.updateBiomeOverlay(world, pos, SUPPORTED_OVERLAYS)); break; @@ -336,6 +366,15 @@ public void setState(StateTypeEnum stateType, State state) { break; + case BIOME_OVERRIDE_STATE: + StargateBiomeOverrideState overrideState = (StargateBiomeOverrideState) state; + + if (rendererStateClient != null) { + getRendererStateClient().biomeOverride = overrideState.biomeOverride; + } + + break; + default: throw new UnsupportedOperationException("EnumStateType."+stateType.name()+" not implemented on "+this.getClass().getName()); } @@ -348,7 +387,9 @@ public void setState(StateTypeEnum stateType, State state) { public static final List SUPPORTED_UPGRADES = Arrays.asList( AunisItems.CRYSTAL_GLYPH_DHD); - private final ItemStackHandler itemStackHandler = new ItemStackHandler(5) { + public static final int BIOME_OVERRIDE_SLOT = 5; + + private final ItemStackHandler itemStackHandler = new AunisItemStackHandler(6) { @Override public boolean isItemValid(int slot, ItemStack stack) { @@ -364,6 +405,13 @@ public boolean isItemValid(int slot, ItemStack stack) { case 4: return SUPPORTED_UPGRADES.contains(item) && upgradeInstalledCount(item) == 0; + case BIOME_OVERRIDE_SLOT: + BiomeOverlayEnum override = AunisConfig.stargateConfig.getBiomeOverrideItemMetaPairs().get(new ItemMetaPair(stack)); + if (override == null) + return false; + + return getSupportedOverlays().contains(override); + default: return true; } @@ -398,8 +446,16 @@ public ItemStack extractItem(int slot, int amount, boolean simulate) { @Override protected void onContentsChanged(int slot) { - super.onContentsChanged(slot); + switch (slot) { + case BIOME_OVERRIDE_SLOT: + sendState(StateTypeEnum.BIOME_OVERRIDE_STATE, new StargateBiomeOverrideState(determineBiomeOverride())); + break; + + default: + break; + } + super.onContentsChanged(slot); markDirty(); } }; diff --git a/src/main/java/mrjake/aunis/tileentity/stargate/StargateAbstractBaseTile.java b/src/main/java/mrjake/aunis/tileentity/stargate/StargateAbstractBaseTile.java index ef6e4622..5d5fbb31 100644 --- a/src/main/java/mrjake/aunis/tileentity/stargate/StargateAbstractBaseTile.java +++ b/src/main/java/mrjake/aunis/tileentity/stargate/StargateAbstractBaseTile.java @@ -187,8 +187,17 @@ public boolean canAcceptConnectionFrom(StargatePos targetGatePos) { } protected void sendRenderingUpdate(EnumGateAction gateAction, int chevronCount, boolean modifyFinal) { + sendState(StateTypeEnum.RENDERER_UPDATE, new StargateRendererActionState(gateAction, chevronCount, modifyFinal)); + } + + // TODO Convert to using this + protected void sendState(StateTypeEnum type, State state) { if (targetPoint != null) { - AunisPacketHandler.INSTANCE.sendToAllTracking(new StateUpdatePacketToClient(pos, StateTypeEnum.RENDERER_UPDATE, new StargateRendererActionState(gateAction, chevronCount, modifyFinal)), targetPoint); + AunisPacketHandler.INSTANCE.sendToAllTracking(new StateUpdatePacketToClient(pos, type, state), targetPoint); + } + + else { + Aunis.logger.debug("targetPoint was null trying to send " + type + " from " + this.getClass().getCanonicalName()); } } @@ -794,18 +803,9 @@ public void update() { energyTransferedLastTick = getEnergyStorage().getEnergyStored() - energyStoredLastTick; energyStoredLastTick = getEnergyStorage().getEnergyStored(); } - - else { - // Client - - // Each 2s check for the sky - if (world.getTotalWorldTime() % 40 == 0 && rendererStateClient != null) { - rendererStateClient.biomeOverlay = BiomeOverlayEnum.updateBiomeOverlay(world, getMergeHelper().getTopBlock().add(pos), getSupportedOverlays()); - } - } } - protected abstract EnumSet getSupportedOverlays(); + public abstract EnumSet getSupportedOverlays(); /** * Method for closing the gate using Autoclose mechanism. @@ -1114,8 +1114,7 @@ public void setState(StateTypeEnum stateType, State state) { case RENDERER_STATE: EnumFacing facing = world.getBlockState(pos).getValue(AunisProps.FACING_HORIZONTAL); - setRendererStateClient(((StargateAbstractRendererState) state).initClient(pos, facing)); - rendererStateClient.biomeOverlay = BiomeOverlayEnum.updateBiomeOverlay(world, pos, getSupportedOverlays()); + setRendererStateClient(((StargateAbstractRendererState) state).initClient(pos, facing, BiomeOverlayEnum.updateBiomeOverlay(world, pos, getSupportedOverlays()))); updateFacing(facing, false); diff --git a/src/main/java/mrjake/aunis/tileentity/stargate/StargateClassicBaseTile.java b/src/main/java/mrjake/aunis/tileentity/stargate/StargateClassicBaseTile.java index 4ba22e2a..2754a601 100644 --- a/src/main/java/mrjake/aunis/tileentity/stargate/StargateClassicBaseTile.java +++ b/src/main/java/mrjake/aunis/tileentity/stargate/StargateClassicBaseTile.java @@ -15,12 +15,14 @@ import mrjake.aunis.Aunis; import mrjake.aunis.beamer.BeamerLinkingHelper; import mrjake.aunis.block.AunisBlocks; +import mrjake.aunis.config.AunisConfig; import mrjake.aunis.gui.container.StargateContainerGuiState; import mrjake.aunis.gui.container.StargateContainerGuiUpdate; import mrjake.aunis.item.AunisItems; import mrjake.aunis.item.notebook.PageNotebookItem; import mrjake.aunis.packet.AunisPacketHandler; import mrjake.aunis.packet.StateUpdatePacketToClient; +import mrjake.aunis.renderer.biomes.BiomeOverlayEnum; import mrjake.aunis.renderer.stargate.StargateClassicRendererState; import mrjake.aunis.renderer.stargate.StargateClassicRendererState.StargateClassicRendererStateBuilder; import mrjake.aunis.sound.StargateSoundEventEnum; @@ -38,6 +40,7 @@ import mrjake.aunis.stargate.power.StargateAbstractEnergyStorage; import mrjake.aunis.stargate.power.StargateClassicEnergyStorage; import mrjake.aunis.stargate.power.StargateEnergyRequired; +import mrjake.aunis.state.StargateBiomeOverrideState; import mrjake.aunis.state.StargateRendererActionState; import mrjake.aunis.state.StargateRendererActionState.EnumGateAction; import mrjake.aunis.state.StargateSpinState; @@ -47,10 +50,12 @@ import mrjake.aunis.tileentity.util.IUpgradable; import mrjake.aunis.tileentity.util.ScheduledTask; import mrjake.aunis.util.AunisAxisAlignedBB; +import mrjake.aunis.util.AunisItemStackHandler; import mrjake.aunis.util.EnumKeyInterface; import mrjake.aunis.util.EnumKeyMap; import mrjake.aunis.util.FacingToRotation; import mrjake.aunis.util.ItemHandlerHelper; +import mrjake.aunis.util.ItemMetaPair; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTBase; @@ -65,7 +70,6 @@ import net.minecraftforge.energy.CapabilityEnergy; import net.minecraftforge.fml.common.Optional; import net.minecraftforge.items.CapabilityItemHandler; -import net.minecraftforge.items.ItemStackHandler; /** * This class wraps common behavior for the fully-functional Stargates i.e. @@ -167,7 +171,7 @@ protected void onGateMerged() { // ------------------------------------------------------------------------ // Loading and ticking - + @Override public void onLoad() { super.onLoad(); @@ -208,6 +212,7 @@ public void update() { } else { + // Client // Aunis.info("lock: " + lockPage); if (lockPage && itemStackHandler.getStackInSlot(pageSlotId).isEmpty()) { @@ -228,10 +233,32 @@ public void update() { } } } + + // Each 2s check for the biome overlay + if (world.getTotalWorldTime() % 40 == 0 && rendererStateClient != null && getRendererStateClient().biomeOverride == null) { + rendererStateClient.setBiomeOverlay(BiomeOverlayEnum.updateBiomeOverlay(world, getMergeHelper().getTopBlock().add(pos), getSupportedOverlays())); + } } } } + // Server + private BiomeOverlayEnum determineBiomeOverride() { + ItemStack stack = itemStackHandler.getStackInSlot(BIOME_OVERRIDE_SLOT); + + if (stack.isEmpty()) { + return null; + } + + BiomeOverlayEnum biomeOverlay = AunisConfig.stargateConfig.getBiomeOverrideItemMetaPairs().get(new ItemMetaPair(stack)); + + if (getSupportedOverlays().contains(biomeOverlay)) { + return biomeOverlay; + } + + return null; + } + @Override protected boolean shouldAutoclose() { boolean beamerActive = false; @@ -281,7 +308,7 @@ public void readFromNBT(NBTTagCompound compound) { if (compound.getBoolean("hasUpgrade")) { itemStackHandler.setStackInSlot(0, new ItemStack(AunisItems.CRYSTAL_GLYPH_STARGATE)); } - + isFinalActive = compound.getBoolean("isFinalActive"); isSpinning = compound.getBoolean("isSpinning"); @@ -317,7 +344,7 @@ protected void updateChevronLight(int lightUp, boolean isFinalActive) { } @Override - protected StargateClassicRendererStateBuilder getRendererStateServer() { + protected StargateClassicRendererStateBuilder getRendererStateServer() { return new StargateClassicRendererStateBuilder(super.getRendererStateServer()) .setSymbolType(getSymbolType()) .setActiveChevrons(dialedAddress.size()) @@ -326,7 +353,8 @@ protected StargateClassicRendererStateBuilder getRendererStateServer() { .setSpinDirection(spinDirection) .setSpinning(isSpinning) .setTargetRingSymbol(targetRingSymbol) - .setSpinStartTime(spinStartTime); + .setSpinStartTime(spinStartTime) + .setBiomeOverride(determineBiomeOverride()); } @Override @@ -370,6 +398,9 @@ public State createState(StateTypeEnum stateType) { case SPIN_STATE: return new StargateSpinState(); + case BIOME_OVERRIDE_STATE: + return new StargateBiomeOverrideState(); + default: return super.createState(stateType); } @@ -439,6 +470,15 @@ public void setState(StateTypeEnum stateType, State state) { break; + case BIOME_OVERRIDE_STATE: + StargateBiomeOverrideState overrideState = (StargateBiomeOverrideState) state; + + if (rendererStateClient != null) { + getRendererStateClient().biomeOverride = overrideState.biomeOverride; + } + + break; + default: break; } @@ -567,7 +607,9 @@ public void setPageProgress(int pageProgress) { // ----------------------------------------------------------------------------- // Item handler - private final ItemStackHandler itemStackHandler = new ItemStackHandler(10) { + public static final int BIOME_OVERRIDE_SLOT = 10; + + private final AunisItemStackHandler itemStackHandler = new AunisItemStackHandler(11) { @Override public boolean isItemValid(int slot, ItemStack stack) { @@ -592,6 +634,13 @@ public boolean isItemValid(int slot, ItemStack stack) { case 9: return item == AunisItems.PAGE_NOTEBOOK_ITEM || item == AunisItems.UNIVERSE_DIALER; + case BIOME_OVERRIDE_SLOT: + BiomeOverlayEnum override = AunisConfig.stargateConfig.getBiomeOverrideItemMetaPairs().get(new ItemMetaPair(stack)); + if (override == null) + return false; + + return getSupportedOverlays().contains(override); + default: return true; } @@ -612,7 +661,11 @@ protected void onContentsChanged(int slot) { case 6: updatePowerTier(); break; - + + case BIOME_OVERRIDE_SLOT: + sendState(StateTypeEnum.BIOME_OVERRIDE_STATE, new StargateBiomeOverrideState(determineBiomeOverride())); + break; + default: break; } diff --git a/src/main/java/mrjake/aunis/tileentity/stargate/StargateMilkyWayBaseTile.java b/src/main/java/mrjake/aunis/tileentity/stargate/StargateMilkyWayBaseTile.java index 543bcb7e..71b73bce 100644 --- a/src/main/java/mrjake/aunis/tileentity/stargate/StargateMilkyWayBaseTile.java +++ b/src/main/java/mrjake/aunis/tileentity/stargate/StargateMilkyWayBaseTile.java @@ -339,7 +339,7 @@ public void update() { BiomeOverlayEnum.SOOTY); @Override - protected EnumSet getSupportedOverlays() { + public EnumSet getSupportedOverlays() { return SUPPORTED_OVERLAYS; } diff --git a/src/main/java/mrjake/aunis/tileentity/stargate/StargateOrlinBaseTile.java b/src/main/java/mrjake/aunis/tileentity/stargate/StargateOrlinBaseTile.java index 07935e99..a87c6db6 100644 --- a/src/main/java/mrjake/aunis/tileentity/stargate/StargateOrlinBaseTile.java +++ b/src/main/java/mrjake/aunis/tileentity/stargate/StargateOrlinBaseTile.java @@ -177,6 +177,11 @@ public void update() { if (world.isRemote) { if (!world.getBlockState(pos).getValue(AunisProps.RENDER_BLOCK) && rendererStateClient != null) Aunis.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())); + } } } @@ -186,7 +191,7 @@ public void update() { BiomeOverlayEnum.MOSSY); @Override - protected EnumSet getSupportedOverlays() { + public EnumSet getSupportedOverlays() { return SUPPORTED_OVERLAYS; } diff --git a/src/main/java/mrjake/aunis/tileentity/stargate/StargateUniverseBaseTile.java b/src/main/java/mrjake/aunis/tileentity/stargate/StargateUniverseBaseTile.java index f6d530b5..ae6f714f 100644 --- a/src/main/java/mrjake/aunis/tileentity/stargate/StargateUniverseBaseTile.java +++ b/src/main/java/mrjake/aunis/tileentity/stargate/StargateUniverseBaseTile.java @@ -134,7 +134,7 @@ protected int getOpenSoundDelay() { BiomeOverlayEnum.AGED); @Override - protected EnumSet getSupportedOverlays() { + public EnumSet getSupportedOverlays() { return SUPPORTED_OVERLAYS; } diff --git a/src/main/java/mrjake/aunis/util/AunisItemStackHandler.java b/src/main/java/mrjake/aunis/util/AunisItemStackHandler.java new file mode 100644 index 00000000..ce63ae15 --- /dev/null +++ b/src/main/java/mrjake/aunis/util/AunisItemStackHandler.java @@ -0,0 +1,35 @@ +package mrjake.aunis.util; + +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraftforge.common.util.Constants; +import net.minecraftforge.items.ItemStackHandler; + +/** + * Modified version of {@link ItemStackHandler}. + * Respects resizing of the item handlers. + */ +public class AunisItemStackHandler extends ItemStackHandler { + + public AunisItemStackHandler(int size) { + super(size); + } + + @Override + public void deserializeNBT(NBTTagCompound nbt) + { + NBTTagList tagList = nbt.getTagList("Items", Constants.NBT.TAG_COMPOUND); + for (int i = 0; i < tagList.tagCount(); i++) + { + NBTTagCompound itemTags = tagList.getCompoundTagAt(i); + int slot = itemTags.getInteger("Slot"); + + if (slot >= 0 && slot < stacks.size()) + { + stacks.set(slot, new ItemStack(itemTags)); + } + } + onLoad(); + } +} diff --git a/src/main/java/mrjake/aunis/util/ItemMetaPair.java b/src/main/java/mrjake/aunis/util/ItemMetaPair.java new file mode 100644 index 00000000..95469d6c --- /dev/null +++ b/src/main/java/mrjake/aunis/util/ItemMetaPair.java @@ -0,0 +1,66 @@ +package mrjake.aunis.util; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +/** + * Basically a simplified {@link ItemStack} with {@code equals} and {@code hashCode}. + * + * @author MrJake222 + * + */ +public class ItemMetaPair { + + private final Item item; + private final int meta; + + public ItemMetaPair(Item item, int meta) { + this.item = item; + this.meta = meta; + } + + public ItemMetaPair(ItemStack stack) { + this(stack.getItem(), stack.getMetadata()); + } + + + public String getDisplayName() { + return item.getItemStackDisplayName(new ItemStack(item, 1, meta)); + } + + public boolean equalsItemStack(ItemStack stack) { + if (item != stack.getItem()) + return false; + + if (meta != stack.getMetadata()) + return false; + + return true; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((item == null) ? 0 : item.hashCode()); + result = prime * result + meta; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!(obj instanceof ItemMetaPair)) + return false; + ItemMetaPair other = (ItemMetaPair) obj; + if (item == null) { + if (other.item != null) + return false; + } else if (item != other.item) // Items are singletons + return false; + if (meta != other.meta) + return false; + return true; + } +} diff --git a/src/main/resources/assets/aunis/lang/en_us.lang b/src/main/resources/assets/aunis/lang/en_us.lang index fd2106da..c4146246 100644 --- a/src/main/resources/assets/aunis/lang/en_us.lang +++ b/src/main/resources/assets/aunis/lang/en_us.lang @@ -256,6 +256,8 @@ gui.dhd.no_fuel=No fuel gui.stargate.milky_way_address=Milky Way address gui.stargate.pegasus_address=Pegasus address gui.stargate.universe_address=Universe address +gui.stargate.biome_overlay=Biome overlay +gui.stargate.biome_overlay.help=Insert blocks to override gui.stargate.capacitors=Capacitors gui.stargate.energyBuffer=Energy buffer diff --git a/src/main/resources/assets/aunis/textures/gui/container_dhd.png b/src/main/resources/assets/aunis/textures/gui/container_dhd.png index f30d2bae..b58edf38 100644 Binary files a/src/main/resources/assets/aunis/textures/gui/container_dhd.png and b/src/main/resources/assets/aunis/textures/gui/container_dhd.png differ diff --git a/src/main/resources/assets/aunis/textures/gui/container_stargate.png b/src/main/resources/assets/aunis/textures/gui/container_stargate.png index a2dc7ef6..8a320445 100644 Binary files a/src/main/resources/assets/aunis/textures/gui/container_stargate.png and b/src/main/resources/assets/aunis/textures/gui/container_stargate.png differ