diff --git a/src/main/java/net/halbear/aotg/AgeoftheGods.java b/src/main/java/net/halbear/aotg/AgeoftheGods.java index facdac8..ce0eb21 100644 --- a/src/main/java/net/halbear/aotg/AgeoftheGods.java +++ b/src/main/java/net/halbear/aotg/AgeoftheGods.java @@ -11,7 +11,9 @@ import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.dimension.DimensionType; import net.minecraft.world.level.levelgen.WorldGenSettings; import net.neoforged.bus.api.Event; +import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent; import net.neoforged.neoforge.network.handling.IPayloadHandler; +import net.neoforged.neoforge.network.registration.PayloadRegistrar; import org.slf4j.Logger; import com.mojang.logging.LogUtils; @@ -144,5 +146,13 @@ public class AgeoftheGods { MESSAGES.put(id, new NetworkMessage<>(reader, handler)); } + @SuppressWarnings({"rawtypes", "unchecked"}) + private void registerNetworking(final RegisterPayloadHandlersEvent event) { + final PayloadRegistrar registrar = event.registrar(MODID); + MESSAGES.forEach((id, networkMessage) -> registrar.playBidirectional(id, ((NetworkMessage) networkMessage).reader(), ((NetworkMessage) networkMessage).handler(), ((NetworkMessage) networkMessage).handler())); + networkingRegistered = true; + } + + } 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 8e4ce16..d076fb2 100644 --- a/src/main/java/net/halbear/aotg/custom/GuiScreens/AlloyFurnaceGUIScreen.java +++ b/src/main/java/net/halbear/aotg/custom/GuiScreens/AlloyFurnaceGUIScreen.java @@ -1,24 +1,43 @@ package net.halbear.aotg.custom.GuiScreens; import com.mojang.blaze3d.platform.InputConstants; +import net.halbear.aotg.custom.blocks.AlloyFurnace.AlloyFurnaceBlockEntity; import net.halbear.aotg.custom.blocks.AlloyFurnace.AlloyFurnaceGUI; +import net.halbear.aotg.custom.blocks.AlloyFurnace.AlloyFurnaceMultiBlock; +import net.halbear.aotg.custom.blocks.AlloyFurnace.AlloyFurnaceUpdateHandler; +import net.halbear.aotg.registries.ModBlocks; import net.halbear.aotg.registries.ModScreens; +import net.halbear.aotg.utility.Networking.AlloyFurnaceGuiButtonHandler; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphicsExtractor; +import net.minecraft.client.gui.components.ImageButton; +import net.minecraft.client.gui.components.WidgetSprites; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.client.input.KeyEvent; import net.minecraft.client.renderer.RenderPipelines; +import net.minecraft.core.BlockPos; import net.minecraft.network.chat.Component; import net.minecraft.resources.Identifier; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.neoforged.neoforge.client.network.ClientPacketDistributor; + +import static net.halbear.aotg.custom.blocks.AlloyFurnace.AlloyFurnaceBlockEntity.MAX_BELLOW; public class AlloyFurnaceGUIScreen extends AbstractContainerScreen implements ModScreens.ScreenAccessor { private final Level world; private final int x, y, z; private final Player entity; private boolean menuStateUpdateActive = false; + private ImageButton Blower; private static final Identifier BACKGROUND = Identifier.parse("ageofthegods:textures/screens/alloy_furnace_gui.png"); + private static final Identifier BELLOW_SPRITE_SHEET = Identifier.parse("ageofthegods:textures/screens/bellow-sheet.png"); + private static final Identifier MOLTEN_FILL_SPRITE = Identifier.parse("ageofthegods:textures/screens/alloy_furnace_molten_element_gui.png"); + private static final Identifier FLAME_SPRITE = Identifier.parse("ageofthegods:textures/screens/alloy_furnace_flame_gui.png"); + public AlloyFurnaceGUIScreen(AlloyFurnaceGUI container, Inventory inventory, Component text) { super(container, inventory, text, 176, 166); @@ -43,6 +62,30 @@ public class AlloyFurnaceGUIScreen extends AbstractContainerScreen 0) guiGraphics.blit(RenderPipelines.GUI_TEXTURED, MOLTEN_FILL_SPRITE, this.leftPos + 100, this.topPos + 36 + (19 - CookProgress), 0, 0, 17, CookProgress, 17, 19); + int FuelProgress = GetMoltenProgress(world,x,y,z,21,0,1); + if(FuelProgress > 0) guiGraphics.blit(RenderPipelines.GUI_TEXTURED, FLAME_SPRITE, this.leftPos + 47, this.topPos + 54 + (21 - FuelProgress), 0, 21 - FuelProgress, 14, FuelProgress, 14, 21); + } + + private int GetMoltenProgress(Level world, int x, int y, int z, int FullHeight, int MinimumHeight, int ElementVariable){ + BlockState state = world.getBlockState(new BlockPos(x,y,z)); + BlockPos position = new BlockPos(x,y,z); + if(state.getBlock().getName().getString().equals(ModBlocks.ALLOY_FURNACE.get().getName().getString())) { +// if(!state.getValue(AlloyFurnaceMultiBlock.PARENT_BLOCK)){ +// int ModelPart = state.getValue(AlloyFurnaceMultiBlock.MODEL_PART); +// position = AlloyFurnaceUpdateHandler.GetParentPosFromModelPart(world,ModelPart,state,position); +// if(position == null) return MinimumHeight; +// } + int cookProgress = this.menu.getSyncedVariable(ElementVariable); + float Multipler = Math.min((float)cookProgress/100.0f,1.0f); + int TargetHeight = (int)Math.ceil((float)FullHeight*Multipler); + return Math.clamp(TargetHeight,MinimumHeight,FullHeight); + } + return MinimumHeight; } @Override @@ -57,10 +100,26 @@ public class AlloyFurnaceGUIScreen extends AbstractContainerScreen { + int x = AlloyFurnaceGUIScreen.this.x; + int y = AlloyFurnaceGUIScreen.this.y; + int z = AlloyFurnaceGUIScreen.this.z; + ClientPacketDistributor.sendToServer(new AlloyFurnaceGuiButtonHandler(0, x, y, z)); + AlloyFurnaceGuiButtonHandler.handleButtonAction(entity, 0, x, y, z); + }) { + @Override + public void extractContents(GuiGraphicsExtractor guiGraphics, int mouseX, int mouseY, float partialTicks) { + guiGraphics.blit(RenderPipelines.GUI_TEXTURED, sprites.get(isActive(), isHoveredOrFocused()), getX(), getY(), 0, 0, width, height, width, height); + } + }; + this.addRenderableWidget(Blower); + } } diff --git a/src/main/java/net/halbear/aotg/custom/blocks/AlloyFurnace/AlloyFurnaceBlockEntity.java b/src/main/java/net/halbear/aotg/custom/blocks/AlloyFurnace/AlloyFurnaceBlockEntity.java index 33efe9a..a639a1a 100644 --- a/src/main/java/net/halbear/aotg/custom/blocks/AlloyFurnace/AlloyFurnaceBlockEntity.java +++ b/src/main/java/net/halbear/aotg/custom/blocks/AlloyFurnace/AlloyFurnaceBlockEntity.java @@ -1,6 +1,7 @@ package net.halbear.aotg.custom.blocks.AlloyFurnace; import io.netty.buffer.Unpooled; +import net.halbear.aotg.AgeoftheGods; import net.halbear.aotg.registries.ModBlocks; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -20,6 +21,7 @@ import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Rotation; import net.minecraft.world.level.block.entity.BlockEntity; @@ -43,29 +45,38 @@ public class AlloyFurnaceBlockEntity extends RandomizableContainerBlockEntity im private boolean isFormed = false; private float Fuel = 0.0f; - private int progress = 0; - private NonNullList items = NonNullList.withSize(5, ItemStack.EMPTY); + private float CookProcess = 0.0f; + private float TemperatureC = 0.0f; + private float BellowPush = 0.0f; + private boolean AbleToCook = false; + public static int MAX_BELLOW = 5; + private boolean pushBellow = false; + private boolean AbleToStartCooking; + private NonNullList items = NonNullList.withSize(8, ItemStack.EMPTY); + + public void PushBellow(){if(BellowPush < 1)pushBellow = true;} + public int GetCookProgress(){return (int)CookProcess;} + public void SetCookProgress(int CookProcess){this.CookProcess = CookProcess ;} + public int GetBellowPush(){return (int)BellowPush;} + public void SetBellowPush(int BellowPush){this.BellowPush = BellowPush ;} + public int GetFuel(){return (int)Fuel;} + public void SetFuel(int Fuel){this.Fuel = Fuel ;} + public int GetTemperatureC(){return (int) TemperatureC;} + public void SetTemperatureC(int Temp){this.TemperatureC = Temp ;} public AlloyFurnaceBlockEntity(BlockPos worldPosition, BlockState blockState) { super(ALLOY_FURNACE_BLOCK_ENTITY.get(), worldPosition, blockState); } - - public boolean checkStructure(Level level, BlockPos masterPos, BlockState blockState) { + public boolean UpdateCompleteStructure(Level level, BlockPos masterPos, BlockState blockState, boolean Complete){ Direction direction = blockState.getValue(FACING); Rotation rotation = getInverseRotationForDirection(direction); - boolean Complete =true; - for (BlockPos offset : MULTI_BLOCK_POSITIONS) { - - BlockPos Rotated = offset.rotate(rotation); - BlockPos targetPos = masterPos.offset(Rotated); - BlockState state = level.getBlockState(targetPos); - - if (!state.is(ModBlocks.ALLOY_FURNACE.get())) { - Complete = false; - } + BlockPos[] Positions = new BlockPos[MULTI_BLOCK_POSITIONS.length + 1]; + Positions[0] = new BlockPos(0,0,0); + for(int i = 0; i < MULTI_BLOCK_POSITIONS.length; i++){ + Positions[1 + i] = MULTI_BLOCK_POSITIONS[i]; } - for (BlockPos offset : MULTI_BLOCK_POSITIONS) { + for (BlockPos offset : Positions) { BlockPos Rotated = offset.rotate(rotation); BlockPos targetPos = masterPos.offset(Rotated); BlockState state = level.getBlockState(targetPos); @@ -84,18 +95,72 @@ public class AlloyFurnaceBlockEntity extends RandomizableContainerBlockEntity im } return Complete; } + public static boolean checkStructure(Level level, BlockPos masterPos, BlockState blockState) { + Direction direction = blockState.getValue(FACING); + Rotation rotation = getInverseRotationForDirection(direction); + boolean Complete =true; + for (BlockPos offset : MULTI_BLOCK_POSITIONS) { + + BlockPos Rotated = offset.rotate(rotation); + BlockPos targetPos = masterPos.offset(Rotated); + BlockState state = level.getBlockState(targetPos); + + if (!state.is(ModBlocks.ALLOY_FURNACE.get())) { + Complete = false; + } + } + + return Complete; + } public static void tick(Level level, BlockPos pos, BlockState state, AlloyFurnaceBlockEntity blockEntity) { if (level.isClientSide() || !state.getValue(AlloyFurnaceMultiBlock.PARENT_BLOCK)) return; + if(blockEntity.pushBellow && blockEntity.BellowPush < MAX_BELLOW){ + blockEntity.BellowPush += 1; + } else if(blockEntity.pushBellow) blockEntity.pushBellow = false; + if (level.getGameTime() % 5 == 0) { + if (level.getGameTime() % 20 == 0) { + blockEntity.isFormed = blockEntity.UpdateCompleteStructure(level,pos,state,blockEntity.checkStructure(level, pos, state)); + } + if (blockEntity.isFormed) { + boolean AbleToStartCooking = blockEntity.items.get(2).getItem().equals(Items.DECORATED_POT) && (!blockEntity.items.get(0).isEmpty()||!blockEntity.items.get(1).isEmpty()); + blockEntity.BellowPush = Math.max(blockEntity.BellowPush - 1, 0); + if(blockEntity.AbleToCook) { + if (blockEntity.Fuel > 0) { + if(AbleToStartCooking && blockEntity.CookProcess < 1 && blockEntity.items.get(5).isEmpty() && blockEntity.items.get(6).isEmpty() && blockEntity.items.get(7).isEmpty()){ + blockEntity.items.set(5,blockEntity.items.get(0)); + blockEntity.items.set(6,blockEntity.items.get(1)); + blockEntity.items.set(7,blockEntity.items.get(2)); + blockEntity.items.set(0,ItemStack.EMPTY); + blockEntity.items.set(1,ItemStack.EMPTY); + blockEntity.items.set(2,ItemStack.EMPTY); + } - if (level.getGameTime() % 20 == 0) { - blockEntity.isFormed = blockEntity.checkStructure(level, pos, state); - } - - if (blockEntity.isFormed) { - blockEntity.progress++; - blockEntity.setChanged(); + if((!blockEntity.items.get(5).isEmpty() || !blockEntity.items.get(6).isEmpty() ) && !blockEntity.items.get(7).isEmpty()) { + blockEntity.CookProcess = Math.min(blockEntity.CookProcess + 1f + blockEntity.BellowPush,100); + } else blockEntity.CookProcess = 0; + } else if(!blockEntity.items.get(3).isEmpty() && ((!blockEntity.items.get(0).isEmpty() || !blockEntity.items.get(1).isEmpty() ) && !blockEntity.items.get(2).isEmpty() || (!blockEntity.items.get(5).isEmpty() || !blockEntity.items.get(6).isEmpty() ) && !blockEntity.items.get(7).isEmpty())){ + blockEntity.Fuel = 100f; + blockEntity.items.get(3).setCount(Math.max(blockEntity.items.get(3).getCount() - 1,0)); + } + if (blockEntity.CookProcess >= 100f) { + if (blockEntity.items.get(4).isEmpty()&& ((!blockEntity.items.get(5).isEmpty() || !blockEntity.items.get(6).isEmpty() ) && !blockEntity.items.get(7).isEmpty())) { + blockEntity.items.set(4, AlloyFurnaceUpdateHandler.CreateFilledPot(blockEntity.items.get(5),blockEntity.items.get(6))); + blockEntity.items.set(5,ItemStack.EMPTY); + blockEntity.items.set(6,ItemStack.EMPTY); + blockEntity.items.set(7,ItemStack.EMPTY); + } + blockEntity.CookProcess = 0; + } + } else{ + blockEntity.CookProcess = 0f; + } + blockEntity.Fuel = Math.max(blockEntity.Fuel - 1f, 0); + blockEntity.AbleToCook = blockEntity.items.get(4).isEmpty() ; + blockEntity.AbleToStartCooking = blockEntity.items.get(2).getItem().equals(Items.DECORATED_POT) && (!blockEntity.items.get(0).isEmpty()||!blockEntity.items.get(1).isEmpty()); + blockEntity.setChanged(); + } } } @@ -105,13 +170,19 @@ public class AlloyFurnaceBlockEntity extends RandomizableContainerBlockEntity im if (!this.tryLoadLootTable(input)) this.items = NonNullList.withSize(this.getContainerSize(), ItemStack.EMPTY); ContainerHelper.loadAllItems(input, this.items); - + this.Fuel = input.getFloatOr("fuel",0); + this.CookProcess = input.getFloatOr("cook_progress",0); + this.TemperatureC = input.getFloatOr("temp",0); + this.BellowPush = input.getFloatOr("bellow_push",0); } @Override public void saveAdditional(ValueOutput output) { super.saveAdditional(output); output.putFloat("fuel", this.Fuel); + output.putFloat("cook_progress", this.CookProcess); + output.putFloat("temp", this.TemperatureC); + output.putFloat("bellow_push", this.BellowPush); if (!this.trySaveLootTable(output)) ContainerHelper.saveAllItems(output, this.items); 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 7a52631..44f3bdd 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 @@ -10,6 +10,7 @@ import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.ContainerData; import net.minecraft.world.inventory.ContainerLevelAccess; import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; @@ -47,8 +48,9 @@ public class AlloyFurnaceGUI extends AbstractContainerMenu implements ModMenus.M private final Map customSlots = new HashMap<>(); private boolean bound = false; private Supplier boundItemMatcher = null; - private Entity boundEntity = null; private BlockEntity boundBlockEntity = null; + private final ContainerData data; + public AlloyFurnaceGUI(int containerId, Inventory playerInv, FriendlyByteBuf buffer) { @@ -120,6 +122,58 @@ public class AlloyFurnaceGUI extends AbstractContainerMenu implements ModMenus.M for (int col = 0; col < 9; ++col) { this.addSlot(new Slot(playerInv, col, 8 + col * 18, 142)); } + if (boundBlockEntity instanceof AlloyFurnaceBlockEntity alloyFurnaceBlockEntity) { + this.data = new ContainerData() { + @Override + public int get(int index) { + int returnVal = 0; + switch (index) { + case 0: + returnVal = alloyFurnaceBlockEntity.GetCookProgress(); + break; + case 1: + returnVal = alloyFurnaceBlockEntity.GetFuel(); + break; + case 2: + returnVal = alloyFurnaceBlockEntity.GetTemperatureC(); + break; + case 3: + returnVal = alloyFurnaceBlockEntity.GetBellowPush(); + break; + } + return returnVal; + } + + @Override + public void set(int index, int value) { + switch(index) { + case 0: + alloyFurnaceBlockEntity.SetCookProgress(value); + break; + case 1: + alloyFurnaceBlockEntity.SetFuel(value); + break; + case 2: + alloyFurnaceBlockEntity.SetTemperatureC(value); + break; + case 3: + alloyFurnaceBlockEntity.SetBellowPush(value); + break; + } + } + + @Override + public int getCount() { + return 4; + } + }; + + this.addDataSlots(this.data); + } else this.data = null; + } + + public int getSyncedVariable(int index) { + return this.data.get(index); } private void setItemInSlot(int index, ItemResource resource, int amount) { @@ -148,8 +202,6 @@ public class AlloyFurnaceGUI extends AbstractContainerMenu implements ModMenus.M return this.boundItemMatcher.get(); else if (this.boundBlockEntity != null) return AbstractContainerMenu.stillValid(this.access, player, this.boundBlockEntity.getBlockState().getBlock()); - else if (this.boundEntity != null) - return this.boundEntity.isAlive(); } return true; } 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 a506e1f..5747db3 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 @@ -118,37 +118,6 @@ public class AlloyFurnaceMultiBlock extends Block implements EntityBlock { if (blockState.getValue(PARENT_BLOCK)) AgeoftheGods.LOGGER.debug("becoming PARENT_BLOCK"); return blockState; } - //old case switch hard code - /*// AgeoftheGods.LOGGER.debug("POS_STRING: " + PosString); - String PosString = Math.abs(offset.getX()) + "_" + Math.abs(offset.getY()) + "_" + Math.abs(offset.getZ()); - switch (PosString) { - case "0_0_0": - blockState = blockState.setValue(PARENT_BLOCK, true); - blockState = blockState.setValue(MODEL_PART, 0); - break; - case "1_0_0": - blockState = blockState.setValue(MODEL_PART, 1); - break; - case "1_0_1": - blockState = blockState.setValue(MODEL_PART, 2); - break; - case "0_0_1": - blockState = blockState.setValue(MODEL_PART, 3); - break; - case "0_1_0": - blockState = blockState.setValue(MODEL_PART, 4); - break; - case "1_1_0": - blockState = blockState.setValue(MODEL_PART, 5); - break; - case "1_1_1": - blockState = blockState.setValue(MODEL_PART, 6); - break; - case "0_1_1": - blockState = blockState.setValue(MODEL_PART, 7); - break; - }*/ - @Override protected void createBlockStateDefinition(StateDefinition.Builder builder){ builder.add(MODEL_PART); @@ -161,30 +130,21 @@ public class AlloyFurnaceMultiBlock extends Block implements EntityBlock { 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) { - 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; + if(!blockstate.getBlock().getName().getString().equals(ModBlocks.ALLOY_FURNACE.get().getName().getString()) || pos == null || !blockstate.getValue(COMPLETE_STRUCTURE)) return InteractionResult.PASS; + AgeoftheGods.LOGGER.debug("OPENING ALLOY FURNACE | POS: " + pos); 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"); - } + BlockPos TargetPos = AlloyFurnaceUpdateHandler.GetParentPosFromModelPart(world, ModelPart, blockstate, pos); + 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(TargetPos)); - } - }, 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/java/net/halbear/aotg/custom/blocks/AlloyFurnace/AlloyFurnaceUpdateHandler.java b/src/main/java/net/halbear/aotg/custom/blocks/AlloyFurnace/AlloyFurnaceUpdateHandler.java index 191b023..2ce51fe 100644 --- a/src/main/java/net/halbear/aotg/custom/blocks/AlloyFurnace/AlloyFurnaceUpdateHandler.java +++ b/src/main/java/net/halbear/aotg/custom/blocks/AlloyFurnace/AlloyFurnaceUpdateHandler.java @@ -1,6 +1,7 @@ package net.halbear.aotg.custom.blocks.AlloyFurnace; import net.halbear.aotg.AgeoftheGods; +import net.halbear.aotg.registries.ModBlocks; import net.halbear.aotg.registries.ModItems; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -9,8 +10,9 @@ import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.item.component.ItemContainerContents; -import net.minecraft.world.level.ItemLike; +import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Rotation; +import net.minecraft.world.level.block.state.BlockState; import net.neoforged.fml.common.EventBusSubscriber; import net.neoforged.neoforge.event.level.BlockEvent; @@ -18,6 +20,9 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import static net.halbear.aotg.custom.blocks.AlloyFurnace.AlloyFurnaceMultiBlock.FACING; +import static net.halbear.aotg.custom.blocks.AlloyFurnace.AlloyFurnaceMultiBlock.PARENT_BLOCK; + @EventBusSubscriber(modid = AgeoftheGods.MODID) public class AlloyFurnaceUpdateHandler { @@ -38,12 +43,22 @@ public class AlloyFurnaceUpdateHandler { return ModelPartLookup.get(PosString); } + public static BlockPos GetParentPosFromModelPart(Level world, int ModelPart, BlockState state, BlockPos sourcePos){ + if(ModelPart == 0) return sourcePos; + BlockPos offset = AlloyFurnaceUpdateHandler.parts[ModelPart]; + Direction direction = state.getValue(FACING); + Rotation rotation = getInverseRotationForDirection(direction); + BlockPos Rotated = offset.rotate(rotation); + BlockPos TargetPos = new BlockPos(sourcePos.getX() - Rotated.getX(), sourcePos.getY() - Rotated.getY(), sourcePos.getZ() - Rotated.getZ()); + if(world.getBlockState(TargetPos).getBlock().getName().getString().equals(ModBlocks.ALLOY_FURNACE.get().getName().getString()) && + world.getBlockState(TargetPos).getValue(PARENT_BLOCK)) return TargetPos; + return null; + } - protected ItemStack CreateFilledPot(Item ItemToFillWith, int StackSize){ + protected static ItemStack CreateFilledPot(ItemStack ItemToFillWith, ItemStack ItemToFillWith2){ ItemStack potStack = new ItemStack(Items.DECORATED_POT); - ItemStack newContents = new ItemStack(ItemToFillWith,StackSize); ItemStack liquidMarker = new ItemStack(ModItems.FLUID_INDICATOR_ITEM.asItem(),1); - ItemContainerContents contents = ItemContainerContents.fromItems(List.of(liquidMarker, newContents)); + ItemContainerContents contents = ItemContainerContents.fromItems(List.of(liquidMarker, ItemToFillWith != null ? ItemToFillWith : ItemStack.EMPTY,ItemToFillWith2 != null ? ItemToFillWith2 : ItemStack.EMPTY)); potStack.set(DataComponents.CONTAINER, contents); return potStack; } diff --git a/src/main/java/net/halbear/aotg/registries/ModRecipeProvider.java b/src/main/java/net/halbear/aotg/registries/ModRecipeProvider.java new file mode 100644 index 0000000..2e2d9ae --- /dev/null +++ b/src/main/java/net/halbear/aotg/registries/ModRecipeProvider.java @@ -0,0 +1,4 @@ +package net.halbear.aotg.registries; + +public class ModRecipeProvider { +} diff --git a/src/main/java/net/halbear/aotg/utility/Networking/AlloyFurnaceGuiButtonHandler.java b/src/main/java/net/halbear/aotg/utility/Networking/AlloyFurnaceGuiButtonHandler.java new file mode 100644 index 0000000..462e839 --- /dev/null +++ b/src/main/java/net/halbear/aotg/utility/Networking/AlloyFurnaceGuiButtonHandler.java @@ -0,0 +1,86 @@ +package net.halbear.aotg.utility.Networking; + +import net.halbear.aotg.AgeoftheGods; +import net.halbear.aotg.custom.blocks.AlloyFurnace.AlloyFurnaceBlockEntity; +import net.halbear.aotg.custom.blocks.AlloyFurnace.AlloyFurnaceUpdateHandler; +import net.halbear.aotg.registries.ModBlocks; +import net.minecraft.core.BlockPos; +import net.minecraft.core.SectionPos; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.chat.Component; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.network.protocol.PacketFlow; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.Identifier; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.EventBusSubscriber; +import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent; +import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent; +import net.neoforged.neoforge.network.handling.IPayloadContext; +import net.neoforged.neoforge.network.registration.PayloadRegistrar; + +import static net.halbear.aotg.custom.blocks.AlloyFurnace.AlloyFurnaceMultiBlock.MODEL_PART; +import static net.halbear.aotg.custom.blocks.AlloyFurnace.AlloyFurnaceMultiBlock.PARENT_BLOCK; + +@EventBusSubscriber +public record AlloyFurnaceGuiButtonHandler(int buttonID, int x, int y, int z) implements CustomPacketPayload { + public static final Type TYPE = new Type<>(Identifier.fromNamespaceAndPath(AgeoftheGods.MODID, "alloy_furnace_buttons")); + public static final StreamCodec STREAM_CODEC = StreamCodec.of((RegistryFriendlyByteBuf buffer, AlloyFurnaceGuiButtonHandler message) -> { + buffer.writeInt(message.buttonID); + buffer.writeInt(message.x); + buffer.writeInt(message.y); + buffer.writeInt(message.z); + }, (RegistryFriendlyByteBuf buffer) -> new AlloyFurnaceGuiButtonHandler(buffer.readInt(), buffer.readInt(), buffer.readInt(), buffer.readInt())); + + @Override + public Type type() { + return TYPE; + } + + public static void handleData(final AlloyFurnaceGuiButtonHandler message, final IPayloadContext context) { + if (context.flow() == PacketFlow.SERVERBOUND) { + context.enqueueWork(() -> handleButtonAction(context.player(), message.buttonID, message.x, message.y, message.z)).exceptionally(e -> { + context.connection().disconnect(Component.literal(e.getMessage())); + return null; + }); + } + } + + public static void handleButtonAction(Player entity, int buttonID, int x, int y, int z) { + Level world = entity.level(); + AgeoftheGods.LOGGER.debug("BUTTON PRESSED, Entity: " + entity.getName().getString() + " | ButtonID: " + buttonID + " | XYZ: " + x + " " + y + " " + z); + if (!world.getChunkSource().hasChunk(SectionPos.blockToSectionCoord(x), SectionPos.blockToSectionCoord(z))) + return; + if (buttonID == 0) { + BlockPos TargetPos = new BlockPos(x,y,z); + BlockState blockstate = world.getBlockState(new BlockPos(x,y,z)); + if(blockstate.getBlock().getName().getString().equals(ModBlocks.ALLOY_FURNACE.get().getName().getString()) && !blockstate.getValue(PARENT_BLOCK)) { + int ModelPart = blockstate.getValue(MODEL_PART); + TargetPos = AlloyFurnaceUpdateHandler.GetParentPosFromModelPart(world, ModelPart, blockstate, new BlockPos(x, y, z)); + } + BlockEntity blockEntity = world.getBlockEntity(new BlockPos(TargetPos)); + if(blockEntity instanceof AlloyFurnaceBlockEntity alloyFurnaceBlockEntity){ + alloyFurnaceBlockEntity.PushBellow(); + } + } + } + @SubscribeEvent + public static void registerMessage(final RegisterPayloadHandlersEvent event) { + final PayloadRegistrar registrar = event.registrar("1.0.0"); + + registrar.playToServer( + AlloyFurnaceGuiButtonHandler.TYPE, + AlloyFurnaceGuiButtonHandler.STREAM_CODEC, + AlloyFurnaceGuiButtonHandler::handleData + ); + } + @SubscribeEvent + public static void registerMessage(FMLCommonSetupEvent event) { + AgeoftheGods.addNetworkMessage(AlloyFurnaceGuiButtonHandler.TYPE, AlloyFurnaceGuiButtonHandler.STREAM_CODEC, AlloyFurnaceGuiButtonHandler::handleData); + } + +} diff --git a/src/main/java/net/halbear/aotg/utility/ServerModEventHandler.java b/src/main/java/net/halbear/aotg/utility/ServerModEventHandler.java index bc2ad47..b9233ef 100644 --- a/src/main/java/net/halbear/aotg/utility/ServerModEventHandler.java +++ b/src/main/java/net/halbear/aotg/utility/ServerModEventHandler.java @@ -3,19 +3,16 @@ package net.halbear.aotg.utility; import net.halbear.aotg.AgeoftheGods; import net.halbear.aotg.registries.ModItems; import net.minecraft.core.BlockPos; -import net.minecraft.core.NonNullList; -import net.minecraft.core.component.DataComponents; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.Items; -import net.minecraft.world.item.component.ItemContainerContents; import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.DecoratedPotBlockEntity; import net.minecraft.world.level.material.Fluids; import net.neoforged.bus.api.SubscribeEvent; import net.neoforged.fml.common.EventBusSubscriber; +import net.neoforged.neoforge.capabilities.Capabilities; import net.neoforged.neoforge.event.level.BlockEvent; +import net.neoforged.neoforge.transfer.ResourceHandler; +import net.neoforged.neoforge.transfer.item.ItemResource; @EventBusSubscriber(modid = AgeoftheGods.MODID) public class ServerModEventHandler { @@ -26,17 +23,20 @@ public class ServerModEventHandler { BlockPos pos = event.getPos(); BlockEntity blockEntity = level.getBlockEntity(pos); - + AgeoftheGods.LOGGER.debug("Block Entity Broken: " + (blockEntity == null ? "no block entity" : blockEntity.getNameForReporting())); if (blockEntity instanceof DecoratedPotBlockEntity potEntity) { - ItemContainerContents contents = potEntity.getContainerBlockEntity().components().get(DataComponents.CONTAINER); + AgeoftheGods.LOGGER.debug("Pot Entity Broken! "); + ResourceHandler itemHandler = level.getCapability(Capabilities.Item.BLOCK, potEntity.getBlockPos(),potEntity.getBlockState(),potEntity,null); - if (contents != null) { - boolean hasMarker = contents.getStackInSlot(0).is(ModItems.FLUID_INDICATOR_ITEM.asItem()); + + if (itemHandler != null) { + boolean hasMarker = itemHandler.getResource(0).getItem().equals(ModItems.FLUID_INDICATOR_ITEM.asItem()); + AgeoftheGods.LOGGER.debug("Pot Entity Contents Exist! Marker: " + hasMarker +" | Item in first slot: " + itemHandler.getResource(0).getItem().toString()); if (hasMarker) { potEntity.getContainerBlockEntity().setRemoved(); potEntity.setChanged(); - level.setBlock(pos, Fluids.WATER.defaultFluidState().createLegacyBlock(), 3); + level.setBlock(pos, Fluids.LAVA.defaultFluidState().createLegacyBlock(), 3); event.setCanceled(true); } diff --git a/src/main/resources/assets/ageofthegods/lang/en_us.json b/src/main/resources/assets/ageofthegods/lang/en_us.json index 4f713fc..43df201 100644 --- a/src/main/resources/assets/ageofthegods/lang/en_us.json +++ b/src/main/resources/assets/ageofthegods/lang/en_us.json @@ -9,7 +9,10 @@ "block.ageofthegods.olive_log": "Olive Log", "block.ageofthegods.alloy_furnace": "Alloy Furnace Segment", + "gui.ageofthegods.alloy_furnace_gui.title": "Alloy Furnace", + "item.ageofthegods.xiphos": "Xiphos", + "item.ageofthegods.fluid_indicator_debug_item": "Molten Alloy Mixture: ", "ageofthegods.configuration.title": "Age of the Gods Configs", "ageofthegods.configuration.section.ageofthegods.common.toml": "Age of the Gods Configs", diff --git a/src/main/resources/assets/ageofthegods/textures/screens/alloy_furnace_flame_gui.png b/src/main/resources/assets/ageofthegods/textures/screens/alloy_furnace_flame_gui.png new file mode 100644 index 0000000..20b6bfb Binary files /dev/null and b/src/main/resources/assets/ageofthegods/textures/screens/alloy_furnace_flame_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 index 46ff1e1..61e32d5 100644 Binary files a/src/main/resources/assets/ageofthegods/textures/screens/bellow-sheet.png and b/src/main/resources/assets/ageofthegods/textures/screens/bellow-sheet.png differ diff --git a/src/main/resources/assets/ageofthegods/textures/screens/bellow_button.png b/src/main/resources/assets/ageofthegods/textures/screens/bellow_button.png new file mode 100644 index 0000000..00fa1c1 Binary files /dev/null and b/src/main/resources/assets/ageofthegods/textures/screens/bellow_button.png differ diff --git a/src/main/resources/assets/ageofthegods/textures/screens/bellow_button_hover.png b/src/main/resources/assets/ageofthegods/textures/screens/bellow_button_hover.png new file mode 100644 index 0000000..aed55fe Binary files /dev/null and b/src/main/resources/assets/ageofthegods/textures/screens/bellow_button_hover.png differ diff --git a/src/main/resources/data/ageofthegods/recipe/alloy_furnace_segment.json b/src/main/resources/data/ageofthegods/recipe/alloy_furnace_segment.json new file mode 100644 index 0000000..d143976 --- /dev/null +++ b/src/main/resources/data/ageofthegods/recipe/alloy_furnace_segment.json @@ -0,0 +1,18 @@ +{ + "type": "minecraft:crafting_shaped", + "category": "equipment", + "pattern": [ + "aaa", + "aba", + "ccc" + ], + "key": { + "a": "minecraft:bricks", + "b": "minecraft:leather", + "c": "minecraft:smooth_stone_slab" + }, + "result": { + "id": "ageofthegods:alloy_furnace", + "count": 1 + } +} \ No newline at end of file