Jump to content

How to Incorporate Experience when crafting an item via new crafting table


Petersfun

Recommended Posts

Hello,

 

I wanted to know if anyone knew how to make a custom Recipe require Experience to craft, I tried looking for the GUI's for Anvil and Experience Tables but i Couldn't seem to find them.

 

Container

 

package XPCrystals.common.Gui;

import XPCrystals.XPCrystals;
import net.minecraft.block.Block;
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 ContainerXPCraftingWorkBench 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;

public ContainerXPCraftingWorkBench(InventoryPlayer par1InventoryPlayer, World par2World, int par3, int par4, int par5)
{
         this.worldObj = par2World;
         this.posX = par3;
         this.posY = par4;
         this.posZ = par5;
         this.addSlotToContainer(new SlotXPCraftingWorkBench(par1InventoryPlayer.player, this.craftMatrix, this.craftResult, 0, 124, 35));
         int var6;
         int var7;

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

         for (var6 = 0; var6 < 3; ++var6)
         {
                 for (var7 = 0; var7 < 9; ++var7)
                 {
                         this.addSlotToContainer(new Slot(par1InventoryPlayer, var7 + var6 * 9 + 9, 8 + var7 * 18, 84 + var6 * 18));
                 }
         }

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

         this.onCraftMatrixChanged(this.craftMatrix);
}

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

public boolean canInteractWith(EntityPlayer par1EntityPlayer)
{
         return this.worldObj.getBlockId(this.posX, this.posY, this.posZ) != XPCrystals.XPCrystalWorkBench.blockID ? false : par1EntityPlayer.getDistanceSq((double)this.posX + 0.5D, (double)this.posY + 0.5D, (double)this.posZ + 0.5D) <= 64.0D;
}

public void onCraftGuiClosed(EntityPlayer par1EntityPlayer)
{
         super.onCraftGuiClosed(par1EntityPlayer);

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

                         if (var3 != null)
                         {
                                 par1EntityPlayer.dropPlayerItem(var3);
                         }
                 }
         }
}

public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2)
{
         ItemStack var3 = null;
         Slot var4 = (Slot)this.inventorySlots.get(par2);

         if (var4 != null && var4.getHasStack())
         {
                 ItemStack var5 = var4.getStack();
                 var3 = var5.copy();

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

                         var4.onSlotChange(var5, var3);
                 }
                 else if (par2 >= 10 && par2 < 37)
                 {
                         if (!this.mergeItemStack(var5, 37, 46, false))
                         {
                                 return null;
                         }
                 }
                 else if (par2 >= 37 && par2 < 46)
                 {
                         if (!this.mergeItemStack(var5, 10, 37, false))
                         {
                                 return null;
                         }
                 }
                 else if (!this.mergeItemStack(var5, 10, 46, false))
                 {
                         return null;
                 }

                 if (var5.stackSize == 0)
                 {
                         var4.putStack((ItemStack)null);
                 }
                 else
                 {
                         var4.onSlotChanged();
                 }

                 if (var5.stackSize == var3.stackSize)
                 {
                         return null;
                 }

                 var4.onPickupFromSlot(par1EntityPlayer, var5);
         }

         return var3;
}
}

 

 

the Recipe for a item in the custom WorkBench

XPCraftingWorkBenchCraftingManager.getInstance().func_92051_a(new ItemStack(XPCrystals.XPCrystal, 1), new Object[] {"xxx", Character.valueOf('x'), Block.dirt});

 

Creating the Recipe for the custom WorkBench with XP  (Want it to look like this or something like this)

