Jump to content

Recommended Posts

Posted

Sounds weird but my Block+Tile causes the Server Threads to get problems and slowly but truely it starts to make the server slower and make the server crash with that.

 

I do not know why this happen. I only know it happen only on the Server side and only on at this TileEntity.

 

 

Ventil (TileEntity):

package speiger.src.api.common.tile;

import cpw.mods.fml.common.FMLLog;
import net.minecraft.block.Block;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.Packet132TileEntityData;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import speiger.src.api.common.blocks.BlockGas;
import speiger.src.api.common.config.APIItems;

public class Ventil extends TileFacing implements IFluidHandler
{
public FluidTank tank = new FluidTank(8000);
public int between = 0;

@Override
public void updateEntity()
{
	super.updateEntity();
	if(!worldObj.isRemote)
	{
		suckGas();
	}

}

public void useForFire()
{
	FMLLog.getLogger().info("Test");
	int blockID = worldObj.getBlockId(xCoord, yCoord+1, zCoord);
	if(blockID != 0 && blockID == Block.fire.blockID)
	{
		if(tank.getFluid() != null && tank.getFluid().amount > 0)
		{
			between++;
			if(between >= 25)
			{
				between = 0;
				tank.drain(1, true);
			}
		}
	}
}

public void suckGas()
{
	int blockID = worldObj.getBlockId(xCoord, yCoord-1, zCoord);
	if(blockID != 0 && blockID == APIItems.gas.blockID)
	{
		int meta = worldObj.getBlockMetadata(xCoord, yCoord-1, zCoord);
		BlockGas block = (BlockGas) Block.blocksList[blockID];
		if(block != null)
		{
			FluidStack liquid = new FluidStack(APIItems.animalGas, 100);
			liquid.amount = 100;
			if(tank.fill(liquid, false) >= 100)
			{
				tank.fill(liquid, true);
				block.removeOneGas(worldObj, xCoord, yCoord-1, zCoord);
			}
		}
	}
}

public boolean isFireSource()
{
	if(tank.getFluid() != null && tank.getFluid().amount > 0)
	{
		useForFire();
		return true;
	}
	return false;
}

@Override
public int getTextureFromTile(int meta, int side)
{
	if(side == 0) return 128;
	else if(side == 1)return 130;
	else return 129;
}

@Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) 
{
	if(resource.isFluidEqual(new FluidStack(APIItems.animalGas, 1000)))
	{
		return tank.fill(resource, doFill);
	}
	return 0;
}

@Override
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain)
{
	return tank.drain(resource.amount, doDrain);
}

@Override
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
{
	return tank.drain(maxDrain, doDrain);
}

@Override
public boolean canFill(ForgeDirection from, Fluid fluid) 
{
	return true;
}

@Override
public boolean canDrain(ForgeDirection from, Fluid fluid) 
{
	return true;
}

@Override
public FluidTankInfo[] getTankInfo(ForgeDirection from) 
{

	return new FluidTankInfo[]{tank.getInfo()};
}

@Override
public void readFromNBT(NBTTagCompound par1)
{
	super.readFromNBT(par1);
        if (par1.hasKey("FirstTank")) {
        	
        	FluidStack stack = FluidStack.loadFluidStackFromNBT(par1.getCompoundTag("FirstTank"));
        	
        	if(stack != null)
        	{
        		tank.setFluid(stack);
        	}
        	
        	
	}
}

@Override
public void writeToNBT(NBTTagCompound par1)
{
	super.writeToNBT(par1);
	if (tank.getFluid() != null) {
		par1.setTag("FirstTank", tank.getFluid().writeToNBT(par1));
	}

}

@Override
public Packet getDescriptionPacket()
{
	NBTTagCompound nbt = new NBTTagCompound();
	super.writeToNBT(nbt);
	if (tank.getFluid() != null) {
		nbt.setTag("FirstTank", tank.getFluid().writeToNBT(nbt));
	}

	return new Packet132TileEntityData(this.xCoord, this.yCoord, this.zCoord, 1, nbt);
}

@Override
public void onDataPacket(INetworkManager net, Packet132TileEntityData pkt)
{
	this.readFromNBT(pkt.data);
}





}

 

 

Here my Block Code:

 

BlockAPI (Block):

package speiger.src.api.common.blocks;

import java.util.List;
import java.util.Random;

