Jump to content

[Resolved][1.5.2] TileEntity container not doing anything upon right click


Rockdude48

Recommended Posts

So in my friend and I's mod there is this machine that acts sort of like a crafting table but just for our mod items. Problem is it doesn't do anything upon a right click:

 

 

BlockScientificAssembler.java

 

 

 

package mods.minecraft.darth.dc.block;

import java.util.Random;

import mods.minecraft.darth.dc.DiscoveryCraft;
import mods.minecraft.darth.dc.lib.GuiIDs;
import mods.minecraft.darth.dc.tileentity.TileScientificAssembler;
import net.minecraft.block.material.Material;
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.world.World;

public class BlockScientificAssembler extends BlockDC
{
    private Random rand = new Random();

    public BlockScientificAssembler(int id)
    {
        super(id, Material.rock);
        this.setResistance(30)
            .setHardness(2)
            .setStepSound(soundAnvilFootstep);
    }
    
    @Override
    public TileEntity createNewTileEntity(World world)
    {
        return new TileScientificAssembler();
    }

    @Override
    public void breakBlock(World world, int x, int y, int z, int id, int meta)
    {
        dropInventory(world, x, y, z);
        super.breakBlock(world, x, y, z, id, meta);
    }
    
    @Override
    public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9)
    {
        if (player.isSneaking())
            return false;
        else
        {
            if (!world.isRemote)
            {
                TileScientificAssembler tile = (TileScientificAssembler) world.getBlockTileEntity(x, y, z);

                if (tile != null){
                	
                    player.openGui(DiscoveryCraft.instance, GuiIDs.ASSEMBLER1, world, x, y, z);
                    System.out.println(tile.toString());
                }
            }

            return true;
        }
    }

    
    private void dropInventory(World world, int x, int y, int z)
    {
        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.getEntityItem().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;
            }
        }

    }

}

 

 

 

 

TileScientificAssembler.java

 

 

 


package mods.minecraft.darth.dc.tileentity;

import mods.minecraft.darth.dc.lib.Strings;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;

public class TileScientificAssembler extends TileDC implements IInventory
{

    public ItemStack[] inventory;
    
    public static final int INVENTORY_SIZE = 9 /*Crafting Grid*/ + 1 /*Output Slot*/ + (1 * 9) /*Storage*/;
    
    public TileScientificAssembler()
    {
        inventory = new ItemStack[iNVENTORY_SIZE];
    }
    
    @Override
    public int getSizeInventory()
    {
        return inventory.length;
    }

    @Override
    public ItemStack getStackInSlot(int slot)
    {
        return inventory[slot];
    }

    @Override
    public ItemStack decrStackSize(int slot, int amount)
    {
        ItemStack itemStack = getStackInSlot(slot);
        
        if (itemStack != null)
        {
            if (itemStack.stackSize <= amount)
            {
                setInventorySlotContents(slot, null);
            }
            else
            {
                itemStack = itemStack.splitStack(amount);
                setInventorySlotContents(slot, null);
            }
        }
        
        return itemStack;
    }

    @Override
    public ItemStack getStackInSlotOnClosing(int slot)
    {
        ItemStack itemStack = getStackInSlot(slot);
        
        if (itemStack != null)
            setInventorySlotContents(slot, null);
        
        return itemStack;
    }

    @Override
    public void setInventorySlotContents(int slot, ItemStack itemStack)
    {
        inventory[slot] = itemStack;
        
        if (itemStack != null && itemStack.stackSize > getInventoryStackLimit())
            itemStack.stackSize = getInventoryStackLimit();
    }

    @Override
    public String getInvName()
    {
        return this.hasCustomName() ? this.getCustomName() : Strings.CONTAINER_SCI_ASSEMBLER_NAME;
    }

    @Override
    public boolean isInvNameLocalized()
    {
        return this.hasCustomName();
    }

    @Override
    public int getInventoryStackLimit()
    {
        return 64;
    }

    @Override
    public void openChest()
    {
    }

    @Override
    public void closeChest()
    {      
    }

