Jump to content

[1.7.10] Custom Crafting Table Issues


Whyneb360

Recommended Posts

So, as the title says, I am making a custom crafting table.

 

My issues are as follows:

 

1. Shift clicking a stack of items crashes the game

2. When you open the crafting table, your inventory moves all over the place, and sometimes items duplicate or move to the crafting grid by themselves

3. Custom crafting recipes don't work

 

Here is the code for all my related classes (Sorry about the copy pasta):

 

ContainerWorkbench:

package com.descon.container;

import com.descon.mod.WorkBenchCraftingManager;
import com.descon.propsmain.PropsGeneral;
import com.descon.tileentity.TileEntityWorkbench;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
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.world.World;

public class ContainerWorkbench extends Container {

public InventoryCrafting craftMatrix;
public IInventory craftResult;
private World worldObj;
private int posX;
private int posY;
private int posZ;

public ContainerWorkbench (InventoryPlayer inventory, TileEntityWorkbench entity, World world, int x, int y, int z) {
	craftMatrix = new InventoryCrafting(this, 3, 3);
	craftResult = new InventoryCraftResult();
	worldObj = world;
	posX = x;
	posY = y;
	posZ = z;
	int l;
        int i1;

        for (l = 0; l < 3; ++l)
        {
            for (i1 = 0; i1 < 3; ++i1)
            {
                this.addSlotToContainer(new Slot(this.craftMatrix, i1 + l * 3, 30 + i1 * 18, 17 + l * 18));
            }
        }

        for (l = 0; l < 3; ++l)
        {
            for (i1 = 0; i1 < 9; ++i1)
            {
                this.addSlotToContainer(new Slot(inventory, i1 + l * 9 + 9, 8 + i1 * 18, 84 + l * 18));
            }
        }

        for (l = 0; l < 9; ++l)
        {
            this.addSlotToContainer(new Slot(inventory, l, 8 + l * 18, 142));
        }

        this.onCraftMatrixChanged(this.craftMatrix);
    }


public void onCraftMatricChanged(IInventory iiventory) {
	craftResult.setInventorySlotContents(0, WorkBenchCraftingManager.getInstance().findMatchingRecipe(craftMatrix, worldObj));
}

@Override
public boolean canInteractWith(EntityPlayer player) {
	if(worldObj.getBlock(posX, posY, posZ) != PropsGeneral.designersworkbench) {
		return false;
	}else{
		return player.getDistanceSq((double)posX + 0.5D, (double)posY + 0.5D, (double)posZ + 0.5D) <= 64.0D;
	}
}

public void onContainerClosed(EntityPlayer p_75134_1_)
{
	super.onContainerClosed(p_75134_1_);

	if (!this.worldObj.isRemote)
	{
		for (int i = 0; i < 9; ++i)
		{
			ItemStack itemstack = this.craftMatrix.getStackInSlotOnClosing(i);

			if (itemstack != null)
			{
				p_75134_1_.dropPlayerItemWithRandomChoice(itemstack, false);
			}
		}
	}
}


public ItemStack transferStackInSlot(EntityPlayer entityplayer, int q)
{
	ItemStack itemstack = null;
	Slot slot = (Slot)this.inventorySlots.get(q);

	if (slot != null && slot.getHasStack())
	{
		ItemStack itemstack1 = slot.getStack();
		itemstack = itemstack1.copy();

		if (q == 0)
		{
			if (!this.mergeItemStack(itemstack1, 10, 46, true))
			{
				return null;
			}

			slot.onSlotChange(itemstack1, itemstack);
		}
		else if (q >= 10 && q < 37)
		{
			if (!this.mergeItemStack(itemstack1, 37, 46, false))
			{
				return null;
			}
		}
		else if (q >= 37 && q < 46)
		{
			if (!this.mergeItemStack(itemstack1, 10, 37, false))
			{
				return null;
			}
		}
		else if (!this.mergeItemStack(itemstack1, 10, 46, false))
		{
			return null;
		}

		if (itemstack1.stackSize == 0)
		{
			slot.putStack((ItemStack)null);
		}
		else
		{
			slot.onSlotChanged();
		}

		if (itemstack1.stackSize == itemstack.stackSize)
		{
			return null;
		}

		slot.onPickupFromSlot(entityplayer, itemstack1);
	}

	return itemstack;
}

}

 

