Jump to content

Problems with custom Crafting Table


Bedrock_Miner

Recommended Posts

Hi!

 

I created a new crafting Table with new recipes which take Mana from the Player.

Everything works fine except from one fact:

If I perform a shift-klick to craft as much Items as possible, neither the Crafting result is placed in the Inventory of the player, nor the Mana is reduced by the specified amount. Only the Crafting-items are removed. Can anybody tell me, why?

 

The Slot for the Crafting result:

 

package magicum.minecraft.items.crafting;

import magicum.minecraft.blocks.container.ContainerMagicCrafting;
import magicum.minecraft.extendedproperties.ExtendedProperties;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.AchievementList;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
import cpw.mods.fml.common.registry.GameRegistry;

public class ModSlotCrafting extends Slot
{
    /** The craft matrix inventory linked to this result slot. */
    private final IInventory craftMatrix;

    /** The player that is using the GUI where this slot resides. */
    private EntityPlayer thePlayer;
    
    public boolean canTake;
    
    private Container owner;

    /**
     * The number of items that have been crafted so far. Gets passed to ItemStack.onCrafting before being reset.
     */
    private int amountCrafted;

    public ModSlotCrafting(Container owner, EntityPlayer par1EntityPlayer, IInventory par2IInventory, IInventory par3IInventory, int par4, int par5, int par6)
    {
        super(par3IInventory, par4, par5, par6);
        this.thePlayer = par1EntityPlayer;
        this.craftMatrix = par2IInventory;
        this.owner = owner;
    }

    /**
     * Check if the stack is a valid item for this slot. Always true beside for the armor slots.
     */
    @Override
public boolean isItemValid(ItemStack par1ItemStack)
    {
        return false;
    }

    /**
     * Decrease the size of the stack in slot (first int arg) by the amount of the second int arg. Returns the new
     * stack.
     */
    @Override
public ItemStack decrStackSize(int par1)
    {
        if (this.getHasStack())
        {
            this.amountCrafted += Math.min(par1, this.getStack().stackSize);
        }

        return super.decrStackSize(par1);
    }

    /**
     * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. Typically increases an
     * internal count then calls onCrafting(item).
     */
    @Override
protected void onCrafting(ItemStack par1ItemStack, int par2)
    {
        this.amountCrafted += par2;
        this.onCrafting(par1ItemStack);
    }

    /**
     * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood.
     */
    @Override
protected void onCrafting(ItemStack par1ItemStack)
    {
        par1ItemStack.onCrafting(this.thePlayer.worldObj, this.thePlayer, this.amountCrafted);
        this.amountCrafted = 0;

        if (par1ItemStack.itemID == Block.workbench.blockID)
        {
            this.thePlayer.addStat(AchievementList.buildWorkBench, 1);
        }
        else if (par1ItemStack.itemID == Item.pickaxeWood.itemID)
        {
            this.thePlayer.addStat(AchievementList.buildPickaxe, 1);
        }
        else if (par1ItemStack.itemID == Block.furnaceIdle.blockID)
        {
            this.thePlayer.addStat(AchievementList.buildFurnace, 1);
        }
        else if (par1ItemStack.itemID == Item.hoeWood.itemID)
        {
            this.thePlayer.addStat(AchievementList.buildHoe, 1);
        }
        else if (par1ItemStack.itemID == Item.bread.itemID)
        {
            this.thePlayer.addStat(AchievementList.makeBread, 1);
        }
        else if (par1ItemStack.itemID == Item.cake.itemID)
        {
            this.thePlayer.addStat(AchievementList.bakeCake, 1);
        }
        else if (par1ItemStack.itemID == Item.pickaxeStone.itemID)
        {
            this.thePlayer.addStat(AchievementList.buildBetterPickaxe, 1);
        }
        else if (par1ItemStack.itemID == Item.swordWood.itemID)
        {
            this.thePlayer.addStat(AchievementList.buildSword, 1);
        }
        else if (par1ItemStack.itemID == Block.enchantmentTable.blockID)
        {
            this.thePlayer.addStat(AchievementList.enchantments, 1);
        }
        else if (par1ItemStack.itemID == Block.bookShelf.blockID)
        {
            this.thePlayer.addStat(AchievementList.bookcase, 1);
        }
    }

