Jump to content

[1.7.10] Mob with inventory, Simple Network Wrapper problem.


SSslimer

Recommended Posts

Hi,

I managed to create inventory for my mob, it is simillar to horse.

But there is one problem. I dont know how to open it, I tried to use method player.displayGUIChest(), but after that my gui looks like chest.Horse gui use method: displayGUIHorse(), but I cant use it due to different entity class.

What method should I use to display my gui?

 

Link to comment
Share on other sites

He suggested me to do it in PM.

The code is mostly from MultiMode to make it only working

Maybe all code for inventory and error log will help.

 

public class InventoryVillager extends InventoryBasic
{
    public InventoryVillager(String name, int slots)
    {
        super(name, false, slots);
    }
}

 

Code from container.

public class ContainerVillager extends Container
{
    protected IInventory inventory;

    private int player_inventory_x = 70;
    private int player_inventory_y = 8;
    private int loot_x = 8;
    private int loot_y = 10;

    public ContainerVillager(InventoryPlayer inventoryPlayer, IInventory iInventory)
    {
        inventory = iInventory;
        {
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    addSlotToContainer(new Slot(iInventory, j + i * 2, (loot_x + j * 18), (loot_y + i * 18)));
                }
            }
        }
        bindPlayerInventory(inventoryPlayer);
    }

public boolean canInteractWith(EntityPlayer player)
    {
	 return inventory.isUseableByPlayer(player);
    }


    protected void bindPlayerInventory(InventoryPlayer inventoryPlayer)
    {
        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 9; j++)
            {
                addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9, player_inventory_x + j * 18, player_inventory_y + i * 18));
            }
        }

        for (int i = 0; i < 9; i++)
        {
            addSlotToContainer(new Slot(inventoryPlayer, i, player_inventory_x + i * 18, player_inventory_y + 54 + 4));
        }
    }

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

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

            int s = inventory.getSizeInventory();

            if (par2 < s)
            {
                if (!this.mergeItemStack(itemstack1, s, this.inventorySlots.size(), true))
                {
                    return null;
                }
            }
            else if (!this.mergeItemStack(itemstack1, 0, s, false))
            {
                return null;
            }

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

        return itemstack;
    }

    public void onContainerClosed(EntityPlayer par1EntityPlayer)
    {
        super.onContainerClosed(par1EntityPlayer);
        this.inventory.closeInventory();
    }
}

 

Code in GUI.

@SideOnly(Side.CLIENT)      
public class GuiVillagerInventory extends GuiContainer
{
private static final ResourceLocation texture = new ResourceLocation("BetterWorld:textures/gui/VillagerInventory.png");
private int invW = 176;
private int invH = 90;

private int lootH = 90;
private int lootW = 50;


public GuiVillagerInventory(InventoryPlayer inventoryPlayer, InventoryVillager inv)
{
	super(new ContainerVillager(inventoryPlayer, inv));
	this.xSize=300;
	this.ySize=90;
}

protected void drawGuiContainerForegroundLayer(int param1, int param2) {}


protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3)
{
	GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
	this.mc.renderEngine.bindTexture(texture);
	int x = (width - invW) / 2;
	int y = (height - invH) / 2;
	this.drawTexturedModalRect(x, y, 0, 0, invW, invH);

	x = (width/ 2)-150;
	y = (height - lootH) / 2;
	this.drawTexturedModalRect(x, y, 176, 0, lootW, lootH);
}
}

 

Code in entity class.

public class EntityBetterVillager extends EntityVillagerType implements INpc, IRangedAttackMob, IInvBasic
{
    private InventoryVillager inventoryVillager;
    public IInventory inventory;

   public EntityBetterVillager(World par1World)
    {
        this(par1World, 0);
        this.setupInventory();
    }

