Read the tutorial and the forge method again. On server, an interact needs to call player.openGui and the MinecraftForge getGuiElement needs to return the Container a client sets his GUI up on.
Basically, the EntityID needs to be below 128, I.E, <=127 and >=1 (maybe 0), unsure if the ID even matters since Forge might auto-sync it anyway, but it *must* be within that range. Perhaps add that to all relevant sections of the tutorial?
Awesome tutorial by the way, very well done.
EDIT: Any chance of getting the DimensionHandler API usage for client/server on adding a new Dimension?
Read the tutorial and the forge method again. On server, an interact needs to call player.openGui and the MinecraftForge getGuiElement needs to return the Container a client sets his GUI up on.
Even though I wasn't the asker, this message helped me with my GUI problem. Thanks heaps +1 Rep
Ok, just one question. How do I substitute ModLoaderMp.sendChatToAll(""). I've noticed the SCM (ServerConfigManager) has sendChatToOps("") but not to all?
Make a chat packet and send it to all via configurationmanager
Okay having some problems with the gui for a block.
Mod File on server.
public Object getGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
{
if(ID == 90)
{
return new ContainerWaterCollector(player.inventory, new TileEntityWaterCollector());
}
if(ID == 91)
{
return new ContainerJM(player.inventory, new TileEntityJM());
}
return null;
}
Mod File on Client:
public Object getGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
{
if(ID == 90)
{
return new GuiWaterCollector(player.inventory, new TileEntityWaterCollector());
}
if(ID == 91)
{
return new GuiJM(player.inventory, new TileEntityJM());
}
return null;
}
ContainerJM Server:
public boolean canInteractWith(EntityPlayer par1EntityPlayer)
{
return jm.isUseableByPlayer(par1EntityPlayer);
}
BlockJM Server:
public boolean blockActivated(World world, int i, int j, int k, EntityPlayer entityplayer)
{
if (world.isRemote)
{
return true;
}
else
{
entityplayer.openGui(mod_ThirstMod.mod, 91, world, i, j, k);
return true;
}
}
However when I run it, game crashes with the following error:
[WARNING] Failed to handle packet: java.lang.NullPointerException
java.lang.NullPointerException
at net.minecraft.src.ThirstMod.containers.TileEntityJM.isUseableByPlayer(TileEntityJM.java:268)
at net.minecraft.src.ThirstMod.containers.ContainerJM.canInteractWith(ContainerJM.java:86)
at net.minecraft.src.EntityPlayer.onUpdate(EntityPlayer.java:239)
at net.minecraft.src.EntityPlayerMP.localOnUpdateEntity(EntityPlayerMP.java:1066)
at net.minecraft.src.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:1060)
at net.minecraft.src.NetServerHandler.handleFlying(NetServerHandler.java:241)
at net.minecraft.src.Packet10Flying.processPacket(Packet10Flying.java:41)
at net.minecraft.src.NetworkManager.processReadPackets(NetworkManager.java:353)
at net.minecraft.src.NetServerHandler.handlePackets(NetServerHandler.java:73)
at net.minecraft.src.NetworkListenThread.handleNetworkListenThread(NetworkListenThread.java:113)
at net.minecraft.server.MinecraftServer.doTick(MinecraftServer.java:566)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:445)
at net.minecraft.src.ThreadServerApplication.run(ThreadServerApplication.java:18)
If you need more code PM me.
This is also happening with the Water Collector
You should at the very least post your code around and including the crashing line
And what is the "this" check supposed to do there.
If that method is invoked, you already know it is an instance of your Block
return this.worldObj.getBlockTileEntity(this.xCoord, this.yCoord, this.zCoord) != this
Look again I have posted around the crash area. I was copying the furnace one for the worldObj to make sure it isn't some problem with my own code.
Edit: For some reason worldObj was null in my code all fixed now. Last Question do you need to use the register for Entities on TileEntity as well. Thanks
I've got a Block whick should open a GUI where you can choose a team. The GUI is similar to the GuiIngameMenu.
So it consists just of buttons ( [Team Red], [Team Blue] and [Exit Team]), but no Container. How can I display this GUI in SMP, SSP just works fine (i think)?
blabla
I think since your block does not have a container (only assuming) you might have to send a special packet which is sent by the server when the block is right clicked. Then on the client side if the packet equals true (for a boolean) you can open the gui with ModLoader.openGUI. Then send another packet with the clicked or chosen teams to the server to calculate and send to everyone on the server.
@Vadammt
Just handle your team menu on client as usual, but when you want to set the team in your mod_ file, send a packet to the server instead and tell him to make it so
@tarun
It's a NullPointerException. You need to use debug printing (System.out.println("Herp: "+value)) and figure out what exactly is null. Then fix it.
@tarun
It's a NullPointerException. You need to use debug printing (System.out.println("Herp: "+value)) and figure out what exactly is null. Then fix it.
So I end up fixing my gui, turns out worldObj was null. But for some reason the client never sends the itemstack packets back to the server and server never sends back the duration for the item to be made back to client. This was all working on MLMP. Nothing is changed.
Then the same line can't throw worldObj == null anymore can it
Dude its all fixed but client isn't sending the container packets to server for some reason. If you can tell me where Vanilla Minecraft does all this sending window packets then I can fix it myself.
BTW have you seen the this.worldObj in vanilla classes?
TileEntityFurnace
if (!this.worldObj.isRemote)
{
if (this.furnaceBurnTime == 0 && this.canSmelt())
cpw.mods.fml.common.LoaderException: java.lang.NullPointerException
at cpw.mods.fml.common.modloader.ModLoaderModContainer.preInit(ModLoaderModContainer.java:114)
at cpw.mods.fml.common.Loader.preModInit(Loader.java:235)
at cpw.mods.fml.common.Loader.loadMods(Loader.java:593)
at cpw.mods.fml.client.FMLClientHandler.onPreLoad(FMLClientHandler.java:193)
at net.minecraft.client.Minecraft.startGame(Minecraft.java:383)
at net.minecraft.client.Minecraft.run(Minecraft.java:735)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
at java.util.Hashtable.put(Unknown Source)
at net.minecraft.src.forge.MinecraftForge.setGuiHandler(MinecraftForge.java:1089)
at net.minecraft.src.mod_DFurnace.<init>(mod_DFurnace.java:21)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at cpw.mods.fml.common.modloader.ModLoaderModContainer.preInit(ModLoaderModContainer.java:107)
... 6 more
My mod_ file client
package net.minecraft.src;
import net.minecraft.src.forge.*;
public class mod_DFurnace extends BaseMod{
public static BaseMod mod;
public static IGuiHandler handler;
public static Block DFurnace;
public static Block DFurnaceOn;
public static int dFurnaceSide = ModLoader.addOverride("/terrain.png", "/dfurnace/DFurnaceSide.png");
public static int dFurnaceFront = ModLoader.addOverride("/terrain.png", "/dfurnace/DFurnaceOff.png");
public static int dFurnaceFrontOn = ModLoader.addOverride("/terrain.png", "/dfurnace/DFurnaceOn.png");
public mod_DFurnace(){
ModLoader.registerBlock(DFurnace);
ModLoader.addName(DFurnace, "Diamond Furnace");
ModLoader.registerTileEntity(net.minecraft.src.TileEntityDFurnace.class, "DFurnace");
ModLoader.addRecipe(new ItemStack(DFurnace, 1), new Object[]{"XXX","X X","XXX", Character.valueOf('X'), Block.blockDiamond});
ModLoader.registerBlock(DFurnaceOn);
ModLoader.addName(DFurnaceOn, "Diamond Furnace On");
ModLoader.registerTileEntity(net.minecraft.src.TileEntityDFurnace.class, "DFurnaceOn");
MinecraftForge.setGuiHandler(mod, handler);
}
{
DFurnace = new BlockDFurnace(246, false).setHardness(0F).setResistance(0F).setStepSound(Block.soundMetalFootstep).setBlockName("Diamond Furnace");
DFurnaceOn = new BlockDFurnace(247, true).setHardness(0F).setResistance(0F).setStepSound(Block.soundMetalFootstep).setBlockName("Diamond Furnace On");
}
public String getVersion() {
return null;
}
public void load() {
}
}
My Block file client
// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) braces deadcode
//blockIndexInTexture; = Regular/Side in the situation
//if(l == 1) = Top texture
//if(l == 0) = Bottom Texture
//if(i == 3) = Front Texture/Off
//blockIndexInTexture + 16; = Active Texture/On
//blockIndexInTexture - 1; = Off Texture/Off
//l = BlockID
package net.minecraft.src;
import java.util.Random;
public class BlockDFurnace extends BlockContainer
{
protected BlockDFurnace(int i, boolean flag)
{
super(i, Material.rock);
dFurnaceRand = new Random();
isActive = flag;
blockIndexInTexture = 45;
}
public int idDropped(int i, Random random)
{
return mod_DFurnace.DFurnace.blockID;
}
public void onBlockAdded(World world, int i, int j, int k)
{
super.onBlockAdded(world, i, j, k);
setDefaultDirection(world, i, j, k);
}
private void setDefaultDirection(World par1World, int par2, int par3, int par4)
{
if (!par1World.isRemote)
{
int var5 = par1World.getBlockId(par2, par3, par4 - 1);
int var6 = par1World.getBlockId(par2, par3, par4 + 1);
int var7 = par1World.getBlockId(par2 - 1, par3, par4);
int var8 = par1World.getBlockId(par2 + 1, par3, par4);
byte var9 = 3;
if (Block.opaqueCubeLookup[var5] && !Block.opaqueCubeLookup[var6])
{
var9 = 3;
}
if (Block.opaqueCubeLookup[var6] && !Block.opaqueCubeLookup[var5])
{
var9 = 2;
}
if (Block.opaqueCubeLookup[var7] && !Block.opaqueCubeLookup[var8])
{
var9 = 5;
}
if (Block.opaqueCubeLookup[var8] && !Block.opaqueCubeLookup[var7])
{
var9 = 4;
}
par1World.setBlockMetadataWithNotify(par2, par3, par4, var9);
}
}
public int getBlockTexture(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
{
if (par5 == 1)
{
return mod_DFurnace.dFurnaceSide;
}
else if (par5 == 0)
{
return mod_DFurnace.dFurnaceSide;
}
else
{
int var6 = par1IBlockAccess.getBlockMetadata(par2, par3, par4);
return par5 != var6 ? mod_DFurnace.dFurnaceSide : (this.isActive ? mod_DFurnace.dFurnaceFrontOn : mod_DFurnace.dFurnaceFront);
}
}
public void randomDisplayTick(World par1World, int par2, int par3, int par4, Random par5Random)
{
if (this.isActive)
{
int var6 = par1World.getBlockMetadata(par2, par3, par4);
float var7 = (float)par2 + 0.5F;
float var8 = (float)par3 + 0.0F + par5Random.nextFloat() * 6.0F / 16.0F;
float var9 = (float)par4 + 0.5F;
float var10 = 0.52F;
float var11 = par5Random.nextFloat() * 0.6F - 0.3F;
if (var6 == 4)
{
par1World.spawnParticle("smoke", (double)(var7 - var10), (double)var8, (double)(var9 + var11), 0.0D, 0.0D, 0.0D);
par1World.spawnParticle("flame", (double)(var7 - var10), (double)var8, (double)(var9 + var11), 0.0D, 0.0D, 0.0D);
}
else if (var6 == 5)
{
par1World.spawnParticle("smoke", (double)(var7 + var10), (double)var8, (double)(var9 + var11), 0.0D, 0.0D, 0.0D);
par1World.spawnParticle("flame", (double)(var7 + var10), (double)var8, (double)(var9 + var11), 0.0D, 0.0D, 0.0D);
}
else if (var6 == 2)
{
par1World.spawnParticle("smoke", (double)(var7 + var11), (double)var8, (double)(var9 - var10), 0.0D, 0.0D, 0.0D);
par1World.spawnParticle("flame", (double)(var7 + var11), (double)var8, (double)(var9 - var10), 0.0D, 0.0D, 0.0D);
}
else if (var6 == 3)
{
par1World.spawnParticle("smoke", (double)(var7 + var11), (double)var8, (double)(var9 + var10), 0.0D, 0.0D, 0.0D);
par1World.spawnParticle("flame", (double)(var7 + var11), (double)var8, (double)(var9 + var10), 0.0D, 0.0D, 0.0D);
}
}
}
public int getBlockTextureFromSide(int par1)
{
return par1 == 1 ? mod_DFurnace.dFurnaceSide : (par1 == 0 ? mod_DFurnace.dFurnaceSide : (par1 == 3 ? mod_DFurnace.dFurnaceFront : mod_DFurnace.dFurnaceSide));
}
public boolean blockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer)
{
if (par1World.isRemote)
{
return true;
}
else
{
TileEntityDFurnace var6 = (TileEntityDFurnace)par1World.getBlockTileEntity(par2, par3, par4);
if (var6 != null)
{
ModLoader.openGUI(par5EntityPlayer, new GuiDFurnace(par5EntityPlayer.inventory, var6));
}
return true;
}
}
public static void updateDFurnaceBlockState(boolean flag, World world, int i, int j, int k)
{
int l = world.getBlockMetadata(i, j, k);
TileEntity tileentity = world.getBlockTileEntity(i, j, k);
keepDFurnaceInventory = true;
if(flag)
{
world.setBlockWithNotify(i, j, k, mod_DFurnace.DFurnaceOn.blockID);
} else
{
world.setBlockWithNotify(i, j, k, mod_DFurnace.DFurnace.blockID);
}
keepDFurnaceInventory = false;
world.setBlockMetadataWithNotify(i, j, k, l);
if(tileentity != null)
{
tileentity.validate();
world.setBlockTileEntity(i, j, k, tileentity);
}
}
public TileEntity getBlockEntity()
{
return new TileEntityDFurnace();
}
public void onBlockPlacedBy(World world, int i, int j, int k, EntityLiving entityliving)
{
int l = MathHelper.floor_double((double)((entityliving.rotationYaw * 4F) / 360F) + 0.5D) & 3;
if(l == 0)
{
world.setBlockMetadataWithNotify(i, j, k, 2);
}
if(l == 1)
{
world.setBlockMetadataWithNotify(i, j, k, 5);
}
if(l == 2)
{
world.setBlockMetadataWithNotify(i, j, k, 3);
}
if(l == 3)
{
world.setBlockMetadataWithNotify(i, j, k, 4);
}
}
public void onBlockRemoval(World par1World, int par2, int par3, int par4)
{
if (!keepDFurnaceInventory)
{
TileEntityDFurnace var5 = (TileEntityDFurnace)par1World.getBlockTileEntity(par2, par3, par4);
if (var5 != null)
{
for (int var6 = 0; var6 < var5.getSizeInventory(); ++var6)
{
ItemStack var7 = var5.getStackInSlot(var6);
if (var7 != null)
{
float var8 = this.dFurnaceRand.nextFloat() * 0.8F + 0.1F;
float var9 = this.dFurnaceRand.nextFloat() * 0.8F + 0.1F;
float var10 = this.dFurnaceRand.nextFloat() * 0.8F + 0.1F;
while (var7.stackSize > 0)
{
int var11 = this.dFurnaceRand.nextInt(21) + 10;
if (var11 > var7.stackSize)
{
var11 = var7.stackSize;
}
var7.stackSize -= var11;
EntityItem var12 = new EntityItem(par1World, (double)((float)par2 + var8), (double)((float)par3 + var9), (double)((float)par4 + var10), new ItemStack(var7.itemID, var11, var7.getItemDamage()));
if (var7.hasTagCompound())
{
var12.item.setTagCompound((NBTTagCompound)var7.getTagCompound().copy());
}
float var13 = 0.05F;
var12.motionX = (double)((float)this.dFurnaceRand.nextGaussian() * var13);
var12.motionY = (double)((float)this.dFurnaceRand.nextGaussian() * var13 + 0.2F);
var12.motionZ = (double)((float)this.dFurnaceRand.nextGaussian() * var13);
par1World.spawnEntityInWorld(var12);
}
}
}
}
}
super.onBlockRemoval(par1World, par2, par3, par4);
}
private Random dFurnaceRand;
private final boolean isActive;
private static boolean keepDFurnaceInventory = false;
}
Your crash is unrelated to Entities - it looks like server knows a TileEntity which client doesnt have.
http://minecraftforg...331.html#msg331
Basically, the EntityID needs to be below 128, I.E, <=127 and >=1 (maybe 0), unsure if the ID even matters since Forge might auto-sync it anyway, but it *must* be within that range. Perhaps add that to all relevant sections of the tutorial?
Awesome tutorial by the way, very well done.
EDIT: Any chance of getting the DimensionHandler API usage for client/server on adding a new Dimension?
You are not supposed to declare the methods i show. You are supposed to invoke them.
@wuppy in particular
Just 8 posts above yours. 2 pages of thread really is not too much to read.
Even though I wasn't the asker, this message helped me with my GUI problem. Thanks heaps +1 Rep
Make a chat packet and send it to all via configurationmanager
However when I run it, game crashes with the following error:
If you need more code PM me.
This is also happening with the Water Collector
And what is the "this" check supposed to do there.
If that method is invoked, you already know it is an instance of your Block
Look again I have posted around the crash area. I was copying the furnace one for the worldObj to make sure it isn't some problem with my own code.
Edit: For some reason worldObj was null in my code all fixed now. Last Question do you need to use the register for Entities on TileEntity as well. Thanks
I think since your block does not have a container (only assuming) you might have to send a special packet which is sent by the server when the block is right clicked. Then on the client side if the packet equals true (for a boolean) you can open the gui with ModLoader.openGUI. Then send another packet with the clicked or chosen teams to the server to calculate and send to everyone on the server.
Just handle your team menu on client as usual, but when you want to set the team in your mod_ file, send a packet to the server instead and tell him to make it so
@tarun
It's a NullPointerException. You need to use debug printing (System.out.println("Herp: "+value)) and figure out what exactly is null. Then fix it.
this.worldObj...
line yet. And if you insist on checking that needlessly, make it entityplayer.worldObj
BTW have you seen the this.worldObj in vanilla classes?
this, this, this. So that is not the problem
My mod_ file client
My Block file client
with guis, how would you be able to get the basemod to recognise a specific entity interacted with.