    @Override
    public boolean isStackValidForSlot(int i, ItemStack itemstack)
    {
        return true;
    }
    
    @Override
    public String toString()
    {
        StringBuilder s = new StringBuilder();
        s.append(super.toString());
        s.append("TileScientificAssembler Data - ");
        
        return s.toString();
    }
    
    @Override
    public void readFromNBT(NBTTagCompound tagCompound) {
            super.readFromNBT(tagCompound);
            
            NBTTagList tagList = tagCompound.getTagList("Inventory");
            for (int i = 0; i < tagList.tagCount(); i++) {
                    NBTTagCompound tag = (NBTTagCompound) tagList.tagAt(i);
                    byte slot = tag.getByte("Slot");
                    if (slot >= 0 && slot < inventory.length) {
                            inventory[slot] = ItemStack.loadItemStackFromNBT(tag);
                    }
            }
    }
    @Override
    public void writeToNBT(NBTTagCompound tagCompound) {
            super.writeToNBT(tagCompound);
                            
            NBTTagList itemList = new NBTTagList();
            for (int i = 0; i < inventory.length; i++) {
                    ItemStack stack = inventory[i];
                    if (stack != null) {
                            NBTTagCompound tag = new NBTTagCompound();
                            tag.setByte("Slot", (byte) i);
                            stack.writeToNBT(tag);
                            itemList.appendTag(tag);
                    }
            }
            tagCompound.setTag("Inventory", itemList);
    }
    

}

 

 

ContainerScientificAssembler.java

 

 

package mods.minecraft.darth.dc.tileentity;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;

public class ContainerScientificAssembler extends Container{
protected TileScientificAssembler tileEntity;
private int sn = 0;
    public ContainerScientificAssembler (InventoryPlayer inventoryPlayer, TileScientificAssembler te){
        tileEntity = te;

        //the Slot constructor takes the IInventory and the slot number in that it binds to
        //and the x-y coordinates it resides on-screen
        
        //crafting grid
        for (int x = 0; x < 3; x++) {
                for (int y = 0; y < 3; y++) {
                		
                        addSlotToContainer(new Slot(tileEntity, sn, 30 + x * 18, 17 + y * 18));
                        sn++;
                }
        }
        //bottom inventory
        for(int x = 0; x < 9; x++){
        	addSlotToContainer(new Slot(tileEntity, sn, 8 + x * 18, 82));
        	sn++;
        }
        
        //result
        	addSlotToContainer(new Slot(tileEntity, sn, 124, 35));
        	sn++;

        //commonly used vanilla code that adds the player's inventory
        bindPlayerInventory(inventoryPlayer);
    }
    protected void bindPlayerInventory(InventoryPlayer inventoryPlayer) {
        for (int i = 0; i < 3; i++) {
                for (int j = 0; j < 9; j++) {
                        addSlotToContainer(new Slot(inventoryPlayer, sn,
                                        8 + j * 18, 111 + i * 18));
                        sn++;
                }
        }

        for (int i = 0; i < 9; i++) {
                addSlotToContainer(new Slot(inventoryPlayer, sn, 8 + i * 18, 169));
                sn++;
        }
}
@Override
public boolean canInteractWith(EntityPlayer entityplayer) {

	return tileEntity.isUseableByPlayer(entityplayer);
}

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

