Jump to content

Arkoonius

Members
  • Posts

    17
  • Joined

  • Last visited

Converted

  • Gender
    Undisclosed
  • Personal Text
    I am new!

Arkoonius's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. facepalm.jpg Yep. That fixed it. Thanks everyone! I'll hopefully be able to take it from here, unless someone else has something they'd like to input to help me out.
  2. It does both. And no tile entities are used because, as far as I'm concerned, they aren't needed. The packet is getting received and the player is getting the item, but the inventories between client and server are unsync'd. In order to see the results, I have to click on the slots to update my inventory on the client. I recorded a quick video to show it visually.
  3. Rofl, sorry. I get lazy with naming when I'm simply trying to figure things out. TestGuiContainer IS the container, while TestGui is the GuiContainer. public class TestGuiContainer extends Container { public InventoryPlayer playerInv; public TestGuiContainer(InventoryPlayer inv) { playerInv = inv; } public void giveOre() { for (int i = 0; i < playerInv.mainInventory.length; i++) { if (playerInv.mainInventory[i] == null) { playerInv.mainInventory[i] = new ItemStack(RBItems.runiteOre, 1); break; } } } @Override public boolean canInteractWith(EntityPlayer arg0) { // TODO Auto-generated method stub return false; } } public class TestGui extends GuiContainer { int bgWidth = 256; int bgHeight = 145; //calc positions to place gui in middle of screen int guiXPos = 0; int guiYPos = 0; int buttonWidth = 40; int buttonHeight = 20; GuiButton btnBalls; boolean mousedOver = false; //for drawing buttons and other GUI elements, keep everything in one image file and work with it //as if you would with a sprite sheet (see drawTexturedModalRect comment) public TestGui(InventoryPlayer inv) { super(new TestGuiContainer(inv)); } @Override public void initGui() { guiXPos = (width - bgWidth) / 2; guiYPos = (height - bgHeight) / 2; buttonList.clear(); //add button id xPos yPos width height text buttonList.add(btnBalls = new GuiButton(0, guiXPos + 10, guiYPos + 70, 40, 20, "Things")); super.initGui(); } @Override public void actionPerformed(GuiButton button) { switch (button.id) { case 0: button.displayString = "Butts"; ClientPacket.createGuiPacket("gui"); } super.actionPerformed(button); } @Override public void keyTyped(char what, int keyCode) { switch (keyCode) { case Keyboard.KEY_E: mc.displayGuiScreen(null); } super.keyTyped(what, keyCode); } @Override public void mouseClicked(int x, int y, int mouseButton) { if (mouseOver(x, y, guiXPos + 10, guiYPos + 50, buttonHeight, buttonWidth)) { mousedOver = true; } else mousedOver = false; super.mouseClicked(x, y, mouseButton); } public boolean mouseOver(int mouseX, int mouseY, int posX, int posY, int height, int width) { if ((mouseX >= posX) & (mouseY >= posY)) { if ((mouseX <= (posX + width)) & (mouseY <= (posY + height))) { return true; } } return false; } @Override protected void drawGuiContainerBackgroundLayer(float arg0, int arg1, int arg2) { guiXPos = (width - bgWidth) / 2; guiYPos = (height - bgHeight) / 2; GL11.glColor4f(1.f, 1.f, 1.f, 1.f); //RGBA drawDefaultBackground(); mc.renderEngine.bindTexture(new ResourceLocation("runeblock", "textures/gui/CraftingGuiBackground.png")); //bind GUI texture //drawing GUI background drawTexturedModalRect(guiXPos, guiYPos, 0, 0, bgWidth, bgHeight); //0s are starting position with texture to draw (think sprite sheets) if (!mousedOver) drawTexturedModalRect(guiXPos + 10, guiYPos + 50, 0, bgHeight, buttonWidth, buttonHeight); else drawTexturedModalRect(guiXPos + 10, guiYPos + 50, 0, bgHeight + buttonHeight, buttonWidth, buttonHeight); } @Override protected void drawGuiContainerForegroundLayer(int arg1, int arg2) { fontRendererObj.drawString("Things", guiXPos + 10, guiYPos + 10, 0x000000); //last arg is hex for color } } public class GuiHandler implements IGuiHandler { @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { switch (ID) { case 0: return new TestGui(player.inventory); } return null; } @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { switch (ID) { case 0: return new TestGuiContainer(player.inventory); } return null; } That's everything directly relevant to my GUI. Once I get this figured (with your help), I'll be making the class names less confusing along with actually putting comments within the code.
  4. -> Server gets packet (that has pressed button ID for example) -> Packet has MessageContext ctx, so ctx.getServerHandler().playerEntity gives you server-side player (EntityPlayerMP) -> playerEntity.openContainer gives you container you have defined in your IGuiHandler (getClientGuiElement you returned GuiContainer for client-side and getServerGuiElement Container for server-side) -> You can set ItemStack to player inventory by getting player's inventory either from Container (if you have passed InventoryPlayer as an argument when constructing Container for server in IGuiHandler, that would be easiest because InventoryPlayer has good methods for handling player's inventory) or from EntityPlayerMP#getInventory() (which returns inventory as ItemStack array). I am passing InventoryPlayer into the constructor, but I can't access it via player.openContainer. public InventoryPlayer playerInv; public TestGuiContainer(InventoryPlayer inv) { playerInv = inv; }
  5. Could you elaborate more on those? I've never done this and trying to learn how to, so I'm going to need it more spelled out than the average guy. Well. It doesn't seem I actually need access to the container. As soon as the packet is received (previously sent by clicking a button), I can just add items to the EntityPlayerMP's inventory no problem. EDIT:: Thought this was working, but the inventory gets unsync'd. Figured as much to begin with. I asked about getting access to the container because I figured I would put whatever logic there to handle adding/removing items and just call the functions to do so from the container itself.
  6. Alright. I figured out the issue and the GUI opens/closes without crashing as well as giving the player an item when opened. Final thing: buttons. Making changes to the GUI client side when a button is pressed is easy enough, but how to detect a button press server side? Need to make a button press detectable by the container so that, upon button press, the container can handle giving the player an item. Packets are needed I'm sure, so I got started on that. Once I was nearly done for testing, I realized I had no idea how to "connect" the server side packet and the container.
  7. Here's the log starting from me joining the game. [18:44:14] [server thread/INFO]: Player680 joined the game [18:44:14] [server thread/INFO]: [runeBlock.network.ServerPacket:sendPacketToClient:46]: sending packet to client [18:44:14] [Client thread/INFO]: [Client thread] Client side modded connection established [18:44:14] [Client thread/INFO]: [runeBlock.network.ClientPacketHandler:onClientPacket:23]: packet received [18:44:14] [server thread/INFO]: Saving and pausing game... [18:44:14] [server thread/INFO]: Saving chunks for level 'New World'/Overworld [18:44:14] [server thread/INFO]: Saving chunks for level 'New World'/Nether [18:44:14] [server thread/INFO]: Saving chunks for level 'New World'/The End [18:44:17] [server thread/ERROR]: Encountered an unexpected exception net.minecraft.util.ReportedException: Ticking memory connection at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:181) ~[NetworkSystem.class:?] at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:659) ~[MinecraftServer.class:?] at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:547) ~[MinecraftServer.class:?] at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:111) ~[integratedServer.class:?] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:427) [MinecraftServer.class:?] at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:685) [MinecraftServer$2.class:?] Caused by: java.lang.NullPointerException at net.minecraft.network.NetHandlerPlayServer.processPlayerBlockPlacement(NetHandlerPlayServer.java:620) ~[NetHandlerPlayServer.class:?] at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(SourceFile:60) ~[C08PacketPlayerBlockPlacement.class:?] at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(SourceFile:9) ~[C08PacketPlayerBlockPlacement.class:?] at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:212) ~[NetworkManager.class:?] at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:165) ~[NetworkSystem.class:?] ... 5 more [18:44:17] [server thread/ERROR]: This crash report has been saved to: C:\Users\Owner\Desktop\my mc mods\RuneBlock\eclipse\.\crash-reports\crash-2015-01-08_18.44.17-server.txt [18:44:17] [server thread/INFO]: Stopping server [18:44:17] [server thread/INFO]: Saving players [18:44:17] [server thread/INFO]: Saving worlds [18:44:17] [server thread/INFO]: Saving chunks for level 'New World'/Overworld [18:44:17] [Client thread/INFO]: [net.minecraft.client.Minecraft:displayCrashReport:349]: ---- Minecraft Crash Report ---- // You're mean. Time: 1/8/15 6:44 PM Description: Ticking memory connection java.lang.NullPointerException: Ticking memory connection at net.minecraft.network.NetHandlerPlayServer.processPlayerBlockPlacement(NetHandlerPlayServer.java:620) at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(SourceFile:60) at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(SourceFile:9) at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:212) at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:165) at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:659) at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:547) at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:111) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:427) at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:685) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Stacktrace: at net.minecraft.network.NetHandlerPlayServer.processPlayerBlockPlacement(NetHandlerPlayServer.java:620) at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(SourceFile:60) at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(SourceFile:9) at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:212) -- Ticking connection -- Details: Connection: net.minecraft.network.NetworkManager@203ab1e1 Stacktrace: at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:165) at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:659) at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:547) at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:111) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:427) at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:685) -- System Details -- Details: Minecraft Version: 1.7.10 Operating System: Windows 7 (amd64) version 6.1 Java Version: 1.7.0_51, Oracle Corporation Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation Memory: 862425928 bytes (822 MB) / 1037959168 bytes (989 MB) up to 1037959168 bytes (989 MB) JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0 FML: MCP v9.05 FML v7.10.85.1230 Minecraft Forge 10.13.2.1230 4 mods loaded, 4 mods active mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available FML{7.10.85.1230} [Forge Mod Loader] (forgeBin-1.7.10-10.13.2.1230.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available Forge{10.13.2.1230} [Minecraft Forge] (forgeBin-1.7.10-10.13.2.1230.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available Ark_RuneBlock{v0.1} [RuneBlock] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available Profiler Position: N/A (disabled) Vec3 Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used Player Count: 1 / 8; [EntityPlayerMP['Player680'/183, l='New World', x=286.37, y=4.00, z=-1259.41]] Type: Integrated Server (map_client.txt) Is Modded: Definitely; Client brand changed to 'fml,forge' [18:44:17] [Client thread/INFO]: [net.minecraft.client.Minecraft:displayCrashReport:354]: #@!@# Game crashed! Crash report saved to: #@!@# .\crash-reports\crash-2015-01-08_18.44.17-server.txt [18:44:17] [Client thread/INFO]: Waiting for the server to terminate/save. [18:44:17] [server thread/INFO]: Saving chunks for level 'New World'/Nether [18:44:17] [server thread/INFO]: Saving chunks for level 'New World'/The End [18:44:17] [server thread/INFO]: Unloading dimension 0 [18:44:17] [server thread/INFO]: Unloading dimension -1 [18:44:17] [server thread/INFO]: Unloading dimension 1 [18:44:17] [server thread/INFO]: Applying holder lookups [18:44:17] [server thread/INFO]: Holder lookups applied [18:44:17] [server thread/INFO]: The state engine was in incorrect state SERVER_STOPPING and forced into state SERVER_STOPPED. Errors may have been discarded. [18:44:17] [Client thread/INFO]: Server terminated. AL lib: (EE) alc_cleanup: 1 device not closed I tried debugging, but it doesn't crash during debug if I put a breakpoint on the the Container being instantiated and then stepping through the code line by line. Going into debug mode and having the code run it's course without any breakpoints still crashes the game, however.
  8. Well, let's first ask this question: am I doing anything wrong in the first place? Here's the relevant code: [spoiler=TestGui.java] public class TestGui extends GuiContainer { int bgWidth = 256; int bgHeight = 145; //calc positions to place gui in middle of screen int guiXPos = 0; int guiYPos = 0; int buttonWidth = 40; int buttonHeight = 20; GuiButton btnBalls; boolean mousedOver = false; //for drawing buttons and other GUI elements, keep everything in one image file and work with it //as if you would with a sprite sheet (see drawTexturedModalRect comment) public TestGui(InventoryPlayer inv) { super(new TestGuiContainer(inv)); } @Override public void initGui() { guiXPos = (width - bgWidth) / 2; guiYPos = (height - bgHeight) / 2; buttonList.clear(); //add button id xPos yPos width height text buttonList.add(btnBalls = new GuiButton(0, guiXPos + 10, guiYPos + 70, 40, 20, "Things")); super.initGui(); } @Override public void actionPerformed(GuiButton button) { switch (button.id) { case 0: button.displayString = "Butts"; } super.actionPerformed(button); } @Override public void keyTyped(char what, int keyCode) { switch (keyCode) { case Keyboard.KEY_E: mc.displayGuiScreen(null); } super.keyTyped(what, keyCode); } @Override public void mouseClicked(int x, int y, int mouseButton) { if (mouseOver(x, y, guiXPos + 10, guiYPos + 50, buttonHeight, buttonWidth)) { mousedOver = true; } else mousedOver = false; super.mouseClicked(x, y, mouseButton); } public boolean mouseOver(int mouseX, int mouseY, int posX, int posY, int height, int width) { if ((mouseX >= posX) & (mouseY >= posY)) { if ((mouseX <= (posX + width)) & (mouseY <= (posY + height))) { return true; } } return false; } @Override protected void drawGuiContainerBackgroundLayer(float arg0, int arg1, int arg2) { guiXPos = (width - bgWidth) / 2; guiYPos = (height - bgHeight) / 2; GL11.glColor4f(1.f, 1.f, 1.f, 1.f); //RGBA drawDefaultBackground(); mc.renderEngine.bindTexture(new ResourceLocation("runeblock", "textures/gui/CraftingGuiBackground.png")); //bind GUI texture //drawing GUI background drawTexturedModalRect(guiXPos, guiYPos, 0, 0, bgWidth, bgHeight); //0s are starting position with texture to draw (think sprite sheets) if (!mousedOver) drawTexturedModalRect(guiXPos + 10, guiYPos + 50, 0, bgHeight, buttonWidth, buttonHeight); else drawTexturedModalRect(guiXPos + 10, guiYPos + 50, 0, bgHeight + buttonHeight, buttonWidth, buttonHeight); } @Override protected void drawGuiContainerForegroundLayer(int arg1, int arg2) { fontRendererObj.drawString("Things", guiXPos + 10, guiYPos + 10, 0x000000); //last arg is hex for color } } [spoiler=TestGuiContainer.java] public class TestGuiContainer extends Container { InventoryPlayer playerInv; public TestGuiContainer(InventoryPlayer inv) { inv.mainInventory[3] = new ItemStack(RBItems.runiteOre, 1); } @Override public boolean canInteractWith(EntityPlayer arg0) { // TODO Auto-generated method stub return false; } } Perhaps not relevant, but I'll include these as well. [spoiler=GuiHandler.java] public class GuiHandler implements IGuiHandler { @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { switch (ID) { case 0: return new TestGui(player.inventory); } return null; } @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { switch (ID) { case 0: return new TestGuiContainer(player.inventory); } return null; } } And this is how I'm opening the GUI [spoiler=GoldBar.java] public class GoldBar extends Item { public GoldBar() { setMaxStackSize(1); setCreativeTab(runeBlock.lib.ModInfo.runeBlockTab); setUnlocalizedName("goldBar"); setTextureName("runeblock:GoldBar"); } @Override public boolean onItemUse(ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int par7, float par8, float par9, float par10) { player.openGui(RuneBlock.instance, 0, world, x, y, z); return false; } }
  9. Thanks for the help you two. I've managed to make some form of progress. Upon opening up the player's inventory, I'm able to give the player an item. Sorta... every time I bring up the GUI the game crashes and I'm left with a TickingMemoryException and NullPointerException within the console. Wiki and forge source documentation is unhelpful due to them being barren in terms of comments and relevant argument names. Though I DO have the item in my inventory when I start the game back up. So how exactly do I properly make changes to the player's inventory within the Container?
  10. Alright. So on button press send a packet to the server and when that is received I can make use of EntityPlayerMP. I can make sense to that, but I'm confused about after that as I have yet to work with containers. From what I understand by reading on the wiki (and please correct me if I'm interpreting this incorrectly), a Container allows interaction between player and TileEntity inventories via GUIs, and TileEntities are simply blocks that can hold extra data beyond just plain metadata (inventory and such). So what I'm thinking what needs to be done is connect the player's inventory with the TileEntity and that TileEntity with the container. Then from there I can mess around with the inventory as needed. But then again, isn't that all serverside? Unless this method has some auto-syncing in the background, I'm seeing this to cause sync issues between server and client player inventories.
  11. Thanks for the advice, but how do I do everything serverside? Everything concerning GUIs and Items points towards GuiContainer, but I can't make heads or tails of it.
  12. Hello all. I would like some help with my GUI. Tutorials I see are mostly just plain code for copy/pasting and I have no idea whether if my issue is specific or not to do that. I want the player to be able to open up a GUI and click on buttons or icons to craft items. This crafting consists of checking the players inventory if it contains the necessary components, destroying them if everything exists, and directly adding the result item to the players inventory. As an example. The player clicks on the "Iron Sword" button on the GUI. The GUI checks the player's inventory that it contains a stick and 2 iron ingots. If the checks return true, a stick and 2 iron ingots are removed from the player's inventory, and the player is given an iron sword as a result. The issues I'm having isn't within the drawing of the GUI, but the actual changes in the player's inventory. In order for what I want to work, I have to do things server-side as well, else everything doesn't work and gets out of sync. I have no idea how to do this, and I'm sure packet handling is required. Could any please explain, in detail, what I have to do? I would normal say "please point me in the right direction," but giving a simple link to another's tutorial, as I've experienced in the past. This GUI is opened by right clicking on a specific block, but it will have no inventory of sorts (e.g. a chest) or even slots (e.g. villager trading). Just simple buttons, textures, and texts.
  13. Ok. How about this: I could use the metadata to determine whether the block can be harvested. If metadata > 0, then the block can be harvested. If the metadata is zero, then you simply can't harvest the block (cancel the BreakBlock event). From there, it's just figuring if I can dynamically switch the texture of the block so the player visually knows that the block can't be harvested. If all else, I suppose I could show a message, but that would just be annoying -- especially when it comes to the rare ores. I can also possibly use said metadata to determine how many times the block can be harvested. So, a block with a metadata of 4 can be harvested 4 times before it has to "respawn". This number would always be between 0 and 15, so it should work. Then just do whats needed if the conditions on a randomTick are met (change metadata/texture. Spawn tree if it's a tree stump, etc).
  14. I could do that. In fact, I'll probably do that. Store the previous block's ID as metadata within the emptyOreBlock. From there, determine a percentage that will determine whether the block respawns or not (probably just make a random number between two values). Higher tier ores will have a lower chance to respawn on tick. I plan to have trees respawn similar to ores, so if using tile entities does mean taking a hit on performance, and with how common trees + ores are going to be in the world, it seems best straight from the start to make due with my plan above. Think Runescape. The ore/trees of that game is what I'm trying to replicate. Well, this mod will be a Runescape mod in general. Once I figure out how to do the skills (and how to make some GUIs), I'm going to work on items, and then eventually mobs. My only issue is that I'll probably have to "combine" some skills on leave some out since the player's dataWatcher only has indexes 19-31 available.
  15. Didn't think about looking at how saplings generate trees, lol. Sounds like a plan. One more thing that just came up -- for the player's dataWatcher, I'm limited to using indexes 19-31. With due to this, I can only track the player's current experience of 13 skills. I'd like to go beyond 13, if it's possible. Any idea of a workaround?
×
×
  • Create New...

Important Information

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