Jump to content

Set Custom Entity's Collision Box {Unsolved}


ZetaHunter

Recommended Posts

Hello, I am having a problem with my entity's collision box, specificly it lets players go thru the entity, I dont want that.

I tried every possible way I saw in the vanilla minecraft logic... sadly couldnt get it to work.

Here is my code,

 

 

/**

*

*/

package com.zetaworx.tardis.block;

 

import java.util.Iterator;

 

import com.google.common.io.ByteArrayDataInput;

import com.google.common.io.ByteArrayDataOutput;

import com.zetaworx.tardis.lib.Vector3;

 

import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData;

 

import net.minecraft.block.Block;

import net.minecraft.entity.Entity;

import net.minecraft.entity.EntityLiving;

import net.minecraft.nbt.NBTTagCompound;

import net.minecraft.util.AxisAlignedBB;

import net.minecraft.util.DamageSource;

import net.minecraft.world.World;

 

/**

* @author ZetaHunter

*

*/

public class EntityTardis extends EntityLiving implements IEntityAdditionalSpawnData {

 

public String owner;

//public AxisAlignedBB boundingBox;

/**

* @param par1World

*/

public EntityTardis(World par1World) {

super(par1World);

this.height = 3;

this.width = 2;

}

 

    public AxisAlignedBB getCollisionBox(Entity par1Entity)

    {

        return par1Entity.boundingBox;

    }

 

public boolean attackEntityFrom(DamageSource par1DamageSource, int par2)

    {

        if (this.isEntityInvulnerable())

        {

            return false;

        }

        else

        {

        if (this.owner != null) {

        System.out.println(this.owner);

        }

            //this.setDead();

            return true;

        }

    }

 

// @Override

//    public AxisAlignedBB getBoundingBox()

//    {

//        return AxisAlignedBB.getBoundingBox(-1, 0, -1, 1, 2, 1);

//    }

 

@Override

    public boolean canBeCollidedWith()

    {

        return true;

    }

 

public EntityTardis(World w, double x, double y, double z, String owner) {

this(w);

this.owner = owner;

this.setPosition(x, y, z);

}

 

public void onUpdate() {

this.activePotionsMap.clear();

this.extinguish();

}

 

@Override

protected void entityInit() {

}

 

@Override

public void readEntityFromNBT(NBTTagCompound var1) {

super.readEntityFromNBT(var1);

this.owner = var1.getString("owner");

}

 

@Override

public void writeEntityToNBT(NBTTagCompound var1) {

super.writeEntityToNBT(var1);

var1.setString("owner", this.owner);

}

 

@Override

public void writeSpawnData(ByteArrayDataOutput data) {

data.writeUTF(this.owner);

}

 

@Override

public void readSpawnData(ByteArrayDataInput data) {

this.owner = data.readUTF();

}

 

//Some cruel fun part :3

public boolean nuke(World worldObj, Vector3 position, Entity explosionSource, int callCount)

{

if (!worldObj.isRemote)

{

if (callCount == 1)

{

for (int x = (int)-getRadius(); x < getRadius(); x++)

{

for (int y = (int)-getRadius(); y < getRadius(); y++)

{

for (int z = (int)-getRadius(); z < getRadius(); z++)

{

Vector3 targetPosition = Vector3.add(position, new Vector3(x, y, z));

double dist = position.distanceTo(targetPosition);

 

if (dist < getRadius())

{

int blockID = targetPosition.getBlockID(worldObj);

 

if (blockID > 0)

{

if ((blockID != Block.bedrock.blockID))

{

if ((dist < getRadius() + 5.0F))

{

targetPosition.setBlockWithNotify(worldObj, 0);

}

}

}

}

}

}

}

Iterator<?> entities = worldObj.getEntitiesWithinAABB(EntityLiving.class, AxisAlignedBB.getAABBPool().addOrModifyAABBInPool(

position.x - getRadius(), position.y - getRadius(), position.z - getRadius(), position.x + getRadius(), position.y + getRadius(), position.z + getRadius())).iterator();

while (entities.hasNext()) {

//System.out.println(entities.next().toString());

EntityLiving entity = (EntityLiving) entities.next();

entity.performHurtAnimation();

entity.attackEntityFrom(DamageSource.outOfWorld, 150);

}

return false;

}

 

}

 

if (callCount > getRadius())

{

return false;

}

 

return true;

}

 

public float getRadius()

{

return 10.0F;

}

 

@Override

public int getMaxHealth() {

return 1;

}

}

 

 

 