        //null checks and checks if the item can be stacked (maxStackSize > 1)
        if (slotObject != null && slotObject.getHasStack()) {
                ItemStack stackInSlot = slotObject.getStack();
                stack = stackInSlot.copy();

                //merges the item into player inventory since its in the tileEntity
                if (slot < tileEntity.INVENTORY_SIZE) {
                        if (!this.mergeItemStack(stackInSlot, 0, 35, true)) {
                                return null;
                        }
                }
                //places it into the tileEntity is possible since its in the player inventory
                else if (!this.mergeItemStack(stackInSlot, 0, tileEntity.INVENTORY_SIZE, 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;
}

}

 

 

GuiScientificAssembler.java

 

 

package mods.minecraft.darth.dc.tileentity;

import org.lwjgl.opengl.GL11;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

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

public class GuiScientificAssembler extends GuiContainer{

public GuiScientificAssembler(InventoryPlayer inventoryPlayer, TileScientificAssembler tileEntity) {
    
        	//the container is instanciated and passed to the superclass for handling
        	super(new ContainerScientificAssembler(inventoryPlayer, tileEntity));

}
@Override
    protected void drawGuiContainerForegroundLayer(int param1, int param2) {
        //draw text and stuff here
        //the parameters for drawString are: string, x, y, color
        fontRenderer.drawString("Scientific Assembler", 8, 6, 4210752);
        //draws "Inventory" or your regional equivalent
        fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 8, ySize - 96 + 2, 4210752);
}
@Override
protected void drawGuiContainerBackgroundLayer(float f, int i, int j) {
        //draw your Gui here, only thing you need to change is the path
        
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        this.mc.renderEngine.bindTexture("DC:SAInventory");
        int x = (width - xSize) / 2;
        int y = (height - ySize) / 2;
        this.drawTexturedModalRect(x, y, 0, 0, xSize, ySize);

}


}

 

 

GuiHandler.java

 

 

package mods.minecraft.darth.dc.tileentity;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import cpw.mods.fml.common.network.IGuiHandler;

public class GuiHandler implements IGuiHandler {
    //returns an instance of the Container you made earlier
    @Override
    public Object getServerGuiElement(int id, EntityPlayer player, World world,
                    int x, int y, int z) {
            TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
            System.out.println("THECODEWASCALLED");
            if(tileEntity instanceof TileScientificAssembler){
                    return new ContainerScientificAssembler(player.inventory, (TileScientificAssembler) tileEntity);
            }
            return null;
    }

    //returns an instance of the Gui you made earlier
    @Override
    public Object getClientGuiElement(int id, EntityPlayer player, World world,
                    int x, int y, int z) {
            TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
            System.out.println("THECODEWASCALLED");
            if(tileEntity instanceof TileScientificAssembler){
            	System.out.println("isTileSA");
                    return new GuiScientificAssembler(player.inventory, (TileScientificAssembler) tileEntity);
                    
            }
            return null;

    }
}
[code]
[/spoiler]
main mod class
[spoiler]
[code]
package mods.minecraft.darth.dc;


import java.io.File;

import net.minecraft.creativetab.CreativeTabs;

import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.FingerprintWarning;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.Mod.PostInit;
import cpw.mods.fml.common.Mod.PreInit;
import cpw.mods.fml.common.Mod.ServerStarting;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLFingerprintViolationEvent;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry;

import mods.minecraft.darth.dc.block.ModBlocks;
import mods.minecraft.darth.dc.command.CommandHandler;
import mods.minecraft.darth.dc.configuration.ConfigHandler;
import mods.minecraft.darth.dc.core.handlers.AddonHandler;
import mods.minecraft.darth.dc.core.handlers.FuelHandler;
import mods.minecraft.darth.dc.core.handlers.LocalizationHandler;
import mods.minecraft.darth.dc.core.proxy.CommonProxy;
import mods.minecraft.darth.dc.core.util.LogUtil;
import mods.minecraft.darth.dc.creativetabs.CreativeTabDC;
import mods.minecraft.darth.dc.event.EventRegistry;
import mods.minecraft.darth.dc.item.ModItems;
import mods.minecraft.darth.dc.lib.Reference;
import mods.minecraft.darth.dc.lib.Strings;
import mods.minecraft.darth.dc.network.PacketHandler;
import mods.minecraft.darth.dc.recipe.ModRecipes;
import mods.minecraft.darth.dc.tileentity.GuiHandler;
import mods.minecraft.darth.dc.world.WorldInit;


/**
* DiscoveryCraft
* 
* @author Darth_Feder Rockdude48
* 
* 
*/


@Mod(modid = Reference.MOD_ID, name = Reference.MOD_NAME, version = Reference.VERSION, dependencies = Reference.DEPENDENCIES, acceptedMinecraftVersions = Reference.MC_VERSIONS, modExclusionList = Reference.EXCLUSION_MODS)
@NetworkMod(channels = {Reference.CHANNEL_NAME}, clientSideRequired = true, serverSideRequired = false, packetHandler = PacketHandler.class)
public class DiscoveryCraft
{

