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());
}
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());
}
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();
}
Aggregations