Jump to content

Model does only update on openGui


Moritz

Recommended Posts

Yeah my block only updated when the player opens the gui!

 

why does this happen?

 

Block:

package speiger.src.tinychest.common.blocks.tinychest;

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

import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import speiger.src.api.common.addonslib.tinychest.TinyChestIDs;
import speiger.src.api.common.addonslib.tinychest.TinyChestTextures;
import speiger.src.tinychest.TinyChest;
import speiger.src.tinychest.client.core.TinyChestClient;
import speiger.src.tinychest.common.config.TinyConfig;
import speiger.src.tinychest.common.lib.TinyFunctions;
import speiger.src.tinychest.common.tileentity.tinychest.TileEntityAdvancedTinyChest;
import speiger.src.tinychest.common.tileentity.tinychest.advanced.*;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class BlockAdvTinyChest extends BlockContainer
{

    private static TinyChestIDs tiny; 
    private static TinyChestTextures tx;
    
    public BlockAdvTinyChest(int id) 
    {
        super(id, Material.iron);
        this.setCreativeTab(TinyChest.tinyChest);
        this.setHardness(4.0F);
    }

//    @Override
//    public String getTextureFile()
//    {
//        return tx.TinyChestBlocksTexturePath;
//    }

//    @Override
//    public boolean renderAsNormalBlock() {
//        return false;
//    }

    
    public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6)
    {
        if(TinyConfig.doDrop)
        {
            dropInventory(par1World, par2, par3, par4);
        }
        super.breakBlock(par1World, par2, par3, par4, par5, par6);    
    
    }

    private void dropInventory(World world, int x, int y, int z) {
        Random rand = new Random();
        TileEntity tileEntity = world.getBlockTileEntity(x, y, z);

        if (!(tileEntity instanceof IInventory))
            return;

        IInventory inventory = (IInventory) tileEntity;

        for (int i = 0; i < inventory.getSizeInventory(); i++) {

            ItemStack itemStack = inventory.getStackInSlot(i);

            if (itemStack != null && itemStack.stackSize > 0) {
                float dX = rand.nextFloat() * 0.8F + 0.1F;
                float dY = rand.nextFloat() * 0.8F + 0.1F;
                float dZ = rand.nextFloat() * 0.8F + 0.1F;

                EntityItem entityItem = new EntityItem(world, x + dX, y + dY, z + dZ, new ItemStack(itemStack.itemID, itemStack.stackSize, itemStack.getItemDamage()));

                if (itemStack.hasTagCompound()) {
                    entityItem.func_92014_d().setTagCompound((NBTTagCompound) itemStack.getTagCompound().copy());
                }

                float factor = 0.05F;
                entityItem.motionX = rand.nextGaussian() * factor;
                entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
                entityItem.motionZ = rand.nextGaussian() * factor;
                world.spawnEntityInWorld(entityItem);
                itemStack.stackSize = 0;
            }
        }
    }
    
    @Override
    public boolean isOpaqueCube() {
        return false;
    }
    
    @SideOnly(Side.CLIENT)
    @Override
    public int getRenderType()
    {
        return TinyChestClient.advtinyID;
    }
    

