Jump to content

Explosion spawning based on the rotation?


Oscarita25

Recommended Posts

Well i try to spawn a explosion on the coardinates of the player.. that works pretty well with this:
 

player.world.createExplosion(player, player.getPosition().getX(), player.getPosition().getY() + 1, player.getPosition().getZ(), (float) (level * 0.1), true);


*i am spawning it with a keybind*
but that wont change if the player rotates ... what i want it to do .. i want it to be always spawned at the right side of the player inside of his right hand ..

Edited by Oscarita25
taking out useless stuff
Link to comment
Share on other sites

i got the packets working.. now everything or the explosions is server sided what is great.. but the explosion does not do damage...

serverPlayer.getServerWorld().createExplosion(serverPlayer, serverPlayer.lastTickPosX + serverPlayer.getLookVec().x , serverPlayer.lastTickPosY + 1, serverPlayer.lastTickPosZ + serverPlayer.getLookVec().z , (float) (amount), true);

is this the right way to do it? (this is in my packet handler class... the packet will send the amount of power that is being used)

Edited by Oscarita25
Link to comment
Share on other sites

9 hours ago, Oscarita25 said:

is this the right way to do it? (this is in my packet handler class... the packet will send the amount of power that is being used)

still not sure about that .. also my explosion still does no damage .... (it should do damage to the entities not the player)
 

Link to comment
Share on other sites

 

21 hours ago, Oscarita25 said:

serverPlayer.lastTickPosX

Why are you using lastTickPos insread of pos?

21 hours ago, Oscarita25 said:

is this the right way to do it? (this is in my packet handler class... the packet will send the amount of power that is being used)

As long as you pass your actions to a server thread this is the correct way to do this.

Show more of your code preferrably as a git repository so I can debug it myself.

Link to comment
Share on other sites

1 hour ago, V0idWa1k3r said:

Why are you using lastTickPos insread of pos?

oh  that was just me trying .. i should change that.. :P

1 hour ago, V0idWa1k3r said:

As long as you pass your actions to a server thread this is the correct way to do this.

Show more of your code preferrably as a git repository so I can debug it myself.

i think i am doing that ... :/
and i don't run a git on it right now :I .. but i can give you some more code :)

Here some more code:
Message Handler:

public class MyMessageHandler implements IMessageHandler<MessageExplosion, IMessage> {


	  @Override 
	  public IMessage onMessage(MessageExplosion message, MessageContext ctx) {

		EntityPlayerMP serverPlayer = ctx.getServerHandler().player;
	    
	    float amount = message.power;
	    serverPlayer.getServerWorld().addScheduledTask(() -> {
	      serverPlayer.getServerWorld().createExplosion(serverPlayer, serverPlayer.lastTickPosX + serverPlayer.getLookVec().x , serverPlayer.lastTickPosY + 1, serverPlayer.lastTickPosZ + serverPlayer.getLookVec().z , (float) (amount), true);
	      
	    });
	    return null;
	  }
	  
}

Message:

public class MessageExplosion implements IMessage {
	
	  public MessageExplosion() {}

	
	  public MessageExplosion(float power) {
	    this.power = power;

	  }
	  
	  float power;
	  EntityPlayer player;
	  
	  @Override public void toBytes(ByteBuf buf) {
	    buf.writeFloat(power);
	  }

	  @Override public void fromBytes(ByteBuf buf) {
	    power = buf.readFloat();
	  }
	  
	  public float getamount() {
		  return power;
	  }
}

Here is what class i am using to spawn the explosion

public class QuirkExplosive extends Quirk {
	
	private static EntityPlayer p;
	
	public QuirkExplosive() {
		super("explosive");
		setMaxCooldown(2000);
		setLevelMinimum(100);
		setLevelFactor(5);
		setMaxActivatedTime(1);
		setLevelUp(new LevelUp(0, 0.99));
		setXpPerTick(1/20);
	}

	@Override
	public void onPlayerUse(EntityPlayer player) {
		p = player;
		if(aviable) {
			BnHA.proxy.simpleNetworkWrapper.sendToServer(new MessageExplosion(level * 0.1F));
			aviable = false;
			xp += level * 2.75;
		}
	}

	@SubscribeEvent
	public static void tick(ServerTickEvent event) {
		if(!aviable) {
			cooldown++;
			if(cooldown >= maxCooldown) {
				aviable = true;
				cooldown = 0;
			}
		}
		if(xp >= nextXp) {
			level++;
			nextXp = xp * levelFactor;
			if(p != null) {
				p.sendMessage(new TextComponentString(TextFormatting.AQUA + "Level Up"));
				p.sendMessage(new TextComponentString(TextFormatting.AQUA + "Your now level " + level));
			}
			maxCooldown *= levelUp.getCooldownMultiplier();
		}
	}

	
}


@V0idWa1k3r if the superclass is relevant i can send it too

 

Link to comment
Share on other sites

6 minutes ago, Oscarita25 said:

(float) (amount)

You do not need to cast a float to a float.

6 minutes ago, Oscarita25 said:

BnHA.proxy.simpleNetworkWrapper

Why is your networkwrapper in your proxy? And this looks like a Code-style Issue #1 to me.

9 minutes ago, Oscarita25 said:

level * 0.1F

I think that your issue is here. Explosions with a very low power value will not damage entities.

Link to comment
Share on other sites

@V0idWa1k3r ... well i have overtaken the mod i am working on but i knew such thing as a "common" proxy should not exist aka. that what i were doing is wrong.. but just ignored that because it worked fine for now (right now i just want something running good XD) i will fix that in a second ..

3 minutes ago, V0idWa1k3r said:

I think that your issue is here. Explosions with a very low power value will not damage entities. 

i wasn't sure about that .. but this actually could it be XD.. i will now debug my code and write another reply .. if changing the power worked

Link to comment
Share on other sites

16 minutes ago, V0idWa1k3r said:

I think that your issue is here. Explosions with a very low power value will not damage entities.

yup .. that was it .. now just out of curiousity ... is there a way to turn off explosion damage and just do damage to entities?

Link to comment
Share on other sites

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.



×
×
  • Create New...

Important Information

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