Skip to content

Commit

Permalink
[NeoForge] 1.21.2
Browse files Browse the repository at this point in the history
Also some adjustments to align Fabric and NF closer
  • Loading branch information
octylFractal committed Oct 22, 2024
1 parent 25ad40e commit e2ca891
Show file tree
Hide file tree
Showing 20 changed files with 148 additions and 140 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ target
forge-download
out
run
runs
.jqwik-database

/dependency-reduced-pom.xml
Expand Down
9 changes: 5 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -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" }

Expand All @@ -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/
Expand All @@ -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"
Expand Down Expand Up @@ -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!!"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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()
)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,14 @@ public boolean setBiome(BlockVector3 position, BiomeType biome) {
return true;
}

private static final LoadingCache<ServerLevel, WorldEditFakePlayer> fakePlayers
= CacheBuilder.newBuilder().weakKeys().softValues().build(CacheLoader.from(WorldEditFakePlayer::new));
private static final LoadingCache<ServerLevel, FabricFakePlayer> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@

import static com.google.common.base.Preconditions.checkArgument;

class PropertyAdapter<T extends Comparable<T>> implements Property<T> {
class FabricPropertyAdapter<T extends Comparable<T>> implements Property<T> {

private final net.minecraft.world.level.block.state.properties.Property<T> property;
private final List<T> values;

public PropertyAdapter(net.minecraft.world.level.block.state.properties.Property<T> property) {
public FabricPropertyAdapter(net.minecraft.world.level.block.state.properties.Property<T> property) {
this.property = property;
this.values = ImmutableList.copyOf(property.getPossibleValues());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
};
}
});
Expand All @@ -93,7 +93,7 @@ private static Map<Property<?>, Object> transmogToWorldEditProperties(BlockType

@SuppressWarnings({ "unchecked", "rawtypes" })
private static net.minecraft.world.level.block.state.BlockState transmogToMinecraftProperties(
StateDefinition<Block, BlockState> stateContainer,
StateDefinition<Block, net.minecraft.world.level.block.state.BlockState> stateContainer,
net.minecraft.world.level.block.state.BlockState newState,
Map<Property<?>, Object> states
) {
Expand All @@ -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<Property<?>, Object> states = blockState.getStates();
Expand Down
4 changes: 2 additions & 2 deletions worldedit-neoforge/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ runs {
runtime(apiClasspath)
}
}
named("client").configure(runConfig)
named("server").configure(runConfig)
register("client").configure(runConfig)
register("server").configure(runConfig)
}

subsystems {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -95,15 +94,15 @@ 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()));
}

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());
Expand All @@ -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) {
Expand All @@ -174,10 +169,12 @@ public static Map<Property<?>, Object> adaptProperties(BlockType block, Map<net.
Map<Property<?>, Object> props = new TreeMap<>(Comparator.comparing(Property::getName));
for (Map.Entry<net.minecraft.world.level.block.state.properties.Property<?>, 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);
}
Expand All @@ -202,15 +199,15 @@ 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) {
return BlockTypes.get(BuiltInRegistries.BLOCK.getKey(block).toString());
}

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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
public class NeoForgeBlockCategoryRegistry implements BlockCategoryRegistry {
@Override
public Set<BlockType> 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)
))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
public class NeoForgeItemCategoryRegistry implements ItemCategoryRegistry {
@Override
public Set<ItemType> 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)
))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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()
)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
Loading

0 comments on commit e2ca891

Please sign in to comment.