
Darki
Members-
Posts
161 -
Joined
-
Last visited
Everything posted by Darki
-
[1.12.2] Force Entities and Player to move to specified Location
Darki replied to Darki's topic in Modder Support
Anyone? What I tried so far: - Using the Entity#move Method - Using the EntityCreature#getNavigator#tryMoveToXYZ Nothing of it works. Do I have to write an own Pathfinder or Method? -
What....Oh ok. I am completely new in coding mods....I can code plugins....and java it selfs....But coding mods is so much diffrent to coding plugins. So does that mean as long as I do nothing completely wrong with the proxies....it should work? Or are there any other things I need to watch out for?
-
Ok. For now I'll leave it like this because its working on the Client....Server-Side I did not test anything in my Mod....Maybe I have to re code some code so that my mod can be played in MP. But for now its just find. And at the moment my mod has other "problems"
-
Its a simple and dumb answer: Because Mojang does it in the same Way. @Nullable public EntityLivingBase getOwner() { try { UUID uuid = this.getOwnerId(); return uuid == null ? null : this.world.getPlayerEntityByUUID(uuid); } catch (IllegalArgumentException var2) { return null; } } This is the Code of EntityTameable#getOwner
-
And this would be the Problem^^ I am storing the UUID of the User in the NBT Tags of an Entity. To explain a little bit more: I have a custom Entity which is not tamable but kind of....The Owner gets set by the mod itsselfs....
-
Would this work? public static EntityPlayer findPlayer(World world, UUID uuid) { return !DeathNote.getInstance().getProxy().isServer() ? world.getPlayerEntityByUUID(uuid) : FMLServerHandler.instance().getServer().getPlayerList().getPlayerByUUID(uuid); }
-
Hi, I have a simple Question but I cant figure out how to solve it. I want to get the Player by the given UUID when the Mod is running on the Client not on the Server. To show you what I want here my current code: public static EntityPlayer findPlayer(World world, UUID uuid) { return !world.isRemote ? Minecraft.getMinecraft().player : // The Getter when the Player is on a Server } I have a Static Method which returns an EntityPlayer Object. I check via world.IsRemote if the Player is on the Server or not, when not it returns the Minecraft Player because there is only one Player but when he is playing on a Server I want to return the Player from the given UUID. I hope I could show you what I want^^ Thanks in advanced. Darki
-
Hey, Its really simple but i am too dumb to solve it. I have a ClientConnectedToServerEvent and I ask how can I get the UUID in this Event from the current Player. When I use Minecraft#player I get a NP Exception. So how^^.
-
Thanks. Cause of your tips I could improve it. But that wasnt the probleme. I figured it out and honestly i am an idiot . I forgot to call markDirty() after generating my data^^
-
Or is there another way to save data which is associated to a world?
-
I debugged a little bit. Everytime i load the data, its null so that its creating a new data. And i find out that when i save the world an exception will thrown. But not in my code i think: [16:46:14] [Server thread/INFO] [STDERR]: [net.minecraft.world.storage.MapStorage:saveData:142]: java.lang.IllegalArgumentException: Name and ID cannot both be blank [16:46:14] [Server thread/INFO] [STDERR]: [net.minecraft.world.storage.MapStorage:saveData:142]: at com.mojang.authlib.GameProfile.<init>(GameProfile.java:25) [16:46:14] [Server thread/INFO] [STDERR]: [net.minecraft.world.storage.MapStorage:saveData:142]: at net.minecraft.server.management.PlayerProfileCache.lookupProfile(PlayerProfileCache.java:100) [16:46:14] [Server thread/INFO] [STDERR]: [net.minecraft.world.storage.MapStorage:saveData:142]: at net.minecraft.server.management.PlayerProfileCache.getGameProfileForUsername(PlayerProfileCache.java:183) [16:46:14] [Server thread/INFO] [STDERR]: [net.minecraft.world.storage.MapStorage:saveData:142]: at net.minecraft.village.Village.writeVillageDataToNBT(Village.java:552) [16:46:14] [Server thread/INFO] [STDERR]: [net.minecraft.world.storage.MapStorage:saveData:142]: at net.minecraft.village.VillageCollection.writeToNBT(VillageCollection.java:300) [16:46:14] [Server thread/INFO] [STDERR]: [net.minecraft.world.storage.MapStorage:saveData:142]: at net.minecraft.world.storage.MapStorage.saveData(MapStorage.java:134) [16:46:14] [Server thread/INFO] [STDERR]: [net.minecraft.world.storage.MapStorage:saveData:142]: at net.minecraft.world.storage.MapStorage.saveAllData(MapStorage.java:114) [16:46:14] [Server thread/INFO] [STDERR]: [net.minecraft.world.storage.MapStorage:saveData:142]: at net.minecraft.world.WorldServer.saveLevel(WorldServer.java:1116) [16:46:14] [Server thread/INFO] [STDERR]: [net.minecraft.world.storage.MapStorage:saveData:142]: at net.minecraft.world.WorldServer.saveAllChunks(WorldServer.java:1057) [16:46:14] [Server thread/INFO] [STDERR]: [net.minecraft.world.storage.MapStorage:saveData:142]: at net.minecraft.server.MinecraftServer.saveAllWorlds(MinecraftServer.java:415) [16:46:14] [Server thread/INFO] [STDERR]: [net.minecraft.world.storage.MapStorage:saveData:142]: at net.minecraft.server.integrated.IntegratedServer.saveAllWorlds(IntegratedServer.java:238) [16:46:14] [Server thread/INFO] [STDERR]: [net.minecraft.world.storage.MapStorage:saveData:142]: at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:141) [16:46:14] [Server thread/INFO] [STDERR]: [net.minecraft.world.storage.MapStorage:saveData:142]: at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:537) [16:46:14] [Server thread/INFO] [STDERR]: [net.minecraft.world.storage.MapStorage:saveData:142]: at java.lang.Thread.run(Unknown Source) Maybe I call the method at the wrong time in the wrong place. The load method will be called when an entity joins the world especially the player. Where else should i call the method? If you need the code where I call the method: @SubscribeEvent public void onJoinWorld(EntityJoinWorldEvent e) { Diseases.instance.combinationManager.load(e.getWorld()); }
-
Nope still not working: public static class CombinationData extends WorldSavedData { private static final String DATA_NAME = Diseases.MOD_ID + "_combinationData"; private List<Combination> combinations; public CombinationData() { super(DATA_NAME); } public CombinationData(String name) { super(name); } public static CombinationData get(World world) { MapStorage storage = world.getMapStorage(); CombinationData data = (CombinationData)storage.getOrLoadData(CombinationData.class, DATA_NAME); if (data == null) { generate(); data = new CombinationData(); data.combinations = CombinationManager.combinations; storage.setData(DATA_NAME, data); } return data; } @Override public void readFromNBT(NBTTagCompound nbt) { for (EnumDisease disease : EnumDisease.values()) { if (nbt.hasKey(disease.getTag())) combinations.add(new Combination(disease, EnumAtom.valueOf(nbt.getString(disease.getTag())), EnumCapsid.valueOf(nbt.getString(disease.getTag())), EnumNucleicAcid.valueOf(nbt.getString(disease.getTag())))); } } public void setCombinations(List<Combination> combinations) { this.combinations = combinations; } public List<Combination> getCombinations() { return combinations; } @Override public NBTTagCompound writeToNBT(NBTTagCompound compound) { for (Combination combination : combinations) { compound.setString(combination.disease.getTag(), combination.atom.toString() + ";" + combination.capsid.toString() + ";" + combination.nucleicAcid.toString()); } return compound; } }
-
Hi, I am just working on my mod. I made an algorithm that generates random recipes for something. I want save this recipes in the world data. I searched for it and found WorldSavedData. I tried it with it but every time the world gets loaded the recipes aren't the same. Here my Code: public static List<Combination> combinations; private boolean loaded; public CombinationManager() { combinations = new ArrayList<CombinationManager.Combination>(); loaded = false; } private static void generate() { List<CacheCombination> cacheCombinations = new ArrayList<CombinationManager.CacheCombination>(); for (EnumDisease disease : EnumDisease.values()) { CacheCombination cacheCombination = generateCombination(); while (cacheCombinations.contains(cacheCombination)) { cacheCombination = generateCombination(); } combinations.add(new Combination(disease, cacheCombination.atom, cacheCombination.capsid, cacheCombination.nucleicAcid)); } } public void load(World world) { if (!loaded) { combinations = CombinationData.get(world).combinations; for (Combination combination : combinations) { System.out.println("COMBI: " + combination.disease.getName() + " = " + combination.atom.toString() + " + " + combination.capsid.toString() + " + " + combination.nucleicAcid.toString()); } loaded = true; } } private static CacheCombination generateCombination() { return new CacheCombination(EnumCapsid.values()[new Random().nextInt(EnumCapsid.values().length)], EnumAtom.values()[new Random().nextInt(EnumAtom.values().length)], EnumNucleicAcid.values()[new Random().nextInt(EnumNucleicAcid.values().length)]); } public static class CombinationData extends WorldSavedData { private static final String DATA_NAME = Diseases.MOD_ID + "_combinationData"; private List<Combination> combinations; public CombinationData() { super(DATA_NAME); } public CombinationData(String name) { super(name); } public static CombinationData get(World world) { CombinationData data = (CombinationData)world.loadItemData(CombinationData.class, DATA_NAME); if (data == null) { generate(); data = new CombinationData(); data.combinations = CombinationManager.combinations; world.setItemData(DATA_NAME, data); } return data; } @Override public void readFromNBT(NBTTagCompound nbt) { for (EnumDisease disease : EnumDisease.values()) { if (nbt.hasKey(disease.getTag())) combinations.add(new Combination(disease, EnumAtom.valueOf(nbt.getString(disease.getTag())), EnumCapsid.valueOf(nbt.getString(disease.getTag())), EnumNucleicAcid.valueOf(nbt.getString(disease.getTag())))); } } public void setCombinations(List<Combination> combinations) { this.combinations = combinations; } public List<Combination> getCombinations() { return combinations; } @Override public NBTTagCompound writeToNBT(NBTTagCompound compound) { for (Combination combination : combinations) { compound.setString(combination.disease.getTag(), combination.atom.toString() + ";" + combination.capsid.toString() + ";" + combination.nucleicAcid.toString()); } return compound; } }
-
Thank you very much. Its working^^ Normally i code spigot plugins its in some points alot easier
-
Ok this I did solve, i hope: @Override public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand) { if(itemStackIn.getItem() == Diseases.instance.items.itemSyringEmpty) { ItemStack itemStack = new ItemStack(Diseases.instance.items.itemSyringFilled); NBTTagCompound data = itemStack.getSubCompound("itemData", true); data.setString("bloodFrom", playerIn.getName()); data.setString("bloodFromID", playerIn.getUniqueID().toString()); return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemStack); } return super.onItemRightClick(itemStackIn, worldIn, playerIn, hand); } I dont know how to use it. And can it be dynamic then? So that the item shows the name of the "victim". Can you just explain how to use it (i dont want code^^) just an explaination.
-
Yes. I use subcompund. But the other ones: I dont know how to do it. Ok the Exception Catch I could change easily. But never used TextFormatting and Tooltips in the lang file
-
Ok. Here we go: public class ItemSyringEmpty extends BasicItem{ public ItemSyringEmpty() { super("SyringEmpty", "You can fill the Syring by rightclicking.", "§7Status: §c§lEmpty"); } @Override public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand) { if(itemStackIn.getItem() == Diseases.instance.items.itemSyringEmpty) { int slot = getSlot(playerIn, itemStackIn); if(slot != -1) { ItemStack itemStack = new ItemStack(Diseases.instance.items.itemSyringFilled); NBTTagCompound data = itemStack.getSubCompound("itemData", true); data.setString("bloodFrom", playerIn.getName()); data.setString("bloodFromID", playerIn.getUniqueID().toString()); playerIn.inventory.mainInventory[slot] = itemStack; } } return super.onItemRightClick(itemStackIn, worldIn, playerIn, hand); } @Override public boolean onLeftClickEntity(ItemStack stack, EntityPlayer player, Entity entity) { if(stack.getItem() == Diseases.instance.items.itemSyringEmpty) { int slot = getSlot(player, stack); if(slot != -1) { ItemStack itemStack = new ItemStack(Diseases.instance.items.itemSyringFilled); NBTTagCompound data = itemStack.getSubCompound("itemData", true); data.setString("bloodFrom", entity.getName()); data.setString("bloodFromID", entity.getUniqueID().toString()); Random random = new Random(); if(random.nextInt(10) == 0) { int amount = random.nextInt(2) + 1; while(amount != 0) { amount--; Diseases.instance.dataManager.addDisease(itemStack, EnumDisease.values()[random.nextInt(EnumDisease.values().length)]); } } player.inventory.mainInventory[slot] = itemStack; } } return super.onLeftClickEntity(stack, player, entity); } private int getSlot(EntityPlayer player, ItemStack item) { try { return player.inventory.getSlotFor(item); }catch (Exception e) { return -1; } } I didnt change the line with removing item from inventory by now but i will....^^ public class ItemSyringFilled extends BasicItem{ public ItemSyringFilled() { super("SyringFilled", "Its filled with Blood. It can be \nused to inject medicine or \nyour own virus by rightclicking.", "§7Status: §a§lFilled"); } @Override public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced) { if(stack.hasTagCompound()) { if(stack.getSubCompound("itemData", true).hasKey("bloodFrom")) { this.addLine("§7Blood from: §4" + stack.getSubCompound("itemData", true).getString("bloodFrom")); } if(stack.getSubCompound("itemData", true).hasKey("diseases")) { } } super.addInformation(stack, playerIn, tooltip, advanced); } @Override public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand) { if(itemStackIn.getItem() == Diseases.instance.items.itemSyringFilled) { //TODO inject } return super.onItemRightClick(itemStackIn, worldIn, playerIn, hand); } }
-
Ok. Changed it. But it didn't solve my probleme.
-
Can the Sub-Compound be null? Because i cant see a hasSubCompund Method....
-
Ok. I'll improve it. But one question: How do i use Sub-compound? Never used it^^
-
Hmm. Yeah i see. Thats better... Nope. I didn't know that. Thanks for the info^^ Here the rest of my Code: BasicItem: public abstract class BasicItem extends Item{ private String[] extraLore; private String[] description; public BasicItem(String description, String...extraLore) { setCreativeTab(Diseases.TAB); this.description = description.split("\n"); this.extraLore = extraLore; } public void addLine(String line) { List<String> list = new ArrayList<String>(); for(String str : extraLore) { list.add(str); } if(!list.contains(line)) list.add(line); extraLore = list.toArray(new String[list.size()]); } @Override public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced) { if(extraLore.length > 0) { for(String line : extraLore) { tooltip.add(line); } tooltip.add(" "); } for(String line : description) { tooltip.add("§7" + line); } } } And you do have the syrings on the top^^
-
Hi, I am working on a mod. I've made a Syring, when you rightclicking it , it will fill with the players blood (i save the player's name and uuid as nbttag in the item). When you hover over the filled syring the Name of the "victim" will be shown (i check the nbt data). My problem is: It seems that the nbt data is for all items the same. When i used a syring and look in the Creative menu the syring in it shows me the name of mine. How can i do it that the nbt is bound to the itemstack? If you need my code: NBT Data (Syring-Use): public class ItemSyringEmpty extends BasicItem{ public ItemSyringEmpty() { super("You can fill the Syring by rightclicking.", "§7Status: §c§lEmpty"); } @Override public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand) { if(itemStackIn.getUnlocalizedName().contains("itemSyringEmpty")) { int slot = getSlot(playerIn, itemStackIn); if(slot != -1) { ItemStack itemStack = new ItemStack(Diseases.instance.items.itemSyringFilled); NBTTagCompound data; if(itemStack.hasTagCompound()) data = itemStack.getTagCompound(); else data = new NBTTagCompound(); data.setString("bloodFrom", playerIn.getName()); data.setString("bloodFromID", playerIn.getUniqueID().toString()); itemStack.setTagCompound(data); playerIn.inventory.mainInventory[slot] = itemStack; } } return super.onItemRightClick(itemStackIn, worldIn, playerIn, hand); } private int getSlot(EntityPlayer player, ItemStack item) { try { return player.inventory.getSlotFor(item); }catch (Exception e) { return -1; } } } NBT Data (Syring-Hover-Lore): public class ItemSyringFilled extends BasicItem{ public ItemSyringFilled() { super("Its filled with Blood. It can be \nused to inject medicine or \nyour own virus by rightclicking.", "§7Status: §a§lFilled"); } @Override public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced) { if(stack.hasTagCompound()) { if(stack.getTagCompound().hasKey("bloodFrom")) { this.addLine("§7Blood from: §4" + stack.getTagCompound().getString("bloodFrom")); } } super.addInformation(stack, playerIn, tooltip, advanced); } @Override public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand) { if(itemStackIn.getUnlocalizedName().contains("itemSyringFilled")) { //TODO inject } return super.onItemRightClick(itemStackIn, worldIn, playerIn, hand); } }
-
Ok I find out that the falling sands spawn for a short time but then they despawn...and I find out that the getBlocksToFall Method doesnt work....
-
I know that, I never said that the Code in Bukkit is the same in Minecraft I just said that the getList Method is the same method in Minecraft as in Bukkit (code changed for Minecraft compatibility) Sorry I didn't mean to imply that you were saying that. I was pointing it out, as it may have caused confusion. Oh sorry, too. I try find the probleme tomorrow with the debugger and than I can say you the result.