MinecraftScripterAI
Discord ↗
Link Copied to Clipboard
×
"create a machine that learn blocks around and visualize what learn on the gui"
-- First, create a custom block entity class that extends BlockEntity and implements ITickableBlockEntity to handle the learning and visualization process public class LearningMachineBlockEntity extends BlockEntity implements ITickableBlockEntity { private final List<BlockState> learnedBlocks = new ArrayList<>(); private int ticks; public LearningMachineBlockEntity(BlockPos pos, BlockState state) { super(BlockEntityInit.LEARNING_MACHINE.get(), pos, state); } @Override public void tick() { -- Increment the tick counter ticks++; -- Learn blocks around every 20 ticks (1 second) if (ticks % 20 == 0) { learnBlocksAround(); } } private void learnBlocksAround() { -- Iterate through the blocks around the machine for (int x = -1; x <= 1; x++) { for (int y = -1; y <= 1; y++) { for (int z = -1; z <= 1; z++) { BlockPos neighborPos = worldPosition.offset(x, y, z); BlockState neighborState = level.getBlockState(neighborPos); -- Add the block state to the list if it's not already there if (!learnedBlocks.contains(neighborState)) { learnedBlocks.add(neighborState); } } } } } -- Getter for the learned blocks list public List<BlockState> getLearnedBlocks() { return learnedBlocks; } } -- Next, create a custom container class for the GUI public class LearningMachineContainer extends AbstractContainerMenu { private final LearningMachineBlockEntity blockEntity; public LearningMachineContainer(int id, Inventory playerInventory, LearningMachineBlockEntity blockEntity) { super(ContainerInit.LEARNING_MACHINE.get(), id); this.blockEntity = blockEntity; } -- Getter for the block entity public LearningMachineBlockEntity getBlockEntity() { return blockEntity; } } -- Finally, create a custom screen class for the GUI public class LearningMachineScreen extends AbstractContainerScreen<LearningMachineContainer> { public LearningMachineScreen(LearningMachineContainer container, Inventory playerInventory, Component title) { super(container, playerInventory, title); } @Override protected void renderBg(PoseStack matrixStack, float partialTicks, int mouseX, int mouseY) { -- Render the background and learned blocks visualization } @Override public void render(PoseStack matrixStack, int mouseX, int mouseY, float partialTicks) { -- Render the container and tooltips super.render(matrixStack, mouseX, mouseY, partialTicks); } }