gravitythief Posted October 30, 2012 Posted October 30, 2012 i have a block that spawns in an item into an item slot in a gui. it works fine with the integrated server as well as with lan servers, but when i put it on an actual server, i can no longer drag items around my inventory while the GUI is open, nor will the item spawn in. Not sure why this happens. Main Mod class: package net.mrblockplacer.JM.CuisineMod; import java.io.File; import java.net.URISyntaxException; import java.util.Random; import net.mrblockplacer.JM.CuisineMod.WorldGenAnything; import net.minecraft.client.Minecraft; import net.minecraft.src.Block; import net.minecraft.src.Item; import net.minecraft.src.ItemStack; import net.minecraft.src.RenderEngine; import net.minecraft.src.RenderGlobal; import net.minecraft.src.World; import net.minecraft.src.WorldGenMinable; import net.minecraftforge.common.Configuration; import net.minecraftforge.common.ForgeHooks; import net.minecraftforge.common.MinecraftForge; import cpw.mods.fml.client.registry.RenderingRegistry; import cpw.mods.fml.common.Mod; 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.SidedProxy; 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.network.NetworkMod; import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.LanguageRegistry; @Mod(modid = "CuisineMod", name = "Cuisine Mod", version = "0.1.0.1") @NetworkMod(clientSideRequired = true, serverSideRequired = false, versionBounds = "0.1.0" ) public class CuisineMod { public static WorldGenAnything worldgen = new WorldGenAnything(); public static CommonProxy guihandler = new CommonProxy(); public static Block saltslab = new BlockSaltSlab(200); public static Block saltblock = new BlockSalt(201); public static Block saltcollectorblock = new BlockSaltCollector(202); public static Block goldLog = new BlockGoldLog(203).setBlockName("GoldLog"); public static Block goldLeaf = new BlockGoldLeaf(204, 4).setBlockName("GoldLeaf"); public static Block goldSapling = new BlockGoldSapling(205, 7).setBlockName("GoldSapling"); public static Block goldgrass = new BlockGoldGrass(206,2).setBlockName("GoldGrass").setStepSound(Block.soundGrassFootstep); public static Item salt = new ItemMaterials(5000, 0, "salt"); public static Item pepper = new ItemMaterials(5001, 1, "pepper"); public static Item filter = new ItemFilter(5002); public static Item lambmeatraw = new ItemModFood(5003, 2, 0.2F, true, 32, 4, "lambmeatraw"); public static Item lambmeatcooked = new ItemModFood(5004, 6, 0.6F, false, 32, 5, "lambmeatcooked"); public static Item goldseeds = new ItemMaterials(5005, 3, "goldseeds;"); public static Item peppercorns = new ItemMaterials(5006, 6, "peppercorns"); @Instance public static CuisineMod instance; @SidedProxy(clientSide = "net.mrblockplacer.JM.CuisineMod.ClientProxy", serverSide = "net.mrblockplacer.JM.CuisineMod.CommonProxy") public static CommonProxy proxy; @PreInit public void preInitializationEvent(FMLPreInitializationEvent event) {} @Init public void loadEvent(FMLInitializationEvent event) { LanguageRegistry.addName(saltslab, "Salt Slab"); GameRegistry.registerBlock(saltslab); LanguageRegistry.addName(saltblock, "Salt Block"); GameRegistry.registerBlock(saltblock); LanguageRegistry.addName(saltcollectorblock, "Salt Collector"); GameRegistry.registerBlock(saltcollectorblock); LanguageRegistry.addName(goldLog, "Golden Log"); GameRegistry.registerBlock(goldLog); LanguageRegistry.addName(goldLeaf, "Golden Leaves"); GameRegistry.registerBlock(goldLeaf); LanguageRegistry.addName(goldSapling, "Golden Sapling"); GameRegistry.registerBlock(goldSapling); LanguageRegistry.addName(goldgrass, "Golden Grass"); GameRegistry.registerBlock(goldgrass); GameRegistry.registerTileEntity(TileEntitySaltCollector.class, "TESaltCollector"); NetworkRegistry.instance().registerGuiHandler(this, guihandler); GameRegistry.registerWorldGenerator(worldgen); MinecraftForge.EVENT_BUS.register(new EventListener()); LanguageRegistry.addName(salt, "Salt"); LanguageRegistry.addName(pepper, "Pepper"); LanguageRegistry.addName(filter, "Filter"); LanguageRegistry.addName(lambmeatraw, "Raw Lambmeat"); LanguageRegistry.addName(lambmeatcooked, "Cooked Lambmeat"); LanguageRegistry.addName(peppercorns, "Peppercorns"); LanguageRegistry.addName(goldseeds, "Golden Seeds"); ItemStack saltstack = new ItemStack(salt); ItemStack saltblockstack = new ItemStack(saltblock); ItemStack filterstack = new ItemStack(filter); ItemStack stickstack = new ItemStack(Item.stick); ItemStack stringstack = new ItemStack(Item.silk); ItemStack woolstack = new ItemStack(Block.cloth); ItemStack plankstack = new ItemStack(Block.planks); ItemStack saltcollectorblockstack = new ItemStack(saltcollectorblock); ItemStack cheststack = new ItemStack(Block.chest); GameRegistry.addRecipe(saltblockstack, new Object[] { "xxx", "xxx", "xxx", Character.valueOf('x'), saltstack }); GameRegistry.addRecipe(filterstack, new Object[] { "xyx", "yzy", "xyx", Character.valueOf('x'), stickstack, Character.valueOf('y'), stringstack, Character.valueOf('z'), woolstack }); GameRegistry.addRecipe(filterstack, new Object[] { "xyx", "yzy", "xyx", Character.valueOf('y'), stickstack, Character.valueOf('x'), stringstack, Character.valueOf('z'), woolstack }); GameRegistry.addRecipe(saltcollectorblockstack, new Object[] { "xyx", "yzy", "xyx", 'x', plankstack, 'y', filterstack, 'z', cheststack }); GameRegistry.addShapelessRecipe(new ItemStack(salt, 9), saltblockstack); GameRegistry.addSmelting(lambmeatraw.shiftedIndex, new ItemStack(lambmeatcooked), 0F); } @PostInit public void postInitializationEvent(FMLPostInitializationEvent event) {} } Block: package net.mrblockplacer.JM.CuisineMod; import java.util.Random; import javax.jws.Oneway; import cpw.mods.fml.common.Side; import cpw.mods.fml.common.asm.SideOnly; import net.minecraft.src.BiomeGenBase; import net.minecraft.src.Block; import net.minecraft.src.BlockContainer; import net.minecraft.src.CreativeTabs; import net.minecraft.src.Entity; import net.minecraft.src.EntityItem; import net.minecraft.src.EntityPlayer; import net.minecraft.src.IInventory; import net.minecraft.src.ItemStack; import net.minecraft.src.Material; import net.minecraft.src.NBTTagCompound; import net.minecraft.src.TileEntity; import net.minecraft.src.World; public class BlockSaltCollector extends BlockContainer { public int SurroundingWater; public BlockSaltCollector(int par1) { super(par1, Material.wood); this.setCreativeTab(CreativeTabs.tabDecorations); setBlockName("saltcollectorblock"); setStepSound(soundWoodFootstep); blockIndexInTexture = 1; } public String getTextureFile() { return CommonProxy.BLOCKS; } public void onBlockAdded(World par1World, int par2, int par3, int par4) { onNeighborBlockChange(par1World, par2, par3, par4, 0); TileEntity tileEntity = par1World.getBlockTileEntity(par2, par3, par4); TileEntitySaltCollector tileEntitySC = (TileEntitySaltCollector) tileEntity; tileEntitySC.startTimeLeft(); } public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5) { int countwater = 0; TileEntity tileEntity = par1World.getBlockTileEntity(par2, par3, par4); TileEntitySaltCollector tileEntitySC = (TileEntitySaltCollector) tileEntity; BiomeGenBase b = par1World.getBiomeGenForCoords(par2, par4); if (b.biomeName == BiomeGenBase.ocean.biomeName || b.biomeName == BiomeGenBase.river.biomeName) { if (par1World.getBlockId(par2, par3, par4 + 1) == Block.waterMoving.blockID || par1World.getBlockId(par2, par3, par4 + 1) == Block.waterStill.blockID) { ++countwater; } if (par1World.getBlockId(par2 + 1, par3, par4) == Block.waterMoving.blockID || par1World.getBlockId(par2 + 1, par3, par4) == Block.waterStill.blockID) { ++countwater; } if (par1World.getBlockId(par2 - 1, par3, par4) == Block.waterMoving.blockID || par1World.getBlockId(par2 - 1, par3, par4) == Block.waterStill.blockID) { ++countwater; } if (par1World.getBlockId(par2, par3 + 1, par4) == Block.waterMoving.blockID || par1World.getBlockId(par2, par3 + 1, par4) == Block.waterStill.blockID) { ++countwater; } if (par1World.getBlockId(par2, par3 - 1, par4) == Block.waterMoving.blockID || par1World.getBlockId(par2, par3 - 1, par4) == Block.waterStill.blockID) { ++countwater; } if (par1World.getBlockId(par2, par3, par4 - 1) == Block.waterMoving.blockID || par1World.getBlockId(par2, par3, par4 - 1) == Block.waterStill.blockID) { ++countwater; } } if (b.biomeName == BiomeGenBase.ocean.biomeName) { tileEntitySC.setSurroundingWater(countwater * 2); } else if (b.biomeName == BiomeGenBase.river.biomeName) { tileEntitySC.setSurroundingWater(countwater); } } Random random; @SideOnly(Side.CLIENT) @Override public boolean onBlockActivated(World world, int x, int height, int z, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) { TileEntity tileEntity = world.getBlockTileEntity(x, height, z); if (tileEntity == null || par5EntityPlayer.isSneaking()) { return false; } // opens gui, to be implemented later par5EntityPlayer.openGui(CuisineMod.instance, 0, world, x, height, z); return true; } @Override public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6) { dropItems(par1World, par2, par3, par4); super.breakBlock(par1World, par2, par3, par4, par5, par6); } private void dropItems(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 item = inventory.getStackInSlot(i); if (item != null && item.stackSize > 0) { float rx = rand.nextFloat() * 0.8F + 0.1F; float ry = rand.nextFloat() * 0.8F + 0.1F; float rz = rand.nextFloat() * 0.8F + 0.1F; EntityItem entityItem = new EntityItem(world, x + rx, y + ry, z + rz, new ItemStack(item.itemID, item.stackSize, item.getItemDamage())); if (item.hasTagCompound()) { entityItem.item.setTagCompound((NBTTagCompound) item.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); item.stackSize = 0; } } } public boolean hasTileEntity(int metadata) { return true; } public TileEntity createNewTileEntity(World par1World) { try { return new TileEntitySaltCollector(); } catch (Exception var3) { throw new RuntimeException(var3); } } } Tile Entity: package net.mrblockplacer.JM.CuisineMod; import cpw.mods.fml.common.Side; import cpw.mods.fml.common.asm.SideOnly; import net.minecraft.src.Block; import net.minecraft.src.EntityPlayer; import net.minecraft.src.IInventory; import net.minecraft.src.ItemStack; import net.minecraft.src.NBTTagCompound; import net.minecraft.src.NBTTagList; import net.minecraft.src.TileEntity; public class TileEntitySaltCollector extends TileEntity implements IInventory { private ItemStack[] inv; public static int TotalTime = 39 * 40; // 640; public int TimeLeft; public int SurroundingWater; public boolean Initialized = false; public TileEntitySaltCollector() { inv = new ItemStack[1]; } public void setSurroundingWater(int par1) { SurroundingWater = par1; } public void startTimeLeft() { TimeLeft = TotalTime; } @Override public int getSizeInventory() { return inv.length; } @Override public ItemStack getStackInSlot(int slot) { return inv[slot]; } @Override public ItemStack decrStackSize(int slot, int amt) { ItemStack stack = getStackInSlot(slot); if (stack != null) { if (stack.stackSize <= amt) { setInventorySlotContents(slot, null); } else { stack = stack.splitStack(amt); if (stack.stackSize == 0) { setInventorySlotContents(slot, null); } } } return stack; } @Override public ItemStack getStackInSlotOnClosing(int slot) { ItemStack stack = getStackInSlot(slot); if (stack != null) { setInventorySlotContents(slot, null); } return stack; } @Override public void setInventorySlotContents(int slot, ItemStack stack) { inv[slot] = stack; if (stack != null && stack.stackSize > getInventoryStackLimit()) { stack.stackSize = getInventoryStackLimit(); } } @Override public String getInvName() { return "container.saltcollector"; } @Override public int getInventoryStackLimit() { return 64; } @Override public boolean isUseableByPlayer(EntityPlayer player) { return worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) == this && player.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) < 64; } @Override public void openChest() { } @Override public void closeChest() { } public void updateEntity() { if (!Initialized) { Block.blocksList[worldObj.getBlockId(xCoord, yCoord, zCoord)] .onNeighborBlockChange(worldObj, xCoord, yCoord, zCoord, 0); Initialized = true; } if (TimeLeft <= 0 && (inv[0] == null || inv[0].stackSize < getInventoryStackLimit())) { TimeLeft = TotalTime; } else if (inv[0] == null || inv[0].stackSize < getInventoryStackLimit()) { TimeLeft -= SurroundingWater; } // if (!this.worldObj.isRemote) { if (inv[0] == null || (inv[0].stackSize != 64 && this.inv[0] .isItemEqual(new ItemStack(CuisineMod.salt)))) { if (TimeLeft <= 0) { if (this.inv[0] == null) { this.inv[0] = new ItemStack(CuisineMod.salt, 1); } else if (this.inv[0].isItemEqual(new ItemStack( CuisineMod.salt))) { setInventorySlotContents(0, new ItemStack(CuisineMod.salt, inv[0].stackSize + 1)); } this.onInventoryChanged(); } } // } } public int getTimeLeft() { return TimeLeft; } @Override public void readFromNBT(NBTTagCompound tagCompound) { super.readFromNBT(tagCompound); TimeLeft = tagCompound.getInteger("SaltTimeLeft"); NBTTagList tagList = tagCompound.getTagList("SaltCollectorInventory"); for (int i = 0; i < tagList.tagCount(); i++) { NBTTagCompound tag = (NBTTagCompound) tagList.tagAt(i); byte slot = tag.getByte("SaltCollectorSlot"); if (slot >= 0 && slot < inv.length) { inv[slot] = ItemStack.loadItemStackFromNBT(tag); } } } @Override public void writeToNBT(NBTTagCompound tagCompound) { super.writeToNBT(tagCompound); tagCompound.setInteger("SaltTimeLeft", TimeLeft); NBTTagList itemList = new NBTTagList(); for (int i = 0; i < inv.length; i++) { ItemStack stack = inv[i]; if (stack != null) { NBTTagCompound tag = new NBTTagCompound(); tag.setByte("SaltCollectorSlot", (byte) i); stack.writeToNBT(tag); itemList.appendTag(tag); } } tagCompound.setTag("SaltCollectorInventory", itemList); } } Container: package net.mrblockplacer.JM.CuisineMod; import java.util.Iterator; import cpw.mods.fml.common.Side; import cpw.mods.fml.common.asm.SideOnly; import net.minecraft.src.Container; import net.minecraft.src.EntityPlayer; import net.minecraft.src.ICrafting; import net.minecraft.src.IInventory; import net.minecraft.src.InventoryPlayer; import net.minecraft.src.ItemStack; import net.minecraft.src.Slot; public class ContainerSaltCollector extends Container { protected TileEntitySaltCollector tileEntity; private int lastTimeLeft; public ContainerSaltCollector(IInventory inventoryPlayer, TileEntitySaltCollector te) { tileEntity = te; addSlotToContainer(new Slot(tileEntity, 0, 80, 57)); for (int i = 0; i < 3; i++) { for (int j = 0; j < 9; j++) { addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); } } for (int i = 0; i < 9; i++) { addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 142)); } } @Override public boolean canInteractWith(EntityPlayer player) { return tileEntity.isUseableByPlayer(player); } @Override public ItemStack func_82846_b(EntityPlayer par1EntityPlayer, int slot) { ItemStack stack = null; Slot slotObject = (Slot) inventorySlots.get(slot); if (slotObject != null && slotObject.getHasStack()) { ItemStack stackInSlot = slotObject.getStack(); stack = stackInSlot.copy(); if (slot == 0) { if (!mergeItemStack(stackInSlot, 1, inventorySlots.size(), true)) { return null; } } else if (!mergeItemStack(stackInSlot, 0, 1, false)) { return null; } if (stackInSlot.stackSize == 0) { slotObject.putStack(null); } else { slotObject.onSlotChanged(); } } return stack; } public void addCraftingToCrafters(ICrafting par1ICrafting) { super.addCraftingToCrafters(par1ICrafting); par1ICrafting.updateCraftingInventoryInfo(this, 0, tileEntity.TimeLeft); } public void updateCraftingResults() { super.updateCraftingResults(); Iterator var1 = this.crafters.iterator(); while (var1.hasNext()) { ICrafting var2 = (ICrafting) var1.next(); if (this.lastTimeLeft != this.tileEntity.TimeLeft) { var2.updateCraftingInventoryInfo(this, 0, this.tileEntity.TimeLeft); } } this.lastTimeLeft = this.tileEntity.TimeLeft; } @SideOnly(Side.CLIENT) public void updateProgressBar(int par1, int par2) { if (par1 == 0) { this.tileEntity.TimeLeft = par2; } } } Gui: package net.mrblockplacer.JM.CuisineMod; import java.util.Random; import org.lwjgl.opengl.GL11; import net.minecraft.src.Container; import net.minecraft.src.GuiContainer; import net.minecraft.src.InventoryPlayer; import net.minecraft.src.StatCollector; public class GuiSaltCollector extends GuiContainer { private TileEntitySaltCollector TE; public GuiSaltCollector(InventoryPlayer inventoryPlayer, TileEntitySaltCollector tileEntity) { super(new ContainerSaltCollector(inventoryPlayer, tileEntity)); TE = tileEntity; } @Override protected void drawGuiContainerForegroundLayer(int par1, int par2) { fontRenderer.drawString("Salt Collector", 53, 6, 4210752); fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 8, ySize - 96 + 2, 4210752); } @Override protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) { int texture = mc.renderEngine.getTexture("/JMMods/Cuisine/Gui/SaltCollector.png"); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); this.mc.renderEngine.bindTexture(texture); int x = (width - xSize) / 2; int y = (height - ySize) / 2; this.drawTexturedModalRect(x, y, 0, 0, xSize, ySize); int part = TE.getTimeLeft(); part = (int) part / (TE.TotalTime / 39); this.drawTexturedModalRect(x + 80, y + 16, 176, 0, 16, 40 - part); } } Handler/Common Proxy: package net.mrblockplacer.JM.CuisineMod; import net.minecraft.src.EntityPlayer; import net.minecraft.src.TileEntity; import net.minecraft.src.World; import cpw.mods.fml.common.network.IGuiHandler; public class CommonProxy implements IGuiHandler { public static String ITEMS = "/JMMods/Cuisine/JMItems.png"; public static String BLOCKS = "/JMMods/Cuisine/JMBlocks.png"; @Override public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) { TileEntity tileEntity = world.getBlockTileEntity(x, y, z); if(tileEntity instanceof TileEntitySaltCollector){ return new ContainerSaltCollector(player.inventory, (TileEntitySaltCollector) tileEntity); } return null; } @Override public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) { TileEntity tileEntity = world.getBlockTileEntity(x, y, z); if(tileEntity instanceof TileEntitySaltCollector){ return new GuiSaltCollector(player.inventory, (TileEntitySaltCollector) tileEntity); } return null; } public void registerRenderers() { } } An explanation would be greatly appreciated. I am going to assume that making a GUI fully multi-player for an actual server is still a little different than for the integrated server. Quote I like collars. XP
Recommended Posts
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.