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.

Featured Replies

You need to create a new class that extends GuiContainer. Look at the vanilla examples of such.

You will also need one that extends Container (again, look at the vanilla examples).

And a class that implements IGuiHandler

Edited by Draco18s

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • Author
3 minutes ago, Draco18s said:

You need to create a new class that extends GuiContainer. Look at the vanilla examples of such.

And how about the processing, recipes? Like I put two items in the first two slots and it creates a new one... Like the anvil

You need to mimic what the furnace does (assuming single input + fuel) or what the crafting table does (any number of inputs or outputs greater than 1).

 

I have something similar here:

https://github.com/Draco18s/ReasonableRealism/blob/1.12.1/src/main/java/com/draco18s/ores/recipes/OreProcessingRecipes.java#L35-93

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • Author
2 minutes ago, Draco18s said:

You need to mimic what the furnace does (assuming single input + fuel) or what the crafting table does (any number of inputs or outputs greater than 1).

 

I have something similar here:

https://github.com/Draco18s/ReasonableRealism/blob/1.12.1/src/main/java/com/draco18s/ores/recipes/OreProcessingRecipes.java#L35-93

Thanks for now, I'll see if my noob skills will be able to do it.

  • Author

And how can I implement some code that makes the items inside the Container to go back to the player's inventory, when the container is closed? I can't manage to find any clue in the vanilla classes.

Edited by Arthur Wesley

1 hour ago, Arthur Wesley said:

And how can I implement some code that makes the items inside the Container to go back to the player's inventory, when the container is closed? I can't manage to find any clue in the vanilla classes.

 

ContainerWorkbench (the Crafting Table's Container) does this in its onContainerClosed method. If you're using IItemHandler for your inventories (which you should be), you'll need to replicate the logic in Container#clearContainer rather than calling it directly.

Edited by Choonster

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

  • Author
3 hours ago, Choonster said:

 

ContainerWorkbench (the Crafting Table's Container) does this in its onContainerClosed method. If you're using IItemHandler for your inventories (which you should be), you'll need to replicate the logic in Container#clearContainer rather than calling it directly.

Thank you.

  • Author

Yay, the slots are worknig. I only need now a recipe system.

 

package tutuicraft3.sapphirecraft.blocks.msinfusortileentity;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.InventoryCraftResult;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.inventory.SlotCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;

public class MSInfusorContainer extends Container {
	
	public InventoryCrafting craftMatrix = new InventoryCrafting(this, 3, 3);
	public InventoryCraftResult craftResult = new InventoryCraftResult();
	private final World world;
	
	public MSInfusorContainer(InventoryPlayer playerInv, World worldIn, final TileEntityMSInfusor infusor) {
		this.world = worldIn;
		IItemHandler inventory = infusor.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.NORTH);
        addSlotToContainer(new SlotCrafting(playerInv.player, this.craftMatrix, this.craftResult, 0, 134, 40));
        addSlotToContainer(new Slot(this.craftMatrix, 0, 27, 40));
		addSlotToContainer(new Slot(this.craftMatrix, 1, 76, 40) {
			@Override
			public void onSlotChanged() {
				infusor.markDirty();
			}
		});
	
		
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 9; j++) {
				addSlotToContainer(new Slot(playerInv, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
			}
		}
	
		for (int k = 0; k < 9; k++) {
			addSlotToContainer(new Slot(playerInv, k, 8 + k * 18, 142));
		}
	}
	
	@Override
    public void onContainerClosed(EntityPlayer playerIn)
    {
        super.onContainerClosed(playerIn);

        if (!this.world.isRemote)
        {
            this.clearContainer(playerIn, this.world, this.craftMatrix);
        }
    }

	@Override
	public boolean canInteractWith(EntityPlayer player) {
		return true;
	}
	
	@Override
	public ItemStack transferStackInSlot(EntityPlayer player, int index) {
		ItemStack itemstack = ItemStack.EMPTY;
		Slot slot = inventorySlots.get(index);
	
		if (slot != null && slot.getHasStack()) {
			ItemStack itemstack1 = slot.getStack();
			itemstack = itemstack1.copy();
	
			int containerSlots = inventorySlots.size() - player.inventory.mainInventory.size();
	
			if (index < containerSlots) {
				if (!this.mergeItemStack(itemstack1, containerSlots, inventorySlots.size(), true)) {
					return ItemStack.EMPTY;
				}
			} else if (!this.mergeItemStack(itemstack1, 0, containerSlots, false)) {
				return ItemStack.EMPTY;
			}
	
			if (itemstack1.getCount() == 0) {
				slot.putStack(ItemStack.EMPTY);
			} else {
				slot.onSlotChanged();
			}
	
			if (itemstack1.getCount() == itemstack.getCount()) {
				return ItemStack.EMPTY;
			}
	
			slot.onTake(player, itemstack1);
		}
	
		return itemstack;
	}
}

 

  • Author

One little thing, I noticed that my GUI is different from the others in one aspect, it doesn't get it's outer part darker. Normal GUIs have its "focus", making everything around it draker, but mine just opens the GUI and don't get darker, strange because I followed correctly the tutorial, and in there his GUI was darker around.

  • Author
18 hours ago, Arthur Wesley said:

One little thing, I noticed that my GUI is different from the others in one aspect, it doesn't get it's outer part darker. Normal GUIs have its "focus", making everything around it draker, but mine just opens the GUI and don't get darker, strange because I followed correctly the tutorial, and in there his GUI was darker around.

I've made it. Just had to add drawDefaultBackground(); to my GUI class on drawGuiContainerBackgroundLayer method:

	@Override
	protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
		drawDefaultBackground();
		GlStateManager.color(1, 1, 1, 1);
		mc.getTextureManager().bindTexture(BG_TEXTURE);
		int x = (width - xSize) / 2;
		int y = (height - ySize) / 2;
		drawTexturedModalRect(x, y, 0, 0, xSize, ySize);	}

 

Or you could call super

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

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.