From 011f97e592c02ca6d4808dea2c803a4829f08dff Mon Sep 17 00:00:00 2001 From: slava_110 Date: Fri, 22 Jan 2021 01:06:04 +0300 Subject: [PATCH] Merged slava's fix --- .../aunis/gui/container/DHDContainer.java | 2 +- .../gui/container/StargateContainer.java | 2 +- .../aunis/gui/element/TabBiomeOverlay.java | 5 ---- .../java/mrjake/aunis/tileentity/DHDTile.java | 23 ++++++------------- .../stargate/StargateAbstractBaseTile.java | 2 +- .../stargate/StargateClassicBaseTile.java | 19 +++------------ .../stargate/StargateMilkyWayBaseTile.java | 13 +++-------- .../aunis/tileentity/util/IUpgradable.java | 19 +++++++++++++++ 8 files changed, 35 insertions(+), 50 deletions(-) diff --git a/src/main/java/mrjake/aunis/gui/container/DHDContainer.java b/src/main/java/mrjake/aunis/gui/container/DHDContainer.java index 473d43b0..c02c962a 100644 --- a/src/main/java/mrjake/aunis/gui/container/DHDContainer.java +++ b/src/main/java/mrjake/aunis/gui/container/DHDContainer.java @@ -101,7 +101,7 @@ public ItemStack transferStackInSlot(EntityPlayer player, int index) { } } - else if (DHDTile.SUPPORTED_UPGRADES.contains(stack.getItem()) && dhdTile.upgradeInstalledCount(stack.getItem()) == 0) { + else if (DHDTile.SUPPORTED_UPGRADES.contains(stack.getItem()) && !dhdTile.hasUpgrade(stack.getItem())) { for (int i=1; i<5; i++) { if (!getSlot(i).getHasStack()) { ItemStack stack1 = stack.copy(); diff --git a/src/main/java/mrjake/aunis/gui/container/StargateContainer.java b/src/main/java/mrjake/aunis/gui/container/StargateContainer.java index 30026ba7..f0b5a5c7 100644 --- a/src/main/java/mrjake/aunis/gui/container/StargateContainer.java +++ b/src/main/java/mrjake/aunis/gui/container/StargateContainer.java @@ -113,7 +113,7 @@ public ItemStack transferStackInSlot(EntityPlayer player, int index) { } } - else if (StargateUpgradeEnum.contains(stack.getItem()) && !gateTile.hasUpgradeInstalled(stack.getItem())) { + else if (StargateUpgradeEnum.contains(stack.getItem()) && !gateTile.hasUpgrade(stack.getItem())) { for (int i=0; i<4; i++) { if (!getSlot(i).getHasStack()) { ItemStack stack1 = stack.copy(); diff --git a/src/main/java/mrjake/aunis/gui/element/TabBiomeOverlay.java b/src/main/java/mrjake/aunis/gui/element/TabBiomeOverlay.java index c56f400d..d6567e4e 100644 --- a/src/main/java/mrjake/aunis/gui/element/TabBiomeOverlay.java +++ b/src/main/java/mrjake/aunis/gui/element/TabBiomeOverlay.java @@ -40,11 +40,6 @@ public void render(FontRenderer fontRenderer, int mouseX, int mouseY) { 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 diff --git a/src/main/java/mrjake/aunis/tileentity/DHDTile.java b/src/main/java/mrjake/aunis/tileentity/DHDTile.java index 73e8ef70..78364d97 100644 --- a/src/main/java/mrjake/aunis/tileentity/DHDTile.java +++ b/src/main/java/mrjake/aunis/tileentity/DHDTile.java @@ -30,6 +30,7 @@ import mrjake.aunis.tileentity.util.IUpgradable; import mrjake.aunis.tileentity.util.ReactorStateEnum; import mrjake.aunis.util.AunisItemStackHandler; +import mrjake.aunis.util.EnumKeyInterface; import mrjake.aunis.util.ILinkable; import mrjake.aunis.util.ItemMetaPair; import net.minecraft.block.state.IBlockState; @@ -403,7 +404,7 @@ public boolean isItemValid(int slot, ItemStack stack) { case 2: case 3: case 4: - return SUPPORTED_UPGRADES.contains(item) && upgradeInstalledCount(item) == 0; + return SUPPORTED_UPGRADES.contains(item) && !hasUpgrade(item); case BIOME_OVERRIDE_SLOT: BiomeOverlayEnum override = AunisConfig.stargateConfig.getBiomeOverrideItemMetaPairs().get(new ItemMetaPair(stack)); @@ -460,30 +461,20 @@ protected void onContentsChanged(int slot) { } }; - public static enum DHDUpgradeEnum { + // TODO Get rid of EnumKeyInterface + public static enum DHDUpgradeEnum implements EnumKeyInterface { CHEVRON_UPGRADE(AunisItems.CRYSTAL_GLYPH_DHD); public Item item; private DHDUpgradeEnum(Item item) { this.item = item; - } - } - public int upgradeInstalledCount(DHDUpgradeEnum upgrade) { - return upgradeInstalledCount(upgrade.item); - } - - public int upgradeInstalledCount(Item upgrade) { - int count = 0; - - for (int slot=1; slot<5; slot++) { - if (itemStackHandler.getStackInSlot(slot).getItem() == upgrade) - count++; + @Override + public Item getKey() { + return item; } - - return count; } // ----------------------------------------------------------------------------- diff --git a/src/main/java/mrjake/aunis/tileentity/stargate/StargateAbstractBaseTile.java b/src/main/java/mrjake/aunis/tileentity/stargate/StargateAbstractBaseTile.java index 5d5fbb31..5d7b8523 100644 --- a/src/main/java/mrjake/aunis/tileentity/stargate/StargateAbstractBaseTile.java +++ b/src/main/java/mrjake/aunis/tileentity/stargate/StargateAbstractBaseTile.java @@ -190,7 +190,7 @@ protected void sendRenderingUpdate(EnumGateAction gateAction, int chevronCount, sendState(StateTypeEnum.RENDERER_UPDATE, new StargateRendererActionState(gateAction, chevronCount, modifyFinal)); } - // TODO Convert to using this + // TODO Convert to using sendState protected void sendState(StateTypeEnum type, State state) { if (targetPoint != null) { AunisPacketHandler.INSTANCE.sendToAllTracking(new StateUpdatePacketToClient(pos, type, state), targetPoint); diff --git a/src/main/java/mrjake/aunis/tileentity/stargate/StargateClassicBaseTile.java b/src/main/java/mrjake/aunis/tileentity/stargate/StargateClassicBaseTile.java index 2754a601..e53891f9 100644 --- a/src/main/java/mrjake/aunis/tileentity/stargate/StargateClassicBaseTile.java +++ b/src/main/java/mrjake/aunis/tileentity/stargate/StargateClassicBaseTile.java @@ -510,7 +510,7 @@ public void executeTask(EnumScheduledTask scheduledTask, NBTTagCompound customDa if (stack.getItem() == AunisItems.UNIVERSE_DIALER) { NBTTagList saved = stack.getTagCompound().getTagList("saved", NBT.TAG_COMPOUND); NBTTagCompound compound = gateAddressMap.get(symbolType).serializeNBT(); - compound.setBoolean("hasUpgrade", hasUpgradeInstalled(StargateUpgradeEnum.CHEVRON_UPGRADE)); + compound.setBoolean("hasUpgrade", hasUpgrade(StargateUpgradeEnum.CHEVRON_UPGRADE)); saved.appendTag(compound); } @@ -519,7 +519,7 @@ public void executeTask(EnumScheduledTask scheduledTask, NBTTagCompound customDa NBTTagCompound compound = PageNotebookItem.getCompoundFromAddress( gateAddressMap.get(symbolType), - hasUpgradeInstalled(StargateUpgradeEnum.CHEVRON_UPGRADE), + hasUpgrade(StargateUpgradeEnum.CHEVRON_UPGRADE), PageNotebookItem.getRegistryPathFromWorld(world, pos)); stack = new ItemStack(AunisItems.PAGE_NOTEBOOK_ITEM, 1, 1); @@ -620,7 +620,7 @@ public boolean isItemValid(int slot, ItemStack stack) { case 1: case 2: case 3: - return StargateUpgradeEnum.contains(item) && !hasUpgradeInstalled(item); + return StargateUpgradeEnum.contains(item) && !hasUpgrade(item); case 4: case 5: @@ -701,19 +701,6 @@ public static boolean contains(Item item) { return idMap.contains(item); } } - - public boolean hasUpgradeInstalled(StargateUpgradeEnum upgrade) { - return hasUpgradeInstalled(upgrade.item); - } - - public boolean hasUpgradeInstalled(Item upgrade) { - for (int slot=0; slot<4; slot++) { - if (itemStackHandler.getStackInSlot(slot).getItem() == upgrade) - return true; - } - - return false; - } @Override public Iterator getUpgradeSlotsIterator() { diff --git a/src/main/java/mrjake/aunis/tileentity/stargate/StargateMilkyWayBaseTile.java b/src/main/java/mrjake/aunis/tileentity/stargate/StargateMilkyWayBaseTile.java index 71b73bce..5406ce08 100644 --- a/src/main/java/mrjake/aunis/tileentity/stargate/StargateMilkyWayBaseTile.java +++ b/src/main/java/mrjake/aunis/tileentity/stargate/StargateMilkyWayBaseTile.java @@ -111,17 +111,10 @@ public void addSymbolToAddressDHD(SymbolMilkyWayEnum symbol) { markDirty(); } - + + @Override protected int getMaxChevrons() { - if (isLinkedAndDHDOperational() && stargateState != EnumStargateState.DIALING_COMPUTER) { - switch (getLinkedDHD(world).upgradeInstalledCount(DHDUpgradeEnum.CHEVRON_UPGRADE)) { - case 0: return 7; - case 1: return 8; - case 2: return 9; - } - } - - return 9; + return isLinkedAndDHDOperational() && stargateState != EnumStargateState.DIALING_COMPUTER && !getLinkedDHD(world).hasUpgrade(DHDUpgradeEnum.CHEVRON_UPGRADE) ? 7 : 9; } @Override diff --git a/src/main/java/mrjake/aunis/tileentity/util/IUpgradable.java b/src/main/java/mrjake/aunis/tileentity/util/IUpgradable.java index 1d825170..fd39bc80 100644 --- a/src/main/java/mrjake/aunis/tileentity/util/IUpgradable.java +++ b/src/main/java/mrjake/aunis/tileentity/util/IUpgradable.java @@ -3,7 +3,9 @@ import java.util.Iterator; import java.util.stream.IntStream; +import mrjake.aunis.util.EnumKeyInterface; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; @@ -23,6 +25,23 @@ public default IItemHandler getItemHandler() { return getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); } + public default boolean hasUpgrade(EnumKeyInterface upgrade) { + return hasUpgrade(upgrade.getKey()); + } + + public default boolean hasUpgrade(Item item) { + final IItemHandler itemHandler = getItemHandler(); + final Iterator iter = getUpgradeSlotsIterator(); + + while (iter.hasNext()) { + int slot = iter.next(); + if(itemHandler.getStackInSlot(slot).getItem() == item) { + return true; + } + } + return false; + } + /** * Get upgrade slot iterator. Used in interface. You can use `IntStream.range(min, max).iterator()` * @return upgrade slot iterator