diff options
author | Raven Szewczyk <git@eigenraven.me> | 2024-07-26 10:26:18 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-26 10:26:18 +0100 |
commit | 2d09c1d5693de31bb500752a8dcc9074acecbd73 (patch) | |
tree | de00b34ed53ec860943afd1a5c72d5087d059f81 /src/main/java/gtPlusPlus/core | |
parent | 0cb32ba6d9f2acf9352af667fa7bcf311b011d9c (diff) | |
download | GT5-Unofficial-2d09c1d5693de31bb500752a8dcc9074acecbd73.tar.gz GT5-Unofficial-2d09c1d5693de31bb500752a8dcc9074acecbd73.tar.bz2 GT5-Unofficial-2d09c1d5693de31bb500752a8dcc9074acecbd73.zip |
Fix Lead Lined Box gui and add ModularUI2 as a dependency (#2767)
Diffstat (limited to 'src/main/java/gtPlusPlus/core')
6 files changed, 71 insertions, 223 deletions
diff --git a/src/main/java/gtPlusPlus/core/block/machine/DecayablesChest.java b/src/main/java/gtPlusPlus/core/block/machine/DecayablesChest.java index c333e7a5ca..16d038bea9 100644 --- a/src/main/java/gtPlusPlus/core/block/machine/DecayablesChest.java +++ b/src/main/java/gtPlusPlus/core/block/machine/DecayablesChest.java @@ -15,14 +15,14 @@ import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; +import com.cleanroommc.modularui.factory.TileEntityGuiFactory; + import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import gtPlusPlus.GTplusplus; import gtPlusPlus.api.interfaces.ITileTooltip; import gtPlusPlus.core.client.renderer.RenderDecayChest; import gtPlusPlus.core.creative.AddToCreativeTab; -import gtPlusPlus.core.handler.GuiHandler; import gtPlusPlus.core.item.base.itemblock.ItemBlockBasicTile; import gtPlusPlus.core.tileentities.general.TileEntityDecayablesChest; import gtPlusPlus.core.util.minecraft.InventoryUtils; @@ -43,8 +43,6 @@ public class DecayablesChest extends BlockContainer implements ITileTooltip { */ private final int mTooltipID = 5; - public final int field_149956_a = 0; - @Override public int getTooltipID() { return this.mTooltipID; @@ -94,18 +92,17 @@ public class DecayablesChest extends BlockContainer implements ITileTooltip { } /** - * Updates the blocks bounds based on its current state. Args: world, x, y, z + * Updates the blocks bounds based on its current state. */ @Override - public void setBlockBoundsBasedOnState(IBlockAccess p_149719_1_, int p_149719_2_, int p_149719_3_, - int p_149719_4_) { - if (p_149719_1_.getBlock(p_149719_2_, p_149719_3_, p_149719_4_ - 1) == this) { + public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) { + if (world.getBlock(x, y, z - 1) == this) { this.setBlockBounds(0.0625F, 0.0F, 0.0F, 0.9375F, 0.875F, 0.9375F); - } else if (p_149719_1_.getBlock(p_149719_2_, p_149719_3_, p_149719_4_ + 1) == this) { + } else if (world.getBlock(x, y, z + 1) == this) { this.setBlockBounds(0.0625F, 0.0F, 0.0625F, 0.9375F, 0.875F, 1.0F); - } else if (p_149719_1_.getBlock(p_149719_2_ - 1, p_149719_3_, p_149719_4_) == this) { + } else if (world.getBlock(x - 1, y, z) == this) { this.setBlockBounds(0.0F, 0.0F, 0.0625F, 0.9375F, 0.875F, 0.9375F); - } else if (p_149719_1_.getBlock(p_149719_2_ + 1, p_149719_3_, p_149719_4_) == this) { + } else if (world.getBlock(x + 1, y, z) == this) { this.setBlockBounds(0.0625F, 0.0F, 0.0625F, 1.0F, 0.875F, 0.9375F); } else { this.setBlockBounds(0.0625F, 0.0F, 0.0625F, 0.9375F, 0.875F, 0.9375F); @@ -118,7 +115,11 @@ public class DecayablesChest extends BlockContainer implements ITileTooltip { @Override @SideOnly(Side.CLIENT) public IIcon getIcon(final int ordinalSide, final int meta) { - return ordinalSide == 1 ? this.textureTop : (ordinalSide == 0 ? this.textureBottom : this.textureFront); + return switch (ordinalSide) { + case 0 -> textureBottom; + case 1 -> textureTop; + default -> textureFront; + }; } @Override @@ -130,19 +131,16 @@ public class DecayablesChest extends BlockContainer implements ITileTooltip { this.textureFront = p_149651_1_.registerIcon(GTPlusPlus.ID + ":" + "TileEntities/" + "DecayablesChest_bottom"); } - /** - * Called upon block activation (right click on the block.) - */ @Override public boolean onBlockActivated(final World world, final int x, final int y, final int z, final EntityPlayer player, final int side, final float lx, final float ly, final float lz) { - if (world.isRemote) { + if (world.isRemote || player == null || player.worldObj != world) { return true; } final TileEntity te = world.getTileEntity(x, y, z); - if ((te != null) && (te instanceof TileEntityDecayablesChest)) { - player.openGui(GTplusplus.instance, GuiHandler.GUI13, world, x, y, z); + if (te instanceof TileEntityDecayablesChest) { + TileEntityGuiFactory.open(player, x, y, z); return true; } return false; @@ -159,11 +157,6 @@ public class DecayablesChest extends BlockContainer implements ITileTooltip { } @Override - public void onBlockAdded(final World world, final int x, final int y, final int z) { - super.onBlockAdded(world, x, y, z); - } - - @Override public void breakBlock(final World world, final int x, final int y, final int z, final Block block, final int number) { InventoryUtils.dropInventoryItems(world, x, y, z, block); diff --git a/src/main/java/gtPlusPlus/core/container/Container_DecayablesChest.java b/src/main/java/gtPlusPlus/core/container/Container_DecayablesChest.java deleted file mode 100644 index d8bab9395a..0000000000 --- a/src/main/java/gtPlusPlus/core/container/Container_DecayablesChest.java +++ /dev/null @@ -1,133 +0,0 @@ -package gtPlusPlus.core.container; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Container; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; - -import gtPlusPlus.core.block.ModBlocks; -import gtPlusPlus.core.inventories.Inventory_DecayablesChest; -import gtPlusPlus.core.tileentities.general.TileEntityDecayablesChest; - -public class Container_DecayablesChest extends Container { - - protected TileEntityDecayablesChest tile_entity; - public final Inventory_DecayablesChest inventoryChest; - - private final World worldObj; - private final int posX; - private final int posY; - private final int posZ; - - public static int StorageSlotNumber = 15; // Number of slots in storage area - public static int InventorySlotNumber = 36; // Inventory Slots (Inventory - // and Hotbar) - public static int FullSlotNumber = InventorySlotNumber + StorageSlotNumber; // All - // slots - - private final int[] slotStorage = new int[15]; - - public Container_DecayablesChest(final InventoryPlayer inventory, final TileEntityDecayablesChest te) { - this.tile_entity = te; - this.inventoryChest = te.getInventory(); - te.openInventory(); - - int var6; - int var7; - this.worldObj = te.getWorldObj(); - this.posX = te.xCoord; - this.posY = te.yCoord; - this.posZ = te.zCoord; - - int o = 0; - - // Storage Side - for (var6 = 0; var6 < 3; var6++) { - for (var7 = 0; var7 < 5; var7++) { - this.slotStorage[o] = o; - this.addSlotToContainer(new Slot(this.inventoryChest, o++, 44 + (var7 * 18), 15 + (var6 * 18))); - } - } - - // Player Inventory - for (var6 = 0; var6 < 3; ++var6) { - for (var7 = 0; var7 < 9; ++var7) { - this.addSlotToContainer(new Slot(inventory, var7 + (var6 * 9) + 9, 8 + (var7 * 18), 84 + (var6 * 18))); - } - } - - // Player Hotbar - for (var6 = 0; var6 < 9; ++var6) { - this.addSlotToContainer(new Slot(inventory, var6, 8 + (var6 * 18), 142)); - } - } - - @Override - public ItemStack slotClick(final int aSlotIndex, final int aMouseclick, final int aShifthold, - final EntityPlayer aPlayer) { - - if (!aPlayer.worldObj.isRemote) { - if ((aSlotIndex == 999) || (aSlotIndex == -999)) { - // Utils.LOG_WARNING("??? - "+aSlotIndex); - } - } - return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer); - } - - @Override - public void onContainerClosed(final EntityPlayer par1EntityPlayer) { - super.onContainerClosed(par1EntityPlayer); - tile_entity.closeInventory(); - } - - @Override - public boolean canInteractWith(final EntityPlayer par1EntityPlayer) { - if (this.worldObj.getBlock(this.posX, this.posY, this.posZ) != ModBlocks.blockDecayablesChest) { - return false; - } - - return par1EntityPlayer.getDistanceSq(this.posX + 0.5D, this.posY + 0.5D, this.posZ + 0.5D) <= 64D; - } - - @Override - public ItemStack transferStackInSlot(final EntityPlayer par1EntityPlayer, final int par2) { - ItemStack var3 = null; - final Slot var4 = (Slot) this.inventorySlots.get(par2); - - if ((var4 != null) && var4.getHasStack()) { - final ItemStack var5 = var4.getStack(); - var3 = var5.copy(); - - /* - * if (par2 == 0) { if (!this.mergeItemStack(var5, InOutputSlotNumber, FullSlotNumber, true)) { return null; - * } var4.onSlotChange(var5, var3); } else if (par2 >= InOutputSlotNumber && par2 < InventoryOutSlotNumber) - * { if (!this.mergeItemStack(var5, InventoryOutSlotNumber, FullSlotNumber, false)) { return null; } } else - * if (par2 >= InventoryOutSlotNumber && par2 < FullSlotNumber) { if (!this.mergeItemStack(var5, - * InOutputSlotNumber, InventoryOutSlotNumber, false)) { return null; } } else if - * (!this.mergeItemStack(var5, InOutputSlotNumber, FullSlotNumber, false)) { return null; } - */ - - if (var5.stackSize == 0) { - var4.putStack((ItemStack) null); - } else { - var4.onSlotChanged(); - } - - if (var5.stackSize == var3.stackSize) { - return null; - } - - var4.onPickupFromSlot(par1EntityPlayer, var5); - } - - return var3; - } - - // Can merge Slot - @Override - public boolean func_94530_a(final ItemStack p_94530_1_, final Slot p_94530_2_) { - return super.func_94530_a(p_94530_1_, p_94530_2_); - } -} diff --git a/src/main/java/gtPlusPlus/core/gui/machine/GUI_DecayablesChest.java b/src/main/java/gtPlusPlus/core/gui/machine/GUI_DecayablesChest.java deleted file mode 100644 index 60e0f0e67e..0000000000 --- a/src/main/java/gtPlusPlus/core/gui/machine/GUI_DecayablesChest.java +++ /dev/null @@ -1,54 +0,0 @@ -package gtPlusPlus.core.gui.machine; - -import static gregtech.api.enums.Mods.GTPlusPlus; - -import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.util.ResourceLocation; - -import org.lwjgl.opengl.GL11; - -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import gtPlusPlus.core.container.Container_DecayablesChest; -import gtPlusPlus.core.tileentities.general.TileEntityDecayablesChest; - -@SideOnly(Side.CLIENT) -public class GUI_DecayablesChest extends GuiContainer { - - private static final ResourceLocation craftingTableGuiTextures = new ResourceLocation( - GTPlusPlus.ID, - "textures/gui/FishTrap.png"); - - public GUI_DecayablesChest(final InventoryPlayer player_inventory, final TileEntityDecayablesChest te) { - super(new Container_DecayablesChest(player_inventory, te)); - } - - @Override - protected void drawGuiContainerForegroundLayer(final int i, final int j) { - - } - - @Override - protected void drawGuiContainerBackgroundLayer(final float f, final int i, final int j) { - GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - this.mc.renderEngine.bindTexture(craftingTableGuiTextures); - final int x = (this.width - this.xSize) / 2; - final int y = (this.height - this.ySize) / 2; - this.drawTexturedModalRect(x, y, 0, 0, this.xSize, this.ySize); - } - - // This method is called when the Gui is first called! - @Override - public void initGui() { - // You have to add this line for the Gui to function properly! - super.initGui(); - - // The parameters of GuiButton are(id, x, y, width, height, text); - // this.buttonList.add(new GuiButton( 1, 367, 132, 18, 18, "X")); - // this.buttonList.add(new GuiButton( 2, 385, 132, 18, 18, "Y")); - // NOTE: the id always has to be different or else it might get called twice or never! - - // Add any other buttons here too! - } -} diff --git a/src/main/java/gtPlusPlus/core/handler/GuiHandler.java b/src/main/java/gtPlusPlus/core/handler/GuiHandler.java index d5d0859472..4509fbea04 100644 --- a/src/main/java/gtPlusPlus/core/handler/GuiHandler.java +++ b/src/main/java/gtPlusPlus/core/handler/GuiHandler.java @@ -11,7 +11,6 @@ import gtPlusPlus.GTplusplus; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.block.machine.Machine_SuperJukebox.TileEntitySuperJukebox; import gtPlusPlus.core.container.Container_CircuitProgrammer; -import gtPlusPlus.core.container.Container_DecayablesChest; import gtPlusPlus.core.container.Container_FishTrap; import gtPlusPlus.core.container.Container_PestKiller; import gtPlusPlus.core.container.Container_ProjectTable; @@ -20,7 +19,6 @@ import gtPlusPlus.core.container.Container_VolumetricFlaskSetter; import gtPlusPlus.core.gui.beta.Gui_ID_Registry; import gtPlusPlus.core.gui.beta.MU_GuiId; import gtPlusPlus.core.gui.machine.GUI_CircuitProgrammer; -import gtPlusPlus.core.gui.machine.GUI_DecayablesChest; import gtPlusPlus.core.gui.machine.GUI_FishTrap; import gtPlusPlus.core.gui.machine.GUI_PestKiller; import gtPlusPlus.core.gui.machine.GUI_ProjectTable; @@ -28,7 +26,6 @@ import gtPlusPlus.core.gui.machine.GUI_SuperJukebox; import gtPlusPlus.core.gui.machine.GUI_VolumetricFlaskSetter; import gtPlusPlus.core.interfaces.IGuiManager; import gtPlusPlus.core.tileentities.general.TileEntityCircuitProgrammer; -import gtPlusPlus.core.tileentities.general.TileEntityDecayablesChest; import gtPlusPlus.core.tileentities.general.TileEntityFishTrap; import gtPlusPlus.core.tileentities.general.TileEntityVolumetricFlaskSetter; import gtPlusPlus.core.tileentities.machines.TileEntityPestKiller; @@ -48,7 +45,6 @@ public class GuiHandler implements IGuiHandler { public static final int GUI10 = 9; // None public static final int GUI11 = 10; // None public static final int GUI12 = 11; // None - public static final int GUI13 = 12; // Decayables Chest public static final int GUI14 = 13; // Super Jukebox public static final int GUI15 = 14; // Pest Killer public static final int GUI16 = 15; // None @@ -79,8 +75,6 @@ public class GuiHandler implements IGuiHandler { return new Container_FishTrap(player.inventory, (TileEntityFishTrap) te); } else if (ID == GUI8) { return new Container_CircuitProgrammer(player.inventory, (TileEntityCircuitProgrammer) te); - } else if (ID == GUI13) { - return new Container_DecayablesChest(player.inventory, (TileEntityDecayablesChest) te); } else if (ID == GUI14) { return new Container_SuperJukebox(player.inventory, (TileEntitySuperJukebox) te); } else if (ID == GUI15) { @@ -119,8 +113,6 @@ public class GuiHandler implements IGuiHandler { return new GUI_FishTrap(player.inventory, (TileEntityFishTrap) te); } else if (ID == GUI8) { return new GUI_CircuitProgrammer(player.inventory, (TileEntityCircuitProgrammer) te); - } else if (ID == GUI13) { - return new GUI_DecayablesChest(player.inventory, (TileEntityDecayablesChest) te); } else if (ID == GUI14) { return new GUI_SuperJukebox(player.inventory, (TileEntitySuperJukebox) te); } else if (ID == GUI15) { diff --git a/src/main/java/gtPlusPlus/core/inventories/Inventory_DecayablesChest.java b/src/main/java/gtPlusPlus/core/inventories/Inventory_DecayablesChest.java index 83b3631fe9..4817545c27 100644 --- a/src/main/java/gtPlusPlus/core/inventories/Inventory_DecayablesChest.java +++ b/src/main/java/gtPlusPlus/core/inventories/Inventory_DecayablesChest.java @@ -120,10 +120,6 @@ public class Inventory_DecayablesChest implements IInventory { public void markDirty() { for (int i = 0; i < this.getSizeInventory(); ++i) { final ItemStack temp = this.getStackInSlot(i); - if (temp != null) { - // Utils.LOG_INFO("Slot "+i+" contains "+temp.getDisplayName()+" x"+temp.stackSize); - } - if ((temp != null) && (temp.stackSize == 0)) { this.inventory[i] = null; } diff --git a/src/main/java/gtPlusPlus/core/tileentities/general/TileEntityDecayablesChest.java b/src/main/java/gtPlusPlus/core/tileentities/general/TileEntityDecayablesChest.java index b641f2e99e..c0e50bcc4f 100644 --- a/src/main/java/gtPlusPlus/core/tileentities/general/TileEntityDecayablesChest.java +++ b/src/main/java/gtPlusPlus/core/tileentities/general/TileEntityDecayablesChest.java @@ -1,5 +1,9 @@ package gtPlusPlus.core.tileentities.general; +import java.util.Collections; +import java.util.Set; +import java.util.WeakHashMap; + import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.ItemStack; @@ -7,12 +11,25 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; +import com.cleanroommc.modularui.api.IGuiHolder; +import com.cleanroommc.modularui.api.drawable.IKey; +import com.cleanroommc.modularui.factory.GuiData; +import com.cleanroommc.modularui.future.InvWrapper; +import com.cleanroommc.modularui.screen.ModularPanel; +import com.cleanroommc.modularui.utils.Alignment; +import com.cleanroommc.modularui.value.sync.GuiSyncManager; +import com.cleanroommc.modularui.value.sync.SyncHandlers; +import com.cleanroommc.modularui.widgets.ItemSlot; +import com.cleanroommc.modularui.widgets.SlotGroupWidget; +import com.cleanroommc.modularui.widgets.TextWidget; +import com.cleanroommc.modularui.widgets.slot.SlotGroup; + import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.inventories.Inventory_DecayablesChest; import gtPlusPlus.core.item.materials.DustDecayable; import gtPlusPlus.core.util.minecraft.ItemUtils; -public class TileEntityDecayablesChest extends TileEntity implements ISidedInventory { +public class TileEntityDecayablesChest extends TileEntity implements ISidedInventory, IGuiHolder { private final Inventory_DecayablesChest inventoryContents; @@ -32,6 +49,7 @@ public class TileEntityDecayablesChest extends TileEntity implements ISidedInven public float prevLidAngle; /** The number of players currently using this chest */ public int numPlayersUsing; + private final Set<EntityPlayer> playersUsing = Collections.newSetFromMap(new WeakHashMap<>()); private String customName; @@ -375,4 +393,40 @@ public class TileEntityDecayablesChest extends TileEntity implements ISidedInven cachedChestType = 0; return cachedChestType; } + + @Override + public ModularPanel buildUI(GuiData data, GuiSyncManager syncManager) { + final SlotGroup SLOT_GROUP = new SlotGroup("decayables", 5); + syncManager.registerSlotGroup(SLOT_GROUP); + syncManager.addOpenListener(player -> { + if (playersUsing.add(player)) { + this.openInventory(); + } + }); + syncManager.addCloseListener(player -> { + if (playersUsing.remove(player)) { + this.closeInventory(); + } + }); + final InvWrapper contents = new InvWrapper(inventoryContents); + final ModularPanel panel = ModularPanel.defaultPanel("decayablesChest"); + panel.bindPlayerInventory(); + panel.child( + new TextWidget(IKey.lang("tile.blockDecayablesChest.name")).top(5) + .left(5)); + panel.child( + SlotGroupWidget.builder() + .matrix("IIIII", "IIIII", "IIIII") + .key( + 'I', + index -> new ItemSlot<>().slot( + SyncHandlers.itemSlot(contents, index) + .slotGroup(SLOT_GROUP))) + .build() + .flex( + flex -> flex.anchor(Alignment.TopCenter) + .marginTop(15) + .leftRelAnchor(0.5f, 0.5f))); + return panel; + } } |