Java源码示例:net.minecraft.entity.item.EntityPainting

示例1
/**
 * Gets the range an entity should be 'tracked' by players and visible in
 * the client.
 *
 * @param entity
 * @param defaultRange Default range defined by Mojang
 * @return
 */
public static int getEntityTrackingRange(Entity entity, int defaultRange) {
    SpigotWorldConfig config = entity.world.spigotConfig;
    if (entity instanceof EntityPlayer) {
        return config.playerTrackingRange;
    } else if (entity.activationType == 1) {
        return config.monsterTrackingRange;
    } else if (entity instanceof EntityGhast) {
        if (config.monsterTrackingRange > config.monsterActivationRange) {
            return config.monsterTrackingRange;
        } else {
            return config.monsterActivationRange;
        }
    } else if (entity.activationType == 2) {
        return config.animalTrackingRange;
    } else if (entity instanceof EntityItemFrame || entity instanceof EntityPainting || entity instanceof EntityItem || entity instanceof EntityXPOrb) {
        return config.miscTrackingRange;
    } else {
        return config.otherTrackingRange;
    }
}
 
示例2
@Inject(method = "renderMob", cancellable = true, at = @At("HEAD"))
private static void injectPaintingSpawnerFix(MobSpawnerBaseLogic mobSpawnerLogic, double posX, double posY, double posZ, float partialTicks, CallbackInfo ci) {
    Entity entity = mobSpawnerLogic.func_180612_a(mobSpawnerLogic.getSpawnerWorld());

    if (entity == null || entity instanceof EntityPainting)
        ci.cancel();
}
 
示例3
@Inject(method = "renderMob", cancellable = true, at = @At("HEAD"))
private static void injectPaintingSpawnerFix(MobSpawnerBaseLogic mobSpawnerLogic, double posX, double posY, double posZ, float partialTicks, CallbackInfo ci) {
    Entity entity = mobSpawnerLogic.func_180612_a(mobSpawnerLogic.getSpawnerWorld());

    if (entity == null || entity instanceof EntityPainting)
        ci.cancel();
}
 
示例4
public boolean setArt(Art art, boolean force) {
    EntityPainting painting = this.getHandle();
    EnumArt oldArt = painting.art;
    painting.art = CraftArt.BukkitToNotch(art);
    painting.updateFacingWithBoundingBox(painting.facingDirection);
    if (!force && !painting.onValidSurface()) {
        // Revert painting since it doesn't fit
        painting.art = oldArt;
        painting.updateFacingWithBoundingBox(painting.facingDirection);
        return false;
    }
    this.update();
    return true;
}
 
示例5
private void update() {
    WorldServer world = ((CraftWorld) getWorld()).getHandle();
    EntityPainting painting = new EntityPainting(world);
    painting.hangingPosition = getHandle().getHangingPosition();
    painting.art = getHandle().art;
    painting.updateFacingWithBoundingBox(getHandle().facingDirection);
    getHandle().setDead();
    getHandle().velocityChanged = true; // because this occurs when the painting is broken, so it might be important
    world.spawnEntity(painting);
    this.entity = painting;
}
 
示例6
/**
 * Gets the range an entity should be 'tracked' by players and visible in
 * the client.
 *
 * @param entity
 * @param defaultRange Default range defined by Mojang
 * @return
 */
public static int getEntityTrackingRange(Entity entity, int defaultRange)
{
    SpigotWorldConfig config = entity.worldObj.getSpigotConfig(); // Cauldron
    int range = defaultRange;
    if ( entity instanceof EntityPlayerMP )
    {
        range = config.playerTrackingRange;
    } else if ( entity.defaultActivationState || entity instanceof EntityGhast )
    {
        range = defaultRange;
    } else if ( entity.activationType == 1 )
    {
        range = config.monsterTrackingRange;
    } else if ( entity.activationType == 2 )
    {
        range = config.animalTrackingRange;
    } else if ( entity instanceof EntityItemFrame || entity instanceof EntityPainting || entity instanceof EntityItem || entity instanceof EntityXPOrb )
    {
        range = config.miscTrackingRange;
    }
    // Cauldron start - allow for 0 to disable tracking ranges
    if (range == 0)
    {
        return defaultRange;
    }
    // Cauldron end

    return Math.min( config.maxTrackingRange, range );
}
 
示例7
@Override
public Object getMeta(EntityPainting target, Vec3 relativePos) {
	Map<String, Object> result = Maps.newHashMap();
	result.put("title", target.art.title);
	result.put("width", target.art.sizeX / 16);
	result.put("height", target.art.sizeY / 16);
	return result;
}
 
示例8
public CraftPainting(CraftServer server, EntityPainting entity) {
    super(server, entity);
}
 