GuiHandler:

package com.descon.gui;

import com.descon.container.ContainerWorkbench;
import com.descon.propsmain.PropsGeneral;
import com.descon.tileentity.TileEntityWorkbench;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import cpw.mods.fml.common.network.IGuiHandler;

public class GuiHandler implements IGuiHandler {

@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world,	int x, int y, int z) {
	TileEntity entity = world.getTileEntity(x, y, z);

	if(entity != null) {
		switch(ID) {
		case PropsGeneral.guiIDdesignersworkbench:
			if (entity instanceof TileEntityWorkbench) {
				return new ContainerWorkbench(player.inventory, (TileEntityWorkbench) entity, world, x, y, z);
			}
			return null;

		}
	}
	return null;

}

@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world,	int x, int y, int z) {
	TileEntity entity = world.getTileEntity(x, y, z);

	if(entity != null) {
		switch(ID) {
		case PropsGeneral.guiIDdesignersworkbench:
			if (entity instanceof TileEntityWorkbench) {
				return new GuiWorkbench(player.inventory, world, x, z, z);
			}
		}
	}
	return null;
}
}

 

GuiWorkbench:

package com.descon.gui;

import org.lwjgl.opengl.GL11;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ContainerWorkbench;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;

import com.descon.mod.Main;

public class GuiWorkbench extends GuiContainer{

private ResourceLocation texture = new ResourceLocation(Main.modID + ":" + "textures/gui/WorkbenchTexture.png");

public GuiWorkbench(InventoryPlayer invPlayer, World world, int x, int y, int z) {
	super(new ContainerWorkbench(invPlayer, world, x, y, z));
	// TODO Auto-generated constructor stub

	this.xSize = 176;
	this.ySize = 166;
}

public void onGuiClosed() {
	super.onGuiClosed();
}

protected void drawGuiContainerForegroundLayer(int i, int j) {

	this.fontRendererObj.drawString(StatCollector.translateToLocal("Designer's Workbench"), 100, 5, 0x000000);
}

@Override
protected void drawGuiContainerBackgroundLayer(float var1, int var2, int var3) {

	GL11.glColor4f(1F, 1F, 1F, 1F);

	Minecraft.getMinecraft().getTextureManager().bindTexture(texture);

	drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
}

}

 

Main class FMLInitializationEvent:

@EventHandler
public void init(FMLInitializationEvent preEvent) {

	//Renderers
	desconProxy.registerRenderThing();
	desconProxy.registerItemRenderers();

	NetworkRegistry.INSTANCE.registerGuiHandler(this, new GuiHandler());

 

WorkBenchCraftingManager:

package com.descon.mod;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;

import com.descon.crafting.WorkBenchShapedRecipes;
import com.descon.propsmain.PropsModern;

import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.RecipeBookCloning;
import net.minecraft.item.crafting.RecipeFireworks;
import net.minecraft.item.crafting.RecipesArmor;
import net.minecraft.item.crafting.RecipesArmorDyes;
import net.minecraft.item.crafting.RecipesCrafting;
import net.minecraft.item.crafting.RecipesDyes;
import net.minecraft.item.crafting.RecipesFood;
import net.minecraft.item.crafting.RecipesIngots;
import net.minecraft.item.crafting.RecipesMapCloning;
import net.minecraft.item.crafting.RecipesMapExtending;
import net.minecraft.item.crafting.RecipesTools;
import net.minecraft.item.crafting.RecipesWeapons;
import net.minecraft.item.crafting.ShapedRecipes;
import net.minecraft.item.crafting.ShapelessRecipes;
import net.minecraft.world.World;

public class WorkBenchCraftingManager {
/** The static instance of this class */
private static final WorkBenchCraftingManager instance = new WorkBenchCraftingManager();
/** A list of all the recipes added */
private List recipes = new ArrayList();
private static final String __OBFID = "CL_00000090";

/**
 * Returns the static instance of this class
 */
public static final WorkBenchCraftingManager getInstance()
{
	/** The static instance of this class */
	return instance;
}

private WorkBenchCraftingManager()
{
	recipes = new ArrayList();

	this.addRecipe(new ItemStack(PropsModern.laptop, 1), new Object[] {"SSS", "SSS", "SSS", 'S', Items.stick});

	Collections.sort(this.recipes, new WorkBenchRecipeSorter(this));

}

public WorkBenchShapedRecipes addRecipe(ItemStack p_92103_1_, Object ... p_92103_2_)
{
	String s = "";
	int i = 0;
	int j = 0;
	int k = 0;

	if (p_92103_2_[i] instanceof String[])
	{
		String[] astring = (String[])((String[])p_92103_2_[i++]);

		for (int l = 0; l < astring.length; ++l)
		{
			String s1 = astring[l];
			++k;
			j = s1.length();
			s = s + s1;
		}
	}
	else
	{
		while (p_92103_2_[i] instanceof String)
		{
			String s2 = (String)p_92103_2_[i++];
			++k;
			j = s2.length();
			s = s + s2;
		}
	}

	HashMap hashmap;

	for (hashmap = new HashMap(); i < p_92103_2_.length; i += 2)
	{
		Character character = (Character)p_92103_2_[i];
		ItemStack itemstack1 = null;

		if (p_92103_2_[i + 1] instanceof Item)
		{
			itemstack1 = new ItemStack((Item)p_92103_2_[i + 1]);
		}
		else if (p_92103_2_[i + 1] instanceof Block)
		{
			itemstack1 = new ItemStack((Block)p_92103_2_[i + 1], 1, 32767);
		}
		else if (p_92103_2_[i + 1] instanceof ItemStack)
		{
			itemstack1 = (ItemStack)p_92103_2_[i + 1];
		}

		hashmap.put(character, itemstack1);
	}

	ItemStack[] aitemstack = new ItemStack[j * k];

	for (int i1 = 0; i1 < j * k; ++i1)
	{
		char c0 = s.charAt(i1);

		if (hashmap.containsKey(Character.valueOf(c0)))
		{
			aitemstack[i1] = ((ItemStack)hashmap.get(Character.valueOf(c0))).copy();
		}
		else
		{
			aitemstack[i1] = null;
		}
	}

	WorkBenchShapedRecipes shapedrecipes = new WorkBenchShapedRecipes(j, k, aitemstack, p_92103_1_);
	this.recipes.add(shapedrecipes);
	return shapedrecipes;
}

public void addShapelessRecipe(ItemStack p_77596_1_, Object ... p_77596_2_)
{
	ArrayList arraylist = new ArrayList();
	Object[] aobject = p_77596_2_;
	int i = p_77596_2_.length;

	for (int j = 0; j < i; ++j)
	{
		Object object1 = aobject[j];

		if (object1 instanceof ItemStack)
		{
			arraylist.add(((ItemStack)object1).copy());
		}
		else if (object1 instanceof Item)
		{
			arraylist.add(new ItemStack((Item)object1));
		}
		else
		{
			if (!(object1 instanceof Block))
			{
				throw new RuntimeException("Invalid shapeless recipe!");
			}

			arraylist.add(new ItemStack((Block)object1));
		}
	}

	this.recipes.add(new ShapelessRecipes(p_77596_1_, arraylist));
}

public ItemStack findMatchingRecipe(InventoryCrafting p_82787_1_, World p_82787_2_)
{
	int i = 0;
	ItemStack itemstack = null;
	ItemStack itemstack1 = null;
	int j;

	for (j = 0; j < p_82787_1_.getSizeInventory(); ++j)
	{
		ItemStack itemstack2 = p_82787_1_.getStackInSlot(j);

		if (itemstack2 != null)
		{
			if (i == 0)
			{
				itemstack = itemstack2;
			}

			if (i == 1)
			{
				itemstack1 = itemstack2;
			}

			++i;
		}
	}

	if (i == 2 && itemstack.getItem() == itemstack1.getItem() && itemstack.stackSize == 1 && itemstack1.stackSize == 1 && itemstack.getItem().isRepairable())
	{
		Item item = itemstack.getItem();
		int j1 = item.getMaxDamage() - itemstack.getItemDamageForDisplay();
		int k = item.getMaxDamage() - itemstack1.getItemDamageForDisplay();
		int l = j1 + k + item.getMaxDamage() * 5 / 100;
		int i1 = item.getMaxDamage() - l;

		if (i1 < 0)
		{
			i1 = 0;
		}

		return new ItemStack(itemstack.getItem(), 1, i1);
	}
	else
	{
		for (j = 0; j < this.recipes.size(); ++j)
		{
			IRecipe irecipe = (IRecipe)this.recipes.get(j);

			if (irecipe.matches(p_82787_1_, p_82787_2_))
			{
				return irecipe.getCraftingResult(p_82787_1_);
			}
		}

		return null;
	}
}

/**
 * returns the List<> of all recipes
 */
public List getRecipeList()
{
	return this.recipes;
}
}

 

WorkBenchRecipeSorter:

package com.descon.mod;

import java.util.Comparator;

import com.descon.crafting.WorkBenchShapedRecipes;
import com.descon.crafting.WorkBenchShapelessRecipes;

import net.minecraft.item.crafting.IRecipe;

public class WorkBenchRecipeSorter implements Comparator {

final WorkBenchCraftingManager workSurface;

public WorkBenchRecipeSorter(WorkBenchCraftingManager workbenchcraftingmanager) {
	this.workSurface = workbenchcraftingmanager;
}

public int compareRecipes(IRecipe irecipe1, IRecipe irecipe2) {
	return irecipe1 instanceof WorkBenchShapelessRecipes && irecipe2 instanceof WorkBenchShapedRecipes ? 1: (irecipe2 instanceof WorkBenchShapelessRecipes && irecipe1 instanceof WorkBenchShapedRecipes ? -1 :(irecipe2.getRecipeSize() < irecipe1.getRecipeSize() ? -1 : (irecipe2.getRecipeSize() > irecipe1.getRecipeSize() ? 1 : 0)));
}

@Override
public int compare(Object o1, Object o2) {
	return this.compareRecipes((IRecipe)o1, (IRecipe)o2);
}

}

 

Workbench Block Class:

package com.descon.propsmain;

import com.descon.mod.DesconCreativeTabs;
import com.descon.mod.Main;
import com.descon.tileentity.TileEntityPlasmaTubeLight;
import com.descon.tileentity.TileEntityWorkbench;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;

public class Workbench extends BlockContainer {

public Workbench(Material material) {
	super(material);

	this.setCreativeTab(DesconCreativeTabs.tabGeneral);
	this.setHarvestLevel("axe", 1);
	this.setHardness(3F);
	this.setBlockBounds(0F, 0F, 0F, 1F, 1F, 2F);	
	}

public int getRenderType() {
	return -1;
}

public boolean isOpaqueCube() {
	return false;
}

public boolean renderAsNormalBlock() {
	return false;
}

public TileEntity createNewTileEntity(World var1, int var2) {
	return new TileEntityWorkbench();
}

@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconRegister) {
	this.blockIcon = iconRegister.registerIcon(Main.modID + ":" + this.getUnlocalizedName().substring(5));
}

//Directional Bollocks

public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack itemstack)
{
	int l = MathHelper.floor_double((double)(player.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;

	world.setBlockMetadataWithNotify(x, y, z, l, 3);

}


public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int q, float a, float b, float c) {
	if(!player.isSneaking()) {
		player.openGui(Main.instance, PropsGeneral.guiIDdesignersworkbench, world, x, y, z);
		return true;
	}else{
		return false;
	}
} 
} 

 