import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import speiger.src.api.SpmodAPI;
import speiger.src.api.common.config.APIItems;
import speiger.src.api.common.functions.MachineRecipeMaker;
import speiger.src.api.common.functions.PathProxy;
import speiger.src.api.common.functions.TextureRegister;
import speiger.src.api.common.lib.APIIDs;
import speiger.src.api.common.tile.BCCompressor;
import speiger.src.api.common.tile.BasicCompressor;
import speiger.src.api.common.tile.BasicExpBench;
import speiger.src.api.common.tile.CobbleWorkbench;
import speiger.src.api.common.tile.ConverterExpBench;
import speiger.src.api.common.tile.Enchanter;
import speiger.src.api.common.tile.EssensCreater;
import speiger.src.api.common.tile.FurzMachine;
import speiger.src.api.common.tile.MobMachine;
import speiger.src.api.common.tile.TileAlphaTree;
import speiger.src.api.common.tile.TileEntityCobbleStorage;
import speiger.src.api.common.tile.TileFacing;
import speiger.src.api.common.tile.Ventil;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class BlockAPI extends BlockContainer 
{
Random rand = new Random();
public Class<? extends BasicCompressor> compressor = BasicCompressor.class;

public BlockAPI(int id) 
{
	super(id, Material.iron);
	setCreativeTab(SpmodAPI.spmodAPI);
	this.setHardness(5F);
	this.setResistance(5F);

}

Icon[] mobFront = new Icon[22];
Icon[] mobSide = new Icon[22];
Icon[] cobbleStorage = new Icon[3];
Icon[] basicExp = new Icon[3];
Icon[] advExp = new Icon[3];
Icon[] cobbleWork = new Icon[3];
Icon[] alpha = new Icon[2];
Icon[] furz = new Icon[6];
Icon[] compressors = new Icon[5];
Icon[] Ventil = new Icon[3];
Icon[] enchanter = new Icon[3];
Icon[] essens = new Icon[3];

    public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3)
    {
        par3.add(new ItemStack(par1, 1, 0));
        par3.add(new ItemStack(par1, 1, 1));
        par3.add(new ItemStack(par1, 1, 2));
        par3.add(new ItemStack(par1, 1, 3));
        par3.add(new ItemStack(par1, 1, 4));
        par3.add(new ItemStack(par1, 1, 5));
        par3.add(new ItemStack(par1, 1, 6));
        par3.add(new ItemStack(par1, 1, 7));
        par3.add(new ItemStack(par1, 1, );
        par3.add(new ItemStack(par1, 1, 9));
        par3.add(new ItemStack(par1, 1, 10));
    }



    
@Override
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z)
{
	int meta = world.getBlockMetadata(x, y, z);
	if(meta == 0)
	{
		TileEntity tile = world.getBlockTileEntity(x, y, z);
		if(tile != null && tile instanceof MobMachine)
		{
			MobMachine mob = (MobMachine) tile;
			if(mob.mode != -1)
			{
				ItemStack end = new ItemStack(APIItems.apiItem, 1, mob.mode);
				return end;
			}
			else
			{
				ItemStack end = new ItemStack(this.blockID, 1, meta);
				return end;
			}
		}
		else
		{
			ItemStack end = new ItemStack(this.blockID, 1, meta);
			return end;
		}
	}
	else
	{
		ItemStack end = new ItemStack(this.blockID, 1, meta);
		return end;
	}

}

    public int quantityDropped(Random par1Random)
    {
        return 1;
    }
    

    
@Override
public boolean isBlockNormalCube(World world, int x, int y, int z)
{
	TileEntity tile = world.getBlockTileEntity(x, y, z);
	if(tile != null && tile instanceof Ventil)
	{
		return true;
	}
	return false;
}




@Override
public boolean canConnectRedstone(IBlockAccess world, int x, int y, int z, int side)
{
	return true;
}




@Override
public Icon getBlockTexture(IBlockAccess world, int var1, int var2, int var3, int side)
{
	TileEntity tile = world.getBlockTileEntity(var1, var2, var3);
	int meta = world.getBlockMetadata(var1, var2, var3);
	if(tile instanceof MobMachine)
	{
		MobMachine mob = (MobMachine)tile;
		if(mob.mode == -1)
		{
			if(side == mob.faceing)return mobFront[0];
			else return mobSide[0];
		}
		else
		{
			if(side == mob.faceing)return mobFront[mob.mode];
			else return mobSide[mob.mode];
		}
	}

	if(tile instanceof TileFacing)
	{
		TileFacing face = (TileFacing)tile;
		if(meta == 1)
		{
			if(side == face.facing)return cobbleStorage[0];
			else if(side == 0 || side == 1)return cobbleStorage[1];
			else return cobbleStorage[2];
		}
		else if(meta == 2)
		{
			if(side == face.facing)return basicExp[0];
			else if(side == 0 || side == 1)return basicExp[1];
			else return basicExp[2];
		}
		else if(meta == 3)
		{
			if(side == face.facing)return advExp[0];
			else if(side == 0 || side == 1)return advExp[1];
			else return advExp[2];
		}
		else if(meta == 4)
		{
			if(side == face.facing)return cobbleWork[0];
			else if(side == 0 || side == 1)return cobbleWork[1];
			else return cobbleWork[2];
		}
		else if(meta == 5)
		{
			if(side == face.facing)return alpha[0];
			else return alpha[1];
		}
		else if(meta == 6)
		{
			return furz[side];
		}
		else if(meta == 7)
		{
			if(side == face.facing)return compressors[2];
			else if(side == 0)return compressors[0];
			else if(side == 1)return compressors[1];
			else if(side == ForgeDirection.getOrientation(face.facing).getOpposite().ordinal())return compressors[3];
			else return compressors[4];
		}
		else if(meta == 
		{
			if(side == 0)return Ventil[0];
			else if(side == 1)return Ventil[1];
			else return Ventil[2];
		}
		else if(meta == 9)
		{
			if(side == 0)return enchanter[0];
			else if(side == 1)return enchanter[1];
			else return enchanter[2];
		}
		else if(meta == 10)
		{
			if(side == face.facing)return essens[0];
			else if(side == 0 || side == 1)return essens[1];
			else return essens[2];
		}
	}

	return null;
}

@Override
public TileEntity createTileEntity(World var1, int meta) 
{
	if(meta == 0)return new MobMachine();
	else if(meta == 1)return new TileEntityCobbleStorage();
	else if(meta == 2)return new BasicExpBench();
	else if(meta == 3)return new ConverterExpBench();
	else if(meta == 4)return new CobbleWorkbench();
	else if(meta == 5)return new TileAlphaTree();
	else if(meta == 6)return new FurzMachine();
	else if(meta == 7)
	{
		if(Loader.isModLoaded("BuildCraft|Energy"))
		{
			return new BCCompressor();
		}
		return new BasicCompressor();
	}
	else if(meta == 8)return new Ventil();
	else if(meta == 9)return new Enchanter();
	else if(meta == 10)return new EssensCreater();
	return null;
}

@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister par1) 
{
	for(int i = 0; i<TextureRegister.mobMachineFront.length;i++)
	{
		mobFront[i] = par1.registerIcon(TextureRegister.mobMachineFront[i]);
		mobSide[i] = par1.registerIcon(TextureRegister.mobMachineSide[i]);
	}
	for(int i = 0; i<3;i++)
	{
		basicExp[i] = par1.registerIcon(TextureRegister.expBench[i]);
		cobbleStorage[i] = par1.registerIcon(TextureRegister.cobbleStorage[i]);
		cobbleWork[i] = par1.registerIcon(TextureRegister.cobbleBench[i]);
		advExp[i] = par1.registerIcon(TextureRegister.transBench[i]);
		enchanter[i] = par1.registerIcon(TextureRegister.enchanter[i]);
		essens[i] = par1.registerIcon(TextureRegister.essens[i]);
		Ventil[i] = par1.registerIcon(TextureRegister.ventil[i]);
	}
	for(int i = 0;i<TextureRegister.animalChunkLoader.length;i++)
	{
		this.furz[i] = par1.registerIcon(TextureRegister.animalChunkLoader[i]);
	}
	for(int i = 0;i<2;i++)
	{
		this.alpha[i] = par1.registerIcon(TextureRegister.alphaSapling[i]);
	}
	for(int i = 0;i<this.compressors.length;i++)
	{
		this.compressors[i] = par1.registerIcon(TextureRegister.compressor[i]);
	}
}



    
    @Override
