Jump to content

(Solved)GUI handling causing game to crash with no crash report?


Roboguy99

Recommended Posts

After a little bit of testing (perhaps not enough) I've discovered that my server-side GUI handler is causing the game to freeze indefinitely. I have successfully managed to print to the console all the way through my class ContainerWindmilll and also in my class BlockWindmill, giving me the feeling that something somewhere else is affected. If anybody can locate the cause of this crash (no errors are shown, it's only when I right-click it crashes) I would be very grateful.

 

EDIT: I've edited my code around a bit and now the FMLNetworkHandler.openGUI line from the BlockWindmill class seems to not freeze the game but freezes console output (perhaps freezes the thread?)

 

Gui Handler:

 

package testmod.gui;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import testmod.gui.container.ContainerWindmill;
import testmod.tileEntities.TileEntityWindmill;
import cpw.mods.fml.common.network.IGuiHandler;

public class GuiHandler implements IGuiHandler
{
public static final int guiIDWindmill = 0;

public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) 
{
	TileEntity tileEntity = world.getTileEntity(x, y, z);

	switch(ID)
	{
		case guiIDWindmill:
			if(tileEntity instanceof TileEntityWindmill)
			{
				return new ContainerWindmill(player.inventory, (TileEntityWindmill) tileEntity);
			}
	}
	return null;
}

public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) 
{
	TileEntity tileEntity = world.getTileEntity(x, y, z);

	switch(ID)
	{
		case guiIDWindmill:
			while(tileEntity instanceof TileEntityWindmill && world.getBlockMetadata(x, y, z) < ;
			{
				System.out.println(y);
				y++;
			}

			return new GuiWindmill(player.inventory, (TileEntityWindmill) tileEntity);
	}
	return null;
}
}

 

 

ContainerWindmill:

 

package testmod.gui.container;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import testmod.tileEntities.TileEntityWindmill;

public class ContainerWindmill extends Container 
{
public TileEntityWindmill windmill;

public ContainerWindmill(InventoryPlayer inventoryPlayer, TileEntityWindmill windmill)
{
	this.windmill = windmill;

	this.addSlotToContainer(new Slot(windmill, 0, 61, 33));
	this.addSlotToContainer(new Slot(windmill, 1, 100, 33));

	for(int i = 0; i < 3; i++) //Create the inventory slots
	{
		for(int j = 0; j < 9; j++)
		{
			this.addSlotToContainer(new Slot(inventoryPlayer, 9+j+i*9, 8+j*18, 84+18*i));
		}
	}

	for(int i = 0; i < 9; i++) //Create the hotbar slots
	{
		this.addSlotToContainer(new Slot(inventoryPlayer, i, 8+18*i, 142));
	}
}

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

/*
* ~~Notes~~
* this.addSlotToContainer(new Slot(inventoryPlayer, ID, xPos, yPos)
* 
* Inventory IDs: Hotbar: 0-8
* 				  Inventory: 9-27
* */

 

 

TileEntityWindmill:

 

package testmod.tileEntities;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;

public class TileEntityWindmill extends TileEntity implements ISidedInventory
{
private ItemStack[] slot = new ItemStack[2];

public float rotation = 0F;

public int maxPower = 10000;
public float power = 0F;
public float powerPerRotation = 1F;

public void updateEntity() //TODO increase power
{
	rotation++;

	powerPerRotation = 5;

	power+=powerPerRotation;

	if(power > maxPower) power = maxPower;

}

public int getPowerScaled(int scaled)
{
	return (int) (this.power * scaled / this.maxPower);
}

public void readFromNBT(NBTTagCompound nbt)
{

}

public void writeToNBT(NBTTagCompound nbt)
{

}

public void closeInventory() 
{

}

public ItemStack decrStackSize(int i, int j) 
{
	if(this.slot[i] != null)
	{
		ItemStack itemStack;

		if(this.slot[i].stackSize <= j)
		{
			itemStack = this.slot[i];
			this.slot[i] = null;
			return itemStack;
		}
		else
		{
			itemStack = this.slot[i].splitStack(j);

			if(this.slot[i].stackSize == 0)
			{
				this.slot[i] = null;
			}

			return itemStack;
		}
	}

	return null;
}

public String getInventoryName() 
{
	return null;
}

public int getInventoryStackLimit()
{
	return 64;
}

public int getSizeInventory() 
{

	return this.slot.length;
}

public ItemStack getStackInSlot(int i) 
{

	return this.slot[i];
}

public ItemStack getStackInSlotOnClosing(int i) 
{
	if(this.slot[i] != null)
	{
		ItemStack itemStack = this.slot[i];
		this.slot[i] = null;
		return itemStack;
	}

	return null;
}

public boolean hasCustomInventoryName()
{

	return false;
}

public boolean isItemValidForSlot(int var1, ItemStack var2)
{

	return false;
}

public boolean isUseableByPlayer(EntityPlayer var1)
{

	return false;
}

public void openInventory() 
{


}

public void setInventorySlotContents(int i, ItemStack itemStack) 
{
	this.slot[i] = itemStack;

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

public boolean canExtractItem(int var1, ItemStack var2, int var3) 
{

	return false;
}

public boolean canInsertItem(int var1, ItemStack var2, int var3) 
{

	return false;
}

public int[] getAccessibleSlotsFromSide(int var1) 
{

	return null;
}
}

 

 

BlockWindmill:

 

package testmod.blocks;

import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import testmod.Main;
import testmod.gui.GuiHandler;
import testmod.tileEntities.TileEntityWindmill;
import cpw.mods.fml.common.network.internal.FMLNetworkHandler;

public class BlockWindmill extends BlockContainer //Class for the windmill block. The block is turned into a tileEntity when placed
{
public BlockWindmill(Material material)
{
	super(material);
}

public int getRenderType()
{
	return -1;
}

public boolean isOpaqueCube()
{
	return false;
}

public boolean renderAsNormalBlock()
{
	return false;
}

public TileEntity createNewTileEntity(World var1, int var2) //Replaces the block with its tileEntity counterpart
{
	return new TileEntityWindmill();
}

public void breakBlock(World world, int x, int y, int z, Block block, int metadata)
{
	if (world.getBlock(x, y+1, z) == CreateBlocks.blockWindmill) world.setBlockToAir(x, y+1, z);
	if (world.getBlock(x, y-1, z) == CreateBlocks.blockWindmill) world.setBlockToAir(x, y-1, z);
}

public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z)
{
	float pixel = 1F/16F;

	if(world.getBlockMetadata(x, y, z) < 7) this.setBlockBounds(pixel*4, 0, pixel*4, 1-pixel*4, 1, 1-pixel*4);
	else this.setBlockBounds(0, 0, 0, 1, 1, 1);
}

public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)
{
	if(!world.isRemote)
	{
		FMLNetworkHandler.openGui(player, Main.instance, GuiHandler.guiIDWindmill, world, x, y, z);
		return true;
	}
	return false;
}
}

 

