Jump to content

Problems between server-client, client-server talk[unsolved but i don't care]


Moritz

Recommended Posts

Yeah same problem as before but now with that i do not click on the block i just put a item in like a furnace here 2 pics that explains more then 1000 words.

 

 

Exp in a bottle (51000 Exp):

 

https://www.dropbox.com/s/p05ftkf8waoee0g/No%20Exp%20in%20the%20storage.bmp

 

Exp now in my Storage (51000 Exp):

 

https://www.dropbox.com/s/d9mwxpi59up5nrs/Exp%20in%20the%20storage.bmp

 

 

here my full code of the Exp Bottles:

 

package speiger.src.api.common.items;

import java.util.List;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import speiger.src.api.SpmodAPI;
import speiger.src.api.api.IExpBottle;
import speiger.src.api.common.lib.APITextures;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class ItemEXPBottles extends ItemSpmod implements IExpBottle
{

private int transferlimit;
private int texture;
private String name;
private int storedExp;

public ItemEXPBottles(int par1, int storedEXP, int transportlimit, int itemTexture, String itemname, boolean beta) 
{
	super(par1, beta);
	this.setNoRepair();
	setMaxDamage(4);
	storedExp = storedEXP;
	setMaxStackSize(1);
	transferlimit = transportlimit;
	texture = itemTexture;
	name = itemname;
	setCreativeTab(SpmodAPI.spmodAPI);
}

    @Override
    public String getTextureFile()
    {
    	return APITextures.apiTexturePath;
    }

public int getIconFromDamage(int par1)
{
	return texture;
}

@Override
public void charge(int i, ItemStack par1)
{
	NBTTagCompound par2 = par1.getTagCompound().getCompoundTag("ExpBottle");
	int b = par2.getInteger("StoredExp");
	par2.setInteger("StoredExp", b+i);
	int d = b+i;
	if(d > 0)
	{
		if(d > (storedExp / 4))
		{
			if(d > (storedExp / 2))
			{
				if(d > ((storedExp / 4) * 3))
				{
					if(d >= storedExp)
					{
						par1.setItemDamage(0);
					}
					else
					{
						par1.setItemDamage(1);
					}
				}
				else
				{
					par1.setItemDamage(2);
				}
			}
			else
			{
				par1.setItemDamage(3);
			}
		}
		else
		{
			par1.setItemDamage(4);
		}
	}
}

@Override
public void discharge(int i, ItemStack par1)
{
	NBTTagCompound par2 = par1.getTagCompound().getCompoundTag("ExpBottle");
	int d = par2.getInteger("StoredExp");
	par2.setInteger("StoredExp", d-i);
	int b = d-i;
	if(b > 0)
	{
		if(b > (storedExp / 4))
		{
			if(b > (storedExp / 2))
			{
				if(b > ((storedExp / 4) * 3))
				{
					if(b >= storedExp)
					{
						par1.setItemDamage(0);
					}
					else
					{
						par1.setItemDamage(1);
					}
				}
				else
				{
					par1.setItemDamage(2);
				}
			}
			else
			{
				par1.setItemDamage(3);
			}
		}
		else
		{
			par1.setItemDamage(4);
		}
	}
}

@Override
public int getTransferlimit(ItemStack par1)
{
	return this.transferlimit;
}

@Override
public int getMaxCharge(ItemStack par1)
{
	return this.storedExp;
}

@Override
public int getStoredExp(ItemStack par1)
{
	NBTTagCompound par2 = par1.getTagCompound().getCompoundTag("ExpBottle");
	return par2.getInteger("StoredExp");
}

@Override
public boolean hasExp(ItemStack par1)
{
	NBTTagCompound par2 = par1.getTagCompound().getCompoundTag("ExpBottle");
	if(par2.getInteger("StoredExp") > 0)
	{
		return true;
	}
	return false;
}

@Override
public boolean needsExp(ItemStack par1)
{
	NBTTagCompound par2 = par1.getTagCompound().getCompoundTag("ExpBottle");
	if(par2.getInteger("StoredExp")< this.storedExp)
	{
		return true;
	}

	return false;
}

@Override
@SideOnly(Side.CLIENT)
public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3)
{
	NBTTagCompound nbtEmpty = new NBTTagCompound();
	nbtEmpty.setCompoundTag("ExpBottle", new NBTTagCompound());
	nbtEmpty.getCompoundTag("ExpBottle").setInteger("StoredExp", 0);
	ItemStack empty = new ItemStack(par1, 1, 4);
	empty.setTagCompound(nbtEmpty);
	par3.add(empty);

	NBTTagCompound nbtFull = new NBTTagCompound();
	nbtFull.setCompoundTag("ExpBottle", new NBTTagCompound());
	nbtFull.getCompoundTag("ExpBottle").setInteger("StoredExp", this.storedExp);
	ItemStack full = new ItemStack(par1, 1, 0);
	full.setTagCompound(nbtFull);
	par3.add(full);
}

@Override
public String getItemDisplayName(ItemStack par1ItemStack)
{
	return this.name;
}

@Override
@SideOnly(Side.CLIENT)
public boolean hasEffect(ItemStack par1ItemStack)
{
	return this.hasExp(par1ItemStack);
}

@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack par1, EntityPlayer par2, List par3, boolean par4)
{
	if(par1.hasTagCompound())
	{
		if(par1.getTagCompound().getCompoundTag("ExpBottle")!= null)
		{
			par3.add("Stored EXP: "+par1.getTagCompound().getCompoundTag("ExpBottle").getInteger("StoredExp"));
		}
	}
	par3.add("Can Store: "+this.storedExp+" EXP");

	this.getInformation(par1, par2, par3, par4);
}






}

 

