-
Posts
867 -
Joined
-
Last visited
-
Days Won
3
Everything posted by JimiIT92
-
I have a mod running on a server and i need to save some json files. For the save part i had no problem, but i noticed that these files are saved in the client folder instead that the server world folder. SO how can i point directly to the server folder and avoid these files being saved on the client? This is what i have right now public static void saveFaction(Faction f) { JSONObject obj = new JSONObject(); obj.put("Name", f.getName()); obj.put("Owner", f.getOwner().toString()); JSONArray members = new JSONArray(); for(UUID u : f.getMembers()) { members.add(u.toString()); } obj.put("Members", members); File dir = new File(DimensionManager.getCurrentSaveRootDirectory() + "/factions"); if(!dir.exists()) dir.mkdirs(); try (FileWriter file = new FileWriter(dir + "/" + f.getName() + ".json")) { file.write(obj.toJSONString()); } catch (IOException e) { e.printStackTrace(); } } I'm using JSON.Simple just to create correctly JSON files
-
This is the GUI code i'm using where i want to put the tab completer package com.cf.gui; import java.io.IOException; import java.util.List; import java.util.UUID; import javax.annotation.Nullable; import org.lwjgl.input.Keyboard; import org.lwjgl.opengl.GL11; import com.cf.CoreFaction; import com.cf.capabilities.world.FactionCapabilitiesProvider; import com.cf.capabilities.world.IFactionCapabilities; import com.cf.messages.FactionCapabilitiesMessage; import com.cf.utils.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiTextField; import net.minecraft.client.resources.I18n; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.util.ResourceLocation; import net.minecraft.util.TabCompleter; import net.minecraft.util.math.BlockPos; import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.TextFormatting; import net.minecraft.world.World; import net.minecraftforge.fml.common.FMLCommonHandler; public class GuiFactionHandling extends GuiScreen { private static final ResourceLocation BG = new ResourceLocation(CoreFaction.MODID, "textures/gui/scroll.png"); private GuiButton inviteBtn; private GuiButton kickBtn; private GuiButton cancelBtn; private GuiTextField nameTextField; private GuiTextField kickTextField; private TabCompleter tabCompleter; public void updateScreen() { this.nameTextField.updateCursorCounter(); this.kickTextField.updateCursorCounter(); if(nameTextField.getText().trim().length() <= 0) this.inviteBtn.enabled = false; else this.inviteBtn.enabled = true; if(kickTextField.getText().trim().length() <= 0) this.kickBtn.enabled = false; else this.kickBtn.enabled = true; } public void initGui() { int xPos = (this.width - 256) / 2; int yPos = (this.height - 256) / 2; this.buttonList.clear(); this.inviteBtn = this.addButton( new GuiButton(0, xPos + 53, yPos + 50, 150, 20, Utils.getTranslation("gui.handling.invite"))); this.kickBtn = this.addButton( new GuiButton(1, xPos + 53, yPos + 100, 150, 20, Utils.getTranslation("gui.handling.kick"))); this.cancelBtn = this.addButton( new GuiButton(2, xPos + 53, yPos + 150, 150, 20, Utils.getTranslation("gui.handling.cancel"))); Keyboard.enableRepeatEvents(true); this.nameTextField = new GuiTextField(3, this.fontRendererObj, xPos + 53, yPos + 70, 150, 20); this.nameTextField.setMaxStringLength(32500); this.nameTextField.setFocused(true); this.kickTextField = new GuiTextField(4, this.fontRendererObj, xPos + 53, yPos + 120, 150, 20); this.kickTextField.setMaxStringLength(32500); this.kickTextField.setFocused(false); this.tabCompleter = new TabCompleter(this.nameTextField, false) { @Nullable public BlockPos getTargetBlockPos() { return null; } }; } public void onGuiClosed() { Keyboard.enableRepeatEvents(false); } protected void keyTyped(char typedChar, int keyCode) throws IOException { this.tabCompleter.resetRequested(); if (keyCode == 15) { this.tabCompleter.complete(); } else { this.tabCompleter.resetDidComplete(); } this.nameTextField.textboxKeyTyped(typedChar, keyCode); this.kickTextField.textboxKeyTyped(typedChar, keyCode); if (keyCode != 28 && keyCode != 156) { if (keyCode == 1) { this.actionPerformed(cancelBtn); } } else { if(this.nameTextField.isFocused()) this.actionPerformed(inviteBtn); else if(this.kickTextField.isFocused()) this.actionPerformed(kickBtn); } } protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { super.mouseClicked(mouseX, mouseY, mouseButton); this.nameTextField.mouseClicked(mouseX, mouseY, mouseButton); this.kickTextField.mouseClicked(mouseX, mouseY, mouseButton); } @Override public boolean doesGuiPauseGame() { return false; } @Override protected void actionPerformed(GuiButton button) throws IOException { if (button.enabled) { World world = this.mc.theWorld; EntityPlayer player = this.mc.thePlayer; if (button.id == 0) { IFactionCapabilities cap = world.getCapability(FactionCapabilitiesProvider.FACTION_CAP, null); EntityPlayerMP inv = FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayerByUsername(this.nameTextField.getText()); if(inv != null) { if(cap.getFaction(inv.getUniqueID()) == null) { cap.getFaction(player.getUniqueID()).addPlayer(inv.getUniqueID()); CoreFaction.NETWORK.sendToServer(new FactionCapabilitiesMessage(cap.getFaction(player.getUniqueID()))); CoreFaction.NETWORK.sendTo(new FactionCapabilitiesMessage(cap.getFaction(player.getUniqueID())), inv); this.actionPerformed(cancelBtn); } else { this.actionPerformed(cancelBtn); Utils.sendMessage(player, TextFormatting.RED + Utils.getTranslation("faction.invite.already")); } } else { this.actionPerformed(cancelBtn); Utils.sendMessage(player, TextFormatting.RED + Utils.getTranslation("faction.invite.notfound")); } } else if (button.id == 1) { IFactionCapabilities cap = world.getCapability(FactionCapabilitiesProvider.FACTION_CAP, null); EntityPlayerMP inv = FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayerByUsername(this.nameTextField.getText()); if(inv != null) { if(cap.getFaction(inv.getUniqueID()) == cap.getFaction(player.getUniqueID())) { cap.getFaction(player.getUniqueID()).removePlayer(inv.getUniqueID()); CoreFaction.NETWORK.sendToServer(new FactionCapabilitiesMessage(cap.getFaction(player.getUniqueID()))); CoreFaction.NETWORK.sendTo(new FactionCapabilitiesMessage(cap.getFaction(player.getUniqueID())), inv); this.actionPerformed(cancelBtn); } else { this.actionPerformed(cancelBtn); Utils.sendMessage(player, TextFormatting.RED + Utils.getTranslation("faction.kick.nofaction")); } } else { this.actionPerformed(cancelBtn); Utils.sendMessage(player, TextFormatting.RED + Utils.getTranslation("faction.invite.notfound")); } } else if (button.id == 2) { this.mc.displayGuiScreen((GuiScreen) null); } } } @Override public void drawScreen(int mouseX, int mouseY, float partialTicks) { World world = this.mc.theWorld; EntityPlayer player = this.mc.thePlayer; int xPos = (this.width - 256) / 2; int yPos = (this.height - 256) / 2; GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glDisable(GL11.GL_LIGHTING); this.mc.getTextureManager().bindTexture(this.BG); this.drawTexturedModalRect(xPos, yPos, 0, 0, 256, 256); IFactionCapabilities capabilities = world .getCapability(FactionCapabilitiesProvider.FACTION_CAP, null); this.drawString(fontRendererObj, Utils.getTranslation("gui.handling.faction")+ " " + capabilities.getFaction(player.getUniqueID()).getName(), xPos + 53, yPos + 27, 0xFFFFE6); this.nameTextField.drawTextBox(); this.kickTextField.drawTextBox(); super.drawScreen(mouseX, mouseY, partialTicks); } public void setCompletions(String... newCompletions) { this.tabCompleter.setCompletions(FMLCommonHandler.instance().getMinecraftServerInstance().getAllUsernames()); } }
-
I have a GUI with a textbox. What i want is that pressing tab will loop through all the usernames of players in the world. I've looked into command block GUI and see how it's tab completer works but editing that didn't worked. So how can i add this tab completer inside my GUI?
-
[1.10.2] Spawning structures using Structure Blocks files
JimiIT92 replied to JimiIT92's topic in Modder Support
As diesieben said this was for an help on generating structures using nbt files created by structure blocks. By the way i heard once there was a mod that put nbt structures into the overworld as natural structures, but i don't remember its name unfortunately -
[1.10.2] Underground structure generation problem
JimiIT92 replied to JimiIT92's topic in Modder Support
*facepalm* totally forgot the wrap! And that's why i should never program when i'm sick, that was a really dumb "error" Thanks for pointed it out, now it works -
So i'm trying to spawn a structure underground but the problem is that is too common, despite i give it a really low chance of spawn. This is the code i'm using in the WorldGenerator class if (world.getBiomeGenForCoords(new BlockPos(x, 30, z)).equals(Biomes.ICE_MOUNTAINS) || world.getBiomeGenForCoords(new BlockPos(x, 30, z)).equals(Biomes.ICE_PLAINS) || world.getBiomeGenForCoords(new BlockPos(x, 30, z)).equals(Biomes.MUTATED_ICE_FLATS) || world.getBiomeGenForCoords(new BlockPos(x, 30, z)).equals(MWWorld.arctic) || world.getBiomeGenForCoords(new BlockPos(x, 30, z)).equals(MWWorld.iceHills) && random.nextInt(1000) == 1) { int randPosX = x + random.nextInt(35); int randPosZ = z + random.nextInt(35); int randPosY = 30 + random.nextInt(10); BlockPos position = new BlockPos(randPosX, randPosY, randPosZ); if (!(world.getBlockState(position).getBlock().equals(Blocks.WATER))) new WorldGenIceDungeon(position, world); } And this is the amount of structures that are generated As you can see there are too much of this. So how can i spawn the structure with the properly rarity?
-
I already know that event but what i want is to cancel the swing animation itself, not the damage of the weapon
-
Pretty explanatory, i want that some weapons can't be used by the player if he doesn't have some requirements. For instance i want that the player can't use a diamond sword. I already tried canceling the left click event, but this event cannot be canceled, so how can i prevent the player from using this item?
-
This is the CommonProxy class (i only have this) package com.forgeguard.proxy; import com.forgeguard.events.*; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.FMLCommonHandler; public class CommonProxy { public void init() { MinecraftForge.EVENT_BUS.register(new EventLeftClick()); MinecraftForge.EVENT_BUS.register(new EventPlaceBlock()); MinecraftForge.EVENT_BUS.register(new EventDestroyBlock()); MinecraftForge.EVENT_BUS.register(new EventPvp()); MinecraftForge.EVENT_BUS.register(new EventEntityInteract()); MinecraftForge.EVENT_BUS.register(new EventDrop()); MinecraftForge.EVENT_BUS.register(new EventMobSpawn()); MinecraftForge.EVENT_BUS.register(new EventExplosion()); MinecraftForge.EVENT_BUS.register(new EventUseItem()); MinecraftForge.EVENT_BUS.register(new EventRightClick()); MinecraftForge.EVENT_BUS.register(new EventChat()); MinecraftForge.EVENT_BUS.register(new EventEntityFall()); MinecraftForge.EVENT_BUS.register(new EventHunger()); MinecraftForge.EVENT_BUS.register(new EventPlayerTick()); } } And this is the main mod class package com.forgeguard; import java.util.HashMap; import java.util.UUID; import com.forgeguard.commands.CommandRegion; import com.forgeguard.proxy.CommonProxy; import com.forgeguard.region.Region; import com.forgeguard.utils.Utils; import net.minecraft.item.ItemStack; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.Mod.Instance; import net.minecraftforge.fml.common.SidedProxy; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.event.FMLServerStartingEvent; @Mod(modid = ForgeGuard.MODID, version = ForgeGuard.VERSION, name = ForgeGuard.NAME,serverSideOnly = true, acceptableRemoteVersions = "*") public class ForgeGuard { public static final String MODID = "forgeguard"; public static final String NAME = "Forge Guard"; public static final String VERSION = "0.1"; @Instance("forgeguard") public static ForgeGuard INSTANCE; @SidedProxy(serverSide = "com.forgeguard.proxy.CommonProxy") public static CommonProxy PROXY; public static Utils UTILS; public static String REGIONPATH = "./config/ForgeGuard/regions.dat"; public static String TEMPPATH = "./config/ForgeGuard/regions_temp.dat"; public static String CONFIGPATH = "./config/ForgeGuard/config.cfg"; public static ItemStack SELECTOR; public static HashMap<UUID, Region> PENDINGS = new HashMap<UUID, Region>(); public static HashMap<UUID, Region> EDITINGS = new HashMap<UUID, Region>(); public static String REGION_PERMISSION = ""; public static String BYPASS_PERMISSION = ""; @EventHandler public void preInit(FMLPreInitializationEvent event) { UTILS = new Utils(); UTILS.loadConfig(); } @EventHandler public void init(FMLInitializationEvent event) { PROXY.init(); } @EventHandler public void serverLoad(FMLServerStartingEvent event) { event.registerServerCommand(new CommandRegion()); } } And this is the event class public class EventExplosion { @SubscribeEvent public void onCreeperExplosion(ExplosionEvent.Detonate event) { System.out.println("EXPLOSION!!"); } }
-
Oh, dumb me then Anyway i have other events registered the same way and they all works, is just this that is ignored and i really don't understand why
-
I tried catching only the Detonate sub event but it still doesn't fire. If i ignite a creeper or a tnt and this explode then that printout is not printed (meaning that the event is never called). I'm sure the vent is registered because i've added a constructor in the event class with a print and it printed. Could this be a bug, since i've seen other example codes of explosion handling and they're all the same as mine (except for the fact that they catch only the Detonate sub event, wich is what i will do)? I'm using the Recommended 1.10.2 Forge version (1.10.2 - 12.18.3.2185)
-
Any idea? A cause of this could be the fact that the mod is server side only?
-
No, the class that implements the event is called EventExplosion, the event that i'm catching is called ExplosionEvent. I have other classes that catches events like this and they works, it's just this i don't know why it doesn't For instance this class public class EventPlayerTick { @SubscribeEvent public void onPlayerTick(PlayerTickEvent event) { ...stuff } does work even if the name of class and the name of the event are similar
-
As the title said, i have a class that should check the explosion event. But for some reason this is never called. The event is registered in preInit CommonProxy by doing this MinecraftForge.EVENT_BUS.register(new EventExplosion()); and this is the event class public class EventExplosion { @SubscribeEvent public void onCreeperExplosion(ExplosionEvent event) { System.out.println("EXPLOSION!!"); } Just for test the only thing it does is to print that string in console, but as you might guess this doesn't happen So why this specific event is not fired?
-
Idk, if i print out the location of the entity and the location of where i clicked (the frame) it shows that the entity is one block above
-
Ok, now it works but i have to get the position of the block below because it seems like the entity of the item frame is placed 1 block above the frame itself Thank you for the help
-
So i should catch the second event right?
-
I'm trying to cancel the event so the player can't destroy or interact with Item Frames. But it looks like isn't working and i really don't know why. Maybe i'm catching the wrong event? This is the event code i'm using @SubscribeEvent public void onPlayerInteract(PlayerInteractEvent.EntityInteractSpecific event) { if(event.getTarget() instanceof EntityItemFrame) event.setCanceled(true); } The event is registered in the CommonProxy (since is a server side only mod) as well
-
Thank you so much, that fixed this
-
I'm making a server side only mod that introduce a command with subcommands. One of this will give a specific item to the player, the item is defined by config. But when i run the command i get the item only the first time i run it, the next times i get nothing. This is how i get the item Configuration config = new Configuration(new File("config/ForgeGuard/config.cfg")); config.load(); String item = config.getString("selector", "Selector Item Properties", "stick", "The item to use as region selector"); String color = config.getString("color", "Selector Item Properties", "light purple", "The color of the name of the region selector item"); String name = config.getString("name", "Selector Item Properties", "Region Selector", "The name of the region selector item"); TextFormatting nameColor = TextFormatting.getValueByName(color); String displayName = ""; if (nameColor != null) displayName += nameColor; displayName += name; ForgeGuard.SELECTOR = new ItemStack(Item.getByNameOrId(item), 1).setStackDisplayName(displayName); config.save(); Notice that ForgeGuard.SELECTOR is a static ItemStack declared in the main class. This code is also called from the preInit method This is the command class, in the execute method i check if there are args on the command. If there are and one of this is "selector" than give the item to the player. As i said this works once but not the other times package com.forgeguard.commands; import java.util.ArrayList; import java.util.List; import com.forgeguard.ForgeGuard; import com.forgeguard.region.Region; import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; import net.minecraft.command.CommandResultStats; import net.minecraft.command.EntitySelector; import net.minecraft.command.ICommand; import net.minecraft.command.ICommandSender; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.SoundEvents; import net.minecraft.server.MinecraftServer; import net.minecraft.util.SoundCategory; import net.minecraft.util.math.BlockPos; import net.minecraft.util.text.TextFormatting; public class CommandRegion extends CommandBase { private ArrayList<String> subCommands = new ArrayList<String>(); private ArrayList<String> flags = new ArrayList<String>(); public CommandRegion() { this.subCommands.add("selector"); this.subCommands.add("save"); this.subCommands.add("flag"); this.flags.add("mobs"); this.flags.add("chests"); this.flags.add("edit"); this.flags.add("pvp"); } @Override public String getCommandName() { return "region"; } @Override public String getCommandUsage(ICommandSender sender) { return "/region [subcommand][flag]"; } @Override public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { if (sender.getCommandSenderEntity() != null) { EntityPlayer player = getPlayer(server, sender, sender.getName()); /** * /region */ if (args.length == 0) { Region r = ForgeGuard.UTILS.getRegion(player.dimension, player.getPosition()); if (r != null) ForgeGuard.UTILS.sendMessage(player, r.getName()); else ForgeGuard.UTILS.sendMessage(player, TextFormatting.RED + "There's no region here!"); } else { String subcommand = args[0].toLowerCase(); /** * /region selector */ if (subcommand.equalsIgnoreCase(this.subCommands.get(0))) { boolean flag = player.inventory.addItemStackToInventory(ForgeGuard.SELECTOR); if (flag) { player.worldObj.playSound((EntityPlayer) null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 0.2F, ((player.getRNG().nextFloat() - player.getRNG().nextFloat()) * 0.7F + 1.0F) * 2.0F); player.inventoryContainer.detectAndSendChanges(); } else { sender.setCommandStat(CommandResultStats.Type.AFFECTED_ITEMS, 1); EntityItem entityitem = player.dropItem(ForgeGuard.SELECTOR, false); if (entityitem != null) { entityitem.setNoPickupDelay(); entityitem.setOwner(player.getName()); } } notifyCommandListener(sender, this, "commands.give.success", new Object[] { ForgeGuard.SELECTOR.getTextComponent(), 1, player.getName() }); } /** * /region save */ else if (subcommand.equalsIgnoreCase(this.subCommands.get(1))) { ForgeGuard.UTILS.saveRegion(player); } /** * /region flag */ else if (subcommand.equalsIgnoreCase(this.subCommands.get(2))) { Region r = ForgeGuard.UTILS.getPendingRegion(player); if (r != null) { String flag = args[1]; if (flag.equalsIgnoreCase(this.flags.get(0))) r.setMobs(Boolean.valueOf(args[2])); if (flag.equalsIgnoreCase(this.flags.get(1))) r.setChests(Boolean.valueOf(args[2])); if (flag.equalsIgnoreCase(this.flags.get(2))) r.setEdit(Boolean.valueOf(args[2])); if (flag.equalsIgnoreCase(this.flags.get(3))) r.setPvp(Boolean.valueOf(args[2])); } else ForgeGuard.UTILS.sendMessage(player, TextFormatting.RED + "Select a region first!"); } } } } @Override public boolean checkPermission(MinecraftServer server, ICommandSender sender) { boolean flag; if(sender.getCommandSenderEntity() == null) flag = true; else flag = server.getServer().getPlayerList().getOppedPlayers().getEntry(((EntityPlayer)sender.getCommandSenderEntity()).getGameProfile()) != null; return flag; } @Override public List<String> getTabCompletionOptions(MinecraftServer server, ICommandSender sender, String[] args, BlockPos pos) { if(args[0].equalsIgnoreCase("flag") && !args[1].isEmpty()) { ArrayList<String> bool = new ArrayList<String>(); bool.add("true"); bool.add("false"); return bool; } if(args[0].equalsIgnoreCase("flag")) return this.flags; if(args.length > 3) return new ArrayList<String>(); return this.subCommands; } } The command is registered in the main class by doing this @EventHandler public void serverLoad(FMLServerStartingEvent event) { event.registerServerCommand(new CommandRegion()); } So what could cause this issue? Thanks to all who will help me
-
[SOLVED][1.10.2] Gui input handled multiple times
JimiIT92 replied to JimiIT92's topic in Modder Support
Yes the fix was to add the button into the initGui method, dumb me Thank you for your help -
Pretty explanatory. i have a GUI with a text field and a button. For testing purpose i made that when i press the button the text in the text box is displayed in eclipse. But instead of being displayed one time is displayed multiple times, like i press multiple times the button. This is the code for the GUI i'm using package com.forgeguard.gui; import java.io.IOException; import org.lwjgl.input.Keyboard; import org.lwjgl.opengl.GL11; import com.forgeguard.capabilities.IRegionCapabilities; import com.forgeguard.capabilities.RegionCapabilitiesProvider; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiTextField; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; public class GuiRegion extends GuiScreen{ private static final ResourceLocation BG = new ResourceLocation("textures/gui/demo_background.png"); private GuiTextField textField; private GuiButton button; public void updateScreen() { this.textField.updateCursorCounter(); } @Override public void initGui() { int xPos = width / 2 - 120; int yPos = height / 2 - 87; this.textField = new GuiTextField(2, this.fontRendererObj, xPos + 5, yPos + 100, 238, 20); this.textField.setMaxStringLength(32500); this.textField.setFocused(true); this.button = new GuiButton(0, xPos + 20, yPos + 140, "Save Region"); } @Override protected void keyTyped(char typedChar, int keyCode) throws IOException { if(keyCode == Keyboard.KEY_ESCAPE) { this.mc.displayGuiScreen(null); if(this.mc.currentScreen == null) this.mc.setIngameFocus(); } this.textField.textboxKeyTyped(typedChar, keyCode); } @Override public void drawScreen(int mouseX, int mouseY, float partialTicks) { GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glDisable(GL11.GL_LIGHTING); this.mc.getTextureManager().bindTexture(this.BG); int xPos = width / 2 - 120; int yPos = height / 2 - 87; this.drawTexturedModalRect(xPos, yPos, 0, 0, 256, 256); BlockPos pos1; BlockPos pos2; IRegionCapabilities capabilities = Minecraft.getMinecraft().thePlayer.getHeldItemMainhand() .getCapability(RegionCapabilitiesProvider.REGION_CAPABILITIES, null); if (capabilities != null) { this.fontRendererObj.drawString("First Point: ", xPos + 5, yPos + 18, 4210752); this.fontRendererObj.drawString("Second Point: ", xPos + 5, yPos + 38, 4210752); if(capabilities.getFirstPoint() != null) { this.fontRendererObj.drawString("" + capabilities.getFirstPoint().getX(), xPos + 80, yPos + 18, 4210752); this.fontRendererObj.drawString("" + capabilities.getFirstPoint().getY(), xPos + 120, yPos + 18, 4210752); this.fontRendererObj.drawString("" + capabilities.getFirstPoint().getZ(), xPos + 160, yPos + 18, 4210752); } if(capabilities.getSecondPoint() != null) { this.fontRendererObj.drawString("" + capabilities.getSecondPoint().getX(), xPos + 80, yPos + 38, 4210752); this.fontRendererObj.drawString("" + capabilities.getSecondPoint().getY(), xPos + 120, yPos + 38, 4210752); this.fontRendererObj.drawString("" + capabilities.getSecondPoint().getZ(), xPos + 160, yPos + 38, 4210752); } } this.textField.drawTextBox(); this.addButton(this.button); super.drawScreen(mouseX, mouseY, partialTicks); } @Override protected void actionPerformed(GuiButton button) throws IOException { if(button == this.button) { System.out.println(this.textField.getText()); } } } And in eclipse this is displayed (assuming that i write the word text in the text box in the gui) [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text Why this happens? Thank you for your help
-
Ah, i didn't know that I'll add a check then to limit it to one hand. But what about the GUI? Why is the button code called many times instead of jsut one?
-
Ok, after doing some changes now it works and the value si displayed correctly. But now i'm having some troubles with the right click event and a GUI. First at all it looks like the right click event is fired twice This is the event code @SubscribeEvent public void onRightClick(PlayerInteractEvent.RightClickBlock event) { if(!event.getWorld().isRemote) { EntityPlayer player = event.getEntityPlayer(); IPlayerCapabilities capabilities = player.getCapability(PlayerCapabilitiesProvider.PLAYER_CAP, null); if(capabilities != null) { capabilities.removeMana(1); event.getEntityPlayer().addChatMessage(new TextComponentString(capabilities.getMana() + "")); RPG.NETWORK.sendTo(new PlayerCapabilitiesMessage(capabilities), (EntityPlayerMP) player); } } } This event should be fired only server side and will send a chat message to the player with the current amount of mana. But for some reason, if for example i have 100 mana, when i right click a block the player got 2 chat messages and the mana goes to 98, meaning that the code is called twice and i don't know why this happen For the GUI i have this GUI package com.rpg.gui; import java.io.IOException; import org.lwjgl.opengl.GL11; import com.rpg.RPG; import com.rpg.capabilities.player.IPlayerCapabilities; import com.rpg.capabilities.player.PlayerCapabilitiesProvider; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiMerchant; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.RenderHelper; import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.client.resources.I18n; import net.minecraft.entity.EntityLivingBase; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class GuiTalents extends GuiScreen { private static final ResourceLocation TALENTS = new ResourceLocation(RPG.MODID, "textures/gui/talents.png"); public GuiTalents() { } /** The old x position of the mouse pointer */ private float oldMouseX; /** The old y position of the mouse pointer */ private float oldMouseY; @Override public void drawScreen(int mouseX, int mouseY, float partialTicks) { GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glDisable(GL11.GL_LIGHTING); this.mc.getTextureManager().bindTexture(this.TALENTS); int xPos = width / 2 - 87; int yPos = height / 2 - 87; this.drawTexturedModalRect(xPos, yPos, 0, 0, 176, 185); this.oldMouseX = (float) mouseX; this.oldMouseY = (float) mouseY; IPlayerCapabilities capabilities = Minecraft.getMinecraft().thePlayer .getCapability(PlayerCapabilitiesProvider.PLAYER_CAP, null); if (capabilities != null) { drawEntityOnScreen(xPos + 31, yPos + 75, 30, (float) (xPos + 31) - this.oldMouseX, (float) (yPos + 75 - 50) - this.oldMouseY, this.mc.thePlayer); this.fontRendererObj.drawString(Minecraft.getMinecraft().thePlayer.getName(), xPos + 80, yPos + 10, 4210752); this.fontRendererObj.drawString(I18n.format("gui.talents.mana") + ": ", xPos + 80, yPos + 28, 4210752); this.fontRendererObj.drawString(I18n.format("gui.talents.level") + ": ", xPos + 80, yPos + 48, 4210752); this.fontRendererObj.drawString(I18n.format("gui.talents.class") + ": ", xPos + 80, yPos + 68, 4210752); this.fontRendererObj.drawString(I18n.format("gui.talents.vitality") + ": ", xPos + 30, yPos + 88, 4210752); this.fontRendererObj.drawString(I18n.format("gui.talents.strength") + ": ", xPos + 30, yPos + 108, 4210752); this.fontRendererObj.drawString(I18n.format("gui.talents.skill") + ": ", xPos + 30, yPos + 128, 4210752); this.fontRendererObj.drawString(I18n.format("gui.talents.speed") + ": ", xPos + 30, yPos + 148, 4210752); this.fontRendererObj.drawString(I18n.format("gui.talents.resistance") + ": ", xPos + 30, yPos + 168, 4210752); this.fontRendererObj.drawString(String.valueOf(capabilities.getMana() + "/100"), xPos + 116, yPos + 28, 4210752); this.fontRendererObj.drawString(String.valueOf(capabilities.getLevel() + "/30"), xPos + 116, yPos + 48, 4210752); this.fontRendererObj.drawString(String.valueOf("No Class"), xPos + 116, yPos + 68, 4210752); this.fontRendererObj.drawString(String.valueOf(capabilities.getVitality() + "/10"), xPos + 116, yPos + 88, 4210752); this.fontRendererObj.drawString(String.valueOf(capabilities.getStrength() + "/10"), xPos + 116, yPos + 108, 4210752); this.fontRendererObj.drawString(String.valueOf(capabilities.getSkill() + "/10"), xPos + 116, yPos + 128, 4210752); this.fontRendererObj.drawString(String.valueOf(capabilities.getSpeed() + "/10"), xPos + 116, yPos + 148, 4210752); this.fontRendererObj.drawString(String.valueOf(capabilities.getResistance() + "/10"), xPos + 116, yPos + 168, 4210752); int points = capabilities.getStrength() + capabilities.getVitality() + capabilities.getResistance() + capabilities.getSkill() + capabilities.getSpeed(); if (points <= capabilities.getLevel()) { this.buttonList.add(new UpgradeButton(1, xPos + 116 + 40, yPos + 88)); this.buttonList.add(new UpgradeButton(2, xPos + 116 + 40, yPos + 108)); this.buttonList.add(new UpgradeButton(3, xPos + 116 + 40, yPos + 128)); this.buttonList.add(new UpgradeButton(4, xPos + 116 + 40, yPos + 148)); this.buttonList.add(new UpgradeButton(5, xPos + 116 + 40, yPos + 168)); } } super.drawScreen(mouseX, mouseY, partialTicks); } @Override public boolean doesGuiPauseGame() { return false; } @Override protected void actionPerformed(GuiButton button) throws IOException { IPlayerCapabilities capabilities = Minecraft.getMinecraft().thePlayer .getCapability(PlayerCapabilitiesProvider.PLAYER_CAP, null); if (capabilities != null) { if (button.id == 1) { capabilities.addVitality(1); return; } } super.actionPerformed(button); } public static void drawEntityOnScreen(int posX, int posY, int scale, float mouseX, float mouseY, EntityLivingBase ent) { GlStateManager.enableColorMaterial(); GlStateManager.pushMatrix(); GlStateManager.translate((float) posX, (float) posY, 50.0F); GlStateManager.scale((float) (-scale), (float) scale, (float) scale); GlStateManager.rotate(180.0F, 0.0F, 0.0F, 1.0F); float f = ent.renderYawOffset; float f1 = ent.rotationYaw; float f2 = ent.rotationPitch; float f3 = ent.prevRotationYawHead; float f4 = ent.rotationYawHead; GlStateManager.rotate(135.0F, 0.0F, 1.0F, 0.0F); RenderHelper.enableStandardItemLighting(); GlStateManager.rotate(-135.0F, 0.0F, 1.0F, 0.0F); GlStateManager.rotate(-((float) Math.atan((double) (mouseY / 40.0F))) * 20.0F, 1.0F, 0.0F, 0.0F); ent.renderYawOffset = (float) Math.atan((double) (mouseX / 40.0F)) * 20.0F; ent.rotationYaw = (float) Math.atan((double) (mouseX / 40.0F)) * 40.0F; ent.rotationPitch = -((float) Math.atan((double) (mouseY / 40.0F))) * 20.0F; ent.rotationYawHead = ent.rotationYaw; ent.prevRotationYawHead = ent.rotationYaw; GlStateManager.translate(0.0F, 0.0F, 0.0F); RenderManager rendermanager = Minecraft.getMinecraft().getRenderManager(); rendermanager.setPlayerViewY(180.0F); rendermanager.setRenderShadow(false); rendermanager.doRenderEntity(ent, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F, false); rendermanager.setRenderShadow(true); ent.renderYawOffset = f; ent.rotationYaw = f1; ent.rotationPitch = f2; ent.prevRotationYawHead = f3; ent.rotationYawHead = f4; GlStateManager.popMatrix(); RenderHelper.disableStandardItemLighting(); GlStateManager.disableRescaleNormal(); GlStateManager.setActiveTexture(OpenGlHelper.lightmapTexUnit); GlStateManager.disableTexture2D(); GlStateManager.setActiveTexture(OpenGlHelper.defaultTexUnit); } @SideOnly(Side.CLIENT) static class UpgradeButton extends GuiButton { public UpgradeButton(int buttonID, int x, int y) { super(buttonID, x, y, 11, 7, ""); this.visible = true; this.enabled = true; } /** * Draws this button to the screen. */ public void drawButton(Minecraft mc, int mouseX, int mouseY) { mc.getTextureManager().bindTexture(GuiTalents.TALENTS); GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); this.hovered = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + 11 && mouseY < this.yPosition + 7; if (this.hovered) this.drawTexturedModalRect(this.xPosition, this.yPosition, 14, 194, 11, 7); else this.drawTexturedModalRect(this.xPosition, this.yPosition, 0, 194, 11, 7); } } } But when i click on a button the value is not incremented by 1 (instead goes from 12 to 45!) and also when i reload the world the value goes back to 0. Now i think this is because this modification is handled client side (in the GUI) but i don't know what should i send to the server (the same message that i send to the client?). Please help me understand why this happen, since it's the very first time i work with capabilities and networking in general
-
Woops, i've changed that so now the Tick Handler is registered in the common proxy and the Message Handler is only registered in the pre-init event, but i got the same issue. Also debugging i noticed that in the message, when i read the value, this return null, even if i specify a capability in the constructor of that message