Jump to content

Recommended Posts

Posted

So learning from my previous post, I won't be posting a metric ton of code, but I still need help. I managed to solve the problem of inventory moving, but I don't think I've activated my crafting manager properly. Crafting works fine in the custom crafting table, but it's just the normal recipes (which shouldn't work) and none of the ones in my custom crafting manager work either.

 

Here is where I referenced it:

public void onCraftMatrixChanged(IInventory inventory)
    {
        this.craftResult.setInventorySlotContents(0, WorkBenchCraftingManager.getInstance().findMatchingRecipe(this.craftMatrix, this.worldObj));
    }

 

In my container class.

 

and this is my crafting manager (Copy pasta warning)

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[] {"S", "S", "S", 'S', Items.stick});
        
        
        Collections.sort(this.recipes, new WorkBenchRecipeSorter(this));
    }

    public WorkBenchShapedRecipes addRecipe(ItemStack par1ItemStack, Object ... par2ArrayOfObj)
    {
        String s = "";
        int i = 0;
        int j = 0;
        int k = 0;
        	
        if (par2ArrayOfObj[i] instanceof String[])
        {	
            String[] astring = (String[])((String[])par2ArrayOfObj[i++]);
            
            for (int l = 0; l < astring.length; ++l)
            {
                String s1 = astring[l];
                ++k;
                j = s1.length();
                s = s + s1;
            }
            
        }else{
        	
            while (par2ArrayOfObj[i] instanceof String)
            {
                String s2 = (String)par2ArrayOfObj[i++];
                ++k;
                j = s2.length();
                s = s + s2;
            }
        }
        	
        HashMap hashmap;

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

            if (par2ArrayOfObj[i + 1] instanceof Item)
            {
                itemstack1 = new ItemStack((Item)par2ArrayOfObj[i + 1]);
            }
            else if (par2ArrayOfObj[i + 1] instanceof Block)
            {
                itemstack1 = new ItemStack((Block)par2ArrayOfObj[i + 1], 1, 32767);
            }
            else if (par2ArrayOfObj[i + 1] instanceof ItemStack)
            {
                itemstack1 = (ItemStack)par2ArrayOfObj[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, par1ItemStack);
        this.recipes.add(shapedrecipes);
        return shapedrecipes;
    }

    public void addShapelessRecipe(ItemStack par1ItemStack, Object ... par2ArrayOfObj)
    {
        ArrayList arraylist = new ArrayList();
        Object[] aobject = par2ArrayOfObj;
        int i = par2ArrayOfObj.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(par1ItemStack, arraylist));
    }

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

        for (j = 0; j < par1InventoryCrafting.getSizeInventory(); ++j)
        {
            ItemStack itemstack2 = par1InventoryCrafting.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(par1InventoryCrafting, par2World))
                {
                    return irecipe.getCraftingResult(par1InventoryCrafting);
                }
            }

            return null;
        }
    }

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

 

Which is almost straight from the vanilla code

 

Thanks in advance,

 

-Whyneb360

Posted

BTW you should get rid of the __OBFID , it's used during (de)obfuscation for vanilla only.

 

I suggest you add a breakpoint to your onCraftMatrixChanged and step into your WorkBenchCraftingManager.findMatchingRecipe().  That should show you straight away where the problem is.

 

-TGG

Posted

What do you mean by "none of the ones in my custom crafting manager work either" ?

Are your custom recipes not registering?

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Posted

Exactly. In my custom crafting manager, all the normal crafting recipes shouldn't work, and the ones I've put in should. In reality, it's the other way around - all the normal ones work (vanilla recipes that is), but the ones I've put in don't.

 

Posted

I added the breakpoint, but the game never gets to it. Do I need to initialize something in my main class?

Are you really doing it for your custom crafting table?

then please post your full code of the tileentity (or block) and the class which onCraftMatrixChanged method is placed.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Posted

Sure thing:

 

ContainerWorkbench class (Where the onCraftMatricChanged method is)

