-
[1.8][Solved]Tile entity for custom doors...
OKay, I understand now ! Thank you very much ! Here is the method I added in the custom tile entity as suggested from diesieben07: @Override public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newSate) { if(newSate.getBlock() instanceof ProtectedDoor) { return false; } return true; } [/Code]
-
[1.8][Solved]Tile entity for custom doors...
So... It works very good ! thanks a lot ! I just have a problem with the playAuxSFXAtEntity which does not work server side... is there an equivalent ? (It will permit me to avoid using nbt synchronization between the client and the server tiles)
-
[1.8][Solved]Tile entity for custom doors...
Okay, I didn't know this method ever exists ! I'll try this when I can ! Thanks !
-
[1.8][Solved]Tile entity for custom doors...
Hello every body ! I have a problem with my custom door : when i right click on it (and open/close the door) it seems the attached tile entity is destroyed and respawn so it delete all the data saved in it... I don't know what to do... Here is my custom door block code public class ProtectedDoor extends BlockDoor implements ITileEntityProvider{ private final String name = "ProtectedDoor"; public ProtectedDoor() { super(Material.wood); GameRegistry.registerBlock(this, name); setUnlocalizedName(Test.MODID + "_" + name); setHardness(3f); setResistance(20f); setHarvestLevel("axe", 2); // TODO Auto-generated constructor stub } public String getName() { return name; } @Override public void onBlockClicked(World worldIn, BlockPos pos, EntityPlayer playerIn) { if(!worldIn.isRemote) { IBlockState state = worldIn.getBlockState(pos); BlockPos blockpos1 = state.getValue(HALF) == BlockDoor.EnumDoorHalf.LOWER ? pos : pos.down(); ProtectedTileEntity t = (ProtectedTileEntity) worldIn.getTileEntity(new BlockPos(blockpos1)); if(t != null) { t.setDatas(playerIn, worldIn); } } super.onBlockClicked(worldIn, pos, playerIn); } @Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ) { BlockPos blockpos1 = state.getValue(HALF) == BlockDoor.EnumDoorHalf.LOWER ? pos : pos.down(); IBlockState iblockstate1 = pos.equals(blockpos1) ? state : worldIn.getBlockState(blockpos1); if (iblockstate1.getBlock() != this) { return false; } else { state = iblockstate1.cycleProperty(OPEN); ProtectedTileEntity t = (ProtectedTileEntity) worldIn.getTileEntity(new BlockPos(blockpos1)); if(t != null) { if(t.TryToOpen(playerIn, !((Boolean)state.getValue(OPEN)).booleanValue())) { worldIn.setBlockState(blockpos1, state, 2); worldIn.markBlockRangeForRenderUpdate(blockpos1, pos); worldIn.playAuxSFXAtEntity(playerIn, ((Boolean)state.getValue(OPEN)).booleanValue() ? 1003 : 1006, pos, 0); return true; } } } return false; } @Override @SideOnly(Side.CLIENT) public Item getItem(World worldIn, BlockPos pos) { return Item.getByNameOrId("shuyintestmod:"+ItemProtectedDoor.getName()); } @Override public Item getItemDropped(IBlockState state, Random rand, int fortune) { return state.getValue(HALF) == BlockDoor.EnumDoorHalf.UPPER ? null : Item.getByNameOrId("shuyintestmod:"+ItemProtectedDoor.getName()); } @Override public TileEntity createNewTileEntity(World worldIn, int meta) { // TODO Auto-generated method stub return new ProtectedTileEntity(); } } And my custom tile entity public class ProtectedTileEntity extends TileEntity{ private String owner=""; private String password=""; private int UUID = (new Random()).nextInt(10000); @Override public Packet getDescriptionPacket() { NBTTagCompound tagCompound = new NBTTagCompound(); newWriteNBT(tagCompound); return new net.minecraft.network.play.server.S35PacketUpdateTileEntity(this.pos, 1, tagCompound); } @Override public void onDataPacket(net.minecraft.network.NetworkManager net, net.minecraft.network.play.server.S35PacketUpdateTileEntity pkt) { newReadNBT(pkt.getNbtCompound()); } public void setDatas(EntityPlayer player, World world) { if(this.owner.equals("")) { this.owner = player.getDisplayNameString(); player.addChatMessage(new ChatComponentText("Proprietaire de la porte : " + this.owner)); world.markBlockForUpdate(pos); } if(player.inventory.getCurrentItem() != null) { ItemStack key = player.inventory.getCurrentItem(); if(key.getItem() instanceof MetalKey) { if(player.isSneaking() && player.getDisplayNameString().equals(owner)) { this.password = key.getDisplayName(); player.addChatMessage(new ChatComponentText("La serrure a ete changee : " + this.password)); world.markBlockForUpdate(pos); } } } } public boolean TryToOpen(EntityPlayer player, boolean open) { boolean creative = player.capabilities.isCreativeMode; boolean mauvaiseCle = false; if(player.inventory.getCurrentItem() != null) { ItemStack key = player.inventory.getCurrentItem(); if(key.getItem() instanceof MetalKey) { if(key.getDisplayName().equals(password)) { return true; } else { mauvaiseCle = true; } } } player.addChatMessage(new ChatComponentText("Proprietaire : " + this.owner + ", mdp : " + this.UUID)); if(password == "") return true; if(creative || open){ return true; } else{ if(!mauvaiseCle) player.addChatMessage(new ChatComponentText("La porte est fermee !")); else player.addChatMessage(new ChatComponentText("Ce n'est pas la bonne cle !")); return false; } } @Override public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); newReadNBT(nbt); System.out.println("reading protected datas : " + this.owner + " | " + this.password); } public void newWriteNBT(NBTTagCompound nbt) { nbt.setString("Owner", owner); nbt.setString("Password", password); } public void newReadNBT(NBTTagCompound nbt) { this.owner = nbt.getString("Owner"); this.password = nbt.getString("Password"); } @Override public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); newWriteNBT(nbt); System.out.println("saving protected datas : " + this.owner + " | " + this.password); } } If you find some mistake not in relation with my problem, don't hesitate to tell me about it ! Thanks in advance !
-
[1.8][SOLVED]Custom entity : saving new fields
OK I'll do that ! Here is my custom Entity class, I hope this will help someone for the dataWatcher or simply create a custom entity ! public class EntityNPCM extends EntityMob{ protected int careerId; protected boolean canWander; public EntityNPCM(World par1World) { super(par1World); canWander = false; updateTasks(); this.setCanPickUpLoot(false); if(this.getCustomNameTag().isEmpty()) this.setCustomNameTag("MALE_NPC"); } private void updateTasks() { this.tasks.taskEntries.clear(); this.tasks.addTask(1, new EntityAISwimming(this)); this.tasks.addTask(2, new EntityAIWatchClosest2(this, EntityPlayer.class, 3.0F, 1.0F)); this.tasks.addTask(3, new EntityAIWatchClosest(this, EntityLiving.class, 8.0F)); if(canWander) this.tasks.addTask(9, new EntityAIWander(this, 0.4D)); } @Override protected void entityInit() { super.entityInit(); this.dataWatcher.addObject(16, 0); this.dataWatcher.addObject(17, 0); } @Override public int getTalkInterval() { return 200; } @Override protected boolean canDespawn() { return false; } //function used in my render class to get the good careerId @SideOnly(Side.CLIENT) public int getClientCarrerId() { return this.dataWatcher.getWatchableObjectInt(16); } @SideOnly(Side.CLIENT) public boolean isClientMale() { return this.dataWatcher.getWatchableObjectInt(17) == 0; } public void setCarrerId(short id) { this.careerId = id; } /** * (abstract) Protected helper method to write subclass entity data to NBT. */ @Override public void writeEntityToNBT(NBTTagCompound tagCompound) { super.writeEntityToNBT(tagCompound); tagCompound.setInteger("Career", this.careerId); tagCompound.setBoolean("Wander", canWander); } /** * (abstract) Protected helper method to read subclass entity data from NBT. */ @Override public void readEntityFromNBT(NBTTagCompound tagCompund) { super.readEntityFromNBT(tagCompund); this.canWander = tagCompund.getBoolean("Wander"); this.careerId = tagCompund.getInteger("Career"); this.dataWatcher.updateObject(16, this.careerId); updateTasks(); } @Override protected String getHurtSound() { return "shuyintestmod:hurtM"; } @Override protected String getDeathSound() { return "shuyintestmod:deathM"; } @Override protected String getLivingSound() { return "shuyintestmod:livingM"; } @Override public boolean interact(EntityPlayer player) { ItemStack itemstack = player.inventory.getCurrentItem(); boolean flag = itemstack != null && (itemstack.getItem() == Items.spawn_egg || itemstack.getItem() == Items.name_tag); if (!flag && this.isEntityAlive() && !this.worldObj.isRemote) { if(itemstack != null) { if(itemstack.getItem() instanceof ItemTest) { if(player.isSneaking()) { this.setDead(); } else { canWander = !canWander; if(canWander) player.addChatMessage(new ChatComponentText(this.getCustomNameTag() + " will now be wandering.")); else player.addChatMessage(new ChatComponentText(this.getCustomNameTag() + " will stand still.")); updateTasks(); } return true; } } if(player.capabilities.isCreativeMode && player.isSneaking()) { this.careerId++; if(this.careerId > 5) this.careerId = 0; this.dataWatcher.updateObject(16, this.careerId); } else { player.addChatMessage(new ChatComponentText(this.getCustomNameTag() + " : Mon ID = "+ this.careerId + " : " + getUniqueID().toString())); } return true; } else { return super.interact(player); } } }
-
[1.8][SOLVED]Custom entity : saving new fields
Aand... It works ! Thank you very much for your precious help ! AAahh if only I knew about datawatcher sooner ! Ernio, "Do not declare Resource with every render pass, save those as static files somewhere and just reference them." Do I have to create a list of strings and create the new Resource location in the getEntityTexture Method or It's best to create a list of ResourceLocation directly ? I will post my custom Entity class later for help
-
[1.8][SOLVED]Custom entity : saving new fields
OK, Client side the getcarrerId returns always 0. Here is my Updated entity class : public class EntityNPCM extends EntityMob{ protected short careerId; public EntityNPCM(World par1World) { super(par1World); this.tasks.addTask(9, new EntityAIWatchClosest2(this, EntityPlayer.class, 3.0F, 1.0F)); this.tasks.addTask(9, new EntityAIWander(this, 0.6D)); this.tasks.addTask(10, new EntityAIWatchClosest(this, EntityLiving.class, 8.0F)); this.setCanPickUpLoot(false); if(this.getCustomNameTag().isEmpty()) this.setCustomNameTag("NPC"); } @Override public int getTalkInterval() { return 200; } @Override protected boolean canDespawn() { return false; } public short getCarrerId() { if(this.worldObj.isRemote) { System.out.println("getting careerId in Client :" + this.careerId); } else { System.out.println("getting careerId in Server :" + this.careerId); } return this.careerId; } public void setCarrerId(short id) { this.careerId = id; } /** * (abstract) Protected helper method to write subclass entity data to NBT. */ @Override public void writeEntityToNBT(NBTTagCompound tagCompound) { super.writeEntityToNBT(tagCompound); tagCompound.setShort("Career", this.careerId); System.out.println("sauvegarde NBT NPC :" + this.careerId +" " + getCustomNameTag() + " : " + getUniqueID().toString()); } /** * (abstract) Protected helper method to read subclass entity data from NBT. */ @Override public void readEntityFromNBT(NBTTagCompound tagCompund) { super.readEntityFromNBT(tagCompund); this.careerId = tagCompund.getShort("Career"); System.out.println("charge NBT NPC :" + this.careerId+" " + getCustomNameTag() + " : " + getUniqueID().toString()); } @Override protected String getHurtSound() { return "shuyintestmod:hurtM"; } @Override protected String getDeathSound() { return "shuyintestmod:deathM"; } @Override protected String getLivingSound() { return "shuyintestmod:livingM"; } @Override public boolean interact(EntityPlayer player) { ItemStack itemstack = player.inventory.getCurrentItem(); boolean flag = itemstack != null && (itemstack.getItem() == Items.spawn_egg || itemstack.getItem() == Items.name_tag); if (!flag && this.isEntityAlive()) { if(!this.worldObj.isRemote) { if(itemstack != null) { if(itemstack.getItem() instanceof ItemTest) { this.setDead(); return true; } } if(player.capabilities.isCreativeMode && player.isSneaking()) { this.careerId++; if(careerId > 5) careerId = 0; } else { player.addChatMessage(new ChatComponentText(this.getCustomNameTag() + " : Mon ID = "+ this.careerId + " : " + getUniqueID().toString())); } } return true; } else { return super.interact(player); } } }
-
[1.8][SOLVED]Custom entity : saving new fields
OK It works server side fine now, thank you very much ! But I have a problem : my entities don't render correctly ! They have the default skin but normally when I shift + right click on them, they have to change skin(switch the careerId). It worked before but wasn't saved. Here, the careerId is saved but the entities don't change their skins. Here is my Render class : public class RenderNPC extends RenderLiving { public RenderNPC(ModelBiped model, float shadowSize) { super(Minecraft.getMinecraft().getRenderManager(), model, shadowSize); } @Override protected boolean canRenderName(Entity Entity) { return true; } @Override protected ResourceLocation getEntityTexture(Entity par1Entity) { if(par1Entity instanceof EntityNPCM) { ResourceLocation textureLocation; EntityNPCM entity = (EntityNPCM) par1Entity; if(entity.getCarrerId()<0 || entity.getCarrerId()>5 ) textureLocation = new ResourceLocation(Test.MODID + ":" + "textures/models/entityNPC" + (par1Entity instanceof EntityNPCF ? "F" : "M") + "0.png"); else textureLocation = new ResourceLocation(Test.MODID + ":" + "textures/models/entityNPC" + (par1Entity instanceof EntityNPCF ? "F" : "M") + entity.getCarrerId()+ ".png"); return textureLocation; } else return null; } } which is called client side only RenderingRegistry.registerEntityRenderingHandler(EntityNPCM.class, new RenderNPC(new ModelBiped(), 0.5F)); RenderingRegistry.registerEntityRenderingHandler(EntityNPCF.class, new RenderNPC(new ModelBiped(), 0.5F));
-
[1.8][SOLVED]Custom entity : saving new fields
OK I can spawn my custom entity. But.. should I spawn it Server side, client side or both ? I tried all the solution : - serveur side : spawn the correct entity but I can't interract with it -Client side : spawn an herited entity and I can interract with it but not saving anything -both : spawn the two entities
-
[1.8][SOLVED]Custom entity : saving new fields
OK what should I use instead of RegsiterGlobal EntityID ? It tried without but I can't see my spawn egg anymore (it's obvious I know) but even with adding EntityList.entityEggs.put(entityID, new EntityList.EntityEggInfo(entityID, primaryColor, secondaryColor)); at the end of my register, I can only see an egg that can't spawn anything !
-
[1.8][SOLVED]Custom entity : saving new fields
OK here is my commonProxy class I register my two entities here (both client and server side) I need to register them only server side ? public class CommonProxy { public static Item testItem; public static Item itemProtectedDoor; public static Block protectedDoor; public static void registerEntity(Class entityClass, String name) { int entityID = EntityRegistry.findGlobalUniqueEntityId(); long seed = name.hashCode(); Random rand = new Random(seed); int primaryColor = rand.nextInt() * 16777215; int secondaryColor = rand.nextInt() * 16777215; EntityRegistry.registerGlobalEntityID(entityClass, name, entityID,primaryColor,secondaryColor); EntityRegistry.registerModEntity(entityClass, name, entityID, Test.instance, 64, 1, true); } public void preInit(FMLPreInitializationEvent e) { testItem = new ItemTest(); protectedDoor = new ProtectedDoor(); itemProtectedDoor = new ItemProtectedDoor(protectedDoor); registerEntity(EntityNPCM.class, "entityNPCM"); registerEntity(EntityNPCF.class, "entityNPCF"); } public void init(FMLInitializationEvent e) { registerEventListeners(); registerRenderers(); } public void postInit(FMLPostInitializationEvent e) { } public void registerEventListeners() { MinecraftForge.EVENT_BUS.register(new EventHandlerTest()); } public void registerRenderers() { } } (both client and server proxy extends to this method. I override the registerRenderers only client side) in my custom entity class, I need to modify my interact method like this ? @Override public boolean interact(EntityPlayer player) { ItemStack itemstack = player.inventory.getCurrentItem(); boolean flag = itemstack != null && (itemstack.getItem() == Items.spawn_egg || itemstack.getItem() == Items.name_tag); if (!flag && this.isEntityAlive()) { if(!this.worldObj.isRemote) { if(itemstack != null) { if(itemstack.getItem() instanceof ItemTest) { this.setDead(); return true; } } if(player.capabilities.isCreativeMode && player.isSneaking()) { this.careerId++; if(careerId > 5) careerId = 0; } else { player.addChatMessage(new ChatComponentText(this.getCustomNameTag() + " : Mon ID = "+ this.careerId + " : " + getUniqueID().toString())); } } return true; } else { return super.interact(player); } }
-
[1.8][SOLVED]Custom entity : saving new fields
OK, since when I set this for both sides, when I right click on them, I receive two messages, how do I make sure I execute the execute method only once ?
-
[1.8][SOLVED]Custom entity : saving new fields
So I'm testing the save with the two methods and a debug in each : [23:21:48] [server thread/INFO] [sTDOUT/]: [com.shuyin.test.NPCExtendedProperties:loadNBTData:31]: charge NPC :0 POupoule : 3892f46a-f22c-4720-b2ce-41bacbcaf0dc [23:21:48] [server thread/INFO] [sTDOUT/]: [com.shuyin.test.EntityNPCM:func_70037_a:83]: charge NBT NPC :0 POupoule : 3892f46a-f22c-4720-b2ce-41bacbcaf0dc [23:21:50] [server thread/INFO] [sTDOUT/]: [com.shuyin.test.NPCExtendedProperties:loadNBTData:31]: charge NPC :0 NPC : b5b17f2a-b5fc-4b3e-a380-27905785a363 [23:21:50] [server thread/INFO] [sTDOUT/]: [com.shuyin.test.EntityNPCM:func_70037_a:83]: charge NBT NPC :0 NPC : b5b17f2a-b5fc-4b3e-a380-27905785a363 -- Here, I suppose I'm playing, and I set the careerId to 2 for the NPC POupoule and 1 for the other -- [23:22:01] [server thread/INFO] [sTDOUT/]: [com.shuyin.test.NPCExtendedProperties:saveNBTData:17]: sauvegarde NPC :0 POupoule : 3892f46a-f22c-4720-b2ce-41bacbcaf0dc [23:22:01] [server thread/INFO] [sTDOUT/]: [com.shuyin.test.EntityNPCM:func_70014_b:71]: sauvegarde NBT NPC :0 POupoule : 3892f46a-f22c-4720-b2ce-41bacbcaf0dc [23:22:01] [server thread/INFO] [sTDOUT/]: [com.shuyin.test.NPCExtendedProperties:saveNBTData:17]: sauvegarde NPC :0 NPC : b5b17f2a-b5fc-4b3e-a380-27905785a363 [23:22:01] [server thread/INFO] [sTDOUT/]: [com.shuyin.test.EntityNPCM:func_70014_b:71]: sauvegarde NBT NPC :0 NPC : b5b17f2a-b5fc-4b3e-a380-27905785a363 But you can see, the custom name of the entity can be read but not the careerId.(always 0) If I set the careerId to 3 for example during the save, It will load 3 but the careerId will be 0 on my real Entity. EDIT : I noticed that the UUID of the Entity wasn't the same that the UUID showed in the log. In the custom entity class, do you have to specify a serverSide for the Write/read to NBT method ? And for the IEEP, do you have to register them in server side only ?
-
[1.8][SOLVED]Custom entity : saving new fields
OK, you suggest I make something like that ? in my custom entity class @Override public void writeEntityToNBT(NBTTagCompound tagCompound) { super.writeEntityToNBT(tagCompound); tagCompound.setInteger("Career", this.careerId); } @Override public void readEntityFromNBT(NBTTagCompound tagCompund) { super.readEntityFromNBT(tagCompund); this.careerId = tagCompund.getInteger("Career"); } I already tried this and it don't work And I'm sure I registered my IEEP because I can see my logs when loading and saving nbt.
-
[1.8][SOLVED]Custom entity : saving new fields
OK, I changed it but it don't work. I'm not sure but It seems to save correctly but when saving, it got 0 from career but have the good CustomName.(I changed the career level during the game and I'm sure the entity have a career lvl different than 0.
IPS spam blocked by CleanTalk.