Everything posted by knokko
-
[1.7.10] save player to nbt
I have readed EntityTameAble before I asked for help. But Mojang has not given his codes easy names so I don't understand it. I have readed it again but I still don't understand it.
-
Having trouble with crashes!
This page is called modder support. This is made to help modders if they have problems with making mods. There is another page for players.
-
[1.7.10] save player to nbt
I have found this problem myself. I have forgotten to check if the summoner is not null. Now I am going to try to get the player from it's UUID. EDIT: I have tried to call a player from it's UUID. I don't know how to write an UUID to NBT. I have made a String from the UUID on this way: summonerUUID = summoner.getUniqueID(); summonerId = "" + summonerUUID; But how can I change it back to an UUID or write an UUID to nbt.
-
[1.7.10] save player to nbt
Here is my class. I have another problem too that is almost the same as this problem. It seems that I have not full access too the summoner. por example: The isBurning check in useHealingMagic() gives a crash and I have tried more methods of the summoner that gave crashes too. I will show the way of summoning the mob too. public class EntityUndeadMage extends EntityAnimal{ /** * The summoner is the player that has summoned this mob. * This mob is programmed to help the summoner. */ public EntityPlayer summoner; /** * The player name of the summoner. */ public String summonerName; public UUID summonerUUID = summoner.getUniqueID(); /** * The type of magic this mob uses. * 0 = healing * 1 = mixed * 2 = offensive */ public int mageType; double movementSpeed = this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).getBaseValue(); /** * The current mana the mob has */ public int mobMana; /** * The time this mob can't cast spells. */ public int manaCooldown; /** * A required constructor for a mob. * * Do not use this constructor to summon this mob. * Use the constructor world, summoner, mageType, x, y, z. * @param world */ public EntityUndeadMage(World world) { super(world); this.setSize(0.9F, 1.8F); } /** * * @param world - The world the mob has to spawn. * @param summoner - The player that summons this mob. * @param mageType - The type of magic this mob will use. 0 = positive 1 = mixed 2 = offensive * @param x - The X location the mob has to spawn. * @param y - The Y location the mob has to spawn. * @param z - The Z location the mob has to spawn. */ public EntityUndeadMage(World world, EntityPlayer summoner, int mageType, double x, double y, double z){ super(world); this.setSize(0.6F, 1.8F); setPosition(x, y, z); prevPosX = x; prevPosY = y; prevPosZ = z; this.summoner = summoner; this.mageType = mageType; } /** * Returns true if the newer Entity AI code should be run */ public boolean isAIEnabled() { return true; } /** * The base attributes of this mob. */ protected void applyEntityAttributes() { super.applyEntityAttributes(); this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(20.0D); this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.35); } /** * Returns the sound this mob makes while it's alive. */ protected String getLivingSound() { return null; } /** * Returns the sound this mob makes when it is hurt. */ protected String getHurtSound() { return "mob.zombie.hurt"; } /** * Returns the sound this mob makes on death. */ protected String getDeathSound() { return "mob.zombie.hurt"; } protected void func_145780_a(int x, int y, int z, Block block) { this.playSound("mob.zombie.step", 0.15F, 1.0F); } /** * Returns the volume for the sounds this mob makes. */ protected float getSoundVolume() { return 0.4F; } protected Item getDropItem() { return Items.bone; } /** * Drop 0-2 items of this living's type. @param par1 - Whether this entity has recently been hit by a player. @param * par2 - Level of Looting used to kill this mob. */ protected void dropFewItems(boolean hitbyplayer, int lootinglevel) { int j = this.rand.nextInt(3) + this.rand.nextInt(1 + lootinglevel); int k; for (k = 0; k < j; ++k) { this.dropItem(Items.bone, 1); } j = this.rand.nextInt(3) + 1 + this.rand.nextInt(1 + lootinglevel); for (k = 0; k < j; ++k) { if (this.isBurning()) { this.dropItem(Items.skull, 1); } else { this.dropItem(Items.skull, 1); } } } /** * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig. */ public boolean interact(EntityPlayer player){ return false; } public EntityUndeadMage createChild(EntityAgeable ageable) { return new EntityUndeadMage(this.worldObj); } public void onUpdate(){ super.onUpdate(); followSummoner(); updateMana(); useMagic(); } public void useMagic() { if(mageType == 0){ useHealingMagic(); } if(mageType == 1){ useMixedMagic(); } if(mageType == 2){ useOffensiveMagic(); } } public void useOffensiveMagic() { } public void useMixedMagic() { } public void useHealingMagic() { if(useMana(0, 0) && summoner.isBurning()){ System.out.println(summoner.getDisplayName() + " is on fire"); } else{ } } private boolean useMana(int amount, int cooldown) { if(cooldown == 0 && mobMana >= amount){ manaCooldown = cooldown; mobMana -= amount; return true; } else { return false; } } public void updateMana() { if(mobMana <= 5000){ mobMana += 1; } if(mobMana >= 5001){ mobMana = 5000; } if(manaCooldown >= 1){ manaCooldown -= 1; } if(manaCooldown <= 0){ manaCooldown = 0; } } private void followSummoner() { if(summoner != null){ if(summoner.posX >= posX + 5){ moveEntity(movementSpeed , 0, 0); } else if(summoner.posX <= posX - 5){ moveEntity(-1 * movementSpeed, 0, 0); } if(summoner.posZ >= posZ + 5){ moveEntity(0, 0, movementSpeed); } else if(summoner.posZ <= posZ - 5){ moveEntity(0, 0, -1 * movementSpeed); } if(this.onGround && summoner.posY >= posY + 2){ moveEntity(0, 3.0, 0); } if(summoner.posX >= posX + 16 || summoner.posX <= posX - 16 ||summoner.posY >= posY + 16 || summoner.posY <= posY - 16 || summoner.posZ >= posZ + 16|| summoner.posZ <= posZ - 16){ setPosition(summoner.posX, summoner.posY, summoner.posZ); } } } public void writeEntityToNBT(NBTTagCompound nbt){ super.writeEntityToNBT(nbt); nbt.setString("summonerName", summoner.getDisplayName()); } public void readEntityFromNBT(NBTTagCompound nbt){ super.readEntityFromNBT(nbt); summonerName = nbt.getString("summonerName"); summoner = this.worldObj.getPlayerEntityByName(summonerName); } } The way I summon the mob: public ItemStack onItemRightClick(ItemStack item, World world, EntityPlayer player){ if(!world.isRemote){ world.spawnEntityInWorld(new EntityUndeadMage(world, player, 1, player.posX, player.posY + 1, player.posZ - 2)); } return item; }
-
[1.7.10] save player to nbt
I have added the method again. This time the game doesn't crash but it has given me an error report and all the mobs have disappeared. And I have not even used that field. The field is written in the class and not in a method or something. Here is the error report: The method was red in the console. EDIT: It seems that the field sometimes causes a crash and sometimes not. And I haven't even used it. I have placed "//" for the field to prevent it from causing crashes.
-
[1.7.10] Adding external Libraries (libs folder or something)
I believe if you have added an external jar and that jar is in the mods folder too, it can use the libraries of that mod. Is that what you mean?
-
[1.7.10] Adding external Libraries (libs folder or something)
I think I know what you mean. right click on minecraft (as java project). choose the option "properties". choose "java build path". choose "libraries". than use "add external jar". I hope this is what you mean.
-
[1.7.10] save player to nbt
What will happen if I use player names? And how can I get the players UUID? public UUID summonerUUID = summoner.getUniqueID(); made a crash.
-
[1.7.10] save player to nbt
That is the way to save it correctly, I have tried this before I posted. But this time I saw the method getPlayerEntityByName. I have added the test to readEntityFromNBT and it works! Thank you again
-
[1.7.10] save player to nbt
hello people, I have a problem again with the same mob. My mob has a summoner that is very important for the mob. But the summoner is null if I leave the world and come back. I think this is because I have not saved it to nbt. But I got a problem, I don't know how to write a player to nbt. I have tried some things but none of them worked. Can anybody help me?
-
custom spawn problem
Oops . The tasks are in the another constructor. My problem is solved now, I am going to make the entity further myself. Thank you.
-
custom spawn problem
I have changed the constructor. The entity doesn't fall through blocks anymore and doesn't disappear. This really helped but my entity can't walk.
-
custom spawn problem
I spawn it 1 meter above the player now. public ItemStack onItemRightClick(ItemStack item, World world, EntityPlayer player){ if(!world.isRemote){ world.spawnEntityInWorld(new EntityUndeadMage(world, player, player.posX, player.posY + 1, player.posZ - 2)); } return item; } There happens the same as before and I have used glass this time. now I see that the entity disappears after 1 second.
-
custom spawn problem
I have added the !world.Isremote check and it doesn't spawn in the player boundingbox anymore. But it still falls through the ground. Here is the new code for summoning: public ItemStack onItemRightClick(ItemStack item, World world, EntityPlayer player){ if(!world.isRemote){ world.spawnEntityInWorld(new EntityUndeadMage(world, player, player.posX, player.posY, player.posZ - 2)); } return item; }
-
custom spawn problem
I have a problem with a mob I have made. I am trying to spawn it with a custom item. But if I spawn it with a custom item my mob falls just through the ground. Here is the mob class: I have copied the most from EntityCow public class EntityUndeadMage extends EntityAnimal{ private static final String __OBFID = "CL_00001640"; public EntityUndeadMage(World p_i1683_1_) { super(p_i1683_1_); this.setSize(0.9F, 1.3F); this.getNavigator().setAvoidsWater(true); this.tasks.addTask(0, new EntityAISwimming(this)); this.tasks.addTask(1, new EntityAIPanic(this, 2.0D)); this.tasks.addTask(2, new EntityAIMate(this, 1.0D)); this.tasks.addTask(3, new EntityAITempt(this, 1.25D, Items.wheat, false)); this.tasks.addTask(4, new EntityAIFollowParent(this, 1.25D)); this.tasks.addTask(5, new EntityAIWander(this, 1.0D)); this.tasks.addTask(6, new EntityAIWatchClosest(this, EntityPlayer.class, 6.0F)); this.tasks.addTask(7, new EntityAILookIdle(this)); } public EntityUndeadMage(World world, EntityPlayer player, double x, double y, double z){ super(world); posX = x; posY = y; posZ = z; } /** * Returns true if the newer Entity AI code should be run */ public boolean isAIEnabled() { return true; } protected void applyEntityAttributes() { super.applyEntityAttributes(); this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(10.0D); this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.20000000298023224D); } /** * Returns the sound this mob makes while it's alive. */ protected String getLivingSound() { return "mob.cow.say"; } /** * Returns the sound this mob makes when it is hurt. */ protected String getHurtSound() { return "mob.cow.hurt"; } /** * Returns the sound this mob makes on death. */ protected String getDeathSound() { return "mob.cow.hurt"; } protected void func_145780_a(int p_145780_1_, int p_145780_2_, int p_145780_3_, Block p_145780_4_) { this.playSound("mob.cow.step", 0.15F, 1.0F); } /** * Returns the volume for the sounds this mob makes. */ protected float getSoundVolume() { return 0.4F; } protected Item getDropItem() { return Items.leather; } /** * Drop 0-2 items of this living's type. @param par1 - Whether this entity has recently been hit by a player. @param * par2 - Level of Looting used to kill this mob. */ protected void dropFewItems(boolean p_70628_1_, int p_70628_2_) { int j = this.rand.nextInt(3) + this.rand.nextInt(1 + p_70628_2_); int k; for (k = 0; k < j; ++k) { this.dropItem(Items.leather, 1); } j = this.rand.nextInt(3) + 1 + this.rand.nextInt(1 + p_70628_2_); for (k = 0; k < j; ++k) { if (this.isBurning()) { this.dropItem(Items.cooked_beef, 1); } else { this.dropItem(Items.beef, 1); } } } /** * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig. */ public boolean interact(EntityPlayer p_70085_1_){ return false; } public EntityUndeadMage createChild(EntityAgeable p_90011_1_) { return new EntityUndeadMage(this.worldObj); } } This is the way I spawn it: public ItemStack onItemRightClick(ItemStack item, World world, EntityPlayer player){ world.spawnEntityInWorld(new EntityUndeadMage(world, player, player.posX, player.posY, player.posZ)); return item; } Does anybody know why it falls through the ground?
-
[1.7.10] problems with building
It almost worked, my mcmod.INFO file was empty but I have fixed that with copy-pasting. I have even tested it in minecraft. It works now.
-
[1.7.2] disappearing entity
I have used an integer, (after the problems with mana is it very easy for me). It works good now. I think I can finish the entity myself. Thank you.
-
[1.7.10] problems with building
I though that this was possible too because it worked good in eclipse. I will try now what will happen if I change it to src/main/java, it will probably work.
-
[1.7.2] disappearing entity
I though I had to set the position and dimension because I am overriding from Entity.class. I do not understand everything. And about that string... It really seems to work before I leave the world. So I can change string to an integer with 3 values to solve this problem? I am going to test it now.
-
[1.7.10] problems with building
hello guys, I have updated 1 of my mods from 1.7.2 to 1.7.10 and I have a problem with building my mod. I have downloaded forge src for 1.7.10 and copied every package and I have put it in a source folder in the version for 1.7.10. Everything seems to work except 1 thing. If I run gradlew build: If I open the jar it has created, there is only a Meta-inf folder and nothing more. My java project is called "Minecraft". My source folder is called "src/main/enderpower". My packages are called like this "enderpower.main"., My packages are called like this "enderpower.mobs". etcetra. Does anybody know why it doesn't build my mod?
-
[1.7.2] disappearing entity
I have deleted the "super.writeToNBT" and the "super.readFromNBT" in my writeEntityToNBT method and readFromNBT method. It doesn't crash anymore and the position is saved correctly, but the entity doesn't shoot anymore on mobs if I have left the world. here is the new Entityclass: public class EntityTowerGun extends Entity{ private String side; private boolean invulnerable; public EntityTowerGun(World world, double x, double y, double z, String side) { super(world); setSize(1.0F, 1.0F); posX = x; posY = y; posZ = z; this.side = side; } public void onUpdate(){ super.onUpdate(); targetMobs(); } public EntityTowerGun(World world){ super(world); } @Override protected void entityInit() { } @Override protected void readEntityFromNBT(NBTTagCompound nbt) { side = nbt.getString("side"); NBTTagList nbttaglist = nbt.getTagList("Pos", 6); setPosition(this.posX, this.posY, this.posZ); dimension = nbt.getInteger("dimension"); invulnerable = nbt.getBoolean("Invulnerable"); } @Override protected void writeEntityToNBT(NBTTagCompound nbt) { nbt.setTag("Pos", this.newDoubleNBTList(new double[] {this.posX, this.posY + (double)this.ySize, this.posZ})); nbt.setInteger("Dimension", this.dimension); nbt.setBoolean("Invulnerable", this.invulnerable); nbt.setString("side", side); } public void targetMobs(){ Entity entity = null; if(side == "north"){ List list = this.worldObj.getEntitiesWithinAABB(EntityMob.class, AxisAlignedBB.getBoundingBox(posX - 3, posY - 10, posZ - 4, posX + 4, posY + 0, posZ - 1)); for (int j = 0; j < list.size(); ++j) { Entity entity1 = (Entity)list.get(j); this.worldObj.spawnEntityInWorld(new EntityGunBullet(this.worldObj, posX, posY, posZ, entity1.posX, entity1.posY, entity1.posZ)); } } if(side == "west"){ List list = this.worldObj.getEntitiesWithinAABB(EntityMob.class, AxisAlignedBB.getBoundingBox(posX - 4, posY - 10, posZ - 3, posX - 1, posY + 0, posZ + 4)); for (int j = 0; j < list.size(); ++j) { Entity entity1 = (Entity)list.get(j); this.worldObj.spawnEntityInWorld(new EntityGunBullet(this.worldObj, posX, posY, posZ, entity1.posX, entity1.posY, entity1.posZ)); } } if(side == "east"){ List list = this.worldObj.getEntitiesWithinAABB(EntityMob.class, AxisAlignedBB.getBoundingBox(posX + 2, posY - 10, posZ - 3, posX + 5, posY + 0, posZ + 4)); for (int j = 0; j < list.size(); ++j) { Entity entity1 = (Entity)list.get(j); this.worldObj.spawnEntityInWorld(new EntityGunBullet(this.worldObj, posX + 1, posY, posZ, entity1.posX, entity1.posY, entity1.posZ)); } } if(side == "south"){ List list = this.worldObj.getEntitiesWithinAABB(EntityMob.class, AxisAlignedBB.getBoundingBox(posX - 3, posY - 10, posZ + 2, posX + 4, posY + 0, posZ + 5)); for (int j = 0; j < list.size(); ++j) { Entity entity1 = (Entity)list.get(j); this.worldObj.spawnEntityInWorld(new EntityGunBullet(this.worldObj, posX, posY, posZ + 1, entity1.posX, entity1.posY, entity1.posZ)); } } } } Maybe the side string is not saved correctly but I don't know shure what the next problem is.
-
[1.7.10] Teleporting players
maybe something like player.posX = x;? I use this sometimes too.
-
[1.7.10] Teleporting players
Is there not a way to change the spawnpoint of the player? I think that is a more logical option to do this.
-
[1.7.2] disappearing entity
I have added a simple world constructor. Like this: public EntityTowerGun(World world){ super(world); This time I had a strange error I never had before. The game crashed when I left my world. And the entity is still not saved. The entity is now visible. This is the error report. I think this has something to do with my writeToNBT method, so here it is: @Override protected void writeEntityToNBT(NBTTagCompound var1) { super.writeToNBT(var1); }
-
[1.7.2] disappearing entity
Updating to 1.7.10 have caused problems, I am going to create another topic for this. I am happy I have made a back-up before trying to update. But for now: I have made this EntityHandler and 1 static method: public class EntityHandler { public static void registerShooter(Class entityClass, String name){ int entityId = EntityRegistry.findGlobalUniqueEntityId(); long x = name.hashCode(); Random random = new Random(x); EntityRegistry.registerGlobalEntityID(entityClass, name, entityId); EntityRegistry.registerModEntity(entityClass, name, entityId, KnokkoBlocks.instance, 64, 1, true); } } If I try to summon the entity with this code: world.spawnEntityInWorld(new EntityTowerGun(world, x + 0, y + 4, z + 2, "south")); world.spawnEntityInWorld(new EntityTowerGun(world, x - 0, y + 4, z - 2, "north")); world.spawnEntityInWorld(new EntityTowerGun(world, x + 2, y + 4, z + 0, "east")); world.spawnEntityInWorld(new EntityTowerGun(world, x - 2, y + 4, z - 0, "west")); My world crashes and I was sended back to the title screen. This was the report in the console: There were more errors but the console was not big enough... This is written in my main class: EntityHandler.registerShooter(EntityTowerGun.class, "guntower");
IPS spam blocked by CleanTalk.