@SideOnly(Side.CLIENT)
public Icon getIcon(int par1, int par2)
    {
    	if(par2 == 0)
    	{
		if(par1 == 3)return mobFront[0];
		else return mobSide[0];
    	}
    	else if(par2 == 1)
	{
		if(par1 == 3)return cobbleStorage[0];
		else if(par1 == 0 || par1 == 1)return cobbleStorage[1];
		else return cobbleStorage[2];
	}
	else if(par2 == 2)
	{
		if(par1 == 3)return basicExp[0];
		else if(par1 == 0 || par1 == 1)return basicExp[1];
		else return basicExp[2];
	}
	else if(par2 == 3)
	{
		if(par1 == 3)return advExp[0];
		else if(par1 == 0 || par1 == 1)return advExp[1];
		else return advExp[2];
	}
	else if(par2 == 4)
	{
		if(par1 == 3)return cobbleWork[0];
		else if(par1 == 0 || par1 == 1)return cobbleWork[1];
		else return cobbleWork[2];
	}
	else if(par2 == 5)
	{
		if(par1 == 3)return alpha[0];
		else return alpha[1];
	}
	else if(par2 == 6)
	{
		return furz[par1];
	}
	else if(par2 == 7)
	{
		if(par1 == 3)return compressors[2];
		else if(par1 == 0)return compressors[0];
		else if(par1 == 1)return compressors[1];
		else if(par1 == ForgeDirection.getOrientation(3).getOpposite().ordinal())return compressors[3];
		else return compressors[3];
	}
	else if(par2 == 
	{
		if(par1 == 0)return Ventil[0];
		else if(par1 == 1)return Ventil[1];
		else return Ventil[2];
	}
	else if(par2 == 9)
	{
		if(par1 == 0)return enchanter[0];
		else if(par1 == 1)return enchanter[1];
		else return enchanter[2];
	}
	else if(par2 == 10)
	{
		if(par1 == 3)return essens[0];
		else if(par1 == 0 || par1 == 1)return essens[1];
		else return essens[2];
	}
    	
    	return null;
}

    
    public int damageDropped(int par1)
    {
        return par1;
    }
    
    public int idDropped(int par1, Random par2Random, int par3)
    {
        return this.blockID;
    }
    

@Override
public void onBlockPlacedBy(World par1, int par2, int par3, int par4, EntityLivingBase par5, ItemStack var1) 
{
	TileEntity tile = par1.getBlockTileEntity(par2, par3, par4);
	int facing = MathHelper.floor_double(par5.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;
	int upanddown = Math.round(par5.rotationPitch);
	int rotation = 0;
        if (facing == 0) {
            rotation = ForgeDirection.NORTH.ordinal();
        }
        else if (facing == 1) {
            rotation = ForgeDirection.EAST.ordinal();
        }
        else if (facing == 2) {
            rotation = ForgeDirection.SOUTH.ordinal();
        }
        else if (facing == 3) {
            rotation = ForgeDirection.WEST.ordinal();
        }
        else
        {
        	rotation = ForgeDirection.NORTH.ordinal();
        }
        
        if(tile instanceof BasicCompressor)
        {
        	BasicCompressor basic = (BasicCompressor) tile;
        	basic.cound = 200;
        	basic.setFacing(rotation);
        }
        
        if(tile instanceof MobMachine)
        {
        	MobMachine mob = (MobMachine)tile;
        	mob.setFacing(rotation); 
        	if(mob.placed > 100)
        	{
        		par1.setBlock(par2, par3, par4, 0);
        		par1.markTileEntityForDespawn(mob);
        	}
        	if(!par1.isRemote)
        	{

            	if(mob.placed <= 100)
            	{
            		mob.placed++;
            	}
        	}
        	FMLLog.getLogger().info("Current Placed: "+mob.placed);
        }
        else if(tile instanceof TileFacing)
        {
        	TileFacing face = (TileFacing)tile;
        	face.setFacing(rotation);
        }
        else if(tile instanceof BasicExpBench)
        {
        	BasicExpBench beb = (BasicExpBench) tile;
        	beb.setFacing(rotation);
        }
        else
        {
        	return;
        }
}

public void fertilize(World par0, int x, int y, int z)
{
	TileEntity par1 = par0.getBlockTileEntity(x, y, z);
	if(par1 != null && par1 instanceof TileAlphaTree)
	{
		TileAlphaTree tile = (TileAlphaTree) par1;
		tile.count+=500;
		FMLLog.getLogger().info("GrowLevel: "+tile.count);
	}
}


@Override
public boolean onBlockActivated(World par1, int par2, int par3, int par4, EntityPlayer par5, int par6, float par7, float par8, float par9)
{
	TileEntity tileentity = par1.getBlockTileEntity(par2, par3, par4);

	int meta = par1.getBlockMetadata(par2, par3, par4);



	if(par5.isSneaking())
	{
		if(tileentity instanceof MobMachine)
		{
			MobMachine mob = (MobMachine)tileentity;
			mob.setFacing(PathProxy.setNextFacing(mob.getFacing()));
    			par1.markBlockForUpdate(par2, par3, par4);
    			par5.addExhaustion(3F);
    			par1.notifyBlocksOfNeighborChange(par2, par3, par4, this.blockID);
    			return true;
		}

		if(tileentity instanceof TileFacing)
		{
			TileFacing face = (TileFacing)tileentity;
			face.setFacing(PathProxy.setNextFacing(face.getFacing()));
    			par1.markBlockForUpdate(par2, par3, par4);
    			par5.addExhaustion(3F);
    			par1.notifyBlocksOfNeighborChange(par2, par3, par4, this.blockID);
    			return true;
		}

		return false;
	}


	ItemStack current = par5.inventory.getCurrentItem();


	if(!par1.isRemote)
	{
		if(meta == 
		{

			if(tileentity instanceof Ventil && current != null)
			{
				Ventil tile = (Ventil) tileentity;
				FluidStack available = tile.getTankInfo(ForgeDirection.UNKNOWN)[0].fluid;
				if(available != null && current.stackSize == 1)
				{
					ItemStack filled = FluidContainerRegistry.fillFluidContainer(available, current);
					if(filled != null)
					{
						FluidStack liquid = FluidContainerRegistry.getFluidForFilledItem(filled);
						if(liquid != null)
						{
							par5.inventory.setInventorySlotContents(par5.inventory.currentItem, filled);
							tile.drain(ForgeDirection.UNKNOWN, liquid.amount, true);
							return true;
						}
					}
				}
			}
		}

		if(meta == 0)
		{
			if(tileentity instanceof MobMachine)
			{
				MobMachine tile = (MobMachine)tileentity;
				if(tile.mode != -1)
				{
					if(tile != null)
					{
						par5.openGui(SpmodAPI.instance, APIIDs.mobmachineGUIID, par1, par2, par3, par4);
						return true;
					}	
				}
				else if(tile.mode == -1)
				{

					if(par5.getCurrentEquippedItem() == null)
					{
						par5.addChatMessage("Machine is not Initialized");
						return true;
					}
					else if(par5.getCurrentEquippedItem().getItem() == APIItems.apiItem)
					{
						par5.getCurrentEquippedItem().stackSize--;
						tile.setMode(par5.getCurrentEquippedItem().getItemDamage());
						tile.setFacing(tile.getFacing());
		    			par1.markBlockForUpdate(par2, par3, par4);
		    			par1.notifyBlocksOfNeighborChange(par2, par3, par4, this.blockID);
						par5.addChatMessage("Machine Initialized");
						return true;
					}
					else if(par5.getCurrentEquippedItem().getItem() == Item.porkRaw)//Pig
					{
						par5.getCurrentEquippedItem().stackSize--;
						tile.setMode(1);
						tile.setFacing(tile.getFacing());
		    			par1.markBlockForUpdate(par2, par3, par4);
		    			par1.notifyBlocksOfNeighborChange(par2, par3, par4, this.blockID);
		    			par5.addChatMessage("Machine Initialized");
		    			return true;

					}
					else if(par5.getCurrentEquippedItem().getItem() == APIItems.sheepbone)//Sheep
					{
						par5.getCurrentEquippedItem().stackSize--;
						tile.setMode(2);
						tile.setFacing(tile.getFacing());
		    			par1.markBlockForUpdate(par2, par3, par4);
		    			par5.addChatMessage("Machine Initialized");
		    			par1.notifyBlocksOfNeighborChange(par2, par3, par4, this.blockID);
						return true;
					}
					else if(par5.getCurrentEquippedItem().getItem() == Item.beefRaw)
					{
						par5.getCurrentEquippedItem().stackSize--;
						tile.setMode(3);
						tile.setFacing(tile.getFacing());
		    			par1.markBlockForUpdate(par2, par3, par4);
		    			par1.notifyBlocksOfNeighborChange(par2, par3, par4, this.blockID);
		    			par5.addChatMessage("Machine Initialized");
						return true;
					}
					else if(par5.getCurrentEquippedItem().getItem() == Item.chickenRaw)
					{
						par5.getCurrentEquippedItem().stackSize--;
						tile.setMode(4);
						tile.setFacing(tile.getFacing());
		    			par1.markBlockForUpdate(par2, par3, par4);
		    			par1.notifyBlocksOfNeighborChange(par2, par3, par4, this.blockID);
		    			par5.addChatMessage("Machine Initialized");
		    			return true;
					}
					else if(par5.getCurrentEquippedItem().getItem() == Item.dyePowder && par5.getCurrentEquippedItem().getItemDamage() == 0)
					{
						par5.getCurrentEquippedItem().stackSize--;
						tile.setMode(5);
						tile.setFacing(tile.getFacing());
		    			par1.markBlockForUpdate(par2, par3, par4);
		    			par1.notifyBlocksOfNeighborChange(par2, par3, par4, this.blockID);
		    			par5.addChatMessage("Machine Initialized");
						return true;
					}
					else if(par5.getCurrentEquippedItem().getItem() == APIItems.mooshroombone)
					{
						par5.getCurrentEquippedItem().stackSize--;
						tile.setMode(6);
						tile.setFacing(tile.getFacing());
		    			par1.markBlockForUpdate(par2, par3, par4);
		    			par1.notifyBlocksOfNeighborChange(par2, par3, par4, this.blockID);
		    			par5.addChatMessage("Machine Initialized");
						return true;
					}
					else if(par5.getCurrentEquippedItem().getItem() == Item.rottenFlesh)
					{
						par5.getCurrentEquippedItem().stackSize--;
						tile.setMode(7);
						tile.setFacing(tile.getFacing());
		    			par1.markBlockForUpdate(par2, par3, par4);
		    			par1.notifyBlocksOfNeighborChange(par2, par3, par4, this.blockID);
		    			par5.addChatMessage("Machine Initialized");
						return true;
					}
					else if(par5.getCurrentEquippedItem().getItem() == Item.bone)
					{
						par5.getCurrentEquippedItem().stackSize--;
						tile.setMode(;
						tile.setFacing(tile.getFacing());
		    			par1.markBlockForUpdate(par2, par3, par4);
		    			par1.notifyBlocksOfNeighborChange(par2, par3, par4, this.blockID);
		    			par5.addChatMessage("Machine Initialized");
						return true;
					}
					else if(par5.getCurrentEquippedItem().getItem() == Item.silk)
					{
						par5.getCurrentEquippedItem().stackSize--;
						tile.setMode(9);
						tile.setFacing(tile.getFacing());
		    			par1.markBlockForUpdate(par2, par3, par4);
		    			par1.notifyBlocksOfNeighborChange(par2, par3, par4, this.blockID);
		    			par5.addChatMessage("Machine Initialized");
						return true;
					}
					else if(par5.getCurrentEquippedItem().getItem() == Item.spiderEye)
					{
						par5.getCurrentEquippedItem().stackSize--;
						tile.setMode(10);
						tile.setFacing(tile.getFacing());
		    			par1.markBlockForUpdate(par2, par3, par4);
		    			par1.notifyBlocksOfNeighborChange(par2, par3, par4, this.blockID);
		    			par5.addChatMessage("Machine Initialized");
						return true;
					}
					else if(par5.getCurrentEquippedItem().getItem() == Item.goldNugget)
					{
						par5.getCurrentEquippedItem().stackSize--;
						tile.setMode(11);
						tile.setFacing(tile.getFacing());
		    			par1.markBlockForUpdate(par2, par3, par4);
		    			par1.notifyBlocksOfNeighborChange(par2, par3, par4, this.blockID);
		    			par5.addChatMessage("Machine Initialized");
						return true;
					}
					else if(par5.getCurrentEquippedItem().getItem() == Item.gunpowder)
					{
						par5.getCurrentEquippedItem().stackSize--;
						tile.setMode(12);
						tile.setFacing(tile.getFacing());
		    			par1.markBlockForUpdate(par2, par3, par4);
		    			par1.notifyBlocksOfNeighborChange(par2, par3, par4, this.blockID);
		    			par5.addChatMessage("Machine Initialized");
						return true;
					}
					else if(par5.getCurrentEquippedItem().getItem() == Item.ghastTear)
					{
						par5.getCurrentEquippedItem().stackSize--;
						tile.setMode(13);
						tile.setFacing(tile.getFacing());
		    			par1.markBlockForUpdate(par2, par3, par4);
		    			par1.notifyBlocksOfNeighborChange(par2, par3, par4, this.blockID);
		    			par5.addChatMessage("Machine Initialized");
						return true;
					}
					else if(par5.getCurrentEquippedItem().getItem() == Item.magmaCream)
					{
						par5.getCurrentEquippedItem().stackSize--;
						tile.setMode(14);
						tile.setFacing(tile.getFacing());
		    			par1.markBlockForUpdate(par2, par3, par4);
		    			par1.notifyBlocksOfNeighborChange(par2, par3, par4, this.blockID);
		    			par5.addChatMessage("Machine Initialized");
						return true;
					}
					else if(par5.getCurrentEquippedItem().getItem() == Item.slimeBall)
					{
						par5.getCurrentEquippedItem().stackSize--;
						tile.setMode(15);
						tile.setFacing(tile.getFacing());
		    			par1.markBlockForUpdate(par2, par3, par4);
		    			par1.notifyBlocksOfNeighborChange(par2, par3, par4, this.blockID);
		    			par5.addChatMessage("Machine Initialized");
						return true;
					}
					else if(par5.getCurrentEquippedItem().getItem() == Item.netherStalkSeeds)
					{
						par5.getCurrentEquippedItem().stackSize--;
						tile.setMode(16);
						tile.setFacing(tile.getFacing());
		    			par1.markBlockForUpdate(par2, par3, par4);
		    			par1.notifyBlocksOfNeighborChange(par2, par3, par4, this.blockID);
		    			par5.addChatMessage("Machine Initialized");
						return true;
					}
					else if(par5.getCurrentEquippedItem().getItem() == Item.skull && par5.getCurrentEquippedItem().getItemDamage() == 0)
					{
						par5.getCurrentEquippedItem().stackSize--;
						tile.setMode(17);
						tile.setFacing(tile.getFacing());
		    			par1.markBlockForUpdate(par2, par3, par4);
		    			par1.notifyBlocksOfNeighborChange(par2, par3, par4, this.blockID);
		    			par5.addChatMessage("Machine Initialized");
						return true;
					}
					else if(par5.getCurrentEquippedItem().getItem() == Item.enderPearl)
					{
						par5.getCurrentEquippedItem().stackSize--;
						tile.setMode(18);
						tile.setFacing(tile.getFacing());
		    			par1.markBlockForUpdate(par2, par3, par4);
		    			par1.notifyBlocksOfNeighborChange(par2, par3, par4, this.blockID);
		    			par5.addChatMessage("Machine Initialized");
						return true;
					}
					else if(par5.getCurrentEquippedItem().getItem() == Item.eyeOfEnder)
					{
						par5.getCurrentEquippedItem().stackSize--;
						tile.setMode(19);
						tile.setFacing(tile.getFacing());
		    			par1.markBlockForUpdate(par2, par3, par4);
		    			par5.addChatMessage("Machine Initialized");
		    			par1.notifyBlocksOfNeighborChange(par2, par3, par4, this.blockID);
						return true;
					}
					else if(par5.getCurrentEquippedItem().getItem() == Item.skull && par5.getCurrentEquippedItem().getItemDamage() == 1)
					{
						par5.getCurrentEquippedItem().stackSize--;
						tile.setMode(20);
						tile.setFacing(tile.getFacing());
		    			par1.markBlockForUpdate(par2, par3, par4);
		    			par1.notifyBlocksOfNeighborChange(par2, par3, par4, this.blockID);
		    			par5.addChatMessage("Machine Initialized");
						return true;
					}
					else if(par5.getCurrentEquippedItem().getItem() == Item.blazePowder)
					{
						par5.getCurrentEquippedItem().stackSize--;
						tile.setMode(21);
						tile.setFacing(tile.getFacing());
		    			par1.markBlockForUpdate(par2, par3, par4);
		    			par1.notifyBlocksOfNeighborChange(par2, par3, par4, this.blockID);
		    			par5.addChatMessage("Machine Initialized");
						return true;
					}
					else
					{
						par5.addChatMessage("Machine is not Initialized");
						return true;
					}


				}
			}

		}
		else
		{
			if(tileentity instanceof TileFacing)
			{
				TileFacing face = (TileFacing)tileentity;
				int id = 0;
				if(meta == 1)id = APIIDs.cobblestorageGUIID;
				else if(meta == 2)id = APIIDs.basicexpbenchGUIID;
				else if(meta == 3)id = APIIDs.converterexpbenchGUIID;
				else if(meta == 4)id = APIIDs.cobblestoneworkbenchGUIID;
				else if(meta == 7)id = APIIDs.compressorGUIID;
				else if(meta == 9)id = APIIDs.EnchanterGUIID;
				else if(meta == 10)id = APIIDs.EssensCreaterGUIID;
				if(face != null && id != 0)
				{
					par5.openGui(SpmodAPI.instance, id, par1, par2, par3, par4);
					if(meta == 7)
					{
						MachineRecipeMaker.getRecipes().updateRecipes();
					}
					return true;
				}


			}
		}
		if(meta == 5)
		{
			return false;
		}


	}

	return true;

}

public boolean addItemStackToInventory(InventoryPlayer par1, ItemStack par2)
{
	for (int i = 0; i < par1.getSizeInventory(); i++)
	{
		ItemStack current = par1.getStackInSlot(i);
		if (current != null)
		{
			if (current.isItemEqual(par2) && current.stackSize + par2.stackSize <= 64 && current.getMaxStackSize() > 1)
			{
				par1.getStackInSlot(i).stackSize += par2.stackSize;
				return true;
			}
		}
	}

	for (int i = 0; i < 36; i++)
	{
		ItemStack current = par1.getStackInSlot(i);
		if (current == null)
		{
			par1.setInventorySlotContents(i, par2);
			return true;
		}
	}

	return false;

}


public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6)
{
	if(par1World.getBlockTileEntity(par2, par3, par4) != null && par1World.getBlockTileEntity(par2, par3, par4) instanceof BasicCompressor)
	{
		((BasicCompressor)par1World.getBlockTileEntity(par2, par3, par4)).breaks();
	}
	dropInventory(par1World, par2, par3, par4);
	this.dropBlock(par1World, par2, par3, par4);
	if(par1World.getBlockTileEntity(par2, par3, par4) != null && par1World.getBlockTileEntity(par2, par3, par4) instanceof MobMachine)
	{
		((MobMachine)par1World.getBlockTileEntity(par2, par3, par4)).placed--;
	}



	super.breakBlock(par1World, par2, par3, par4, par5, par6);
}

public void dropBlock(World par0, int par1, int par2, int par3)
{
	int meta = par0.getBlockMetadata(par1, par2, par3);
	if(meta == 0)
	{
		MobMachine mm = (MobMachine)par0.getBlockTileEntity(par1, par2, par3);
		if(mm != null)
		{
			if(!(mm.mode == -1))
			{
				this.dropBlockAsItem_do(par0, par1, par2, par3, new ItemStack(APIItems.apiItem, 1, mm.mode));
			}
		}
	}
}

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



public static void doDistroyBlock(World world, int par1, int par2, int par3) 
{
	int meta = world.getBlockMetadata(par1, par2, par3);

	if(meta == 4)
	{
		world.setBlock(par1, par2, par3, 0);

	}

}
    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;
            }
        }
    }
    
