Skip to content
This repository has been archived by the owner on Nov 7, 2023. It is now read-only.

Commit

Permalink
Merged slava's fix
Browse files Browse the repository at this point in the history
  • Loading branch information
slava110 authored and MrJake222 committed Feb 1, 2021
1 parent 42504d7 commit 011f97e
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 50 deletions.
2 changes: 1 addition & 1 deletion src/main/java/mrjake/aunis/gui/container/DHDContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/mrjake/aunis/gui/element/TabBiomeOverlay.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 7 additions & 16 deletions src/main/java/mrjake/aunis/tileentity/DHDTile.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -460,30 +461,20 @@ protected void onContentsChanged(int slot) {
}
};

public static enum DHDUpgradeEnum {
// TODO Get rid of EnumKeyInterface
public static enum DHDUpgradeEnum implements EnumKeyInterface<Item> {
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;
}

// -----------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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<Integer> getUpgradeSlotsIterator() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/mrjake/aunis/tileentity/util/IUpgradable.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,6 +25,23 @@ public default IItemHandler getItemHandler() {
return getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
}

public default boolean hasUpgrade(EnumKeyInterface<Item> upgrade) {
return hasUpgrade(upgrade.getKey());
}

public default boolean hasUpgrade(Item item) {
final IItemHandler itemHandler = getItemHandler();
final Iterator<Integer> 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
Expand Down

0 comments on commit 011f97e

Please sign in to comment.