Jump to content

Add boolean to entity


Gugu42

Recommended Posts

Hello !

I have a little problem.

 

I don't have any special code that makes me crash etc...

 

So, I want to make a rocket launcher that fire 9 rockets ( I have this already done )

 

The rockets are homing rockets, but since it fires 9 rockets, I don't want an entity to be targeted by more than 1 rocket, how could I do that ?

 

I tought about applying a boolean to the targeted entity, and in the rocket code, something that verify if the boolean is true before making the rocket targeting the entity.

 

How could I do ?

Link to comment
Share on other sites

Question:

 

What do you want to happen if there is only one entity in the area?  What do you want the other 8 rockets do?

 

As for the boolean: yes.

 

anEntity.entityData.setBoolean("targettedByRocket",true)

and

anEnttiy.entitytData.getBoolean("targettedByRocket")

 

And you'll want to set that value to false after the rocket deals damage or just before spawning any, depending on how multiple shots from your rocket launcher should work.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

To other rockets would have some random flying.

 

The weapon I'm trying to recreate is the RYNO from Ratchet & Clank.

 

Here's a video showing the weapon in the original game :

 

( It's only for the first minute, after that, it's the other versions of the weapon etc.. )

 

I'll try what you said

 

 

EDIT :

 

I tried, but since the entity all spawns at the same time, it looks bad, is there anyway to make the method wait for 1 tick between each entitySpawn ?

 

( Here's my right click method :

 

public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World,
		EntityPlayer par3EntityPlayer) {
	if (!par2World.isRemote) {

		EntityRYNOAmmo ent1 = new EntityRYNOAmmo(par2World,
				par3EntityPlayer);
		EntityRYNOAmmo ent2 = new EntityRYNOAmmo(par2World,
				par3EntityPlayer);
		EntityRYNOAmmo ent3 = new EntityRYNOAmmo(par2World,
				par3EntityPlayer);
		EntityRYNOAmmo ent4 = new EntityRYNOAmmo(par2World,
				par3EntityPlayer);
		EntityRYNOAmmo ent5 = new EntityRYNOAmmo(par2World,
				par3EntityPlayer);
		EntityRYNOAmmo ent6 = new EntityRYNOAmmo(par2World,
				par3EntityPlayer);
		EntityRYNOAmmo ent7 = new EntityRYNOAmmo(par2World,
				par3EntityPlayer);
		EntityRYNOAmmo ent8 = new EntityRYNOAmmo(par2World,
				par3EntityPlayer);
		EntityRYNOAmmo ent9 = new EntityRYNOAmmo(par2World,
				par3EntityPlayer);
		par2World.spawnEntityInWorld(ent1);
		par2World.spawnEntityInWorld(ent2);
		par2World.spawnEntityInWorld(ent3);

		par2World.spawnEntityInWorld(ent4);
		par2World.spawnEntityInWorld(ent5);
		par2World.spawnEntityInWorld(ent6);

		par2World.spawnEntityInWorld(ent7);
		par2World.spawnEntityInWorld(ent8);
		par2World.spawnEntityInWorld(ent9);

	}

	if (!par3EntityPlayer.capabilities.isCreativeMode) {
		if (maxAmmo - par1ItemStack.getItemDamage() > 0) {
			par1ItemStack.damageItem(1, par3EntityPlayer);
		}
	}

	return par1ItemStack;
}

Link to comment
Share on other sites

After you right click you would have to set a variable in the itemstack that would then be checked/modified by the updateTick function.

 

Take a look at how I handle it here:

https://github.com/Draco18s/Artifacts/blob/master/draco18s/artifacts/components/ComponentFireball.java (right click method)

https://github.com/Draco18s/Artifacts/blob/master/draco18s/artifacts/item/ItemArtifact.java (updateTick method)

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

And, what does your method do ?

 

Because, I can see your code, but I don't understand what it does ( Sending a packet ?)

 

EDIT : I have the rocket launching working, but when I fire, even if there are 9 entities, some rocket will just fly away while other might go like 3 on one entity.

 

Here's my entity code :

 