public void updateTick(World world, int i, int j, int k, Random random)
    {
	notifyNeighbors(world, i, j, k);
	world.scheduleBlockUpdate(i, j, k, blockID, tickRate());
    }

public void onBlockDestroyedByPlayer(World world, int i, int j, int k, int l)
    {
	notifyNeighbors(world, i, j, k);
    }

public void notifyNeighbors(World world, int i, int j, int k)
{
	world.notifyBlocksOfNeighborChange(i, j, k, blockID);
	world.notifyBlocksOfNeighborChange(i, j - 1, k, blockID);
        world.notifyBlocksOfNeighborChange(i, j + 1, k, blockID);
        world.notifyBlocksOfNeighborChange(i - 1, j, k, blockID);
        world.notifyBlocksOfNeighborChange(i + 1, j, k, blockID);
        world.notifyBlocksOfNeighborChange(i, j, k - 1, blockID);
        world.notifyBlocksOfNeighborChange(i, j, k + 1, blockID);
}


public void onBlockAdded(World world, int i, int j, int k)
    {        
        world.scheduleBlockUpdate(i, j, k, blockID, tickRate());
    }

public int tickRate()
{
	return 1;
}



@Override
public boolean isFireSource(World world, int x, int y, int z, int metadata, ForgeDirection side)
{
	if(side == side.UP)
	{
		if(world.getBlockTileEntity(x, y, z) != null && world.getBlockTileEntity(x, y, z) instanceof Ventil)
		{
			Ventil tile = (Ventil) world.getBlockTileEntity(x, y, z);
			return tile.isFireSource();
		}
	}

	return super.isFireSource(world, x, y, z, metadata, side);
}



}

 

 