XPCraftingWorkBenchCraftingManager.getInstance().func_92051_a(new ItemStack(XPCrystals.XPCrystal, 1), new Object[] {"xxx", Character.valueOf('x'), Block.dirt}, 30 //<---XP Amount);

 

Kinda Need a way for it to Show Green Text or Numbers like

you have enough Example

 

Level:30

 

you dont have enough example

 

Level:30

 

The WorkBench Gui's Code

 

 

package XPCrystals.common.Gui;

import org.lwjgl.opengl.GL11;

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

public class XPCrystalWorkBenchGUI extends GuiContainer
{
public XPCrystalWorkBenchGUI(InventoryPlayer par1InventoryPlayer, World par2World, int par3, int par4, int par5)
{
         super(new ContainerXPCraftingWorkBench(par1InventoryPlayer, par2World, par3, par4, par5));
}

/**
         * Draw the foreground layer for the GuiContainer (everything in front of the items)
         */
protected void drawGuiContainerForegroundLayer(int par1, int par2)
{
         this.fontRenderer.drawString(StatCollector.translateToLocal("Crystal WorkBench"), 28, 6, 4210752);
         this.fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 8, this.ySize - 96 + 2, 4210752);
}

/**
         * Draw the background layer for the GuiContainer (everything behind the items)
         */
protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3)
{
         int var4 = this.mc.renderEngine.getTexture("/XPCrystals/Images/Guis/XPCraftingTableGui.png");
         GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
         this.mc.renderEngine.bindTexture(var4);
         int var5 = (this.width - this.xSize) / 2;
         int var6 = (this.height - this.ySize) / 2;
         this.drawTexturedModalRect(var5, var6, 0, 0, this.xSize, this.ySize);
}
}

 

 

How would i incorporate The amount of XP Levels to Craft this

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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I recently updated my mods and now my game is crashing on startup i tried adding them one at a time and couldn't find anything wrong and no crash log is being made the only thing I have is the debug log. If it helps I'm also using the curseforge launcher to launch the game. Minecraft version- 1.20.1 Forge Version-47.2.0 https://gist.github.com/keepinitreal247/d3105af6bb70e30f183505715113c61a
    • i managed to use another launcher but it still says logging in
    • i tried to open the modpack with multimc by importing it from Ftb and it gave me an error https://paste.ee/p/YDqWN
    • Hi, I'm trying to render a single quad in the world. I'm mixing into the ChestRenderer class. If I understand correctly, BufferSource#getBuffer opens a buffer according to the supplied RenderType (Quads with POSITION_COLOR in my case). Then, I can supply my vertices (a simple 1-block plane along the Z Axis) and close the buffer using BufferSource#endBatch for rendering. This is the code I'm using: @Inject(at = @At("TAIL"), method = "render(...)V") public void render(T blockEntity, float partialTick, PoseStack poseStack, MultiBufferSource multiBufferSource, int packedLight, int packedOverlay, CallbackInfo ci) { BlockPos pos = blockEntity.getBlockPos(); AABB box = new AABB(pos, pos.offset(1, 1, 1)); BufferSource buffer = Minecraft.getInstance().renderBuffers().bufferSource(); VertexConsumer consumer = buffer.getBuffer(RenderType.guiOverlay()); poseStack.pushPose(); poseStack.translate(-pos.getX(), -pos.getY(), -pos.getZ()); consumer.vertex(box.minX, box.maxY, box.minZ).color(1, 1, 1, 1).endVertex(); consumer.vertex(box.minX, box.maxY, box.maxZ).color(1, 1, 1, 1).endVertex(); consumer.vertex(box.minX, box.minY, box.maxZ).color(1, 1, 1, 1).endVertex(); consumer.vertex(box.minX, box.minY, box.minZ).color(1, 1, 1, 1).endVertex(); buffer.endBatch(RenderType.guiOverlay()); poseStack.popPose(); } However, the plane does not get rendered. However, if I replace those 4 vertices with a call to LevelRenderer#renderLineBox and set the RenderType to LINES, it works. Do I need something else to render planes other than the 4 edges of the quad? I used QUADS back in 1.8 where it was still the raw OpenGL type and it worked then. Or am I missing something else entirely? Thanks!
  • Topics

×
×
  • Create New...

Important Information

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