    public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound)
    {
        super.writeEntityToNBT(par1NBTTagCompound);       
        if (!this.isChild())
        {
            NBTTagList nbttaglist = new NBTTagList();
            for (int i = 0; i < this.inventoryVillager.getSizeInventory(); ++i)
            {
                ItemStack itemstack = this.inventoryVillager.getStackInSlot(i);
                if (itemstack != null)
                {
                    NBTTagCompound nbttagcompound1 = new NBTTagCompound();
                    nbttagcompound1.setByte("Slot", (byte) i);
                    itemstack.writeToNBT(nbttagcompound1);
                    nbttaglist.appendTag(nbttagcompound1);
                }
                par1NBTTagCompound.setTag("Items", nbttaglist);
            }
        }
    }


    public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound)
    {
        super.readEntityFromNBT(par1NBTTagCompound);
        if (!this.isChild())
        {
            NBTTagList nbttaglist = par1NBTTagCompound.getTagList("Items", 20);
            this.setupInventory();
            for (int i = 0; i < nbttaglist.tagCount(); ++i)
            {
                NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
                int j = nbttagcompound1.getByte("Slot") & 255;
                if (j >= 0 && j < this.inventoryVillager.getSizeInventory())
                {
                    this.inventoryVillager.setInventorySlotContents(j, ItemStack.loadItemStackFromNBT(nbttagcompound1));
                }
            }
        }
    }

    public int howManySlots() 
    {
        return 8;
    }

    private void setupInventory() 
    {
        InventoryVillager inventory = this.inventoryVillager;
        this.inventoryVillager = new InventoryVillager("Villager Inventory", howManySlots());
        this.inventoryVillager.func_110133_a(this.getCommandSenderName());

        if (inventory != null)
        {
        	inventory.func_110132_b(this);
            int i = Math.min(inventory.getSizeInventory(), this.inventoryVillager.getSizeInventory());

            for (int j = 0; j < i; ++j)
            {
                ItemStack itemstack = inventory.getStackInSlot(j);

                if (itemstack != null)
                {
                    this.inventoryVillager.setInventorySlotContents(j, itemstack.copy());
                }
            }

            inventory = null;
        }

        this.inventoryVillager.func_110134_a(this);
    }

@Override
public void onInventoryChanged(InventoryBasic var1) {}
}

 

Code from another gui, in method actionPerformed(GuiButton guiButton)

ModBetterWorld.packets.sendToServer(new GuiRequestPacket(3, this.villager.getEntityId()));

 

In main class

public static SimpleNetworkWrapper packets;

@EventHandler
public void postInit(FMLPostInitializationEvent event)
{
	packets = NetworkRegistry.INSTANCE.newSimpleChannel("ModBetterWorld");
	packets.registerMessage(GuiRequestPacket.class, GuiRequestPacket.class, 0, Side.SERVER);
}	

 

 

Packet Handler

public class GuiRequestPacket implements IMessage, IMessageHandler<GuiRequestPacket, IMessage>
{ 
int type;
int entityID;

public GuiRequestPacket()
{

}

public GuiRequestPacket(int type, int entityID)
{
	this.type = type;
	this.entityID = entityID;
}	

@Override
public void toBytes(ByteBuf target)
{
	target.writeInt(type);
	target.writeInt(entityID);
}

@Override
public void fromBytes(ByteBuf dat)
{
	type = dat.readInt();
	entityID = dat.readInt();
}

@Override
public IMessage onMessage(GuiRequestPacket message, MessageContext ctx)
{
	System.out.println("requested guiID" + message.type + " for entity ID " + message.entityID);
	EntityPlayer player = ctx.getServerHandler().playerEntity;
	World world = player.worldObj;
	player.openGui(ModBetterWorld.instance, message.type, world, message.entityID, 0, 0);
	return null;
}
}

 

When I open gui by button the game crashes.

I can see for a while gui screen. Then crash occure.

It says sth about forge error.

 

Here is error log:

 

