May 7, 201510 yr KeyBinding#unpressKey() is private, so you should use reflection to get reach to it. I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP) II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.
May 7, 201510 yr Author KeyBinding#unpressKey() is private, so you should use reflection to get reach to it. I will admit, I have never looked into reflection before and have no idea how to do it. So far what I have found about it, shows, but doesnt really explain really well.
May 7, 201510 yr You can also check KeyBinding#isPressed() to see if the key was pressed - this will decrement the pressed value (which should only have been at 1 since it was just pressed), then unset it with setKeyBindState as you were doing. Another thing to keep in mind is that the KeyInputEvent fires TWICE for each key press: once when the key is pressed (that's the one you want to intercept), and once again when it is released. Use Keyboard#getEventKeyState to check which state (press or release) the key is in. The trouble, I think, may be that KeyInputEvent, since it is not designed to be cancelable, fires too late to stop the client's action from sending a packet to the server, and when that packet is received, it no longer cares about the state of any client-side input. You may have to take some more drastic measures and attempt to intercept this packet, or just call it 'good enough' to expect most users to be using the LMB (mouse) to attack, and cancel the MouseEvent when appropriate. At least that way, you can move on to other things, then come back to this issue if users of your mod complain about it (very few people don't use the mouse, but they do exist...). http://i.imgur.com/NdrFdld.png[/img]
May 7, 201510 yr Author I do have it setup to run when the key is pressed and not released. EDIT: I set it up so that if someone is using a keyboard press to try to get rid of the block it will say "Please contact saxon564 if you are trying to put out a fire using a key on your keyboard as your attack key." This will help show me how many people actually use their keyboard. Now I just need to get the packet sending all figured out and get the mouse input to run on the server.
May 7, 201510 yr Now I just need to get the packet sending all figured out and get the mouse input to run on the server. Why do you need mouse input on the server? Or do you mean you need to send a packet to put out the flame? Not quite the same thing http://i.imgur.com/NdrFdld.png[/img]
May 7, 201510 yr Author I meant to send the packet, which with the wording I used would still technically be correct, but its all on interpretation there. EDIT: I have gotten everything working right with the mouse. You can see the final code here for the event handler and here for the packet management EDIT2: I have determined, the only way this would work all around would be using the PlayerInteractEvent, but I would have to translate it to a client event and send it as a packet to the client to cancel it. Just some final thoughts about it. Im probably just going to stick with what I already have for now.
May 7, 201510 yr Here's my code: package common.zeroquest.events; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.world.World; import net.minecraftforge.client.event.MouseEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent.PlayerTickEvent; import common.zeroquest.ModBlocks; public class InteractiveEvents { @SubscribeEvent public void onMouseEvent(MouseEvent event) { int button = event.button; EntityPlayer player = Minecraft.getMinecraft().thePlayer; World world = Minecraft.getMinecraft().theWorld; BlockPos pos = Minecraft.getMinecraft().objectMouseOver.getBlockPos(); EnumFacing face = Minecraft.getMinecraft().objectMouseOver.sideHit; if (button == 0) { if (world.getBlockState(pos).getBlock() != null) { this.extinguishFire(player, pos, face, world, event); } } } @SubscribeEvent public void onPlayerMovement(PlayerTickEvent event) { EntityPlayer player = event.player; BlockPos pos = player.getPosition(); World world = player.worldObj; Block block = world.getBlockState(pos).getBlock(); if (((block == ModBlocks.nileFire) || (world.getBlockState(pos.up()).getBlock() == ModBlocks.nileFire)) && (!player.capabilities.isCreativeMode)) { player.setFire(; } else if (((block == ModBlocks.darkFire) || (world.getBlockState(pos.up()).getBlock() == ModBlocks.darkFire)) && (!player.capabilities.isCreativeMode)) { player.setFire(; } } private void extinguishFire(EntityPlayer player, BlockPos pos, EnumFacing face, World world, MouseEvent event) { pos = pos.offset(face); int i = pos.getX(); int j = pos.getY(); int k = pos.getZ(); if (world.getBlockState(pos).getBlock() == ModBlocks.nileFire) { world.playSoundEffect((double)((float)i + 0.5F), (double)((float)j + 0.5F), (double)((float)k + 0.5F), "random.fizz", 0.5F, 2.6F + (world.rand.nextFloat() - world.rand.nextFloat()) * 0.8F); world.setBlockToAir(pos); event.setCanceled(true); } else if (world.getBlockState(pos).getBlock() == ModBlocks.darkFire) { world.playSoundEffect((double)((float)i + 0.5F), (double)((float)j + 0.5F), (double)((float)k + 0.5F), "random.fizz", 0.5F, 2.6F + (world.rand.nextFloat() - world.rand.nextFloat()) * 0.8F); world.setBlockToAir(pos); event.setCanceled(true); } } } Main Developer and Owner of Zero Quest Visit the Wiki for more information If I helped anyone, please give me a applaud and a thank you!
May 8, 201510 yr Author Everything you have there is only happening on the client that did the action. the server does not update the block. EDIT: You also need to check for pos to be null, because if you hit an entity, pos is null and it will crash.
May 8, 201510 yr How do I fix it were to make it not null? Main Developer and Owner of Zero Quest Visit the Wiki for more information If I helped anyone, please give me a applaud and a thank you!
May 8, 201510 yr My code now package common.zeroquest.events; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.world.World; import net.minecraftforge.client.event.MouseEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent.PlayerTickEvent; import common.zeroquest.ModBlocks; public class InteractiveEvents { @SubscribeEvent public void onMouseEvent(MouseEvent event) { int button = event.button; EntityPlayer player = Minecraft.getMinecraft().thePlayer; World world = Minecraft.getMinecraft().theWorld; BlockPos pos = Minecraft.getMinecraft().objectMouseOver.getBlockPos(); EnumFacing face = Minecraft.getMinecraft().objectMouseOver.sideHit; if (button == 0) { if (world.getBlockState(pos).getBlock() != null) { this.extinguishFire(player, pos, face, world, event); } } } @SubscribeEvent public void onPlayerMovement(PlayerTickEvent event) { EntityPlayer player = event.player; BlockPos pos = player.getPosition(); World world = player.worldObj; Block block = world.getBlockState(pos).getBlock(); if (pos != null) { if (((block == ModBlocks.nileFire) || (world.getBlockState(pos.up()).getBlock() == ModBlocks.nileFire)) && (!player.capabilities.isCreativeMode)) { player.setFire(; } else if (((block == ModBlocks.darkFire) || (world.getBlockState(pos.up()).getBlock() == ModBlocks.darkFire)) && (!player.capabilities.isCreativeMode)) { player.setFire(; } } } private void extinguishFire(EntityPlayer player, BlockPos pos, EnumFacing face, World world, MouseEvent event) { pos = pos.offset(face); int i = pos.getX(); int j = pos.getY(); int k = pos.getZ(); if (pos != null) { if (world.getBlockState(pos).getBlock() == ModBlocks.nileFire) { world.playSoundEffect(i + 0.5F, j + 0.5F, k + 0.5F, "random.fizz", 0.5F, 2.6F + (world.rand.nextFloat() - world.rand.nextFloat()) * 0.8F); world.setBlockToAir(pos); event.setCanceled(true); } else if (world.getBlockState(pos).getBlock() == ModBlocks.darkFire) { world.playSoundEffect(i + 0.5F, j + 0.5F, k + 0.5F, "random.fizz", 0.5F, 2.6F + (world.rand.nextFloat() - world.rand.nextFloat()) * 0.8F); world.setBlockToAir(pos); event.setCanceled(true); } } } } I'm still not hearing the fizz sfx when I extinguish the fire Main Developer and Owner of Zero Quest Visit the Wiki for more information If I helped anyone, please give me a applaud and a thank you!
May 8, 201510 yr Author For pos check it in the MouseEvent, thats where it has a possibility to be null, as for the fizz, you have to use packets to send the information to the server, on the server is when you play the fizz sound. You can look at my github for how I did it.
May 8, 201510 yr package common.zeroquest.events; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.world.World; import net.minecraftforge.client.event.MouseEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent.PlayerTickEvent; import common.zeroquest.ModBlocks; import common.zeroquest.network.PacketHandler; import common.zeroquest.network.imessage.FireSound; public class InteractiveEvents { @SubscribeEvent public void onMouseEvent(MouseEvent event) { int button = event.button; EntityPlayer player = Minecraft.getMinecraft().thePlayer; World world = Minecraft.getMinecraft().theWorld; BlockPos pos = Minecraft.getMinecraft().objectMouseOver.getBlockPos(); EnumFacing face = Minecraft.getMinecraft().objectMouseOver.sideHit; if (button == 0) { if (pos != null) { if (world.getBlockState(pos).getBlock() != null) { this.extinguishFire(player, pos, face, world, event); } } } } @SubscribeEvent public void onPlayerMovement(PlayerTickEvent event) { EntityPlayer player = event.player; BlockPos pos = player.getPosition(); World world = player.worldObj; Block block = world.getBlockState(pos).getBlock(); if (((block == ModBlocks.nileFire) || (world.getBlockState(pos.up()).getBlock() == ModBlocks.nileFire)) && (!player.capabilities.isCreativeMode)) { player.setFire(; } else if (((block == ModBlocks.darkFire) || (world.getBlockState(pos.up()).getBlock() == ModBlocks.darkFire)) && (!player.capabilities.isCreativeMode)) { player.setFire(; } } private void extinguishFire(EntityPlayer player, BlockPos pos, EnumFacing face, World world, MouseEvent event) { pos = pos.offset(face); int i = pos.getX(); int j = pos.getY(); int k = pos.getZ(); if (world.getBlockState(pos).getBlock() == ModBlocks.nileFire) { world.setBlockToAir(pos); event.setCanceled(true); PacketHandler.sendToServer(new FireSound()); } else if (world.getBlockState(pos).getBlock() == ModBlocks.darkFire) { world.setBlockToAir(pos); event.setCanceled(true); PacketHandler.sendToServer(new FireSound()); } } } package common.zeroquest.network.imessage; import io.netty.buffer.ByteBuf; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.world.World; import net.minecraftforge.fml.common.network.ByteBufUtils; 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 FireSound implements IMessage { private String text; private String player; private int face; public FireSound() {} public FireSound(EntityPlayer playerIn, EnumFacing faceIn) { player = playerIn.toString(); face = faceIn.getIndex(); } @Override public void fromBytes(ByteBuf buf) { player = ByteBufUtils.readUTF8String(buf); face = ByteBufUtils.readVarInt(buf, 5); } @Override public void toBytes(ByteBuf buf) { ByteBufUtils.writeUTF8String(buf, player); ByteBufUtils.writeVarInt(buf, face, 5); } public static class Handler implements IMessageHandler<FireSound, IMessage> { @Override public IMessage onMessage(FireSound message, MessageContext ctx) { EntityPlayer player = ctx.getServerHandler().playerEntity; World world = player.worldObj; System.out.println(String.format("Received %s from %s", message.text, ctx.getServerHandler().playerEntity.getDisplayName())); world.playSoundAtEntity(player, "random.fizz", player.getPosition().getX(), player.getPosition().getY()); return null; } } } Still not working Main Developer and Owner of Zero Quest Visit the Wiki for more information If I helped anyone, please give me a applaud and a thank you!
May 8, 201510 yr Oh also, I'm not getting set on fire when I step on the fire Main Developer and Owner of Zero Quest Visit the Wiki for more information If I helped anyone, please give me a applaud and a thank you!
May 8, 201510 yr Author take a look at my network proxy here: https://github.com/saxon564/MoChickens/blob/Dev/src/main/java/com/saxon564/mochickens/network/FireMessage.java and my event handler here: https://github.com/saxon564/MoChickens/blob/Dev/src/main/java/com/saxon564/mochickens/events/FireEventHandler.java You should cross check it with your code.
May 8, 201510 yr Thanks! that works on my client now.. but what about the server? Main Developer and Owner of Zero Quest Visit the Wiki for more information If I helped anyone, please give me a applaud and a thank you!
May 9, 201510 yr Author If you're setting the block to air on the server and playing the sound in your Packet class, as well as canceling the event in your event handler, you're done. That's all you need to do, it will work on both server and client.
May 9, 201510 yr Thanks! Main Developer and Owner of Zero Quest Visit the Wiki for more information If I helped anyone, please give me a applaud and a thank you!
May 9, 201510 yr Author meant to say, setting the block to air and playing the sound in your packet class. just to clarify where the server code gets run.
May 9, 201510 yr Hi. I saw this thread. In World.java on line 2430 Changing if (this.getBlockState(pos).getBlock() == Blocks.fire) >> if (this.getBlockState(pos).getBlock() instanceof net.minecraft.block.BlockFire) I think should be fix with another mod. And no conflict (Maybe. -.-)
May 9, 201510 yr Author Hi. I saw this thread. In World.java on line 2430 Changing if (this.getBlockState(pos).getBlock() == Blocks.fire) >> if (this.getBlockState(pos).getBlock() instanceof net.minecraft.block.BlockFire) I think should be fix with another mod. And no conflict (Maybe. -.-) That would be a simple solution, yes. But there is no reason you should ever edit a base class. If you find yourself trying to edit a base class to do something, then you need a core mod. If you dont know how to make a core mod, then you should just stop trying what you are doing and go learn how to, or ask if there is another way to accomplish it.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.