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 0000000..a4bff67 Binary files /dev/null and b/src/main/resources/assets/ageofthegods/textures/screens/alloy_furnace_gui.png differ 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 0000000..bf317ee Binary files /dev/null and b/src/main/resources/assets/ageofthegods/textures/screens/alloy_furnace_molten_element_gui.png differ 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 0000000..46ff1e1 Binary files /dev/null and b/src/main/resources/assets/ageofthegods/textures/screens/bellow-sheet.png differ 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 a871597..0000000 Binary files a/src/main/resources/assets/ageofthegods/textures/screens/example_gui.png and /dev/null differ