Jump to content

[1.7.10]How do I make a block suck in entities?


roket333

Recommended Posts

I have recently been trying to make a black hole but I cannot find code for it ANYWHERE! I tried " double radius = 5;

        List<EntityItem> items = world.getEntitiesWithinAABB(EntityItem.class, ep.boundingBox.expand(32, 32, 32)); //The area to pull items from (change 32 to any number)

        for(EntityItem it : items){

            double distX = ep.posX - it.posX; //Move those items!

            double distZ = ep.posZ - it.posZ;

            double distY = it.posY+1.5D - ep.posY;

            double dir = Math.atan2(distZ, distX);

            double speed = 1F / it.getDistanceToEntity(ep) * 15; //Adjust the speed here (change 15)

 

            if (distY<0)

            {

                it.motionY += speed;

            }

 

            it.motionX = Math.cos(dir) * speed;

            it.motionZ = Math.sin(dir) * speed;

        }

}"

but that just gives me a ton of errors saying it cant find distx,y and z.

I really need some help! any kind is appreciated.

Link to comment
Share on other sites

do you think you could supply me with the code for the sucking entities and killing them thing? I would really appreciate it! If you want, I could give you a link to a custom model of Sonic the Hedgehog and Tails, all ready to be animated and put in-game in return of the code.

Link to comment
Share on other sites

do you think you could supply me with the code for the sucking entities and killing them thing? I would really appreciate it! If you want, I could give you a link to a custom model of Sonic the Hedgehog and Tails, all ready to be animated and put in-game in return of the code.

Not how it really works around here, would be nice, but if that was the case not many would learn.

 

You can post the class in

[code] {/code]

 

Seems like you have a rough idea on how to do this, just some error troubles.

Link to comment
Share on other sites

  • 1 year later...

from my experience it is wise to avoid using sin/cos at all costs if possible as they are heavy on processing, you might wanna read up some on linear algebra to help you aswell

I know this post is over a year old but to be honest, I tried to take that from the Vacuum Hopper in Open Blocks. I feel kind stupid but I really need this code for a Black Hole. I have all the textures ready as well as the custom model.

 

Also, someone PLEASE supply me with the code. Of course, I'll give proper credit too.

Link to comment
Share on other sites

I have tried to create a blackhole myself some time ago. Even though the code i used to "suck" entities inside it worked i never got it's rendering to work properly. I can supply you with the code of my blackhole but you have to work through the rendering process yourself.

 

Code:

 

public class blackHoleTE extends TileEntity implements IUpdatePlayerListBox{

private int Mass;

@Override
public void update() {

	List<Entity> EntitiesAround = this.worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.fromBounds
			(this.getPos().getX() - 10 - Mass / 10, this.getPos().getY() - 10 - Mass / 10, this.getPos().getZ() - 10 - Mass / 10,
			this.getPos().getX() + 10 + Mass / 10 + 1, this.getPos().getY() + 10 + Mass / 10 + 1, this.getPos().getZ() + 10 + Mass / 10 + 1));

	for(Entity e : EntitiesAround){
		double motionX = this.getPos().getX() - (e.posX + 0.5);
		double motionY = this.getPos().getY() - (e.posY + 0.5);
		double motionZ = this.getPos().getZ() - (e.posZ + 0.5);

		e.motionX = motionX * 0.1F;
		e.motionY = motionY * 0.1F;
		e.motionZ = motionZ * 0.1F;

	}

	List<Entity> ToClose = this.worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.fromBounds
			(this.getPos().getX() - 1 , this.getPos().getY() - 1 , this.getPos().getZ() - 1,
			this.getPos().getX() + 2, this.getPos().getY() + 2, this.getPos().getZ() + 2));

	for(Entity e : ToClose){
		if(e instanceof EntityItem){
			Mass++;
			e.attackEntityFrom(DamageSource.cactus, 7.5F);
		}else{
			e.attackEntityFrom(DamageSource.cactus, 7.5F);
		}
	}

	if(Mass >= 500){
		if(!worldObj.isRemote){
		worldObj.destroyBlock(this.pos, false);
		worldObj.createExplosion(null, this.getPos().getX(), this.getPos().getY(),
				this.getPos().getZ(), 100F, true);
		}
	}
}

@Override
public void writeToNBT(NBTTagCompound compound) {
	compound.setInteger("Mass", Mass);
	super.writeToNBT(compound);
}

@Override
public void readFromNBT(NBTTagCompound compound) {
	compound.getInteger("Mass");
	super.readFromNBT(compound);
}

}

 

 

My blackhole is made so it adds an explosion after it takes up to much entities inside it. Remove the parts of code that do that.

Link to comment
Share on other sites

Alert: supplied code is 1.8ish.  1.7.10 does not require IUpdatePlayerListBox and all

pos

and

Blockpos

objects should be some variant of

x

,

posx

, or

xCoord

.

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

How do xp orbs get drawn toward a player? Even if the movement is calculated by each orb itself, you should see useful examples of vector math and entity search there that you can adapt to your tile entity.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

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.