Search in sources :

Example 11 with CraftHumanEntity

use of org.bukkit.craftbukkit.v1_11_R1.entity.CraftHumanEntity in project Magma-1.16.x by magmafoundation.

the class CraftLootTable method convertContext.

private net.minecraft.loot.LootContext convertContext(LootContext context) {
    Location loc = context.getLocation();
    ServerWorld handle = ((CraftWorld) loc.getWorld()).getHandle();
    net.minecraft.loot.LootContext.Builder builder = new net.minecraft.loot.LootContext.Builder(handle);
    setMaybe(builder, LootParameters.ORIGIN, new Vector3d(loc.getX(), loc.getY(), loc.getZ()));
    if (getHandle() != LootTable.EMPTY) {
        if (context.getLootedEntity() != null) {
            Entity nmsLootedEntity = ((CraftEntity) context.getLootedEntity()).getHandle();
            setMaybe(builder, LootParameters.THIS_ENTITY, nmsLootedEntity);
            setMaybe(builder, LootParameters.DAMAGE_SOURCE, DamageSource.GENERIC);
            setMaybe(builder, LootParameters.POSITION, new BlockPos(nmsLootedEntity));
        }
        if (context.getKiller() != null) {
            PlayerEntity nmsKiller = ((CraftHumanEntity) context.getKiller()).getHandle();
            setMaybe(builder, LootParameters.KILLER_ENTITY, nmsKiller);
            // If there is a player killer, damage source should reflect that in case loot tables use that information
            setMaybe(builder, LootParameters.DAMAGE_SOURCE, DamageSource.playerAttack(nmsKiller));
            // SPIGOT-5603 - Set minecraft:killed_by_player
            setMaybe(builder, LootParameters.LAST_DAMAGE_PLAYER, nmsKiller);
        }
        // SPIGOT-5603 - Use LootContext#lootingModifier
        if (context.getLootingModifier() != LootContext.DEFAULT_LOOT_MODIFIER) {
            setMaybe(builder, LootParameters.LOOTING_MOD, context.getLootingModifier());
        }
    }
    // SPIGOT-5603 - Avoid IllegalArgumentException in LootTableInfo#build()
    // PAIL rename Builder
    LootParameterSet.Builder nmsBuilder = new LootParameterSet.Builder();
    for (LootParameter<?> param : getHandle().getParamSet().getAllowed()) {
        // PAIL rename required
        // PAIL rename addRequired
        nmsBuilder.required(param);
    }
    for (LootParameter<?> param : getHandle().getParamSet().getAllowed()) {
        // PAIL rename optional
        if (!getHandle().getParamSet().getAllowed().contains(param)) {
            // PAIL rename required
            // PAIL rename addOptional
            nmsBuilder.optional(param);
        }
    }
    nmsBuilder.optional(LootParameters.LOOTING_MOD);
    return builder.create(nmsBuilder.build());
}
Also used : Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) CraftHumanEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftHumanEntity) CraftEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity) LootContext(org.bukkit.loot.LootContext) CraftEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerWorld(net.minecraft.world.server.ServerWorld) Vector3d(net.minecraft.util.math.vector.Vector3d) LootParameterSet(net.minecraft.loot.LootParameterSet) CraftHumanEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftHumanEntity) BlockPos(net.minecraft.util.math.BlockPos) Location(org.bukkit.Location)

Example 12 with CraftHumanEntity

use of org.bukkit.craftbukkit.v1_11_R1.entity.CraftHumanEntity in project LoliServer by Loli-Server.

the class CraftLootTable method convertContext.