Posted

Hi

 

When it crashes, what does the error message say?

 

Can you use your IDE Profiler to tell where the server is spending all of its time? 

 

The vanilla code is also sprinkled with a lot of debugging logfile statements, every time it (eg) starts a tick or updates or entity - if you look at the log you might get a clue from that, if certain parts are taking an increasingly long time.

 

-TGG

Posted

I had no luck with Crashreports. The log say sometimes that the NBT does not work but i can not find the place where the mcp server does save his log files.

How do i activate the debug mode?

Posted

Hi

 

From the command line:

 

/debug start

 

and when you're finished

 

/debug stop

 

When you stop it will save to a file in .\debug

eg

 

forge\mcp\jars\debug\profile-results-2014-01-28_00.21.46.txt

 

It typically looks like this

 

 

---- Minecraft Profiler Results ----

// Now with less numbers

 

Time span: 44984 ms

Tick span: 302 ticks

// This is approximately 6.71 ticks per second. It should be 20 ticks per second

 

--- BEGIN PROFILE DUMP ---

 

[00] levels - 99.05%/99.05%

[01]  TestWorld-SpeedyTools - 99.91%/98.97%

[02]  tick - 99.40%/98.38%

[03]    entities - 90.58%/89.11%

[04]    regular - 99.28%/88.48%