I think that's it. Any help would be greatly appreciated

 

-Whyneb360

Link to comment
Share on other sites

Thanks, now I know for next time, but it seems like all of my issues are related to the inventory being messed up. It makes sense that the crafting would be off if all the the inventory slots are messed up. Going from the original crafting table to my own, the inventory switches around and goes all out of order and duplicated.

 

Sorry about my previous post, but whereabouts would this code be?

 

Thanks,

 

-Whyneb360

Link to comment
Share on other sites

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hi! If you have your forge installation file not in the system disc on PC (D, E etc.), drag it to disk C and try to start again. In my case it solved the problem.
    • KILAT77 : Waspada Situs Scam dengan Withdraw Yang Tidak Dibayar Di era digital saat ini, banyak orang yang mencari keberuntungan melalui situs perjudian online. Namun, dibalik gemerlap janji-janji manis kemenangan, ada bahaya yang mengintai. Salah satu situs yang patut diwaspadai adalah KILAT77. Situs ini mendapat reputasi buruk karena banyak laporan dari pengguna yang mengklaim bahwa mereka tidak bisa menarik dana kemenangan mereka. Dalam artikel ini, kita akan membahas mengapa ROTER88 dianggap sebagai situs scam dan bagaimana Anda bisa melindungi diri dari penipuan serupa. Pengalaman Pengguna: Penarikan Tidak Dibayar Beberapa pengguna telah melaporkan pengalaman buruk mereka dengan KILAT77. Mereka mengaku bahwa setelah memenangkan sejumlah uang dan mencoba menariknya, proses penarikan mereka ditolak tanpa alasan yang jelas. Bahkan, beberapa pengguna melaporkan bahwa akun mereka tiba-tiba diblokir setelah mencoba melakukan penarikan, sehingga mereka kehilangan akses ke dana mereka sama sekali.
    • It is a dupe mod issue Remove Rubidium - you are already using Embeddium which is a fork of Rubidium
    • I made a block entity in forge 1.20.1, I want to prevent hopper from taking input slot item, i tried to override the extractItem method, it prevented hopper from taking input slot item, but the player also unable to take/change the item in input slot unless the slot is empty. public class FluidSeparatorBlockEntity extends BlockEntity implements MenuProvider { private static final int INPUT_SLOT = 0; private final CustomItemHandler itemHandler = new CustomItemHandler(3){ @Override protected void onContentsChanged(int slot) { setChanged(); } @Override public boolean isItemValid(int slot, @NotNull ItemStack stack) { return slot == INPUT_SLOT; } @Override public @NotNull ItemStack extractItem(int slot, int amount, boolean simulate) { if (slot == INPUT_SLOT) { return ItemStack.EMPTY; } return super.extractItem(slot, amount, simulate); } }; private LazyOptional<IItemHandler> lazyItemHandler = LazyOptional.empty(); protected final ContainerData data; private int progress = 0; private int maxProgress = 78; public FluidSeparatorBlockEntity(BlockPos pPos, BlockState pBlockState) { super(ModBlockEntities.FLUID_SEPARATOR_BE.get(), pPos, pBlockState); this.data = new ContainerData() { @Override public int get(int pIndex) { return switch (pIndex) { case 0 -> FluidSeparatorBlockEntity.this.progress; case 1, 2 -> FluidSeparatorBlockEntity.this.maxProgress; default -> 0; }; } @Override public void set(int pIndex, int pValue) { switch (pIndex) { case 0 -> FluidSeparatorBlockEntity.this.progress = pValue; case 1, 2 -> FluidSeparatorBlockEntity.this.maxProgress = pValue; } } @Override public int getCount() { return 3; } }; } @Override public @NotNull <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable Direction side) { if(cap == ForgeCapabilities.ITEM_HANDLER) { return lazyItemHandler.cast(); } return super.getCapability(cap, side); } @Override public void onLoad() { super.onLoad(); lazyItemHandler = LazyOptional.of(() -> itemHandler); } @Override public void invalidateCaps() { super.invalidateCaps(); lazyItemHandler.invalidate(); } public void drops() { SimpleContainer inventory = new SimpleContainer(itemHandler.getSlots()); for(int i = 0; i < itemHandler.getSlots(); i++) { inventory.setItem(i, itemHandler.getStackInSlot(i)); } Containers.dropContents(this.level, this.worldPosition, inventory); } @Override public Component getDisplayName() { return Component.translatable("block.chemmaster.fluid_separator"); } @Nullable @Override public AbstractContainerMenu createMenu(int pContainerId, Inventory pPlayerInventory, Player pPlayer) { return new FluidSeparatorMenu(pContainerId, pPlayerInventory, this, this.data); } @Override protected void saveAdditional(CompoundTag pTag) { pTag.put("inventory", itemHandler.serializeNBT()); pTag.putInt("fluid_separator.progress", progress); super.saveAdditional(pTag); } @Override public void load(CompoundTag pTag) { super.load(pTag); itemHandler.deserializeNBT(pTag.getCompound("inventory")); progress = pTag.getInt("fluid_separator.progress"); } public void tick(Level pLevel, BlockPos pPos, BlockState pState) { ItemStack inputStack = this.itemHandler.getStackInSlot(INPUT_SLOT); if (inputStack.getCount() < 2) { resetProgress(); return; } if(hasRecipe()) { increaseCraftingProgress(); setChanged(pLevel, pPos, pState); if(hasProgressFinished()) { craftItem(); resetProgress(); } } else { resetProgress(); } } private void resetProgress() { progress = 0; } private void craftItem() { Optional<FluidSeparatingRecipe> recipe = getCurrentRecipe(); if (recipe.isPresent()) { List<ItemStack> results = recipe.get().getOutputs(); ItemStack inputStack = this.itemHandler.getStackInSlot(INPUT_SLOT); if (inputStack.getCount() < 2) { // If there are not enough items, do not proceed with crafting return; } // Extract the input item from the input slot this.itemHandler.internalExtractItem(INPUT_SLOT, 2, false); // Loop through each result item and find suitable output slots for (ItemStack result : results) { int outputSlot = findSuitableOutputSlot(result); if (outputSlot != -1) { this.itemHandler.setStackInSlot(outputSlot, new ItemStack(result.getItem(), this.itemHandler.getStackInSlot(outputSlot).getCount() + result.getCount())); } else { // Handle the case where no suitable output slot is found // This can be logging an error, throwing an exception, or any other handling logic System.err.println("No suitable output slot found for item: " + result); } } } } private int findSuitableOutputSlot(ItemStack result) { // Implement logic to find a suitable output slot for the given result // Return the slot index or -1 if no suitable slot is found for (int i = 0; i < this.itemHandler.getSlots(); i++) { // Ensure we do not place the output item in the input slot if (i == INPUT_SLOT) { continue; } ItemStack stackInSlot = this.itemHandler.getStackInSlot(i); if (stackInSlot.isEmpty() || (stackInSlot.getItem() == result.getItem() && stackInSlot.getCount() + result.getCount() <= stackInSlot.getMaxStackSize())) { return i; } } return -1; } private boolean hasRecipe() { Optional<FluidSeparatingRecipe> recipe = getCurrentRecipe(); if (recipe.isEmpty()) { return false; } List<ItemStack> results = recipe.get().getOutputs(); for (ItemStack result : results) { if (!canInsertAmountIntoOutputSlot(result) || !canInsertItemIntoOutputSlot(result.getItem())) { return false; } } return true; } private Optional<FluidSeparatingRecipe> getCurrentRecipe(){ SimpleContainer inventory = new SimpleContainer(this.itemHandler.getSlots()); for (int i = 0; i < itemHandler.getSlots(); i++) { inventory.setItem(i, this.itemHandler.getStackInSlot(i)); } return this.level.getRecipeManager().getRecipeFor(FluidSeparatingRecipe.Type.INSTANCE, inventory, level); } private boolean canInsertAmountIntoOutputSlot(ItemStack result) { for (int i = 1; i < this.itemHandler.getSlots(); i++) { ItemStack stackInSlot = this.itemHandler.getStackInSlot(i); if (stackInSlot.isEmpty() || (stackInSlot.getItem() == result.getItem() && stackInSlot.getCount() + result.getCount() <= stackInSlot.getMaxStackSize())) { return true; } } return false; } private boolean canInsertItemIntoOutputSlot(Item item) { for (int i = 1; i < this.itemHandler.getSlots(); i++) { ItemStack stackInSlot = this.itemHandler.getStackInSlot(i); if (stackInSlot.isEmpty() || stackInSlot.getItem() == item) { return true; } } return false; } private boolean hasProgressFinished() { return progress >= maxProgress; } private void increaseCraftingProgress() { progress++; } }  
  • Topics

×
×
  • Create New...

Important Information

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