Jump to content

OrangeVillager61

Members
  • Posts

    339
  • Joined

  • Last visited

Everything posted by OrangeVillager61

  1. Where the generation is actually initialized: @EventHandler public void preInit(FMLPreInitializationEvent e) { if (Config.enableVillages){ MinecraftForge.TERRAIN_GEN_BUS.register(new ChangeVillageGeneration()); } }
  2. GuiHandler public class GuiHandler implements IGuiHandler{ public static final int Hire = 0; public static final int Hauler = 1; public static final int Info = 2; public static final int Inventory = 3; @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { // x is used as the entity ID for entity-based GUIs, suggested by Choonster if (ID == Hire){ return new ContainerIvVillagerHireNitwit((IvVillager) world.getEntityByID(x), player.inventory); } else if (ID == Hauler){ return new ContainerIvVillagerHauler((IvVillager) world.getEntityByID(x), player.inventory); } else if (ID == Info) { return new ContainerIvVillagerInfo((IvVillager) world.getEntityByID(x), player.inventory); } else if (ID == Inventory) { return new ContainerIvVillagerInventory((IvVillager) world.getEntityByID(x), player.inventory); } else { return null; } } @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { // x is used as the entity ID for entity-based GUIs, suggested by Choonster if (ID == Hire) { return new GuiIvVillagerHireNitwit((IvVillager) world.getEntityByID(x), player.inventory, player); } else if (ID == Hauler){ return new GuiIvVillagerHauler((IvVillager) world.getEntityByID(x), player.inventory); } else if (ID == Info){ return new GuiIvVillagerInfo((IvVillager) world.getEntityByID(x), player.inventory); } else if (ID == Inventory){ return new GuiIvVillagerInventory((IvVillager) world.getEntityByID(x), player.inventory); } else { return null; } } Where it is opened (most of the unrelated code here has been cut out). @Override public boolean processInteract(EntityPlayer player, EnumHand hand){ else if (this.getTab().equals("Inventory")) { if (!world.isRemote) { player.openGui(Iv.instance, GuiHandler.Inventory, world, getEntityId(), 0, 0); } return true; } }
  3. Okay, but when I do just a complete replacement I get this error. While I know it is a arraysize error I don't know where it is coming from: java.util.concurrent.ExecutionException: java.lang.IndexOutOfBoundsException: Index: 51, Size: 51 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.client.Minecraft.runGameLoop(Minecraft.java:1117) [Minecraft.class:?] at net.minecraft.client.Minecraft.run(Minecraft.java:407) [Minecraft.class:?] at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_121] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_121] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_121] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_121] at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?] at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_121] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_121] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_121] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_121] at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?] at GradleStart.main(GradleStart.java:26) [start/:?] Caused by: java.lang.IndexOutOfBoundsException: Index: 51, Size: 51 at java.util.ArrayList.rangeCheck(Unknown Source) ~[?:1.8.0_121] at java.util.ArrayList.get(Unknown Source) ~[?:1.8.0_121] at net.minecraft.inventory.Container.getSlot(Container.java:135) ~[Container.class:?] at net.minecraft.inventory.Container.setAll(Container.java:559) ~[Container.class:?] at net.minecraft.client.network.NetHandlerPlayClient.handleWindowItems(NetHandlerPlayClient.java:1306) ~[NetHandlerPlayClient.class:?] at net.minecraft.network.play.server.SPacketWindowItems.processPacket(SPacketWindowItems.java:72) ~[SPacketWindowItems.class:?] at net.minecraft.network.play.server.SPacketWindowItems.processPacket(SPacketWindowItems.java:13) ~[SPacketWindowItems.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] The container: public class ContainerIvVillagerInventory extends Container{ private IvVillager villager; private IInventory handler; public ContainerIvVillagerInventory(IvVillager villager, IInventory playerInv){ this.villager = villager; this.handler = this.villager.getVillagerInventory(); this.addSlotToContainer(new Slot(handler, 0, 40, 66)); this.addSlotToContainer(new Slot(handler, 1, 58, 66)); this.addSlotToContainer(new Slot(handler, 2, 76, 66)); this.addSlotToContainer(new Slot(handler, 3, 94, 66)); this.addSlotToContainer(new Slot(handler, 4, 112, 66)); this.addSlotToContainer(new Slot(handler, 5, 40, 84)); this.addSlotToContainer(new Slot(handler, 6, 58, 84)); this.addSlotToContainer(new Slot(handler, 7, 76, 84)); this.addSlotToContainer(new Slot(handler, 8, 94, 84)); this.addSlotToContainer(new Slot(handler, 9, 112, 84)); this.addSlotToContainer(new Slot(handler, 10, 40, 102)); this.addSlotToContainer(new Slot(handler, 11, 58, 102)); this.addSlotToContainer(new Slot(handler, 12, 76, 102)); this.addSlotToContainer(new Slot(handler, 13, 94, 102)); this.addSlotToContainer(new Slot(handler, 14, 112, 102)); this.addSlotToContainer(new Slot(handler, 15, 40, 120)); this.addSlotToContainer(new Slot(handler, 16, 58, 120)); this.addSlotToContainer(new Slot(handler, 17, 76, 120)); this.addSlotToContainer(new Slot(handler, 18, 94, 120)); this.addSlotToContainer(new Slot(handler, 19, 112, 120)); int xPos = 8; int yPos = 153; 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)); } } @Override public boolean canInteractWith(EntityPlayer player) { return false; } }
  4. I am trying to use an InventoryBasic as an ItemStackHandler. I am trying to create a GUI for a player to view a villager's inventory. I am using the below method for a container for the inventory. As you can see, it needs to be a hander but the inventory is an InventoryBasic. Is there some way to convert it into an ItemStackHandler? The reason why it is an InventoryBasic is that I'm using modified vanilla code for my mob. public class ContainerIvVillagerInventory extends Container{ private IvVillager villager; private IItemHandler handler; public ContainerIvVillagerInventory(IvVillager villager, IInventory playerInv){ this.villager = villager; this.handler = this.villager.getVillagerInventory(); //Need the inventory here this.addSlotToContainer(new SlotItemHandler(handler, 0, 40, 66)); this.addSlotToContainer(new SlotItemHandler(handler, 1, 58, 66)); this.addSlotToContainer(new SlotItemHandler(handler, 2, 76, 66)); this.addSlotToContainer(new SlotItemHandler(handler, 3, 94, 66)); this.addSlotToContainer(new SlotItemHandler(handler, 4, 112, 66)); this.addSlotToContainer(new SlotItemHandler(handler, 5, 40, 84)); this.addSlotToContainer(new SlotItemHandler(handler, 6, 58, 84)); this.addSlotToContainer(new SlotItemHandler(handler, 7, 76, 84)); this.addSlotToContainer(new SlotItemHandler(handler, 8, 94, 84)); this.addSlotToContainer(new SlotItemHandler(handler, 9, 112, 84)); this.addSlotToContainer(new SlotItemHandler(handler, 10, 40, 102)); this.addSlotToContainer(new SlotItemHandler(handler, 11, 58, 102)); this.addSlotToContainer(new SlotItemHandler(handler, 12, 76, 102)); this.addSlotToContainer(new SlotItemHandler(handler, 13, 94, 102)); this.addSlotToContainer(new SlotItemHandler(handler, 14, 112, 102)); this.addSlotToContainer(new SlotItemHandler(handler, 15, 40, 120)); this.addSlotToContainer(new SlotItemHandler(handler, 16, 58, 120)); this.addSlotToContainer(new SlotItemHandler(handler, 17, 76, 120)); this.addSlotToContainer(new SlotItemHandler(handler, 18, 94, 120)); this.addSlotToContainer(new SlotItemHandler(handler, 19, 112, 120)); int xPos = 8; int yPos = 153; 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)); } } @Override public boolean canInteractWith(EntityPlayer player) { return false; } }
  5. The Village Gen file: public class IvMapGenVillage extends MapGenVillage { private final static List<Biome> VILLAGE_SPAWN_BIOMES = Arrays.<Biome>asList(new Biome[] {Biomes.SAVANNA_PLATEAU, Biomes.PLAINS, Biomes.DESERT, Biomes.SAVANNA, Biomes.FOREST, Biomes.FOREST_HILLS, Biomes.TAIGA, Biomes.TAIGA_HILLS, Biomes.REDWOOD_TAIGA, Biomes.REDWOOD_TAIGA_HILLS, Biomes.MESA, Biomes.MESA_ROCK, Biomes.MESA_CLEAR_ROCK}); /** None */ private int size; private int distance; protected boolean isMetropolis; public Random r = new Random(); private final int minTownSeparation; public IvMapGenVillage() { this.distance = Config.VillageDistance; this.minTownSeparation = 4; this.isMetropolis = true; if (r.nextInt(20) + 1 == 2 && Config.enable_Metro){ this.isMetropolis = true; } } public IvMapGenVillage(Map<String, String> map) { this(); for (Entry<String, String> entry : map.entrySet()) { if (((String)entry.getKey()).equals("size")) { this.size = MathHelper.getInt((String)entry.getValue(), this.size, 0); } else if (((String)entry.getKey()).equals("distance")) { this.distance = MathHelper.getInt((String)entry.getValue(), this.distance, 9); } } } public String getStructureName() { return "Village"; } protected boolean canSpawnStructureAtCoords(int chunkX, int chunkZ) { int i = chunkX; int j = chunkZ; if (chunkX < 0) { chunkX -= this.distance - 1; } if (chunkZ < 0) { chunkZ -= this.distance - 1; } int k = chunkX / this.distance; int l = chunkZ / this.distance; Random random = this.world.setRandomSeed(k, l, 10387312); k = k * this.distance; l = l * this.distance; k = k + random.nextInt(this.distance/2); l = l + random.nextInt(this.distance/2); if (i == k && j == l) { boolean flag = this.world.getBiomeProvider().areBiomesViable(i * 16 + 8, j * 16 + 8, 0, VILLAGE_SPAWN_BIOMES); if (flag) { return true; } } return false; } public BlockPos getClosestStrongholdPos(World worldIn, BlockPos pos, boolean p_180706_3_) { this.world = worldIn; return findNearestStructurePosBySpacing(worldIn, this, pos, this.distance, 8, 10387312, false, 100, p_180706_3_); } protected StructureStart getStructureStart(int chunkX, int chunkZ) { if (this.isMetropolis) { this.size = r.nextInt(1) + 4; } return new IvMapGenVillage.Start(this.world, this.rand, chunkX, chunkZ, this.size, this.isMetropolis); } public static class Start extends StructureStart { /** well ... thats what it does */ private boolean hasMoreThanTwoComponents; public Start() { } public Start(World worldIn, Random rand, int x, int z, int size, boolean isMetro) { super(x, z); MapGenStructureIO.registerStructure(Start.class, "Village"); List<VillageStructures.PieceWeight> list = VillageStructures.getStructureVillageWeightedPieceList(rand, size); VillageStructures.Start structurevillagepieces$start = new VillageStructures.Start(worldIn.getBiomeProvider(), 0, rand, (x << 4) + 2, (z << 4) + 2, list, size, isMetro); this.components.add(structurevillagepieces$start); structurevillagepieces$start.buildComponent(structurevillagepieces$start, this.components, rand); List<StructureComponent> list1 = structurevillagepieces$start.pendingRoads; List<StructureComponent> list2 = structurevillagepieces$start.pendingHouses; while (!list1.isEmpty() || !list2.isEmpty()) { if (list1.isEmpty()) { int i = rand.nextInt(list2.size()); StructureComponent structurecomponent = (StructureComponent)list2.remove(i); structurecomponent.buildComponent(structurevillagepieces$start, this.components, rand); } else { int j = rand.nextInt(list1.size()); StructureComponent structurecomponent2 = (StructureComponent)list1.remove(j); structurecomponent2.buildComponent(structurevillagepieces$start, this.components, rand); } } this.updateBoundingBox(); int k = 0; for (StructureComponent structurecomponent1 : this.components) { if (!(structurecomponent1 instanceof VillageStructures.Road)) { ++k; } } this.hasMoreThanTwoComponents = k > 2; } /** * currently only defined for Villages, returns true if Village has more than 2 non-road components */ public boolean isSizeableStructure() { return this.hasMoreThanTwoComponents; } public void writeToNBT(NBTTagCompound tagCompound) { super.writeToNBT(tagCompound); tagCompound.setBoolean("Valid", this.hasMoreThanTwoComponents); } public void readFromNBT(NBTTagCompound tagCompound) { super.readFromNBT(tagCompound); this.hasMoreThanTwoComponents = tagCompound.getBoolean("Valid"); } } }
  6. My mod overrides vanilla villages in order to add many changes to them and for them to go in different biomes. With some assistance from the forum helpers I was able to override the vanilla villages by having a new village file with a new village structures and then overrding the original villages with setting a new gen on InitMapGenEvent. However, this prevents villages and village buildings from other mods from spawning which is a serious issue. How do I override village structures and VILLAGE_SPAWN_BIOMES without overriding village stuff from other mods. (BTW, I'm very very bad with reflecting) The actual act of changing the village gen: public class ChangeVillageGeneration { @SubscribeEvent public void changeVillageGen (InitMapGenEvent event) { if (event.getType() != null && event.getType() == EventType.VILLAGE){ IvMapGenVillage newGen = new IvMapGenVillage(); event.setNewGen(newGen); } } } Current Reflector: ublic class Reflector { public static Object reflectMethod1(List<VillageStructures.PieceWeight> list, Random random, int size){ Class reflectClass = net.minecraftforge.fml.common.registry.VillagerRegistry.class; Method method; try { method = reflectClass.getMethod("addExtraVillageComponents", VillageStructures.PieceWeight.class, Random.class, int.class); Object returnValue = method.invoke(null, list, random, size); return returnValue; } catch (NoSuchMethodException e) { // TODO Auto-generated catch block //e.printStackTrace(); } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } public static Village reflectMethod2(VillageStructures.Start start, VillageStructures.PieceWeight weight, List<StructureComponent> structureComponents, Random rand, int structureMinX, int structureMinY, int structureMinZ, EnumFacing facing, int componentType){ Class reflectClass = net.minecraftforge.fml.common.registry.VillagerRegistry.class; Method method; try { method = reflectClass.getMethod("getVillageComponent", List.class, VillageStructures.Start.class, VillageStructures.PieceWeight.class, StructureComponent.class, Random.class, int.class, EnumFacing.class); Object returnValue = method.invoke(null, weight, start , structureComponents, rand, structureMinX, structureMinY, structureMinZ, facing, componentType); Village returnObj = (Village) returnValue; return returnObj; } catch (NoSuchMethodException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } { return null; } } }
  7. Oops, I meant VillageStructures in the below method: protected void spawnIvVillagers(World worldIn, StructureBoundingBox structurebb, int x, int y, int z, int count, boolean allow_children, int prof) { if (this.villagersSpawned < count) { for (int i = this.villagersSpawned; i < count; ++i) { int j = this.getXWithOffset(x + i, z); int k = this.getYWithOffset(y); int l = this.getZWithOffset(x + i, z); if (!structurebb.isVecInside(new BlockPos(j, k, l))) { break; } ++this.villagersSpawned; if (this.isZombieInfested) { EntityZombieVillager entityzombievillager = new EntityZombieVillager(worldIn); entityzombievillager.setLocationAndAngles((double)j + 0.5D, (double)k, (double)l + 0.5D, 0.0F, 0.0F); entityzombievillager.onInitialSpawn(worldIn.getDifficultyForLocation(new BlockPos(entityzombievillager)), (IEntityLivingData)null); entityzombievillager.enablePersistence(); worldIn.spawnEntity(entityzombievillager); } else { if (allow_children) { int Gender; Gender = r.nextInt(2) + 1; String Name = IvVillager.random_name(Gender); IvVillager entityvillager = new IvVillager(worldIn, prof, Gender, Name); entityvillager.setLocationAndAngles((double)j + 0.5D, (double)k, (double)l + 0.5D, 0.0F, 0.0F); entityvillager.setProfession(this.chooseForgeProfession(i, entityvillager.getProfessionForge())); entityvillager.finalizeMobSpawn(worldIn.getDifficultyForLocation(new BlockPos(entityvillager)), (IEntityLivingData)null, false); worldIn.spawnEntity(entityvillager); if (r.nextInt(3) == 0) { UUID father_id = entityvillager.getUniqueID(); Gender = r.nextInt(2) + 1; Name = IvVillager.random_name(Gender); IvVillager entityvillager2 = new IvVillager(worldIn, prof, Gender, Name); entityvillager2.setLocationAndAngles((double)j + 0.5D, (double)k, (double)l + 0.5D, 0.0F, 0.0F); entityvillager2.setProfession(this.chooseForgeProfession(i, entityvillager2.getProfessionForge())); entityvillager2.finalizeMobSpawn(worldIn.getDifficultyForLocation(new BlockPos(entityvillager2)), (IEntityLivingData)null, false); worldIn.spawnEntity(entityvillager2); UUID mother_id = entityvillager2.getUniqueID(); Gender = r.nextInt(2) + 1; Name = IvVillager.random_name(Gender); IvVillager entityvillager3 = new IvVillager(worldIn, prof, Gender, Name, father_id, mother_id); entityvillager3.setGrowingAge(-23000); entityvillager3.setLocationAndAngles((double)j + 0.5D, (double)k, (double)l + 0.5D, 0.0F, 0.0F); entityvillager3.setProfession(this.chooseForgeProfession(i, entityvillager.getProfessionForge())); entityvillager3.finalizeMobSpawn(worldIn.getDifficultyForLocation(new BlockPos(entityvillager3)), (IEntityLivingData)null, false); worldIn.spawnEntity(entityvillager3); } } int Gender; Gender = r.nextInt(2) + 1; String Name = IvVillager.random_name(Gender); IvVillager entityvillager = new IvVillager(worldIn, prof, Gender, Name); entityvillager.setLocationAndAngles((double)j + 0.5D, (double)k, (double)l + 0.5D, 0.0F, 0.0F); entityvillager.setProfession(this.chooseForgeProfession(i, entityvillager.getProfessionForge())); entityvillager.finalizeMobSpawn(worldIn.getDifficultyForLocation(new BlockPos(entityvillager)), (IEntityLivingData)null, false); worldIn.spawnEntity(entityvillager); } } } }
  8. I don't know where it is doing that, so I'll post the github: https://github.com/Orange1861/Improved-Villagers/tree/Orange1861-2.1.0-B1
  9. Alright, but when I use the UUIDs, the console is spammed with this: [19:48:20] [Server thread/WARN]: Keeping entity iv:villager that already exists with UUID 8bcface4-efef-410c-94db-637c8434c733
  10. At either world gen or birth, I want the baby of my custom mob to store its parents' entity ids. As well, I want the game to check if the id is dead to check if the parents are dead. If MC reuses the ids too often, then the above way will eventually break.
  11. At which point does this happen? (A.K.A., can I rely on it not ever being not reused)
  12. Does MC reused Entity Ids when the original holder is kill? For example: There are 600 entities in a world and I kill entity number 32, will entity 601 have an id of 600 or 31?
  13. Lastly, how do I allow the button to dynamically change from following to follow and vice versa in the text as a confirmation that the packet had been sent and worked?
  14. So this then? @Override public void writeEntityToNBT(NBTTagCompound compound) { super.writeEntityToNBT(compound); compound.setInteger("Profession", this.getProfession()); compound.setString("ProfessionName", this.getProfessionForge().getRegistryName().toString()); compound.setInteger("Riches", this.wealth); compound.setInteger("Gender", this.getGender()); compound.setInteger("Int_Age", this.getIntAge()); compound.setInteger("Hire_Cost", this.getHireCost()); compound.setBoolean("Is_Hired", this.getHired()); compound.setInteger("Career", this.careerId); compound.setInteger("CareerLevel", this.careerLevel); compound.setBoolean("Willing", this.isWillingToMate); compound.setTag("Villager_Inv", this.item_handler.serializeNBT()); } @Override public void readEntityFromNBT(NBTTagCompound compound){ super.readEntityFromNBT(compound); this.item_handler.deserializeNBT((NBTTagCompound) compound.getTag("Villager_Inv")); } Huh, some code that I forgot to remove when I got the player id fixed.
  15. Also, I've been getting this error, do you know what it means? [Server thread/INFO]: [STDOUT]: 7c91ca05-60d3-468c-9c4e-5a2202557afe
  16. I know but what kind of compound I use to set the serialization? Alright, I'll remove this.
  17. How do I do that? What do I use to handle the serializeNBT? @Override public void writeEntityToNBT(NBTTagCompound compound) { super.writeEntityToNBT(compound); if (world.isRemote == false){ this.item_handler.serializeNBT(); }
  18. The hiring mostly works but I have one major issue: The inventories are reset on reload, I have no clue how to prevent this.
  19. Yeah, I've had many issues with linking my workspace with a local Git, I'll try to continue this after I complete this update. I will go through the changes and I'll reply if there are remaining issues.
  20. Alright, but the hiring of the villager button and then the enable/disable follow on the hired villager still don't work (do nothing) and the console doesn't print any errors or anything. I think it has something with my GUI but it may be something else, github. 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(); this.addButton(new Button_Hire(0, this.getGuiLeft() + 115, this.getGuiTop() + 20, 50, 25, "Hire", this.villager, 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) { 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 MessageSendEntityId(this.villager.getEntityId())); } } @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 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, 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(); } 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; } }
  21. Um, how do I get the world without using the ctx? So this container is correct (my other just has more slots? 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)); } } }
  22. Ah, I understand now regarding the packet (I'll still post it below as a finished solution/in case I still screwed up). 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 serverPlayer.mcServer.addScheduledTask(new Runnable_Hire_Villager(message, ctx)); // No response packet return null; } } class Runnable_Hire_Villager implements Runnable{ private IvVillager villager; private int EntityID; private EntityPlayerMP player; private World world; public Runnable_Hire_Villager(MessageSendEntityId message, MessageContext ctx){ this.player = ctx.getServerHandler().player; this.EntityID = message.EntityID; this.world = this.player.world; this.villager = (IvVillager) world.getEntityByID(EntityID); } @Override public void run() { if (this.player.getDistanceToEntity(this.villager) <= 10) { this.villager.hire_Villager(this.player); } } } With the containers I assumed that each container contains different slots, if they always refer to the same slot id throughout the item handler, then how do I only use my mod's inventory or is starting from 0 okay? -Edit I have started preliminary testing and results don't look good.
  23. Is this below what you meant then? 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 serverPlayer.mcServer.addScheduledTask(Runnable_Hire_Villager(ctx.getServerHandler().player.mcServer, message, ctx)); // No response packet return null; } } public class Runnable_Hire_Villager implements Runnable{ private IvVillager villager; private int EntityID; private EntityPlayerMP player; private World world; public Runnable_Hire_Villager(MinecraftServer mcServer, MessageSendEntityId message, MessageContext ctx){ this.player = ctx.getServerHandler().player; this.EntityID = message.EntityID; this.world = mcServer.getEntityWorld(); this.villager = (IvVillager) world.getEntityByID(EntityID); } @Override public void run() { if (this.player.getDistanceToEntity(this.villager) <= 10) { this.villager.hire_Villager(this.player); } } } I mean, how do I get individual containers and get their inv slots separately out of the villager item_handler?
×
×
  • Create New...

Important Information

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