        @Instance(Reference.MOD_ID)
        public static DiscoveryCraft instance;
        
        @SidedProxy(clientSide = Reference.CLIENT_PROXY_CLASS, serverSide = Reference.SERVER_PROXY_CLASS)
        public static CommonProxy proxy;
        
        
        public static CreativeTabs tabDC = new CreativeTabDC(Reference.MOD_ID);

        
        @FingerprintWarning
        public void invalidFingerprint(FMLFingerprintViolationEvent event)
        {
            LogUtil.severe(Strings.INVALID_FINGERPRINT_WARNING);
        }
        
        
        @ServerStarting
        public void serverStarting(FMLServerStartingEvent event)
        {
            
            //Initialize Commands
            CommandHandler.initCommands(event);
            
        }
        
        
        @PreInit
        public void preInit(FMLPreInitializationEvent event)
        {
            //Some gui stuff
        	NetworkRegistry.instance().registerGuiHandler(this, new GuiHandler());
        	
            //Register Logger
            LogUtil.init();
            
            //Load Language Localization Files
            LocalizationHandler.loadLanguages();
            
            //Load the Configuration File
            ConfigHandler.init(new File(event.getModConfigurationDirectory().getAbsolutePath() + File.separator + Reference.MOD_NAME + ".cfg"));
            
            //Register Key Bindings (Client-Side)
            //proxy.registerKeyBindingHandler();
            
            //Register Sound Handler (Client-Side)
            proxy.registerSoundHandler();
            
            //Initialize Blocks
            ModBlocks.init();
            
            //Initialize Items
            ModItems.init();
            
            //Initialize Mod Recipes
            ModRecipes.init();
            
        }
    
    
        @Init
        public void load(FMLInitializationEvent event)
        {
            
            //Register World Additions
            WorldInit.init();
            
            //Register the GUI Handler
            NetworkRegistry.instance().registerGuiHandler(instance, proxy);
            
            //Register Tile Entities
            proxy.registerTileEntities();
            
            //Register Events
            EventRegistry.init();
            
            //Register Fuel Handler
            GameRegistry.registerFuelHandler(new FuelHandler());
            
        }
        
        
        @PostInit
        public void postInit(FMLPostInitializationEvent event)
        {

            //Initialize Mod Addons
            AddonHandler.init();
            
        }
    
}

 

 

 

Right now we just want to get the block into an inventory, then do all the crafting logic.

If it helps I'll be commiting all of this stuff to our GitHub repository. https://github.com/DarthFeder/DiscoveryCraft

Also, there are no errors that I can see, it just doesn't do anything upon a right click of the block. and I have checked that it is a tile entity by pushing it with a piston, it checks out.

 

Edit: Sorry forgot to add the main class:

 

 

 

package mods.minecraft.darth.dc;


import java.io.File;

import net.minecraft.creativetab.CreativeTabs;

import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.FingerprintWarning;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.Mod.PostInit;
import cpw.mods.fml.common.Mod.PreInit;
import cpw.mods.fml.common.Mod.ServerStarting;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLFingerprintViolationEvent;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry;

import mods.minecraft.darth.dc.block.ModBlocks;
import mods.minecraft.darth.dc.command.CommandHandler;
import mods.minecraft.darth.dc.configuration.ConfigHandler;
import mods.minecraft.darth.dc.core.handlers.AddonHandler;
import mods.minecraft.darth.dc.core.handlers.FuelHandler;
import mods.minecraft.darth.dc.core.handlers.LocalizationHandler;
import mods.minecraft.darth.dc.core.proxy.CommonProxy;
import mods.minecraft.darth.dc.core.util.LogUtil;
import mods.minecraft.darth.dc.creativetabs.CreativeTabDC;
import mods.minecraft.darth.dc.event.EventRegistry;
import mods.minecraft.darth.dc.item.ModItems;
import mods.minecraft.darth.dc.lib.Reference;
import mods.minecraft.darth.dc.lib.Strings;
import mods.minecraft.darth.dc.network.PacketHandler;
import mods.minecraft.darth.dc.recipe.ModRecipes;
import mods.minecraft.darth.dc.tileentity.GuiHandler;
import mods.minecraft.darth.dc.world.WorldInit;


/**
* DiscoveryCraft
* 
* @author Darth_Feder
* 
* 
*/


@Mod(modid = Reference.MOD_ID, name = Reference.MOD_NAME, version = Reference.VERSION, dependencies = Reference.DEPENDENCIES, acceptedMinecraftVersions = Reference.MC_VERSIONS, modExclusionList = Reference.EXCLUSION_MODS)
@NetworkMod(channels = {Reference.CHANNEL_NAME}, clientSideRequired = true, serverSideRequired = false, packetHandler = PacketHandler.class)
public class DiscoveryCraft
{

