Skip to content

Commit d268f84

Browse files
committed
QoL and minor bug fixes
1 parent 49e3c08 commit d268f84

File tree

18 files changed

+479
-35
lines changed

18 files changed

+479
-35
lines changed

worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/FaweBlockStateListPopulator.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import net.minecraft.core.Holder;
66
import net.minecraft.server.MinecraftServer;
77
import net.minecraft.server.level.ServerLevel;
8+
import net.minecraft.util.RandomSource;
9+
import net.minecraft.world.DifficultyInstance;
810
import net.minecraft.world.entity.Entity;
911
import net.minecraft.world.flag.FeatureFlagSet;
1012
import net.minecraft.world.level.biome.Biome;
@@ -19,6 +21,8 @@
1921
import org.bukkit.craftbukkit.v1_20_R2.util.BlockStateListPopulator;
2022
import org.jetbrains.annotations.Nullable;
2123

24+
import javax.annotation.Nonnull;
25+
2226
public class FaweBlockStateListPopulator extends BlockStateListPopulator {
2327

2428
private final ServerLevel world;
@@ -34,31 +38,47 @@ public long getSeed() {
3438
}
3539

3640
@Override
41+
@Nonnull
3742
public ServerLevel getLevel() {
3843
return world.getLevel();
3944
}
4045

46+
@Override
47+
@Nonnull
48+
public DifficultyInstance getCurrentDifficultyAt(final BlockPos pos) {
49+
return world.getCurrentDifficultyAt(pos);
50+
}
51+
4152
@Override
4253
public MinecraftServer getServer() {
4354
return world.getServer();
4455
}
4556

4657
@Override
58+
@Nonnull
4759
public ChunkSource getChunkSource() {
4860
return world.getChunkSource();
4961
}
5062

63+
@Override
64+
@Nonnull
65+
public RandomSource getRandom() {
66+
return world.getRandom();
67+
}
68+
5169
@Override
5270
public ChunkAccess getChunk(final int chunkX, final int chunkZ, final ChunkStatus leastStatus, final boolean create) {
5371
return world.getChunk(chunkX, chunkZ, leastStatus, create);
5472
}
5573

5674
@Override
75+
@Nonnull
5776
public BiomeManager getBiomeManager() {
5877
return world.getBiomeManager();
5978
}
6079

6180
@Override
81+
@Nonnull
6282
public Holder<Biome> getUncachedNoiseBiome(final int biomeX, final int biomeY, final int biomeZ) {
6383
return world.getUncachedNoiseBiome(biomeX, biomeY, biomeZ);
6484
}
@@ -69,6 +89,7 @@ public int getSeaLevel() {
6989
}
7090

7191
@Override
92+
@Nonnull
7293
public FeatureFlagSet enabledFeatures() {
7394
return world.enabledFeatures();
7495
}
@@ -79,6 +100,7 @@ public float getShade(final Direction direction, final boolean shaded) {
79100
}
80101

81102
@Override
103+
@Nonnull
82104
public LevelLightEngine getLightEngine() {
83105
return world.getLightEngine();
84106
}
@@ -100,6 +122,7 @@ public FluidState getFluidIfLoaded(final BlockPos blockposition) {
100122
}
101123

102124
@Override
125+
@Nonnull
103126
public WorldBorder getWorldBorder() {
104127
return world.getWorldBorder();
105128
}
@@ -120,6 +143,7 @@ public boolean destroyBlock(final BlockPos pos, final boolean drop, final Entity
120143
}
121144

122145
@Override
146+
@Nonnull
123147
public BlockState getBlockState(final BlockPos pos) {
124148
return world.getBlockState(pos);
125149
}

worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightFaweAdapter.java

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,15 @@
5959
import net.minecraft.core.WritableRegistry;
6060
import net.minecraft.core.registries.BuiltInRegistries;
6161
import net.minecraft.core.registries.Registries;
62+
import net.minecraft.data.worldgen.features.AquaticFeatures;
63+
import net.minecraft.data.worldgen.features.CaveFeatures;
64+
import net.minecraft.data.worldgen.features.EndFeatures;
65+
import net.minecraft.data.worldgen.features.NetherFeatures;
66+
import net.minecraft.data.worldgen.features.PileFeatures;
67+
import net.minecraft.data.worldgen.features.TreeFeatures;
68+
import net.minecraft.data.worldgen.features.VegetationFeatures;
6269
import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket;
70+
import net.minecraft.resources.ResourceKey;
6371
import net.minecraft.resources.ResourceLocation;
6472
import net.minecraft.server.MinecraftServer;
6573
import net.minecraft.server.dedicated.DedicatedServer;
@@ -106,7 +114,10 @@
106114
import java.lang.reflect.Field;
107115
import java.lang.reflect.InvocationTargetException;
108116
import java.lang.reflect.Method;
117+
import java.lang.reflect.Modifier;
118+
import java.lang.reflect.ParameterizedType;
109119
import java.util.ArrayList;
120+
import java.util.Arrays;
110121
import java.util.Collection;
111122
import java.util.Collections;
112123
import java.util.HashMap;
@@ -706,10 +717,46 @@ private boolean placeFeatureIntoSession(
706717
public void setupFeatures() {
707718
DedicatedServer server = ((CraftServer) Bukkit.getServer()).getServer();
708719

720+
// All these features should be the "face" selected
721+
Set<String> face_features = Arrays
722+
.stream(new Class[]{AquaticFeatures.class, PileFeatures.class, TreeFeatures.class, VegetationFeatures.class})
723+
.flatMap(c -> Arrays.stream(c.getFields()))
724+
.filter(f -> {
725+
int modifiers = f.getModifiers();
726+
return Modifier.isPublic(modifiers) && Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers);
727+
})
728+
.filter(f -> f.getType().equals(ResourceKey.class))
729+
.map(f -> {
730+
try {
731+
Object val = f.get(null);
732+
return val;
733+
} catch (IllegalAccessException e) {
734+
LOGGER.error(e);
735+
return null;
736+
}
737+
})
738+
.filter(Objects::nonNull)
739+
.map(o -> (ResourceKey) o)
740+
.map(k -> k.location().toString())
741+
.collect(Collectors.toCollection(java.util.HashSet::new));
742+
face_features.add(CaveFeatures.DRIPSTONE_CLUSTER.location().toString());
743+
face_features.add(CaveFeatures.LARGE_DRIPSTONE.location().toString());
744+
face_features.add(CaveFeatures.POINTED_DRIPSTONE.location().toString());
745+
face_features.add(CaveFeatures.GLOW_LICHEN.location().toString());
746+
face_features.add(CaveFeatures.CAVE_VINE.location().toString());
747+
face_features.add(CaveFeatures.CAVE_VINE_IN_MOSS.location().toString());
748+
face_features.add(CaveFeatures.MOSS_VEGETATION.location().toString());
749+
face_features.add(CaveFeatures.DRIPLEAF.location().toString());
750+
face_features.add(EndFeatures.CHORUS_PLANT.location().toString());
751+
face_features.add(NetherFeatures.SMALL_BASALT_COLUMNS.location().toString());
752+
face_features.add(NetherFeatures.LARGE_BASALT_COLUMNS.location().toString());
753+
face_features.add(NetherFeatures.GLOWSTONE_EXTRA.location().toString());
754+
709755
// Features
710756
for (ResourceLocation name : server.registryAccess().registryOrThrow(Registries.CONFIGURED_FEATURE).keySet()) {
711-
if (ConfiguredFeatureType.REGISTRY.get(name.toString()) == null) {
712-
ConfiguredFeatureType.REGISTRY.register(name.toString(), new ConfiguredFeatureType(name.toString()));
757+
String id = name.toString();
758+
if (ConfiguredFeatureType.REGISTRY.get(id) == null) {
759+
ConfiguredFeatureType.REGISTRY.register(id, new ConfiguredFeatureType(id, face_features.contains(id)));
713760
}
714761
}
715762

worldedit-bukkit/adapters/adapter-1_20_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R3/FaweBlockStateListPopulator.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import net.minecraft.core.Holder;
66
import net.minecraft.server.MinecraftServer;
77
import net.minecraft.server.level.ServerLevel;
8+
import net.minecraft.util.RandomSource;
9+
import net.minecraft.world.DifficultyInstance;
810
import net.minecraft.world.entity.Entity;
911
import net.minecraft.world.flag.FeatureFlagSet;
1012
import net.minecraft.world.level.biome.Biome;
@@ -19,6 +21,8 @@
1921
import org.bukkit.craftbukkit.v1_20_R3.util.BlockStateListPopulator;
2022
import org.jetbrains.annotations.Nullable;
2123

24+
import javax.annotation.Nonnull;
25+
2226
public class FaweBlockStateListPopulator extends BlockStateListPopulator {
2327

2428
private final ServerLevel world;
@@ -34,31 +38,47 @@ public long getSeed() {
3438
}
3539

3640
@Override
41+
@Nonnull
3742
public ServerLevel getLevel() {
3843
return world.getLevel();
3944
}
4045

46+
@Override
47+
@Nonnull
48+
public DifficultyInstance getCurrentDifficultyAt(final BlockPos pos) {
49+
return world.getCurrentDifficultyAt(pos);
50+
}
51+
4152
@Override
4253
public MinecraftServer getServer() {
4354
return world.getServer();
4455
}
4556

4657
@Override
58+
@Nonnull
4759
public ChunkSource getChunkSource() {
4860
return world.getChunkSource();
4961
}
5062

63+
@Override
64+
@Nonnull
65+
public RandomSource getRandom() {
66+
return world.getRandom();
67+
}
68+
5169
@Override
5270
public ChunkAccess getChunk(final int chunkX, final int chunkZ, final ChunkStatus leastStatus, final boolean create) {
5371
return world.getChunk(chunkX, chunkZ, leastStatus, create);
5472
}
5573

5674
@Override
75+
@Nonnull
5776
public BiomeManager getBiomeManager() {
5877
return world.getBiomeManager();
5978
}
6079

6180
@Override
81+
@Nonnull
6282
public Holder<Biome> getUncachedNoiseBiome(final int biomeX, final int biomeY, final int biomeZ) {
6383
return world.getUncachedNoiseBiome(biomeX, biomeY, biomeZ);
6484
}
@@ -69,6 +89,7 @@ public int getSeaLevel() {
6989
}
7090

7191
@Override
92+
@Nonnull
7293
public FeatureFlagSet enabledFeatures() {
7394
return world.enabledFeatures();
7495
}
@@ -79,6 +100,7 @@ public float getShade(final Direction direction, final boolean shaded) {
79100
}
80101

81102
@Override
103+
@Nonnull
82104
public LevelLightEngine getLightEngine() {
83105
return world.getLightEngine();
84106
}
@@ -100,6 +122,7 @@ public FluidState getFluidIfLoaded(final BlockPos blockposition) {
100122
}
101123

102124
@Override
125+
@Nonnull
103126
public WorldBorder getWorldBorder() {
104127
return world.getWorldBorder();
105128
}
@@ -120,6 +143,7 @@ public boolean destroyBlock(final BlockPos pos, final boolean drop, final Entity
120143
}
121144

122145
@Override
146+
@Nonnull
123147
public BlockState getBlockState(final BlockPos pos) {
124148
return world.getBlockState(pos);
125149
}

worldedit-bukkit/adapters/adapter-1_20_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R3/PaperweightFaweAdapter.java

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,15 @@
5858
import net.minecraft.core.WritableRegistry;
5959
import net.minecraft.core.registries.BuiltInRegistries;
6060
import net.minecraft.core.registries.Registries;
61+
import net.minecraft.data.worldgen.features.AquaticFeatures;
62+
import net.minecraft.data.worldgen.features.CaveFeatures;
63+
import net.minecraft.data.worldgen.features.EndFeatures;
64+
import net.minecraft.data.worldgen.features.NetherFeatures;
65+
import net.minecraft.data.worldgen.features.PileFeatures;
66+
import net.minecraft.data.worldgen.features.TreeFeatures;
67+
import net.minecraft.data.worldgen.features.VegetationFeatures;
6168
import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket;
69+
import net.minecraft.resources.ResourceKey;
6270
import net.minecraft.resources.ResourceLocation;
6371
import net.minecraft.server.MinecraftServer;
6472
import net.minecraft.server.dedicated.DedicatedServer;
@@ -105,7 +113,10 @@
105113
import java.lang.reflect.Field;
106114
import java.lang.reflect.InvocationTargetException;
107115
import java.lang.reflect.Method;
116+
import java.lang.reflect.Modifier;
117+
import java.lang.reflect.ParameterizedType;
108118
import java.util.ArrayList;
119+
import java.util.Arrays;
109120
import java.util.Collection;
110121
import java.util.Collections;
111122
import java.util.HashMap;
@@ -705,10 +716,46 @@ private boolean placeFeatureIntoSession(
705716
public void setupFeatures() {
706717
DedicatedServer server = ((CraftServer) Bukkit.getServer()).getServer();
707718

719+
// All these features should be the "face" selected
720+
Set<String> face_features = Arrays
721+
.stream(new Class[]{AquaticFeatures.class, PileFeatures.class, TreeFeatures.class, VegetationFeatures.class})
722+
.flatMap(c -> Arrays.stream(c.getFields()))
723+
.filter(f -> {
724+
int modifiers = f.getModifiers();
725+
return Modifier.isPublic(modifiers) && Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers);
726+
})
727+
.filter(f -> f.getType().equals(ResourceKey.class))
728+
.map(f -> {
729+
try {
730+
Object val = f.get(null);
731+
return val;
732+
} catch (IllegalAccessException e) {
733+
LOGGER.error(e);
734+
return null;
735+
}
736+
})
737+
.filter(Objects::nonNull)
738+
.map(o -> (ResourceKey) o)
739+
.map(k -> k.location().toString())
740+
.collect(Collectors.toCollection(java.util.HashSet::new));
741+
face_features.add(CaveFeatures.DRIPSTONE_CLUSTER.location().toString());
742+
face_features.add(CaveFeatures.LARGE_DRIPSTONE.location().toString());
743+
face_features.add(CaveFeatures.POINTED_DRIPSTONE.location().toString());
744+
face_features.add(CaveFeatures.GLOW_LICHEN.location().toString());
745+
face_features.add(CaveFeatures.CAVE_VINE.location().toString());
746+
face_features.add(CaveFeatures.CAVE_VINE_IN_MOSS.location().toString());
747+
face_features.add(CaveFeatures.MOSS_VEGETATION.location().toString());
748+
face_features.add(CaveFeatures.DRIPLEAF.location().toString());
749+
face_features.add(EndFeatures.CHORUS_PLANT.location().toString());
750+
face_features.add(NetherFeatures.SMALL_BASALT_COLUMNS.location().toString());
751+
face_features.add(NetherFeatures.LARGE_BASALT_COLUMNS.location().toString());
752+
face_features.add(NetherFeatures.GLOWSTONE_EXTRA.location().toString());
753+
708754
// Features
709755
for (ResourceLocation name : server.registryAccess().registryOrThrow(Registries.CONFIGURED_FEATURE).keySet()) {
710-
if (ConfiguredFeatureType.REGISTRY.get(name.toString()) == null) {
711-
ConfiguredFeatureType.REGISTRY.register(name.toString(), new ConfiguredFeatureType(name.toString()));
756+
String id = name.toString();
757+
if (ConfiguredFeatureType.REGISTRY.get(id) == null) {
758+
ConfiguredFeatureType.REGISTRY.register(id, new ConfiguredFeatureType(id, face_features.contains(id)));
712759
}
713760
}
714761

0 commit comments

Comments
 (0)