[05]      tick - 94.21%/83.35%

[06]      ai - 46.40%/38.67%

[07]        newAi - 94.46%/36.53%

[08]        goalSelector - 33.17%/12.12%

[09]          unspecified - 83.61%/10.13%

[09]          canUse - 11.58%/1.40%

[09]          goalStart - 2.91%/0.35%

[10]          unspecified - 60.01%/0.21%

[10]          EntityAIWander - 36.45%/0.13%

[11]            pathfind - 99.53%/0.13%

[11]            unspecified - 0.47%/0.00%

[10]          EntityAILookIdle - 3.36%/0.01%

[10]          EntityAISwimming - 0.13%/0.00%

[10]          EntityAIWatchClosest - 0.04%/0.00%

[10]          EntityAIRestrictSun - 0.01%/0.00%

[09]          goalTick - 1.76%/0.21%

[09]          canContinue - 0.14%/0.02%

[08]        unspecified - 32.19%/11.76%

[08]        targetSelector - 16.98%/6.20%

[09]          unspecified - 93.03%/5.77%

[09]          goalTick - 3.26%/0.20%

[09]          goalStart - 2.79%/0.17%

[09]          canUse - 0.93%/0.06%

[08]        controls - 14.85%/5.42%

[09]          unspecified - 82.81%/4.49%

