alloy furnace functionality
This commit is contained in:
@@ -11,7 +11,9 @@ import net.minecraft.world.level.biome.Biome;
|
|||||||
import net.minecraft.world.level.dimension.DimensionType;
|
import net.minecraft.world.level.dimension.DimensionType;
|
||||||
import net.minecraft.world.level.levelgen.WorldGenSettings;
|
import net.minecraft.world.level.levelgen.WorldGenSettings;
|
||||||
import net.neoforged.bus.api.Event;
|
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.handling.IPayloadHandler;
|
||||||
|
import net.neoforged.neoforge.network.registration.PayloadRegistrar;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
import com.mojang.logging.LogUtils;
|
import com.mojang.logging.LogUtils;
|
||||||
@@ -144,5 +146,13 @@ public class AgeoftheGods {
|
|||||||
MESSAGES.put(id, new NetworkMessage<>(reader, handler));
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,24 +1,43 @@
|
|||||||
package net.halbear.aotg.custom.GuiScreens;
|
package net.halbear.aotg.custom.GuiScreens;
|
||||||
|
|
||||||
import com.mojang.blaze3d.platform.InputConstants;
|
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.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.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.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.gui.screens.inventory.AbstractContainerScreen;
|
||||||
import net.minecraft.client.input.KeyEvent;
|
import net.minecraft.client.input.KeyEvent;
|
||||||
import net.minecraft.client.renderer.RenderPipelines;
|
import net.minecraft.client.renderer.RenderPipelines;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.resources.Identifier;
|
import net.minecraft.resources.Identifier;
|
||||||
import net.minecraft.world.entity.player.Inventory;
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.level.Level;
|
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<AlloyFurnaceGUI> implements ModScreens.ScreenAccessor {
|
public class AlloyFurnaceGUIScreen extends AbstractContainerScreen<AlloyFurnaceGUI> implements ModScreens.ScreenAccessor {
|
||||||
private final Level world;
|
private final Level world;
|
||||||
private final int x, y, z;
|
private final int x, y, z;
|
||||||
private final Player entity;
|
private final Player entity;
|
||||||
private boolean menuStateUpdateActive = false;
|
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 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) {
|
public AlloyFurnaceGUIScreen(AlloyFurnaceGUI container, Inventory inventory, Component text) {
|
||||||
super(container, inventory, text, 176, 166);
|
super(container, inventory, text, 176, 166);
|
||||||
@@ -43,6 +62,30 @@ public class AlloyFurnaceGUIScreen extends AbstractContainerScreen<AlloyFurnaceG
|
|||||||
public void extractBackground(GuiGraphicsExtractor guiGraphics, int mouseX, int mouseY, float partialTicks) {
|
public void extractBackground(GuiGraphicsExtractor guiGraphics, int mouseX, int mouseY, float partialTicks) {
|
||||||
super.extractBackground(guiGraphics, mouseX, mouseY, partialTicks);
|
super.extractBackground(guiGraphics, mouseX, mouseY, partialTicks);
|
||||||
guiGraphics.blit(RenderPipelines.GUI_TEXTURED, BACKGROUND, this.leftPos, this.topPos, 0, 0, this.imageWidth, this.imageHeight, this.imageWidth, this.imageHeight);
|
guiGraphics.blit(RenderPipelines.GUI_TEXTURED, BACKGROUND, this.leftPos, this.topPos, 0, 0, this.imageWidth, this.imageHeight, this.imageWidth, this.imageHeight);
|
||||||
|
int bellowPush = this.menu.getSyncedVariable(3);
|
||||||
|
int blowerSprite = (int)Math.clamp(3 * (float)bellowPush/(float)MAX_BELLOW,0,2);
|
||||||
|
guiGraphics.blit(RenderPipelines.GUI_TEXTURED, BELLOW_SPRITE_SHEET, this.leftPos + 9, this.topPos + 58, 0, 20 * blowerSprite, 35, 20, 35, 60);
|
||||||
|
int CookProgress = GetMoltenProgress(world,x,y,z,19,0,0);
|
||||||
|
if(CookProgress > 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
|
@Override
|
||||||
@@ -57,10 +100,26 @@ public class AlloyFurnaceGUIScreen extends AbstractContainerScreen<AlloyFurnaceG
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void extractLabels(GuiGraphicsExtractor guiGraphics, int mouseX, int mouseY) {
|
protected void extractLabels(GuiGraphicsExtractor guiGraphics, int mouseX, int mouseY) {
|
||||||
|
guiGraphics.text(this.font, Component.translatable("gui.ageofthegods.alloy_furnace_gui.title"), 90, 6, -12829636, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init() {
|
public void init() {
|
||||||
super.init();
|
super.init();
|
||||||
|
Blower = new ImageButton( this.leftPos + 9, this.topPos + 58, 35, 20,
|
||||||
|
new WidgetSprites(Identifier.parse("ageofthegods:textures/screens/bellow_button.png"), Identifier.parse("ageofthegods:textures/screens/bellow_button.png")), e -> {
|
||||||
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+94
-23
@@ -1,6 +1,7 @@
|
|||||||
package net.halbear.aotg.custom.blocks.AlloyFurnace;
|
package net.halbear.aotg.custom.blocks.AlloyFurnace;
|
||||||
|
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
|
import net.halbear.aotg.AgeoftheGods;
|
||||||
import net.halbear.aotg.registries.ModBlocks;
|
import net.halbear.aotg.registries.ModBlocks;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Direction;
|
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.entity.player.Player;
|
||||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraft.world.item.Items;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.block.Rotation;
|
import net.minecraft.world.level.block.Rotation;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
@@ -43,29 +45,38 @@ public class AlloyFurnaceBlockEntity extends RandomizableContainerBlockEntity im
|
|||||||
|
|
||||||
private boolean isFormed = false;
|
private boolean isFormed = false;
|
||||||
private float Fuel = 0.0f;
|
private float Fuel = 0.0f;
|
||||||
private int progress = 0;
|
private float CookProcess = 0.0f;
|
||||||
private NonNullList<ItemStack> items = NonNullList.withSize(5, ItemStack.EMPTY);
|
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<ItemStack> 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) {
|
public AlloyFurnaceBlockEntity(BlockPos worldPosition, BlockState blockState) {
|
||||||
super(ALLOY_FURNACE_BLOCK_ENTITY.get(), worldPosition, blockState);
|
super(ALLOY_FURNACE_BLOCK_ENTITY.get(), worldPosition, blockState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean UpdateCompleteStructure(Level level, BlockPos masterPos, BlockState blockState, boolean Complete){
|
||||||
public boolean checkStructure(Level level, BlockPos masterPos, BlockState blockState) {
|
|
||||||
Direction direction = blockState.getValue(FACING);
|
Direction direction = blockState.getValue(FACING);
|
||||||
Rotation rotation = getInverseRotationForDirection(direction);
|
Rotation rotation = getInverseRotationForDirection(direction);
|
||||||
boolean Complete =true;
|
BlockPos[] Positions = new BlockPos[MULTI_BLOCK_POSITIONS.length + 1];
|
||||||
for (BlockPos offset : MULTI_BLOCK_POSITIONS) {
|
Positions[0] = new BlockPos(0,0,0);
|
||||||
|
for(int i = 0; i < MULTI_BLOCK_POSITIONS.length; i++){
|
||||||
BlockPos Rotated = offset.rotate(rotation);
|
Positions[1 + i] = MULTI_BLOCK_POSITIONS[i];
|
||||||
BlockPos targetPos = masterPos.offset(Rotated);
|
|
||||||
BlockState state = level.getBlockState(targetPos);
|
|
||||||
|
|
||||||
if (!state.is(ModBlocks.ALLOY_FURNACE.get())) {
|
|
||||||
Complete = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for (BlockPos offset : MULTI_BLOCK_POSITIONS) {
|
for (BlockPos offset : Positions) {
|
||||||
BlockPos Rotated = offset.rotate(rotation);
|
BlockPos Rotated = offset.rotate(rotation);
|
||||||
BlockPos targetPos = masterPos.offset(Rotated);
|
BlockPos targetPos = masterPos.offset(Rotated);
|
||||||
BlockState state = level.getBlockState(targetPos);
|
BlockState state = level.getBlockState(targetPos);
|
||||||
@@ -84,18 +95,72 @@ public class AlloyFurnaceBlockEntity extends RandomizableContainerBlockEntity im
|
|||||||
}
|
}
|
||||||
return Complete;
|
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) {
|
public static void tick(Level level, BlockPos pos, BlockState state, AlloyFurnaceBlockEntity blockEntity) {
|
||||||
if (level.isClientSide() || !state.getValue(AlloyFurnaceMultiBlock.PARENT_BLOCK)) return;
|
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) {
|
if((!blockEntity.items.get(5).isEmpty() || !blockEntity.items.get(6).isEmpty() ) && !blockEntity.items.get(7).isEmpty()) {
|
||||||
blockEntity.isFormed = blockEntity.checkStructure(level, pos, state);
|
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())){
|
||||||
if (blockEntity.isFormed) {
|
blockEntity.Fuel = 100f;
|
||||||
blockEntity.progress++;
|
blockEntity.items.get(3).setCount(Math.max(blockEntity.items.get(3).getCount() - 1,0));
|
||||||
blockEntity.setChanged();
|
}
|
||||||
|
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))
|
if (!this.tryLoadLootTable(input))
|
||||||
this.items = NonNullList.withSize(this.getContainerSize(), ItemStack.EMPTY);
|
this.items = NonNullList.withSize(this.getContainerSize(), ItemStack.EMPTY);
|
||||||
ContainerHelper.loadAllItems(input, this.items);
|
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
|
@Override
|
||||||
public void saveAdditional(ValueOutput output) {
|
public void saveAdditional(ValueOutput output) {
|
||||||
super.saveAdditional(output);
|
super.saveAdditional(output);
|
||||||
output.putFloat("fuel", this.Fuel);
|
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))
|
if (!this.trySaveLootTable(output))
|
||||||
ContainerHelper.saveAllItems(output, this.items);
|
ContainerHelper.saveAllItems(output, this.items);
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import net.minecraft.world.entity.Entity;
|
|||||||
import net.minecraft.world.entity.player.Inventory;
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||||
|
import net.minecraft.world.inventory.ContainerData;
|
||||||
import net.minecraft.world.inventory.ContainerLevelAccess;
|
import net.minecraft.world.inventory.ContainerLevelAccess;
|
||||||
import net.minecraft.world.inventory.Slot;
|
import net.minecraft.world.inventory.Slot;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
@@ -47,8 +48,9 @@ public class AlloyFurnaceGUI extends AbstractContainerMenu implements ModMenus.M
|
|||||||
private final Map<Integer, Slot> customSlots = new HashMap<>();
|
private final Map<Integer, Slot> customSlots = new HashMap<>();
|
||||||
private boolean bound = false;
|
private boolean bound = false;
|
||||||
private Supplier<Boolean> boundItemMatcher = null;
|
private Supplier<Boolean> boundItemMatcher = null;
|
||||||
private Entity boundEntity = null;
|
|
||||||
private BlockEntity boundBlockEntity = null;
|
private BlockEntity boundBlockEntity = null;
|
||||||
|
private final ContainerData data;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public AlloyFurnaceGUI(int containerId, Inventory playerInv, FriendlyByteBuf buffer) {
|
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) {
|
for (int col = 0; col < 9; ++col) {
|
||||||
this.addSlot(new Slot(playerInv, col, 8 + col * 18, 142));
|
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) {
|
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();
|
return this.boundItemMatcher.get();
|
||||||
else if (this.boundBlockEntity != null)
|
else if (this.boundBlockEntity != null)
|
||||||
return AbstractContainerMenu.stillValid(this.access, player, this.boundBlockEntity.getBlockState().getBlock());
|
return AbstractContainerMenu.stillValid(this.access, player, this.boundBlockEntity.getBlockState().getBlock());
|
||||||
else if (this.boundEntity != null)
|
|
||||||
return this.boundEntity.isAlive();
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-53
@@ -118,37 +118,6 @@ public class AlloyFurnaceMultiBlock extends Block implements EntityBlock {
|
|||||||
if (blockState.getValue(PARENT_BLOCK)) AgeoftheGods.LOGGER.debug("becoming PARENT_BLOCK");
|
if (blockState.getValue(PARENT_BLOCK)) AgeoftheGods.LOGGER.debug("becoming PARENT_BLOCK");
|
||||||
return blockState;
|
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
|
@Override
|
||||||
protected void createBlockStateDefinition(StateDefinition.Builder<Block,BlockState> builder){
|
protected void createBlockStateDefinition(StateDefinition.Builder<Block,BlockState> builder){
|
||||||
builder.add(MODEL_PART);
|
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) {
|
public InteractionResult useWithoutItem(BlockState blockstate, Level world, BlockPos pos, Player entity, BlockHitResult hit) {
|
||||||
super.useWithoutItem(blockstate, world, pos, entity, hit);
|
super.useWithoutItem(blockstate, world, pos, entity, hit);
|
||||||
if (entity instanceof ServerPlayer player) {
|
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()) || pos == null || !blockstate.getValue(COMPLETE_STRUCTURE)) return InteractionResult.PASS;
|
||||||
if(!blockstate.getBlock().getName().getString().equals(ModBlocks.ALLOY_FURNACE.get().getName().getString()) ||
|
AgeoftheGods.LOGGER.debug("OPENING ALLOY FURNACE | POS: " + pos);
|
||||||
blockstate.getBlock().getName().getString().equals(ModBlocks.ALLOY_FURNACE.get().getName().getString()) && !blockstate.getValue(COMPLETE_STRUCTURE)) return InteractionResult.PASS;
|
|
||||||
int ModelPart = blockstate.getValue(MODEL_PART);
|
int ModelPart = blockstate.getValue(MODEL_PART);
|
||||||
BlockPos offset = AlloyFurnaceUpdateHandler.parts[ModelPart];
|
BlockPos TargetPos = AlloyFurnaceUpdateHandler.GetParentPosFromModelPart(world, ModelPart, blockstate, pos);
|
||||||
Direction direction = blockstate.getValue(FACING);
|
player.openMenu(new MenuProvider() {
|
||||||
Rotation rotation = getInverseRotationForDirection(direction);
|
@Override
|
||||||
BlockPos Rotated = offset.rotate(rotation);
|
public Component getDisplayName() {
|
||||||
BlockPos TargetPos = new BlockPos(pos.getX() - Rotated.getX(), pos.getY() - Rotated.getY(), pos.getZ() - Rotated.getZ());
|
return Component.literal("Sigma");
|
||||||
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
|
@Override
|
||||||
public AbstractContainerMenu createMenu(int id, Inventory inventory, Player player) {
|
public AbstractContainerMenu createMenu(int id, Inventory inventory, Player player) {
|
||||||
return new AlloyFurnaceGUI(id, inventory, new FriendlyByteBuf(Unpooled.buffer()).writeBlockPos(TargetPos));
|
return new AlloyFurnaceGUI(id, inventory, new FriendlyByteBuf(Unpooled.buffer()).writeBlockPos(TargetPos));
|
||||||
}
|
}
|
||||||
}, pos);
|
}, pos);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return InteractionResult.SUCCESS;
|
return InteractionResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-4
@@ -1,6 +1,7 @@
|
|||||||
package net.halbear.aotg.custom.blocks.AlloyFurnace;
|
package net.halbear.aotg.custom.blocks.AlloyFurnace;
|
||||||
|
|
||||||
import net.halbear.aotg.AgeoftheGods;
|
import net.halbear.aotg.AgeoftheGods;
|
||||||
|
import net.halbear.aotg.registries.ModBlocks;
|
||||||
import net.halbear.aotg.registries.ModItems;
|
import net.halbear.aotg.registries.ModItems;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Direction;
|
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.ItemStack;
|
||||||
import net.minecraft.world.item.Items;
|
import net.minecraft.world.item.Items;
|
||||||
import net.minecraft.world.item.component.ItemContainerContents;
|
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.Rotation;
|
||||||
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.neoforged.fml.common.EventBusSubscriber;
|
import net.neoforged.fml.common.EventBusSubscriber;
|
||||||
import net.neoforged.neoforge.event.level.BlockEvent;
|
import net.neoforged.neoforge.event.level.BlockEvent;
|
||||||
|
|
||||||
@@ -18,6 +20,9 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
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)
|
@EventBusSubscriber(modid = AgeoftheGods.MODID)
|
||||||
public class AlloyFurnaceUpdateHandler {
|
public class AlloyFurnaceUpdateHandler {
|
||||||
|
|
||||||
@@ -38,12 +43,22 @@ public class AlloyFurnaceUpdateHandler {
|
|||||||
return ModelPartLookup.get(PosString);
|
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 potStack = new ItemStack(Items.DECORATED_POT);
|
||||||
ItemStack newContents = new ItemStack(ItemToFillWith,StackSize);
|
|
||||||
ItemStack liquidMarker = new ItemStack(ModItems.FLUID_INDICATOR_ITEM.asItem(),1);
|
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);
|
potStack.set(DataComponents.CONTAINER, contents);
|
||||||
return potStack;
|
return potStack;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package net.halbear.aotg.registries;
|
||||||
|
|
||||||
|
public class ModRecipeProvider {
|
||||||
|
}
|
||||||
@@ -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<AlloyFurnaceGuiButtonHandler> TYPE = new Type<>(Identifier.fromNamespaceAndPath(AgeoftheGods.MODID, "alloy_furnace_buttons"));
|
||||||
|
public static final StreamCodec<RegistryFriendlyByteBuf, AlloyFurnaceGuiButtonHandler> 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<AlloyFurnaceGuiButtonHandler> 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -3,19 +3,16 @@ package net.halbear.aotg.utility;
|
|||||||
import net.halbear.aotg.AgeoftheGods;
|
import net.halbear.aotg.AgeoftheGods;
|
||||||
import net.halbear.aotg.registries.ModItems;
|
import net.halbear.aotg.registries.ModItems;
|
||||||
import net.minecraft.core.BlockPos;
|
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.Level;
|
||||||
import net.minecraft.world.level.block.Blocks;
|
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
import net.minecraft.world.level.block.entity.DecoratedPotBlockEntity;
|
import net.minecraft.world.level.block.entity.DecoratedPotBlockEntity;
|
||||||
import net.minecraft.world.level.material.Fluids;
|
import net.minecraft.world.level.material.Fluids;
|
||||||
import net.neoforged.bus.api.SubscribeEvent;
|
import net.neoforged.bus.api.SubscribeEvent;
|
||||||
import net.neoforged.fml.common.EventBusSubscriber;
|
import net.neoforged.fml.common.EventBusSubscriber;
|
||||||
|
import net.neoforged.neoforge.capabilities.Capabilities;
|
||||||
import net.neoforged.neoforge.event.level.BlockEvent;
|
import net.neoforged.neoforge.event.level.BlockEvent;
|
||||||
|
import net.neoforged.neoforge.transfer.ResourceHandler;
|
||||||
|
import net.neoforged.neoforge.transfer.item.ItemResource;
|
||||||
|
|
||||||
@EventBusSubscriber(modid = AgeoftheGods.MODID)
|
@EventBusSubscriber(modid = AgeoftheGods.MODID)
|
||||||
public class ServerModEventHandler {
|
public class ServerModEventHandler {
|
||||||
@@ -26,17 +23,20 @@ public class ServerModEventHandler {
|
|||||||
|
|
||||||
BlockPos pos = event.getPos();
|
BlockPos pos = event.getPos();
|
||||||
BlockEntity blockEntity = level.getBlockEntity(pos);
|
BlockEntity blockEntity = level.getBlockEntity(pos);
|
||||||
|
AgeoftheGods.LOGGER.debug("Block Entity Broken: " + (blockEntity == null ? "no block entity" : blockEntity.getNameForReporting()));
|
||||||
if (blockEntity instanceof DecoratedPotBlockEntity potEntity) {
|
if (blockEntity instanceof DecoratedPotBlockEntity potEntity) {
|
||||||
ItemContainerContents contents = potEntity.getContainerBlockEntity().components().get(DataComponents.CONTAINER);
|
AgeoftheGods.LOGGER.debug("Pot Entity Broken! ");
|
||||||
|
ResourceHandler<ItemResource> 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) {
|
if (hasMarker) {
|
||||||
potEntity.getContainerBlockEntity().setRemoved();
|
potEntity.getContainerBlockEntity().setRemoved();
|
||||||
potEntity.setChanged();
|
potEntity.setChanged();
|
||||||
level.setBlock(pos, Fluids.WATER.defaultFluidState().createLegacyBlock(), 3);
|
level.setBlock(pos, Fluids.LAVA.defaultFluidState().createLegacyBlock(), 3);
|
||||||
|
|
||||||
event.setCanceled(true);
|
event.setCanceled(true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,10 @@
|
|||||||
"block.ageofthegods.olive_log": "Olive Log",
|
"block.ageofthegods.olive_log": "Olive Log",
|
||||||
"block.ageofthegods.alloy_furnace": "Alloy Furnace Segment",
|
"block.ageofthegods.alloy_furnace": "Alloy Furnace Segment",
|
||||||
|
|
||||||
|
"gui.ageofthegods.alloy_furnace_gui.title": "Alloy Furnace",
|
||||||
|
|
||||||
"item.ageofthegods.xiphos": "Xiphos",
|
"item.ageofthegods.xiphos": "Xiphos",
|
||||||
|
"item.ageofthegods.fluid_indicator_debug_item": "Molten Alloy Mixture: ",
|
||||||
|
|
||||||
"ageofthegods.configuration.title": "Age of the Gods Configs",
|
"ageofthegods.configuration.title": "Age of the Gods Configs",
|
||||||
"ageofthegods.configuration.section.ageofthegods.common.toml": "Age of the Gods Configs",
|
"ageofthegods.configuration.section.ageofthegods.common.toml": "Age of the Gods Configs",
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 278 B |
Binary file not shown.
|
Before Width: | Height: | Size: 809 B After Width: | Height: | Size: 937 B |
Binary file not shown.
|
After Width: | Height: | Size: 95 B |
Binary file not shown.
|
After Width: | Height: | Size: 121 B |
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user