    @Override
public void onPickupFromSlot(EntityPlayer par1EntityPlayer, ItemStack par2ItemStack)
    {
        GameRegistry.onItemCrafted(par1EntityPlayer, par2ItemStack, this.craftMatrix);
        this.onCrafting(par2ItemStack);
        
        if (par1EntityPlayer instanceof EntityPlayerMP)
        {
        	ExtendedProperties.get((EntityPlayerMP) par1EntityPlayer).rem("Mana", ((ContainerMagicCrafting)this.owner).manaNeeded);
        } 

        for (int i = 0; i < this.craftMatrix.getSizeInventory(); ++i)
        {
            ItemStack itemstack1 = this.craftMatrix.getStackInSlot(i);

            if (itemstack1 != null)
            {
                this.craftMatrix.decrStackSize(i, 1);

                if (itemstack1.getItem().hasContainerItem())
                {
                    ItemStack itemstack2 = itemstack1.getItem().getContainerItemStack(itemstack1);

                    if (itemstack2.isItemStackDamageable() && itemstack2.getItemDamage() > itemstack2.getMaxDamage())
                    {
                        MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(this.thePlayer, itemstack2));
                        itemstack2 = null;
                    }

                    if (itemstack2 != null && (!itemstack1.getItem().doesContainerItemLeaveCraftingGrid(itemstack1) || !this.thePlayer.inventory.addItemStackToInventory(itemstack2)))
                    {
                        if (this.craftMatrix.getStackInSlot(i) == null)
                        {
                            this.craftMatrix.setInventorySlotContents(i, itemstack2);
                        }
                        else
                        {
                            this.thePlayer.dropPlayerItem(itemstack2);
                        }
                    }
                }
            }
        }
        
        this.owner.onCraftMatrixChanged(((ContainerMagicCrafting)this.owner).tileEntity);
    }

@Override
public boolean canTakeStack(EntityPlayer par1EntityPlayer) {
	return this.canTake;
}
}

 

The Container:

 

package magicum.minecraft.blocks.container;

import java.util.ArrayList;
import java.util.List;

import magicum.Main;
import magicum.minecraft.blocks.tileentity.TileEntityMagicCrafting;
import magicum.minecraft.elements.ElementCounted;
import magicum.minecraft.items.crafting.ModCraftingManager;
import magicum.minecraft.items.crafting.ModSlotCraftMatrix;
import magicum.minecraft.items.crafting.ModSlotCrafting;
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.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

public class ContainerMagicCrafting extends Container {

public TileEntityMagicCrafting tileEntity;
public IInventory craftResult = new InventoryCraftResult();
private World worldObj;

public int manaNeeded;
public List<ElementCounted> Elements = new ArrayList<ElementCounted>();
private ModSlotCrafting crafting;

    public ContainerMagicCrafting (InventoryPlayer inventoryPlayer, TileEntityMagicCrafting te){
    	this.tileEntity = te;
    	this.worldObj = inventoryPlayer.player.worldObj;
    	
    	for (int i = 0; i < 3; i++) {
    		for (int j = 0; j < 3; j++) {
    			this.addSlotToContainer(new ModSlotCraftMatrix(this, this.tileEntity, j + i * 3, 44 + j * 18, 17 + i * 18));
    		}
    	}
    	
    	for (int i = 0; i < 3; i++)
    		this.addSlotToContainer(new Slot(this.tileEntity, 9 + i, 8, 17 + i * 18));
    	
    	this.crafting = new ModSlotCrafting(this, inventoryPlayer.player, this.tileEntity, this.craftResult, 0, 138, 35);
    	this.addSlotToContainer(this.crafting);

    	this.addPlayerInventory(inventoryPlayer);
    	
    	this.onCraftMatrixChanged(this.tileEntity);
    }

    @Override
    public boolean canInteractWith(EntityPlayer player) {
    	return this.tileEntity.isUseableByPlayer(player);
    }


