Jump to content

[1.8] [90% SOLVED] Cannot Interact With CustomFire E.G. Hit to Extinguish


Recommended Posts

Posted

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.

  • Replies 70
  • Created
  • Last Reply

Top Posters In This Topic

Posted

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.

Posted

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...).

Posted

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.

Posted

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.

Posted

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!

Posted

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.

Posted

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!

Posted

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.

Posted

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!

Posted

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.

Posted

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. -.-)

Posted

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements




  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • When I first heard about Bitcoin back in 2018, I was skeptical. The idea of a decentralized, digital currency seemed too good to be true. But I was intrigued as I learned more about the technology behind it and its potential. I started small, investing just a few hundred dollars, dipping my toes into the cryptocurrency waters. At first, it was exhilarating to watch the value of my investment grow exponentially. I felt like I was part of the future, an early adopter of this revolutionary new asset. But that euphoria was short-lived. One day, I logged into my digital wallet only to find it empty - my Bitcoin had vanished without a trace. It turned out that the online exchange I had trusted had been hacked, and my funds were stolen. I was devastated, both financially and emotionally. All the potential I had seen in Bitcoin was tainted by the harsh reality that with decentralization came a lack of regulation and oversight. My hard-earned money was gone, lost to the ether of the digital world. This experience taught me a painful lesson about the price of trust in the uncharted territory of cryptocurrency. While the technology holds incredible promise, the risks can be catastrophic if you don't approach it with extreme caution. My Bitcoin investment gamble had failed, and I was left to pick up the pieces, wiser but poorer for having placed my faith in the wrong hands. My sincere appreciation goes to MUYERN TRUST HACKER. You are my hero in recovering my lost funds. Send a direct m a i l ( muyerntrusted ( @ ) mail-me ( . )c o m ) or message on whats app : + 1 ( 4-4-0 ) ( 3 -3 -5 ) ( 0-2-0-5 )
    • You could try posting a log (if there is no log at all, it may be the launcher you are using, the FAQ may have info on how to enable the log) as described in the FAQ, however this will probably need to be reported to/remedied by the mod author.
    • So me and a couple of friends are playing with a shitpost mod pack and one of the mods in the pack is corail tombstone and for some reason there is a problem with it, where on death to fire the player will get kicked out of the server and the tombstone will not spawn basically deleting an entire inventory, it doesn't matter what type of fire it is, whether it's from vanilla fire/lava, or from modded fire like ice&fire/lycanites and it's common enough to where everyone on the server has experienced at least once or twice and it doesn't give any crash log. a solution to this would be much appreciated thank you!
    • It is 1.12.2 - I have no idea if there is a 1.12 pack
  • Topics

×
×
  • Create New...

Important Information

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