[09]          look - 7.31%/0.40%

[09]          jump - 5.01%/0.27%

[09]          move - 4.87%/0.26%

[08]        checkDespawn - 0.89%/0.32%

[08]        mob tick - 0.80%/0.29%

[08]        sensing - 0.64%/0.24%

[08]        navigation - 0.49%/0.18%

[07]        unspecified - 5.05%/1.95%

[07]        oldAi - 0.49%/0.19%

[08]        unspecified - 61.12%/0.11%

[08]        ai - 34.02%/0.06%

[08]        stroll - 3.79%/0.01%

[09]          pathfind - 96.92%/0.01%

[09]          unspecified - 3.08%/0.00%

[08]        followpath - 1.06%/0.00%

[06]      unspecified - 29.24%/24.37%

[06]      travel - 10.72%/8.94%

[07]        unspecified - 49.76%/4.45%

[07]        move - 29.72%/2.66%

[07]        rest - 20.51%/1.83%

[06]      entityBaseTick - 6.62%/5.52%

[07]        unspecified - 94.95%/5.24%

[07]        portal - 5.05%/0.28%

[06]      livingEntityBaseTick - 2.04%/1.70%

[06]      push - 1.08%/0.90%

[06]      move - 0.98%/0.81%

[06]      headTurn - 0.62%/0.51%

