Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

MrOlegTitov

Members
  • Joined

  • Last visited

  1. I need to do the generation of my structures in the overworld, what is the best way to do it?
  2. I want to make my items display using the 2D texture in my inventory, but have a completely different 3D model when the player actually holds them, and they are displayed in their hand. Is this even possible, and if so, how do I do it?
  3. Workbench Screen class: package net.xale.satiscraft.screen; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.TextComponent; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraftforge.client.gui.widget.ExtendedButton; import net.xale.satiscraft.SatisCraft; import net.xale.satiscraft.block.entity.WorkbenchBlockEntity; import net.xale.satiscraft.container.WorkbenchContainer; import net.xale.satiscraft.crafting.WorkbenchRecipe; import net.xale.satiscraft.crafting.WorkbenchRecipes; public class WorkbenchScreen extends AbstractContainerScreen<WorkbenchContainer> { private static final ResourceLocation GUI_TEXTURE = new ResourceLocation(SatisCraft.MOD_ID, "textures/gui/workbench.png"); private ExtendedButton craftbutton; public WorkbenchScreen(WorkbenchContainer container, Inventory playerInventory, Component title){ super(container, playerInventory, title); this.leftPos = 0; this.topPos = 0; this.imageWidth = 176; this.imageHeight = 166; } @Override protected void renderBg(PoseStack stack, float mouseX, int mouseY, int partialTicks) { renderBackground(stack); bindTexture(); blit(stack, this.leftPos, this.topPos, 0, 0, this.imageWidth, this.imageHeight); } @Override protected void renderLabels(PoseStack stack, int mouseX, int mouseY){ } @Override public void render(PoseStack stack, int mouseX, int mouseY, float partialTicks) { super.render(stack, mouseX, mouseY, partialTicks); this.font.draw(stack, this.title, this.leftPos + 20, this.topPos + 5, 0xFFFFFF); this.font.draw(stack, this.playerInventoryTitle, this.leftPos + 5, this.topPos + 73, 0x404040); } @Override protected void init(){ super.init(); this.craftbutton = this.addRenderableWidget(new ExtendedButton(150, 35, 40, 20, new TextComponent("Craft!"), btn -> { Minecraft.getInstance().gameMode.handleInventoryButtonClick(1, 0); })); } public static void bindTexture(){ RenderSystem.setShader(GameRenderer::getPositionColorTexShader); RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f); RenderSystem.setShaderTexture(0, GUI_TEXTURE); } } WorkbenchContainer class: package net.xale.satiscraft.container; import net.minecraft.client.Minecraft; import net.minecraft.core.BlockPos; import net.minecraft.network.chat.TextComponent; import net.minecraft.world.Container; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.*; import net.minecraft.world.item.ItemStack; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.ItemStackHandler; import net.minecraftforge.items.SlotItemHandler; import net.xale.satiscraft.block.entity.WorkbenchBlockEntity; import net.xale.satiscraft.crafting.WorkbenchRecipes; import net.xale.satiscraft.init.BlockInit; import net.xale.satiscraft.init.ContainerInit; public class WorkbenchContainer extends AbstractContainerMenu { private final ContainerLevelAccess containerAccess; // Client Constructor public WorkbenchContainer(int id, Inventory playerInv) { this(id, playerInv, new ItemStackHandler(27), BlockPos.ZERO); } // Server constructor public WorkbenchContainer(int id, Inventory playerInv, IItemHandler slots, BlockPos pos) { super(ContainerInit.WORKBENCH.get(), id); this.containerAccess = ContainerLevelAccess.create(playerInv.player.level, pos); final int slotSizePlus2 = 18, startX = 8, startY = 84, hotbarY = 142; for (int column = 0; column < 9; column++) { for (int row = 0; row < 3; row++) { addSlot(new Slot(playerInv, 9 + row * 9 + column, startX + column * slotSizePlus2, startY + row * slotSizePlus2)); } addSlot(new Slot(playerInv, column, startX + column * slotSizePlus2, hotbarY)); } addSlot(new SlotItemHandler(slots, 0, 30, 35)); addSlot(new SlotItemHandler(slots, 1, 48, 35)); addSlot(new SlotItemHandler(slots, 2, 66, 35)); addSlot(new SlotItemHandler(slots, 3, 125, 35)); } @Override public boolean clickMenuButton(Player clickedBy, int buttonId) { super.clickMenuButton(clickedBy, buttonId); if (buttonId == 0) { ItemStack result = WorkbenchRecipes.getInstance().getCraftingResult(this.getSlot(36).getItem(), this.getSlot(37).getItem(), this.getSlot(38).getItem()); if (result != ItemStack.EMPTY && !this.getSlot(39).hasItem()) { this.getSlot(36).getItem().shrink(1); this.getSlot(37).getItem().shrink(1); this.getSlot(38).getItem().shrink(1); this.getSlot(39).safeInsert(result); } } return true; } @Override public ItemStack quickMoveStack(Player player, int index) { var retStack = ItemStack.EMPTY; final Slot slot = getSlot(index); if (slot.hasItem()) { final ItemStack item = slot.getItem(); retStack = item.copy(); if (index < 27) { if (!moveItemStackTo(item, 27, this.slots.size(), true)) return ItemStack.EMPTY; } else if (!moveItemStackTo(item, 0, 27, false)) return ItemStack.EMPTY; if (item.isEmpty()) { slot.set(ItemStack.EMPTY); } else { slot.setChanged(); } } return retStack; } @Override public boolean stillValid(Player player) { return stillValid(this.containerAccess, player, BlockInit.WORKBENCH.get()); } public static MenuConstructor getServerContainer(WorkbenchBlockEntity workbenchBlock, BlockPos pos) { return (id, playerInv, player) -> new WorkbenchContainer(id, playerInv, workbenchBlock.inventory, pos); } }
  4. I meant that I exit the workbench interface by pressing escape and then open it by clicking on the block.
  5. Hello, everyone. When developing a mod, I needed to set an icon for items that have a 3D model. That is, I want the item to have an icon in inventory, but when the item is in hand, the model is displayed. How can I do this?
  6. I've got a bug, when I exit the gui and reopen it, the event stops working when the button is pressed. What can this be connected to?
  7. This function takes two parameters, what should I pass to it?
  8. This function takes two parameters, what should I pass to it?
  9. Hello all. I've started building a custom workbench, but have run into a problem. According to my idea, a person needs to press a special button to create a thing. But I don't know how to track its pressing from container class. I tried using ContainerData class, but it seems you can't change its values from Screen class. What can I do to fix this issue? ? Container Class: package net.xale.satiscraft.container; import net.minecraft.client.Minecraft; import net.minecraft.core.BlockPos; import net.minecraft.network.chat.TextComponent; import net.minecraft.world.Container; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.*; import net.minecraft.world.item.ItemStack; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.ItemStackHandler; import net.minecraftforge.items.SlotItemHandler; import net.xale.satiscraft.block.entity.WorkbenchBlockEntity; import net.xale.satiscraft.container.syncdata.WorkbenchContainerData; import net.xale.satiscraft.crafting.WorkbenchRecipes; import net.xale.satiscraft.init.BlockInit; import net.xale.satiscraft.init.ContainerInit; public class WorkbenchContainer extends AbstractContainerMenu { private final ContainerLevelAccess containerAccess; public final ContainerData data; // Client Constructor public WorkbenchContainer(int id, Inventory playerInv) { this(id, playerInv, new ItemStackHandler(27), BlockPos.ZERO, new SimpleContainerData(1)); } // Server constructor public WorkbenchContainer(int id, Inventory playerInv, IItemHandler slots, BlockPos pos, ContainerData data) { super(ContainerInit.WORKBENCH.get(), id); this.containerAccess = ContainerLevelAccess.create(playerInv.player.level, pos); this.data = data; final int slotSizePlus2 = 18, startX = 8, startY = 84, hotbarY = 142; for (int column = 0; column < 9; column++){ for (int row = 0; row < 3; row++){ addSlot(new Slot(playerInv, 9 + row * 9 + column, startX + column * slotSizePlus2, startY + row * slotSizePlus2)); } addSlot(new Slot(playerInv, column, startX + column * slotSizePlus2, hotbarY)); } addSlot(new SlotItemHandler(slots, 0, 30, 35)); addSlot(new SlotItemHandler(slots, 1, 48, 35)); addSlot(new SlotItemHandler(slots, 2, 66, 35)); addSlot(new SlotItemHandler(slots, 3, 125, 35)); addDataSlots(data); } @Override public void broadcastChanges() { if (this.data.get(0) == 1){ ItemStack result = WorkbenchRecipes.getInstance().getCraftingResult(this.getSlot(36).getItem(), this.getSlot(37).getItem(), this.getSlot(38).getItem()); if (result != ItemStack.EMPTY){ this.getSlot(36).getItem().shrink(1); this.getSlot(37).getItem().shrink(1); this.getSlot(38).getItem().shrink(1); this.getSlot(39).safeInsert(result, 1); this.data.set(0, 0); } } } @Override public ItemStack quickMoveStack(Player player, int index) { var retStack = ItemStack.EMPTY; final Slot slot = getSlot(index); if (slot.hasItem()) { final ItemStack item = slot.getItem(); retStack = item.copy(); if (index < 27) { if (!moveItemStackTo(item, 27, this.slots.size(), true)) return ItemStack.EMPTY; } else if (!moveItemStackTo(item, 0, 27, false)) return ItemStack.EMPTY; if (item.isEmpty()) { slot.set(ItemStack.EMPTY); } else { slot.setChanged(); } } return retStack; } @Override public boolean stillValid(Player player) { return stillValid(this.containerAccess, player, BlockInit.WORKBENCH.get()); } public static MenuConstructor getServerContainer(WorkbenchBlockEntity workbenchBlock, BlockPos pos) { return (id, playerInv, player) -> new WorkbenchContainer(id, playerInv, workbenchBlock.inventory, pos, new WorkbenchContainerData(workbenchBlock, 1)); } } Screen Class: package net.xale.satiscraft.screen; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.TextComponent; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraftforge.client.gui.widget.ExtendedButton; import net.xale.satiscraft.SatisCraft; import net.xale.satiscraft.block.entity.WorkbenchBlockEntity; import net.xale.satiscraft.container.WorkbenchContainer; import net.xale.satiscraft.crafting.WorkbenchRecipe; import net.xale.satiscraft.crafting.WorkbenchRecipes; public class WorkbenchScreen extends AbstractContainerScreen<WorkbenchContainer> { private static final ResourceLocation GUI_TEXTURE = new ResourceLocation(SatisCraft.MOD_ID, "textures/gui/workbench.png"); private ExtendedButton craftbutton; public WorkbenchScreen(WorkbenchContainer container, Inventory playerInventory, Component title){ super(container, playerInventory, title); this.leftPos = 0; this.topPos = 0; this.imageWidth = 176; this.imageHeight = 166; } @Override protected void renderBg(PoseStack stack, float mouseX, int mouseY, int partialTicks) { RenderSystem.setShader(GameRenderer::getPositionColorTexShader); RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f); RenderSystem.setShaderTexture(0, GUI_TEXTURE); blit(stack, this.leftPos, this.topPos, 0, 0, this.imageWidth, this.imageHeight); } @Override protected void renderLabels(PoseStack stack, int mouseX, int mouseY){ drawString(stack, font, title, this.leftPos, this.topPos + 2, 0x404040); drawString(stack, font, playerInventoryTitle, this.leftPos + 8, this.topPos + 80, 0x404040); } @Override protected void init(){ super.init(); this.craftbutton = this.addRenderableWidget(new ExtendedButton(leftPos, topPos, 16, 16, new TextComponent("Craft!"), btn -> { if (this.menu.data.get(0) == 0){ this.menu.data.set(0, 1); Minecraft.getInstance().player.displayClientMessage(new TextComponent(String.valueOf(this.menu.data.get(0))), false); } })); } } Custom Container Data Class: package net.xale.satiscraft.container.syncdata; import net.minecraft.client.Minecraft; import net.minecraft.network.chat.TextComponent; import net.minecraft.world.inventory.ContainerData; import net.minecraft.world.inventory.SimpleContainerData; import net.xale.satiscraft.block.entity.WorkbenchBlockEntity; import net.xale.satiscraft.container.WorkbenchContainer; public class WorkbenchContainerData extends SimpleContainerData { private final WorkbenchBlockEntity blockEntity; public WorkbenchContainerData(WorkbenchBlockEntity be, int amount){ super(amount); this.blockEntity = be; } @Override public int get(int key) { return switch (key){ case 0 -> this.blockEntity.canCraft; default -> throw new UnsupportedOperationException("There is no value corresponding to key: '" + key + "' in '" + this.blockEntity + "'"); }; } @Override public void set(int key, int value) { Minecraft.getInstance().player.displayClientMessage(new TextComponent("Trying to set!"), false); switch (key){ case 0: Minecraft.getInstance().player.displayClientMessage(new TextComponent("Setting 0"), false); this.blockEntity.canCraft = 1; break; default: throw new UnsupportedOperationException("There is no value corresponding to key: '" + key + "' in '" + this.blockEntity + "'"); } } }

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.