Update to Minecraft 1.18-pre5

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot
2021-11-22 09:00:00 +11:00
parent a852b81a69
commit 43702a9e10
700 changed files with 10286 additions and 10098 deletions

View File

@@ -42,7 +42,7 @@ public class CraftLootTable implements org.bukkit.loot.LootTable {
@Override
public Collection<ItemStack> populateLoot(Random random, LootContext context) {
LootTableInfo nmsContext = convertContext(context);
List<net.minecraft.world.item.ItemStack> nmsItems = handle.populateLoot(nmsContext);
List<net.minecraft.world.item.ItemStack> nmsItems = handle.getRandomItems(nmsContext);
Collection<ItemStack> bukkit = new ArrayList<>(nmsItems.size());
for (net.minecraft.world.item.ItemStack item : nmsItems) {
@@ -62,7 +62,7 @@ public class CraftLootTable implements org.bukkit.loot.LootTable {
IInventory handle = craftInventory.getInventory();
// TODO: When events are added, call event here w/ custom reason?
getHandle().fillInventory(handle, nmsContext);
getHandle().fill(handle, nmsContext);
}
@Override
@@ -83,7 +83,7 @@ public class CraftLootTable implements org.bukkit.loot.LootTable {
Entity nmsLootedEntity = ((CraftEntity) context.getLootedEntity()).getHandle();
setMaybe(builder, LootContextParameters.THIS_ENTITY, nmsLootedEntity);
setMaybe(builder, LootContextParameters.DAMAGE_SOURCE, DamageSource.GENERIC);
setMaybe(builder, LootContextParameters.ORIGIN, nmsLootedEntity.getPositionVector());
setMaybe(builder, LootContextParameters.ORIGIN, nmsLootedEntity.position());
}
if (context.getKiller() != null) {
@@ -102,46 +102,46 @@ public class CraftLootTable implements org.bukkit.loot.LootTable {
// SPIGOT-5603 - Avoid IllegalArgumentException in LootTableInfo#build()
LootContextParameterSet.Builder nmsBuilder = new LootContextParameterSet.Builder();
for (LootContextParameter<?> param : getHandle().getLootContextParameterSet().getRequired()) {
nmsBuilder.addRequired(param);
for (LootContextParameter<?> param : getHandle().getParamSet().getRequired()) {
nmsBuilder.required(param);
}
for (LootContextParameter<?> param : getHandle().getLootContextParameterSet().getOptional()) {
if (!getHandle().getLootContextParameterSet().getRequired().contains(param)) {
nmsBuilder.addOptional(param);
for (LootContextParameter<?> param : getHandle().getParamSet().getAllowed()) {
if (!getHandle().getParamSet().getRequired().contains(param)) {
nmsBuilder.optional(param);
}
}
nmsBuilder.addOptional(LootContextParameters.LOOTING_MOD);
nmsBuilder.optional(LootContextParameters.LOOTING_MOD);
return builder.build(nmsBuilder.build());
return builder.create(nmsBuilder.build());
}
private <T> void setMaybe(LootTableInfo.Builder builder, LootContextParameter<T> param, T value) {
if (getHandle().getLootContextParameterSet().getRequired().contains(param) || getHandle().getLootContextParameterSet().getOptional().contains(param)) {
builder.set(param, value);
if (getHandle().getParamSet().getRequired().contains(param) || getHandle().getParamSet().getAllowed().contains(param)) {
builder.withParameter(param, value);
}
}
public static LootContext convertContext(LootTableInfo info) {
Vec3D position = info.getContextParameter(LootContextParameters.ORIGIN);
Vec3D position = info.getParamOrNull(LootContextParameters.ORIGIN);
if (position == null) {
position = info.getContextParameter(LootContextParameters.THIS_ENTITY).getPositionVector(); // Every vanilla context has origin or this_entity, see LootContextParameterSets
position = info.getParamOrNull(LootContextParameters.THIS_ENTITY).position(); // Every vanilla context has origin or this_entity, see LootContextParameterSets
}
Location location = new Location(info.getWorld().getWorld(), position.getX(), position.getY(), position.getZ());
Location location = new Location(info.getLevel().getWorld(), position.x(), position.y(), position.z());
LootContext.Builder contextBuilder = new LootContext.Builder(location);
if (info.hasContextParameter(LootContextParameters.KILLER_ENTITY)) {
CraftEntity killer = info.getContextParameter(LootContextParameters.KILLER_ENTITY).getBukkitEntity();
if (info.hasParam(LootContextParameters.KILLER_ENTITY)) {
CraftEntity killer = info.getParamOrNull(LootContextParameters.KILLER_ENTITY).getBukkitEntity();
if (killer instanceof CraftHumanEntity) {
contextBuilder.killer((CraftHumanEntity) killer);
}
}
if (info.hasContextParameter(LootContextParameters.THIS_ENTITY)) {
contextBuilder.lootedEntity(info.getContextParameter(LootContextParameters.THIS_ENTITY).getBukkitEntity());
if (info.hasParam(LootContextParameters.THIS_ENTITY)) {
contextBuilder.lootedEntity(info.getParamOrNull(LootContextParameters.THIS_ENTITY).getBukkitEntity());
}
if (info.hasContextParameter(LootContextParameters.LOOTING_MOD)) {
contextBuilder.lootingModifier(info.getContextParameter(LootContextParameters.LOOTING_MOD));
if (info.hasParam(LootContextParameters.LOOTING_MOD)) {
contextBuilder.lootingModifier(info.getParamOrNull(LootContextParameters.LOOTING_MOD));
}
contextBuilder.luck(info.getLuck());