12:56:36] [server thread/ERROR] [FML]: SimpleChannelHandlerWrapper exception
java.lang.NullPointerException
at net.minecraft.inventory.Slot.getStack(Slot.java:88) ~[slot.class:?]
at net.minecraft.inventory.Container.getInventory(Container.java:67) ~[Container.class:?]
at net.minecraft.inventory.Container.addCraftingToCrafters(Container.java:53) ~[Container.class:?]
at cpw.mods.fml.common.network.internal.FMLNetworkHandler.openGui(FMLNetworkHandler.java:88) ~[FMLNetworkHandler.class:?]
at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2501) ~[EntityPlayer.class:?]
at BetterWorld.GuiRequestPacket.onMessage(GuiRequestPacket.java:46) ~[GuiRequestPacket.class:?]
at BetterWorld.GuiRequestPacket.onMessage(GuiRequestPacket.java:1) ~[GuiRequestPacket.class:?]
at cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.channelRead0(SimpleChannelHandlerWrapper.java:37) ~[simpleChannelHandlerWrapper.class:?]
at cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.channelRead0(SimpleChannelHandlerWrapper.java:17) ~[simpleChannelHandlerWrapper.class:?]
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:98) ~[simpleChannelInboundHandler.class:?]
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [DefaultChannelHandlerContext.class:?]
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) [DefaultChannelHandlerContext.class:?]
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) [MessageToMessageDecoder.class:?]
at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) [MessageToMessageCodec.class:?]
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [DefaultChannelHandlerContext.class:?]
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) [DefaultChannelHandlerContext.class:?]
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) [DefaultChannelPipeline.class:?]
at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) [EmbeddedChannel.class:?]
at cpw.mods.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:86) [FMLProxyPacket.class:?]
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) [NetworkManager.class:?]
at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182) [NetworkSystem.class:?]
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614) [MinecraftServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) [integratedServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752) [MinecraftServer$2.class:?]
[12:56:36] [server thread/ERROR] [FML]: There was a critical exception handling a packet on channel ModBetterWorld
java.lang.NullPointerException
at net.minecraft.inventory.Slot.getStack(Slot.java:88) ~[slot.class:?]
at net.minecraft.inventory.Container.getInventory(Container.java:67) ~[Container.class:?]
at net.minecraft.inventory.Container.addCraftingToCrafters(Container.java:53) ~[Container.class:?]
at cpw.mods.fml.common.network.internal.FMLNetworkHandler.openGui(FMLNetworkHandler.java:88) ~[FMLNetworkHandler.class:?]
at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2501) ~[EntityPlayer.class:?]
at BetterWorld.GuiRequestPacket.onMessage(GuiRequestPacket.java:46) ~[GuiRequestPacket.class:?]
at BetterWorld.GuiRequestPacket.onMessage(GuiRequestPacket.java:1) ~[GuiRequestPacket.class:?]
at cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.channelRead0(SimpleChannelHandlerWrapper.java:37) ~[simpleChannelHandlerWrapper.class:?]
at cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.channelRead0(SimpleChannelHandlerWrapper.java:17) ~[simpleChannelHandlerWrapper.class:?]
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:98) ~[simpleChannelInboundHandler.class:?]
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) ~[DefaultChannelHandlerContext.class:?]
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) ~[DefaultChannelHandlerContext.class:?]
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) ~[MessageToMessageDecoder.class:?]
at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) ~[MessageToMessageCodec.class:?]
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) ~[DefaultChannelHandlerContext.class:?]
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) ~[DefaultChannelHandlerContext.class:?]
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) ~[DefaultChannelPipeline.class:?]
at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) ~[EmbeddedChannel.class:?]
at cpw.mods.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:86) [FMLProxyPacket.class:?]
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) [NetworkManager.class:?]
at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182) [NetworkSystem.class:?]
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614) [MinecraftServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) [integratedServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752) [MinecraftServer$2.class:?]
[12:56:36] [server thread/ERROR]: Encountered an unexpected exception
net.minecraft.util.ReportedException: Ticking player
at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:198) ~[NetworkSystem.class:?]
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726) ~[MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614) ~[MinecraftServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) ~[integratedServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752) [MinecraftServer$2.class:?]
Caused by: java.lang.NullPointerException
at BetterWorld.mobs.ContainerVillager.canInteractWith(ContainerVillager.java:36) ~[ContainerVillager.class:?]
at net.minecraftforge.event.entity.player.PlayerOpenContainerEvent.<init>(PlayerOpenContainerEvent.java:27) ~[PlayerOpenContainerEvent.class:?]
at net.minecraftforge.common.ForgeHooks.canInteractWith(ForgeHooks.java:386) ~[ForgeHooks.class:?]
at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:329) ~[EntityPlayer.class:?]
at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:330) ~[EntityPlayerMP.class:?]
at net.minecraft.network.NetHandlerPlayServer.processPlayer(NetHandlerPlayServer.java:329) ~[NetHandlerPlayServer.class:?]
at net.minecraft.network.play.client.C03PacketPlayer.processPacket(C03PacketPlayer.java:37) ~[C03PacketPlayer.class:?]
at net.minecraft.network.play.client.C03PacketPlayer.processPacket(C03PacketPlayer.java:111) ~[C03PacketPlayer.class:?]
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) ~[NetworkManager.class:?]
at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182) ~[NetworkSystem.class:?]
... 5 more

 

