Java Code Examples for net.minecraft.entity.Entity#writeToNBT()

The following examples show how to use net.minecraft.entity.Entity#writeToNBT() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CauldronHooks.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public static boolean checkBoundingBoxSize(Entity entity, AxisAlignedBB aabb)
{
    if (entity instanceof EntityLivingBase && (!(entity instanceof IBossDisplayData) || !(entity instanceof IEntityMultiPart))
            && !(entity instanceof EntityPlayer))
    {
        int logSize = MinecraftServer.cauldronConfig.largeBoundingBoxLogSize.getValue();
        if (logSize <= 0 || !MinecraftServer.cauldronConfig.checkEntityBoundingBoxes.getValue()) return false;
        int x = MathHelper.floor_double(aabb.minX);
        int x1 = MathHelper.floor_double(aabb.maxX + 1.0D);
        int y = MathHelper.floor_double(aabb.minY);
        int y1 = MathHelper.floor_double(aabb.maxY + 1.0D);
        int z = MathHelper.floor_double(aabb.minZ);
        int z1 = MathHelper.floor_double(aabb.maxZ + 1.0D);

        int size = Math.abs(x1 - x) * Math.abs(y1 - y) * Math.abs(z1 - z);
        if (size > MinecraftServer.cauldronConfig.largeBoundingBoxLogSize.getValue())
        {
            logWarning("Entity being removed for bounding box restrictions");
            logWarning("BB Size: {0} > {1} avg edge: {2}", size, logSize, aabb.getAverageEdgeLength());
            logWarning("Motion: ({0}, {1}, {2})", entity.motionX, entity.motionY, entity.motionZ);
            logWarning("Calculated bounding box: {0}", aabb);
            logWarning("Entity bounding box: {0}", entity.getBoundingBox());
            logWarning("Entity: {0}", entity);
            NBTTagCompound tag = new NBTTagCompound();
            entity.writeToNBT(tag);
            logWarning("Entity NBT: {0}", tag);
            logStack();
            entity.setDead();
            return true;
        }
    }

    return false;
}
 
Example 2
Source File: EntityRocket.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
/**
 * Prepares this entity in new dimension by copying NBT data from entity in old dimension
 */
public void copyDataFromOld(Entity entityIn)
{
	NBTTagCompound nbttagcompound = entityIn.writeToNBT(new NBTTagCompound());
	nbttagcompound.removeTag("Dimension");
	nbttagcompound.removeTag("Passengers");
	this.readFromNBT(nbttagcompound);
	this.timeUntilPortal = entityIn.timeUntilPortal;
}
 
Example 3
Source File: EntityElevatorCapsule.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
public void copyDataFromOld(Entity entityIn)
{
	NBTTagCompound nbttagcompound = entityIn.writeToNBT(new NBTTagCompound());
	nbttagcompound.removeTag("Dimension");
	nbttagcompound.removeTag("Passengers");
	this.readFromNBT(nbttagcompound);
	this.timeUntilPortal = entityIn.timeUntilPortal;
}
 
Example 4
Source File: EntityHandler.java    From OmniOcular with Apache License 2.0 5 votes vote down vote up
@Override
public NBTTagCompound getNBTData(EntityPlayerMP player, Entity ent, NBTTagCompound tag, World world) {
    if (ent != null)
        ent.writeToNBT(tag);
    return tag;

}
 
Example 5
Source File: EntityRequestPacket.java    From NBTEdit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void handleServerSide(EntityPlayerMP player) {
	Entity e = player.worldObj.getEntityByID(entityID);
	if (e instanceof EntityPlayer && e != player) {
		sendMessageToPlayer(player, SECTION_SIGN + "cError - You may not use NBTEdit on other Players");
		NBTEdit.log(Level.WARNING, player.getCommandSenderName() +  " tried to use NBTEdit on another player, " + ((EntityPlayer)e).getCommandSenderName());
	}
	else if (e != null) {
		NBTTagCompound tag = new NBTTagCompound();
		e.writeToNBT(tag);
		NBTEdit.DISPATCHER.sendTo(new EntityNBTPacket(entityID, tag), player);
	}
	else
		sendMessageToPlayer(player, SECTION_SIGN + "cError - Unknown EntityID #" + entityID );
}
 
Example 6
Source File: BlockTeleportRail.java    From Signals with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Prepares this entity in new dimension by copying NBT data from entity in old dimension
 */
private static void copyDataFromOld(Entity newEntity, Entity entityIn){
    NBTTagCompound nbttagcompound = entityIn.writeToNBT(new NBTTagCompound());
    nbttagcompound.removeTag("Dimension");
    newEntity.readFromNBT(nbttagcompound);
}
 
Example 7
Source File: CauldronHooks.java    From Thermos with GNU General Public License v3.0 4 votes vote down vote up
public static boolean checkEntitySpeed(Entity entity, double x, double y, double z)
{
    int maxSpeed = MinecraftServer.cauldronConfig.entityMaxSpeed.getValue();
    if (maxSpeed > 0 && MinecraftServer.cauldronConfig.checkEntityMaxSpeeds.getValue())
    {
        double distance = x * x + z * z;
        if (distance > maxSpeed)
        {
            if (MinecraftServer.cauldronConfig.logEntitySpeedRemoval.getValue())
            {
                logInfo("Speed violation: {0} was over {1} - Removing Entity: {2}", distance, maxSpeed, entity);
                if (entity instanceof EntityLivingBase)
                {
                    EntityLivingBase livingBase = (EntityLivingBase)entity;
                    logInfo("Entity Motion: ({0}, {1}, {2}) Move Strafing: {3} Move Forward: {4}", entity.motionX, entity.motionY, entity.motionZ, livingBase.moveStrafing, livingBase.moveForward);
                }

                if (MinecraftServer.cauldronConfig.logWithStackTraces.getValue())
                {
                    logInfo("Move offset: ({0}, {1}, {2})", x, y, z);
                    logInfo("Motion: ({0}, {1}, {2})", entity.motionX, entity.motionY, entity.motionZ);
                    logInfo("Entity: {0}", entity);
                    NBTTagCompound tag = new NBTTagCompound();
                    entity.writeToNBT(tag);
                    logInfo("Entity NBT: {0}", tag);
                    logStack();
                }
            }
            if (entity instanceof EntityPlayer) // Skip killing players
            {
                entity.motionX = 0;
                entity.motionY = 0;
                entity.motionZ = 0;
                return false;
            }
            // Remove the entity;
            entity.isDead = true;
            return false;
        }
    }
    return true;
}