    protected void addPlayerInventory(InventoryPlayer inventoryPlayer) {
    	for (int i = 0; i < 3; i++) {
    		for (int j = 0; j < 9; j++) {
    			this.addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9,  8 + j * 18, 95 + i * 18));
    		}
    	}

    	for (int i = 0; i < 9; i++) {
    		this.addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 153));
    	}
    }

    @Override
    public ItemStack transferStackInSlot(EntityPlayer player, int slot) {
    	ItemStack stack = null;
    	Slot slotObject = (Slot) this.inventorySlots.get(slot);

    	if (slotObject != null && slotObject.getHasStack()) {
    		ItemStack stackInSlot = slotObject.getStack();
    		stack = stackInSlot.copy();
    		
    		if (slot < 9) {
    			if (!this.mergeItemStack(stackInSlot, 0, 35, true)) {
    				return null;
    			}
    		}
    		
    		else if (!this.mergeItemStack(stackInSlot, 0, 9, false)) {
    			return null;
    		}
    		
    		if (stackInSlot.stackSize == 0) {
    			slotObject.putStack(null);
    		} else {
    			slotObject.onSlotChanged();
    		}
    		
    		if (stackInSlot.stackSize == stack.stackSize) {
    			return null;
    		}
    		slotObject.onPickupFromSlot(player, stackInSlot);
    	}
    	return stack;
    }
    
    /**
     * Callback for when the crafting matrix is changed.
     */
    @Override
public void onCraftMatrixChanged(IInventory par1IInventory)
    {    	
        this.manaNeeded = ModCraftingManager.getInstance().getManaRequired(this.tileEntity, this.worldObj);
        this.Elements = ModCraftingManager.getInstance().getElementsRequired(this.tileEntity, this.worldObj);
        
        this.crafting.canTake = Main.proxy.playerMana >= this.manaNeeded && this.elementsCorrect();
        this.craftResult.setInventorySlotContents(0, ModCraftingManager.getInstance().findMatchingRecipe(this.tileEntity, this.worldObj));
    }

private boolean elementsCorrect() {
	return true;
}
}

 

Write if you need more code!

Link to comment
Share on other sites

I did some experiments and found out, that the crafted Items are placed in the craftMatrix, not in the Player's inventory.

There the stacksize is reduced and the Item vanishes.

 

How can I get the Items into the correct Inventory?

I really don't know, which classes to change.

Link to comment
Share on other sites

OK, I solved it now, but I really don't understand y´why:

I just put addPlayerInventory(inventoryPlayer); to the Top. Now it works..

Such a little problem  :-\

 

But now, I got another Problem:

 

If I do a shift klick, I craft as much Items as possible from the Item Count. But if I got maybe the Mana for 2 Items and the Items for 4, it will craft 4. How can I add a Control for the Mana when performing a Shiftklick?

 

Link to comment
Share on other sites

Its just me who's posting..

I now solved the problem. Final Code:

ContainerMagicCrafting:

package magicum.minecraft.blocks.container;

import java.util.ArrayList;
import java.util.List;

import magicum.Main;
import magicum.minecraft.blocks.tileentity.TileEntityMagicCrafting;
import magicum.minecraft.elements.ElementCounted;
import magicum.minecraft.items.crafting.ModCraftingManager;
import magicum.minecraft.items.crafting.ModSlotCraftMatrix;
import magicum.minecraft.items.crafting.ModSlotCrafting;
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.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

public class ContainerMagicCrafting extends Container {

public TileEntityMagicCrafting tileEntity;
public IInventory craftResult = new InventoryCraftResult();
private World worldObj;

public int manaNeeded;
public List<ElementCounted> Elements = new ArrayList<ElementCounted>();
private ModSlotCrafting crafting;

    public ContainerMagicCrafting (InventoryPlayer inventoryPlayer, TileEntityMagicCrafting te){
    	this.tileEntity = te;
    	this.worldObj = inventoryPlayer.player.worldObj;
    	
    	this.addPlayerInventory(inventoryPlayer);
    	
    	for (int i = 0; i < 3; i++) {
    		for (int j = 0; j < 3; j++) {
    			this.addSlotToContainer(new ModSlotCraftMatrix(this, this.tileEntity, j + i * 3, 44 + j * 18, 17 + i * 18));
    		}
    	}
    	
    	for (int i = 0; i < 3; i++)
    		this.addSlotToContainer(new Slot(this.tileEntity, 9 + i, 8, 17 + i * 18));
    	
    	this.crafting = new ModSlotCrafting(this, inventoryPlayer.player, this.tileEntity, this.craftResult, 0, 138, 35);
    	this.addSlotToContainer(this.crafting);
    	
    	this.onCraftMatrixChanged(this.tileEntity);
    }

    @Override
    public boolean canInteractWith(EntityPlayer player) {
    	return this.tileEntity.isUseableByPlayer(player);
    }


