Jump to content

TheRPGAdventurer

Members
  • Posts

    642
  • Joined

  • Last visited

Everything posted by TheRPGAdventurer

  1. Something Like this but I have to place the Item
  2. So I added a dragon essence item, when the dragon dies, it drops it with the owner nbt UUID and the dragon UUID stored using that, we can throw the item on 5 X 5 square area with the required block to respawn the dragon (just like you need to detect iron blocks and a pumpkin to make iron golems), with that you could "respawn" your dragon. PS: how do I make my dragon essence item immune to fire and make it last forever
  3. If you walk underwater you get slowed down. So I overrided this code, but instead the dragon slides when walking under the ocean instead of crossing it. @Override protected float getWaterSlowDown() { return 1.0F; }
  4. should i write and read it on the nbt aswell? or straight up make a setter or getter, i registered it in entityInit private static final DataParameter<ItemStack> BANNER1 = EntityDataManager .<ItemStack>createKey(EntityTameableDragon.class, DataSerializers.ITEM_STACK); private static final DataParameter<ItemStack> BANNER2 = EntityDataManager .<ItemStack>createKey(EntityTameableDragon.class, DataSerializers.ITEM_STACK); private static final DataParameter<ItemStack> BANNER3 = EntityDataManager .<ItemStack>createKey(EntityTameableDragon.class, DataSerializers.ITEM_STACK); private static final DataParameter<ItemStack> BANNER4 = EntityDataManager .<ItemStack>createKey(EntityTameableDragon.class, DataSerializers.ITEM_STACK);
  5. Also how do I make a guitextfield maybe different? It has arrows you can increase or decrease an integer for, I am gonna use it on how high the dragon can fly Using the gui
  6. public class MessageDragonWhistle extends AbstractMessage<MessageDragonWhistle> { public UUID dragonId; public byte controlState; EntityTameableDragon dragon; public MessageDragonWhistle(UUID dragonId, byte controlState) { this.dragonId = dragonId; this.controlState = controlState; } public MessageDragonWhistle() { } @Override public void fromBytes(ByteBuf buf) { PacketBuffer packetBuf = new PacketBuffer(buf); dragonId = packetBuf.readUniqueId(); controlState = buf.readByte(); } @Override public void toBytes(ByteBuf buf) { PacketBuffer packetBuf = new PacketBuffer(buf); packetBuf.writeUniqueId(dragonId); buf.writeByte(controlState); } @Override @SideOnly(Side.CLIENT) public void onClientReceived(Minecraft client, MessageDragonWhistle message, EntityPlayer player, MessageContext messageContext) { } @Override public void onServerReceived(MinecraftServer server, MessageDragonWhistle message, EntityPlayer player, MessageContext messageContext) { World world = player.world; // if(world instanceof WorldServer) { WorldServer worldServer = (WorldServer) world; Entity entity = server.getEntityFromUuid(dragonId); if (entity != null && entity instanceof EntityTameableDragon) { EntityTameableDragon dragon = (EntityTameableDragon) entity; this.setDragon(dragon); if (dragon.isOwner(player)) { dragon.setWhistleState(message.controlState); } } // } } public EntityTameableDragon getDragon() { return dragon; } public void setDragon(EntityTameableDragon dragon) { this.dragon = dragon; } would just using a setter and getter in a dragon would work? @Override @SideOnly(Side.CLIENT) public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn) { NBTTagCompound nbt = stack.getTagCompound(); if(stack != null && stack.hasTagCompound() && nbt.hasKey(DragonMounts.MODID.toLowerCase() + "dragon")) { MessageDragonWhistle whistle = new MessageDragonWhistle(); EntityTameableDragon dragon = whistle.getDragon(); if(dragon != null) { String dragonName = dragon.hasCustomName() ? dragon.getCustomNameTag() : dragon.getBreedType().toString().toLowerCase() + " dragon"; String ownerName = dragon.getOwner() != null ? dragon.getOwner().getName() : "null"; tooltip.add("Dragon:" + dragonName + " " + " Owner:" + " " + ownerName); } } } I tried but it didnt.
  7. Now in the addInformation, since its client and you cannot call getUUID method, how to do I get my dragon and its display name also its owner?
  8. so how should I set it with a button, with an interface for the dragon, or set a new state there that is used to Identify it in the server?
  9. oh so this is the wrong ive done, no wonder my head keeps persisting to get the dragon there. In the gui
  10. @Override protected void actionPerformed(GuiButton button) { if(dragon != null) { byte previousState = dragon.getWhistleState(); dragon.come(button == come); dragon.circle(button == circle); dragon.follow(button == followFlying); dragon.nothing(button == nothing); this.mc.player.world.playSound(this.mc.player, this.mc.player.getPosition(), ModSounds.DRAGON_WHISTLE, SoundCategory.PLAYERS, 5, 1); byte controlState = dragon.getWhistleState(); if (controlState != previousState) { DragonMounts.NETWORK_WRAPPER .sendToServer(new MessageDragonWhistle(uuid, controlState)); } // } } } so that would mean the come and other commands shouldnt be called on using the dragon but on the packet itself?, the commands are in statefields i forgot to mention that. public boolean nothing() { return (dataManager.get(WHISTLE_STATE).byteValue() & 1) == 1; } public boolean follow() { return (dataManager.get(WHISTLE_STATE).byteValue() >> 1 & 1) == 1; } public boolean circle() { return (dataManager.get(WHISTLE_STATE).byteValue() >> 2 & 1) == 1; } public boolean come() { return (dataManager.get(WHISTLE_STATE).byteValue() >> 3 & 1) == 1; } @Override public void nothing(boolean nothing) { setStateField(0, nothing); } @Override public void follow(boolean follow) { setStateField(1, follow); } @Override public void circle(boolean circle) { setStateField(2, circle); } @Override public void come(boolean come) { setStateField(3, come); } /** * @TheRPGAdventurer thanks AlexThe666 * @param * @param */ private void setStateField(int i, boolean newState) { byte prevState = dataManager.get(WHISTLE_STATE).byteValue(); if (newState) { dataManager.set(WHISTLE_STATE, (byte) (prevState | (1 << i))); } else { dataManager.set(WHISTLE_STATE, (byte) (prevState & ~(1 << i))); } }
  11. Exactly why it makes zero sense, thats why im confused right now :D, I really should use getEntityID there because its clientside, but I only stored the uuid on the Item nbt(should I store the ID integer too as well?), or do I have to convert the UUId to id? and how ? Message Packets?
  12. Oh sorry about that package com.TheRPGAdventurer.ROTD.client.gui; import java.util.UUID; import javax.annotation.Nullable; import org.lwjgl.input.Keyboard; import com.TheRPGAdventurer.ROTD.DragonMounts; import com.TheRPGAdventurer.ROTD.client.sound.ModSounds; import com.TheRPGAdventurer.ROTD.server.entity.EntityTameableDragon; import com.TheRPGAdventurer.ROTD.server.network.MessageDragonWhistle; import com.TheRPGAdventurer.ROTD.util.DMUtils; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.resources.I18n; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.item.ItemStack; import net.minecraft.server.MinecraftServer; import net.minecraft.util.SoundCategory; import net.minecraft.world.World; import net.minecraft.world.WorldServer; public class GuiDragonWhistle extends GuiScreen { Entity entity; private final MessageDragonWhistle dcw = new MessageDragonWhistle(); private float mousePosX; private float mousePosY; World world; ItemStack whistle; UUID uuid; GuiButton nothing; GuiButton circle; GuiButton followFlying; GuiButton come; GuiButton sit; EntityTameableDragon owner; public GuiDragonWhistle(World world, UUID uuid, ItemStack whistle) { super(); this.whistle = whistle; this.uuid = uuid; this.world = world; } @Override public void initGui() { buttonList.clear(); Keyboard.enableRepeatEvents(true); nothing = new GuiButton(0, width / 2 - 50, height / 2 + 10, 98, 20, I18n.format("gui.nothing", new Object[0])); circle = new GuiButton(0, width / 2 + 100 - 50, height / 2 + 10, 98, 20, I18n.format("gui.circle", new Object[0])); followFlying = new GuiButton(0, width / 2 - 100 - 50, height / 2 + 10, 98, 20, I18n.format("gui.followFlying", new Object[0])); come = new GuiButton(0, width / 2 - 50, height / 2 - 15, 98, 20, I18n.format("gui.goToPlayer", new Object[0])); buttonList.add(nothing); buttonList.add(circle); buttonList.add(followFlying); buttonList.add(come); } @Nullable public EntityTameableDragon getDragon() { //tried using this if (this.owner == null && this.uuid != null && this.world instanceof WorldServer) { Entity entity = ((WorldServer)this.world).getEntityFromUuid(this.uuid); if (entity instanceof EntityLivingBase) { this.owner = (EntityTameableDragon)entity; } } return this.owner; } @Override protected void actionPerformed(GuiButton button) { EntityTameableDragon dragon = (EntityTameableDragon)((WorldServer) world).getEntityFromUuid(uuid); // causes nullpointer if(dragon != null) { byte previousState = dragon.getWhistleState(); dragon.come(button == come); dragon.circle(button == circle); dragon.follow(button == followFlying); dragon.nothing(button == nothing); dragon.world.playSound(this.mc.player, this.mc.player.getPosition(), ModSounds.DRAGON_WHISTLE, SoundCategory.PLAYERS, 5, 1); byte controlState = dragon.getWhistleState(); if (controlState != previousState) { DragonMounts.NETWORK_WRAPPER .sendToServer(new MessageDragonWhistle(dragon.getUniqueID(), controlState)); } // } } } @Override public void drawScreen(int mouseX, int mouseY, float partialTicks) { this.mousePosX = mouseX; this.mousePosY = mouseY; super.drawScreen(mouseX, mouseY, partialTicks); } @Override public boolean doesGuiPauseGame() { return false; } }
  13. I know now, what Im confused is the client and server stuff, sorry for making too many threads btw. SO gui is client right? and getting the entity uuid is server, so how am I supposed to get the dragon with the uuid? if i do however a nullpointer happens
  14. Ok so i tried using getEntityId for this but it keeps dissappearing and dieseben071 guy said to use UUID, the id is stored in an nbt for a dragon whistle item which when right clicked will open that gui, and the gui will set some command data by pressing the buttons fly,come,circle etc. but since guis are client, it causes a nullPointer by worldServer.getEntityByUUid. Is there any way around this? package com.TheRPGAdventurer.ROTD.client.gui; import java.util.UUID; import javax.annotation.Nullable; import org.lwjgl.input.Keyboard; import com.TheRPGAdventurer.ROTD.DragonMounts; import com.TheRPGAdventurer.ROTD.client.sound.ModSounds; import com.TheRPGAdventurer.ROTD.server.entity.EntityTameableDragon; import com.TheRPGAdventurer.ROTD.server.network.MessageDragonWhistle; import com.TheRPGAdventurer.ROTD.util.DMUtils; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.resources.I18n; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.item.ItemStack; import net.minecraft.server.MinecraftServer; import net.minecraft.util.SoundCategory; import net.minecraft.world.World; import net.minecraft.world.WorldServer; public class GuiDragonWhistle extends GuiScreen { Entity entity; private final MessageDragonWhistle dcw = new MessageDragonWhistle(); private float mousePosX; private float mousePosY; World world; ItemStack whistle; UUID uuid; GuiButton nothing; GuiButton circle; GuiButton followFlying; GuiButton come; GuiButton sit; EntityTameableDragon owner; public GuiDragonWhistle(World world, UUID uuid, ItemStack whistle) { super(); this.whistle = whistle; this.uuid = uuid; this.world = world; } @Override public void initGui() { buttonList.clear(); Keyboard.enableRepeatEvents(true); nothing = new GuiButton(0, width / 2 - 50, height / 2 + 10, 98, 20, I18n.format("gui.nothing", new Object[0])); circle = new GuiButton(0, width / 2 + 100 - 50, height / 2 + 10, 98, 20, I18n.format("gui.circle", new Object[0])); followFlying = new GuiButton(0, width / 2 - 100 - 50, height / 2 + 10, 98, 20, I18n.format("gui.followFlying", new Object[0])); come = new GuiButton(0, width / 2 - 50, height / 2 - 15, 98, 20, I18n.format("gui.goToPlayer", new Object[0])); buttonList.add(nothing); buttonList.add(circle); buttonList.add(followFlying); buttonList.add(come); } @Nullable public EntityTameableDragon getDragon() { //tried using this if (this.owner == null && this.uuid != null && this.world instanceof WorldServer) { Entity entity = ((WorldServer)this.world).getEntityFromUuid(this.uuid); if (entity instanceof EntityLivingBase) { this.owner = (EntityTameableDragon)entity; } } return this.owner; } @Override protected void actionPerformed(GuiButton button) { EntityTameableDragon dragon = (EntityTameableDragon)((WorldServer) world).getEntityFromUuid(uuid); // causes nullpointer DMUtils.getLogger().info("Current State at " + dragon.getUniqueID().toString() + "" + dragon.getPosition() +""+uuid); if(dragon != null) { byte previousState = dragon.getWhistleState(); dragon.come(button == come); dragon.circle(button == circle); dragon.follow(button == followFlying); dragon.nothing(button == nothing); dragon.world.playSound(this.mc.player, this.mc.player.getPosition(), ModSounds.DRAGON_WHISTLE, SoundCategory.PLAYERS, 5, 1); byte controlState = dragon.getWhistleState(); if (controlState != previousState) { DragonMounts.NETWORK_WRAPPER .sendToServer(new MessageDragonWhistle(dragon.getUniqueID(), controlState)); } // } } } @Override public void drawScreen(int mouseX, int mouseY, float partialTicks) { this.mousePosX = mouseX; this.mousePosY = mouseY; super.drawScreen(mouseX, mouseY, partialTicks); } @Override public boolean doesGuiPauseGame() { return false; } }
  15. when I use UUID it sends a different UUID I printed it out with a logger [14:59:35] [main/INFO] [dragonmounts]: Current State at 527561dd-f8a1-4e39-8ee1-a26897e4ce36 [14:59:38] [main/INFO] [dragonmounts]: Current State at 7020e729-f0b5-4b60-ae91-def0d5b83d26
  16. Like this @Override public void fromBytes(ByteBuf buf) { if(buf instanceof PacketBuffer) { PacketBuffer packetBuf = (PacketBuffer) buf; dragonId = packetBuf.readUniqueId(); } controlState = buf.readByte(); } @Override public void toBytes(ByteBuf buf) { if(buf instanceof PacketBuffer) { PacketBuffer packetBuf = (PacketBuffer) buf; packetBuf.writeUniqueId(dragonId); } buf.writeByte(controlState); }
  17. Like this? but it crashes, with a classexception @Override public void fromBytes(ByteBuf buf) { PacketBuffer packetBuf = (PacketBuffer) buf; dragonId = packetBuf.readUniqueId(); controlState = buf.readByte(); } @Override public void toBytes(ByteBuf buf) { PacketBuffer packetBuf = (PacketBuffer) buf; packetBuf.writeUniqueId(dragonId); buf.writeByte(controlState); }
  18. package com.TheRPGAdventurer.ROTD.client.items; import java.util.List; import java.util.UUID; import javax.annotation.Nullable; import com.TheRPGAdventurer.ROTD.DragonMounts; import com.TheRPGAdventurer.ROTD.client.userinput.StatCollector; import com.TheRPGAdventurer.ROTD.server.entity.EntityTameableDragon; import com.TheRPGAdventurer.ROTD.util.DMUtils; import net.minecraft.client.util.ITooltipFlag; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.ItemWritableBook; import net.minecraft.item.ItemWrittenBook; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTUtil; import net.minecraft.util.ActionResult; import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumHand; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StringUtils; import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.world.World; import net.minecraft.world.WorldServer; import net.minecraftforge.common.config.ConfigElement; import net.minecraftforge.common.util.Constants; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import scala.reflect.internal.Trees.Modifiers; public class ItemDragonWhistle extends Item { // private final MessageDragonWhistle dcw = new MessageDragonWhistle(); // private List<EntityTameableDragon> dragons = new ArrayList(); // EntityTameableDragon dragon; private byte oldIndex; public ItemDragonWhistle() { this.setUnlocalizedName("dragon_whistle"); this.setRegistryName(new ResourceLocation(DragonMounts.MODID, "dragon_whistle")); this.setMaxStackSize(1); this.setCreativeTab(DragonMounts.TAB); } @Override @SideOnly(Side.CLIENT) public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn) { NBTTagCompound nbt = stack.getTagCompound(); if(stack != null && stack.hasTagCompound() && nbt.hasKey(DragonMounts.MODID.toLowerCase() + "dragon")) { if(worldIn instanceof WorldServer) { WorldServer worldServer = (WorldServer) worldIn; EntityTameableDragon dragon = (EntityTameableDragon) worldServer.getEntityFromUuid(nbt.getUniqueId(DragonMounts.MODID.toLowerCase() + "dragon")); if(dragon != null) { String dragonName = dragon.hasCustomName() ? dragon.getCustomNameTag() : dragon.getBreedType().toString().toLowerCase() + " dragon"; String ownerName = dragon.getOwner() != null ? dragon.getOwner().getName() : "null"; tooltip.add("Dragon:" + dragonName + " " + " Owner:" + " " + ownerName); } } } } @Override public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer player, EnumHand hand) { ItemStack stack = player.getHeldItem(hand); NBTTagCompound nbt = stack.getTagCompound(); if (stack.hasTagCompound()) { nbt = stack.getTagCompound(); } else { nbt = new NBTTagCompound(); } stack.setTagCompound(nbt); if (!player.isSneaking() && stack.hasTagCompound()) { if (worldIn.isRemote) { DragonMounts.proxy.openDragonWhistleGui(nbt.getUniqueId(DragonMounts.MODID.toLowerCase() + "dragon"), new ItemStack(this), worldIn); return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack); } } return new ActionResult<ItemStack>(EnumActionResult.FAIL, stack); } @Override public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { super.onUpdate(stack, worldIn, entityIn, itemSlot, isSelected); } @Override public boolean onLeftClickEntity(ItemStack stack, EntityPlayer player, Entity target) { NBTTagCompound nbt = stack.getTagCompound(); if (stack.hasTagCompound()) { nbt = stack.getTagCompound(); } else { nbt = new NBTTagCompound(); } stack.setTagCompound(nbt); if (target instanceof EntityTameableDragon) { EntityTameableDragon dragon = (EntityTameableDragon) target; if (dragon.isTamedFor(player)) { // I blame this, if my guess is right, this means that it only sets the dragon ID integer and removed if the player is untamed if(stack.getTagCompound() != null) { if (nbt.hasKey(DragonMounts.MODID.toLowerCase() + "dragon")) { // nbt.setInteger("dragon", null); } else { String dragonName = dragon.hasCustomName() ? dragon.getCustomNameTag() : dragon.getBreedType().toString().toLowerCase() + " dragon"; String ownerName = dragon.getOwner() != null ? dragon.getOwner().getName() : "NULL"; nbt.setUniqueId(DragonMounts.MODID.toLowerCase() + "dragon", dragon.getUniqueID()); player.sendStatusMessage(new TextComponentTranslation("item.whistle.hasDragon" + ":" + dragonName + " for " + ownerName, new Object[0]), true); } } // else { // return false; // } // EntityTameableDragon storedDragon = (EntityTameableDragon) player.world.getEntityByID(nbt.getInteger("dragon")); // if(storedDragon.isDead && storedDragon != null && nbt.hasKey("dragon")) { // nbt.removeTag("dragon"); // } } else { player.sendStatusMessage(new TextComponentTranslation("item.whistle.notOwned", new Object[0]), true); } return true; } else { return false; } } @Override public boolean hasEffect(ItemStack stack) { NBTTagCompound nbt = stack.getTagCompound(); if (stack.hasTagCompound()) { nbt = stack.getTagCompound(); } else { nbt = new NBTTagCompound(); } stack.setTagCompound(nbt); if(nbt.hasKey("dragon")) { return true; } else { return super.hasEffect(stack); } } }
  19. oh but it didnt work for some reason, do I need to use packets, thyey are accessed by the gui and pressing the command the dragon it worked with entityIds but not UUIDs
  20. reason i change it to ID because i got confused @Override @SideOnly(Side.CLIENT) public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn) { NBTTagCompound nbt = stack.getTagCompound(); if(stack != null && stack.hasTagCompound() && nbt.hasKey(DragonMounts.MODID.toLowerCase() + "dragon")) { EntityTameableDragon dragon = (EntityTameableDragon) worldIn.getEntityByID(nbt.getInteger(DragonMounts.MODID.toLowerCase() + "dragon")); if(dragon != null) { String dragonName = dragon.hasCustomName() ? dragon.getCustomNameTag() : dragon.getBreedType().toString().toLowerCase() + " dragon"; String ownerName = dragon.getOwner() != null ? dragon.getOwner().getName() : "null"; tooltip.add("Dragon:" + dragonName + " " + " Owner:" + " " + ownerName); } } } gettingUUID from an entity is a worldserver right? would it work here which is a client?
  21. So I tried storing a 3 entities in a dragon whistle using NBTTagList and NBTTAgCompound it was hard and I tried starting on one dragon first with NBTTagCompound. SO I have a problem, so if I tamed a dragon and left click the dragon with the whistle, its entityID will be stored as an NBT Integer. Problem is when printing it, on addInformation it dissapears whenever I quit as if the NBT got deleted the eclipse not just in addInformation game and restart with a different playerName and ID. What I want is if the player is not the owner, it will not open the dragon whistle gui thus not controlling it, and the player name and the dragon name will be printed so the player would understand why. package com.TheRPGAdventurer.ROTD.client.items; import java.util.List; import java.util.UUID; import javax.annotation.Nullable; import com.TheRPGAdventurer.ROTD.DragonMounts; import com.TheRPGAdventurer.ROTD.client.userinput.StatCollector; import com.TheRPGAdventurer.ROTD.server.entity.EntityTameableDragon; import com.TheRPGAdventurer.ROTD.util.DMUtils; import net.minecraft.client.util.ITooltipFlag; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.ItemWritableBook; import net.minecraft.item.ItemWrittenBook; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTUtil; import net.minecraft.util.ActionResult; import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumHand; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StringUtils; import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.world.World; import net.minecraft.world.WorldServer; import net.minecraftforge.common.config.ConfigElement; import net.minecraftforge.common.util.Constants; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import scala.reflect.internal.Trees.Modifiers; public class ItemDragonWhistle extends Item { // private final MessageDragonWhistle dcw = new MessageDragonWhistle(); // private List<EntityTameableDragon> dragons = new ArrayList(); // EntityTameableDragon dragon; private byte oldIndex; public ItemDragonWhistle() { this.setUnlocalizedName("dragon_whistle"); this.setRegistryName(new ResourceLocation(DragonMounts.MODID, "dragon_whistle")); this.setMaxStackSize(1); this.setCreativeTab(DragonMounts.TAB); } @Override @SideOnly(Side.CLIENT) public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn) { NBTTagCompound nbt = stack.getTagCompound(); if(stack != null && stack.hasTagCompound() && nbt.hasKey(DragonMounts.MODID.toLowerCase() + "dragon")) { EntityTameableDragon dragon = (EntityTameableDragon) worldIn.getEntityByID(nbt.getInteger(DragonMounts.MODID.toLowerCase() + "dragon")); if(dragon != null) { String dragonName = dragon.hasCustomName() ? dragon.getCustomNameTag() : dragon.getBreedType().toString().toLowerCase() + " dragon"; String ownerName = dragon.getOwner() != null ? dragon.getOwner().getName() : "null"; tooltip.add("Name:" + dragonName + " " + " Owner:" + " " + ownerName); } } } @Override public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer player, EnumHand hand) { ItemStack stack = player.getHeldItem(hand); NBTTagCompound nbt = stack.getTagCompound(); if (!player.isSneaking() && stack.hasTagCompound()) { if (worldIn.isRemote) { DragonMounts.proxy.openDragonWhistleGui(nbt.getInteger(DragonMounts.MODID.toLowerCase() + "dragon"), new ItemStack(this), worldIn); return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack); } } return new ActionResult<ItemStack>(EnumActionResult.FAIL, stack); } @Override public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { super.onUpdate(stack, worldIn, entityIn, itemSlot, isSelected); } @Override public boolean onLeftClickEntity(ItemStack stack, EntityPlayer player, Entity target) { NBTTagCompound nbt = stack.getTagCompound(); if (stack.hasTagCompound()) { nbt = stack.getTagCompound(); } else { nbt = new NBTTagCompound(); } stack.setTagCompound(nbt); if (target instanceof EntityTameableDragon) { EntityTameableDragon dragon = (EntityTameableDragon) target; if (dragon.isTamedFor(player)) { // I blame this, if my guess is right, this means that it only sets the dragon ID integer and removed if the player is untamed if(stack.getTagCompound() != null) { if (nbt.hasKey(DragonMounts.MODID.toLowerCase() + "dragon")) { // nbt.setInteger("dragon", null); } else { String dragonName = dragon.hasCustomName() ? dragon.getCustomNameTag() : dragon.getBreedType().toString().toLowerCase() + " dragon"; String ownerName = dragon.getOwner() != null ? dragon.getOwner().getName() : "NULL"; nbt.setInteger(DragonMounts.MODID.toLowerCase() + "dragon", dragon.getEntityId()); player.sendStatusMessage(new TextComponentTranslation("item.whistle.hasDragon" + ":" + dragonName + " for " + ownerName, new Object[0]), true); } } // else { // return false; // } // EntityTameableDragon storedDragon = (EntityTameableDragon) player.world.getEntityByID(nbt.getInteger("dragon")); // if(storedDragon.isDead && storedDragon != null && nbt.hasKey("dragon")) { // nbt.removeTag("dragon"); // } } else { player.sendStatusMessage(new TextComponentTranslation("item.whistle.notOwned", new Object[0]), true); } return true; } else { return false; } } }
  22. Ok I learned a ne thing, I used dragonEntityID instead of the UUID
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.