        @Instance(Reference.MOD_ID)
        public static DiscoveryCraft instance;
        
        @SidedProxy(clientSide = Reference.CLIENT_PROXY_CLASS, serverSide = Reference.SERVER_PROXY_CLASS)
        public static CommonProxy proxy;
        
        
        public static CreativeTabs tabDC = new CreativeTabDC(Reference.MOD_ID);

        
        @FingerprintWarning
        public void invalidFingerprint(FMLFingerprintViolationEvent event)
        {
            LogUtil.severe(Strings.INVALID_FINGERPRINT_WARNING);
        }
        
        
        @ServerStarting
        public void serverStarting(FMLServerStartingEvent event)
        {
            
            //Initialize Commands
            CommandHandler.initCommands(event);
            
        }
        
        
        @PreInit
        public void preInit(FMLPreInitializationEvent event)
        {
            //Some gui stuff
        	NetworkRegistry.instance().registerGuiHandler(this, new GuiHandler());
        	
            //Register Logger
            LogUtil.init();
            
            //Load Language Localization Files
            LocalizationHandler.loadLanguages();
            
            //Load the Configuration File
            ConfigHandler.init(new File(event.getModConfigurationDirectory().getAbsolutePath() + File.separator + Reference.MOD_NAME + ".cfg"));
            
            //Register Key Bindings (Client-Side)
            //proxy.registerKeyBindingHandler();
            
            //Register Sound Handler (Client-Side)
            proxy.registerSoundHandler();
            
            //Initialize Blocks
            ModBlocks.init();
            
            //Initialize Items
            ModItems.init();
            
            //Initialize Mod Recipes
            ModRecipes.init();
            
        }
    
    
        @Init
        public void load(FMLInitializationEvent event)
        {
            
            //Register World Additions
            WorldInit.init();
            
            //Register the GUI Handler
            NetworkRegistry.instance().registerGuiHandler(instance, proxy);
            
            //Register Tile Entities
            proxy.registerTileEntities();
            
            //Register Events
            EventRegistry.init();
            
            //Register Fuel Handler
            GameRegistry.registerFuelHandler(new FuelHandler());
            
        }
        
        
        @PostInit
        public void postInit(FMLPostInitializationEvent event)
        {

            //Initialize Mod Addons
            AddonHandler.init();
            
        }
    
}


 

 

 

Link to comment
Share on other sites

I found an error: 2013-07-23 22:58:39 [sEVERE] [ForgeModLoader] A TileEntity type mods.minecraft.darth.dc.tileentity.TileScientificAssembler has throw an exception trying to write state. It will not persist. Report this to the mod author

java.lang.RuntimeException: class mods.minecraft.darth.dc.tileentity.TileScientificAssembler is missing a mapping! This is a bug!

at net.minecraft.tileentity.TileEntity.writeToNBT(TileEntity.java:105)

at mods.minecraft.darth.dc.tileentity.TileScientificAssembler.writeToNBT(TileScientificAssembler.java:133)

at net.minecraft.world.chunk.storage.AnvilChunkLoader.writeChunkToNBT(AnvilChunkLoader.java:316)

at net.minecraft.world.chunk.storage.AnvilChunkLoader.saveChunk(AnvilChunkLoader.java:127)

at net.minecraft.world.gen.ChunkProviderServer.safeSaveChunk(ChunkProviderServer.java:232)

at net.minecraft.world.gen.ChunkProviderServer.saveChunks(ChunkProviderServer.java:284)

at net.minecraft.world.WorldServer.saveAllChunks(WorldServer.java:906)

at net.minecraft.server.MinecraftServer.saveAllWorlds(MinecraftServer.java:345)

at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:577)

