Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

knokko

Members
  • Joined

  • Last visited

Everything posted by knokko

  1. I make commands with classes that do not extend CommandBase, but implements ICommand. So you can use that too, I don't believe it is very important what you do.
  2. Add this to you initializationEvent: "GameRegistry.registerWorldGenerator(new RPGGenerator(), 1);". But use instead of my class a new class that implements IWorldGenerator. If you have eclipse, you can use "add unimplement methods" to get the method you will have to use. That method is called every time a new chunk is generated, I hope I have you told enough.
  3. I allready know that a player has another posY on the server and client. I have allready solved this by using the boundingbox.minY + height * 0.8, this is the same on client and server. The strangest I found was that the rayTrace was acting very stange when a player looks down and on the server side, if you look at the console messages what the line is. The rayTrace method of EntityLivingBase seems to look directly at the ground when it is called on server side AND the entity is looking down a little bit. The way I check the entity in the line is not very difficult: I make a sort of formula with the line first, and than I check if the formula works on the entity. I make 2 of them because it is a 3D world.
  4. Do you have a difficult model or a simple model? ModelClasses are a bit difficult so if the model is simple, you can better remake it.
  5. hello guys, I am trying to get all entities in a raytrace. I have made a class called Line and a working method to get all the entities in it. But there is a problem with the raytrace of the player: if the player is looking down, the list is glitching on the server side, but not on the client side. If the player is look upwards, the method works great. Here are the important methods: public class TestItem extends Item { public ItemStack onItemRightClick(ItemStack item, World world, EntityPlayer player){ player.swingItem(); Line line = Line.fromRaytrace(player); Line line2 = new Line(new Position(10,10,10), new Position(0,0,0)); line.spawnParticles(world, 0.1, 10, 10, 0.001); System.out.println(line.getEntities(world, Entity.class) + " " + world.isRemote); //System.out.println(player.height * 0.8 + player.boundingBox.minY); return item; } } public List getEntities(World world, Class entityClass){ refresh(); double minX = Math.min(position1.x, position2.x); double maxX = Math.max(position1.x, position2.x); double minY = Math.min(position1.y, position2.y); double maxY = Math.max(position1.y, position2.y); double minZ = Math.min(position1.z, position2.z); double maxZ = Math.max(position1.z, position2.z); //System.out.println("minX = " + minX + " maxX = " + maxX + " minY = " + minY + " maxY = " + maxY + " minZ = " + minZ + " maxZ = " + maxZ + " isRemote = " + world.isRemote); List entities = world.getEntitiesWithinAABB(entityClass, AxisAlignedBB.getBoundingBox(minX, minY, minZ, maxX, maxY, maxZ)); //System.out.println("entities = " + entities + " isRemote = " + world.isRemote); double factorXY = ExtraFeatures.divineAccurate(distanceYT, distanceXT); double factorXZ = ExtraFeatures.divineAccurate(distanceZT, distanceXT); double bufferXY = position1.y - (position1.x * factorXY); double bufferXZ = position1.z - (position1.x * factorXZ); //System.out.println("factorXY = " + factorXY + " factorXZ = " + factorXZ + " bufferXY = " + bufferXY + " bufferXZ = " + bufferXZ + " isRemote = " + world.isRemote); List entities2 = new ArrayList(); int times = 0; while(times < entities.size()){ Entity entity = (Entity) entities.get(times); AxisAlignedBB aabb = entity.boundingBox; //System.out.println("boundingbox = " + aabb + " entity = " + entity + " isRemote = " + world.isRemote); //System.out.println("rotationYaw = " + entity.rotationYaw + " rotationPitch = " + entity.rotationPitch + " entity = " + entity); double d = (aabb.minX * factorXY) + bufferXY; double e = (aabb.maxX * factorXY) + bufferXY; double m = (aabb.minX * factorXZ) + bufferXZ; double n = (aabb.maxX * factorXZ) + bufferXZ; //System.out.println("d = " + d + " e = " + e + " m = " + m + " n = " + n + " entity = " + entity + "isRemote = " + world.isRemote); boolean flag1 = m <= aabb.maxZ && n >= aabb.minZ || m >= aabb.minZ && n <= aabb.maxZ; boolean flag2 = d <= aabb.maxY && e >= aabb.minY || d >= aabb.minY && e <= aabb.maxY; if(flag1 && flag2){ entities2.add(entity); } ++times; } System.out.println("line = " + this + " isRemote = " + world.isRemote); return entities2; } public static Line fromRaytrace(EntityLivingBase entity){ Position pos1 = new Position(entity.posX, entity.height * 0.8 + entity.boundingBox.minY, entity.posZ); Position pos2 = new Position(entity.rayTrace(100, 1)); return new Line(pos1, pos2); } Here is the whole line class: public class Line { public Line(Position pos1, Position pos2){ position1 = pos1; position2 = pos2; refresh(); } private Position position1; private Position position2; public double distanceX; public double distanceY; public double distanceZ; protected double distanceXT; protected double distanceYT; protected double distanceZT; public double distance; public void refresh(){ distanceX = position2.x - position1.x; distanceY = position2.y - position1.y; distanceZ = position2.z - position1.z; distanceXT = distanceX; distanceYT = distanceY; distanceZT = distanceZ; if(distanceX < 0){ distanceX *= -1; } if(distanceY < 0){ distanceY *= -1; } if(distanceZ < 0){ distanceZ *= -1; } double distanceXZ = Math.hypot(distanceX, distanceZ); distance = Math.hypot(distanceXZ, distanceY); } public Position getPosition(int i){ if(i <= 1){ return position1; } else { return position2; } } public void setPosition(int i, Position pos){ if(i <= 1){ position1 = pos; } else { position2 = pos; } refresh(); } /** * * @param world the world to spawn the particles. * @param red how red the particles will be. * @param green how green the particles will be. * @param blue how blue the particles will be. * @param dbp distance between particles. */ public void spawnParticles(World world, double red, double green, double blue, double dbp){ double speedX = distanceXT * dbp; double speedY = distanceYT * dbp; double speedZ = distanceZT * dbp; double x = position1.x; double y = position1.y; double z = position1.z; int times = 0; int particles = ExtraFeatures.fromDouble(ExtraFeatures.divineAccurate(position1.getSquaredDistance(position2), dbp)); while(times <= particles){ world.spawnParticle("reddust", x, y, z, red, green, blue); x += speedX; y += speedY; z += speedZ; ++times; } } public String toString(){ return "Line: distance = " + distance + " position1 = [" + position1 + "], position2 = [" + position2 + "]"; } public List getEntities(World world, Class entityClass){ refresh(); double minX = Math.min(position1.x, position2.x); double maxX = Math.max(position1.x, position2.x); double minY = Math.min(position1.y, position2.y); double maxY = Math.max(position1.y, position2.y); double minZ = Math.min(position1.z, position2.z); double maxZ = Math.max(position1.z, position2.z); //System.out.println("minX = " + minX + " maxX = " + maxX + " minY = " + minY + " maxY = " + maxY + " minZ = " + minZ + " maxZ = " + maxZ + " isRemote = " + world.isRemote); List entities = world.getEntitiesWithinAABB(entityClass, AxisAlignedBB.getBoundingBox(minX, minY, minZ, maxX, maxY, maxZ)); //System.out.println("entities = " + entities + " isRemote = " + world.isRemote); double factorXY = ExtraFeatures.divineAccurate(distanceYT, distanceXT); double factorXZ = ExtraFeatures.divineAccurate(distanceZT, distanceXT); double bufferXY = position1.y - (position1.x * factorXY); double bufferXZ = position1.z - (position1.x * factorXZ); //System.out.println("factorXY = " + factorXY + " factorXZ = " + factorXZ + " bufferXY = " + bufferXY + " bufferXZ = " + bufferXZ + " isRemote = " + world.isRemote); List entities2 = new ArrayList(); int times = 0; while(times < entities.size()){ Entity entity = (Entity) entities.get(times); AxisAlignedBB aabb = entity.boundingBox; //System.out.println("boundingbox = " + aabb + " entity = " + entity + " isRemote = " + world.isRemote); //System.out.println("rotationYaw = " + entity.rotationYaw + " rotationPitch = " + entity.rotationPitch + " entity = " + entity); double d = (aabb.minX * factorXY) + bufferXY; double e = (aabb.maxX * factorXY) + bufferXY; double m = (aabb.minX * factorXZ) + bufferXZ; double n = (aabb.maxX * factorXZ) + bufferXZ; //System.out.println("d = " + d + " e = " + e + " m = " + m + " n = " + n + " entity = " + entity + "isRemote = " + world.isRemote); boolean flag1 = m <= aabb.maxZ && n >= aabb.minZ || m >= aabb.minZ && n <= aabb.maxZ; boolean flag2 = d <= aabb.maxY && e >= aabb.minY || d >= aabb.minY && e <= aabb.maxY; if(flag1 && flag2){ entities2.add(entity); } ++times; } System.out.println("line = " + this + " isRemote = " + world.isRemote); return entities2; } public static Line fromRaytrace(EntityLivingBase entity){ Position pos1 = new Position(entity.posX, entity.height * 0.8 + entity.boundingBox.minY, entity.posZ); Position pos2 = new Position(entity.rayTrace(100, 1)); return new Line(pos1, pos2); } } Here is the position class: public class Position { public double x; public double y; public double z; /** * Creates a new position on the given location. * @param posX The x location of the position. * @param posY The y location of the position. * @param posZ The z location of the given position. */ public Position(double posX, double posY, double posZ){ x = posX; y = posY; z = posZ; } /** * Creates a new position on the given location, this constructor works with integers. * @param posX The x location of the position. * @param posY The y location of the position. * @param posZ The z location of the given position. */ public Position(int posX, int posY, int posZ){ x = posX; y = posY; z = posZ; } /** * Creates a new position on the given location, this constructor works with floats. * @param posX The x location of the position. * @param posY The y location of the position. * @param posZ The z location of the given position. */ public Position(float posX, float posY, float posZ){ x = posX; y = posY; z = posZ; } /** * Creates a new position at the given entity. * @param entity The entity where the position has to be created. */ public Position(Entity entity){ x = entity.posX; y = entity.posY; z = entity.posZ; } public Position(MovingObjectPosition mop){ x = mop.hitVec.xCoord; y = mop.hitVec.yCoord; z = mop.hitVec.zCoord; } public Position(Vec3 vec3){ x = vec3.xCoord; y = vec3.yCoord; z = vec3.zCoord; } /** * Returns this position as string. */ public String toString(){ String string = "Position: x = " + x + ", y = " + y + ", z = " + z; return string; } /** * Makes a string for the given position. * @param p * @return the string. */ public static String makeString(Position p){ return p.toString(); } /** * Gives the x of this position as integer. * @return The integer the double is the closest to. */ public int intX(){ double t = x - (int)x; if(t >= 0.5){ t = 1; } else { t = 0; } return (int) ((int)x + t); } /** * Gives the y of this position as integer. * @return The integer the double is the closest to. */ public int intY(){ double t = y - (int)y; if(t >= 0.5){ t = 1; } else { t = 0; } return (int) ((int)y + t); } /** * Gives the z of this position as integer. * @return The integer the double is the closest to. */ public int intZ(){ double t = z - (int)z; if(t >= 0.5){ t = 1; } else { t = 0; } return (int) ((int)z + t); } /** * this method gives the x of the position as float. * @return The x of the position as float. */ public float floatX(){ return (float) x; } /** * this method gives the y of the position as float. * @return The y of the position as float. */ public float floatY(){ return (float)y; } /** * this method gives the z of the position as float. * @return The z of the position as float. */ public float floatZ(){ return (float)z; } /** * Gives the squared distance to another position. It will use Math.hypot for getting it. * @param p The other position. * @return The squared distance from this position to the given position. */ public double getSquaredDistance(Position p){ double distanceX; double distanceY; double distanceZ; if(x >= p.x){ distanceX = x - p.x; } else { distanceX = p.x - x; } if(y >= p.y){ distanceY = y - p.y; } else { distanceY = p.y - y; } if(z >= p.z){ distanceZ = z - p.z; } else { distanceZ = p.z - z; } double distanceXZ = Math.hypot(distanceX, distanceZ); return Math.hypot(distanceXZ, distanceY); } /** * Gives the distance to the given position. This will just use distanceX + distanceY + distanceZ. * @param p The other position. * @return The distance to the given position. */ public double getIndirectDistance(Position p){ double distanceX; double distanceY; double distanceZ; if(x >= p.x){ distanceX = x - p.x; } else { distanceX = p.x - x; } if(y >= p.y){ distanceY = y - p.y; } else { distanceY = p.y - y; } if(z >= p.z){ distanceZ = z - p.z; } else { distanceZ = p.z - z; } return distanceX + distanceY + distanceZ; } /** * Gives the squared distance between two positions. It will use Math.hypot. * @param a The first position. * @param p The second position. * @return The squared distance between the two positions. */ public static double getSquaredDistance(Position a, Position p){ double distanceX; double distanceY; double distanceZ; if(a.x >= p.x){ distanceX = a.x - p.x; } else { distanceX = p.x - a.x; } if(a.y >= p.y){ distanceY = a.y - p.y; } else { distanceY = p.y - a.y; } if(a.z >= p.z){ distanceZ = a.z - p.z; } else { distanceZ = p.z - a.z; } double distanceXZ = Math.hypot(distanceX, distanceZ); return Math.hypot(distanceXZ, distanceY); } /** * Gives the distance between the given positions. This will just use distanceX + distanceY + distanceZ. * @param p The first position. * @param a The second position. * @return The distance between the given positions. */ public static double getIndirectDistance(Position a, Position p){ double distanceX; double distanceY; double distanceZ; if(a.x >= p.x){ distanceX = a.x - p.x; } else { distanceX = p.x - a.x; } if(a.y >= p.y){ distanceY = a.y - p.y; } else { distanceY = p.y - a.y; } if(a.z >= p.z){ distanceZ = a.z - p.z; } else { distanceZ = p.z - a.z; } return distanceX + distanceY + distanceZ; } /** * This method will write itself in the given NBTTagCompound. * It will set a tag with the given key, and set the doubles there. * This method is not called automatically, so save it where you need it. * Be sure to use the same key at readFromNBt and to use another key for every position. * @param nbt The NBTTagCompound where it will save its position. * @param key The key it will use to create a new tag. */ public void writeToNBT(NBTTagCompound nbt, String key){ NBTTagCompound a = new NBTTagCompound(); a.setDouble("x", x); a.setDouble("y", y); a.setDouble("z", z); nbt.setTag(key, a); } /** * This method is made to read the position from the given NBTTagCompound. * Be sure to use the same NBTTagCompound and string as writeToNBT. * @param nbt The NBTTagCompound it will use to read the position. * @param key The tag of the NBTTagCompound it will check. */ public void readFromNBT(NBTTagCompound nbt, String key){ x = nbt.getCompoundTag(key).getDouble("x"); y = nbt.getCompoundTag(key).getDouble("y"); z = nbt.getCompoundTag(key).getDouble("z"); } /** * Spawns an entity at the given position. * @param p The position the entity has to spawn. * @param entity The entity to spawn. * @param world The world to spawn the entity. */ public static void spawnEntity(Position p, Entity entity, World world){ entity.posX = p.x; entity.posY = p.y; entity.posZ = p.z; world.spawnEntityInWorld(entity); } /** * Spawns an entity at this position. * @param entity The entity to spawn. * @param world The world to spawn the entity. */ public void spawnEntity(Entity entity, World world){ entity.posX = x; entity.posY = y; entity.posZ = z; world.spawnEntityInWorld(entity); } /** * Sets a block at the given position. * @param p The position to place the block. * @param world The world to set the block. * @param block The block to set. */ public static void setBlock(Position p, World world, Block block){ world.setBlock(p.intX(), p.intY(), p.intZ(), block); } /** * Sets a block at this position. * @param world The world to place the block. * @param block The block to place. */ public void setBlock(World world, Block block){ world.setBlock(intX(), intY(), intZ(), block); } /** * Spawns a particle at the given position with the given colors. * @param world The world to spawn the particle. * @param p The position to spawn the particle. * @param color1 The amount red. * @param color2 The amount green. * @param color3 The amount purple/blue. */ public static void spawnParticle(World world, Position p, double color1, double color2, double color3){ world.spawnParticle("reddust", p.x, p.y, p.z, color1, color2, color3); } /** * Spawn a particle at this position with the given colors. * @param world The world to spawn the particle. * @param color1 The amount red. * @param color2 The amount green. * @param color3 The amount purple/blue. */ public void spawnParticle(World world, double color1, double color2, double color3){ world.spawnParticle("reddust", x, y, z, color1, color2, color3); } } The lines in the console are like this: if I am looking upwards: if I am looking down: Can anybody explain why the raytrace is doing so strange on the server?
  6. tile is probably null because that methods causes a nullpointerexception. But I don't know how that is possible because the method you get your tileentity seems to be good. Try System.out.println(tile); Maybe this will help to understand the problem.
  7. System.out.println(slots); will show your slot in the console. Use this on writeToNBT and readFromNBT and you will know more.
  8. If you want to drop the items, you can better use entity.attackEntityFrom(DamageSource.causePlayerDamage(player),2000000F)
  9. Ok, that sounds good. But I only know how to spawn particles with world#spawnParticle(World, double, double, double, double, double, double); And spawning particles as a normal entity makes it an ugly cube, does anybody know how to spawn particles on another way?
  10. hello guys, I was wondering it is possible to render particles from further than 16 blocks without too much work? Is this possible and/or is there an easy way to make them visible from a further distance?
  11. I don't see an @Override annotation above your nbt methods, and most of your methods have one. Maybe it is not overriding, but I am not sure.
  12. The idea of calculating the number of particles to spawn worked. But I still want to know why only the serverside freezed, it was called on client and server. (otherwise I couldn't see the particles.) Can someone find out why?
  13. hello guys, I am making a method to spawn particles on every point of a line. It makes the particles succesfully, but I found a really big and strange problem: If I use that method, all entities in the world stop moving and are immume to communications with player, if I close the world, minecraft freezes... The problem disappeares if I remove the while statement in the method. Here is the method: public void spawnParticles(World world, double red, double green, double blue, double dbp){ double distanceXT = position2.x - position1.x; double distanceYT = position2.y - position1.y; double distanceZT = position2.z - position1.z; double speedX = distanceXT * dbp; double speedY = distanceYT * dbp; double speedZ = distanceZT * dbp; double x = position1.x; double y = position1.y; double z = position1.z; double minX = position1.x; double maxX = position2.x; if(minX > position2.x){ minX = position2.x; maxX = position1.x; } while(x <= maxX && x >= minX){ world.spawnParticle("reddust", x, y, z, red, green, blue); x += speedX; y += speedY; z += speedZ; }//TODO big problem } Here is the whole class: public class Line { public Line(Position pos1, Position pos2){ position1 = pos1; position2 = pos2; refreshDistance(); } private Position position1; private Position position2; public double distanceX; public double distanceY; public double distanceZ; public double distance; public void refreshDistance(){ distanceX = position2.x - position1.x; distanceY = position2.y - position1.y; distanceZ = position2.z - position1.z; if(distanceX < 0){ distanceX *= -1; } if(distanceY < 0){ distanceY *= -1; } if(distanceZ < 0){ distanceZ *= -1; } double distanceXZ = Math.hypot(distanceX, distanceZ); distance = Math.hypot(distanceXZ, distanceY); } public Position getPosition(int i){ if(i <= 1){ return position1; } else { return position2; } } public void setPosition(int i, Position pos){ if(i <= 1){ position1 = pos; } else { position2 = pos; } refreshDistance(); } /** * * @param world the world to spawn the particles. * @param red how red the particles will be. * @param green how green the particles will be. * @param blue how blue the particles will be. * @param dbp distance between particles. */ public void spawnParticles(World world, double red, double green, double blue, double dbp){ double distanceXT = position2.x - position1.x; double distanceYT = position2.y - position1.y; double distanceZT = position2.z - position1.z; double speedX = distanceXT * dbp; double speedY = distanceYT * dbp; double speedZ = distanceZT * dbp; double x = position1.x; double y = position1.y; double z = position1.z; double minX = position1.x; double maxX = position2.x; if(minX > position2.x){ minX = position2.x; maxX = position1.x; } while(x <= maxX && x >= minX){ world.spawnParticle("reddust", x, y, z, red, green, blue); x += speedX; y += speedY; z += speedZ; }//TODO big problem } public List getEntities(World world, Class entityClass){ double x1 = position1.x; double x2 = position2.x; if(x1 > position2.x){ x1 = position2.x; x2 = position1.x; } double y1 = position1.y; double y2 = position2.y; if(y1 > position2.y){ y1 = position2.y; y2 = position1.y; } double z1 = position1.z; double z2 = position2.z; if(z1 > position2.z){ z1 = position2.z; z2 = position1.z; } List entities2 = new ArrayList(); List entities = world.getEntitiesWithinAABB(entityClass, AxisAlignedBB.getBoundingBox(x1, y1, z1, x2, y2, z2)); int times = 0; double factor = ExtraFeatures.divineAccurate(position2.y - position1.y, position2.x - position1.x); System.out.println(factor); while(times < entities.size()){ Entity entity = (Entity) entities.get(times); AxisAlignedBB aabb = entity.boundingBox; if(aabb != null){ double a = aabb.minX - x1; double b = aabb.maxX - x1; double c = aabb.minY - y1; double d = aabb.maxY - y1; if(a <= d && b >= c){ entities2.add(entity); } else { System.out.println("id: " + entity.getUniqueID() + " xMin: " + aabb.minX + " xMax: " + aabb.maxX + " yMin: " + aabb.minY + " yMax: " + aabb.maxY + " a,b,c,d " + a + " " + b + " " + c + " " + d); } } else { System.out.println(entity + " " + aabb); } ++times; } //TODO work in progress return entities2; } } And here is position.java if you need it: public class Position { public double x; public double y; public double z; /** * Creates a new position on the given location. * @param posX The x location of the position. * @param posY The y location of the position. * @param posZ The z location of the given position. */ public Position(double posX, double posY, double posZ){ x = posX; y = posY; z = posZ; } /** * Creates a new position on the given location, this constructor works with integers. * @param posX The x location of the position. * @param posY The y location of the position. * @param posZ The z location of the given position. */ public Position(int posX, int posY, int posZ){ x = posX; y = posY; z = posZ; } /** * Creates a new position on the given location, this constructor works with floats. * @param posX The x location of the position. * @param posY The y location of the position. * @param posZ The z location of the given position. */ public Position(float posX, float posY, float posZ){ x = posX; y = posY; z = posZ; } /** * Creates a new position at the given entity. * @param entity The entity where the position has to be created. */ public Position(Entity entity){ x = entity.posX; y = entity.posY; z = entity.posZ; } public Position(MovingObjectPosition mop){ x = mop.hitVec.xCoord; y = mop.hitVec.yCoord; z = mop.hitVec.zCoord; } /** * Returns this position as string. */ public String toString(){ String string = x + "," + y + "," + z; return string; } /** * Makes a string for the given position. * @param p * @return the string. */ public static String makeString(Position p){ return p.toString(); } /** * Gives the x of this position as integer. * @return The integer the double is the closest to. */ public int intX(){ double t = x - (int)x; if(t >= 0.5){ t = 1; } else { t = 0; } return (int) ((int)x + t); } /** * Gives the y of this position as integer. * @return The integer the double is the closest to. */ public int intY(){ double t = y - (int)y; if(t >= 0.5){ t = 1; } else { t = 0; } return (int) ((int)y + t); } /** * Gives the z of this position as integer. * @return The integer the double is the closest to. */ public int intZ(){ double t = z - (int)z; if(t >= 0.5){ t = 1; } else { t = 0; } return (int) ((int)z + t); } /** * this method gives the x of the position as float. * @return The x of the position as float. */ public float floatX(){ return (float) x; } /** * this method gives the y of the position as float. * @return The y of the position as float. */ public float floatY(){ return (float)y; } /** * this method gives the z of the position as float. * @return The z of the position as float. */ public float floatZ(){ return (float)z; } /** * Gives the squared distance to another position. It will use Math.hypot for getting it. * @param p The other position. * @return The squared distance from this position to the given position. */ public double getSquaredDistance(Position p){ double distanceX; double distanceY; double distanceZ; if(x >= p.x){ distanceX = x - p.x; } else { distanceX = p.x - x; } if(y >= p.y){ distanceY = y - p.y; } else { distanceY = p.y - y; } if(z >= p.z){ distanceZ = z - p.z; } else { distanceZ = p.z - z; } double distanceXZ = Math.hypot(distanceX, distanceZ); return Math.hypot(distanceXZ, distanceY); } /** * Gives the distance to the given position. This will just use distanceX + distanceY + distanceZ. * @param p The other position. * @return The distance to the given position. */ public double getIndirectDistance(Position p){ double distanceX; double distanceY; double distanceZ; if(x >= p.x){ distanceX = x - p.x; } else { distanceX = p.x - x; } if(y >= p.y){ distanceY = y - p.y; } else { distanceY = p.y - y; } if(z >= p.z){ distanceZ = z - p.z; } else { distanceZ = p.z - z; } return distanceX + distanceY + distanceZ; } /** * Gives the squared distance between two positions. It will use Math.hypot. * @param a The first position. * @param p The second position. * @return The squared distance between the two positions. */ public static double getSquaredDistance(Position a, Position p){ double distanceX; double distanceY; double distanceZ; if(a.x >= p.x){ distanceX = a.x - p.x; } else { distanceX = p.x - a.x; } if(a.y >= p.y){ distanceY = a.y - p.y; } else { distanceY = p.y - a.y; } if(a.z >= p.z){ distanceZ = a.z - p.z; } else { distanceZ = p.z - a.z; } double distanceXZ = Math.hypot(distanceX, distanceZ); return Math.hypot(distanceXZ, distanceY); } /** * Gives the distance between the given positions. This will just use distanceX + distanceY + distanceZ. * @param p The first position. * @param a The second position. * @return The distance between the given positions. */ public static double getIndirectDistance(Position a, Position p){ double distanceX; double distanceY; double distanceZ; if(a.x >= p.x){ distanceX = a.x - p.x; } else { distanceX = p.x - a.x; } if(a.y >= p.y){ distanceY = a.y - p.y; } else { distanceY = p.y - a.y; } if(a.z >= p.z){ distanceZ = a.z - p.z; } else { distanceZ = p.z - a.z; } return distanceX + distanceY + distanceZ; } /** * This method will write itself in the given NBTTagCompound. * It will set a tag with the given key, and set the doubles there. * This method is not called automatically, so save it where you need it. * Be sure to use the same key at readFromNBt and to use another key for every position. * @param nbt The NBTTagCompound where it will save its position. * @param key The key it will use to create a new tag. */ public void writeToNBT(NBTTagCompound nbt, String key){ NBTTagCompound a = new NBTTagCompound(); a.setDouble("x", x); a.setDouble("y", y); a.setDouble("z", z); nbt.setTag(key, a); } /** * This method is made to read the position from the given NBTTagCompound. * Be sure to use the same NBTTagCompound and string as writeToNBT. * @param nbt The NBTTagCompound it will use to read the position. * @param key The tag of the NBTTagCompound it will check. */ public void readFromNBT(NBTTagCompound nbt, String key){ x = nbt.getCompoundTag(key).getDouble("x"); y = nbt.getCompoundTag(key).getDouble("y"); z = nbt.getCompoundTag(key).getDouble("z"); } /** * Spawns an entity at the given position. * @param p The position the entity has to spawn. * @param entity The entity to spawn. * @param world The world to spawn the entity. */ public static void spawnEntity(Position p, Entity entity, World world){ entity.posX = p.x; entity.posY = p.y; entity.posZ = p.z; world.spawnEntityInWorld(entity); } /** * Spawns an entity at this position. * @param entity The entity to spawn. * @param world The world to spawn the entity. */ public void spawnEntity(Entity entity, World world){ entity.posX = x; entity.posY = y; entity.posZ = z; world.spawnEntityInWorld(entity); } /** * Sets a block at the given position. * @param p The position to place the block. * @param world The world to set the block. * @param block The block to set. */ public static void setBlock(Position p, World world, Block block){ world.setBlock(p.intX(), p.intY(), p.intZ(), block); } /** * Sets a block at this position. * @param world The world to place the block. * @param block The block to place. */ public void setBlock(World world, Block block){ world.setBlock(intX(), intY(), intZ(), block); } /** * Spawns a particle at the given position with the given colors. * @param world The world to spawn the particle. * @param p The position to spawn the particle. * @param color1 The amount red. * @param color2 The amount green. * @param color3 The amount purple/blue. */ public static void spawnParticle(World world, Position p, double color1, double color2, double color3){ world.spawnParticle("reddust", p.x, p.y, p.z, color1, color2, color3); } /** * Spawn a particle at this position with the given colors. * @param world The world to spawn the particle. * @param color1 The amount red. * @param color2 The amount green. * @param color3 The amount purple/blue. */ public void spawnParticle(World world, double color1, double color2, double color3){ world.spawnParticle("reddust", x, y, z, color1, color2, color3); } }
  14. I have found out the whole problem, my xp was far too high. So the strike was far too strong. And the getting of xp goes to fase. Thank you both for help.
  15. Thank you for that, now I understand the problem much better. Now I am going to look what the big number is...
  16. I don't understand what you mean, 1.4107303442451825E15 is a number between 1 and 2, isn't it? But I don't know why there is an "E" in the double. RPG.getPlayerStrengt returns that number because I have programmed it that way. It is bound with several classes and playerdata that is added in livinghurtevent. Is it so strange it returns a number between 1 and 2? And do you mean with "1x10^15" 1000000000000000? That would say something. Here is RPG.java if you need it: package knokko.rpg; import knokko.rpg.data.WorldData; import net.minecraft.entity.player.EntityPlayer; public class RPG { public static boolean isKnownClass(String string){ if(string.matches("warrior")){ return true; } else if(string.matches("mage")){ return true; } else { return false; } } public static boolean isKnownRace(String string){ if(string.matches("human")){ return true; } else if(string.matches("orc")){ return true; } else if(string.matches("enderman")){ return true; } else { return false; } } private static double getClassStrengt(String Class){ if(Class.matches("warrior")){ return 1.25; } else if(Class.matches("mage")){ return 0.5; } else { return 1; } } private static double getClassStrengt(EntityPlayer player){ return getClassStrengt(WorldData.getClass(player)); } private static double getRaceStrengt(String race){ if(race.matches("human")){ return 1; } else if(race.matches("orc")){ return 3; } else if(race.matches("enderman")){ return 2; } else { return 1; } } private static double getRaceHealth(String race){ if(race.matches("human")){ return 1; } else if(race.matches("orc")){ return 2.5; } else if(race.matches("enderman")){ return 2; } else { return 1; } } private static double getRaceHealth(EntityPlayer player){ return getRaceHealth(WorldData.getRace(player)); } public static double getPlayerHealth(EntityPlayer player){ double xp = WorldData.getRaceXP(player); double raceHealth = getRaceHealth(player); return raceHealth * (1 + (xp * 0.0001)); } private static double getRaceStrengt(EntityPlayer player){ return getRaceStrengt(WorldData.getRace(player)); } public static double getPlayerStrengt(EntityPlayer player){ double raceStrengt = getRaceStrengt(player); double classStrengt = getClassStrengt(player); double xp = WorldData.getXP(player); double racexp = WorldData.getXP(player); return raceStrengt * (1 + (xp * 0.0001 * racexp)) * classStrengt; } private static double getRaceMana(String race){ if(race.matches("human")){ return 1; } else if(race.matches("enderman")){ return 1.25; } else if(race.matches("orc")){ return 0.25; } else { return 1; } } private static double getClassMana(String Class){ if(Class.matches("warrior")){ return 0.75; } else if(Class.matches("mage")){ return 2; } else { return 1; } } private static double getClassMana(EntityPlayer player){ return getClassMana(WorldData.getClass(player)); } private static double getRaceMana(EntityPlayer player){ return getRaceMana(WorldData.getRace(player)); } public static double getPlayerMana(EntityPlayer player){ double raceMana = getRaceMana(player); double classMana = getClassMana(player); double xp = WorldData.getXP(player); double racexp = WorldData.getRaceXP(player); return raceMana * (1 + (racexp * xp * 0.0001)) * classMana; } } Here is WorldData.java, but it is more playerdata at the moment package knokko.rpg.data; import knokko.rpg.main.s; import net.minecraft.command.PlayerSelector; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; import net.minecraft.world.WorldSavedData; public class WorldData extends WorldSavedData{ public static final String id = s.i; public static final String xp = "experience"; public static final String clas = "class"; public static final String mana = "mana"; public static final String maxmana = "maxmana"; public static final String race = "race"; public static final String racexp = "race xp"; public EntityLivingBase test; public NBTTagCompound players; public WorldData(String id) { super(id); } public WorldData(){ super(id); } @Override public void readFromNBT(NBTTagCompound nbt) { players = (NBTTagCompound) nbt.getTag("players"); } @Override public void writeToNBT(NBTTagCompound nbt) { nbt.setTag("players", players); } public static WorldData get(World world){ WorldData data = (WorldData) world.loadItemData(WorldData.class, id); if(data == null){ data = new WorldData(); world.setItemData(id, data); } return data; } public static int getXP(EntityPlayer player){ if(player == null){ return -1; } else { WorldData data = get(player.worldObj); if(data != null){ if(data.players == null){ data.players = new NBTTagCompound(); } } return data.players.getInteger(player.getUniqueID() + xp + getClass(player)); } } public static void addXP(EntityPlayer player, int amount){ if(player != null){ WorldData data = get(player.worldObj); if(data != null){ if(data.players == null){ data.players = new NBTTagCompound(); } } data.players.setInteger(player.getUniqueID() + xp + getClass(player), data.players.getInteger(player.getUniqueID() + xp + getClass(player)) + amount); data.markDirty(); } } public static void setXP(EntityPlayer player, int amount){ if(player != null){ WorldData data = get(player.worldObj); if(data != null){ if(data.players == null){ data.players = new NBTTagCompound(); } } data.players.setInteger(player.getUniqueID() + xp + getClass(player), amount); data.markDirty(); } } public static String getClass(EntityPlayer player){ if(player != null){ WorldData data = get(player.worldObj); return data.players.getString(player.getUniqueID() + clas); } else { return null; } } public static void setClass(String clas, EntityPlayer player){ if(player != null){ WorldData data = get(player.worldObj); if(data.players == null){ data.players = new NBTTagCompound(); } data.players.setString(player.getUniqueID() + data.clas, clas); data.markDirty(); } } public static int getMana(EntityPlayer player){ if(player != null){ WorldData data = get(player.worldObj); if(data.players == null){ data.players = new NBTTagCompound(); } return data.players.getInteger(player.getUniqueID() + mana + getClass(player)); } else { return -10; } } public static void setMana(EntityPlayer player, int amount){ if(player != null){ WorldData data = get(player.worldObj); if(data.players == null){ data.players = new NBTTagCompound(); } data.players.setInteger(player.getUniqueID() + mana + getClass(player), amount); data.markDirty(); } } public static void addMana(EntityPlayer player, int amount){ if(player != null){ WorldData data = get(player.worldObj); if(data.players == null){ data.players = new NBTTagCompound(); } if(data.players.getInteger(player.getUniqueID() + mana + getClass(player) + amount) > data.players.getInteger(player.getUniqueID() + maxmana + getClass(player))){ data.players.setInteger(player.getUniqueID() + mana + getClass(player), data.players.getInteger(player.getUniqueID() + maxmana + getClass(player))); } else { data.players.setInteger(player.getUniqueID() + mana + getClass(player), data.players.getInteger(player.getUniqueID() + mana + getClass(player)) + amount); } } } public static int getMaxMana(EntityPlayer player){ if(player != null){ WorldData data = get(player.worldObj); if(data.players == null){ data.players = new NBTTagCompound(); } return data.players.getInteger(player.getUniqueID() + maxmana + getClass(player)); } else{ return -10; } } public static void setMaxMana(EntityPlayer player, int amount){ if(player != null){ WorldData data = get(player.worldObj); if(data.players == null){ data.players = new NBTTagCompound(); } data.players.setInteger(player.getUniqueID() + maxmana + getClass(player), amount); data.markDirty(); } } public static void setRace(EntityPlayer player, String race){ if(player != null){ WorldData data = get(player.worldObj); if(data.players == null){ data.players = new NBTTagCompound(); } data.players.setString(player.getUniqueID() + data.race, race); data.markDirty(); } } public static String getRace(EntityPlayer player){ if(player != null){ WorldData data = get(player.worldObj); if(data.players == null){ data.players = new NBTTagCompound(); } return data.players.getString(player.getUniqueID() + race); } else { return null; } } public static void addRaceXp(EntityPlayer player, int amount){ if(player != null){ WorldData data = get(player.worldObj); if(data.players == null){ data.players = new NBTTagCompound(); } data.players.setInteger(player.getUniqueID() + racexp + getRace(player), data.players.getInteger(player.getUniqueID() + racexp + getRace(player)) + amount); data.markDirty(); } } public static void setRaceXP(EntityPlayer player, int amount){ if(player != null){ WorldData data = get(player.worldObj); if(data.players == null){ data.players = new NBTTagCompound(); } data.players.setInteger(player.getUniqueID() + racexp + getRace(player), amount); data.markDirty(); } } public static int getRaceXP(EntityPlayer player){ if(player != null){ WorldData data = get(player.worldObj); if(data.players == null){ data.players = new NBTTagCompound(); } return data.players.getInteger(player.getUniqueID() + racexp + getRace(player)); } else { return -10; } } } Giving the stats is done in the HurtEvent you could allready see.
  17. Here is the code: I have used system.out.println for better understanding. package knokko.rpg.events.living; import knokko.rpg.RPG; import knokko.rpg.data.WorldData; import knokko.rpg.entity.effect.EntityBlood; import net.minecraft.entity.EntityCreature; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ChatComponentTranslation; import net.minecraft.util.DamageSource; import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.event.entity.living.LivingHurtEvent; import cpw.mods.fml.common.eventhandler.SubscribeEvent; public class HurtEvent { @SubscribeEvent public void hurtEvent(LivingHurtEvent event){ if(event.entityLiving != null){ if(event.source == DamageSource.fall){ event.setCanceled(true); } if(event.source.getEntity() instanceof EntityPlayer){ EntityPlayer player = (EntityPlayer) event.source.getEntity(); System.out.println("getPlayerStrengt = " + RPG.getPlayerStrengt(player)); System.out.println("event.amount before multitplying = " + event.ammount); event.ammount *= RPG.getPlayerStrengt(player); System.out.println("event.amount after multiplying = " + event.ammount); } if(!event.isCanceled()) { float armor = (float) (event.entityLiving.getTotalArmorValue() * 0.04); float armor2 = 1 - armor; int damage = (int) (event.ammount * armor2); if(event.entityLiving instanceof EntityPlayer && event.source.getEntity() instanceof EntityLiving){ if(!((EntityLiving) event.source.getEntity()).getCustomNameTag().isEmpty()){ EntityPlayer hurtPlayer = (EntityPlayer) event.entityLiving; hurtPlayer.addChatMessage(new ChatComponentTranslation(EnumChatFormatting.RED + "You are hurt for " + damage + " damage by " + ((EntityLiving) event.source.getEntity()).getCustomNameTag())); } } else if(event.entityLiving instanceof EntityPlayer && !(event.source.getEntity() instanceof EntityPlayer) ){ EntityPlayer hurtPlayer = (EntityPlayer) event.entityLiving; hurtPlayer.addChatMessage(new ChatComponentTranslation(EnumChatFormatting.RED + "You are hurt for " + damage + " damage by " + event.source.damageType)); } if(event.source.getEntity() instanceof EntityPlayer){ EntityPlayer player = (EntityPlayer) event.source.getEntity(); WorldData.addXP(player, damage); WorldData.addRaceXp(player, damage % 3); } if(event.entityLiving instanceof EntityPlayer && event.source.getEntity() instanceof EntityPlayer){ EntityPlayer hurtPlayer = (EntityPlayer) event.entityLiving; hurtPlayer.addChatMessage(new ChatComponentTranslation(EnumChatFormatting.RED + "You are hurt for " + damage + " damage by " + ((EntityPlayer) event.source.getEntity()).getDisplayName())); EntityPlayer attacker = (EntityPlayer)event.source.getEntity(); attacker.addChatMessage(new ChatComponentTranslation(EnumChatFormatting.GREEN + "You have hit " + hurtPlayer.getDisplayName() + " for " + damage + " damage.")); } else if(event.source.getEntity() instanceof EntityPlayer && ((EntityLiving) event.entityLiving).getCustomNameTag().isEmpty()){ EntityPlayer attacker = (EntityPlayer) event.source.getEntity(); attacker.addChatMessage(new ChatComponentTranslation(EnumChatFormatting.GREEN + "You have hit a mob for " + damage + " damage.")); } else if(event.source.getEntity() instanceof EntityPlayer){ EntityPlayer attacker = (EntityPlayer) event.source.getEntity(); attacker.addChatMessage(new ChatComponentTranslation(EnumChatFormatting.GREEN + "You have hit " + ((EntityLiving) event.entityLiving).getCustomNameTag() + " for " + damage + " damage.")); } if(event.entityLiving instanceof EntityCreature || event.entityLiving instanceof EntityPlayer){ if(damage >= 1){ event.entityLiving.worldObj.spawnEntityInWorld(new EntityBlood(event.entityLiving.worldObj, event.entityLiving.posX, event.entityLiving.posY, event.entityLiving.posZ, 1)); } if(damage >= 2){ event.entityLiving.worldObj.spawnEntityInWorld(new EntityBlood(event.entityLiving.worldObj, event.entityLiving.posX, event.entityLiving.posY + 1, event.entityLiving.posZ, 1)); } if(damage >= 3){ event.entityLiving.worldObj.spawnEntityInWorld(new EntityBlood(event.entityLiving.worldObj, event.entityLiving.posX + 1, event.entityLiving.posY, event.entityLiving.posZ, 1)); } if(damage >= 4){ event.entityLiving.worldObj.spawnEntityInWorld(new EntityBlood(event.entityLiving.worldObj, event.entityLiving.posX - 1, event.entityLiving.posY, event.entityLiving.posZ, 1)); } if(damage >= 5){ event.entityLiving.worldObj.spawnEntityInWorld(new EntityBlood(event.entityLiving.worldObj, event.entityLiving.posX, event.entityLiving.posY, event.entityLiving.posZ + 1, 1)); } if(damage >= 6){ event.entityLiving.worldObj.spawnEntityInWorld(new EntityBlood(event.entityLiving.worldObj, event.entityLiving.posX, event.entityLiving.posY, event.entityLiving.posZ - 1, 1)); } if(damage >= 7){ event.entityLiving.worldObj.spawnEntityInWorld(new EntityBlood(event.entityLiving.worldObj, event.entityLiving.posX, event.entityLiving.posY, event.entityLiving.posZ, 1)); } if(damage >= { event.entityLiving.worldObj.spawnEntityInWorld(new EntityBlood(event.entityLiving.worldObj, event.entityLiving.posX, event.entityLiving.posY + 0.5, event.entityLiving.posZ, 1)); } if(damage >= 9){ event.entityLiving.worldObj.spawnEntityInWorld(new EntityBlood(event.entityLiving.worldObj, event.entityLiving.posX + 0.5, event.entityLiving.posY, event.entityLiving.posZ, 1)); } if(damage >= 10){ event.entityLiving.worldObj.spawnEntityInWorld(new EntityBlood(event.entityLiving.worldObj, event.entityLiving.posX - 0.5, event.entityLiving.posY, event.entityLiving.posZ, 1)); } if(damage >= 11){ event.entityLiving.worldObj.spawnEntityInWorld(new EntityBlood(event.entityLiving.worldObj, event.entityLiving.posX, event.entityLiving.posY, event.entityLiving.posZ + 0.5, 1)); } if(damage >= 12){ event.entityLiving.worldObj.spawnEntityInWorld(new EntityBlood(event.entityLiving.worldObj, event.entityLiving.posX, event.entityLiving.posY, event.entityLiving.posZ - 0.5, 1)); } } } } } } Here is the important part of the console: I can't really help that the file is not very easy...
  18. hello guys, I have tried for hours to edit the attack damage a player causes, but it didn't work. I have tried the LivingHurtEvent and editing event.ammount, but this made the damage infinite. I have tried player.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue();, but this only edits the base value, there is almost no difference if I striked with a sword. Does somebody know a better way to do this?
  19. Just check if the player is in water and than set motionY to -0.5 or something.
  20. A simple tip for having 2 blocks with 1 tileEntity. world.getTileEntity(x, y-1, z);
  21. hello guys, I have made a mob that extends EntityCreature. I am trying to let is spawn in the world naturally, but I am not sure this will work. I have found a sort of link between EnumCreatureType.creature and EntityAnimal. So is my mob able to spawn naturally? The egg allready works. Here is the part of myentityHandler: public static void registerCreatures(Class entityClass, String name){ int entityId = EntityRegistry.findGlobalUniqueEntityId(); EntityList.entityEggs.put(Integer.valueOf(entityId), new EntityList.EntityEggInfo(entityId, 494999444, 333333333)); EntityRegistry.addSpawn(entityClass, 20, 3, 5, EnumCreatureType.creature, BiomeGenBase.plains, BiomeGenBase.savanna, BiomeGenBase.savannaPlateau); EntityRegistry.registerGlobalEntityID(entityClass, name, entityId); EntityRegistry.registerModEntity(entityClass, name, entityId, KnokkoRPG.modInstance, 64, 1, true); } This is called in the initializationEvent.
  22. Just use if(player.getHeldItem == null){ Do something }
  23. Check first if player.getHeldItem != null. You can only use player.getHeldItem.getItem if the player.getHeldItem is not null, this will make a crash.
  24. You could all read this in the crash report. And the game crashes if you register 2 things with the same ID.
  25. I have rewritten it a little bit. The ItemStacks are now saved on the tileentity. But I have found another problem. I have let the block and the tile entity print the value of the ironstack. The tileEntity always says the stacksize = 0! Does anybody know why? Here is the new block class: public class MetalEnchanter extends BlockContainer{ @SideOnly(Side.CLIENT) public IIcon top; @SideOnly(Side.CLIENT) public IIcon bottom; public TileEntityMetalEnchanter tileEntity; public MetalEnchanter() { super(Material.rock); setHardness(5); setResistance(10); } @Override public TileEntity createNewTileEntity(World world, int i) { tileEntity = new TileEntityMetalEnchanter(); return tileEntity; } @SideOnly(Side.CLIENT) public IIcon getIcon(int side, int metadata) { if(side == 0){ return bottom; } if(side == 1){ return top; } else { return blockIcon; } } @SideOnly(Side.CLIENT) public void registerBlockIcons(IIconRegister icon) { this.blockIcon = icon.registerIcon(R.T + "metalenchanter_side"); this.bottom = icon.registerIcon(R.T + "metalenchanter_bottom"); this.top = icon.registerIcon(R.T + "metalenchanter_top"); } public boolean onBlockActivated(World world, int x, int y,int z, EntityPlayer player, int side, float f1, float f2, float f3){ if(player.getCurrentEquippedItem() != null && !world.isRemote){ if(player.getCurrentEquippedItem().getItem() == Items.iron_ingot && tileEntity.input_iron.stackSize < 64){ player.getCurrentEquippedItem().stackSize -= 1; tileEntity.input_iron.stackSize += 1; } if(tileEntity.input_powder != null){ if(tileEntity.input_powder.stackSize < 64){ if(player.getCurrentEquippedItem().getItem() == tileEntity.input_powder.getItem()){ player.getCurrentEquippedItem().stackSize -= 1; tileEntity.input_powder.stackSize += 1; } } } else if(tileEntity.input_powder == null){ System.out.println("input_powder = null."); if(isValidItem(player)){ tileEntity.input_powder = new ItemStack(player.getCurrentEquippedItem().getItem(), 1); player.getCurrentEquippedItem().stackSize -= 1; } } } if(!world.isRemote){ System.out.println(tileEntity.input_iron); } return true; } public void onBlockClicked(World world, int x, int y, int z, EntityPlayer player){ if(player.getCurrentEquippedItem() != null && !world.isRemote){ if(tileEntity.input_iron.stackSize > 0 && player.getCurrentEquippedItem().getItem() == Items.iron_ingot){ player.inventory.addItemStackToInventory(new ItemStack(Items.iron_ingot)); tileEntity.input_iron.stackSize -= 1; } if(tileEntity.input_powder != null){ if(tileEntity.input_powder.getItem() == player.getCurrentEquippedItem().getItem() && tileEntity.input_powder.stackSize > 0 && player.getCurrentEquippedItem().stackSize < 64){ tileEntity.input_powder.stackSize -= 1; player.getCurrentEquippedItem().stackSize += 1; } } } else if(player.getCurrentEquippedItem() == null && !world.isRemote && tileEntity != null){ if(tileEntity.input_iron.stackSize > 0){ player.inventory.addItemStackToInventory(new ItemStack(Items.iron_ingot, tileEntity.input_iron.stackSize)); tileEntity.input_iron.stackSize = 0; } if(tileEntity.input_powder != null){ player.inventory.addItemStackToInventory(tileEntity.input_powder); tileEntity.input_powder = null; } } } public void breakBlock(World world, int x, int y, int z, Block block, int metadata) { if(tileEntity.input_iron.stackSize > 0){ world.spawnEntityInWorld(new EntityItem(world, x, y, z, tileEntity.input_iron)); } if(tileEntity.input_powder != null){ world.spawnEntityInWorld(new EntityItem(world, x, y, z, tileEntity.input_powder)); } if(tileEntity.output != null){ world.spawnEntityInWorld(new EntityItem(world, x, y, z, tileEntity.output)); } super.breakBlock(world, x, y, z, block, metadata); } public boolean isValidItem(EntityPlayer player){ if(player.getCurrentEquippedItem().getItem() == EnderpowerItems.cursedpowder || player.getCurrentEquippedItem().getItem() == EnderpowerItems.poison || player.getCurrentEquippedItem().getItem() == EnderpowerItems.witherpowder){ return true; } else { return false; } } @Override public void onBlockAdded(World world, int x, int y, int z){ if(world.getTileEntity(x, y, z) != null){ tileEntity = (TileEntityMetalEnchanter) world.getTileEntity(x, y, z); } } The tileEntity is shorter: public class TileEntityMetalEnchanter extends TileEntity{ public MetalEnchanter enchanter; public void updateEntity(){ if(input_powder != null){ if(input_powder.stackSize < 1){ input_powder = null; } } if(output != null){ if(output.stackSize < 1){ output = null; } } if(!worldObj.isRemote){ System.out.println(input_iron); } } public void writeToNBT(NBTTagCompound nbt){ super.writeToNBT(nbt); if(input_iron != null){ nbt.setInteger("Iron", input_iron.stackSize); } } public void readFromNBT(NBTTagCompound nbt){ super.readFromNBT(nbt); input_iron = new ItemStack(Items.iron_ingot, nbt.getInteger("Iron")); } public ItemStack input_iron = new ItemStack(Items.iron_ingot, 0); public ItemStack input_powder; public ItemStack output; } EDIT: I have found the problem. The block wasn't connected with the tileEntity but it looked like it was. Now the connection is good, saving the data is easy.

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.