Update to Minecraft 1.20.5

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot
2024-04-24 01:15:00 +10:00
parent 4deda9501f
commit 65bc2541a3
524 changed files with 7788 additions and 6181 deletions

View File

@@ -2,6 +2,7 @@ package org.bukkit.craftbukkit.structure;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.core.IRegistryCustom;
import net.minecraft.world.level.levelgen.structure.templatesystem.DefinedStructure;
import org.bukkit.block.BlockState;
import org.bukkit.craftbukkit.block.CraftBlockStates;
@@ -10,16 +11,18 @@ import org.bukkit.structure.Palette;
public class CraftPalette implements Palette {
private final DefinedStructure.a palette;
private final IRegistryCustom registry;
public CraftPalette(DefinedStructure.a palette) {
public CraftPalette(DefinedStructure.a palette, IRegistryCustom registry) {
this.palette = palette;
this.registry = registry;
}
@Override
public List<BlockState> getBlocks() {
List<BlockState> blocks = new ArrayList<>();
for (DefinedStructure.BlockInfo blockInfo : palette.blocks()) {
blocks.add(CraftBlockStates.getBlockState(blockInfo.pos(), blockInfo.state(), blockInfo.nbt()));
blocks.add(CraftBlockStates.getBlockState(registry, blockInfo.pos(), blockInfo.state(), blockInfo.nbt()));
}
return blocks;
}

View File

@@ -8,6 +8,7 @@ import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;
import net.minecraft.core.BlockPosition;
import net.minecraft.core.IRegistryCustom;
import net.minecraft.util.RandomSource;
import net.minecraft.world.entity.EntityTypes;
import net.minecraft.world.level.ChunkCoordIntPair;
@@ -42,9 +43,11 @@ import org.bukkit.util.EntityTransformer;
public class CraftStructure implements Structure {
private final DefinedStructure structure;
private final IRegistryCustom registry;
public CraftStructure(DefinedStructure structure) {
public CraftStructure(DefinedStructure structure, IRegistryCustom registry) {
this.structure = structure;
this.registry = registry;
}
@Override
@@ -145,7 +148,7 @@ public class CraftStructure implements Structure {
@Override
public List<Palette> getPalettes() {
return structure.palettes.stream().map(CraftPalette::new).collect(Collectors.toList());
return structure.palettes.stream().map((palette) -> new CraftPalette(palette, registry)).collect(Collectors.toList());
}
@Override

View File

@@ -13,6 +13,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import net.minecraft.core.IRegistryCustom;
import net.minecraft.nbt.NBTCompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.resources.MinecraftKey;
@@ -26,16 +27,18 @@ import org.bukkit.structure.StructureManager;
public class CraftStructureManager implements StructureManager {
private final StructureTemplateManager structureManager;
private final IRegistryCustom registry;
public CraftStructureManager(StructureTemplateManager structureManager) {
public CraftStructureManager(StructureTemplateManager structureManager, IRegistryCustom registry) {
this.structureManager = structureManager;
this.registry = registry;
}
@Override
public Map<NamespacedKey, Structure> getStructures() {
Map<NamespacedKey, Structure> cachedStructures = new HashMap<>();
for (Map.Entry<MinecraftKey, Optional<DefinedStructure>> entry : structureManager.structureRepository.entrySet()) {
entry.getValue().ifPresent(definedStructure -> cachedStructures.put(CraftNamespacedKey.fromMinecraft(entry.getKey()), new CraftStructure(definedStructure)));
entry.getValue().ifPresent(definedStructure -> cachedStructures.put(CraftNamespacedKey.fromMinecraft(entry.getKey()), new CraftStructure(definedStructure, registry)));
}
return Collections.unmodifiableMap(cachedStructures);
}
@@ -48,7 +51,7 @@ public class CraftStructureManager implements StructureManager {
if (definedStructure == null) {
return null;
}
return definedStructure.map(CraftStructure::new).orElse(null);
return definedStructure.map((s) -> new CraftStructure(s, registry)).orElse(null);
}
@Override
@@ -64,7 +67,7 @@ public class CraftStructureManager implements StructureManager {
structureManager.structureRepository.put(minecraftKey, structure);
}
return structure.map(CraftStructure::new).orElse(null);
return structure.map((s) -> new CraftStructure(s, registry)).orElse(null);
}
@Override
@@ -97,7 +100,7 @@ public class CraftStructureManager implements StructureManager {
final Optional<DefinedStructure> optionalDefinedStructure = Optional.of(((CraftStructure) structure).getHandle());
final Optional<DefinedStructure> previousStructure = structureManager.structureRepository.put(minecraftKey, optionalDefinedStructure);
return previousStructure == null ? null : previousStructure.map(CraftStructure::new).orElse(null);
return previousStructure == null ? null : previousStructure.map((s) -> new CraftStructure(s, registry)).orElse(null);
}
@Override
@@ -106,7 +109,7 @@ public class CraftStructureManager implements StructureManager {
MinecraftKey minecraftKey = createAndValidateMinecraftStructureKey(structureKey);
final Optional<DefinedStructure> previousStructure = structureManager.structureRepository.remove(minecraftKey);
return previousStructure == null ? null : previousStructure.map(CraftStructure::new).orElse(null);
return previousStructure == null ? null : previousStructure.map((s) -> new CraftStructure(s, registry)).orElse(null);
}
@Override
@@ -143,7 +146,7 @@ public class CraftStructureManager implements StructureManager {
public Structure loadStructure(InputStream inputStream) throws IOException {
Preconditions.checkArgument(inputStream != null, "inputStream cannot be null");
return new CraftStructure(structureManager.readStructure(inputStream));
return new CraftStructure(structureManager.readStructure(inputStream), registry);
}
@Override
@@ -166,7 +169,7 @@ public class CraftStructureManager implements StructureManager {
@Override
public Structure createStructure() {
return new CraftStructure(new DefinedStructure());
return new CraftStructure(new DefinedStructure(), registry);
}
private MinecraftKey createAndValidateMinecraftStructureKey(NamespacedKey structureKey) {
@@ -180,6 +183,6 @@ public class CraftStructureManager implements StructureManager {
@Override
public Structure copy(Structure structure) {
Preconditions.checkArgument(structure != null, "Structure cannot be null");
return new CraftStructure(structureManager.readStructure(((CraftStructure) structure).getHandle().save(new NBTTagCompound())));
return new CraftStructure(structureManager.readStructure(((CraftStructure) structure).getHandle().save(new NBTTagCompound())), registry);
}
}