And next part:

Time: 19.10.14 12:56
Description: Ticking player

java.lang.NullPointerException: Ticking player
at BetterWorld.mobs.ContainerVillager.canInteractWith(ContainerVillager.java:36)
at net.minecraftforge.event.entity.player.PlayerOpenContainerEvent.<init>(PlayerOpenContainerEvent.java:27)
at net.minecraftforge.common.ForgeHooks.canInteractWith(ForgeHooks.java:386)
at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:329)
at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:330)
at net.minecraft.network.NetHandlerPlayServer.processPlayer(NetHandlerPlayServer.java:329)
at net.minecraft.network.play.client.C03PacketPlayer.processPacket(C03PacketPlayer.java:37)
at net.minecraft.network.play.client.C03PacketPlayer.processPacket(C03PacketPlayer.java:111)
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241)
at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752)


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Stacktrace:
at BetterWorld.mobs.ContainerVillager.canInteractWith(ContainerVillager.java:36)
at net.minecraftforge.event.entity.player.PlayerOpenContainerEvent.<init>(PlayerOpenContainerEvent.java:27)
at net.minecraftforge.common.ForgeHooks.canInteractWith(ForgeHooks.java:386)
at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:329)

-- Player being ticked --
Details:
Entity Type: null (net.minecraft.entity.player.EntityPlayerMP)
Entity ID: 109
Entity Name: Player170
Entity's Exact location: 642,57, 4,00, 174,03
Entity's Block location: World: (642,4,174), Chunk: (at 2,0,14 in 40,10; contains blocks 640,0,160 to 655,255,175), Region: (1,0; contains chunks 32,0 to 63,31, blocks 512,0,0 to 1023,255,511)
Entity's Momentum: 0,00, -0,08, 0,00
Stacktrace:
at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:330)
at net.minecraft.network.NetHandlerPlayServer.processPlayer(NetHandlerPlayServer.java:329)
at net.minecraft.network.play.client.C03PacketPlayer.processPacket(C03PacketPlayer.java:37)
at net.minecraft.network.play.client.C03PacketPlayer.processPacket(C03PacketPlayer.java:111)
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241)

-- Ticking connection --
Details:
Connection: net.minecraft.network.NetworkManager@3d7e16
Stacktrace:
at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752)

 

 

 

I know that is a lot of code but I will be very thankful if someone help me  :)

 

 

 

 

 

Link to comment
Share on other sites

  • 3 weeks later...

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.