use of org.bukkit.craftbukkit.v1_17_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_17_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();
}
use of org.bukkit.craftbukkit.v1_17_R1.entity.CraftHumanEntity in project Mohist by MohistMC.
the class CraftLootTable method convertContext.
private net.minecraft.world.level.storage.loot.LootContext convertContext(LootContext context, Random random) {
Location loc = context.getLocation();
ServerLevel handle = ((CraftWorld) loc.getWorld()).getHandle();
net.minecraft.world.level.storage.loot.LootContext.Builder builder = new net.minecraft.world.level.storage.loot.LootContext.Builder(handle);
if (random != null) {
builder = builder.withRandom(random);
}
setMaybe(builder, LootContextParams.ORIGIN, new Vec3(loc.getX(), loc.getY(), loc.getZ()));
if (getHandle() != LootTable.EMPTY) {
if (context.getLootedEntity() != null) {
Entity nmsLootedEntity = ((CraftEntity) context.getLootedEntity()).getHandle();
setMaybe(builder, LootContextParams.THIS_ENTITY, nmsLootedEntity);
setMaybe(builder, LootContextParams.DAMAGE_SOURCE, DamageSource.GENERIC);
setMaybe(builder, LootContextParams.ORIGIN, nmsLootedEntity.position());
}
if (context.getKiller() != null) {
net.minecraft.world.entity.player.Player nmsKiller = ((CraftHumanEntity) context.getKiller()).getHandle();
setMaybe(builder, LootContextParams.KILLER_ENTITY, nmsKiller);
// If there is a player killer, damage source should reflect that in case loot tables use that information
setMaybe(builder, LootContextParams.DAMAGE_SOURCE, DamageSource.playerAttack(nmsKiller));
// SPIGOT-5603 - Set minecraft:killed_by_player
setMaybe(builder, LootContextParams.LAST_DAMAGE_PLAYER, nmsKiller);
// SPIGOT-6925 - Set minecraft:match_tool
setMaybe(builder, LootContextParams.TOOL, nmsKiller.getUseItem());
}
// SPIGOT-5603 - Use LootContext#lootingModifier
if (context.getLootingModifier() != LootContext.DEFAULT_LOOT_MODIFIER) {
setMaybe(builder, LootContextParams.LOOTING_MOD, context.getLootingModifier());
}
}
// SPIGOT-5603 - Avoid IllegalArgumentException in LootContext#build()
LootContextParamSet.Builder nmsBuilder = new LootContextParamSet.Builder();
for (LootContextParam<?> param : getHandle().getParamSet().getRequired()) {
nmsBuilder.required(param);
}
for (LootContextParam<?> param : getHandle().getParamSet().getAllowed()) {
if (!getHandle().getParamSet().getRequired().contains(param)) {
nmsBuilder.optional(param);
}
}
nmsBuilder.optional(LootContextParams.LOOTING_MOD);
return builder.create(nmsBuilder.build());
}
Aggregations