mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-06-26 09:34:27 +00:00
* Add a BiomeCategories API (#2338) * Add a BiomeCategories API * licenses * Use a supplier to retain the lazy-load & dynamicness of the existing system, but still retaining the inversion of control that this PR was intended to provide * Minor fawe adapter cleanup * Actually add the new files? * Fixes --------- Co-authored-by: Maddy Miller <mnmiller1@me.com>
This commit is contained in:
@ -57,6 +57,7 @@ import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
|
||||
import com.sk89q.worldedit.util.io.file.SafeFiles;
|
||||
import com.sk89q.worldedit.world.DataFixer;
|
||||
import com.sk89q.worldedit.world.RegenOptions;
|
||||
import com.sk89q.worldedit.world.biome.BiomeCategory;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.biome.BiomeTypes;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
@ -67,6 +68,9 @@ import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import com.sk89q.worldedit.world.item.ItemType;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.HolderSet;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundEntityEventPacket;
|
||||
@ -292,6 +296,14 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
|
||||
return DedicatedServer.getServer().registryAccess().registryOrThrow(Registries.ITEM).get(ResourceLocation.tryParse(itemType.id()));
|
||||
}
|
||||
|
||||
public BiomeType adapt(Biome biome) {
|
||||
var mcBiome = ((CraftServer) Bukkit.getServer()).getServer().registryAccess().registryOrThrow(Registries.BIOME).getKey(biome);
|
||||
if (mcBiome == null) {
|
||||
return null;
|
||||
}
|
||||
return BiomeType.REGISTRY.get(mcBiome.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public OptionalInt getInternalBlockStateId(BlockData data) {
|
||||
net.minecraft.world.level.block.state.BlockState state = ((CraftBlockData) data).getState();
|
||||
@ -806,6 +818,34 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeRegistries() {
|
||||
DedicatedServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||
// Biomes
|
||||
for (ResourceLocation name : server.registryAccess().registryOrThrow(Registries.BIOME).keySet()) {
|
||||
if (BiomeType.REGISTRY.get(name.toString()) == null) {
|
||||
BiomeType.REGISTRY.register(name.toString(), new BiomeType(name.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
// BiomeCategories
|
||||
Registry<Biome> biomeRegistry = server.registryAccess().registryOrThrow(Registries.BIOME);
|
||||
biomeRegistry.getTagNames().forEach(tagKey -> {
|
||||
String key = tagKey.location().toString();
|
||||
if (BiomeCategory.REGISTRY.get(key) == null) {
|
||||
BiomeCategory.REGISTRY.register(key, new BiomeCategory(
|
||||
key,
|
||||
() -> biomeRegistry.getTag(tagKey)
|
||||
.stream()
|
||||
.flatMap(HolderSet.Named::stream)
|
||||
.map(Holder::value)
|
||||
.map(this::adapt)
|
||||
.collect(Collectors.toSet()))
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Code that is less likely to break
|
||||
// ------------------------------------------------------------------------
|
||||
|
@ -154,6 +154,12 @@ public class PaperweightWorldNativeAccess implements WorldNativeAccess<LevelChun
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateBlock(BlockPos pos, net.minecraft.world.level.block.state.BlockState oldState, net.minecraft.world.level.block.state.BlockState newState) {
|
||||
ServerLevel world = getWorld();
|
||||
newState.onPlace(world, pos, oldState, false);
|
||||
}
|
||||
|
||||
// Not sure why neighborChanged is deprecated
|
||||
@SuppressWarnings("deprecation")
|
||||
private void fireNeighborChanged(BlockPos pos, ServerLevel world, Block block, BlockPos neighborPos) {
|
||||
|
@ -217,6 +217,12 @@ public class PaperweightFaweWorldNativeAccess implements WorldNativeAccess<Level
|
||||
newState.updateIndirectNeighbourShapes(level, blockPos, NOTIFY, recursionLimit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateBlock(BlockPos pos, net.minecraft.world.level.block.state.BlockState oldState, net.minecraft.world.level.block.state.BlockState newState) {
|
||||
Level world = getLevel();
|
||||
newState.onPlace(world, pos, oldState, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockStateChange(
|
||||
BlockPos blockPos,
|
||||
|
Reference in New Issue
Block a user