Jump to content

Ernio

Forge Modder
  • Posts

    2638
  • Joined

  • Last visited

  • Days Won

    4

Everything posted by Ernio

  1. This has nothing to do with modding, but rather code design. Well... some may argue. Anyway - to make it look nice you need some kind of abstraction. If all TEs are doing similar thing, you can make some AbstractBaseTe. Make some common methods that return data or even better - make methods that encode data onto buffer of your packet. That way you could make one packet that accepts AbstractBaseTE and calls some encode(). Then when you receive packet you can read some ID (type) of TE and read it back. There is literally infinite ways to design your code and if you don't know now - give it time, read other ppl code (open sources). You will probably rewrite big parts of your mod some day when you realize there is better way to do it. Finally - yes, you will always use IMessage and MessageHandler. INSTA EDIT Well, damn me! Failender was faster
  2. Read this thread. http://www.minecraftforge.net/forum/index.php/topic,31297.msg163070.html#msg163070 If that won't help, nothing will. Well.. unless you are having problems with for loop and iteration - in that case go to uncle google and ask how programming works. :*
  3. @Override public ItemStack onItemRightClick(ItemStack stack, World par2World, EntityPlayer par3EntityPlayer) { NBTTagCompound nbt = stack.getTagCompound(); if (nbt == null) { nbt = new NBTTagCompound(); stack.setTagCompound(nbt); } nbt.setBoolean("active", !(nbt.getBoolean("active"))); // "nbt" is alredy itemStack's NBT, you are now setting value inside of it - a "active" boolean. return stack; } @Override @SideOnly(Side.CLIENT) public boolean hasEffect(ItemStack stack) { NBTTagCompound nbt = stack.getTagCompound(); // nbt of itemStack boolean active = nbt.getBoolean("active"); // value stored inside nbt marked wtih "active" key. return active; }
  4. 1. Too fast bump (much too fast). 2. You are adding infinite number of "new GuiButton" to your gui. basically - each FPS, one more button. If buttons overlay each other - all will be pressed, thus - multiple clicks. 3. You should be adding Buttons in initGui() (not neccessary, the point is - do it once). 4. Point of interest: minecraft handles buttonList.clear() for you (just before initGui() is called), but if you were to call initGui() on your own, or add more buttons while gui is alredy opened - remember to clear the list 1st (or remove unused). I am refering to guis that have e.g multiple pages with different buttons on each.
  5. 1.1. IDE "Search" tool. You HAVE TO learn to use it. 1.2. Reading source (yes, MC source and callbacks). 2. Pretty much: https://docs.oracle.com/javase/tutorial/reflect/ More on google. Point of interest (regarding moddig): ObfuscationReflectionHelper.
  6. Also: (look at your coords) x + x x + y x + z It probably works, just sets block in some useless place.
  7. loading and saving is manual - look at static method at end of file in example (Questology).
  8. My mistake for giving bad example, your bad for not looking at method. openGui(instance, id, world, x, y, z);
  9. Well, basically Draco is right (Was that a pure guess Draco?). You need to override onBlockActivated method in your Block class and call player.openGui(id, Mod.instance, x, y, z); Looking at GuiHandler and everything else - it should work.
  10. You don't have to do this: (initializing I mean) @Instance public static SteelMain instance = new SteelMain(); This is useless: (tab[0, 1, ..., n-1] is literally a number from 0 to n-1.) private static final int[] slots = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; As to your problem - "we" need Block, Gui and GuiHandler classes. 1st one is basically responsible for calling opening, which should be done with GuiHandler implementation and which should then open Container AND Gui accordingly (to side).
  11. No, No, No, No... Minecraft is client-only class. Everything there is a display stuff - You cannot edit it, it won't do shit to actual data on server. public static UUID getUUID(ItemStack stack) { NBTTagCompound nbt = stack.getTagCompound(); if (nbtTagCompound != null) { return new UUID(nbt.getLong("MSB"), nbt.getLong("LSB")); // most and least significant bits } return null; } In your Item class you need to write data to NBT on usage: UUID uuid = entity.getUniqueId(); // entity is some entity you want to save ref to. nbt.setLong("MSB", uuid.getMostSignificantBits()); // nbt of itemstack. nbt.setLong("LSB", uuid.getLeastSignificantBits()); Getting actual ref: @Override public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) { if (!world.isRemote) // UUIDs ONLY exist on server (not counting players) { UUID uuid = getUUID(itemStack); // 1st method in post Entity entity = ((WorldServer) world).getEntityFromUuid(uuid); Do note that srcs above are unsafe and need null handling for NBT/entity/uuid.
  12. Ah, I used bad naming, getEntityByID uses "network" IDs used to sync server and client entity data. It's just that I have my own utilitiy method that does it for UUID (thus, my confusion). Anyway: World isntance has "loadedEntityList". You need to make utility method that will take UUID and return Entity. Then in that method you will iterate through all entities ("loadedEntityList") and check if entity.getUniqueId().equals(paramUUID), if so - return entity. As one could expect - retrieving UUID from ItemStack's NBT, converting it from 2 longs to "new UUID(least, most)" and then comparing it to list of ALL entities (until found) MIGHT be a little overhead if not used with care - so if you'd ever use it in future to manage per-tick actions - try caching refernce at all cost (not quite possible with ItemStacks).
  13. Should be noted: If you don't know yet - Item is singleton, logically speaking "a description of what you are holding". The thing you are actually holding is ItemStack and only ItemStack can hold per-stack data. To save reference to entity in ItemStack you need to use entity.getUniqueId() which can then be saved in ItemStack's NBT as 2 longs (UUID#getMost/LeastSignificantBits()). Then you can re-reference entity by getting it from saved UUID - World#getEntityById (or similar method, i don't remember). Do note that entity might not be found (unloaded), might only be found on server (client is too far to see entity) or other expected or not behaviours - that all needs to be handled properly.
  14. 1. Read about how Java creates instances. 2. Notice that applyEntityAttributes() is called from super-constructor of your entity. 3. Think about what is happening and say: "Oh, shit, those 2 globals "spirit_damage" and "spirit_health" are not yet initialized! Therefore, generic data in java is set to default 0.0 for doubles! 4. Ahh... so that's why my entity dies! EDIT What you need: Use "static" keyword to make it shared between all entities. If you need different entities have different health you CANNOT use "SharedMonsterAttributes" - notice word "Shared". To achieve different values (and make them sync automatically) for different you need to apply AttributeModifier to entity after it's been spawned.
  15. Short: No. http://www.minecraftforge.net/forum/index.php/topic,22764.0.html My input: http://www.minecraftforge.net/forum/index.php/topic,33918.msg178740.html#msg178740 You cannot "program minecraft" while also having "bad java knowledge", therefore I say: "You have no idea what you are doing, do you?"
  16. While editing ItemStack will happen on server, the particles can only spawn on client. Basically - particle is "special" (retarded) brother of normal entity and should be spawned on client, not on server.
  17. Without even reading rest of code: You can (should, only exception is synchronization or administrative tools) only edit inventory from server: if(!world.isRemote){edit}
  18. StatisticsFile stats = ((EntityPlayerMP) player).getStatFile() // only on server this.thePlayer.triggerAchievement(Your achi instance); if (stats.hasAchievementUnlocked(some other instance of your archi)) // Check all of your archivements // If all are true, give another one with: this.thePlayer.triggerAchievement(Your achi instance);
  19. So what exacly are you asking?
  20. For your own block - override: public Item getItemDropped(IBlockState state, Random rand, int fortune) // for only one thing. public int quantityDropped(IBlockState state, int fortune, Random random) // for quantity of one thing. public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) // for maximum flexibility (you can drop multiple different things) For vanilla blocks - Subscribe to HarvestDropsEvent and edit event.drops.
  21. Well: int count = 0; for (int i; i < 36; ++i) { ItemStack stack = player.inventory.mainInventory[i]; if (stack != null && stack.getItem() == Item.someItem) count += stack.stackSize; } if (count >= requiredToRemove) { int i = 0; while (requiredToRemove > 0) { ItemStack stack = player.inventory.mainInventory[i]; if (stack != null && stack.getItem() == Item.someItem) { if (requiredToRemove >= stack.stackSize) player.inventory.mainInventory[i] = null; else stack.stackSize -= requiredToRemove; requiredToRemove -= stack.stackSize; } ++i; } Something like this. Wrote it here so probably forgot something. This can be done better.
  22. CompressedStreamTools allow you to read/write NBT to file. Note that this operation still needs to act only on server. Client cannot manipulate data.
  23. You should really learn tesselator (and math?) to understand the drawing process. The method you are using now: drawTexturedModalRect(xPos -94, yPos - 32 + 3, 0, 9, expbar, 7); Is pretty much: Draw box from x/y, with width/height. So logically, when width is your progress, the "walls" of box are at: left: x right: x+progress top: y bot: y+height To draw in reverse you would need to have: left: x+max-progress right: x+max top: y bot: y+height Converted to drawing: drawTexturedModalRect(xPos + 194 - expbar, yPos - 29, 0, 9, expbar, 7); But that is just plain stupid if you can easily learn tess and draw nice things, example: wr.addVertex(right, top, zLevel); // top right corner wr.addVertex(left, top, zLevel); // top left corner wr.addVertex(left, bottom, zLevel); // bot left wr.addVertex(right, bottom, zLevel); // bot right This draws a box with said 4 corners. Since vertexes go anti-clockwise, you add them in this order. Look at "drawTexturedModalRect" on how to implement it, I leave it as an exerice. Read more: http://greyminecraftcoder.blogspot.com.au/2013/08/the-tessellator.html
  24. Iterate list and draw line by line (offset Y by +i*10) ?
  25. If I understand you: ItemStack represents some container item (e.g: backpack) with one slot for another item. Container (backpack) item stores its content (that one item) inside its NBT using primitives. So if you want to change container item OR the item within based on item within, you need to read it. You can either do something like: ItemStack itemWithin = ItemStack.loadItemStackFromNBT(nbtOfContainerItem.getTag("itemWithin")); And then operate on it. Or you can operate on ItemStack within without recreating it (so basically operate on raw data).
×
×
  • Create New...

Important Information

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