    protected void addPlayerInventory(InventoryPlayer inventoryPlayer) {
    	for (int i = 0; i < 3; i++) {
    		for (int j = 0; j < 9; j++) {
    			this.addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9,  8 + j * 18, 95 + i * 18));
    		}
    	}

    	for (int i = 0; i < 9; i++) {
    		this.addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 153));
    	}
    }

    @Override
    public ItemStack transferStackInSlot(EntityPlayer player, int slot) {
    	ItemStack stack = null;
    	Slot slotObject = (Slot) this.inventorySlots.get(slot);

    	if (slotObject != null && slotObject.getHasStack()) {
    		ItemStack stackInSlot = slotObject.getStack();
    		stack = stackInSlot.copy();
    		
    		if (slot < 9) {
    			if (!this.mergeItemStack(stackInSlot, 0, 35, true)) {
    				return null;
    			}
    		}
    		
    		else if (!this.mergeItemStack(stackInSlot, 0, 9, false)) {
    			return null;
    		}
    		
    		if (stackInSlot.stackSize == 0) {
    			slotObject.putStack(null);
    		} else {
    			slotObject.onSlotChanged();
    		}
    		
    		if (stackInSlot.stackSize == stack.stackSize) {
    			return null;
    		}
    		slotObject.onPickupFromSlot(player, stackInSlot);
    	}
    	return stack;
    }
    
    /**
     * Callback for when the crafting matrix is changed.
     */
    @Override
public void onCraftMatrixChanged(IInventory par1IInventory)
    {    	
        this.manaNeeded = ModCraftingManager.getInstance().getManaRequired(this.tileEntity, this.worldObj);
        this.Elements = ModCraftingManager.getInstance().getElementsRequired(this.tileEntity, this.worldObj);
        
        if (Main.proxy.playerMana >= this.manaNeeded && this.elementsCorrect())
        	this.craftResult.setInventorySlotContents(0, ModCraftingManager.getInstance().findMatchingRecipe(this.tileEntity, this.worldObj));
    }

private boolean elementsCorrect() {
	return true;
}
}

ModSlotCrafting:

package magicum.minecraft.items.crafting;

import magicum.Main;
import magicum.minecraft.blocks.container.ContainerMagicCrafting;
import magicum.minecraft.extendedproperties.ExtendedProperties;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.AchievementList;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
import cpw.mods.fml.common.registry.GameRegistry;

public class ModSlotCrafting extends Slot
{
    /** The craft matrix inventory linked to this result slot. */
    private final IInventory craftMatrix;

    /** The player that is using the GUI where this slot resides. */
    private EntityPlayer thePlayer;
    
    private ContainerMagicCrafting owner;

    /**
     * The number of items that have been crafted so far. Gets passed to ItemStack.onCrafting before being reset.
     */
    private int amountCrafted;

    public ModSlotCrafting(ContainerMagicCrafting owner, EntityPlayer par1EntityPlayer, IInventory par2IInventory, IInventory par3IInventory, int par4, int par5, int par6)
    {
        super(par3IInventory, par4, par5, par6);
        this.thePlayer = par1EntityPlayer;
        this.craftMatrix = par2IInventory;
        this.owner = owner;
    }

    /**
     * Check if the stack is a valid item for this slot. Always true beside for the armor slots.
     */
    @Override
public boolean isItemValid(ItemStack par1ItemStack)
    {
        return false;
    }

    /**
     * Decrease the size of the stack in slot (first int arg) by the amount of the second int arg. Returns the new
     * stack.
     */
    @Override
public ItemStack decrStackSize(int par1)
    {
        if (this.getHasStack())
        {
            this.amountCrafted += Math.min(par1, this.getStack().stackSize);
        }

        return super.decrStackSize(par1);
    }

    /**
     * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. Typically increases an
     * internal count then calls onCrafting(item).
     */
    @Override
protected void onCrafting(ItemStack par1ItemStack, int par2)
    {
        this.amountCrafted += par2;
        this.onPickupFromSlot(this.thePlayer, par1ItemStack);
    }

