Posted July 12, 201510 yr I ran into a weird problem while testing my mod, the code to spawn the entity have always stayed the same while I added on a yaml check for the entity. To clarify every the mod is to keep the player infomation online when they log off so I spawn an entity into the location of the player as they log off and everything worked fine until today. This is my code to spawn the entity (it have remain unchanged since I add the yaml checking code): @SubscribeEvent public void playerLogOff(PlayerLoggedOutEvent e) { EntityPlayer player = e.player; World world = player.getEntityWorld(); EntityOfflinePlayer offline = new EntityOfflinePlayer(player.getEntityWorld(), player.posX, player.posY, player.posZ);// <-- set the position and world // // //change player to config offline.setCustomNameTag(player.getDisplayNameString()); offline.setHealth(player.getHealth()); offline.setCurrentItemOrArmor(0, player.getHeldItem()); world.spawnEntityInWorld(offline);// <--- should spawn the entity System.out.println(player + ", " + player.posX + ", " + player.posY + ", " + player.posZ); System.out.println(offline + ", " + offline.posX + ", " + offline.posY + ", " + offline.posZ ); try { data.createFile(player.getUniqueID()); data.savePlayerInfo(player); System.out.println("Loaded"); } catch (IOException e1) { e1.printStackTrace(); } } Result of sysout: [23:36:19] [server thread/INFO] [sTDOUT]: [com.pandaism.NLO.events.PlayerLoggingHandler:playerLogOff:77]: EntityPlayerMP['Player890'/7111, l='New World', x=-243.50, y=72.00, z=6.50], -243.5, 72.0, 6.5 [23:36:19] [server thread/INFO] [sTDOUT]: [com.pandaism.NLO.events.PlayerLoggingHandler:playerLogOff:78]: EntityOfflinePlayer['Player890'/9920, l='New World', x=-243.50, y=72.00, z=6.50], -243.5, 72.0, 6.5
July 12, 201510 yr Author When I check with if(world.loadedEntityList.contains(offline)) { System.out.println("Success"); } else { System.out.println("Failed"); } sysout will always print "Success" but the entity is nowhere to be found
July 12, 201510 yr Author Yep it renders the entity on smp but on ssp it doesn't but I guess that's good cause the mod is suppose to be for smp
July 12, 201510 yr Author Renderer: package com.pandaism.NLO.mobs.graphics; import net.minecraft.client.Minecraft; import net.minecraft.client.model.ModelBiped; import net.minecraft.client.renderer.entity.RenderBiped; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public class RenderOfflinePlayer extends RenderBiped { private ResourceLocation texture; public RenderOfflinePlayer(ModelBiped model, float shadowSize, String string) { super(Minecraft.getMinecraft().getRenderManager(), model, shadowSize); this.texture = new ResourceLocation("nlo", string); } protected ResourceLocation getEntityTexture(EntityLiving entity) { return this.texture; } } register: package com.pandaism.NLO; import com.pandaism.NLO.mobs.entity.EntityOfflinePlayer; import com.pandaism.NLO.mobs.graphics.RenderOfflinePlayer; import net.minecraft.client.Minecraft; import net.minecraft.client.model.ModelBiped; import net.minecraft.client.renderer.entity.RenderManager; import net.minecraftforge.fml.client.registry.RenderingRegistry; import net.minecraftforge.fml.common.registry.EntityRegistry; public class ClientProxy extends ServerProxy { public void registerRenders() { RenderingRegistry.registerEntityRenderingHandler(EntityOfflinePlayer.class, new RenderOfflinePlayer(new ModelBiped(), 0.5F, "textures/entity/offlineplayer.png")); } } main: package com.pandaism.NLO; import java.io.File; import java.io.IOException; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.FMLCommonHandler; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.SidedProxy; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import com.pandaism.NLO.events.OfflinePlayerDropsHandler; import com.pandaism.NLO.events.PlayerLoggingHandler; import com.pandaism.NLO.handlers.EntityHandler; import com.pandaism.NLO.mobs.entity.EntityOfflinePlayer; @Mod(modid = RefString.MODID, name = RefString.NAME, version = RefString.VERSION) public class NeverLogOff { PlayerLoggingHandler logging; @Mod.Instance public static NeverLogOff instance; @SidedProxy(clientSide = RefString.CLIENT, serverSide = RefString.SERVER) public static ServerProxy proxy; @EventHandler public void preLoad(FMLPreInitializationEvent e) { } @EventHandler public void Load(FMLInitializationEvent e) { FMLCommonHandler.instance().bus().register(new PlayerLoggingHandler()); MinecraftForge.EVENT_BUS.register(new OfflinePlayerDropsHandler()); EntityHandler.RegisterMobs(EntityOfflinePlayer.class, "Offline Player"); proxy.registerRenders(); } }
July 12, 201510 yr Author package com.pandaism.NLO.handlers; import java.util.Random; import com.pandaism.NLO.NeverLogOff; import com.pandaism.NLO.RefString; import net.minecraft.entity.EntityList; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.common.registry.EntityRegistry; public class EntityHandler { public static void RegisterMobs(Class entityClass, String name) { int entityID = EntityRegistry.findGlobalUniqueEntityId(); long x = name.hashCode(); Random ran = new Random(x); int mainColor = ran.nextInt() * 16777215; int subColor = ran.nextInt() * 16777215; EntityRegistry.registerGlobalEntityID(entityClass, name, entityID); EntityRegistry.registerModEntity(entityClass, name, entityID, NeverLogOff.instance, 64, 1, false); EntityList.entityEggs.put(Integer.valueOf(entityID), new EntityList.EntityEggInfo(entityID, mainColor, subColor)); } } This is the entity on SMP http://prntscr.com/7ru9v7 which spawns properly
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.