Container of the Basic Exp Storage:

 


package speiger.src.api.common.container;

import java.util.Iterator;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import speiger.src.api.api.IExpBottle;
import speiger.src.api.common.tile.BasicExpBench;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class ContainerBasicExpBench extends Container {

private int expnow = 0;
private BasicExpBench tile;

public ContainerBasicExpBench(InventoryPlayer par1, BasicExpBench par2) 
{
	addSlotToContainer(new Slot(par2, 0, 43, 35)); //Import Slot
	addSlotToContainer(new Slot(par2, 1, 116, 35)); //Output Slot
	tile = par2;
        int var3;

        for (var3 = 0; var3 < 3; ++var3)
        {
            for (int var4 = 0; var4 < 9; ++var4)
            {
                this.addSlotToContainer(new Slot(par1, var4 + var3 * 9 + 9, 8 + var4 * 18, 84 + var3 * 18));
            }
        }

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

@Override
public boolean canInteractWith(EntityPlayer var1) 
{
	return true;
}

@Override
    public void detectAndSendChanges()
    {
        super.detectAndSendChanges();

        for (int var1 = 0; var1 < this.crafters.size(); ++var1)
        {
            ICrafting var2 = (ICrafting)this.crafters.get(var1);

            if (this.expnow != this.tile.exp)
            {
                var2.sendProgressBarUpdate(this, 0, this.tile.exp);
            }
        }
        expnow = tile.exp;
    }

    @SideOnly(Side.CLIENT)
    public void updateProgressBar(int par1, int par2)
    {
        if (par1 == 0)
        {
            this.tile.exp = par2;
        }
    }
    
    public void addCraftingToCrafters(ICrafting par1ICrafting)
    {
        super.addCraftingToCrafters(par1ICrafting);
        par1ICrafting.sendProgressBarUpdate(this, 0, tile.exp);
    }

    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 != 1 && par2 != 0)
            {
                if (var5.getItem() instanceof IExpBottle)
                {
                    if (!this.mergeItemStack(var5, 0, 1, false))
                    {
                        return null;
                    }
                }
                else if (var5.getItem() instanceof IExpBottle)
                {
                    if (!this.mergeItemStack(var5, 1, 2, false))
                    {
                        return null;
                    }
                }
                else if (par2 >= 30 && par2 < 39 && !this.mergeItemStack(var5, 3, 30, false))
                {
                    return null;
                }
            }
            else if (!this.mergeItemStack(var5, 3, 39, 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;
    }
}


 

Code of the gui Basic Exp Storage:

 


package speiger.src.api.client.gui;

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

import org.lwjgl.opengl.GL11;

import speiger.src.api.common.container.ContainerBasicExpBench;
import speiger.src.api.common.tile.BasicExpBench;

public class GuiBasicExpBench extends GuiContainer {

private BasicExpBench bench;

public GuiBasicExpBench(InventoryPlayer par1, BasicExpBench par2) 
{
	super(new ContainerBasicExpBench(par1, par2));
	bench = par2;
}

    protected void drawGuiContainerForegroundLayer(int par1, int par2)
    {
    	this.fontRenderer.drawString("Stored Exp: " + bench.gettingEXP(), 60, 20, 4210752);
        this.fontRenderer.drawString("Basic Exp Storage", 50, 4, 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("/speiger/src/api/textures/gui/basicEXPBench.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);
    }

}


 

 

and now the TileEntity:

package speiger.src.api.common.tile;

import java.util.List;
import java.util.Random;

import net.minecraft.entity.item.EntityXPOrb;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.Packet132TileEntityData;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
import speiger.src.api.api.IExpBottle;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class BasicExpBench extends TileFacing implements IInventory
{
public Random rand = new Random();
public int exp = 0;
public ItemStack[] basicExp = new ItemStack[2];
public boolean update = false;
public int facing = 0;

    @SideOnly(Side.CLIENT)
public int gettingEXP()
{
	return exp;
}
    
    @Override
public int getTextureFromTile(int meta, int side) 
{
    	if(side == this.facing)return 65;
    	else if(side == 0 || side == 1)return 64;
    	else return 66;
}

    @Override
public Packet getDescriptionPacket() 
    {
    	NBTTagCompound var1 = new NBTTagCompound();
    	super.writeToNBT(var1);
    	var1.setInteger("rotation", facing);
    	var1.setInteger("Experience", exp);
        this.worldObj.markBlockForRenderUpdate(this.xCoord, this.yCoord, this.zCoord);
    	return new Packet132TileEntityData(this.xCoord, this.yCoord, this.zCoord, 1, var1);
}
    

@Override
public void onDataPacket(INetworkManager net, Packet132TileEntityData pkt) 
{
	this.readFromNBT(pkt.customParam1);
}

    public int getSizeInventory()
    {
        return this.basicExp.length;
    }
    
    public ItemStack getStackInSlot(int par1)
    {
        return this.basicExp[par1];
    }


    public ItemStack decrStackSize(int par1, int par2)
    {
        if (this.basicExp[par1] != null)
        {
            ItemStack var3;

            if (this.basicExp[par1].stackSize <= par2)
            {
                var3 = this.basicExp[par1];
                this.basicExp[par1] = null;
                return var3;
            }
            else
            {
                var3 = this.basicExp[par1].splitStack(par2);

                if (this.basicExp[par1].stackSize == 0)
                {
                    this.basicExp[par1] = null;
                }

                return var3;
            }
        }
        else
        {
            return null;
        }
    }

    
    public ItemStack getStackInSlotOnClosing(int par1)
    {
        if (this.basicExp[par1] != null)
        {
            ItemStack var2 = this.basicExp[par1];
            this.basicExp[par1] = null;
            return var2;
        }
        else
        {
            return null;
        }
    }

    
    public void setInventorySlotContents(int par1, ItemStack par2ItemStack)
    {
        this.basicExp[par1] = par2ItemStack;

        if (par2ItemStack != null && par2ItemStack.stackSize > this.getInventoryStackLimit())
        {
            par2ItemStack.stackSize = this.getInventoryStackLimit();
        }
    }

    
    public String getInvName()
    {
        return "Basic EXP Storage";
    }

public int getInventoryStackLimit() 
{
	return 1;
}


public boolean isUseableByPlayer(EntityPlayer var1) 
{
	return true;
}


public void openChest() 
{
}

@Override
    public void readFromNBT(NBTTagCompound par1NBTTagCompound)
    {
        super.readFromNBT(par1NBTTagCompound);
        exp = par1NBTTagCompound.getInteger("Experience");
        facing = par1NBTTagCompound.getInteger("rotation");
        NBTTagList var2 = par1NBTTagCompound.getTagList("Items");
        this.basicExp = new ItemStack[this.getSizeInventory()];

        for (int var3 = 0; var3 < var2.tagCount(); ++var3)
        {
            NBTTagCompound var4 = (NBTTagCompound)var2.tagAt(var3);
            byte var5 = var4.getByte("Slot");

            if (var5 >= 0 && var5 < this.basicExp.length)
            {
                this.basicExp[var5] = ItemStack.loadItemStackFromNBT(var4);
            }
        }
        
    }

    /**
     * Writes a tile entity to NBT.
     */
@Override
    public void writeToNBT(NBTTagCompound par1NBTTagCompound)
    {
        super.writeToNBT(par1NBTTagCompound);
       
        NBTTagList var2 = new NBTTagList();

        for (int var3 = 0; var3 < this.basicExp.length; ++var3)
        {
            if (this.basicExp[var3] != null)
            {
                NBTTagCompound var4 = new NBTTagCompound();
                var4.setByte("Slot", (byte)var3);
                this.basicExp[var3].writeToNBT(var4);
                var2.appendTag(var4);
            }
        }

        par1NBTTagCompound.setTag("Items", var2);
        par1NBTTagCompound.setInteger("Experience", exp);
     	par1NBTTagCompound.setInteger("rotation", facing);
    }

public void closeChest() 
{
}

public void updateBlock()
    {
        int var1 = this.worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord);
        this.worldObj.markBlockForRenderUpdate(this.xCoord, this.yCoord, this.zCoord);
        markBlockDirty(this.worldObj, this.xCoord, this.yCoord, this.zCoord);
    }

    public void markBlockDirty(World var0, int var1, int var2, int var3)
    {
        if (var0.blockExists(var1, var2, var3))
        {
            var0.getChunkFromBlockCoords(var1, var3).setChunkModified();
        }
    }


@Override
public void updateEntity() 
{


	updateBlock();
                                if(!worldObj.isRemote)
                                {
	       getEXP();
	       transferExp();
                                }

	if(update)
	{
		update = false;
		this.onInventoryChanged();
	}
}


public void transferExp()
{
	if(basicExp[0] != null && basicExp[0].getItem() instanceof IExpBottle)
	{
		IExpBottle eb = (IExpBottle) basicExp[0].getItem();
		if(eb.hasExp(basicExp[0]))
		{
			if(eb.getStoredExp(basicExp[0]) > eb.getTransferlimit(basicExp[0]))
			{
				eb.discharge(eb.getTransferlimit(basicExp[0]),basicExp[0]);
				exp+= eb.getTransferlimit(basicExp[0]);
				update = true;
			}
			else if(eb.getStoredExp(basicExp[0]) > 1000)
			{
				eb.discharge(1000, basicExp[0]);
				exp+= 1000;
				update = true;
			}
			else if(eb.getStoredExp(basicExp[0]) > 100)
			{
				eb.discharge(100, basicExp[0]);
				exp+=100;
				update = true;
			}
			else
			{
				eb.discharge(1, basicExp[0]);
				exp+=1;
				update = true;
			}
		}


	}

	if(basicExp[1] != null && basicExp[1].getItem() instanceof IExpBottle)
	{
		IExpBottle eb = (IExpBottle) basicExp[1].getItem();
		if(exp > eb.getTransferlimit(basicExp[1]))
		{
			if(eb.needsExp(basicExp[1]))
			{
				if(eb.getStoredExp(basicExp[1]) + eb.getTransferlimit(basicExp[1]) <= eb.getMaxCharge(basicExp[1]))
				{
					eb.charge(eb.getTransferlimit(basicExp[1]), basicExp[1]);
					exp -= eb.getTransferlimit(basicExp[1]);
					update = true;
				}
				else
				{
					eb.charge(1, basicExp[1]);
					exp-=1;
					update = true;
				}
			}
		}
		else if(exp > 1000)
		{
			if((eb.getMaxCharge(basicExp[1]) - eb.getStoredExp(basicExp[1])) > 1000)
			{
				exp-= 1000;
				eb.charge(1000, basicExp[1]);
				update = true;
			}
		}
		else if(exp > 100)
		{
			if((eb.getMaxCharge(basicExp[1]) - eb.getStoredExp(basicExp[1])) > 100)
			{
				exp-= 100;
				eb.charge(100, basicExp[1]);
				update = true;
			}
		}
		else if(exp > 0)
		{
			if(eb.getStoredExp(basicExp[1]) < eb.getMaxCharge(basicExp[1]))
			{
				eb.charge(1, basicExp[1]);
				exp--;
				update = true;
			}
		}
	}
}


public void getEXP()
{
	List<EntityXPOrb> hitList = worldObj.getEntitiesWithinAABB(net.minecraft.entity.item.EntityXPOrb.class,
			AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 1, zCoord + 1).expand(5.0D, 5.0D, 5.0D));

	if (hitList.size() > 0) {
		Loop:
		for (EntityXPOrb orb : hitList) {
			if (orb.isDead) {
				update = true;
				continue Loop;

			}

			int oldxp = exp;
			worldObj.playSoundAtEntity(orb, "random.orb", 0.1F, 0.5F * ((rand.nextFloat() - rand.nextFloat()) * 0.7F + 1.8F));
			exp += orb.getXpValue();
			orb.setDead();
			if (oldxp == 0 && exp > 0) {
				notifyChange();
				update = true;
			} else {
				notifyResize();
				update = true;
			}
		}
	}
	return;
}
private void notifyChange() {
	worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, getBlockType().blockID);
	worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord - 1, zCoord, getBlockType().blockID);
	notifyResize();
}

