Jump to content

Markk

Members
  • Posts

    16
  • Joined

  • Last visited

Everything posted by Markk

  1. Have almost the same issue, just more compiler errors. Was upgrading from 1.8.8 to 1.10.2. Log
  2. No problem, I appreciate your time. I'm not too great at using the debugger but I'll see if I can find anything.
  3. package com.mark.nbgui; import com.mark.nbgui.packet.Packet; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityNote; import net.minecraft.world.World; import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.event.world.NoteBlockEvent; import net.minecraftforge.fml.client.FMLClientHandler; import net.minecraftforge.fml.common.eventhandler.Event; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.InputEvent; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class EventHandlerCommon { /*@SubscribeEvent public void noteBlockChange(NoteBlockEvent.Change event) { event.setCanceled(true); //CHANGE EVENT }*/ /*@SubscribeEvent public void noteBlockPlay(NoteBlockEvent.Play event) { //PLAY OVERRIDDEN }*/ @SubscribeEvent @SideOnly(Side.CLIENT) public void onKeyInput(InputEvent.KeyInputEvent event) { Minecraft mc = Minecraft.getMinecraft(); if (KeyBindings.returnInput.isPressed() && FMLClientHandler.instance().getClient().inGameHasFocus) { } } @SubscribeEvent public void playerInteract(PlayerInteractEvent event) { if (event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) { World world = event.world; Block block = world.getBlockState(event.pos).getBlock(); if (block.equals(Blocks.noteblock)) { event.entityPlayer.openGui(NBGUI.instance, GUI.GUI_ID, world, event.pos.getX(), event.pos.getY(), event.pos.getZ()); event.useBlock = Event.Result.DENY; event.setCanceled(true); } } } } package com.mark.nbgui; import net.minecraft.block.Block; import net.minecraft.block.BlockNote; 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.init.Blocks; import net.minecraft.tileentity.TileEntityNote; import net.minecraft.util.BlockPos; import net.minecraft.world.World; import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.event.world.NoteBlockEvent; import net.minecraftforge.event.world.NoteBlockEvent.Octave; import net.minecraftforge.fml.common.eventhandler.Event; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.network.internal.FMLMessage; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import java.io.IOException; import org.lwjgl.input.Keyboard; import com.mark.nbgui.packet.Packet; public class GUI extends GuiScreen { public final static int GUI_ID = 20; private static String instrumentText = I18n.format("nbgui.string.gui.instrument", new Object[0])+" {instrument}"; private static String noteText = I18n.format("nbgui.string.gui.note", new Object[0])+" {note}"; private static String octaveText = I18n.format("nbgui.string.gui.octave", new Object[0])+" {octave}"; private int x; private int y; private int z; private TileEntityNote entityNote; private BlockNote blockNote; private Block underBlock; public static GuiTextField noteTextField; public static GuiTextField octaveTextField; public GUI(EntityPlayer player, World world, int x, int y, int z) { BlockPos pos = new BlockPos(x, y, z); this.x = x; this.y = y; this.z = z; //TODO Returns null, fix. //System.out.println("[DEBUG] GNote: "+entityNote); //System.out.println("[DEBUG] GBlock: "+blockNote); //System.out.println("[DEBUG] GUnder: "+underBlock); this.entityNote = (TileEntityNote) world.getTileEntity(pos); this.blockNote = (BlockNote) world.getBlockState(pos).getBlock(); this.underBlock = world.getBlockState(pos.down()).getBlock(); } @Override public void drawScreen(int x, int y, float f) { this.drawDefaultBackground(); super.drawScreen(x, y, f); this.noteTextField.drawTextBox(); this.octaveTextField.drawTextBox(); this.drawCenteredString(this.fontRendererObj, GUI.instrumentText.replace("{instrument}", NoteUtils.getInstrumentString(NoteUtils.getNoteBlockInstrument(this.underBlock))), this.width / 2, 30, 0xFFFFFFFF); //TODO Remove note and octave strings; redundant with text fields this.drawCenteredString(this.fontRendererObj, GUI.noteText.replace("{note}", NoteUtils.getNoteString(NoteUtils.getBlockNote(this.entityNote))), this.width / 2, 50, 0xFFFFFFFF); this.drawCenteredString(this.fontRendererObj, GUI.octaveText.replace("{octave}", NoteUtils.getOctaveString(NoteUtils.getBlockOctave(this.entityNote))), this.width / 2, 70, 0xFFFFFFFF); } @Override public void initGui() { Keyboard.enableRepeatEvents(false); //Play Button GuiButton playButton = new GuiButton(1, this.width / 2 - 30, 90, 60, 20, I18n.format("nbgui.button.playNote", new Object[0])); this.buttonList.add(playButton); //Note +1 Button GuiButton noteButtonAdd = new GuiButton(2, this.width / 2 - 60, 130, 20, 20, "+"); this.buttonList.add(noteButtonAdd); //Note -1 Button GuiButton noteButtonSub = new GuiButton(3, this.width / 2 + 40, 130, 20, 20, "-"); this.buttonList.add(noteButtonSub); //Octave +1 Button GuiButton octaveButtonAdd = new GuiButton(4, this.width / 2 - 60, 160, 20, 20, "+"); this.buttonList.add(octaveButtonAdd); //TODO Grey out button if octave == 5 && note.equals("F_SHARP") //Octave -1 Button GuiButton octaveButtonSub = new GuiButton(5, this.width / 2 + 40, 160, 20, 20, "-"); this.buttonList.add(octaveButtonSub); //TODO Grey out button if octave == 3 //Note Text Field this.noteTextField = new GuiTextField(2, fontRendererObj, this.width/2 - 30, 130, 60, 20); this.noteTextField.setFocused(false); this.noteTextField.setCanLoseFocus(true); this.noteTextField.setText(NoteUtils.getNoteString(NoteUtils.getBlockNote(this.entityNote))); this.noteTextField.setTextColor(-1); this.noteTextField.setDisabledTextColour(-1); this.noteTextField.setEnableBackgroundDrawing(true); this.noteTextField.setMaxStringLength(7); //Octave Text Field this.octaveTextField = new GuiTextField(3, fontRendererObj, this.width/2 - 30, 160, 60, 20); this.octaveTextField.setFocused(false); this.octaveTextField.setCanLoseFocus(true); this.octaveTextField.setText(NoteUtils.getOctaveString(NoteUtils.getBlockOctave(this.entityNote))); this.octaveTextField.setTextColor(-1); this.octaveTextField.setDisabledTextColour(-1); this.octaveTextField.setEnableBackgroundDrawing(true); this.octaveTextField.setMaxStringLength(1); //TODO Add option to merge note and octave text fields into one. } @Override public void keyTyped(char character, int keyCode) throws IOException { super.keyTyped(character, keyCode); if (keyCode == 28 && this.noteTextField.isFocused()) { System.out.println("[DEBUG] Character: "+character); System.out.println("[DEBUG] Code: "+keyCode); //TODO Send packets } else if (keyCode == 28 && this.octaveTextField.isFocused()) { System.out.println("[DEBUG] Character: "+character); System.out.println("[DEBUG] Code: "+keyCode); //TODO Send packets } } @Override public void mouseClicked(int x, int y, int clickedButon) throws IOException { super.mouseClicked(x, y, clickedButon); this.noteTextField.mouseClicked(x, y, clickedButon); this.octaveTextField.mouseClicked(x, y, clickedButon); if (this.noteTextField.isFocused()) { this.noteTextField.setText(""); } else if (this.octaveTextField.isFocused()) { this.octaveTextField.setText(""); } /*Debug System.out.println("[DEBUG] Note focused: "+noteTextField.isFocused()); System.out.println("[DEBUG] Octave focused: "+octaveTextField.isFocused()); System.out.println("[DEBUG]-------------------END-----------------------");*/ } @Override public void updateScreen() { this.noteTextField.updateCursorCounter(); this.octaveTextField.updateCursorCounter(); } @Override public void onGuiClosed() { Keyboard.enableRepeatEvents(false); super.onGuiClosed(); } @Override protected void actionPerformed(GuiButton button) throws IOException { switch (button.id) { case 1: //Play Packet playNote = new Packet(x, y, z); //playNote.setText("play"); NBGUI.network.sendToServer(playNote); break; case 2: //Note +1 break; case 3: //Note -1 break; case 4: //Octave +1 break; case 5: //Octave -1 break; } } @Override public boolean doesGuiPauseGame() { return false; } } package com.mark.nbgui; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockPos; import net.minecraft.world.World; import net.minecraftforge.fml.common.network.IGuiHandler; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public class GUIHandler implements IGuiHandler { @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { return null; } @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { if (ID == GUI.GUI_ID) { return new GUI(player, world, x, y, z); } return null; } } package com.mark.nbgui.packet; import io.netty.buffer.ByteBuf; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntityNote; import net.minecraft.world.World; import net.minecraftforge.fml.common.network.ByteBufUtils; import net.minecraftforge.fml.common.network.simpleimpl.IMessage; public class Packet implements IMessage { //protected NBTTagCompound compound; protected int x; protected int y; protected int z; public Packet() { //this.compound = new NBTTagCompound(); } public Packet(int x, int y, int z) { this.x = x; this.y = y; this.z = z; //this(); //entityNote.writeToNBT(this.compound); } /*public void setText(String text) { this.compound.setString("____NBGUIMsg", text); } public void setPitch(int pitch) { this.compound.setString("____NBGUIMsg", "PITCH_" + pitch); }*/ @Override public void fromBytes(ByteBuf buf) { //this.compound = ByteBufUtils.readTag(buf); x = buf.readInt(); y = buf.readInt(); z = buf.readInt(); } @Override public void toBytes(ByteBuf buf) { //ByteBufUtils.writeTag(buf, this.compound); buf.writeInt(x); buf.writeInt(y); buf.writeInt(z); } } package com.mark.nbgui.packet; import net.minecraft.client.Minecraft; import net.minecraft.server.MinecraftServer; import net.minecraft.tileentity.TileEntityNote; import net.minecraft.util.BlockPos; import net.minecraft.util.IThreadListener; import net.minecraft.world.World; import net.minecraft.world.WorldServer; import net.minecraftforge.fml.common.network.simpleimpl.IMessage; import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; public class PacketHandler implements IMessageHandler<Packet, Packet> { @Override public Packet onMessage(final Packet packet, final MessageContext ctx) { final IThreadListener mainThread = (WorldServer) ctx.getServerHandler().playerEntity.worldObj; mainThread.addScheduledTask(new Runnable() { @Override public void run() { World world = (World) mainThread; BlockPos pos = new BlockPos(packet.x, packet.y, packet.z); TileEntityNote noteBlock = (TileEntityNote) world.getTileEntity(pos); System.out.println("[DEBUG] PH World: "+world); System.out.println("[DEBUG] PH Pos: "+pos); noteBlock.triggerNote(world, pos); //DEBUG System.out.println("[DEBUG] PH getWorld: "+noteBlock.getWorld()); System.out.println("[DEBUG] PH getPos: "+noteBlock.getPos()); System.out.println("[DEBUG] PH note: "+noteBlock.note); } }); return null; } }
  4. I have this too right now, just excluded it: @SubscribeEvent public void noteBlockChange(NoteBlockEvent.Change event) { event.setCanceled(true); //CHANGE EVENT } That, along with setting useBlock to DENY just stops the default action of changing the pitch. If I allow the pitch to be changed while still opening the GUI, a similar thing happens (since the note is played upon tuning the block). If I also left click to play a note and then open the GUI, again, a similar thing happens: [embed=425,349]<iframe width="560" height="315" src="https://www.youtube.com/embed/mMUPkPS3hCY" frameborder="0" allowfullscreen></iframe>[/embed] Note that the GUI does not pause the game. And do I cancel the event with event.setCanceled(true); If so, it didn't help.
  5. Okay, cool, that's simpler than what I was trying to do. I think I did it correctly, but it the issue still occurs. Some of the GUI class:
  6. Okay. Again, how do I obtain the position of the block the GUI is open for then? If the field can not be static, that means that the actionPerformed method (which is in another class) can not use that, and conversely I cannot use the current method of obtaining the position from the same event as the one that opens the GUI. Thus, there needs to be an alternative.
  7. The point of the event handler is to open the GUI. I need to obtain the position of the TileEntity, and I do that by obtaining the position of the block in the same event that opens the GUI. How can I obtain the position directly from the actionPerformed method?
  8. Okay, I think I understand where I went wrong. I was getting the TE before sending it to the server. Instead, I am now getting the world and the coordinates from the event that opens the GUI and sending that info to the server. I get the tile entity in the packet handler. However, this didn't fix the issue. The point of the static field in the event handler is so that it can be used to send a packet in the actionPerformed method in the GUI class: IMessage: IMessageHandler:
  9. This video demonstrates the issue: [embed=425,349]<iframe width="560" height="315" src="https://www.youtube.com/embed/5FWh_9MUk9I" frameborder="0" allowfullscreen></iframe>[/embed] Event Handler: actionPerformed method in GUI class: IMessage: IMessageHandler:
  10. If you look carefully, you'll notice that it's being printed once from the client thread and once from the server thread. There is almost never a good reason to use the output of toString for anything but log/exception messages. In this case, you should compare block directly to the Note Block instance ( Blocks.noteblock ) using the equality ( == ) operator. If they're the equal (i.e. the same object), the block is a Note Block. Ah okay, I can't believe I didn't notice it was server and client outputs together. I thought the doubling had something to do with the note block tuning up twice in a laggy manner when I right click it. I don't know why that happens or if it will be in issue later (because I plan to remove the original right click functionality.)
  11. Okay, I've figured it out. However, for some reason, my my debug prints occur twice in the console: [22:26:35] [Client thread/INFO] [sTDOUT]: [com.mark.nbgui.EventHandlerCommon:openGUI:23]: POS: BlockPos{x=-256, y=64, z=119} [22:26:35] [Client thread/INFO] [sTDOUT]: [com.mark.nbgui.EventHandlerCommon:openGUI:24]: BLOCK: Block{minecraft:noteblock} Block{minecraft:noteblock} [22:26:35] [server thread/INFO]: Saving and pausing game... [22:26:35] [server thread/INFO]: Saving chunks for level 'New World'/Overworld [22:26:35] [server thread/INFO]: Saving chunks for level 'New World'/Nether [22:26:35] [server thread/INFO]: Saving chunks for level 'New World'/The End [22:26:35] [server thread/INFO] [sTDOUT]: [com.mark.nbgui.EventHandlerCommon:openGUI:23]: POS: BlockPos{x=-256, y=64, z=119} [22:26:35] [server thread/INFO] [sTDOUT]: [com.mark.nbgui.EventHandlerCommon:openGUI:24]: BLOCK: Block{minecraft:noteblock} Block{minecraft:noteblock} Here is my code: @SubscribeEvent public void openGUI(PlayerInteractEvent event) { if (event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK){ World world = event.world; Block block = world.getBlockState(event.pos).getBlock(); String blocktype = block.toString(); EntityPlayer player = event.entityPlayer; if (blocktype.equals("Block{minecraft:noteblock}")) { player.openGui(NBGUI.instance, GUI.GUI_ID, world, event.pos.getX(), event.pos.getY(), event.pos.getZ()); } //DEBUG System.out.println("POS: " +event.pos); System.out.println("BLOCK: " +block); System.out.print(blocktype); } } } Is this normal/something I can ignore, or is it a sign that something is wrong (presumably with my event handler)?
  12. Ah, no I did not put @SubscribeEvent. I also never made an event handler. I guess I should look that up now. Also, still not sure about openGui. Are the integers supposed to be the block position? I put in the event position (which I'm assuming is the position of the block rather than of the player when the event happens), but I get an error saying "Cannot make a static reference to the non-static method openGui(Object, int, World, int, int, int) from the type EntityPlayer." Edit: Do I make this event in the client or common event handler?
  13. I've figured out how to get the block, but now I need to figure out how to check if it's the right block. I don't know if getBlock returns an ID or a name and how it will be formatted, so I've made some prints to help me figure this out and just see if what I have so far works. However, when I right click any block, nothing is printed to the console. public void openGUI(PlayerInteractEvent event) { if (event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK){ World world = event.world; Block block = world.getBlockState(event.pos).getBlock(); //EntityPlayer.openGui(NBGUI.instance, GUI_ID, world, event.pos.getX(), event.pos.getY(), event.pos.getZ()); //DEBUG System.out.println("Position:" +event.pos); System.out.println("Block:" +block); } }
  14. So, something like this? public void openGUI(PlayerInteractEvent event) { if (event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK){ EntityPlayer.openGui(); } } I'm still not sure which arguments to put into openGui. Also, how do I specify which block the player has to interact with to trigger openGui?
  15. I want to modify the vanilla note block so that when a player right clicks it, a GUI opens (rather than tuning it.) However, I have not been successful. Main class with the initiation methods: Client and Common proxies are empty. GUI class: GUI Handler: Class that overrides onBlockActivated for the note block. I followed these two tutorials: http://www.minecraftforge.net/wiki/Basic_GUI http://jabelarminecraft.blogspot.com/p/minecraft-modding-block-with-simple-gui.html (the GUI class was copied from this tutorial.) http://jabelarminecraft.blogspot.com/p/minecraft-modding-containers.html (didn't copy any code, just read for information.) I first tried following the second tutorial fully, but the interface didn't open. I thought that since the note block is a block that extends BlockContainer, perhaps I need to make a GuiHandler and use openGui() instead to open the interface. This didn't work either. I think it may be because I haven't properly made an instance of the block in my main class. I attempted to with public static final BlockNote BlockNote = new BlockNote(); public static final NoteBlock NoteBlock = new NoteBlock(); , first for my own class and then also with the vanilla class. Also, if I used EntityPlayer.openGui rather than playerIn.openGui (I'm not even sure what the difference is), I would get an error saying that I can't make a static reference to a non-static method. Lastly, I had no idea what to put for the integer arguments, so I just put in 10. Where did I go wrong? How can I fix this? I'm new to Java and this is my first mod, so excuse any blatant faults with the code.
×
×
  • Create New...

Important Information

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