private net.minecraft.loot.LootContext convertContext(LootContext context) {
    Location loc = context.getLocation();
    ServerWorld handle = ((CraftWorld) loc.getWorld()).getHandle();
    net.minecraft.loot.LootContext.Builder builder = new net.minecraft.loot.LootContext.Builder(handle);
    setMaybe(builder, LootParameters.ORIGIN, new Vector3d(loc.getX(), loc.getY(), loc.getZ()));
    if (getHandle() != LootTable.EMPTY) {
        if (context.getLootedEntity() != null) {
            Entity nmsLootedEntity = ((CraftEntity) context.getLootedEntity()).getHandle();
            setMaybe(builder, LootParameters.THIS_ENTITY, nmsLootedEntity);
            setMaybe(builder, LootParameters.DAMAGE_SOURCE, DamageSource.GENERIC);
            setMaybe(builder, LootParameters.POSITION, new BlockPos(nmsLootedEntity));
        }
        if (context.getKiller() != null) {
            PlayerEntity nmsKiller = ((CraftHumanEntity) context.getKiller()).getHandle();
            setMaybe(builder, LootParameters.KILLER_ENTITY, nmsKiller);
            // If there is a player killer, damage source should reflect that in case loot tables use that information
            setMaybe(builder, LootParameters.DAMAGE_SOURCE, DamageSource.playerAttack(nmsKiller));
            // SPIGOT-5603 - Set minecraft:killed_by_player
            setMaybe(builder, LootParameters.LAST_DAMAGE_PLAYER, nmsKiller);
        }
        // SPIGOT-5603 - Use LootContext#lootingModifier
        if (context.getLootingModifier() != LootContext.DEFAULT_LOOT_MODIFIER) {
            setMaybe(builder, LootParameters.LOOTING_MOD, context.getLootingModifier());
        }
    }
    // SPIGOT-5603 - Avoid IllegalArgumentException in LootTableInfo#build()
    // PAIL rename Builder
    LootParameterSet.Builder nmsBuilder = new LootParameterSet.Builder();
    for (LootParameter<?> param : getHandle().getParamSet().getAllowed()) {
        // PAIL rename required
        // PAIL rename addRequired
        nmsBuilder.required(param);
    }
    for (LootParameter<?> param : getHandle().getParamSet().getAllowed()) {
        // PAIL rename optional
        if (!getHandle().getParamSet().getAllowed().contains(param)) {
            // PAIL rename required
            // PAIL rename addOptional
            nmsBuilder.optional(param);
        }
    }
    nmsBuilder.optional(LootParameters.LOOTING_MOD);
    return builder.create(nmsBuilder.build());
}
Also used : Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) CraftHumanEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftHumanEntity) CraftEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity) LootContext(org.bukkit.loot.LootContext) CraftEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerWorld(net.minecraft.world.server.ServerWorld) Vector3d(net.minecraft.util.math.vector.Vector3d) LootParameterSet(net.minecraft.loot.LootParameterSet) CraftHumanEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftHumanEntity) BlockPos(net.minecraft.util.math.BlockPos) Location(org.bukkit.Location)

Example 13 with CraftHumanEntity

use of org.bukkit.craftbukkit.v1_11_R1.entity.CraftHumanEntity in project LoliServer by Loli-Server.

the class CraftLootTable method convertContext.

public static LootContext convertContext(net.minecraft.loot.LootContext info) {
    Vector3d position = info.getParamOrNull(LootParameters.ORIGIN);
    if (position == null) {
        // Every vanilla context has origin or this_entity, see LootParameters
        position = info.getParamOrNull(LootParameters.THIS_ENTITY).position();
    }
    Location location = new Location(info.getLevel().getWorld(), position.x(), position.y(), position.z());
    LootContext.Builder contextBuilder = new LootContext.Builder(location);
    if (info.hasParam(LootParameters.KILLER_ENTITY)) {
        CraftEntity killer = info.getParamOrNull(LootParameters.KILLER_ENTITY).getBukkitEntity();
        if (killer instanceof CraftHumanEntity) {
            contextBuilder.killer((CraftHumanEntity) killer);
        }
    }
    if (info.hasParam(LootParameters.THIS_ENTITY)) {
        contextBuilder.lootedEntity(info.getParamOrNull(LootParameters.THIS_ENTITY).getBukkitEntity());
    }
    if (info.hasParam(LootParameters.LOOTING_MOD)) {
        contextBuilder.lootingModifier(info.getParamOrNull(LootParameters.LOOTING_MOD));
    }
    contextBuilder.luck(info.getLuck());
    return contextBuilder.build();
}
Also used : Vector3d(net.minecraft.util.math.vector.Vector3d) LootContext(org.bukkit.loot.LootContext) CraftHumanEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftHumanEntity) CraftEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity) Location(org.bukkit.Location)

Aggregations

Location (org.bukkit.Location)6 LootContext (org.bukkit.loot.LootContext)6 CraftHumanEntity (org.bukkit.craftbukkit.v1_16_R3.entity.CraftHumanEntity)5 Vector3d (net.minecraft.util.math.vector.Vector3d)4 CraftEntity (org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity)4 EntityHuman (net.minecraft.world.entity.player.EntityHuman)3 ItemStack (net.minecraft.world.item.ItemStack)3 CraftHumanEntity (org.bukkit.craftbukkit.v1_18_R2.entity.CraftHumanEntity)3 Entity (net.minecraft.entity.Entity)2 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 LootParameterSet (net.minecraft.loot.LootParameterSet)2 BlockPos (net.minecraft.util.math.BlockPos)2 Vec3 (net.minecraft.world.phys.Vec3)2 ServerWorld (net.minecraft.world.server.ServerWorld)2 CraftEntity (org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity)2 Iterator (java.util.Iterator)1 Map (java.util.Map)1 ServerLevel (net.minecraft.server.level.ServerLevel)1 Enchantment (net.minecraft.server.v1_11_R1.Enchantment)1 EntityHuman (net.minecraft.server.v1_11_R1.EntityHuman)1