[06]      mobBaseTick - 0.54%/0.45%

[06]      chunkCheck - 0.47%/0.40%

[06]      rest - 0.43%/0.36%

[06]      jump - 0.32%/0.27%

[06]      looting - 0.31%/0.26%

[06]      rangeChecks - 0.23%/0.19%

[06]      portal - 0.01%/0.00%

[05]      unspecified - 5.33%/4.72%

[05]      remove - 0.46%/0.41%

[04]    unspecified - 0.58%/0.51%

[04]    remove - 0.09%/0.08%

[04]    tileEntities - 0.04%/0.04%

[04]    pendingTileEntities - 0.00%/0.00%

[04]    global - 0.00%/0.00%

[03]    tickTiles - 8.36%/8.23%

[04]    unspecified - 68.46%/5.63%

[04]    tickTiles - 11.83%/0.97%

[05]      unspecified - 98.24%/0.96%

[05]      checkLight - 1.60%/0.02%

[06]      unspecified - 77.70%/0.01%

[06]      getBrightness - 18.45%/0.00%

[06]      checkedPosition < toCheckCount - 3.85%/0.00%

[05]      checkedPosition < toCheckCount - 0.10%/0.00%

[05]      getBrightness - 0.06%/0.00%

[04]    moodSound - 4.34%/0.36%

[04]    iceandsnow - 4.27%/0.35%

[04]    checkLight - 3.48%/0.29%

[04]    tickChunk - 2.69%/0.22%

[05]      unspecified - 99.04%/0.22%

[05]      recheckGaps - 0.96%/0.00%

[06]      unspecified - 80.63%/0.00%

[06]      getBrightness - 14.82%/0.00%

[06]      checkedPosition < toCheckCount - 4.55%/0.00%

[04]    getChunk - 2.07%/0.17%

[04]    thunder - 1.50%/0.12%

[04]    buildList - 0.97%/0.08%

[04]    playerCheckLight - 0.39%/0.03%

[05]      unspecified - 75.41%/0.02%

[05]      getBrightness - 21.37%/0.01%

[05]      checkedPosition < toCheckCount - 3.22%/0.00%

[03]    mobSpawner - 0.64%/0.63%

[03]    unspecified - 0.23%/0.23%

[03]    chunkSource - 0.07%/0.07%

[03]    portalForcer - 0.04%/0.04%

[03]    tickPending - 0.03%/0.03%

[04]    unspecified - 88.32%/0.03%

[04]    ticking - 7.02%/0.00%

[04]    cleaning - 4.67%/0.00%

[03]    village - 0.03%/0.03%

[03]    chunkMap - 0.02%/0.02%

[02]  tracker - 0.43%/0.43%

[02]  unspecified - 0.15%/0.15%

[02]  timeSync - 0.01%/0.01%

[02]  pools - 0.00%/0.00%

[01]  unspecified - 0.09%/0.09%

[00] connection - 0.84%/0.84%

[01]  packetflow - 97.10%/0.82%

[02]  unspecified - 82.55%/0.68%

[02]  travel - 8.99%/0.07%

[03]    unspecified - 45.21%/0.03%

[03]    rest - 36.19%/0.03%

[03]    move - 18.60%/0.01%

[02]  entityBaseTick - 2.93%/0.02%

[03]    unspecified - 90.59%/0.02%

[03]    portal - 9.41%/0.00%

[02]  ai - 1.57%/0.01%

[03]    unspecified - 77.95%/0.01%

[03]    oldAi - 22.05%/0.00%

[02]  livingEntityBaseTick - 1.21%/0.01%

[02]  move - 0.93%/0.01%

[02]  rest - 0.92%/0.01%

[02]  push - 0.42%/0.00%

[02]  headTurn - 0.23%/0.00%

[02]  rangeChecks - 0.14%/0.00%

[02]  jump - 0.11%/0.00%

[01]  unspecified - 2.55%/0.02%

[01]  keepAlive - 0.28%/0.00%

[01]  playerTick - 0.07%/0.00%

[00] unspecified - 0.09%/0.09%

[00] dim_unloading - 0.00%/0.00%

[00] tallying - 0.00%/0.00%

[00] players - 0.00%/0.00%

[00] snooper - 0.00%/0.00%

[00] tickables - 0.00%/0.00%

--- END PROFILE DUMP ---

 

 

 

so if you leave it run for a minute or so at the start, then again for another minute when your server is getting really laggy, you might see an obvious difference in one of the sections.  That might be enough of a clue to narrow it down.

 

Of course, if your IDE supports profiling then that's probably even better...

 

-TGG

 

 

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.

Announcements



×
×
  • Create New...

Important Information

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