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.



×
×
  • Create New...

Important Information

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