public class ContainerWorkbench extends Container {

public InventoryCrafting craftMatrix = new InventoryCrafting(this, 3, 3);
    public IInventory craftResult = new InventoryCraftResult();
    private World worldObj;
    private int posX;
    private int posY;
    private int posZ;
    private static final String __OBFID = "CL_00001744";

    public ContainerWorkbench(InventoryPlayer invplayer, TileEntityWorkbench entity, World world, int x, int y, int z)
    {
        this.worldObj = world;
        this.posX = x;
        this.posY = y;
        this.posZ = z;
        this.addSlotToContainer(new SlotCrafting(invplayer.player, this.craftMatrix, this.craftResult, 0, 124, 35));
        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(invplayer, i1 + l * 9 + 9, 8 + i1 * 18, 84 + l * 18));
            }
        }

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

        this.onCraftMatrixChanged(this.craftMatrix);
    }

    public void onCraftMatrixChanged(IInventory inventory)
    {
        this.craftResult.setInventorySlotContents(0, WorkBenchCraftingManager.getInstance().findMatchingRecipe(this.craftMatrix, this.worldObj));
    }
    
    public boolean canInteractWith(EntityPlayer player)
    {
        return this.worldObj.getBlock(this.posX, this.posY, this.posZ) != PropsGeneral.designersworkbench ? false : player.getDistanceSq((double)this.posX + 0.5D, (double)this.posY + 0.5D, (double)this.posZ + 0.5D) <= 64.0D;
    }

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

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

			if (itemstack != null)
			{
				player.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;
}

}

 

WorkBenchShapedRecipes and its shapless counterpart is directly from the vanilla code

 

Workbench class

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;
	}
} 
} 

 

Posted

The fact that onCraftMatrixChanged method is never called implies that the ContainerWorkbench is not being used.

It is strange.. anyway please show your Gui Handler class.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Posted

Here you go:

 

GUIHandler

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

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"), 20, 10, 0xFFFFFF);
}

@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);
}

}

Posted

That seems strange.

 

Does the GUI really open?

 

and retry putting breakpoint in the method "onCraftMatrixChanged".

 

It would be called at least once.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Posted

I have made a breakthrough. When I tested the crafting originally, I just put the recipe into the custom crafting table and since no icon appeared in the output slot, I assumed it didn't work. Just now I tried clicking that empty slot, and the materials disappeared and I got the item(successful crafting procedure). Then I tried a vanilla crafting recipe (wooden button for example) and even though that output icon (of the wooden button) does appear in the output slot, I can't craft it/take it out of the output slot.

 

So my new problem is making the icon for my custom recipes appear, and the icon for the old recipes disappear.

 

Tell me if I need to clarify anything

Posted

I have made a breakthrough. When I tested the crafting originally, I just put the recipe into the custom crafting table and since no icon appeared in the output slot, I assumed it didn't work. Just now I tried clicking that empty slot, and the materials disappeared and I got the item(successful crafting procedure). Then I tried a vanilla crafting recipe (wooden button for example) and even though that output icon (of the wooden button) does appear in the output slot, I can't craft it/take it out of the output slot.

 

So my new problem is making the icon for my custom recipes appear, and the icon for the old recipes disappear.

 

Tell me if I need to clarify anything

 

That really make sense.

 

Then it is working normally on Server side, but not working on Client side.

 

So.. make sure that GuiWorkbench class does not import ContainerWorkbench of vanilla minecraft.

 

 

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Posted

I have made a breakthrough. When I tested the crafting originally, I just put the recipe into the custom crafting table and since no icon appeared in the output slot, I assumed it didn't work. Just now I tried clicking that empty slot, and the materials disappeared and I got the item(successful crafting procedure). Then I tried a vanilla crafting recipe (wooden button for example) and even though that output icon (of the wooden button) does appear in the output slot, I can't craft it/take it out of the output slot.

 

So my new problem is making the icon for my custom recipes appear, and the icon for the old recipes disappear.

 

Tell me if I need to clarify anything

 

Make ABSOLUTELY sure that the client knows the crafting recipe is valid. Otherwise you're just turning a blind eye to it.

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.

Announcements



×
×
  • Create New...

Important Information

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