示例9
@Override
public EntityPainting getHandle() {
    return (EntityPainting) entity;
}
 
示例10
/**
 * Called when a user uses the creative pick block button on this entity.
 *
 * @param target The full target the player is looking at
 * @return A ItemStack to add to the player's inventory, Null if nothing should be added.
 */
public ItemStack getPickedResult(MovingObjectPosition target)
{
    if (this instanceof EntityPainting)
    {
        return new ItemStack(Items.painting);
    }
    else if (this instanceof EntityLeashKnot)
    {
        return new ItemStack(Items.lead);
    }
    else if (this instanceof EntityItemFrame)
    {
        ItemStack held = ((EntityItemFrame)this).getDisplayedItem();
        if (held == null)
        {
            return new ItemStack(Items.item_frame);
        }
        else
        {
            return held.copy();
        }
    }
    else if (this instanceof EntityMinecart)
    {
        return ((EntityMinecart)this).getCartItem();
    }
    else if (this instanceof EntityBoat)
    {
        return new ItemStack(Items.boat);
    }
    else
    {
        int id = EntityList.getEntityID(this);
        if (id > 0 && EntityList.entityEggs.containsKey(id))
        {
            return new ItemStack(Items.spawn_egg, 1, id);
        }
    }
    return null;
}
 
示例11
public void addEntitiesToWorld(World world, BlockPos posStart)
{
    if (this.placement.getIgnoreEntities())
    {
        return;
    }

    Mirror mirror = this.placement.getMirror();
    Rotation rotation = this.placement.getRotation();

    BlockPos posEnd = posStart.add(PositionUtils.getRelativeEndPositionFromAreaSize(this.size));
    BlockPos pos1 = PositionUtils.getMinCorner(posStart, posEnd);
    BlockPos pos2 = PositionUtils.getMaxCorner(posStart, posEnd).add(1, 1, 1);
    List<Entity> existingEntities = world.getEntitiesWithinAABBExcludingEntity(null, new AxisAlignedBB(pos1, pos2));

    for (TemplateEnderUtilities.TemplateEntityInfo entityInfo : this.entities)
    {
        BlockPos pos = transformedBlockPos(this.placement, entityInfo.blockPos).add(posStart);

        NBTTagCompound nbt = entityInfo.entityData;
        UUID uuidOriginal = nbt.getUniqueId("UUID");
        Vec3d vec3d = PositionUtils.transformedVec3d(entityInfo.pos, mirror, rotation);
        Vec3d vec3d1 = vec3d.add((double)posStart.getX(), (double)posStart.getY(), (double)posStart.getZ());
        NBTTagList tagList = new NBTTagList();
        tagList.appendTag(new NBTTagDouble(vec3d1.x));
        tagList.appendTag(new NBTTagDouble(vec3d1.y));
        tagList.appendTag(new NBTTagDouble(vec3d1.z));
        nbt.setTag("Pos", tagList);
        nbt.setUniqueId("UUID", UUID.randomUUID());
        Entity entity;

        try
        {
            entity = EntityList.createEntityFromNBT(nbt, world);
        }
        catch (Exception e)
        {
            entity = null;
        }

        if (entity != null)
        {
            if (entity instanceof EntityPainting)
            {
                entity.getMirroredYaw(mirror);
                entity.getRotatedYaw(rotation);
                entity.setPosition(pos.getX(), pos.getY(), pos.getZ());
                entity.setLocationAndAngles(vec3d1.x, vec3d1.y, vec3d1.z, entity.rotationYaw, entity.rotationPitch);
            }
            else
            {
                float f = entity.getMirroredYaw(mirror);
                f = f + (entity.rotationYaw - entity.getRotatedYaw(rotation));
                entity.setLocationAndAngles(vec3d1.x, vec3d1.y, vec3d1.z, f, entity.rotationPitch);
                // FIXME should call updateFacingWithBoundingBox(EnumFacing) for EntityHanging, otherwise a world reload is needed
                // for ItemFrames for example to visually update to the correct facing
            }

            // Use the original UUID if possible. If there is an entity with the same UUID within the pasted area,
            // then the old one will be killed. Otherwise if there is no entity currently in the world with
            // the same UUID, then the original UUID will be used.
            Entity existing = EntityUtils.findEntityByUUID(existingEntities, uuidOriginal);
            if (existing != null)
            {
                world.removeEntityDangerously(existing);
                entity.setUniqueId(uuidOriginal);
            }
            else if (world instanceof WorldServer && ((WorldServer) world).getEntityFromUuid(uuidOriginal) == null)
            {
                entity.setUniqueId(uuidOriginal);
            }

            world.spawnEntity(entity);
        }
    }
}