package com.gugu42.rcmod.entity;

import java.util.List;

import com.gugu42.rcmod.handler.ExtendedEntityLivingBaseTarget;

import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumMovingObjectType;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;

public class EntityRYNOAmmo extends EntityThrowable {
public boolean homing = true;
private int ticksAlive = 0;
protected EntityLiving target;

public EntityRYNOAmmo(World par1World) {
	super(par1World);
}

public EntityRYNOAmmo(World par1World, EntityPlayer par3EntityPlayer) {
	super(par1World, par3EntityPlayer);
}

protected void entityInit() {
}

protected float getGravityVelocity() {
	return 0.0F;
}

protected float func_70182_d() {
	return 1.2F;
}

protected float func_70183_g() {
	return -0.0F;
}

public void onUpdate() {
	super.onUpdate();
	this.ticksAlive += 1;
	if (this.ticksAlive >= 300) {
		setDead();
		this.ticksAlive = 0;
	}
	this.worldObj.spawnParticle("smoke", this.posX, this.posY, this.posZ,
			0.0D, 0.0D, 0.0D);

	if (this.homing) {
		if ((this.target == null) || (this.target.velocityChanged)
				|| (!this.target.canEntityBeSeen(this))) {
			this.target = getNearestEntity();
		}

		if (this.target != null) {

			double d = this.target.boundingBox.minX
					+ (this.target.boundingBox.maxX - this.target.boundingBox.minX)
					/ 2.0D - this.posX;
			double d1 = this.target.boundingBox.minY
					+ (this.target.boundingBox.maxY - this.target.boundingBox.minY)
					/ 2.0D - this.posY;
			double d2 = this.target.boundingBox.minZ
					+ (this.target.boundingBox.maxZ - this.target.boundingBox.minZ)
					/ 2.0D - this.posZ;
			setThrowableHeading(d, d1, d2, 0.9F, 0.0F);
		}

	}

	float f4 = 0.99F;
	float f6 = 0.05F;

	if (!this.homing) {
		this.motionX *= f4;
		this.motionY *= f4;
		this.motionZ *= f4;
		this.motionY -= f6;
	}
}

private EntityLiving getTarget(double d, double d1, double d2, double d3) {
	double d4 = -1.0D;
	EntityLiving entityliving = null;
	List list = this.worldObj.getEntitiesWithinAABBExcludingEntity(
			getThrower(), this.boundingBox.expand(16.0D, 16.0D, 16.0D));

	for (int i = 0; i < list.size(); i++) {
		EntityLiving entityliving1 = (EntityLiving) list.get(i);

		if (entityliving1 != getThrower()) {
			double d5 = entityliving1.getDistance(d, d1, d2);

			if (((d3 < 0.0D) || (d5 < d3 * d3))
					&& ((d4 == -1.0D) || (d5 < d4))
					&& (entityliving1.canEntityBeSeen(this))) {
				d4 = d5;
				entityliving = entityliving1;
			}
		}
	}

	return entityliving;
}

public boolean validTarget(EntityLiving entityliving) {
	if (entityliving.equals(getThrower())) {
		return false;
	}

	return true;
}

protected void onImpact(MovingObjectPosition movingobjectposition) {
	if (movingobjectposition.entityHit != null) {
		byte b0 = 20;
		movingobjectposition.entityHit.attackEntityFrom(
				DamageSource.causeThrownDamage(this, getThrower()), b0);
		movingobjectposition.entityHit.getEntityData().setBoolean("isTargetedByRYNO", false);
		if (!this.worldObj.isRemote) {
			setDead();
		}
	}

	for (int i = 0; i < 8; i++) {
		this.worldObj.spawnParticle("snowballpoof", this.posX, this.posY,
				this.posZ, 0.0D, 0.0D, 0.0D);
	}

	if (!this.worldObj.isRemote) {
		setDead();
	}

	if ((!this.isDead)
			&& (movingobjectposition.typeOfHit == EnumMovingObjectType.TILE)
			&& (!this.worldObj.isRemote))
		setDead();
}

private EntityLiving getNearestEntity() {
	EntityLiving target = null;
	float explosionSize = 5.0F;
	explosionSize *= 2.0F;
	int i = MathHelper.floor_double(this.posX - explosionSize - 1.0D);
	int j = MathHelper.floor_double(this.posX + explosionSize + 1.0D);
	int k = MathHelper.floor_double(this.posY - explosionSize - 1.0D);
	int l1 = MathHelper.floor_double(this.posY + explosionSize + 1.0D);
	int i2 = MathHelper.floor_double(this.posZ - explosionSize - 1.0D);
	int j2 = MathHelper.floor_double(this.posZ + explosionSize + 1.0D);

	if (!this.worldObj.isRemote) {
		List list = this.worldObj.getEntitiesWithinAABBExcludingEntity(
				getThrower(),
				AxisAlignedBB.getAABBPool().getAABB(i, k, i2, j, l1, j2));

		for (int k2 = 0; k2 < list.size(); k2++) {
			Entity entity = (Entity) list.get(k2);
			if (((entity instanceof EntityLiving))
					&& (((EntityLiving) entity).canEntityBeSeen(this))) {
				target = (EntityLiving) entity;
				if(!target.getEntityData().getBoolean("isTargetedByRYNO")){
					target.getEntityData().setBoolean("isTargetedByRYNO", true);
					return target;
				}
			}
		}
	}
	return target;
}
}