    /**
     * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood.
     */
    @Override
protected void onCrafting(ItemStack par1ItemStack)
    {   
    		if (this.thePlayer instanceof EntityPlayerMP)
    			ExtendedProperties.get((EntityPlayerMP) this.thePlayer).rem("Mana", this.owner.manaNeeded);
    		Main.proxy.playerMana -= this.owner.manaNeeded;
    	
    		par1ItemStack.onCrafting(this.thePlayer.worldObj, this.thePlayer, this.amountCrafted);
    		this.amountCrafted = 0;

    		if (par1ItemStack.itemID == Block.workbench.blockID)
    		{
    			this.thePlayer.addStat(AchievementList.buildWorkBench, 1);
    		}
    		else if (par1ItemStack.itemID == Item.pickaxeWood.itemID)
    		{
    			this.thePlayer.addStat(AchievementList.buildPickaxe, 1);
    		}
    		else if (par1ItemStack.itemID == Block.furnaceIdle.blockID)
    		{
    			this.thePlayer.addStat(AchievementList.buildFurnace, 1);
    		}
    		else if (par1ItemStack.itemID == Item.hoeWood.itemID)
    		{
    			this.thePlayer.addStat(AchievementList.buildHoe, 1);
    		}
    		else if (par1ItemStack.itemID == Item.bread.itemID)
    		{
    			this.thePlayer.addStat(AchievementList.makeBread, 1);
    		}
    		else if (par1ItemStack.itemID == Item.cake.itemID)
    		{
    			this.thePlayer.addStat(AchievementList.bakeCake, 1);
    		}
    		else if (par1ItemStack.itemID == Item.pickaxeStone.itemID)
    		{
    			this.thePlayer.addStat(AchievementList.buildBetterPickaxe, 1);
    		}
    		else if (par1ItemStack.itemID == Item.swordWood.itemID)
    		{
    			this.thePlayer.addStat(AchievementList.buildSword, 1);
    		}
    		else if (par1ItemStack.itemID == Block.enchantmentTable.blockID)
    		{
    			this.thePlayer.addStat(AchievementList.enchantments, 1);
    		}
    		else if (par1ItemStack.itemID == Block.bookShelf.blockID)
    		{
    			this.thePlayer.addStat(AchievementList.bookcase, 1);
    		}
    }
    	
