MinecraftScripterAI
Discord ↗
Link Copied to Clipboard
×
"create a machine that learn blocks around and visualize what learn on the gui"
-- First, create a block class for your machine that extends BlockContainer. Then, create a tile entity class that extends TileEntity and implements IInventory. In your tile entity class, you can write the logic for learning blocks around and storing that information in the inventory. Finally, create a GUI class that extends ContainerScreen and displays the information stored in the tile entity's inventory. public class LearningMachineBlock extends BlockContainer { public LearningMachineBlock() { super(Material.IRON); setRegistryName("learning_machine_block"); setUnlocalizedName("learning_machine_block"); setCreativeTab(CreativeTabs.MISC); } @Override public TileEntity createNewTileEntity(World worldIn, int meta) { return new LearningMachineTileEntity(); } } public class LearningMachineTileEntity extends TileEntity implements IInventory { private ItemStack[] inventory; public LearningMachineTileEntity() { inventory = new ItemStack[getSizeInventory()]; } @Override public int getSizeInventory() { return 9; } @Override public boolean isEmpty() { for (ItemStack itemStack : inventory) { if (!itemStack.isEmpty()) { return false; } } return true; } @Override public ItemStack getStackInSlot(int index) { return inventory[index]; } @Override public ItemStack decrStackSize(int index, int count) { if (inventory[index].isEmpty()) { return ItemStack.EMPTY; } ItemStack itemStack; if (inventory[index].getCount() <= count) { itemStack = inventory[index]; inventory[index] = ItemStack.EMPTY; markDirty(); return itemStack; } else { itemStack = inventory[index].splitStack(count); if (inventory[index].getCount() == 0) { inventory[index] = ItemStack.EMPTY; } markDirty(); return itemStack; } } @Override public ItemStack removeStackFromSlot(int index) { ItemStack itemStack = inventory[index]; inventory[index] = ItemStack.EMPTY; return itemStack; } @Override public void setInventorySlotContents(int index, ItemStack stack) { inventory[index] = stack; markDirty(); } @Override public int getInventoryStackLimit() { return 64; } @Override public boolean isUsableByPlayer(PlayerEntity player) { return true; } @Override public void openInventory(PlayerEntity player) {} @Override public void closeInventory(PlayerEntity player) {} @Override public boolean isItemValidForSlot(int index, ItemStack stack) { return true; } @Override public void clear() { for (int i = 0; i < inventory.length; i++) { inventory[i] = ItemStack.EMPTY; } markDirty(); } } public class LearningMachineGui extends ContainerScreen<LearningMachineContainer> { private static final ResourceLocation BACKGROUND_TEXTURE = new ResourceLocation("minecraft:textures/gui/container/generic_54.png"); public LearningMachineGui(LearningMachineContainer container, PlayerInventory playerInventory, ITextComponent title) { super(container, playerInventory, title); xSize = 176; ySize = 222; } @Override protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); minecraft.getTextureManager().bindTexture(BACKGROUND_TEXTURE); int i = (width - xSize) / 2; int j = (height - ySize) / 2; blit(i, j, 0, 0, xSize, ySize); } @Override protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { font.drawString(title.getFormattedText(), 8, 6, 4210752); font.drawString(playerInventory.getDisplayName().getFormattedText(), 8, ySize - 96 + 2, 4210752); } } public class LearningMachineContainer extends Container { private final LearningMachineTileEntity tileEntity; public LearningMachineContainer(int windowId, PlayerInventory playerInventory, LearningMachineTileEntity tileEntity) { super(ModContainers.LEARNING_MACHINE.get(), windowId); this.tileEntity = tileEntity; for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { addSlot(new Slot(tileEntity, j + i * 3, 62 + j * 18, 17 + i * 18)); } } for (int k = 0; k < 3; ++k) { for (int i1 = 0; i1 < 9; ++i1) { addSlot(new Slot(playerInventory, i1 + k * 9 + 9, 8 + i1 * 18, 84 + k * 18)); } } for (int l = 0; l < 9; ++l) { addSlot(new Slot(playerInventory, l, 8 + l * 18, 142)); } } @Override public boolean canInteractWith(PlayerEntity playerIn) { return tileEntity.isUsableByPlayer(playerIn); } }