Currently everything but the collision box works perfectly so I dont see point posting any other source's.

But if needed I will.

 

Before I tried to make the block do what I planed, but it was causing even more trouble...

~I was here~

Link to comment
Share on other sites

Do you want to let your entity push / block the Player like in the old versions of Minecraft? If yes, you would have to edit the EntityPlayer class. You can do that directly and risk incompatibilities with many other mods (which is bad), or you make your mod as a coremod.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

There really isnt any other way to make the entity solid? :/

Cause I want it to be compatibly with everything...

 

Well, the only thing you could do is to make your mod as a core mod. But don't ask me how, since I never made such a mod before.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

Let me start this off with WRONG!

Do

@Override

public AxisAlignedBb getBoundingBox(){

return yourboundingbox;

}

 

Simple as that

Btw, do you know anyways to get entities to be less fidgety?

"you seem to be THE best modder I've seen imo."

~spynathan

 

ლ(́◉◞౪◟◉‵ლ

Link to comment
Share on other sites

Let me start this off with WRONG!

Do

@Override

public AxisAlignedBb getBoundingBox(){

return yourboundingbox;

}

 

Simple as that

Btw, do you know anyways to get entities to be less fidgety?

 

That is PARTIALLY right. You can add a collision box, yes, but that would only be recognized for the entity itself. Other entities ignore the Bounding Box. In order to achieve the idea the thread creator has, you have to add this method and return a Bounding Box to the EntityPlayer class (which must be done either with ASM (coremod) or base-edits)

 

WHOOPS, I looked at the wrong method (getCollisionBoundingBox). Yes, you're right, it works... I never used that method before. :D

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

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

    • Your drivers are in a broken state, follow the guide in the FAQ: https://forums.minecraftforge.net/topic/125488-rules-and-frequently-asked-questions-faq/#:~:text=How do I update my drivers%3F
    • A fatal error has been detected by the Java Runtime Environment: # # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007ffc3fe22b60, pid=15228, tid=5140 # # JRE version: OpenJDK Runtime Environment Microsoft-8035246 (17.0.8+7) (build 17.0.8+7-LTS) # Java VM: OpenJDK 64-Bit Server VM Microsoft-8035246 (17.0.8+7-LTS, mixed mode, tiered, compressed oops, compressed class ptrs, g1 gc, windows-amd64) # Problematic frame: # C [atio6axx.dll+0x192b60] # # No core dump will be written. Minidumps are not enabled by default on client versions of Windows # # If you would like to submit a bug report, please visit: # https://aka.ms/minecraftjavacrashes # The crash happened outside the Java Virtual Machine in native code. # See problematic frame for where to report the bug i have no idea why please help
    • Quick-Books is great with regards to coordinating your monetary data. You can decide to live talk with a specialist at Quick-Books to get the answer for your questions. You will actually want to get to the talk going to the landing page and call us +1855-210-1428.
    • Update: I managed to make the item not disappear after crafting, but it doesn't remove any durability. import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.enchantment.Enchantments; import net.minecraft.enchantment.UnbreakingEnchantment; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; public class NuggetHammer extends Item { private boolean damage; public NuggetHammer(Properties p_i48487_1_) { super(p_i48487_1_); } @Override public int getMaxDamage(ItemStack stack) { return 54 - 1; } public boolean isBarVisible(ItemStack stack) { return false; } @Override public ItemStack getContainerItem(ItemStack stack) { ItemStack copy = stack.copy(); copy.setCount(1); if (!this.damage) return copy; int unbreaking = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.UNBREAKING, stack); for (int i = 0; i < unbreaking; i++) { if (UnbreakingEnchantment.shouldIgnoreDurabilityDrop(stack, unbreaking, random)) return copy; } copy.setDamageValue(stack.getDamageValue() + 1); if (copy.getDamageValue() > stack.getMaxDamage()) return ItemStack.EMPTY; return copy; } }  
  • Topics

×
×
  • Create New...

Important Information

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