
SSslimer
Members-
Posts
152 -
Joined
-
Last visited
Everything posted by SSslimer
-
Hm ok, I need to change those class. I found sth wired. After changing profession system of villager. When I try to print int of prof. I see 0 and the prof. number. I add that prof. can be changed in gui. Texture works fine and in villager info correct prof. shows. After next word opening prof. turns to 0, despite NBT data laoding and saving.
-
Here is WordHandler class: package BetterWorld; public class WorldHandler { public WorldHandler() {} public static BetterVillageCollection villageCollectionObj; @SubscribeEvent public void worldMethod(WorldEvent event) { BetterVillageCollection villagecollection = (BetterVillageCollection)event.world.perWorldStorage.loadData(BetterVillageCollection.class, "bettervillages"); if (villagecollection == null) { this.villageCollectionObj = new BetterVillageCollection(event.world); event.world.perWorldStorage.setData("bettervillages", this.villageCollectionObj); } else { this.villageCollectionObj = villagecollection; this.villageCollectionObj.func_82566_a(event.world); } } } Inwentory works fine, items in slots can be saved and loaded. When I try to get an itemstack to render armor and item in hand method returns always null. ItemStack itemstack = villager.inventory.armorItemInSlot(3 - par2); villager is correct(I can get its pos.)method for getting item is correct too. I think that inventory returns null so method after too. Method works because it returns item when I use it in entity class.
-
Returning to BetterVillageCollection vlgc = WorldHandler.villageCollectionObj; Want you see the handler class? Can I expect help with inventory?
-
In interact method: player.openGui(ModBetterWorld.instance, 4, world, this.getEntityId(), y, z); In gui handler: case 4: Entity villager = world.getEntityByID(x); if(villager!=null && villager instanceof EntityBetterVillager) { return new GuiVillager((EntityBetterVillager) villager, player); } Works fine, now can it crash? So I can use show gui screen only in other guis when I want to open gui??
-
GUI should be opened by displaying gui screen only if the gui to open we are opening from another gui?? I changed few guis to open from gui handler. Now I am trying to senda packet on client side to open gui which opens by interaction with villager. Should I use method from SimpleNetworkWrapper sendTo or other? If sendTo what I need to change to make player as a EntityPlayerMP?
-
Some code edited in previous post. I should have changed betterai to sth else. It wont be an ai but system of tasks. In ai system there are some issues that I dont like. Dont ask what and why. @Override, ok I must read on forums how to properly use it. Ok now I think I know how to use it, I am not planing any other entities implementing my villager so I dont need to Override methods?? I will try to fix gui opening and villages handling. My 17 holidays stared so I have a time to fix and add what I want
-
As I said my entity code is messy. Better tasks is my first step to make an orders and tasks system. This system is in second pos. of my plans after finishing inventory. PersistenceRequired deleted - useless. I am not sure when to use @Override. Sometimes I add this but when I know that it is needed. WorldHandler.villageCollectionObj what is wrong with it? Interact method, open gui by gui handler but why? Now it works fine. By the way, thanks for help, I have learnt lot by fixing errors since my first contact with java.
-
Thats why I asked. Not evrything is copied, when sth is good why create own version? Mob works as I want it.
-
It is a bit messy. package BetterWorld.mobs; public class EntityBetterVillager extends EntityAgeable implements INpc, IRangedAttackMob, IMob { private int randomTickDivider; private boolean isMating; private boolean isPlaying; private boolean isLookingForHome; private int tick; private String firstName; private String secondName; public String villageName; private int age; private boolean canPickUpItems; public BetterVillage nearestVillager; public BetterVillage homevillage; public EntityPlayer boss; public ItemStack itemwlapie; public InventoryVillager inventory = new InventoryVillager(this, "Villager Inventory", false); public final EntityBetterAITasks bettertasks; public final EntityBetterAITasks bettertargetTasks; private EntityAIArrowAttack aiArrowAttack = new EntityAIArrowAttack(this, 0.6D, 20, 60, 15.0F); private EntityAIAttackOnCollide aiAttackOnCollide = new EntityAIAttackOnCollide(this, EntityZombie.class, 0.6D, true); private String[] firstnames = new String[] {"a", "b", "c"}; private String[] secondnames = new String[] {"a", "b", "c"}; public EntityBetterVillager(World par1World) { this(par1World, 0); } public EntityBetterVillager(World par1World, int par2) { super(par1World); this.setSize(0.6F, 1.8F); this.experienceValue = 5; this.setProfession(par2); this.bettertasks = new EntityBetterAITasks(par1World != null && par1World.theProfiler != null ? par1World.theProfiler : null); this.bettertargetTasks = new EntityBetterAITasks(par1World != null && par1World.theProfiler != null ? par1World.theProfiler : null); this.getNavigator().setBreakDoors(true); this.getNavigator().setAvoidsWater(true); this.tasks.addTask(0, new EntityAISwimming(this)); this.tasks.addTask(1, new EntityAIAttackOnCollide(this, 0.6D, true)); this.tasks.addTask(2, new EntityAIMoveIndoors(this)); this.bettertasks.addTask(3, new EntityBetterAIRestrictOpenDoor(this)); this.bettertasks.addTask(4, new EntityBetterAIOpenDoor(this, true)); this.tasks.addTask(5, new EntityAIMoveTowardsTarget(this, 0.6D, 32.0F)); this.tasks.addTask(5, new EntityAIMoveTowardsRestriction(this, 0.6D)); this.tasks.addTask(6, new EntityAIFollowGolem(this)); this.tasks.addTask(7, new EntityAIPlay(this, 0.32D)); this.tasks.addTask(8, new EntityAIWatchClosest(this, EntityPlayer.class, 3.0F, 1.0F)); this.tasks.addTask(8, new EntityAIWatchClosest2(this, EntityBetterVillager.class, 5.0F, 0.02F)); this.tasks.addTask(9, new EntityAIAvoidEntity(this, EntityZombie.class, 8.0F, 0.6D, 0.6D)); this.tasks.addTask(6, new EntityAIVillagerMate(this)); this.tasks.addTask(9, new EntityAIWander(this, 0.6D)); this.targetTasks.addTask(2, new EntityAIHurtByTarget(this, false)); this.bettertargetTasks.addTask(3, new EntityAINearestAttackableVillager(this, EntityBetterVillager.class, 0, true, true)); } protected void applyEntityAttributes() { super.applyEntityAttributes(); this.getEntityAttribute(SharedMonsterAttributes.followRange).setBaseValue(50.0D); this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.5D); } public boolean isAIEnabled() { return true; } public void onLivingUpdate() { tick++; if(this.firstName == null)this.setFirstName(); if(this.secondName == null)this.setRandomSecondName(); if(tick % 8766000 == 0) { this.age++; tick = 0; } if(tick % 20 == 0) { //System.out.println(inventory.armorItemInSlot(3)); if(this.getProfession() == 5)this.setCombatTask(); if(this.villageName == null)this.setHomeVillage(); } if(!this.isChild()) { this.setCanPickUpItems(true); }else this.setCanPickUpItems(false); this.bettertargetTasks.onUpdateTasks(); this.bettertasks.onUpdateTasks(); this.updateArmSwingProgress(); if (!this.worldObj.isRemote && !this.dead && this.canPickUpItems() == true){ List list = this.worldObj.getEntitiesWithinAABB(EntityItem.class, this.boundingBox.expand(1.0D, 0.0D, 1.0D)); Iterator iterator = list.iterator(); while (iterator.hasNext()){ EntityItem entityitem = (EntityItem)iterator.next(); if (!entityitem.isDead && entityitem.getEntityItem() != null){ ItemStack itemstack = entityitem.getEntityItem(); this.inventory.addItemStackToInventory(itemstack); this.onItemPickup(entityitem, 1); entityitem.setDead(); } } } super.onLivingUpdate(); } protected boolean canPickUpItems(){ return this.canPickUpItems; } protected void setCanPickUpItems(boolean par1){ this.canPickUpItems = par1; } protected Entity findPlayerToAttack() { EntityPlayer entityplayer = this.worldObj.getClosestVulnerablePlayerToEntity(this, 16.0D); return entityplayer != null && this.canEntityBeSeen(entityplayer) ? entityplayer : null; } public boolean canAttackClass(Class p_70686_1_) { Entity entity = this.entityToAttack; return ((this.villageName != null) && (entity != null) && (entity instanceof EntityBetterVillager) && (this.villageName != ((EntityBetterVillager) entity).villageName) && EntityBetterVillager.class.isAssignableFrom(p_70686_1_)) ? false : super.canAttackClass(p_70686_1_); } public boolean attackEntityFrom(DamageSource par1DamageSource, float par2) { if (this.isEntityInvulnerable()) { return false; } else if (super.attackEntityFrom(par1DamageSource, par2)) { Entity entity = par1DamageSource.getEntity(); if (this.riddenByEntity != entity && this.ridingEntity != entity) { if (entity != this) { this.entityToAttack = entity; } return true; } else { return true; } } else { return false; } } public boolean attackEntityAsMob(Entity par1Entity) { float f = (float) 1.0D; int i = 0; if (par1Entity instanceof EntityLivingBase) { f += EnchantmentHelper.getEnchantmentModifierLiving(this, (EntityLivingBase)par1Entity); i += EnchantmentHelper.getKnockbackModifier(this, (EntityLivingBase)par1Entity); } boolean flag = par1Entity.attackEntityFrom(DamageSource.causeMobDamage(this), f); if (flag) { if (i > 0) { par1Entity.addVelocity((double)(-MathHelper.sin(this.rotationYaw * (float)Math.PI / 180.0F) * (float)i * 0.5F), 0.1D, (double)(MathHelper.cos(this.rotationYaw * (float)Math.PI / 180.0F) * (float)i * 0.5F)); this.motionX *= 0.6D; this.motionZ *= 0.6D; } int j = EnchantmentHelper.getFireAspectModifier(this); if (j > 0) { par1Entity.setFire(j * 4); } if (par1Entity instanceof EntityLivingBase) { EnchantmentHelper.func_151384_a((EntityLivingBase)par1Entity, this); } EnchantmentHelper.func_151385_b(this, par1Entity); } return flag; } protected void attackEntity(Entity par1Entity, float par2) { if (this.attackTime <= 0 && par2 < 2.0F && par1Entity.boundingBox.maxY > this.boundingBox.minY && par1Entity.boundingBox.minY < this.boundingBox.maxY) { this.attackTime = 20; this.attackEntityAsMob(par1Entity); } } protected void updateAITick() { if (--this.randomTickDivider <= 0) { BetterVillageCollection vlgc = WorldHandler.villageCollectionObj; vlgc.addVillagerPosition(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.posY), MathHelper.floor_double(this.posZ)); this.randomTickDivider = 70 + this.rand.nextInt(50); this.nearestVillager = vlgc.findNearestVillage(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.posY), MathHelper.floor_double(this.posZ), 32); if (this.nearestVillager == null) { this.detachHome(); } else { ChunkCoordinates chunkcoordinates = this.nearestVillager.getCenter(); this.setHomeArea(chunkcoordinates.posX, chunkcoordinates.posY, chunkcoordinates.posZ, (int)((float)this.nearestVillager.getVillageRadius() * 0.6F)); if (this.isLookingForHome) { this.isLookingForHome = false; this.nearestVillager.setDefaultPlayerReputation(5); } } } super.updateAITick(); } public boolean interact(EntityPlayer player) { Minecraft mc = FMLClientHandler.instance().getClient(); if(mc == null || mc.thePlayer == null)return false; ItemStack itemstack = player.inventory.getCurrentItem(); boolean flag = itemstack != null && itemstack.getItem() == Items.spawn_egg; int x = MathHelper.floor_double(posX); int y = MathHelper.floor_double(posY); int z = MathHelper.floor_double(posZ); if (this.isEntityAlive() && !this.isChild() && !player.isSneaking()) { mc.displayGuiScreen(new GuiVillager(this, player)); return true; } else { return super.interact(player); } } protected void entityInit() { super.entityInit(); this.dataWatcher.addObject(16, Integer.valueOf(0)); } public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound) { super.writeEntityToNBT(par1NBTTagCompound); par1NBTTagCompound.setInteger("Profession", this.getProfession()); if(this.firstName != null)par1NBTTagCompound.setString("FirstName", this.firstName); if(this.secondName != null)par1NBTTagCompound.setString("SecondName", this.secondName); if(this.villageName !=null)par1NBTTagCompound.setString("VillageName", this.villageName); par1NBTTagCompound.setInteger("Age", this.age); par1NBTTagCompound.setTag("Inventory", this.inventory.writeToNBT(new NBTTagList())); } public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound) { super.readEntityFromNBT(par1NBTTagCompound); this.setProfession(par1NBTTagCompound.getInteger("Profession")); this.age = par1NBTTagCompound.getInteger("Age"); this.firstName = par1NBTTagCompound.getString("FirstName"); this.secondName = par1NBTTagCompound.getString("SecondName"); this.villageName = par1NBTTagCompound.getString("VillageName"); NBTTagList nbttaglist = par1NBTTagCompound.getTagList("Inventory", 10); this.inventory.readFromNBT(nbttaglist); } protected boolean canDespawn(){ return false; } protected String getLivingSound(){ return "mob.villager.idle"; } protected String getHurtSound(){ return "mob.villager.hit"; } protected String getDeathSound(){ return "mob.villager.death"; } public void setProfession(int par1){ this.dataWatcher.updateObject(16, Integer.valueOf(par1)); } public int getProfession(){ return this.dataWatcher.getWatchableObjectInt(16); } public boolean isMating(){ return this.isMating; } public void setMating(boolean par1){ this.isMating = par1; } public void setPlaying(boolean par1){ this.isPlaying = par1; } public boolean isPlaying(){ return this.isPlaying; } public void setFirstName(){ this.firstName = this.firstnames[this.rand.nextInt(this.firstnames.length)]; } public void setRandomSecondName(){ this.secondName = this.secondnames[this.rand.nextInt(this.secondnames.length)]; } public void setSecondName(String par1){ this.secondName = par1; } public String getFirstName(){ return this.firstName; } public String getSecondName(){ return this.secondName; } public int getAge(){ return this.age; } public String getHomeName(){ if(this.villageName != null) { return this.villageName; } return null; } public void setHomeVillage(){ VillageInfo info = VillageInfo.build(); if(info !=null && info.getNearestVillage() != null) { this.villageName = info.getNearestVillage().getName(); } } public void setRevengeTarget(EntityLivingBase par1EntityLivingBase) { super.setRevengeTarget(par1EntityLivingBase); if (this.nearestVillager != null && par1EntityLivingBase != null) { this.nearestVillager.addOrRenewAgressor(par1EntityLivingBase); if (par1EntityLivingBase instanceof EntityPlayer) { byte b0 = -1; if (this.isChild()) { b0 = -3; } this.nearestVillager.setReputationForPlayer(par1EntityLivingBase.getCommandSenderName(), b0); if (this.isEntityAlive()) { this.worldObj.setEntityState(this, (byte)13); } } } } public void onDeath(DamageSource par1DamageSource) { if (this.nearestVillager != null) { Entity entity = par1DamageSource.getEntity(); if (entity != null) { if (entity instanceof EntityPlayer) { this.nearestVillager.setReputationForPlayer(entity.getCommandSenderName(), -2); } else if (entity instanceof IMob) { this.nearestVillager.endMatingSeason(); } }else if (entity == null) { EntityPlayer entityplayer = this.worldObj.getClosestPlayerToEntity(this, 16.0D); if (entityplayer != null) { this.nearestVillager.endMatingSeason(); } } } if (inventory != null && !this.worldObj.isRemote) { for (int i = 0; i < inventory.getSizeInventory(); ++i) { ItemStack itemstack = inventory.getStackInSlot(i); if (itemstack != null) { this.entityDropItem(itemstack, 0.0F); } } } super.onDeath(par1DamageSource); } @SideOnly(Side.CLIENT) public void handleHealthUpdate(byte par1) { if (par1 == 12) { this.generateRandomParticles("heart"); } else if (par1 == 13) { this.generateRandomParticles("angryVillager"); } else if (par1 == 14) { this.generateRandomParticles("happyVillager"); } else { super.handleHealthUpdate(par1); } } public IEntityLivingData onSpawnWithEgg(IEntityLivingData par1EntityLivingData) { par1EntityLivingData = super.onSpawnWithEgg(par1EntityLivingData); this.setFirstName(); this.setRandomSecondName(); this.setHomeVillage(); return par1EntityLivingData; } @SideOnly(Side.CLIENT) private void generateRandomParticles(String par1Str) { for (int i = 0; i < 5; ++i) { double d0 = this.rand.nextGaussian() * 0.02D; double d1 = this.rand.nextGaussian() * 0.02D; double d2 = this.rand.nextGaussian() * 0.02D; this.worldObj.spawnParticle(par1Str, this.posX + (double)(this.rand.nextFloat() * this.width * 2.0F) - (double)this.width, this.posY + 1.0D + (double)(this.rand.nextFloat() * this.height), this.posZ + (double)(this.rand.nextFloat() * this.width * 2.0F) - (double)this.width, d0, d1, d2); } } public void setLookingForHome() { this.isLookingForHome = true; } public EntityBetterVillager createChild(EntityAgeable par1EntityAgeable) { EntityBetterVillager entityvillager = new EntityBetterVillager(this.worldObj); entityvillager.onSpawnWithEgg((IEntityLivingData)null); entityvillager.setFirstName(); entityvillager.setSecondName(this.secondName); entityvillager.setHomeVillage(); return entityvillager; } public boolean allowLeashing() { return false; } @Override public void attackEntityWithRangedAttack(EntityLivingBase par1EntityLivingBase, float par2) { ItemStack itemstack = this.inventory.getStackInSlot(0); if (itemstack != null && itemstack.getItem() == Items.bow) { EntityArrow entityarrow = new EntityArrow(this.worldObj, this, par1EntityLivingBase, 1.6F, (float)(14 - this.worldObj.difficultySetting.getDifficultyId() * 4)); int i = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, this.getHeldItem()); int j = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, this.getHeldItem()); entityarrow.setDamage(4.5D); if (i > 0)entityarrow.setDamage(entityarrow.getDamage() + (double)i * 0.5D + 0.5D); if (j > 0)entityarrow.setKnockbackStrength(j); this.playSound("random.bow", 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F)); this.worldObj.spawnEntityInWorld(entityarrow); } else if (itemstack != null && itemstack.getItem() == ModBetterWorld.LongBow) { EntityArrow entityarrow = new EntityArrow(this.worldObj, this, par1EntityLivingBase, 1.6F, (float)(14 - this.worldObj.difficultySetting.getDifficultyId() * 4)); int i = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, this.getHeldItem()); int j = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, this.getHeldItem()); entityarrow.setDamage(6.0D); if (i > 0)entityarrow.setDamage(entityarrow.getDamage() + (double)i * 0.5D + 0.5D); if (j > 0)entityarrow.setKnockbackStrength(j); this.playSound("random.bow", 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F)); this.worldObj.spawnEntityInWorld(entityarrow); } else if (itemstack != null && itemstack.getItem() == ModBetterWorld.Crossbow) { //na koncu jest jaki rozrzut na boki przy strzale EntityBolt entityarrow = new EntityBolt(this.worldObj, this, par1EntityLivingBase, 1.3F, (float)(14 - this.worldObj.difficultySetting.getDifficultyId() * 4)); int i = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, this.getHeldItem()); int j = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, this.getHeldItem()); entityarrow.setDamage(7.5D); if (i > 0)entityarrow.setDamage(entityarrow.getDamage() + (double)i * 0.5D + 0.5D); if (j > 0)entityarrow.setKnockbackStrength(j); this.playSound("random.bow", 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F)); this.worldObj.spawnEntityInWorld(entityarrow); } } public void setCombatTask() { ItemStack itemstack = this.getHeldItem(); this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true)); this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityZombie.class, 0, true, true)); this.tasks.addTask(7, new EntityAIWatchClosest(this, EntityZombie.class, 64.0F)); this.tasks.removeTask(new EntityAIAvoidEntity(this, EntityZombie.class, 8.0F, 0.6D, 0.6D)); if (itemstack != null && itemstack.getItem() == Items.bow) { this.tasks.addTask(4, this.aiArrowAttack); this.tasks.removeTask(this.aiAttackOnCollide); } else if(itemstack != null && itemstack.getItem() == ModBetterWorld.LongBow) { this.tasks.addTask(4, this.aiArrowAttack); this.tasks.removeTask(this.aiAttackOnCollide); } else if(itemstack != null && itemstack.getItem() == ModBetterWorld.Crossbow) { this.tasks.addTask(4, this.aiArrowAttack); this.tasks.removeTask(this.aiAttackOnCollide); } else { this.tasks.addTask(4, this.aiAttackOnCollide); this.tasks.removeTask(this.aiArrowAttack); } } public boolean func_142018_a(EntityLivingBase par1EntityLivingBase, EntityLivingBase par2EntityLivingBase) { return true; } public EntityPlayer getBoss() { return this.boss; } public void setBoss(EntityPlayer player) { this.boss = player; } }
-
All class or paste only what is needed?
-
Please help me, I am working on this inventory for a long time and I want to finish it as fast as I can. I am not sure what is wrong. I was considering NBT loading, but I dont have a knowledge how to do that. Maybe packets, some special method or I made an error somewhere?
-
@2Up Yes, it can store 20 stacks of items and 4 armor. Inventory works fine, items are loaded and saved. @Up What do you mean, can you explain a bit? I am not fluent in english. Should I make a method in render class and there get an itemstack?
-
You can make those scroll lists elements as a buttons. Create method to remove button from list and reload the screen.
-
Any help or suggestion?
-
[1.7.10]Throwable Item/Entity is spawning the wrong thing[SOLVED]
SSslimer replied to FishSauce's topic in Modder Support
Can you add main class to first post and other classes which could be collocated with pistol? -
[1.7.10]Throwable Item/Entity is spawning the wrong thing[SOLVED]
SSslimer replied to FishSauce's topic in Modder Support
You want your pistol to shot with 2 different entities?? par2World.spawnEntityInWorld(new powerPack(par2World, par3EntityPlayer)); It spawns only powerPack entity. -
Hey, I have made entity with own inventory, it can store armor items. Problem is when I am trying to get an ItemStack from Slot in armor render class. Code in render class. That method returns itemstack from slot for armor. ItemStack itemstack = villager.inventory.armorItemInSlot(3 - par2); The villager isnt null and when I am trying to use the same method but from entity class I get an item. But in this code it returns always null. It should work but it doesnt. So here is my question for help.
-
Do you use eclipse and have properly set up forge?
-
[1.7.10] Mob with inventory, Simple Network Wrapper problem.
SSslimer replied to SSslimer's topic in Modder Support
Still doesnt work. Do you know some tutorials or sollution? Solved. It was my fault. I made a mistake. Thanks for help. -
[1.7.10] Mob with inventory, Simple Network Wrapper problem.
SSslimer replied to SSslimer's topic in Modder Support
Have you some suggestions or tips how to make it working? Can someone help just a bit? -
[1.7.10] Mob with inventory, Simple Network Wrapper problem.
SSslimer replied to SSslimer's topic in Modder Support
I thinks the same, alse the line with .getEntityByID() is wrong. Is any other way to choose entity? -
[1.7.10] Mob with inventory, Simple Network Wrapper problem.
SSslimer replied to SSslimer's topic in Modder Support
Sorry, it is not very visible and clearly by: Code from another gui, in method actionPerformed(GuiButton guiButton) -
[1.7.10] Mob with inventory, Simple Network Wrapper problem.
SSslimer replied to SSslimer's topic in Modder Support
What do you mean by normal GuiHandler? -
[1.7.10] Trying to use lang file but nothing happens
SSslimer replied to EmperorZelos's topic in Modder Support
What is the name of your lang file? -
[1.7.10] Mob with inventory, Simple Network Wrapper problem.
SSslimer replied to SSslimer's topic in Modder Support
He suggested me to do it in PM. The code is mostly from MultiMode to make it only working Maybe all code for inventory and error log will help. public class InventoryVillager extends InventoryBasic { public InventoryVillager(String name, int slots) { super(name, false, slots); } } Code from container. public class ContainerVillager extends Container { protected IInventory inventory; private int player_inventory_x = 70; private int player_inventory_y = 8; private int loot_x = 8; private int loot_y = 10; public ContainerVillager(InventoryPlayer inventoryPlayer, IInventory iInventory) { inventory = iInventory; { for (int i = 0; i < 4; i++) { for (int j = 0; j < 2; j++) { addSlotToContainer(new Slot(iInventory, j + i * 2, (loot_x + j * 18), (loot_y + i * 18))); } } } bindPlayerInventory(inventoryPlayer); } public boolean canInteractWith(EntityPlayer player) { return inventory.isUseableByPlayer(player); } protected void bindPlayerInventory(InventoryPlayer inventoryPlayer) { for (int i = 0; i < 3; i++) { for (int j = 0; j < 9; j++) { addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9, player_inventory_x + j * 18, player_inventory_y + i * 18)); } } for (int i = 0; i < 9; i++) { addSlotToContainer(new Slot(inventoryPlayer, i, player_inventory_x + i * 18, player_inventory_y + 54 + 4)); } } public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) { ItemStack itemstack = null; Slot slot = (Slot)this.inventorySlots.get(par2); if (slot != null && slot.getHasStack()) { ItemStack itemstack1 = slot.getStack(); itemstack = itemstack1.copy(); int s = inventory.getSizeInventory(); if (par2 < s) { if (!this.mergeItemStack(itemstack1, s, this.inventorySlots.size(), true)) { return null; } } else if (!this.mergeItemStack(itemstack1, 0, s, false)) { return null; } if (itemstack1.stackSize == 0) { slot.putStack(null); } else { slot.onSlotChanged(); } } return itemstack; } public void onContainerClosed(EntityPlayer par1EntityPlayer) { super.onContainerClosed(par1EntityPlayer); this.inventory.closeInventory(); } } Code in GUI. @SideOnly(Side.CLIENT) public class GuiVillagerInventory extends GuiContainer { private static final ResourceLocation texture = new ResourceLocation("BetterWorld:textures/gui/VillagerInventory.png"); private int invW = 176; private int invH = 90; private int lootH = 90; private int lootW = 50; public GuiVillagerInventory(InventoryPlayer inventoryPlayer, InventoryVillager inv) { super(new ContainerVillager(inventoryPlayer, inv)); this.xSize=300; this.ySize=90; } protected void drawGuiContainerForegroundLayer(int param1, int param2) {} protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) { GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); this.mc.renderEngine.bindTexture(texture); int x = (width - invW) / 2; int y = (height - invH) / 2; this.drawTexturedModalRect(x, y, 0, 0, invW, invH); x = (width/ 2)-150; y = (height - lootH) / 2; this.drawTexturedModalRect(x, y, 176, 0, lootW, lootH); } } Code in entity class. public class EntityBetterVillager extends EntityVillagerType implements INpc, IRangedAttackMob, IInvBasic { private InventoryVillager inventoryVillager; public IInventory inventory; public EntityBetterVillager(World par1World) { this(par1World, 0); this.setupInventory(); } public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound) { super.writeEntityToNBT(par1NBTTagCompound); if (!this.isChild()) { NBTTagList nbttaglist = new NBTTagList(); for (int i = 0; i < this.inventoryVillager.getSizeInventory(); ++i) { ItemStack itemstack = this.inventoryVillager.getStackInSlot(i); if (itemstack != null) { NBTTagCompound nbttagcompound1 = new NBTTagCompound(); nbttagcompound1.setByte("Slot", (byte) i); itemstack.writeToNBT(nbttagcompound1); nbttaglist.appendTag(nbttagcompound1); } par1NBTTagCompound.setTag("Items", nbttaglist); } } } public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound) { super.readEntityFromNBT(par1NBTTagCompound); if (!this.isChild()) { NBTTagList nbttaglist = par1NBTTagCompound.getTagList("Items", 20); this.setupInventory(); for (int i = 0; i < nbttaglist.tagCount(); ++i) { NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i); int j = nbttagcompound1.getByte("Slot") & 255; if (j >= 0 && j < this.inventoryVillager.getSizeInventory()) { this.inventoryVillager.setInventorySlotContents(j, ItemStack.loadItemStackFromNBT(nbttagcompound1)); } } } } public int howManySlots() { return 8; } private void setupInventory() { InventoryVillager inventory = this.inventoryVillager; this.inventoryVillager = new InventoryVillager("Villager Inventory", howManySlots()); this.inventoryVillager.func_110133_a(this.getCommandSenderName()); if (inventory != null) { inventory.func_110132_b(this); int i = Math.min(inventory.getSizeInventory(), this.inventoryVillager.getSizeInventory()); for (int j = 0; j < i; ++j) { ItemStack itemstack = inventory.getStackInSlot(j); if (itemstack != null) { this.inventoryVillager.setInventorySlotContents(j, itemstack.copy()); } } inventory = null; } this.inventoryVillager.func_110134_a(this); } @Override public void onInventoryChanged(InventoryBasic var1) {} } Code from another gui, in method actionPerformed(GuiButton guiButton) ModBetterWorld.packets.sendToServer(new GuiRequestPacket(3, this.villager.getEntityId())); In main class public static SimpleNetworkWrapper packets; @EventHandler public void postInit(FMLPostInitializationEvent event) { packets = NetworkRegistry.INSTANCE.newSimpleChannel("ModBetterWorld"); packets.registerMessage(GuiRequestPacket.class, GuiRequestPacket.class, 0, Side.SERVER); } Packet Handler public class GuiRequestPacket implements IMessage, IMessageHandler<GuiRequestPacket, IMessage> { int type; int entityID; public GuiRequestPacket() { } public GuiRequestPacket(int type, int entityID) { this.type = type; this.entityID = entityID; } @Override public void toBytes(ByteBuf target) { target.writeInt(type); target.writeInt(entityID); } @Override public void fromBytes(ByteBuf dat) { type = dat.readInt(); entityID = dat.readInt(); } @Override public IMessage onMessage(GuiRequestPacket message, MessageContext ctx) { System.out.println("requested guiID" + message.type + " for entity ID " + message.entityID); EntityPlayer player = ctx.getServerHandler().playerEntity; World world = player.worldObj; player.openGui(ModBetterWorld.instance, message.type, world, message.entityID, 0, 0); return null; } } When I open gui by button the game crashes. I can see for a while gui screen. Then crash occure. It says sth about forge error. Here is error log: 12:56:36] [server thread/ERROR] [FML]: SimpleChannelHandlerWrapper exception java.lang.NullPointerException at net.minecraft.inventory.Slot.getStack(Slot.java:88) ~[slot.class:?] at net.minecraft.inventory.Container.getInventory(Container.java:67) ~[Container.class:?] at net.minecraft.inventory.Container.addCraftingToCrafters(Container.java:53) ~[Container.class:?] at cpw.mods.fml.common.network.internal.FMLNetworkHandler.openGui(FMLNetworkHandler.java:88) ~[FMLNetworkHandler.class:?] at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2501) ~[EntityPlayer.class:?] at BetterWorld.GuiRequestPacket.onMessage(GuiRequestPacket.java:46) ~[GuiRequestPacket.class:?] at BetterWorld.GuiRequestPacket.onMessage(GuiRequestPacket.java:1) ~[GuiRequestPacket.class:?] at cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.channelRead0(SimpleChannelHandlerWrapper.java:37) ~[simpleChannelHandlerWrapper.class:?] at cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.channelRead0(SimpleChannelHandlerWrapper.java:17) ~[simpleChannelHandlerWrapper.class:?] at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:98) ~[simpleChannelInboundHandler.class:?] at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) [DefaultChannelHandlerContext.class:?] at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) [MessageToMessageDecoder.class:?] at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) [MessageToMessageCodec.class:?] at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) [DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) [DefaultChannelPipeline.class:?] at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) [EmbeddedChannel.class:?] at cpw.mods.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:86) [FMLProxyPacket.class:?] at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) [NetworkManager.class:?] at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182) [NetworkSystem.class:?] at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726) [MinecraftServer.class:?] at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614) [MinecraftServer.class:?] at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) [integratedServer.class:?] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485) [MinecraftServer.class:?] at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752) [MinecraftServer$2.class:?] [12:56:36] [server thread/ERROR] [FML]: There was a critical exception handling a packet on channel ModBetterWorld java.lang.NullPointerException at net.minecraft.inventory.Slot.getStack(Slot.java:88) ~[slot.class:?] at net.minecraft.inventory.Container.getInventory(Container.java:67) ~[Container.class:?] at net.minecraft.inventory.Container.addCraftingToCrafters(Container.java:53) ~[Container.class:?] at cpw.mods.fml.common.network.internal.FMLNetworkHandler.openGui(FMLNetworkHandler.java:88) ~[FMLNetworkHandler.class:?] at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2501) ~[EntityPlayer.class:?] at BetterWorld.GuiRequestPacket.onMessage(GuiRequestPacket.java:46) ~[GuiRequestPacket.class:?] at BetterWorld.GuiRequestPacket.onMessage(GuiRequestPacket.java:1) ~[GuiRequestPacket.class:?] at cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.channelRead0(SimpleChannelHandlerWrapper.java:37) ~[simpleChannelHandlerWrapper.class:?] at cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.channelRead0(SimpleChannelHandlerWrapper.java:17) ~[simpleChannelHandlerWrapper.class:?] at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:98) ~[simpleChannelInboundHandler.class:?] at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) ~[DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) ~[DefaultChannelHandlerContext.class:?] at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) ~[MessageToMessageDecoder.class:?] at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) ~[MessageToMessageCodec.class:?] at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) ~[DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) ~[DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) ~[DefaultChannelPipeline.class:?] at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) ~[EmbeddedChannel.class:?] at cpw.mods.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:86) [FMLProxyPacket.class:?] at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) [NetworkManager.class:?] at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182) [NetworkSystem.class:?] at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726) [MinecraftServer.class:?] at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614) [MinecraftServer.class:?] at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) [integratedServer.class:?] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485) [MinecraftServer.class:?] at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752) [MinecraftServer$2.class:?] [12:56:36] [server thread/ERROR]: Encountered an unexpected exception net.minecraft.util.ReportedException: Ticking player at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:198) ~[NetworkSystem.class:?] at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726) ~[MinecraftServer.class:?] at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614) ~[MinecraftServer.class:?] at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) ~[integratedServer.class:?] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485) [MinecraftServer.class:?] at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752) [MinecraftServer$2.class:?] Caused by: java.lang.NullPointerException at BetterWorld.mobs.ContainerVillager.canInteractWith(ContainerVillager.java:36) ~[ContainerVillager.class:?] at net.minecraftforge.event.entity.player.PlayerOpenContainerEvent.<init>(PlayerOpenContainerEvent.java:27) ~[PlayerOpenContainerEvent.class:?] at net.minecraftforge.common.ForgeHooks.canInteractWith(ForgeHooks.java:386) ~[ForgeHooks.class:?] at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:329) ~[EntityPlayer.class:?] at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:330) ~[EntityPlayerMP.class:?] at net.minecraft.network.NetHandlerPlayServer.processPlayer(NetHandlerPlayServer.java:329) ~[NetHandlerPlayServer.class:?] at net.minecraft.network.play.client.C03PacketPlayer.processPacket(C03PacketPlayer.java:37) ~[C03PacketPlayer.class:?] at net.minecraft.network.play.client.C03PacketPlayer.processPacket(C03PacketPlayer.java:111) ~[C03PacketPlayer.class:?] at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) ~[NetworkManager.class:?] at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182) ~[NetworkSystem.class:?] ... 5 more And next part: Time: 19.10.14 12:56 Description: Ticking player java.lang.NullPointerException: Ticking player at BetterWorld.mobs.ContainerVillager.canInteractWith(ContainerVillager.java:36) at net.minecraftforge.event.entity.player.PlayerOpenContainerEvent.<init>(PlayerOpenContainerEvent.java:27) at net.minecraftforge.common.ForgeHooks.canInteractWith(ForgeHooks.java:386) at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:329) at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:330) at net.minecraft.network.NetHandlerPlayServer.processPlayer(NetHandlerPlayServer.java:329) at net.minecraft.network.play.client.C03PacketPlayer.processPacket(C03PacketPlayer.java:37) at net.minecraft.network.play.client.C03PacketPlayer.processPacket(C03PacketPlayer.java:111) at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182) at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726) at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614) at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485) at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Stacktrace: at BetterWorld.mobs.ContainerVillager.canInteractWith(ContainerVillager.java:36) at net.minecraftforge.event.entity.player.PlayerOpenContainerEvent.<init>(PlayerOpenContainerEvent.java:27) at net.minecraftforge.common.ForgeHooks.canInteractWith(ForgeHooks.java:386) at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:329) -- Player being ticked -- Details: Entity Type: null (net.minecraft.entity.player.EntityPlayerMP) Entity ID: 109 Entity Name: Player170 Entity's Exact location: 642,57, 4,00, 174,03 Entity's Block location: World: (642,4,174), Chunk: (at 2,0,14 in 40,10; contains blocks 640,0,160 to 655,255,175), Region: (1,0; contains chunks 32,0 to 63,31, blocks 512,0,0 to 1023,255,511) Entity's Momentum: 0,00, -0,08, 0,00 Stacktrace: at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:330) at net.minecraft.network.NetHandlerPlayServer.processPlayer(NetHandlerPlayServer.java:329) at net.minecraft.network.play.client.C03PacketPlayer.processPacket(C03PacketPlayer.java:37) at net.minecraft.network.play.client.C03PacketPlayer.processPacket(C03PacketPlayer.java:111) at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) -- Ticking connection -- Details: Connection: net.minecraft.network.NetworkManager@3d7e16 Stacktrace: at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182) at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726) at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614) at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485) at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752) I know that is a lot of code but I will be very thankful if someone help me