Link to comment
Share on other sites

Probably because getNearestEntity() can't return null.  If it fails to find a target that's not already targetted, it's going to return the last one it checked.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Yeah, but when there are like 15 entities, 4 rockets go away, ignoring the method, and the other 5 go on only one entity, and sometimes 2

 

You're going to need to use debug statements to figure out why.  I can't help you do that.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Turning the Tables: My Journey to Reclaim Stolen Bitcoins with Expert Help. When my Bitcoin wallet was hacked and my entire cryptocurrency portfolio was stolen, I felt utterly devastated and hopeless. Having worked hard to build up my digital assets, the sudden loss was gut-wrenching. It felt like my financial future had been ripped away in an instant, leaving me overwhelmed by a sense of betrayal and despair. In my search for help, I discovered TECH CYBER FORCE Recovery, a renowned cybersecurity firm specializing in cryptocurrency recovery. I was met with professionalism and empathy from my first contact with them. The team demonstrated a steadfast commitment to helping me retrieve my stolen Bitcoins. They understood the emotional toll of my situation and approached my case with genuine concern. TECH CYBER FORCE Recovery swung into action immediately, leveraging its extensive expertise in blockchain forensics and hacker tracking techniques. Their process was meticulous. They analyzed my transaction history, followed the digital trail left by the hackers, and worked diligently to pinpoint the location of the stolen funds. I was impressed by their technical prowess; they employed advanced cryptographic methods and strategic negotiations with the perpetrators, all while keeping me informed about their progress. The recovery process was complex and fraught with challenges. However, the tenacity displayed by the team was truly awe-inspiring. They navigated cryptocurrency crime's murky and ever-evolving landscape with skill and determination. After a series of strategic moves, they managed to recover the majority of my Bitcoins successfully.  
    • I removed giacomos_hud, oculus, (dont know what you mean with iris), enhanced_boss_bars, epicfight and essential.  Server still doesnt want to boot. new logs after removing: https://pastebin.com/LuM2PFtN I dont quite understand the "server side" and "client side" difference..
    • There are client side only mods in your server files   Remove giacomos_hud, oculus, iris, enhanced_boss_bars and epicfight You can keep these mods in your client Maybe also remove essentials
    • Here is my Log with java 17: https://pastebin.com/RPdWSjwq
    • Been working on creating a server for this mod, but i keep getting this error over and over again.  I have tried updating/changing the Forge launcher, Removing/replacing the ops.json and whitelist.json folders, and removing certain mods. Crash report log: https://pastebin.com/Bu046cVq Debug.log https://pastebin.com/7hKm40ke Latest.log https://pastebin.com/nCRLUH3b any help would be great thanks!
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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