diff --git a/.gitignore b/.gitignore index dfea5f9e53..75b7307731 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ target forge-download out run +runs .jqwik-database /dependency-reduced-pom.xml diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index a9fe67b7fd..0f25398549 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,6 +1,6 @@ [plugins] codecov = "org.enginehub.codecov:0.2.0" -neogradle-userdev = "net.neoforged.gradle.userdev:7.0.142" +neogradle-userdev = { id = "net.neoforged.gradle.userdev", version.ref = "neogradle" } sponge-spongegradle = "org.spongepowered.gradle.plugin:2.2.0" sponge-vanillagradle = { id = "org.spongepowered.gradle.vanilla", version.ref = "sponge-vanillagradle" } @@ -12,7 +12,8 @@ antlr = "4.13.1" fabric-api = "0.106.1+1.21.2" -neoforge-minecraft = "1.21" +neogradle = "7.0.165" +neoforge-minecraft = "1.21.2" sponge-minecraft = "1.21" # https://repo.spongepowered.org/service/rest/repository/browse/maven-public/org/spongepowered/spongeapi/ @@ -35,7 +36,7 @@ lang-worldeditBase = "7.3.7" lang-version = "1589" [libraries] -neogradle-neoform = "net.neoforged.gradle:neoform:7.0.142" +neogradle-neoform = { module = "net.neoforged.gradle:neoform", version.ref = "neogradle" } sponge-vanillagradle = { module = "org.spongepowered:vanillagradle", version.ref = "sponge-vanillagradle" } licenser = "gradle.plugin.org.cadixdev.gradle:licenser:0.6.1" @@ -90,7 +91,7 @@ fabric-minecraft = "com.mojang:minecraft:1.21.2" fabric-loader = "net.fabricmc:fabric-loader:0.16.7" fabric-permissions-api = "me.lucko:fabric-permissions-api:0.3.1" -neoforge = "net.neoforged:neoforge:21.0.16-beta" +neoforge = "net.neoforged:neoforge:21.2.0-beta" # Mojang-provided libraries, CHECK AGAINST MINECRAFT for versions guava = "com.google.guava:guava:32.1.3-jre!!" diff --git a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/WorldEditFakePlayer.java b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricFakePlayer.java similarity index 95% rename from worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/WorldEditFakePlayer.java rename to worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricFakePlayer.java index 516d617984..bcbcf5aa35 100644 --- a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/WorldEditFakePlayer.java +++ b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricFakePlayer.java @@ -31,13 +31,13 @@ import java.util.UUID; -public class WorldEditFakePlayer extends ServerPlayer { +public class FabricFakePlayer extends ServerPlayer { private static final GameProfile FAKE_WORLDEDIT_PROFILE = new GameProfile(UUID.nameUUIDFromBytes("worldedit".getBytes()), "[WorldEdit]"); private static final ClientInformation FAKE_CLIENT_INFO = new ClientInformation( "en_US", 16, ChatVisiblity.FULL, true, 0, HumanoidArm.LEFT, false, false, ParticleStatus.MINIMAL ); - public WorldEditFakePlayer(ServerLevel world) { + public FabricFakePlayer(ServerLevel world) { super(world.getServer(), world, FAKE_WORLDEDIT_PROFILE, FAKE_CLIENT_INFO); } diff --git a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricItemRegistry.java b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricItemRegistry.java index 7d495b4b3a..8d35a1b428 100644 --- a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricItemRegistry.java +++ b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricItemRegistry.java @@ -22,6 +22,7 @@ import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.formatting.text.serializer.gson.GsonComponentSerializer; import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.registry.BundledItemRegistry; @@ -36,8 +37,11 @@ public Component getRichName(ItemType itemType) { @Override public Component getRichName(BaseItemStack itemStack) { - return TranslatableComponent.of( - FabricAdapter.adapt(itemStack).getItem().getDescriptionId() + return GsonComponentSerializer.INSTANCE.deserialize( + net.minecraft.network.chat.Component.Serializer.toJson( + FabricAdapter.adapt(itemStack).getItemName(), + FabricWorldEdit.LIFECYCLED_SERVER.valueOrThrow().registryAccess() + ) ); } diff --git a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricWorld.java b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricWorld.java index 19d9034f4c..75cbced8a5 100644 --- a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricWorld.java +++ b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricWorld.java @@ -256,14 +256,14 @@ public boolean setBiome(BlockVector3 position, BiomeType biome) { return true; } - private static final LoadingCache fakePlayers - = CacheBuilder.newBuilder().weakKeys().softValues().build(CacheLoader.from(WorldEditFakePlayer::new)); + private static final LoadingCache fakePlayers + = CacheBuilder.newBuilder().weakKeys().softValues().build(CacheLoader.from(FabricFakePlayer::new)); @Override public boolean useItem(BlockVector3 position, BaseItem item, Direction face) { ItemStack stack = FabricAdapter.adapt(new BaseItemStack(item.getType(), item.getNbtReference(), 1)); ServerLevel world = (ServerLevel) getWorld(); - final WorldEditFakePlayer fakePlayer; + final FabricFakePlayer fakePlayer; try { fakePlayer = fakePlayers.get(world); } catch (ExecutionException ignored) { diff --git a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricWorldEdit.java b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricWorldEdit.java index 32e96ebd6b..9b00c72839 100644 --- a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricWorldEdit.java +++ b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricWorldEdit.java @@ -176,7 +176,7 @@ public void onInitialize() { ServerPlayConnectionEvents.DISCONNECT.register(this::onPlayerDisconnect); AttackBlockCallback.EVENT.register(this::onLeftClickBlock); UseBlockCallback.EVENT.register(this::onRightClickBlock); - UseItemCallback.EVENT.register(this::onRightClickAir); + UseItemCallback.EVENT.register(this::onRightClickItem); LOGGER.info("WorldEdit for Fabric (version " + getInternalVersion() + ") is loaded"); } @@ -373,7 +373,7 @@ public void onLeftClickAir(ServerPlayer playerEntity, InteractionHand hand) { debouncer.setLastInteraction(player, result); } - private InteractionResult onRightClickAir(Player playerEntity, Level world, InteractionHand hand) { + private InteractionResult onRightClickItem(Player playerEntity, Level world, InteractionHand hand) { if (skipInteractionEvent(playerEntity, hand)) { return InteractionResult.PASS; } diff --git a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/internal/PropertyAdapter.java b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/internal/FabricPropertyAdapter.java similarity index 91% rename from worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/internal/PropertyAdapter.java rename to worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/internal/FabricPropertyAdapter.java index 32271ee749..a1d6791a69 100644 --- a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/internal/PropertyAdapter.java +++ b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/internal/FabricPropertyAdapter.java @@ -27,12 +27,12 @@ import static com.google.common.base.Preconditions.checkArgument; -class PropertyAdapter> implements Property { +class FabricPropertyAdapter> implements Property { private final net.minecraft.world.level.block.state.properties.Property property; private final List values; - public PropertyAdapter(net.minecraft.world.level.block.state.properties.Property property) { + public FabricPropertyAdapter(net.minecraft.world.level.block.state.properties.Property property) { this.property = property; this.values = ImmutableList.copyOf(property.getPossibleValues()); } diff --git a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/internal/FabricTransmogrifier.java b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/internal/FabricTransmogrifier.java index 866c374660..9d0afbb60c 100644 --- a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/internal/FabricTransmogrifier.java +++ b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/internal/FabricTransmogrifier.java @@ -30,10 +30,10 @@ import com.sk89q.worldedit.registry.state.IntegerProperty; import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.util.Direction; +import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; import net.minecraft.util.StringRepresentable; import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; import java.util.Comparator; @@ -66,7 +66,7 @@ yield new EnumProperty(property.getName(), enumProperty.getPossibleValues().stre .map(x -> x.getSerializedName()) .collect(ImmutableList.toImmutableList())); } - default -> new PropertyAdapter<>(property); + default -> new FabricPropertyAdapter<>(property); }; } }); @@ -93,7 +93,7 @@ private static Map, Object> transmogToWorldEditProperties(BlockType @SuppressWarnings({ "unchecked", "rawtypes" }) private static net.minecraft.world.level.block.state.BlockState transmogToMinecraftProperties( - StateDefinition stateContainer, + StateDefinition stateContainer, net.minecraft.world.level.block.state.BlockState newState, Map, Object> states ) { @@ -118,7 +118,7 @@ private static net.minecraft.world.level.block.state.BlockState transmogToMinecr return newState; } - public static net.minecraft.world.level.block.state.BlockState transmogToMinecraft(com.sk89q.worldedit.world.block.BlockState blockState) { + public static net.minecraft.world.level.block.state.BlockState transmogToMinecraft(BlockState blockState) { Block mcBlock = FabricAdapter.adapt(blockState.getBlockType()); net.minecraft.world.level.block.state.BlockState newState = mcBlock.defaultBlockState(); Map, Object> states = blockState.getStates(); diff --git a/worldedit-neoforge/build.gradle.kts b/worldedit-neoforge/build.gradle.kts index 18f2e45fe5..a3f8b3792f 100644 --- a/worldedit-neoforge/build.gradle.kts +++ b/worldedit-neoforge/build.gradle.kts @@ -57,8 +57,8 @@ runs { runtime(apiClasspath) } } - named("client").configure(runConfig) - named("server").configure(runConfig) + register("client").configure(runConfig) + register("server").configure(runConfig) } subsystems { diff --git a/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgeAdapter.java b/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgeAdapter.java index 95c204e1a7..8706822486 100644 --- a/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgeAdapter.java +++ b/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgeAdapter.java @@ -54,7 +54,6 @@ import net.minecraft.world.level.BaseCommandBlock; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.properties.DirectionProperty; import net.minecraft.world.phys.Vec3; import net.neoforged.neoforge.server.ServerLifecycleHooks; import org.enginehub.linbus.tree.LinCompoundTag; @@ -95,7 +94,7 @@ public static ServerLevel adapt(World world) { public static Biome adapt(BiomeType biomeType) { return ServerLifecycleHooks.getCurrentServer() .registryAccess() - .registryOrThrow(Registries.BIOME) + .lookupOrThrow(Registries.BIOME) .getOptional(ResourceLocation.parse(biomeType.id())) .orElseThrow(() -> new IllegalStateException("No biome for " + biomeType.id())); } @@ -103,7 +102,7 @@ public static Biome adapt(BiomeType biomeType) { public static BiomeType adapt(Biome biome) { ResourceLocation id = ServerLifecycleHooks.getCurrentServer() .registryAccess() - .registryOrThrow(Registries.BIOME) + .lookupOrThrow(Registries.BIOME) .getKey(biome); Objects.requireNonNull(id, "biome is not registered"); return BiomeTypes.get(id.toString()); @@ -122,32 +121,28 @@ public static Vec3 toVec3(BlockVector3 vector) { } public static net.minecraft.core.Direction adapt(Direction face) { - switch (face) { - case NORTH: return net.minecraft.core.Direction.NORTH; - case SOUTH: return net.minecraft.core.Direction.SOUTH; - case WEST: return net.minecraft.core.Direction.WEST; - case EAST: return net.minecraft.core.Direction.EAST; - case DOWN: return net.minecraft.core.Direction.DOWN; - case UP: - default: - return net.minecraft.core.Direction.UP; - } + return switch (face) { + case NORTH -> net.minecraft.core.Direction.NORTH; + case SOUTH -> net.minecraft.core.Direction.SOUTH; + case WEST -> net.minecraft.core.Direction.WEST; + case EAST -> net.minecraft.core.Direction.EAST; + case DOWN -> net.minecraft.core.Direction.DOWN; + default -> net.minecraft.core.Direction.UP; + }; } public static Direction adaptEnumFacing(@Nullable net.minecraft.core.Direction face) { if (face == null) { return null; } - switch (face) { - case NORTH: return Direction.NORTH; - case SOUTH: return Direction.SOUTH; - case WEST: return Direction.WEST; - case EAST: return Direction.EAST; - case DOWN: return Direction.DOWN; - case UP: - default: - return Direction.UP; - } + return switch (face) { + case NORTH -> Direction.NORTH; + case SOUTH -> Direction.SOUTH; + case WEST -> Direction.WEST; + case EAST -> Direction.EAST; + case DOWN -> Direction.DOWN; + default -> Direction.UP; + }; } public static BlockPos toBlockPos(BlockVector3 vector) { @@ -174,10 +169,12 @@ public static Map, Object> adaptProperties(BlockType block, Map, Object> props = new TreeMap<>(Comparator.comparing(Property::getName)); for (Map.Entry, Comparable> prop : mcProps.entrySet()) { Object value = prop.getValue(); - if (prop.getKey() instanceof DirectionProperty) { - value = adaptEnumFacing((net.minecraft.core.Direction) value); - } else if (prop.getKey() instanceof net.minecraft.world.level.block.state.properties.EnumProperty) { - value = ((StringRepresentable) value).getSerializedName(); + if (prop.getKey() instanceof net.minecraft.world.level.block.state.properties.EnumProperty) { + if (prop.getKey().getValueClass() == net.minecraft.core.Direction.class) { + value = adaptEnumFacing((net.minecraft.core.Direction) value); + } else { + value = ((StringRepresentable) value).getSerializedName(); + } } props.put(block.getProperty(prop.getKey().getName()), value); } @@ -202,7 +199,7 @@ public static BlockState adapt(net.minecraft.world.level.block.state.BlockState } public static Block adapt(BlockType blockType) { - return BuiltInRegistries.BLOCK.get(ResourceLocation.parse(blockType.id())); + return BuiltInRegistries.BLOCK.getValue(ResourceLocation.parse(blockType.id())); } public static BlockType adapt(Block block) { @@ -210,7 +207,7 @@ public static BlockType adapt(Block block) { } public static Item adapt(ItemType itemType) { - return BuiltInRegistries.ITEM.get(ResourceLocation.parse(itemType.id())); + return BuiltInRegistries.ITEM.getValue(ResourceLocation.parse(itemType.id())); } public static ItemType adapt(Item item) { diff --git a/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgeBlockCategoryRegistry.java b/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgeBlockCategoryRegistry.java index e8dc209a35..fb8c6aaed3 100644 --- a/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgeBlockCategoryRegistry.java +++ b/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgeBlockCategoryRegistry.java @@ -34,8 +34,8 @@ public class NeoForgeBlockCategoryRegistry implements BlockCategoryRegistry { @Override public Set getCategorisedByName(String category) { - return ServerLifecycleHooks.getCurrentServer().registryAccess().registryOrThrow(Registries.BLOCK) - .getTag(TagKey.create( + return ServerLifecycleHooks.getCurrentServer().registryAccess().lookupOrThrow(Registries.BLOCK) + .get(TagKey.create( Registries.BLOCK, ResourceLocation.parse(category) )) diff --git a/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/WorldEditFakePlayer.java b/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgeFakePlayer.java similarity index 87% rename from worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/WorldEditFakePlayer.java rename to worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgeFakePlayer.java index 3940f6198b..51ac6c7aa0 100644 --- a/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/WorldEditFakePlayer.java +++ b/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgeFakePlayer.java @@ -22,22 +22,22 @@ import com.mojang.authlib.GameProfile; import net.minecraft.network.chat.Component; import net.minecraft.server.level.ClientInformation; +import net.minecraft.server.level.ParticleStatus; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.stats.Stat; -import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.HumanoidArm; import net.minecraft.world.entity.player.ChatVisiblity; import java.util.UUID; -public class WorldEditFakePlayer extends ServerPlayer { +public class NeoForgeFakePlayer extends ServerPlayer { private static final GameProfile FAKE_WORLDEDIT_PROFILE = new GameProfile(UUID.nameUUIDFromBytes("worldedit".getBytes()), "[WorldEdit]"); private static final ClientInformation FAKE_CLIENT_INFO = new ClientInformation( - "en_US", 16, ChatVisiblity.FULL, true, 0, HumanoidArm.LEFT, false, false + "en_US", 16, ChatVisiblity.FULL, true, 0, HumanoidArm.LEFT, false, false, ParticleStatus.MINIMAL ); - public WorldEditFakePlayer(ServerLevel world) { + public NeoForgeFakePlayer(ServerLevel world) { super(world.getServer(), world, FAKE_WORLDEDIT_PROFILE, FAKE_CLIENT_INFO); } @@ -57,9 +57,4 @@ public void awardStat(Stat stat) { public void displayClientMessage(Component message, boolean actionBar) { super.displayClientMessage(message, actionBar); } - - @Override - public boolean isInvulnerableTo(DamageSource damageSource) { - return true; - } } diff --git a/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgeItemCategoryRegistry.java b/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgeItemCategoryRegistry.java index 0ef83b6db8..fb062367ac 100644 --- a/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgeItemCategoryRegistry.java +++ b/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgeItemCategoryRegistry.java @@ -34,8 +34,8 @@ public class NeoForgeItemCategoryRegistry implements ItemCategoryRegistry { @Override public Set getCategorisedByName(String category) { - return ServerLifecycleHooks.getCurrentServer().registryAccess().registryOrThrow(Registries.ITEM) - .getTag(TagKey.create( + return ServerLifecycleHooks.getCurrentServer().registryAccess().lookupOrThrow(Registries.ITEM) + .get(TagKey.create( Registries.ITEM, ResourceLocation.parse(category) )) diff --git a/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgeItemRegistry.java b/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgeItemRegistry.java index 7b9d2a9baf..b1ecfa85d3 100644 --- a/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgeItemRegistry.java +++ b/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgeItemRegistry.java @@ -22,8 +22,10 @@ import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.formatting.text.serializer.gson.GsonComponentSerializer; import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.registry.BundledItemRegistry; +import net.neoforged.neoforge.server.ServerLifecycleHooks; public class NeoForgeItemRegistry extends BundledItemRegistry { @@ -36,8 +38,11 @@ public Component getRichName(ItemType itemType) { @Override public Component getRichName(BaseItemStack itemStack) { - return TranslatableComponent.of( - NeoForgeAdapter.adapt(itemStack).getDescriptionId() + return GsonComponentSerializer.INSTANCE.deserialize( + net.minecraft.network.chat.Component.Serializer.toJson( + NeoForgeAdapter.adapt(itemStack).getItemName(), + ServerLifecycleHooks.getCurrentServer().registryAccess() + ) ); } diff --git a/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgePlayer.java b/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgePlayer.java index fddd8bc453..342a811468 100644 --- a/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgePlayer.java +++ b/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgePlayer.java @@ -53,6 +53,7 @@ import org.enginehub.linbus.tree.LinCompoundTag; import java.util.Locale; +import java.util.Set; import java.util.UUID; import javax.annotation.Nullable; @@ -106,7 +107,9 @@ public boolean setLocation(Location location) { this.player.teleportTo( level, location.getX(), location.getY(), location.getZ(), - location.getYaw(), location.getPitch() + Set.of(), + location.getYaw(), location.getPitch(), + true ); // This may be false if the teleport was cancelled by a mod return this.player.serverLevel() == level; diff --git a/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgeWorld.java b/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgeWorld.java index da7ae7e880..5d5e00e731 100644 --- a/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgeWorld.java +++ b/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgeWorld.java @@ -79,6 +79,7 @@ import net.minecraft.world.Clearable; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.EntitySpawnReason; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.item.ItemStack; @@ -138,7 +139,7 @@ public class NeoForgeWorld extends AbstractWorld { private static ResourceLocation getDimensionRegistryKey(ServerLevel world) { return Objects.requireNonNull(world.getServer(), "server cannot be null") .registryAccess() - .registryOrThrow(Registries.DIMENSION_TYPE) + .lookupOrThrow(Registries.DIMENSION_TYPE) .getKey(world.dimensionType()); } @@ -240,22 +241,21 @@ public boolean setBiome(BlockVector3 position, BiomeType biome) { var biomes = (PalettedContainer>) chunk.getSection(chunk.getSectionIndex(position.y())).getBiomes(); biomes.getAndSetUnchecked( position.x() & 3, position.y() & 3, position.z() & 3, - getWorld().registryAccess().registry(Registries.BIOME) - .orElseThrow() - .getHolderOrThrow(ResourceKey.create(Registries.BIOME, ResourceLocation.parse(biome.id()))) + getWorld().registryAccess().lookupOrThrow(Registries.BIOME) + .getOrThrow(ResourceKey.create(Registries.BIOME, ResourceLocation.parse(biome.id()))) ); - chunk.setUnsaved(true); + chunk.markUnsaved(); return true; } - private static final LoadingCache fakePlayers - = CacheBuilder.newBuilder().weakKeys().softValues().build(CacheLoader.from(WorldEditFakePlayer::new)); + private static final LoadingCache fakePlayers + = CacheBuilder.newBuilder().weakKeys().softValues().build(CacheLoader.from(NeoForgeFakePlayer::new)); @Override public boolean useItem(BlockVector3 position, BaseItem item, Direction face) { ItemStack stack = NeoForgeAdapter.adapt(new BaseItemStack(item.getType(), item.getNbtReference(), 1)); ServerLevel world = getWorld(); - final WorldEditFakePlayer fakePlayer; + final NeoForgeFakePlayer fakePlayer; try { fakePlayer = fakePlayers.get(world); } catch (ExecutionException ignored) { @@ -271,12 +271,11 @@ public boolean useItem(BlockVector3 position, BaseItem item, Direction face) { InteractionResult used = stack.onItemUseFirst(itemUseContext); if (used != InteractionResult.SUCCESS) { // try activating the block - InteractionResult resultType = getWorld().getBlockState(blockPos).useItemOn(stack, world, fakePlayer, InteractionHand.MAIN_HAND, rayTraceResult) - .result(); + InteractionResult resultType = getWorld().getBlockState(blockPos).useItemOn(stack, world, fakePlayer, InteractionHand.MAIN_HAND, rayTraceResult); if (resultType.consumesAction()) { used = resultType; } else { - used = stack.getItem().use(world, fakePlayer, InteractionHand.MAIN_HAND).getResult(); + used = stack.getItem().use(world, fakePlayer, InteractionHand.MAIN_HAND); } } return used == InteractionResult.SUCCESS; @@ -455,7 +454,7 @@ private List> submitChunkLoadTasks(Region region, public boolean generateTree(TreeType type, EditSession editSession, BlockVector3 position) { ServerLevel world = getWorld(); ConfiguredFeature generator = Optional.ofNullable(createTreeFeatureGenerator(type)) - .map(k -> world.registryAccess().registryOrThrow(Registries.CONFIGURED_FEATURE).get(k)) + .flatMap(k -> world.registryAccess().lookupOrThrow(Registries.CONFIGURED_FEATURE).getOptional(k)) .orElse(null); ServerChunkCache chunkManager = world.getChunkSource(); if (type == TreeType.CHORUS_PLANT) { @@ -469,7 +468,7 @@ public boolean generateTree(TreeType type, EditSession editSession, BlockVector3 public boolean generateFeature(ConfiguredFeatureType type, EditSession editSession, BlockVector3 position) { ServerLevel world = getWorld(); - ConfiguredFeature k = world.registryAccess().registryOrThrow(Registries.CONFIGURED_FEATURE).get(ResourceLocation.tryParse(type.id())); + ConfiguredFeature k = world.registryAccess().lookupOrThrow(Registries.CONFIGURED_FEATURE).getValue(ResourceLocation.tryParse(type.id())); ServerChunkCache chunkManager = world.getChunkSource(); WorldGenLevel levelProxy = NeoForgeServerLevelDelegateProxy.newInstance(editSession, world); return k != null && k.place(levelProxy, chunkManager.getGenerator(), random, NeoForgeAdapter.toBlockPos(position)); @@ -478,7 +477,7 @@ public boolean generateFeature(ConfiguredFeatureType type, EditSession editSessi @Override public boolean generateStructure(StructureType type, EditSession editSession, BlockVector3 position) { ServerLevel world = getWorld(); - Structure k = world.registryAccess().registryOrThrow(Registries.STRUCTURE).get(ResourceLocation.tryParse(type.id())); + Structure k = world.registryAccess().lookupOrThrow(Registries.STRUCTURE).getValue(ResourceLocation.tryParse(type.id())); if (k == null) { return false; } @@ -494,7 +493,7 @@ public boolean generateStructure(StructureType type, EditSession editSession, Bl BoundingBox boundingBox = structureStart.getBoundingBox(); ChunkPos min = new ChunkPos(SectionPos.blockToSectionCoord(boundingBox.minX()), SectionPos.blockToSectionCoord(boundingBox.minZ())); ChunkPos max = new ChunkPos(SectionPos.blockToSectionCoord(boundingBox.maxX()), SectionPos.blockToSectionCoord(boundingBox.maxZ())); - ChunkPos.rangeClosed(min, max).forEach((chunkPosx) -> structureStart.placeInChunk(proxyLevel, world.structureManager(), chunkManager.getGenerator(), world.getRandom(), new BoundingBox(chunkPosx.getMinBlockX(), world.getMinBuildHeight(), chunkPosx.getMinBlockZ(), chunkPosx.getMaxBlockX(), world.getMaxBuildHeight(), chunkPosx.getMaxBlockZ()), chunkPosx)); + ChunkPos.rangeClosed(min, max).forEach((chunkPosx) -> structureStart.placeInChunk(proxyLevel, world.structureManager(), chunkManager.getGenerator(), world.getRandom(), new BoundingBox(chunkPosx.getMinBlockX(), world.getMinY(), chunkPosx.getMinBlockZ(), chunkPosx.getMaxBlockX(), world.getMaxY(), chunkPosx.getMaxBlockZ()), chunkPosx)); return true; } } @@ -586,12 +585,12 @@ public void setWeather(WeatherType weatherType, long duration) { @Override public int getMinY() { - return getWorld().getMinBuildHeight(); + return getWorld().getMinY(); } @Override public int getMaxY() { - return getWorld().getMaxBuildHeight() - 1; + return getWorld().getMaxY() - 1; } @Override @@ -685,7 +684,7 @@ public Entity createEntity(Location location, BaseEntity entity) { } tag.putString("id", entityId); - net.minecraft.world.entity.Entity createdEntity = EntityType.loadEntityRecursive(tag, world, (loadedEntity) -> { + net.minecraft.world.entity.Entity createdEntity = EntityType.loadEntityRecursive(tag, world, EntitySpawnReason.COMMAND, (loadedEntity) -> { loadedEntity.absMoveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); return loadedEntity; }); diff --git a/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgeWorldEdit.java b/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgeWorldEdit.java index b0518be5d0..9f6d859e45 100644 --- a/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgeWorldEdit.java +++ b/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgeWorldEdit.java @@ -57,7 +57,6 @@ import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; -import net.minecraft.tags.TagKey; import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.biome.Biome; @@ -178,32 +177,32 @@ private void setupRegistries(MinecraftServer server) { } } // Biomes - for (ResourceLocation name : server.registryAccess().registryOrThrow(Registries.BIOME).keySet()) { + for (ResourceLocation name : server.registryAccess().lookupOrThrow(Registries.BIOME).keySet()) { String key = name.toString(); if (BiomeType.REGISTRY.get(key) == null) { BiomeType.REGISTRY.register(key, new BiomeType(key)); } } // Tags - server.registryAccess().registryOrThrow(Registries.BLOCK).getTagNames().map(TagKey::location).forEach(name -> { + server.registryAccess().lookupOrThrow(Registries.BLOCK).getTags().map(t -> t.key().location()).forEach(name -> { String key = name.toString(); if (BlockCategory.REGISTRY.get(key) == null) { BlockCategory.REGISTRY.register(key, new BlockCategory(key)); } }); - server.registryAccess().registryOrThrow(Registries.ITEM).getTagNames().map(TagKey::location).forEach(name -> { + server.registryAccess().lookupOrThrow(Registries.ITEM).getTags().map(t -> t.key().location()).forEach(name -> { String key = name.toString(); if (ItemCategory.REGISTRY.get(key) == null) { ItemCategory.REGISTRY.register(key, new ItemCategory(key)); } }); - Registry biomeRegistry = server.registryAccess().registryOrThrow(Registries.BIOME); - biomeRegistry.getTagNames().forEach(tagKey -> { - String key = tagKey.location().toString(); + Registry biomeRegistry = server.registryAccess().lookupOrThrow(Registries.BIOME); + biomeRegistry.getTags().forEach(tag -> { + String key = tag.key().location().toString(); if (BiomeCategory.REGISTRY.get(key) == null) { BiomeCategory.REGISTRY.register(key, new BiomeCategory( key, - () -> biomeRegistry.getTag(tagKey) + () -> biomeRegistry.get(tag.key()) .stream() .flatMap(HolderSet.Named::stream) .map(Holder::value) @@ -213,14 +212,14 @@ private void setupRegistries(MinecraftServer server) { } }); // Features - for (ResourceLocation name : server.registryAccess().registryOrThrow(Registries.CONFIGURED_FEATURE).keySet()) { + for (ResourceLocation name : server.registryAccess().lookupOrThrow(Registries.CONFIGURED_FEATURE).keySet()) { String key = name.toString(); if (ConfiguredFeatureType.REGISTRY.get(key) == null) { ConfiguredFeatureType.REGISTRY.register(key, new ConfiguredFeatureType(key)); } } // Structures - for (ResourceLocation name : server.registryAccess().registryOrThrow(Registries.STRUCTURE).keySet()) { + for (ResourceLocation name : server.registryAccess().lookupOrThrow(Registries.STRUCTURE).keySet()) { String key = name.toString(); if (StructureType.REGISTRY.get(key) == null) { StructureType.REGISTRY.register(key, new StructureType(key)); diff --git a/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/internal/IPropertyAdapter.java b/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/internal/NeoForgePropertyAdapter.java similarity index 91% rename from worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/internal/IPropertyAdapter.java rename to worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/internal/NeoForgePropertyAdapter.java index 2d7d965cd1..f340b2953a 100644 --- a/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/internal/IPropertyAdapter.java +++ b/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/internal/NeoForgePropertyAdapter.java @@ -27,12 +27,12 @@ import static com.google.common.base.Preconditions.checkArgument; -class IPropertyAdapter> implements Property { +class NeoForgePropertyAdapter> implements Property { private final net.minecraft.world.level.block.state.properties.Property property; private final List values; - public IPropertyAdapter(net.minecraft.world.level.block.state.properties.Property property) { + public NeoForgePropertyAdapter(net.minecraft.world.level.block.state.properties.Property property) { this.property = property; this.values = ImmutableList.copyOf(property.getPossibleValues()); } diff --git a/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/internal/NeoForgeTransmogrifier.java b/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/internal/NeoForgeTransmogrifier.java index c835ae1ae8..43ea7c0e37 100644 --- a/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/internal/NeoForgeTransmogrifier.java +++ b/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/internal/NeoForgeTransmogrifier.java @@ -35,12 +35,10 @@ import net.minecraft.util.StringRepresentable; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.world.level.block.state.properties.DirectionProperty; import java.util.Comparator; import java.util.Map; import java.util.TreeMap; -import java.util.stream.Collectors; /** * Raw, un-cached transformations. @@ -50,26 +48,26 @@ public class NeoForgeTransmogrifier { private static final LoadingCache, Property> PROPERTY_CACHE = CacheBuilder.newBuilder().build(new CacheLoader<>() { @Override public Property load(net.minecraft.world.level.block.state.properties.Property property) throws Exception { - if (property instanceof net.minecraft.world.level.block.state.properties.BooleanProperty) { - return new BooleanProperty(property.getName(), ImmutableList.copyOf(((net.minecraft.world.level.block.state.properties.BooleanProperty) property).getPossibleValues())); - } - if (property instanceof net.minecraft.world.level.block.state.properties.IntegerProperty) { - return new IntegerProperty(property.getName(), ImmutableList.copyOf(((net.minecraft.world.level.block.state.properties.IntegerProperty) property).getPossibleValues())); - } - if (property instanceof DirectionProperty) { - return new DirectionalProperty(property.getName(), ((DirectionProperty) property).getPossibleValues().stream() - .map(NeoForgeAdapter::adaptEnumFacing) - .collect(Collectors.toList())); - } - if (property instanceof net.minecraft.world.level.block.state.properties.EnumProperty) { - // Note: do not make x.getSerializedName a method reference. - // It will cause runtime bootstrap exceptions. - //noinspection Convert2MethodRef - return new EnumProperty(property.getName(), ((net.minecraft.world.level.block.state.properties.EnumProperty) property).getPossibleValues().stream() - .map(x -> x.getSerializedName()) - .collect(Collectors.toList())); - } - return new IPropertyAdapter<>(property); + return switch (property) { + case net.minecraft.world.level.block.state.properties.BooleanProperty booleanProperty -> + new BooleanProperty(property.getName(), ImmutableList.copyOf(booleanProperty.getPossibleValues())); + case net.minecraft.world.level.block.state.properties.IntegerProperty integerProperty -> + new IntegerProperty(property.getName(), ImmutableList.copyOf(integerProperty.getPossibleValues())); + case net.minecraft.world.level.block.state.properties.EnumProperty enumProperty -> { + if (property.getValueClass() == net.minecraft.core.Direction.class) { + yield new DirectionalProperty(property.getName(), property.getPossibleValues().stream() + .map(v -> NeoForgeAdapter.adaptEnumFacing((net.minecraft.core.Direction) v)) + .collect(ImmutableList.toImmutableList())); + } + // Note: do not make x.asString a method reference. + // It will cause runtime bootstrap exceptions. + //noinspection Convert2MethodRef + yield new EnumProperty(property.getName(), enumProperty.getPossibleValues().stream() + .map(x -> x.getSerializedName()) + .collect(ImmutableList.toImmutableList())); + } + default -> new NeoForgePropertyAdapter<>(property); + }; } }); @@ -81,29 +79,38 @@ public static Map, Object> transmogToWorldEditProperties(BlockType b Map, Object> props = new TreeMap<>(Comparator.comparing(Property::getName)); for (Map.Entry, Comparable> prop : mcProps.entrySet()) { Object value = prop.getValue(); - if (prop.getKey() instanceof DirectionProperty) { - value = NeoForgeAdapter.adaptEnumFacing((net.minecraft.core.Direction) value); - } else if (prop.getKey() instanceof net.minecraft.world.level.block.state.properties.EnumProperty) { - value = ((StringRepresentable) value).getSerializedName(); + if (prop.getKey() instanceof net.minecraft.world.level.block.state.properties.EnumProperty) { + if (prop.getKey().getValueClass() == net.minecraft.core.Direction.class) { + value = NeoForgeAdapter.adaptEnumFacing((net.minecraft.core.Direction) value); + } else { + value = ((StringRepresentable) value).getSerializedName(); + } + props.put(block.getProperty(prop.getKey().getName()), value); } - props.put(block.getProperty(prop.getKey().getName()), value); } return props; } - @SuppressWarnings({ "rawtypes", "unchecked" }) - private static net.minecraft.world.level.block.state.BlockState transmogToMinecraftProperties(StateDefinition stateContainer, net.minecraft.world.level.block.state.BlockState newState, Map, Object> states) { + @SuppressWarnings({"rawtypes", "unchecked"}) + private static net.minecraft.world.level.block.state.BlockState transmogToMinecraftProperties( + StateDefinition stateContainer, + net.minecraft.world.level.block.state.BlockState newState, + Map, Object> states + ) { for (Map.Entry, Object> state : states.entrySet()) { net.minecraft.world.level.block.state.properties.Property property = stateContainer.getProperty(state.getKey().getName()); Comparable value = (Comparable) state.getValue(); // we may need to adapt this value, depending on the source prop - if (property instanceof DirectionProperty) { - Direction dir = (Direction) value; - value = NeoForgeAdapter.adapt(dir); - } else if (property instanceof net.minecraft.world.level.block.state.properties.EnumProperty) { - String enumName = (String) value; - value = ((net.minecraft.world.level.block.state.properties.EnumProperty) property).getValue((String) value) - .orElseThrow(() -> new IllegalStateException("Enum property " + property.getName() + " does not contain " + enumName)); + if (property instanceof net.minecraft.world.level.block.state.properties.EnumProperty) { + if (property.getValueClass() == net.minecraft.core.Direction.class) { + Direction dir = (Direction) value; + value = NeoForgeAdapter.adapt(dir); + } else { + String enumName = (String) value; + value = ((net.minecraft.world.level.block.state.properties.EnumProperty) property).getValue((String) value).orElseThrow(() -> + new IllegalStateException("Enum property " + property.getName() + " does not contain " + enumName) + ); + } } newState = newState.setValue(property, value); diff --git a/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/internal/NeoForgeWorldNativeAccess.java b/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/internal/NeoForgeWorldNativeAccess.java index c1e98765bf..9c4ffd35db 100644 --- a/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/internal/NeoForgeWorldNativeAccess.java +++ b/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/internal/NeoForgeWorldNativeAccess.java @@ -32,6 +32,7 @@ import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.LevelChunk; +import net.minecraft.world.level.redstone.ExperimentalRedstoneUtils; import org.enginehub.linbus.tree.LinCompoundTag; import java.lang.ref.WeakReference; @@ -140,14 +141,10 @@ public void notifyNeighbors(BlockPos pos, BlockState oldState, BlockState newSta if (sideEffectSet.shouldApply(SideEffect.EVENTS)) { world.updateNeighborsAt(pos, oldState.getBlock()); } else { - // Manually update each side - Block block = oldState.getBlock(); - world.neighborChanged(pos.west(), block, pos); - world.neighborChanged(pos.east(), block, pos); - world.neighborChanged(pos.below(), block, pos); - world.neighborChanged(pos.above(), block, pos); - world.neighborChanged(pos.north(), block, pos); - world.neighborChanged(pos.south(), block, pos); + // Bypasses events currently, watch for changes... + world.updateNeighborsAt(pos, oldState.getBlock(), ExperimentalRedstoneUtils.initialOrientation( + world, null, null + )); } if (newState.hasAnalogOutputSignal()) { world.updateNeighbourForOutputSignal(pos, newState.getBlock());