private void notifyResize() {
	worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}






}

 

 

what is the problem?

I know server has to talk to the client but how if i never use the blockSide?

Link to comment
Share on other sites

Nope does not work.

 

i had to add a function to the container.

 

 

public int getExp()
{
     return expnow;
}

 

this only returns always 0. so i made it like this:

 

public int getExp()
{
   this.detectAndSendChanges();
   return expnow;
}

Now it showes the changes of the exp. But now the trouble it does not change anything else then i use the tile instead of the container.

 

Any other idea?

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

    • rp.crazyheal.xyz mods  
    • I'm developing a dimension, but it's kinda resource intensive so some times during player teleporting it lags behind making the player phase down into the void, so im trying to implement some kind of pregeneration to force the game loading a small set of chunks in the are the player will teleport to. Some of the things i've tried like using ServerLevel and ServerChunkCache methods like getChunk() dont actually trigger chunk generation if the chunk isn't already on persistent storage (already generated) or placing tickets, but that doesn't work either. Ideally i should be able to check when the task has ended too. I've peeked around some pregen engines, but they're too complex for my current understanding of the system of which I have just a basic understanding (how ServerLevel ,ServerChunkCache  and ChunkMap work) of. Any tips or other classes I should be looking into to understand how to do this correctly?
    • https://mclo.gs/4UC49Ao
    • Way back in the Forge 1.17 days, work started for adding JPMS (Java Platform Module Support) to ModLauncher and ForgeModLoader. This has been used internally by Forge and some libraries for a while now, but mods (those with mods.toml specifically) have not been able to take advantage of it. As of Forge 1.21.1 and 1.21.3, this is now possible!   What is JPMS and what does it mean for modders? JPMS is the Java Platform Module System, introduced in Java 9. It allows you to define modules, which are collections of packages and resources that can be exported or hidden from other modules. This allows for much more fine-tuned control over visibility, cleaner syntax for service declarations and support for sealed types across packages. For example, you might have a mod with a module called `com.example.mod` that exports `com.example.mod.api` and `com.example.mod.impl` to other mods, but hides `com.example.mod.internal` from them. This would allow you to have a clean API for other mods to use, while keeping your internal implementation details hidden from IDE hints, helping prevent accidental usage of internals that might break without prior notice. This is particularly useful if you'd like to use public records with module-private constructors or partially module-private record components, as you can create a sealed interface that only your record implements, having the interface be exported and the record hidden. It's also nice for declaring and using services, as you'll get compile-time errors from the Java compiler for typos and the like, rather than deferring to runtime errors. In more advanced cases, you can also have public methods that are only accessible to specific other modules -- handy if you want internal interactions between multiple of your own mods.   How do I bypass it? We understand there may be drama in implementing a system that prevents mods from accessing each other's internals when necessary (like when a mod is abandoned or you need to fix a compat issue) -- after all, we are already modding a game that doesn't have explicit support for Java mods yet. We have already thought of this and are offering APIs from day one to selectively bypass module restrictions. Let me be clear: Forge mods are not required to use JPMS. If you don't want to use it, you don't have to. The default behaviour is to have fully open, fully exported automatic modules. In Java, you can use the `Add-Opens` and `Add-Exports` manifest attributes to selectively bypass module restrictions of other mods at launch time, and we've added explicit support for these when loading your Forge mods. At compile-time, you can use existing solutions such as the extra-java-module-info Gradle plugin to deal with non-modular dependencies and add extra opens and exports to other modules. Here's an example on how to make the internal package `com.example.examplemod.internal` open to your mod in your build.gradle: tasks.named('jar', Jar) { manifest { attributes([ 'Add-Opens' : 'com.example.examplemod/com.example.examplemod.internal' 'Specification-Title' : mod_id, 'Specification-Vendor' : mod_authors // (...) ]) } } With the above in your mod's jar manifest, you can now reflectively access the classes inside that internal package. Multiple entries are separated with a space, as per Java's official spec. You can also use Add-Exports to directly call without reflection, however you'd need to use the Gradle plugin mentioned earlier to be able to compile. The syntax for Add-Exports is the same as Add-Opens, and instructions for the compile-time step with the Gradle plugin are detailed later in this post. Remember to prefer the opens and exports keywords inside module-info.java for sources you control. The Add-Opens/Add-Exports attributes are only intended for forcing open other mods.   What else is new with module support? Previously, the runtime module name was always forced to the first mod ID in your `mods.toml` file and all packages were forced fully open and exported. Module names are now distinguished from mod IDs, meaning the module name in your module-info.java can be different from the mod ID in your `mods.toml`. This allows you to have a more descriptive module name that doesn't have to be the same as your mod ID, however we strongly recommend including your mod ID as part of your module name to aid troubleshooting. The `Automatic-Module-Name` manifest attribute is now also honoured, allowing you to specify a module name for your mod without needing to create a `module-info.java` file. This is particularly useful for mods that don't care about JPMS features but want to have a more descriptive module name and easier integration with other mods that do use JPMS.   How do I use it? The first step is to create a `module-info.java` file in your mod's source directory. This file should be in the same package as your main mod class, and should look something like this: open module com.example.examplemod { requires net.minecraftforge.eventbus; requires net.minecraftforge.fmlcore; requires net.minecraftforge.forge; requires net.minecraftforge.javafmlmod; requires net.minecraftforge.mergetool.api; requires org.slf4j; requires logging; } For now, we're leaving the whole module open to reflection, which is a good starting point. When we know we want to close something off, we can remove the open modifier from the module and open or export individual packages instead. Remember that you need to be open to Forge (module name net.minecraftforge.forge), otherwise it can't call your mod's constructor. Next is fixing modules in Gradle. While Forge and Java support modules properly, Gradle does not put automatic modules on the module path by default, meaning that the logging module (from com.mojang:logging) is not found. To fix this, add the Gradle plugin and add a compile-time module definition for that Mojang library: plugins { // (...) id 'org.gradlex.extra-java-module-info' version "1.9" } // (...) extraJavaModuleInfo { failOnMissingModuleInfo = false automaticModule("com.mojang:logging", "logging") } The automatic module override specified in your build.gradle should match the runtime one to avoid errors. You can do the same for any library or mod dependency that is missing either a module-info or explicit Automatic-Module-Name, however be aware that you may need to update your mod once said library adds one. That's all you need to get started with module support in your mods. You can learn more about modules and how to use them at dev.java.
    • Faire la mise à jour grâce à ce lien m'a aider personnellement, merci à @Paint_Ninja. https://www.amd.com/en/support 
  • Topics

×
×
  • Create New...

Important Information

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