Jump to content

OrangeVillager61

Members
  • Posts

    339
  • Joined

  • Last visited

Everything posted by OrangeVillager61

  1. Alright, but how do I get the container for the different slot ids since I have two different containers for it in addition to the already villager stuff?
  2. Is this what you meant? public class HireVillagerPacket implements IMessageHandler<MessageSendEntityId, IMessage> { // Do note that the default constructor is required, but implicitly defined in this case @Override public IMessage onMessage(MessageSendEntityId message, MessageContext ctx) { // This is the player the packet was sent to the server from EntityPlayerMP serverPlayer = ctx.getServerHandler().player; // The value that was sent int amount = message.EntityID; serverPlayer.mcServer.addScheduledTask(Run_Hire_Villager.run_hire_villager(ctx.getServerHandler().player.mcServer, message.EntityID, ctx.getServerHandler().player)); // No response packet return null; } } public class Run_Hire_Villager { public static Runnable run_hire_villager(MinecraftServer server, int EntityID, EntityPlayerMP player) { World world = server.getEntityWorld(); IvVillager villager = (IvVillager) world.getEntityByID(EntityID); if (player.getDistanceToEntity(villager) <= 10) { villager.hire_Villager(player); return null; } return null; } }
  3. Alright, but what do I do with it after I call the method? You said I need to use the code after I get the villager into addScheduledTask so do I make a seperate method and put my code in said method or this? @Override public IMessage onMessage(MessageSendEntityId message, MessageContext ctx) { // This is the player the packet was sent to the server from EntityPlayerMP serverPlayer = ctx.getServerHandler().player; // The value that was sent int amount = message.EntityID; IvVillager villager = (IvVillager) ctx.getServerHandler().player.world.getEntityByID(amount); serverPlayer.mcServer.addScheduledTask(villager.hire_Villager(serverPlayer); // No response packet return null; } If I do the below, I would still need to use different ids for all containers I have added to my villager or is that intended? public ItemStackHandler getItemHandler() { return this.item_handler; } Why do I check if the player is close enough if the GUI that the player uses cannot be opened unless they are close enough or is just for malicious code?
  4. So I put the code to run from the IvVillager like this? @Override public IMessage onMessage(MessageSendEntityId message, MessageContext ctx) { // This is the player the packet was sent to the server from EntityPlayerMP serverPlayer = ctx.getServerHandler().player; // The value that was sent int amount = message.EntityID; IvVillager villager = (IvVillager) ctx.getServerHandler().player.world.getEntityByID(amount); ItemStackHandler item_handler = (ItemStackHandler) villager.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); if (item_handler.getStackInSlot(15).getCount() >= villager.getHireCost() && item_handler.getStackInSlot(15).getItem().equals(Items.EMERALD) && !villager.getHired()) { int remaining_i = item_handler.getStackInSlot(15).getCount() - villager.getHireCost(); WorldServer.addScheduledTask(villager.hire_Villager(serverPlayer, remaining_i)); } // No response packet return null; } So I don't access the IItemHandler directly through the villager? Do I need to directly make a new ICapabiltyProvider or what do I need to do?
  5. Is this what is needed to accomplish what I am trying to do? @Override protected void actionPerformed(GuiButton button) { Boolean has_emeralds; if (this.inventorySlots.getSlot(0).getStack().getCount() >= villager.getHireCost() && this.inventorySlots.getSlot(0).getStack().getItem().equals(Items.EMERALD)){ has_emeralds = true; } else { has_emeralds = false; } if (has_emeralds) { Reference.PACKET_MODID.sendToServer(new EntityIdProxy(this.villager.getEntityId())); } } public class PacketHandler implements IMessageHandler<EntityIdProxy, IMessage> { // Do note that the default constructor is required, but implicitly defined in this case @Override public IMessage onMessage(EntityIdProxy message, MessageContext ctx) { // This is the player the packet was sent to the server from EntityPlayerMP serverPlayer = ctx.getServerHandler().player; // The value that was sent int amount = message.toSend; int remaining_i; IvVillager villager = (IvVillager) ctx.getServerHandler().player.world.getEntityByID(amount); ItemStackHandler item_handler = (ItemStackHandler) villager.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); if (item_handler.getStackInSlot(15).getCount() >= villager.getHireCost() && item_handler.getStackInSlot(15).getItem().equals(Items.EMERALD) && villager.getHired()) { remaining_i = item_handler.getStackInSlot(15).getCount() - villager.getHireCost(); villager.hire_Villager(serverPlayer, remaining_i); } // No response packet return null; } }
  6. How do I check if it is allowed from onMessage and access the GUI from onMessage.
  7. Alright, do I call the function that hires the villager in the onMessage or in IvVillager? Also, how to get the entity from the id?
  8. Alright, but how to send the villager instance, the number of emeralds to drop and the player in the same class or is that not possible?
  9. Is this what you meant? public class GuiIvVillagerHireNitwit extends GuiContainer{ private IvVillager villager; private IInventory playerInv; private EntityPlayer player; protected int remaining_i = 0; public GuiIvVillagerHireNitwit(IvVillager villager, IInventory playerInv, EntityPlayer player) { super(new ContainerIvVillagerHireNitwit(villager, playerInv)); this.xSize = 176; this.ySize = 166; this.player = player; this.villager = villager; this.playerInv = playerInv; } @Override public void initGui() { super.initGui(); Boolean has_emeralds; if (this.inventorySlots.getSlot(0).getStack().getCount() >= villager.getHireCost() && this.inventorySlots.getSlot(0).getStack().getItem().equals(Items.EMERALD)){ //this is where the container needs to be accessed has_emeralds = true; if (this.inventorySlots.getSlot(0).getStack().getCount() > villager.getHireCost()) { this.remaining_i = this.inventorySlots.getSlot(0).getStack().getCount() - villager.getHireCost(); } } else { has_emeralds = false; } this.addButton(new Button_Hire(0, this.getGuiLeft() + 115, this.getGuiTop() + 20, 50, 25, "Hire", this.villager, has_emeralds, this.player, this.remaining_i)); } @Override protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); this.mc.getTextureManager().bindTexture(new ResourceLocation(Reference.MOD_ID, "gui/hire_nitwit.png")); this.drawTexturedModalRect(this.getGuiLeft(), this.getGuiTop(), 0, 0, this.xSize, this.ySize); } @Override protected void actionPerformed(GuiButton button) { this.villager.hire_Villager(this.player, remaining_i); } @Override protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { String s = this.villager.getName(); this.mc.fontRenderer.drawString(String.valueOf(villager.getHireCost()), 46, 50, 4210752); this.mc.fontRenderer.drawString(s, this.xSize / 2 - this.mc.fontRenderer.getStringWidth(s) / 2, 6, 4210752); this.mc.fontRenderer.drawString(this.playerInv.getDisplayName().getFormattedText(), 8, 72, 4210752); } } public void hire_Villager(EntityPlayer player, int remaining_i) { if (!this.world.isRemote){ this.setHired(true); this.setOwnerId(player.getUniqueID()); this.entityDropItem(new ItemStack(Items.EMERALD, remaining_i), 0); } } How to send a packet to the server? I'm also particularly bad with packets and client-server connections.
  10. The items now stay! But the button that I used doesn't work when I press it nor render correctly. I get no console errors from this. GUI Code: public class GuiIvVillagerHireNitwit extends GuiContainer{ private IvVillager villager; private IInventory playerInv; private EntityPlayer player; public GuiIvVillagerHireNitwit(IvVillager villager, IInventory playerInv, EntityPlayer player) { super(new ContainerIvVillagerHireNitwit(villager, playerInv)); this.xSize = 176; this.ySize = 166; this.player = player; this.villager = villager; this.playerInv = playerInv; } @Override protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); this.mc.getTextureManager().bindTexture(new ResourceLocation(Reference.MOD_ID, "gui/hire_nitwit.png")); this.drawTexturedModalRect(this.getGuiLeft(), this.getGuiTop(), 0, 0, this.xSize, this.ySize); } @Override protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { String s = this.villager.getName(); int i = 0; Boolean has_emeralds; this.mc.fontRenderer.drawString(String.valueOf(villager.getHireCost()), 46, 50, 4210752); this.mc.fontRenderer.drawString(s, this.xSize / 2 - this.mc.fontRenderer.getStringWidth(s) / 2, 6, 4210752); this.mc.fontRenderer.drawString(this.playerInv.getDisplayName().getFormattedText(), 8, 72, 4210752); if (this.inventorySlots.getSlot(0).getStack().getCount() >= villager.getHireCost() && this.inventorySlots.getSlot(0).getStack().getItem().equals(Items.EMERALD)){ //this is where the container needs to be accessed has_emeralds = true; if (this.inventorySlots.getSlot(0).getStack().getCount() > villager.getHireCost()) { i = this.inventorySlots.getSlot(0).getStack().getCount() - villager.getHireCost(); } } else { has_emeralds = false; } this.addButton(new Button_Hire(0, this.getGuiLeft() + 115, this.getGuiTop() + 20, 50, 25, "Hire", this.villager, has_emeralds, this.player, i)); } } Button_Hire: public class Button_Hire extends GuiButton{ public IvVillager villager; public Button_Hire(int buttonId, int x, int y, int widthIn, int heightIn, String buttonText, IvVillager villager, boolean has_emeralds, EntityPlayer player, int remaining_i) { super(buttonId, x, y, widthIn, heightIn, buttonText); PointerInfo a = MouseInfo.getPointerInfo(); Point b = a.getLocation(); int mouseX = (int) b.getX(); int mouseY = (int) b.getY(); if (this.mousePressed(mouseX, mouseY)) { if (has_emeralds){ villager.hire_Villager(player, remaining_i); } } } public boolean mousePressed(int mouseX, int mouseY) { return this.enabled && this.visible && mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height; } }
  11. Ah, okay, what do I initialize it with? Edit - I used ItemStackHandler from Choonster's suggestions.
  12. I get a null pointerexception when I activate the GUI java.util.concurrent.ExecutionException: java.lang.NullPointerException at java.util.concurrent.FutureTask.report(Unknown Source) ~[?:1.8.0_121] at java.util.concurrent.FutureTask.get(Unknown Source) ~[?:1.8.0_121] at net.minecraft.util.Util.runTask(Util.java:30) [Util.class:?] at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:754) [MinecraftServer.class:?] at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:699) [MinecraftServer.class:?] at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:156) [IntegratedServer.class:?] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:548) [MinecraftServer.class:?] at java.lang.Thread.run(Unknown Source) [?:1.8.0_121] Caused by: java.lang.NullPointerException at net.minecraftforge.items.SlotItemHandler.getStack(SlotItemHandler.java:79) ~[SlotItemHandler.class:?] at net.minecraft.inventory.Container.getInventory(Container.java:71) ~[Container.class:?] at net.minecraft.inventory.Container.addListener(Container.java:57) ~[Container.class:?] at net.minecraftforge.fml.common.network.internal.FMLNetworkHandler.openGui(FMLNetworkHandler.java:102) ~[FMLNetworkHandler.class:?] at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2744) ~[EntityPlayer.class:?] at orangeVillager61.ImprovedVillagers.Entities.IvVillager.processInteract(IvVillager.java:699) ~[IvVillager.class:?] at net.minecraft.entity.EntityLiving.processInitialInteract(EntityLiving.java:1338) ~[EntityLiving.class:?] at net.minecraft.entity.player.EntityPlayer.interactOn(EntityPlayer.java:1280) ~[EntityPlayer.class:?] at net.minecraft.network.NetHandlerPlayServer.processUseEntity(NetHandlerPlayServer.java:1067) ~[NetHandlerPlayServer.class:?] at net.minecraft.network.play.client.CPacketUseEntity.processPacket(CPacketUseEntity.java:94) ~[CPacketUseEntity.class:?] at net.minecraft.network.play.client.CPacketUseEntity.processPacket(CPacketUseEntity.java:15) ~[CPacketUseEntity.class:?] at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:21) ~[PacketThreadUtil$1.class:?] at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_121] at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_121] at net.minecraft.util.Util.runTask(Util.java:29) ~[Util.class:?] ... 5 more [17:40:07] [Server thread/ERROR]: Encountered an unexpected exception net.minecraft.util.ReportedException: Ticking player at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:801) ~[MinecraftServer.class:?] at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:699) ~[MinecraftServer.class:?] at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:156) ~[IntegratedServer.class:?] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:548) [MinecraftServer.class:?] at java.lang.Thread.run(Unknown Source) [?:1.8.0_121] Caused by: java.lang.NullPointerException at net.minecraftforge.items.SlotItemHandler.getStack(SlotItemHandler.java:79) ~[SlotItemHandler.class:?] at net.minecraft.inventory.Container.detectAndSendChanges(Container.java:93) ~[Container.class:?] at net.minecraft.entity.player.EntityPlayerMP.onUpdate(EntityPlayerMP.java:319) ~[EntityPlayerMP.class:?] at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2126) ~[World.class:?] at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:883) ~[WorldServer.class:?] at net.minecraft.world.World.updateEntity(World.java:2092) ~[World.class:?] at net.minecraft.world.WorldServer.tickPlayers(WorldServer.java:680) ~[WorldServer.class:?] at net.minecraft.world.World.updateEntities(World.java:1879) ~[World.class:?] at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:651) ~[WorldServer.class:?] at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:795) ~[MinecraftServer.class:?] I have updated my github to reflect the recent changes.
  13. Ah, okay, I think you mean this then? @Override @Nullable public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing) { if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(this.item_handler); } else { return super.getCapability(capability, facing); } }
  14. @Override public boolean hasCapability(net.minecraftforge.common.capabilities.Capability<?> capability, @Nullable net.minecraft.util.EnumFacing facing) { if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { return true; } else { return super.hasCapability(capability, facing); } } @Override @Nullable public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing) { if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(this.item_handler)) { return (T) this.item_handler; } else { return super.getCapability(capability, facing); } } So then how is this wrong then?
  15. Alright, so is the below be what you suggested? @Override public boolean hasCapability(Capability<?> capability, @Nullable EnumFacing facing) { if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { return true; } else { return super.hasCapability(capability, facing); } } @Override @Nullable public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing) { if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { return this.item_handler.cast(this.item_handler); } else { return super.getCapability(capability, facing); } }
  16. Hmmm, the inventory still destroys items even in newly spawned villagers. I'll update the github if you wish to see there and I'll post the affected code below. Container: public class ContainerIvVillagerHireNitwit extends Container{ private IvVillager villager; private IItemHandler handler; public ContainerIvVillagerHireNitwit(IvVillager villager, IInventory playerInv){ this.villager = villager; this.handler = this.villager.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); this.addSlotToContainer(new SlotItemHandler(handler, 0, 76, 47)); int xPos = 8; int yPos = 84; for (int y = 0; y < 3; ++y) { for (int x = 0; x < 9; ++x) { this.addSlotToContainer(new Slot(playerInv, x + y * 9 + 9, xPos + x * 18, yPos + y * 18)); } } for (int x = 0; x < 9; ++x) { this.addSlotToContainer(new Slot(playerInv, x, xPos + x * 18, yPos + 58)); } } New Item Handler Code: private ItemStackHandler item_handler; @Override public boolean hasCapability(net.minecraftforge.common.capabilities.Capability<?> capability, @Nullable net.minecraft.util.EnumFacing facing) { if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { return true; } else { return super.hasCapability(capability, facing); } } @Override @Nullable public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing) { if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(this.item_handler)) { return (T) this.item_handler; } else { return super.getCapability(capability, facing); } }
  17. Oh, okay. Do I still cast this.item_handler to T since I get errors when I don't?
  18. Okay, I understand the rest of the text, but I don't really understand this. Is the below what you meant? @Override public boolean hasCapability(net.minecraftforge.common.capabilities.Capability<?> capability, @Nullable net.minecraft.util.EnumFacing facing) { if (capability.equals(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)) { return true; } else { return super.hasCapability(capability, facing); } } @SuppressWarnings("unchecked") @Override @Nullable public <T> T getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, @Nullable net.minecraft.util.EnumFacing facing) { if (capability.equals((Capability)CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)) { return (T) this.item_handler; } else { return super.getCapability(capability, facing); } }
  19. So something like this? Or do I need to create a capability for the items? I did have a fully functioning capability system but now since it is unused parts of it have been removed (mainly proxy references) public IItemHandler item_handler; public IItemHandler getCapability() { return this.item_handler; }
  20. Thank you so much! This fixed the bulk of my issues. However, my skill with GUI (especially with MC/Java) is limited and I have a major issue where when I put an item into the hire slot and the item disappears, I suspect that this may happen with the other GUI for the hired Villager which is supposed to act as a moving chest.
  21. Ah, I see now with createKey, I thought you meant the registry, thanks. I have updated my project to contain some of the new fixes and the build.grade file you requested.
  22. Huh, interesting, I wonder when I am registering for EntityTameable? I went through entityInit() dataParameters and there is no EntityTameable between IvVillager and EntityLiving and most of all, I renamed the variable from OWNER_UNIQUE_ID to OWNER_DEFINED_ID to prevent this specific issue. Thanks for the advice. I'll make a comit containing the current code on my mod's github, https://github.com/Orange1861/Improved-Villagers/pull/4
  23. I still get nullpointerexceptions on the return hire container (I can't use Blockpos since the game requires it to be x, y and z). @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { AxisAlignedBB vilSearch = new AxisAlignedBB(x, y - 1, z, x + 1, y + 2, z + 1); if (ID == Villager_Hire){ return new ContainerIvVillagerHireNitwit((IvVillager)world.getEntitiesWithinAABB(IvVillager.class, vilSearch).get(0), player.inventory); //Erroring code } else if (ID == Hauler){ return new ContainerIvVillagerHauler((IvVillager)world.getEntitiesWithinAABB(IvVillager.class, vilSearch).get(0), player.inventory); } else { return null; } }
  24. IvVillager gist: https://gist.github.com/Orange1861/7f412fe1d4c37921c39d0e5dc01079df.js
  25. Ah, okay, however, whenever I call the UI, it can't find anything so the list is empty. I think it is my AxisAlignedBB since I'm not sure if I specified the right area. Where the error occurs: @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { AxisAlignedBB vilSearch = new AxisAlignedBB(x, y - 1.0D, z, x, y + 2.0D, z); if (ID == Villager_Hire){ return new ContainerIvVillagerHireNitwit((IvVillager)world.getEntitiesWithinAABB(IvVillager.class, vilSearch).get(0), player.inventory); } } Where it is called: @Override public boolean processInteract(EntityPlayer player, EnumHand hand){ if (this.getHired() == false && this.getProfession() == 5 && !world.isRemote && !this.isChild()) { BlockPos blockpos = new BlockPos(this); player.openGui(Iv.instance, GuiHandler.Villager_Hire, world, blockpos.getX(), blockpos.getY(), blockpos.getZ()); return true; } } Edit: As well, when I try to register the data parameter that holds the player id, I get this: [13:45:40] [Server thread/ERROR] [FML]: Exception caught during firing event net.minecraftforge.event.entity.EntityJoinWorldEvent@44fae74c: java.lang.IllegalArgumentException: Duplicate id value for 15! at net.minecraft.network.datasync.EntityDataManager.register(EntityDataManager.java:105) ~[EntityDataManager.class:?] at orangeVillager61.ImprovedVillagers.Entities.IvVillager.entityInit(IvVillager.java:210) ~[IvVillager.class:?] Erroring code: this.getDataManager().register(OWNER_DEFINED_ID, Optional.<UUID>absent());
×
×
  • Create New...

Important Information

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