From c3b176dbeb26000e479ebe0503234a69b5b0ec36 Mon Sep 17 00:00:00 2001 From: Halbear Date: Tue, 28 Jul 2026 00:59:23 +0100 Subject: [PATCH] alloy furnace GUI w.i.p --- .../GuiScreens/AlloyFurnaceGUIScreen.java | 2 +- .../AlloyFurnace/AlloyFurnaceBlockEntity.java | 109 +++++++++++++++--- .../blocks/AlloyFurnace/AlloyFurnaceGUI.java | 22 +++- .../AlloyFurnace/AlloyFurnaceMultiBlock.java | 37 ++++-- .../textures/screens/alloy_furnace_gui.png | Bin 0 -> 3034 bytes .../alloy_furnace_molten_element_gui.png | Bin 0 -> 262 bytes .../textures/screens/bellow-sheet.png | Bin 0 -> 809 bytes .../textures/screens/example_gui.png | Bin 1177 -> 0 bytes 8 files changed, 137 insertions(+), 33 deletions(-) create mode 100644 src/main/resources/assets/ageofthegods/textures/screens/alloy_furnace_gui.png create mode 100644 src/main/resources/assets/ageofthegods/textures/screens/alloy_furnace_molten_element_gui.png create mode 100644 src/main/resources/assets/ageofthegods/textures/screens/bellow-sheet.png delete mode 100644 src/main/resources/assets/ageofthegods/textures/screens/example_gui.png diff --git a/src/main/java/net/halbear/aotg/custom/GuiScreens/AlloyFurnaceGUIScreen.java b/src/main/java/net/halbear/aotg/custom/GuiScreens/AlloyFurnaceGUIScreen.java index 8e24ace..8e4ce16 100644 --- a/src/main/java/net/halbear/aotg/custom/GuiScreens/AlloyFurnaceGUIScreen.java +++ b/src/main/java/net/halbear/aotg/custom/GuiScreens/AlloyFurnaceGUIScreen.java @@ -18,7 +18,7 @@ public class AlloyFurnaceGUIScreen extends AbstractContainerScreen items = NonNullList.withSize(2, ItemStack.EMPTY); + private NonNullList items = NonNullList.withSize(5, ItemStack.EMPTY); public AlloyFurnaceBlockEntity(BlockPos worldPosition, BlockState blockState) { super(ALLOY_FURNACE_BLOCK_ENTITY.get(), worldPosition, blockState); @@ -58,18 +65,22 @@ public class AlloyFurnaceBlockEntity extends BlockEntity implements MenuProvider Complete = false; } } - if(Complete){ - for (BlockPos offset : MULTI_BLOCK_POSITIONS) { - int Part = AlloyFurnaceUpdateHandler.GetModelPart(offset); - BlockPos Rotated = offset.rotate(rotation); - BlockPos targetPos = masterPos.offset(Rotated); - BlockState state = level.getBlockState(targetPos); - if(state.getValue(PARENT_BLOCK) && !(offset.getX() == 0 && offset.getY() == 0 && offset.getZ() == 0)) state = state.setValue(AlloyFurnaceMultiBlock.PARENT_BLOCK,false); - if(state.getValue(MODEL_PART) != Part) state = state.setValue(AlloyFurnaceMultiBlock.MODEL_PART,Part); - if(state.getValue(FACING) != direction) state = state.setValue(FACING,direction); - level.setBlockAndUpdate(targetPos,state); + for (BlockPos offset : MULTI_BLOCK_POSITIONS) { + BlockPos Rotated = offset.rotate(rotation); + BlockPos targetPos = masterPos.offset(Rotated); + BlockState state = level.getBlockState(targetPos); + if (state.getBlock().getName().getString().equals(ModBlocks.ALLOY_FURNACE.get().getName().getString())) { + if (Complete) { + int Part = AlloyFurnaceUpdateHandler.GetModelPart(offset); + if (!state.getValue(COMPLETE_STRUCTURE)) state = state.setValue(COMPLETE_STRUCTURE, true); + if (state.getValue(PARENT_BLOCK) && !(offset.getX() == 0 && offset.getY() == 0 && offset.getZ() == 0)) state = state.setValue(AlloyFurnaceMultiBlock.PARENT_BLOCK, false); + if (state.getValue(MODEL_PART) != Part) state = state.setValue(AlloyFurnaceMultiBlock.MODEL_PART, Part); + if (state.getValue(FACING) != direction) state = state.setValue(FACING, direction); + } else { + state = state.setValue(COMPLETE_STRUCTURE, false); + } + level.setBlockAndUpdate(targetPos, state); } - } return Complete; } @@ -91,18 +102,24 @@ public class AlloyFurnaceBlockEntity extends BlockEntity implements MenuProvider @Override public void loadAdditional(ValueInput input) { super.loadAdditional(input); - this.Fuel = input.getFloatOr("fuel", 0); + if (!this.tryLoadLootTable(input)) + this.items = NonNullList.withSize(this.getContainerSize(), ItemStack.EMPTY); + ContainerHelper.loadAllItems(input, this.items); + } @Override public void saveAdditional(ValueOutput output) { super.saveAdditional(output); output.putFloat("fuel", this.Fuel); + if (!this.trySaveLootTable(output)) + ContainerHelper.saveAllItems(output, this.items); + } @Override public CompoundTag getUpdateTag(HolderLookup.Provider registries) { - return this.saveWithoutMetadata(registries); + return this.saveWithFullMetadata(registries); } @Override @@ -127,10 +144,21 @@ public class AlloyFurnaceBlockEntity extends BlockEntity implements MenuProvider } @Override - public @Nullable AbstractContainerMenu createMenu(int i, Inventory inventory, Player player) { + protected Component getDefaultName() { return null; } + @Override + public @Nullable AbstractContainerMenu createMenu(int i, Inventory inventory, Player player) { + return new AlloyFurnaceGUI(i, inventory, new FriendlyByteBuf(Unpooled.buffer()).writeBlockPos(this.worldPosition)); + + } + + @Override + protected AbstractContainerMenu createMenu(int i, Inventory inventory) { + return new AlloyFurnaceGUI(i, inventory, new FriendlyByteBuf(Unpooled.buffer()).writeBlockPos(this.worldPosition)); + } + private final StacksResourceHandler resourceHandler = new ItemStacksResourceHandler(this.items) { @Override protected void onContentsChanged(int index, ItemStack stack) { @@ -142,4 +170,53 @@ public class AlloyFurnaceBlockEntity extends BlockEntity implements MenuProvider public StacksResourceHandler getResourceHandler() { return this.resourceHandler; } + + + @Override + public int getContainerSize() { + return items.size(); + } + + @Override + public boolean isEmpty() { + for (ItemStack itemstack : this.items) + if (!itemstack.isEmpty()) + return false; + return true; + } + + @Override + protected NonNullList getItems() { + return this.items; + } + + @Override + protected void setItems(NonNullList stacks) { + this.items = stacks; + } + + @Override + public boolean canPlaceItem(int index, ItemStack stack) { + return true; + } + + @Override + public int[] getSlotsForFace(Direction side) { + return IntStream.range(0, this.getContainerSize()).toArray(); + } + + @Override + public boolean canPlaceItemThroughFace(int index, ItemStack itemstack, @Nullable Direction direction) { + return this.canPlaceItem(index, itemstack); + } + + @Override + public boolean canTakeItemThroughFace(int index, ItemStack itemstack, Direction direction) { + return true; + } + + @Override + public void clearContent() { + items.clear(); + } } diff --git a/src/main/java/net/halbear/aotg/custom/blocks/AlloyFurnace/AlloyFurnaceGUI.java b/src/main/java/net/halbear/aotg/custom/blocks/AlloyFurnace/AlloyFurnaceGUI.java index 6d265cf..7a52631 100644 --- a/src/main/java/net/halbear/aotg/custom/blocks/AlloyFurnace/AlloyFurnaceGUI.java +++ b/src/main/java/net/halbear/aotg/custom/blocks/AlloyFurnace/AlloyFurnaceGUI.java @@ -14,6 +14,7 @@ import net.minecraft.world.inventory.ContainerLevelAccess; import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.entity.BaseContainerBlockEntity; import net.minecraft.world.level.block.entity.BlockEntity; import net.neoforged.neoforge.capabilities.Capabilities; @@ -33,7 +34,7 @@ public class AlloyFurnaceGUI extends AbstractContainerMenu implements ModMenus.M public final Map menuState = new HashMap<>() { @Override public Object put(String key, Object value) { - if (!this.containsKey(key) && this.size() >= 4) + if (!this.containsKey(key) && this.size() >= 5) return null; return super.put(key, value); } @@ -72,25 +73,36 @@ public class AlloyFurnaceGUI extends AbstractContainerMenu implements ModMenus.M this.bound = true; } } - this.customSlots.put(0, this.addSlot(new ResourceHandlerSlot(internal, this::setItemInSlot, 0, 42, 41) { + this.customSlots.put(0, this.addSlot(new ResourceHandlerSlot(internal, this::setItemInSlot, 0, 37, 16) { private final int slot = 0; private int x = this.x; private int y = this.y; })); - this.customSlots.put(1, this.addSlot(new ResourceHandlerSlot(internal, this::setItemInSlot, 1, 21, 40) { + this.customSlots.put(1, this.addSlot(new ResourceHandlerSlot(internal, this::setItemInSlot, 1, 57, 16) { private final int slot = 1; private int x = this.x; private int y = this.y; })); - this.customSlots.put(2, this.addSlot(new ResourceHandlerSlot(internal, this::setItemInSlot, 2, 63, 41) { + this.customSlots.put(2, this.addSlot(new ResourceHandlerSlot(internal, this::setItemInSlot, 2, 47, 35) { private final int slot = 2; private int x = this.x; private int y = this.y; + + @Override + public boolean mayPlace(ItemStack stack) { + return Blocks.DECORATED_POT.asItem() == stack.getItem(); + } + })); - this.customSlots.put(3, this.addSlot(new ResourceHandlerSlot(internal, this::setItemInSlot, 3, 129, 41) { + this.customSlots.put(3, this.addSlot(new ResourceHandlerSlot(internal, this::setItemInSlot, 3, 64, 58) { private final int slot = 3; private int x = this.x; private int y = this.y; + })); + this.customSlots.put(4, this.addSlot(new ResourceHandlerSlot(internal, this::setItemInSlot, 4, 130, 37) { + private final int slot = 4; + private int x = this.x; + private int y = this.y; @Override public boolean mayPlace(ItemStack stack) { diff --git a/src/main/java/net/halbear/aotg/custom/blocks/AlloyFurnace/AlloyFurnaceMultiBlock.java b/src/main/java/net/halbear/aotg/custom/blocks/AlloyFurnace/AlloyFurnaceMultiBlock.java index 57208d5..a506e1f 100644 --- a/src/main/java/net/halbear/aotg/custom/blocks/AlloyFurnace/AlloyFurnaceMultiBlock.java +++ b/src/main/java/net/halbear/aotg/custom/blocks/AlloyFurnace/AlloyFurnaceMultiBlock.java @@ -48,10 +48,11 @@ public class AlloyFurnaceMultiBlock extends Block implements EntityBlock { public static final EnumProperty FACING = BlockStateProperties.HORIZONTAL_FACING; public static final IntegerProperty MODEL_PART = IntegerProperty.create("modelpart",0,8); public static final BooleanProperty PARENT_BLOCK = BooleanProperty.create("parent"); + public static final BooleanProperty COMPLETE_STRUCTURE = BooleanProperty.create("complete_structure"); public AlloyFurnaceMultiBlock(Properties properties) { super(properties); - this.registerDefaultState(this.defaultBlockState().setValue(MODEL_PART,0).setValue(PARENT_BLOCK,true).setValue(FACING,Direction.NORTH)); + this.registerDefaultState(this.defaultBlockState().setValue(MODEL_PART,0).setValue(COMPLETE_STRUCTURE,false).setValue(PARENT_BLOCK,true).setValue(FACING,Direction.NORTH)); } @Override @@ -153,23 +154,37 @@ public class AlloyFurnaceMultiBlock extends Block implements EntityBlock { builder.add(MODEL_PART); builder.add(FACING); builder.add(PARENT_BLOCK); + builder.add(COMPLETE_STRUCTURE); } @Override public InteractionResult useWithoutItem(BlockState blockstate, Level world, BlockPos pos, Player entity, BlockHitResult hit) { super.useWithoutItem(blockstate, world, pos, entity, hit); if (entity instanceof ServerPlayer player) { - player.openMenu(new MenuProvider() { - @Override - public Component getDisplayName() { - return Component.literal("Sigma"); - } + AgeoftheGods.LOGGER.debug("BLOCKSTATE: " + blockstate.getBlock().getName().getString() + " | BLOCK: " + ModBlocks.ALLOY_FURNACE.get().getName().getString()); + if(!blockstate.getBlock().getName().getString().equals(ModBlocks.ALLOY_FURNACE.get().getName().getString()) || + blockstate.getBlock().getName().getString().equals(ModBlocks.ALLOY_FURNACE.get().getName().getString()) && !blockstate.getValue(COMPLETE_STRUCTURE)) return InteractionResult.PASS; + int ModelPart = blockstate.getValue(MODEL_PART); + BlockPos offset = AlloyFurnaceUpdateHandler.parts[ModelPart]; + Direction direction = blockstate.getValue(FACING); + Rotation rotation = getInverseRotationForDirection(direction); + BlockPos Rotated = offset.rotate(rotation); + BlockPos TargetPos = new BlockPos(pos.getX() - Rotated.getX(), pos.getY() - Rotated.getY(), pos.getZ() - Rotated.getZ()); + AgeoftheGods.LOGGER.debug("TARGET GUI POS: " + TargetPos +"\n INTERACTION POS:" + pos + "\n ROTATION" + Rotated + "\n OFFSET" + offset); + if(world.getBlockState(TargetPos).getBlock().getName().getString().equals(ModBlocks.ALLOY_FURNACE.get().getName().getString()) && + world.getBlockState(TargetPos).getValue(PARENT_BLOCK)) { + player.openMenu(new MenuProvider() { + @Override + public Component getDisplayName() { + return Component.literal("Sigma"); + } - @Override - public AbstractContainerMenu createMenu(int id, Inventory inventory, Player player) { - return new AlloyFurnaceGUI(id, inventory, new FriendlyByteBuf(Unpooled.buffer()).writeBlockPos(pos)); - } - }, pos); + @Override + public AbstractContainerMenu createMenu(int id, Inventory inventory, Player player) { + return new AlloyFurnaceGUI(id, inventory, new FriendlyByteBuf(Unpooled.buffer()).writeBlockPos(TargetPos)); + } + }, pos); + } } return InteractionResult.SUCCESS; } diff --git a/src/main/resources/assets/ageofthegods/textures/screens/alloy_furnace_gui.png b/src/main/resources/assets/ageofthegods/textures/screens/alloy_furnace_gui.png new file mode 100644 index 0000000000000000000000000000000000000000..a4bff67ca2b3758c187d7faef3c309fe4d7ae304 GIT binary patch literal 3034 zcmbVOc{~)_7avPARFWuTn_g%nvW2{iAzKWMHA<6YO{fsf$eML5Df?u5cG+emTgb?s z8I%mhHu0E-vW=~={igSM@Avon{r;$@e*V+5HMPH2>|HMg>@8=v)guRag4T~VtaIr&4MR{rk2Rb+Uo!vzp6;N++cM| zgTnsWB-iE_aQ*Ux=)!5DLm(?-c!wNW1FEWC-8AbG6*Gn^1CK@ScUEbS>G*z?uUp`g zSv_C3Jn>GQCBlH zxxSWp+*8Ps$im-IzJVEVJy8C|nY`}=AbPg=>ogC-a&&o1)i3US?)q>OKwP|t z&mRei8ga9iX!gINjl}X3iDH={IxKWbjN4*uI^AQWrm61oab>Jt3LCGMN>U9-_+3>@ zhoAU;pN@EOS!>qM@1UhDnDid)C(z^o!FR;$Q7H9DD@}Yfl@@THe}qt77ke9kUW{j= zd%kfCudtIH1*3jW)xMFKT?Xllo5X|gZe}?|*3dN%%~<;N(%B6#b=PU|764tnv*8fv zdIZoXtPN0ImY6k6)<1maiy1*gG~?UMq0o(zOl+ls!U$M{fj&zq+&8U$c<P&oYOcP<=>=b6A~8}*MOP59I)q>0cUhi)z0T8&A&bMHEc3#>02Nh|tfLo2gs zq4~)`>SWNT29n{o5jPW{ZiIg z0sf0>P^NzV3ulO6`p;nt9sw??yIH35vQfH87}F$}9gcu;kbp9U^n^Idt&LJi1xi}4 zBEVqY*&k~2z%ie?6w?z?G)|jdSe^KEMTQRw#SFjw2pd+NOR~zu&0j-FKRYrCohTdw z^(rgLvUk>Ozw=Tl?6UFxjaF zp(La`(>WlX5tr}iP;Avz@ZvEdlg>967Nms@cRKoAGkcA4m3}c1L%(F(vLTaj4uUS9 z0>^-Pb4Kbx{kOg`bZw539)H~ag;TCdd&%tjjjX5BiCXF43`WW-_KnH_ z``H2Q-Rtbz@%TOETGZ7oPxXO{^aG;hc=6Mziu<$jsJ_@V#bBirBtz~P@`%(ir|m!R zB*6);kd5B%@Q_P8iJ$Z?r~&;2{O|{!rR(Qj%b%+ZEFEIdsB3e1$}(6rIpBlM)3a@) zdgi_`-y`gk+XKJLe>kQlkJSQsM+4UX~X^J{1HC+m7 zd_Mm{9J0F@_wvwsNyz@wLgwROZFq$CrWh)pE{}rQWTFYpNRqy30U#zKA zwRTlNH7M03AWOn+%I92Qn3&|j_qnIb(~=O(W_M;~p6~I`^Ch=oE1oS-b>Y!&{7r!) zg;xhahKBJXj&Kb{u}#DMif3Xp<>ws5t;3WM~K_zsH?i0IE=x( zMSu7|l{7%H4H&o6AC=(fZ5N{x=1r4bySuwIzt7>gica1kmPh?Kmq0m)BUwj?qM-<0?hT z^>pw*uuEP$Gf$`cV%;V%4!;6XjI|T1^i(F81p83XdQ}N&>XE?iv1nr<#aQaMM`f%h z4yFT(}`q3gBUJ2Bq?%Ai zUhk;x>u((P419K2!^}87u7vW#b;H9$uf5WB_LpbvO-7h;_n2KxYvD*<~PI|0vS6c6&*U0VDg$9we=X?>%Oyp6fjC44t|73*M(|<0C)jSgIiF^N#{hk zC7DYwN%(L^3{)**rTU~*$WD&{Jc=?zf+-Vr$THE1E_1$v`=kdnN1szqI@x1j%qyc_AeMzC)(^dK`kE%!&G{|4MED zMW!WN)lyD{M^-Ap0I0|F-?)uiuuj)iex$TLznNOmUgpf+C}DFp`Tt~{YWf%J@+7Rr zjZ{-8@bBcBe+{2G2}ng0y{Uiq?(+JXGcH##G=v>P<&29{t8=TR^3=4Pt4741#hicx Zu0k{Y$CTN)6n3)?Fg8HySLr%D`wvs~+Zq4> literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/ageofthegods/textures/screens/alloy_furnace_molten_element_gui.png b/src/main/resources/assets/ageofthegods/textures/screens/alloy_furnace_molten_element_gui.png new file mode 100644 index 0000000000000000000000000000000000000000..bf317ee1125b1e3bec2754897ff338643ca0d3f3 GIT binary patch literal 262 zcmV+h0r~!kP)Px#z)3_wR5*=|l+6_bAqa%W_w2-8wubbQUbc|jQi!#XL(~ieP);g;->kSrZU{Pn zhM#p>H)n5R>N;d6uRHl|fzhDI8=?rf>$J;I8nUW7JE%&IZP2)gIsE$$jL(usTy;A{ z$?&Plx*cntH2BhMn%FiJL)MqX21Qf>S&a~tWyRO+^aMSknfn(|;M1& M07*qoM6N<$g5=a}KL7v# literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/ageofthegods/textures/screens/bellow-sheet.png b/src/main/resources/assets/ageofthegods/textures/screens/bellow-sheet.png new file mode 100644 index 0000000000000000000000000000000000000000..46ff1e1c946b36d395b2326cbb20a02498b4be5b GIT binary patch literal 809 zcmV+^1J?YBP)Px%<4Ht8R9J=Wn7?n+Kp2J}iz3BMYHEd|HUxzMp-K!aU63+WWkDdeN~j|Y%-vw3 z3q!>pzyKo)8ygZT6M})Mu%I$PM3uBEkjjwS1tc@rcR8PZZrb#R5P7Hg?tJ&?z3+VA z7x-5c#yYI^hVnq}-kz1e0W8b1js(WCEK5Kf7L*Z21qxQ090rteGO^&jtCs;NSw789 z)VDrj1MuY83kkg+FqzJTVHn=JG=*aqaE5J4mJh&%6Y%A?4L_pi{dUT@P1UjsfVbu2 ziN<2&P^kz%LmN-ozDBFvH&pI6J-Ai}qJ;rgzqN7ff*j)v+Y*>~`)U&|_a8oGFHot$ zYOILuaTWjCe~^FzLV$_q!ublouAvfx)L2m$0XTEKyRZO4b4|VzzrWi+&vZs?4PIpM0dNOG}&YT0G-WV+uOb~7FF{D6g9erb?iVz-I+&lXr!u!+)d)^a4TMY= zY_E{HMO?M)QYm)Zn;jokqQpu~y+nE`+(dIU%grpn9i8b#de$f8*aa#@_fQi-e3g&Q?6d!L5_|XGc3${Uf nCu`!JwCh^C*FO^foBa4M44AA(=gEyr00000NkvXXu0mjf5A1Qc literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/ageofthegods/textures/screens/example_gui.png b/src/main/resources/assets/ageofthegods/textures/screens/example_gui.png deleted file mode 100644 index a871597bcf83c280fb1b0bfa4884818523e734e3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1177 zcmeAS@N?(olHy`uVBq!ia0vp^8-REj2OE&AvS7Wzz`&B=>Eakt5%>0PVwQBINXx}H zr?fw=dQ+MjEqN>9SnxBmNo)AFw|#!_XQGdwy`7{`%G2xX>(9$;e0=+-aL%;iFIsWS zzy105_qV-ZeYKETb#3k650V=zRw^Z|;+&Div}{(xN;T>;r?dU}^yyRb`}gnfmp#1v zlyU#wy?;IaMH+o@f6}cqzuqO!?9}_0g7v@Uw3yGW-+BH1jhrhL{7m~YHU~bo<@mAa ztXuDQg$Lbc(x&&C8}x5cQ?elQ!0~G5`Gx!P;tEfO=a^;fY4>K{cSuyfOB-aJbL@c+ zQz;ITTW1;N<*mO2A6MW1B)NY>@w@+fCdb|rEvVzWwzn@iJ?;6O!cE?cw6KNz6m-|<|bWEb;(c98s>k!KjD_8ec3txvdZEE$F*N9pZD|JpPDy< zW#>T7c+X`~zvTXFi?Xz`bF#E{4w^6X`F=#cU$MQo?#-O}Z-7qi55M4V`+4rqpEs1> z%(=Y-9CZIY_Fpf2bLPz)Yrith1nb4U);E_nyzMc2molAcoAE86BCZ?fG9FW3@}A6x z&G!QHpZ~dGX@B$SS;oU|uuOAT=EKMBC+1f@%U}Ks6w7%)+bhEl{5&u9-KuZy%(=zK z=@h%r;5x$av2R750imzopr09Bkvy#N3J