I have no idea what I'm doing.

Link to comment
Share on other sites

When you start it with the debugger (bug button) it keeps track of certain stats and vars. You can then use the Terminate button to kill the process and it should show you the breakpoint.

 

 

bbc501943d.png

 

 

Its not crashing when there is no log its just stuck in an infinite loop and windows stops it when the user tries to interact with it.

PM's regarding modding questions should belong in the Modder Support sub-forum and won't be answered.

Link to comment
Share on other sites

Ok I tried that and all it did was paste

 AL lib: (EE) alc_cleanup: 1 device not closed 

to the console. What might be worth noting is that the game no longer freezes. In the method below, it prints "before", but "after" is never printed.

 

public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)
{	
	if(!world.isRemote)
	{
		Main.print("before"); //Just a custom print method to put my mod name on there
		FMLNetworkHandler.openGui(player, Main.instance, GuiHandler.guiIDWindmill, world, x, y, z);
		Main.print("after");
		return true;
	}
	return false;
}

I have no idea what I'm doing.

Link to comment
Share on other sites

Eclipse and debuggers in general usage involves placing breakpoints and stepping through code a line at a time while examining variables in the method. Use eclipse help if you need to learn how.

Link to comment
Share on other sites

while(tileEntity instanceof TileEntityWindmill && world.getBlockMetadata(x, y, z) < ;

Yeah, that is an infinite loop.

 

Sorry I'm sure I'm being an idiot here. Could you explain how please? I copied that piece of code from a tutorial video, and theirs worked fine.

I have no idea what I'm doing.

Link to comment
Share on other sites

Eclipse and debuggers in general usage involves placing breakpoints and stepping through code a line at a time while examining variables in the method. Use eclipse help if you need to learn how.

 

I thought that, but the buttons were disabled. I will make sure to look into the help for them, thanks.

I have no idea what I'm doing.

Link to comment
Share on other sites

while(tileEntity instanceof TileEntityWindmill && world.getBlockMetadata(x, y, z) < ;

Yeah, that is an infinite loop.

 

Sorry I'm sure I'm being an idiot here. Could you explain how please? I copied that piece of code from a tutorial video, and theirs worked fine.

 

Okay, there are two kinds of loops that use

while

. One is:

do BLOCK while (boolean-expression);

(note the ';' after the keyword. The other is:

while (boolean-expression) BLOCK;

(notice the ';' after the body of the loop). In both cases BLOCK is usually an actualy block ('

{ statement; ... }

'), but it may also be a single statement.

 

Your while loop appears to be executing a null statement (';' alone is a null statement), and that is why the loop repeats forever.

Link to comment
Share on other sites

while(tileEntity instanceof TileEntityWindmill && world.getBlockMetadata(x, y, z) < ;

Yeah, that is an infinite loop.

 

Sorry I'm sure I'm being an idiot here. Could you explain how please? I copied that piece of code from a tutorial video, and theirs worked fine.

 

Okay, there are two kinds of loops that use

while

. One is:

do BLOCK while (boolean-expression);

(note the ';' after the keyword. The other is:

while (boolean-expression) BLOCK;

(notice the ';' after the body of the loop). In both cases BLOCK is usually an actualy block ('

{ statement; ... }

'), but it may also be a single statement.

 

Your while loop appears to be executing a null statement (';' alone is a null statement), and that is why the loop repeats forever.

 

Oh my whatever the supreme being(s) may or may not be. In other words, I misplaced a semicolon on a block like I do so often. Thanks!

I have no idea what I'm doing.

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

    • Great that is working in your case. Are there any other solutions I can try? Mine is not working for a week.
    • We tried but now it doesnt even load, it gets stuck on loading. https://mclo.gs/sYJGdXx
    • the modpack start but when i close crash DEBUG LOG : https://paste.ee/p/3WjHl#section0 i've tryied to install performance mod but i have this DEBUG LOG 2 : https://paste.ee/p/8T0He#section0
    • Looks like an issue with betterpingdisplay - make a test without it
    • I made a basic homing arrow, which I am going to refine further, but as of now I have the problem of the Arrow not rendering properly. It works fine on the server side, but on the client it always appears as if the arrow was flying normally, until it synchs and teleports around.   [https://gemoo.com/tools/upload-video/share/661346070437036032?codeId=MpmzxaW0pBpE1&card=661346066800603136&origin=videolinkgenerator] the white particles are created by the entity every tick on the server side and represent its actual flying path.   My best guess is that this behaviour is caused, because minecraft appears to try to predict the projectiles path on the client side instead of constantly synching (perhaps something to do with it implementing the TracableEntity interface??). I am thinking I need help with either 1. Getting the client to use my custom Tick function in its path prediction, or 2. (the less elegant solution) getting the game to synch up the direction, position and movement etc. every tick.     Note that my custom arrow class extends AbstractArrow. everything important it does: private static final EntityDataAccessor<Integer> TARGET_ENTITY = SynchedEntityData.defineId(ReachArrow.class, EntityDataSerializers.INT); @Override public void addAdditionalSaveData(CompoundTag pCompound) { super.addAdditionalSaveData(pCompound); pCompound.putInt("TargetEntity", this.getTargetEntity()); } @Override public void readAdditionalSaveData(CompoundTag pCompound) { super.readAdditionalSaveData(pCompound); this.setTargetEntity(pCompound.getInt("TargetEntity")); } @Override protected void defineSynchedData() { super.defineSynchedData(); this.entityData.define(TARGET_ENTITY, -1); } @Override public void shootFromRotation(Entity pShooter, float pX, float pY, float pZ, float pVelocity, float pInaccuracy) { LivingEntity target = ReachArrow.findNearestTarget(this.level(),(LivingEntity) pShooter,50d); if(pShooter instanceof LivingEntity && target !=null){ //pShooter.sendSystemMessage(Component.literal("setting id "+target.getId()+" as target")); setTargetEntity(target.getId()); //pShooter.sendSystemMessage(Component.literal("target set")); } super.shootFromRotation(pShooter, pX, pY, pZ, pVelocity, pInaccuracy); } public static LivingEntity findNearestTarget(Level world, LivingEntity shooter, double range) { AABB searchBox = shooter.getBoundingBox().inflate(range); List<LivingEntity> potentialTargets = world.getEntitiesOfClass(LivingEntity.class, searchBox, EntitySelector.NO_SPECTATORS); LivingEntity nearestTarget = null; double closestDistance = Double.MAX_VALUE; for (LivingEntity potentialTarget : potentialTargets) { if (potentialTarget != shooter && potentialTarget.isAlive()) { double distance = shooter.distanceToSqr(potentialTarget); if (distance < closestDistance) { closestDistance = distance; nearestTarget = potentialTarget; } } } return nearestTarget; } I tried fixing the problem by storing the Target using SynchedEntityData, which not only didn't fix the problem, but also added unwanted, blue particles to the arrow (like on tipped arrow) Thank you in advance for any help or hints, I am quite new at this so you could probably help me a lot. :)
  • Topics

×
×
  • Create New...

Important Information

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