at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:127)

at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:469)

at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:16)

 

Link to comment
Share on other sites

Thought TileDC.java would be good

 

 

package mods.minecraft.darth.dc.tileentity;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;

public class TileDC extends TileEntity
{

    private ForgeDirection orientation;
    private byte state;
    private String customName;
    
    public TileDC()
    {
        
        state = 0;
        customName = "";
        
    }
    
    public ForgeDirection getOrientation()
    {
        return orientation;
    }
    
    public void setOrientation(ForgeDirection orientation)
    {
        this.orientation = orientation;
    }
    
    public void setOrientation(int orientation)
    {
        this.orientation = ForgeDirection.getOrientation(orientation);
    }

    public short getState()
    {
        return state;
    }
    
    public void setState(byte state)
    {
        this.state = state;
    }


    public boolean hasCustomName()
    {
        return customName != null && customName.length() > 0;
    }


    public String getCustomName()
    {
        return customName;
    }


    public void setCustomName(String customName)
    {
        this.customName = customName;
    }


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

    public String toString()
    {
        StringBuilder s = new StringBuilder();
        
        s.append(String.format("TileDC Data - xCoord: %d, yCoord: %d, zCoord: %d, customName: '%s', orientation: %s, state: %d\n", xCoord, yCoord, zCoord, customName, orientation, state));
        
        return s.toString();
    }
    static{
    	addMapping(TileScientificAssembler.class,"Scientific Assembler");
    }
}

 

 

 

And BlockDC.java

 

 

 

package mods.minecraft.darth.dc.block;


import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

import mods.minecraft.darth.dc.lib.Reference;
import mods.minecraft.darth.dc.tileentity.TileDC;

import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.EntityLiving;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;


public class BlockDC extends BlockContainer
{

