Skip to content

Commit

Permalink
Update to NeoForge 20.2.77-beta, Forge 49.0.14 and Fabric Loader & AP…
Browse files Browse the repository at this point in the history
…I 0.15.3 & 0.92.0 (#468)
  • Loading branch information
Jab125 authored Jan 7, 2024
1 parent 7d771c2 commit 760b2a7
Show file tree
Hide file tree
Showing 17 changed files with 130 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,23 @@

package dev.architectury.hooks.level;

import dev.architectury.injectables.annotations.ExpectPlatform;
import net.minecraft.world.level.Explosion;
import net.minecraft.world.phys.Vec3;

/**
* @deprecated no longer needed.
*/
@Deprecated(forRemoval = true)
public final class ExplosionHooks {
private ExplosionHooks() {
}

@ExpectPlatform
/**
* @deprecated no longer needed.
* @see Explosion#center()
*/
@Deprecated(forRemoval = true)
public static Vec3 getPosition(Explosion explosion) {
throw new AssertionError();
return explosion.center();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

package dev.architectury.networking.fabric;
package dev.architectury.networking;

import dev.architectury.extensions.network.EntitySpawnExtension;
import dev.architectury.networking.NetworkManager;
import io.netty.buffer.Unpooled;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.minecraft.client.Minecraft;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.FriendlyByteBuf;
Expand All @@ -42,7 +41,7 @@ public static Packet<ClientGamePacketListener> create(Entity entity) {
if (entity.level().isClientSide()) {
throw new IllegalStateException("SpawnPacketUtil.create called on the logical client!");
}
var buffer = PacketByteBufs.create();
var buffer = new FriendlyByteBuf(Unpooled.buffer());
buffer.writeVarInt(BuiltInRegistries.ENTITY_TYPE.getId(entity.getType()));
buffer.writeUUID(entity.getUUID());
buffer.writeVarInt(entity.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import dev.architectury.event.events.client.ClientLifecycleEvent;
import dev.architectury.event.events.common.LifecycleEvent;
import dev.architectury.networking.fabric.SpawnEntityPacket;
import dev.architectury.networking.SpawnEntityPacket;
import net.minecraft.client.Minecraft;

public class ArchitecturyClient {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@
package dev.architectury.mixin.fabric;

import dev.architectury.event.events.common.ExplosionEvent;
import dev.architectury.hooks.level.fabric.ExplosionHooksImpl;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.*;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
Expand All @@ -37,33 +36,15 @@
import java.util.Set;

@Mixin(Explosion.class)
public class MixinExplosion implements ExplosionHooksImpl.ExplosionExtensions {
public class MixinExplosion {
@Shadow
@Final
private Level level;
@Shadow
@Final
private double x;
@Shadow
@Final
private double y;
@Shadow
@Final
private double z;
@Unique
Vec3 position;

@SuppressWarnings("InvalidInjectorMethodSignature")
@Inject(method = "explode", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/phys/Vec3;<init>(DDD)V", ordinal = 1),
locals = LocalCapture.CAPTURE_FAILHARD)
private void explodePost(CallbackInfo ci, Set<BlockPos> set, int i, float q, int r, int s, int t, int u, int v, int w, List<Entity> list) {
ExplosionEvent.DETONATE.invoker().explode(level, (Explosion) (Object) this, list);
}

@Override
public Vec3 architectury_getPosition() {
if (position == null) {
return position = new Vec3(x, y, z);
}
return position;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.mojang.logging.LogUtils;
import dev.architectury.networking.NetworkManager;
import dev.architectury.networking.NetworkManager.NetworkReceiver;
import dev.architectury.networking.SpawnEntityPacket;
import dev.architectury.networking.transformers.PacketSink;
import dev.architectury.networking.transformers.PacketTransformer;
import dev.architectury.utils.Env;
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion forge/src/main/resources/architectury.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"MixinMinecraft"
],
"mixins": [
"MixinEntitySpawnExtension",
"MixinFallingBlockEntity",
"MixinItemExtension",
"MixinLevelEvent",
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ archives_base_name_snapshot=architectury-snapshot
base_version=11.0
maven_group=dev.architectury

fabric_loader_version=0.15.1
fabric_api_version=0.91.1+1.20.4
mod_menu_version=7.0.0
fabric_loader_version=0.15.3
fabric_api_version=0.92.0+1.20.4
mod_menu_version=9.0.0

forge_version=49.0.3
neoforge_version=20.4.46-beta
forge_version=49.0.14
neoforge_version=20.4.77-beta

curseforge_id=419699
modrinth_id=lhGA9TYQ
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

package dev.architectury.mixin.forge;
package dev.architectury.mixin.forge.minecraftforge;

import dev.architectury.extensions.network.EntitySpawnExtension;
import net.minecraft.network.FriendlyByteBuf;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,18 @@
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.event.network.CustomPayloadEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.LogicalSide;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.network.*;
import net.minecraftforge.network.ChannelBuilder;
import net.minecraftforge.network.EventNetworkChannel;
import net.minecraftforge.network.NetworkDirection;
import org.slf4j.Logger;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import java.util.function.Consumer;

Expand Down Expand Up @@ -179,19 +180,7 @@ public static boolean canPlayerReceive(ServerPlayer player, ResourceLocation id)
}

public static Packet<ClientGamePacketListener> createAddEntityPacket(Entity entity) {
try {
// I love forge
Constructor<?> constructor = Class.forName("net.minecraftforge.network.packets.SpawnEntity").getDeclaredConstructor(Entity.class);
constructor.setAccessible(true);
Object message = constructor.newInstance(entity);
Packet<ClientGamePacketListener>[] packet = new Packet[1];
NetworkInitialization.PLAY.send(message, new PacketDistributor.PacketTarget(p -> {
packet[0] = (Packet<ClientGamePacketListener>) p;
}, NetworkDirection.PLAY_TO_CLIENT));
return Objects.requireNonNull(packet[0], "Expected packet to be sent!");
} catch (InstantiationException | ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
throw new RuntimeException(e);
}
return ForgeHooks.getEntitySpawnPacket(entity);
}

static FriendlyByteBuf sendSyncPacket(Map<ResourceLocation, NetworkReceiver> map) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"client": [
],
"mixins": [
"minecraftforge.MixinChunkSerializer"
"minecraftforge.MixinChunkSerializer",
"minecraftforge.MixinEntitySpawnExtension"
],
"injectors": {
"defaultRequire": 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,24 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

package dev.architectury.hooks.level.fabric;
package dev.architectury.networking.forge;

import net.minecraft.world.level.Explosion;
import net.minecraft.world.phys.Vec3;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceLocation;

public class ExplosionHooksImpl {
public static Vec3 getPosition(Explosion explosion) {
return ((ExplosionExtensions) explosion).architectury_getPosition();
/**
* Wraps a {@link FriendlyByteBuf} because NeoForge doesn't easily let us use the buf directly.
*/
public record BufCustomPacketPayload(FriendlyByteBuf buf) implements CustomPacketPayload {
@Override
public void write(FriendlyByteBuf arg) {
arg.writeBytes(buf);
}

public interface ExplosionExtensions {
Vec3 architectury_getPosition();
@SuppressWarnings("NullableProblems")
@Override
public ResourceLocation id() {
return NetworkManagerImpl.CHANNEL_ID;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.neoforge.client.event.ClientPlayerNetworkEvent;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.network.PlayNetworkDirection;
import net.neoforged.neoforge.network.handling.IPlayPayloadHandler;

import java.util.Collections;
import java.util.Set;

@OnlyIn(Dist.CLIENT)
public class ClientNetworkingManager {
public static void initClient() {
NetworkManagerImpl.CHANNEL.addListener(NetworkManagerImpl.createPacketHandler(PlayNetworkDirection.PLAY_TO_CLIENT, NetworkManagerImpl.S2C_TRANSFORMERS));
public static IPlayPayloadHandler<BufCustomPacketPayload> initClient() {
var handler = NetworkManagerImpl.createPacketHandler(NetworkManager.Side.S2C, NetworkManagerImpl.S2C_TRANSFORMERS);
NeoForge.EVENT_BUS.register(ClientNetworkingManager.class);

NetworkManagerImpl.registerS2CReceiver(NetworkManagerImpl.SYNC_IDS, Collections.emptyList(), (buffer, context) -> {
Expand All @@ -50,6 +50,8 @@ public static void initClient() {
NetworkManager.sendToServer(NetworkManagerImpl.SYNC_IDS, NetworkManagerImpl.sendSyncPacket(NetworkManagerImpl.C2S));
});
});

return handler;
}

public static Player getClientPlayer() {
Expand Down
Loading

0 comments on commit 760b2a7

Please sign in to comment.