//    public int getBlockTextureFromSideAndMetadata(int side, int meta)
//    {
//        if(side == ForgeDirection.NORTH.getOpposite().ordinal())
//            if(TinyConfig.differendtextures)
//                if(meta == 0)return tx.AdvTinyChestFront1;
//                else if(meta == 1)return tx.AdvTinyChestFront2;
//                else if(meta == 2)return tx.AdvTinyChestFront3;
//                else if(meta == 3)return tx.AdvTinyChestFront4;
//                else if(meta == 4)return tx.AdvTinyChestFront5;
//                else if(meta == 5)return tx.AdvTinyChestFront6;
//                else if(meta == 6)return tx.AdvTinyChestFront7;
//                else if(meta == 7)return tx.AdvTinyChestFront8;
//                else if(meta == 8)return tx.AdvTinyChestFront9;
//                else return 0;
//        
//            else return tx.AllAdvTinyChestFront;
//                
//        
//        else if(side == 0 || side == 1)return tx.AdvTinyChestTop;
//        else return tx.AdvTinyChestSide;
//    }
//    
//    
//
//    @Override
//    public int getBlockTexture(IBlockAccess world, int var1, int var2, int var3, int side)
//    {
//        int meta = world.getBlockMetadata(var1, var2, var3);
//        TileEntityAdvancedTinyChest te = (TileEntityAdvancedTinyChest)world.getBlockTileEntity(var1, var2, var3);
//        
//        return te.getTexture(side, meta, te.getFacing());
//        
//    }
    
    
    @Override
    public void onBlockPlacedBy(World var1, int var2, int var3, int var4, EntityLiving var5)
    {
            int direction = 2;
            TileEntityAdvancedTinyChest par6 = (TileEntityAdvancedTinyChest)var1.getBlockTileEntity(var2, var3, var4);
            int facing = MathHelper.floor_double(var5.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;

            if (facing == 0) {
                direction = ForgeDirection.NORTH.ordinal();
            }
            else if (facing == 1) {
                direction = ForgeDirection.EAST.ordinal();
            }
            else if (facing == 2) {
                direction = ForgeDirection.SOUTH.ordinal();
            }
            else if (facing == 3) {
                direction = ForgeDirection.WEST.ordinal();
            }
            
            par6.setFacing(direction);              
        }
    
    @Override
    public boolean isBlockSolid(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
    {
        TileEntityAdvancedTinyChest tile = (TileEntityAdvancedTinyChest) par1IBlockAccess.getBlockTileEntity(par2, par3, par4);
        if(tile.isFull())return true;
        else return false;
    }
    
    public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3)
    {
            par3.add(new ItemStack(par1, 1, 0));
            par3.add(new ItemStack(par1, 1, 1));
            par3.add(new ItemStack(par1, 1, 2));
            par3.add(new ItemStack(par1, 1, 3));
            par3.add(new ItemStack(par1, 1, 4));
            par3.add(new ItemStack(par1, 1, 5));
            par3.add(new ItemStack(par1, 1, 6));
            par3.add(new ItemStack(par1, 1, 7));
            par3.add(new ItemStack(par1, 1, );
    }
    
    public boolean canProvidePower()
    {
        return true;
    }
   
    public boolean isProvidingStrongPower(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
    {
        return isPoweringTo(par1IBlockAccess, par2, par3, par4, par5);
    }
    
    public boolean isProvidingWeakPower(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
    {
        return isPoweringTo(par1IBlockAccess, par2, par3, par4, par5);
    }
    
    
    public boolean isPoweringTo(IBlockAccess par1, int par2, int par3, int par4, int par5)
    {
        TileEntityAdvancedTinyChest tile = (TileEntityAdvancedTinyChest)par1.getBlockTileEntity(par2, par3, par4);
        
        if(tile.isFull()) return par5 == 1;
        if(tile.isEmpty()) return par5 == 0;
        else return false;
        
    }
   



    
    public boolean onBlockActivated(World par1, int par2, int par3, int par4, EntityPlayer par5, int par6, float par7, float par8, float par9)
    {
        TileEntityAdvancedTinyChest tile = (TileEntityAdvancedTinyChest)par1.getBlockTileEntity(par2, par3, par4);
        
        if(par5.isSneaking())
        {
            if(par5.getCurrentEquippedItem() == null)
            {
                tile.setFacing(TinyFunctions.setNextFacing(tile.getFacing()));
                par1.markBlockForUpdate(par2, par3, par4);
                notifyNeighbors(par1, par2, par3, par4);
                par5.addExhaustion(3);
                return true;
            }
        }
        
        if(!par1.isRemote)
        {
            int meta = par1.getBlockMetadata(par2, par3, par4);
            int id = 0;
            if(meta == 0)id = tiny.advtinychestguieins;
            else if(meta == 1)id = tiny.advtinychestguizwei;
            else if(meta == 2)id = tiny.advtinychestguidrei;
               else if(meta == 3)id = tiny.advtinychestguivier;
               else if(meta == 4)id = tiny.advtinychestguifunf;
               else if(meta == 5)id = tiny.advtinychestguisechs;
               else if(meta == 6)id = tiny.advtinychestguisieben;
            else if(meta == 7)id = tiny.advtinychestguiacht;
            else if(meta == 8)id = tiny.advtinychestguineun;
            
            
            if(tile != null)
            {
                par5.openGui(TinyChest.instance, id, par1, par2, par3, par4);
                return true;
            }
                                    
        }
        return true;
        
    }
    


    @Override
    public TileEntity createNewTileEntity(World var1) 
    {
        return null;
    }
    
    public TileEntity createNewTileEntity(World var1, int meta)
    {
        if(meta == 0)
        {
            return new AdvancedTinyChestEins();
        }
        else if(meta == 1)
        {
            return new AdvancedTinyChestZwei();
        }
        else if(meta == 2)
        {
            return new AdvancedTinyChestDrei();
        }
        else if(meta == 3)
        {
            return new AdvancedTinyChestVier();
        }
        else if(meta == 4)
        {
            return new AdvancedTinyChestFunf();
        }
        else if(meta == 5)
        {
            return new AdvancedTinyChestSechs();
        }
        else if(meta == 6)
        {
            return new AdvancedTinyChestSieben();
        }
        else if(meta == 7)
        {
            return new AdvancedTinyChestAcht();
        }
        else if(meta == 
        {
            return new AdvancedTinyChestNeun();
        }

        
        return null;
    }
    
    
    public void updateTick(World world, int i, int j, int k, Random random)
    {
        notifyNeighbors(world, i, j, k);
        world.scheduleBlockUpdate(i, j, k, blockID, tickRate());
    }
    
    public void onBlockDestroyedByPlayer(World world, int i, int j, int k, int l)
    {
        notifyNeighbors(world, i, j, k);
    }
    
    public void notifyNeighbors(World world, int i, int j, int k)
    {
        world.notifyBlocksOfNeighborChange(i, j, k, blockID);
        world.notifyBlocksOfNeighborChange(i, j - 1, k, blockID);
        world.notifyBlocksOfNeighborChange(i, j + 1, k, blockID);
        world.notifyBlocksOfNeighborChange(i - 1, j, k, blockID);
        world.notifyBlocksOfNeighborChange(i + 1, j, k, blockID);
        world.notifyBlocksOfNeighborChange(i, j, k - 1, blockID);
        world.notifyBlocksOfNeighborChange(i, j, k + 1, blockID);
    }
    
    
    public void onBlockAdded(World world, int i, int j, int k)
    {        
        world.scheduleBlockUpdate(i, j, k, blockID, tickRate());
    }
    
    public int tickRate()
    {
        return TinyConfig.tickspeed;
    }


}

 

TileEntity:

package speiger.src.tinychest.common.tileentity.tinychest;

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.tileentity.TileEntity;

public abstract class TileEntityAdvancedTinyChest extends TileEntity implements IInventory
{
    private int inventorysize;
    private String inventoryName;
    private ItemStack[] advTinyChest;
    private int facing = 0;
    private boolean isFull = false;
    private boolean isEmpty = true;
    private boolean[] chestfulldetect = new boolean[9];
    private boolean[] chestemptydetect = new boolean[9];

    
    
    public TileEntityAdvancedTinyChest(String name, int par1) 
    {
        inventoryName = name;
        advTinyChest = new ItemStack[par1];
        inventorysize = par1;
    }

    public int getSizeInventory()
    {
        return this.advTinyChest.length;
    }

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

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

    public ItemStack getStackInSlot(int par1)
    {
        return this.advTinyChest[par1];
    }


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

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

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

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

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

    

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

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

    
    public String getInvName()
    {
        return inventoryName;
    }

    public int getInventoryStackLimit() 
    {
        return 64;
    }

    

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


    public void openChest() 
    {
    }

    
    public void readFromNBT(NBTTagCompound par1NBTTagCompound)
    {
        super.readFromNBT(par1NBTTagCompound);
        NBTTagList var2 = par1NBTTagCompound.getTagList("Items");
        this.advTinyChest = 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.advTinyChest.length)
            {
                this.advTinyChest[var5] = ItemStack.loadItemStackFromNBT(var4);
            }
        }
        this.facing = par1NBTTagCompound.getInteger("faceing");
        
    }

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

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

        par1NBTTagCompound.setTag("Items", var2);
        par1NBTTagCompound.setInteger("faceing", facing);
    }
    

    


    public boolean isFull()
    {
        return isFull;
    }
    
    public boolean isEmpty()
    {
        return isEmpty;
    }


    public void closeChest() 
    {
    }

    public void setFacing(int i)
    {
        facing = i;
    }
    
    
    public int getFacing()
    {
        return facing;
    }

    public void updateEntity()
    {
        for(int i = 0; i < getSizeInventory(); i++)
        {
            if (getStackInSlot(i) != null && getStackInSlot(i).stackSize == Math.min(getInventoryStackLimit(), getStackInSlot(i).getMaxStackSize())) 
            {
                this.chestfulldetect[i] = true;    
            }
            else chestfulldetect[i] = false;
            
            if(getStackInSlot(i) == null)
            {
                chestemptydetect[i] = true;
            }
            else
            {
                chestemptydetect[i] = false;
            }
        }
        
        if(inventorysize == 1)
        {
            if(chestfulldetect[0] == true)isFull = true;
            else isFull = false;
            if(chestemptydetect[0] == true)isEmpty = true;
            else isEmpty = false;
        }
        else if(inventorysize == 2)
        {
            if(chestfulldetect[0] == true && chestfulldetect[1] == true)isFull = true;
            else isFull = false;
            if(chestemptydetect[0] == true && chestemptydetect[1] == true)isEmpty = true;
            else isEmpty = false;
        }
        else if(inventorysize == 3)
        {
            if(chestfulldetect[0] == true && chestfulldetect[1] == true && chestfulldetect[2] == true)isFull = true;
            else isFull = false;
            if(chestemptydetect[0] == true && chestemptydetect[1] == true && chestemptydetect[2] == true)isEmpty = true;
            else isEmpty = false;
        }
        else if(inventorysize == 4)
        {
            if(chestfulldetect[0] == true && chestfulldetect[1] == true && chestfulldetect[2] == true && chestfulldetect[3] == true)isFull = true;
            else isFull = false;
            if(chestemptydetect[0] == true && chestemptydetect[1] == true && chestemptydetect[2] == true && chestemptydetect[3] == true)isEmpty = true;
            else isEmpty = false;
        }
        else if(inventorysize == 5)
        {
            if(chestfulldetect[0] == true && chestfulldetect[1] == true && chestfulldetect[2] == true && chestfulldetect[3] == true && chestfulldetect[4] == true)isFull = true;
            else isFull = false;
            if(chestemptydetect[0] == true && chestemptydetect[1] == true && chestemptydetect[2] == true && chestemptydetect[3] == true && chestemptydetect[4] == true)isEmpty = true;
            else isEmpty = false;
        }
        else if(inventorysize == 6)
        {
            if(chestfulldetect[0] == true && chestfulldetect[1] == true && chestfulldetect[2] == true && chestfulldetect[3] == true && chestfulldetect[4] == true && chestfulldetect[5] == true)isFull = true;
            else isFull = false;
            if(chestemptydetect[0] == true && chestemptydetect[1] == true && chestemptydetect[2] == true && chestemptydetect[3] == true && chestemptydetect[4] == true && chestemptydetect[5] == true)isEmpty = true;
            else isEmpty = false;
        }
        else if(inventorysize == 7)
        {
            if(chestfulldetect[0] == true && chestfulldetect[1] == true && chestfulldetect[2] == true && chestfulldetect[3] == true && chestfulldetect[4] == true && chestfulldetect[5] == true && chestfulldetect[6] == true)isFull = true;
            else isFull = false;
            if(chestemptydetect[0] == true && chestemptydetect[1] == true && chestemptydetect[2] == true && chestemptydetect[3] == true && chestemptydetect[4] == true && chestemptydetect[5] == true && chestemptydetect[6] == true)isEmpty = true;
            else isEmpty = false;
        }
        else if(inventorysize == 
        {
            if(chestfulldetect[0] == true && chestfulldetect[1] == true && chestfulldetect[2] == true && chestfulldetect[3] == true && chestfulldetect[4] == true && chestfulldetect[5] == true && chestfulldetect[6] == true && chestfulldetect[7] == true)isFull = true;
            else isFull = false;
            if(chestemptydetect[0] == true && chestemptydetect[1] == true && chestemptydetect[2] == true && chestemptydetect[3] == true && chestemptydetect[4] == true && chestemptydetect[5] == true && chestemptydetect[6] == true && chestemptydetect[7] == true)isEmpty = true;
            else isEmpty = false;
        }
        else if(inventorysize == 9)
        {
            if(chestfulldetect[0] == true && chestfulldetect[1] == true && chestfulldetect[2] == true && chestfulldetect[3] == true && chestfulldetect[4] == true && chestfulldetect[5] == true && chestfulldetect[6] == true && chestfulldetect[7] == true && chestfulldetect[8] == true)isFull = true;
            else isFull = false;
            if(chestemptydetect[0] == true && chestemptydetect[1] == true && chestemptydetect[2] == true && chestemptydetect[3] == true && chestemptydetect[4] == true && chestemptydetect[5] == true && chestemptydetect[6] == true && chestemptydetect[7] == true && chestemptydetect[8] == true)isEmpty = true;
            else isEmpty = false;
        }
        
    }

    public int getTexture(int side, int meta, int facing2) 
    {
        return 0;
    }

    
    
    
    
}

 

Renderring:

package speiger.src.tinychest.client.render;

import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;

import org.lwjgl.opengl.GL11;

import speiger.src.tinychest.client.models.ModelAdvancedTinyChest;
import speiger.src.tinychest.common.tileentity.tinychest.TileEntityAdvancedTinyChest;

public class RenderAdvancedTinyChest extends TileEntitySpecialRenderer {

    ModelAdvancedTinyChest model = new ModelAdvancedTinyChest();

    @Override
    public void renderTileEntityAt(TileEntity var1, double var2, double var4, double var6, float var8) 
    {
        renderChest((TileEntityAdvancedTinyChest)var1, var2, var4, var6, var8);

    }

    private void renderChest(TileEntityAdvancedTinyChest var1, double var2, double var4, double var6, float var8) 
    {
        GL11.glPushMatrix();
        GL11.glTranslatef((float) var2 + 0.5f, (float) var4 + 1.5f, (float) var6 + 0.5f);
        if(var1.isFull())
        {
            bindTextureByName("/speiger/src/tinychest/textures/models/ModelAdvancedTinyChestFull.png");
        }
        else
        {
            bindTextureByName("/speiger/src/tinychest/textures/models/ModelAdvancedTinyChest.png");
        }

        
        switch(var1.getFacing())
        {
            case 2: GL11.glRotatef(0, 0.0F, 1.0F, 0.0F); break; 
            case 3: GL11.glRotatef(180, 0.0F, 1.0F, 0.0F); break;
            case 4: GL11.glRotatef(90, 0.0F, 1.0F, 0.0F); break;
            case 5: GL11.glRotatef(270, 0.0F, 1.0F, 0.0F); break;
        }
        

        
        GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
        model.render(0.0625F);
        GL11.glPopMatrix();
        
    }

}

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

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

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