    public BlockDC(int id, Material material)
    {
        super(id, material);
    }
    
    
    @Override
    @SideOnly(Side.CLIENT)
    public void registerIcons(IconRegister iconRegister)
    {
        blockIcon = iconRegister.registerIcon(Reference.MOD_ID.toLowerCase() + ":" + this.getUnlocalizedName2());
    }

    
    //Sets the direction of the block when placed
    @Override
    public void onBlockPlacedBy(World world, int x, int y, int z, EntityLiving entityLiving, ItemStack itemStack)
    {
        int direction = 0;
        int facing = MathHelper.floor_double(entityLiving.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;


        switch (facing)
        {
            case 0:
                direction = ForgeDirection.NORTH.ordinal();
                break;
                
            case 1:
                direction = ForgeDirection.EAST.ordinal();
                break;
                
            case 2:
                direction = ForgeDirection.SOUTH.ordinal();
                break;
                
            case 3:
                direction = ForgeDirection.WEST.ordinal();
                break;
                
        };


        world.setBlockMetadataWithNotify(x, y, z, direction, 3);

        
        if (itemStack.hasDisplayName())
        {
            ((TileDC) world.getBlockTileEntity(x, y, z)).setCustomName(itemStack.getDisplayName());
        }
        
        ((TileDC) world.getBlockTileEntity(x, y, z)).setOrientation(direction);
        
    }


    @Override
    public TileEntity createNewTileEntity(World world)
    {
        return null;
    }


}

 

 

 

if you need any more classes check out the repo.

 

 

Link to comment
Share on other sites

if (!world.isRemote)
            {
                TileScientificAssembler tile = (TileScientificAssembler) world.getBlockTileEntity(x, y, z);

                if (tile != null){
                	
                    player.openGui(DiscoveryCraft.instance, GuiIDs.ASSEMBLER1, world, x, y, z);
                    System.out.println(tile.toString());
                }
            }

 

btw this says that the gui will only be opened server side

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

Alright, I figured out why it wasn't doing anything, but now I have a crash that is stumping me.

 

---- Minecraft Crash Report ----
// Shall we play a game?

Time: 7/24/13 3:19 PM
Description: Ticking memory connection

java.lang.ArrayIndexOutOfBoundsException: 4
at net.minecraft.entity.player.InventoryPlayer.getStackInSlot(InventoryPlayer.java:635)
at net.minecraft.inventory.Slot.getStack(Slot.java:88)
at net.minecraft.inventory.Container.getInventory(Container.java:68)
at net.minecraft.inventory.Container.addCraftingToCrafters(Container.java:54)
at cpw.mods.fml.common.network.NetworkRegistry.openRemoteGui(NetworkRegistry.java:321)
at cpw.mods.fml.common.network.FMLNetworkHandler.openGui(FMLNetworkHandler.java:347)
at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2396)
at mods.minecraft.darth.dc.block.BlockScientificAssembler.onBlockActivated(BlockScientificAssembler.java:84)
at net.minecraft.item.ItemInWorldManager.activateBlockOrUseItem(ItemInWorldManager.java:412)
at net.minecraft.network.NetServerHandler.handlePlace(NetServerHandler.java:553)
at net.minecraft.network.packet.Packet15Place.processPacket(Packet15Place.java:79)
at net.minecraft.network.MemoryConnection.processReadPackets(MemoryConnection.java:89)
at net.minecraft.network.NetServerHandler.networkTick(NetServerHandler.java:134)
at net.minecraft.network.NetworkListenThread.networkTick(NetworkListenThread.java:53)
at net.minecraft.server.integrated.IntegratedServerListenThread.networkTick(IntegratedServerListenThread.java:109)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:675)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:571)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:127)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:469)
at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:16)


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

-- System Details --
Details:
Minecraft Version: 1.5.2
Operating System: Windows 7 (amd64) version 6.1
Java Version: 1.7.0_15, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 356614072 bytes (340 MB) / 457244672 bytes (436 MB) up to 3806593024 bytes (3630 MB)
JVM Flags: 0 total; 
AABB Pool Size: 3814 (213584 bytes; 0 MB) allocated, 3699 (207144 bytes; 0 MB) used
Suspicious classes: FML and Forge are installed
IntCache: cache: 0, tcache: 0, allocated: 1, tallocated: 63
FML: MCP v7.51 FML v5.2.6.696 Minecraft Forge 7.8.0.696 5 mods loaded, 5 mods active
mcp{7.44} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
FML{5.2.6.696} [Forge Mod Loader] (coremods) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Forge{7.8.0.696} [Minecraft Forge] (coremods) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
CC{pralpha1} [CookingCraft] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
DC{pre1} [DiscoveryCraft] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Profiler Position: N/A (disabled)
Vec3 Pool Size: 1216 (68096 bytes; 0 MB) allocated, 1052 (58912 bytes; 0 MB) used
Player Count: 1 / 8; [EntityPlayerMP['Player703'/297, l='Test World', x=41.35, y=72.00, z=325.34]]
Type: Integrated Server (map_client.txt)
Is Modded: Definitely; Client brand changed to 'fml,forge'

 

you can see full changes I made at the github repo

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

    • 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 
    • When I came across the 'Exit Code: I got a 1 error in my Minecraft mods, so I decided to figure out what was wrong. First, I took a look at the logs. In the mods folder (usually where you'd find logs or crash reports), I found the latest.log file or the corresponding crash report. I read it through carefully, looking for any lines with errors or warnings. Then I checked the Minecraft Forge support site, where you can often find info on what causes errors and how to fix them. I then disabled half of my mods and tried running the game. If the error disappeared, it meant that the problem was with the disabled mod. I repeated this several times to find the problem mod.
  • Topics

×
×
  • Create New...

Important Information

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