    @Override
public void onPickupFromSlot(EntityPlayer par1EntityPlayer, ItemStack par2ItemStack)
    {
        GameRegistry.onItemCrafted(par1EntityPlayer, par2ItemStack, this.thePlayer.inventory);
        this.onCrafting(par2ItemStack);

        for (int i = 0; i < this.craftMatrix.getSizeInventory(); ++i)
        {
            ItemStack itemstack1 = this.craftMatrix.getStackInSlot(i);

            if (itemstack1 != null)
            {
                this.craftMatrix.decrStackSize(i, 1);

                if (itemstack1.getItem().hasContainerItem())
                {
                    ItemStack itemstack2 = itemstack1.getItem().getContainerItemStack(itemstack1);

                    if (itemstack2.isItemStackDamageable() && itemstack2.getItemDamage() > itemstack2.getMaxDamage())
                    {
                        MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(this.thePlayer, itemstack2));
                        itemstack2 = null;
                    }

                    if (itemstack2 != null && (!itemstack1.getItem().doesContainerItemLeaveCraftingGrid(itemstack1) || !this.thePlayer.inventory.addItemStackToInventory(itemstack2)))
                    {
                        if (this.craftMatrix.getStackInSlot(i) == null)
                        {
                            this.craftMatrix.setInventorySlotContents(i, itemstack2);
                        }
                        else
                        {
                            this.thePlayer.dropPlayerItem(itemstack2);
                        }
                    }
                }
            }
        }
        this.inventory.setInventorySlotContents(0, null);
        this.owner.onCraftMatrixChanged(this.owner.tileEntity);
    }
}

 

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

    • It is the field that accesses the portal entrance position relative to the entity. So very much needed to make a portal work. What I don't understand is why the access widener works when running the client in Intellij but doesn't after I publish the jar and try to play with game with it.
    • So I'm using a mod that adds a "god sword" into the game. This sword is unfortunately not enchantable so I'm looking to change it. The only code that seems related is in the weapon's .class file which is here:  public int getItemEnchantability() { return this.tier.m_6601_(); }   The entire file is below: package blackwolf00.elementalswords.common; import blackwolf00.elementalswords.config.ConfigEffects; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.Multimap; import com.mojang.blaze3d.platform.InputConstants; import java.util.List; import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; import net.minecraft.core.BlockPos; import net.minecraft.network.chat.Component; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.effect.MobEffects; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.ai.attributes.Attribute; import net.minecraft.world.entity.ai.attributes.AttributeModifier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Tier; import net.minecraft.world.item.TieredItem; import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.item.Vanishable; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.common.ToolAction; import net.minecraftforge.common.ToolActions; public class FusionSword extends TieredItem implements Vanishable { private final float totalDamage; private final Tier tier; private final Multimap<Attribute, AttributeModifier> defaultModifiers; public FusionSword(Tier tierIn, int damage, float speed, Item.Properties builderIn) { super(tierIn, builderIn); this.tier = tierIn; this.totalDamage = damage + this.tier.m_6631_(); ImmutableMultimap.Builder<Attribute, AttributeModifier> builder = ImmutableMultimap.builder(); builder.put(Attributes.f_22281_, new AttributeModifier(f_41374_, "Weapon modifier", this.totalDamage, AttributeModifier.Operation.ADDITION)); builder.put(Attributes.f_22283_, new AttributeModifier(f_41375_, "Weapon modifier", speed, AttributeModifier.Operation.ADDITION)); this.defaultModifiers = (Multimap<Attribute, AttributeModifier>)builder.build(); } public int getItemEnchantability() { return this.tier.m_6601_(); } public boolean getIsRepairable(ItemStack toRepair, ItemStack repair) { return (this.tier.m_6282_().test(repair) || isRepairable(toRepair)); } public float getAttackDamage() { return this.totalDamage; } public boolean m_6777_(BlockState state, Level level, BlockPos pos, Player player) { return !player.m_7500_(); } public float m_8102_(ItemStack stack, BlockState state) { return 1.0F; } public boolean m_7579_(ItemStack stack, LivingEntity target, LivingEntity attacker) { stack.m_41622_(1, attacker, entity -> entity.m_21166_(EquipmentSlot.MAINHAND)); return true; } public boolean m_6813_(ItemStack stack, Level level, BlockState state, BlockPos pos, LivingEntity entityLiving) { if (state.m_60800_((BlockGetter)level, pos) != 0.0F) stack.m_41622_(2, entityLiving, entity -> entity.m_21166_(EquipmentSlot.MAINHAND)); return true; } public boolean m_8096_(BlockState blockIn) { return blockIn.m_60713_(Blocks.f_50033_); } public boolean m_5812_(ItemStack item) { return true; } public Multimap<Attribute, AttributeModifier> m_7167_(EquipmentSlot equipmentSlot) { return (equipmentSlot == EquipmentSlot.MAINHAND) ? this.defaultModifiers : super.m_7167_(equipmentSlot); } public boolean onLeftClickEntity(ItemStack stack, Player player, Entity entity) { return super.onLeftClickEntity(stack, player, entity); } @OnlyIn(Dist.CLIENT) public void m_7373_(ItemStack stack, Level level, List<Component> tooltip, TooltipFlag flag) { super.m_7373_(stack, level, tooltip, flag); if (InputConstants.m_84830_(Minecraft.m_91087_().m_91268_().m_85439_(), 340)) { tooltip.add(Component.m_237115_("tooltip.fusion_sword").m_130940_(ChatFormatting.GRAY)); } else { tooltip.add(Component.m_237115_("tooltip.hold_shift").m_130940_(ChatFormatting.GRAY)); } } public InteractionResultHolder<ItemStack> m_7203_(Level level, Player playerIn, InteractionHand handIn) { if (((Boolean)ConfigEffects.JUMP_F.get()).booleanValue()) playerIn.m_7292_(new MobEffectInstance(MobEffects.f_19603_, 10000, ((Integer)ConfigEffects.JUMP_F_LEVEL.get()).intValue() - 1)); if (((Boolean)ConfigEffects.MOVEMENT_SPEED_F.get()).booleanValue()) playerIn.m_7292_(new MobEffectInstance(MobEffects.f_19596_, 10000, ((Integer)ConfigEffects.MOVEMENT_SPEED_F_LEVEL.get()).intValue() - 1)); if (((Boolean)ConfigEffects.SLOW_FALLING_F.get()).booleanValue()) playerIn.m_7292_(new MobEffectInstance(MobEffects.f_19591_, 10000, ((Integer)ConfigEffects.SLOW_FALLING_F_LEVEL.get()).intValue() - 1)); if (((Boolean)ConfigEffects.ABSORPTION_F.get()).booleanValue()) playerIn.m_7292_(new MobEffectInstance(MobEffects.f_19617_, 10000, ((Integer)ConfigEffects.ABSORPTION_F_LEVEL.get()).intValue() - 1)); if (((Boolean)ConfigEffects.DAMAGE_RESISTANCE_F.get()).booleanValue()) playerIn.m_7292_(new MobEffectInstance(MobEffects.f_19606_, 10000, ((Integer)ConfigEffects.DAMAGE_RESISTANCE_F_LEVEL.get()).intValue() - 1)); if (((Boolean)ConfigEffects.DAMAGE_BOOST_F.get()).booleanValue()) playerIn.m_7292_(new MobEffectInstance(MobEffects.f_19600_, 10000, ((Integer)ConfigEffects.DAMAGE_BOOST_F_LEVEL.get()).intValue() - 1)); if (((Boolean)ConfigEffects.CONDUIT_POWER_F.get()).booleanValue()) playerIn.m_7292_(new MobEffectInstance(MobEffects.f_19592_, 10000, ((Integer)ConfigEffects.CONDUIT_POWER_F_LEVEL.get()).intValue() - 1)); if (((Boolean)ConfigEffects.DOLPHINS_GRACE_F.get()).booleanValue()) playerIn.m_7292_(new MobEffectInstance(MobEffects.f_19593_, 10000, ((Integer)ConfigEffects.DOLPHINS_GRACE_F_LEVEL.get()).intValue() - 1)); if (((Boolean)ConfigEffects.WATER_BREATHING_F.get()).booleanValue()) playerIn.m_7292_(new MobEffectInstance(MobEffects.f_19608_, 10000, ((Integer)ConfigEffects.WATER_BREATHING_F_LEVEL.get()).intValue() - 1)); if (((Boolean)ConfigEffects.FIRE_RESISTANCE_F.get()).booleanValue()) playerIn.m_7292_(new MobEffectInstance(MobEffects.f_19607_, 10000, ((Integer)ConfigEffects.FIRE_RESISTANCE_F_LEVEL.get()).intValue() - 1)); if (((Boolean)ConfigEffects.HEALTH_BOOST_F.get()).booleanValue()) playerIn.m_7292_(new MobEffectInstance(MobEffects.f_19616_, 10000, ((Integer)ConfigEffects.HEALTH_BOOST_F_LEVEL.get()).intValue() - 1)); if (((Boolean)ConfigEffects.REGENERATION_F.get()).booleanValue()) playerIn.m_7292_(new MobEffectInstance(MobEffects.f_19605_, 10000, ((Integer)ConfigEffects.REGENERATION_F_LEVEL.get()).intValue() - 1)); return InteractionResultHolder.m_19098_(playerIn.m_21120_(handIn)); } public boolean canPerformAction(ItemStack stack, ToolAction toolAction) { return ToolActions.DEFAULT_SWORD_ACTIONS.contains(toolAction); } } How do I make this thing enchantable?  
    • The mod I'm working on is in 1.19.2. The portal works correctly in Intellij but when I publish the jar, put it in the mods folder of the game it crashes with the following error whenever any entity collides with it: java.lang.IllegalAccessError: class com.github.warrentode.turtleblockacademy.blocks.TBAMiningPortalBlock tried to access protected field net.minecraft.world.entity.Entity.f_19819_ (com.github.warrentode.turtleblockacademy.blocks.TBAMiningPortalBlock is in module [email protected] of loader 'TRANSFORMER' @16c5b50a; net.minecraft.world.entity.Entity is in module [email protected] of loader 'TRANSFORMER' @16c5b50a)     at com.github.warrentode.turtleblockacademy.blocks.TBAMiningPortalBlock.m_7892_(TBAMiningPortalBlock.java:124) ~[turtleblockacademy-2024.2025-1.0.0.jar%23572!/:2024.2025-1.0.0] {re:classloading} The thing is, I have Entity.f_19819_ in my accessTransformer.cfg file in this line: public net.minecraft.world.entity.Entity f_19819_ # portalEntrancePos So what do I need to do to fix this error?
    • It will be about medeaival times
  • Topics

×
×
  • Create New...

Important Information

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