1.20.6 works, except for forge
This commit is contained in:
parent
b574f5b509
commit
8cc0424d46
|
|
@ -58,11 +58,9 @@ public class CarryOnCommon
|
||||||
public static void registerServerPackets(Object... args)
|
public static void registerServerPackets(Object... args)
|
||||||
{
|
{
|
||||||
Services.PLATFORM.registerServerboundPacket(
|
Services.PLATFORM.registerServerboundPacket(
|
||||||
Constants.PACKET_ID_KEY_PRESSED,
|
ServerboundCarryKeyPressedPacket.TYPE,
|
||||||
0,
|
|
||||||
ServerboundCarryKeyPressedPacket.class,
|
ServerboundCarryKeyPressedPacket.class,
|
||||||
ServerboundCarryKeyPressedPacket::write,
|
ServerboundCarryKeyPressedPacket.CODEC,
|
||||||
ServerboundCarryKeyPressedPacket::new,
|
|
||||||
ServerboundCarryKeyPressedPacket::handle,
|
ServerboundCarryKeyPressedPacket::handle,
|
||||||
args
|
args
|
||||||
);
|
);
|
||||||
|
|
@ -71,21 +69,17 @@ public class CarryOnCommon
|
||||||
public static void registerClientPackets(Object... args)
|
public static void registerClientPackets(Object... args)
|
||||||
{
|
{
|
||||||
Services.PLATFORM.registerClientboundPacket(
|
Services.PLATFORM.registerClientboundPacket(
|
||||||
Constants.PACKET_ID_START_RIDING,
|
ClientboundStartRidingPacket.TYPE,
|
||||||
1,
|
|
||||||
ClientboundStartRidingPacket.class,
|
ClientboundStartRidingPacket.class,
|
||||||
ClientboundStartRidingPacket::write,
|
ClientboundStartRidingPacket.CODEC,
|
||||||
ClientboundStartRidingPacket::new,
|
|
||||||
ClientboundStartRidingPacket::handle,
|
ClientboundStartRidingPacket::handle,
|
||||||
args
|
args
|
||||||
);
|
);
|
||||||
|
|
||||||
Services.PLATFORM.registerClientboundPacket(
|
Services.PLATFORM.registerClientboundPacket(
|
||||||
Constants.PACKET_ID_SYNC_SCRIPTS,
|
ClientboundSyncScriptsPacket.TYPE,
|
||||||
2,
|
|
||||||
ClientboundSyncScriptsPacket.class,
|
ClientboundSyncScriptsPacket.class,
|
||||||
ClientboundSyncScriptsPacket::write,
|
ClientboundSyncScriptsPacket.CODEC,
|
||||||
ClientboundSyncScriptsPacket::new,
|
|
||||||
ClientboundSyncScriptsPacket::handle,
|
ClientboundSyncScriptsPacket::handle,
|
||||||
args
|
args
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -202,6 +202,10 @@ public class CarryOnData {
|
||||||
this.activeScript = null;
|
this.activeScript = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CarryOnData clone() {
|
||||||
|
return new CarryOnData(nbt.copy());
|
||||||
|
}
|
||||||
|
|
||||||
public int getTick()
|
public int getTick()
|
||||||
{
|
{
|
||||||
if(!this.nbt.contains("tick"))
|
if(!this.nbt.contains("tick"))
|
||||||
|
|
|
||||||
|
|
@ -28,21 +28,21 @@ import net.minecraft.world.entity.player.Player;
|
||||||
|
|
||||||
public class CarryOnDataManager {
|
public class CarryOnDataManager {
|
||||||
|
|
||||||
public static final EntityDataAccessor<CompoundTag> CARRY_DATA_KEY = SynchedEntityData.defineId(Player.class, EntityDataSerializers.COMPOUND_TAG);
|
|
||||||
|
|
||||||
|
|
||||||
public static CarryOnData getCarryData(Player player)
|
public static CarryOnData getCarryData(Player player)
|
||||||
{
|
{
|
||||||
CompoundTag data = player.getEntityData().get(CARRY_DATA_KEY);
|
return ((ICarrying)player).getCarryOnData();
|
||||||
return new CarryOnData(data.copy());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setCarryData(Player player, CarryOnData data)
|
public static void setCarryData(Player player, CarryOnData data)
|
||||||
{
|
{
|
||||||
data.setSelected(player.getInventory().selected);
|
((ICarrying)player).setCarryOnData(data);
|
||||||
CompoundTag nbt = data.getNbt();
|
}
|
||||||
nbt.putInt("tick", player.tickCount);
|
|
||||||
player.getEntityData().set(CARRY_DATA_KEY, nbt);
|
public interface ICarrying {
|
||||||
|
|
||||||
|
void setCarryOnData(CarryOnData data);
|
||||||
|
|
||||||
|
CarryOnData getCarryOnData();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.level.block.Blocks;
|
import net.minecraft.world.level.block.Blocks;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
|
import org.spongepowered.asm.mixin.Unique;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||||
|
|
@ -38,6 +39,7 @@ import tschipp.carryon.common.carry.CarryOnDataManager;
|
||||||
@Mixin(Inventory.class)
|
@Mixin(Inventory.class)
|
||||||
public class InventoryMixin
|
public class InventoryMixin
|
||||||
{
|
{
|
||||||
|
@Unique
|
||||||
private static final ItemStack DUMMY_STACK = new ItemStack(Blocks.COBBLESTONE, 1);
|
private static final ItemStack DUMMY_STACK = new ItemStack(Blocks.COBBLESTONE, 1);
|
||||||
|
|
||||||
@Shadow
|
@Shadow
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
package tschipp.carryon.mixin;
|
package tschipp.carryon.mixin;
|
||||||
|
|
||||||
import com.llamalad7.mixinextras.injector.WrapWithCondition;
|
import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.world.entity.player.Inventory;
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
|
|
||||||
|
|
@ -22,12 +22,17 @@ package tschipp.carryon.mixin;
|
||||||
|
|
||||||
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.network.syncher.EntityDataAccessor;
|
||||||
|
import net.minecraft.network.syncher.EntityDataSerializers;
|
||||||
import net.minecraft.network.syncher.SynchedEntityData;
|
import net.minecraft.network.syncher.SynchedEntityData;
|
||||||
import net.minecraft.world.entity.EntityType;
|
import net.minecraft.world.entity.EntityType;
|
||||||
import net.minecraft.world.entity.LivingEntity;
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
|
import org.spongepowered.asm.mixin.Unique;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
@ -35,17 +40,42 @@ import tschipp.carryon.common.carry.CarryOnData;
|
||||||
import tschipp.carryon.common.carry.CarryOnDataManager;
|
import tschipp.carryon.common.carry.CarryOnDataManager;
|
||||||
|
|
||||||
@Mixin(Player.class)
|
@Mixin(Player.class)
|
||||||
public abstract class PlayerMixin extends LivingEntity {
|
public abstract class PlayerMixin extends LivingEntity implements CarryOnDataManager.ICarrying {
|
||||||
|
|
||||||
|
@Unique
|
||||||
|
private static final EntityDataAccessor<CompoundTag> CARRY_DATA_KEY = SynchedEntityData.defineId(Player.class, EntityDataSerializers.COMPOUND_TAG);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCarryOnData(CarryOnData data)
|
||||||
|
{
|
||||||
|
data.setSelected(this.getInventory().selected);
|
||||||
|
CompoundTag nbt = data.getNbt();
|
||||||
|
nbt.putInt("tick", tickCount);
|
||||||
|
this.getEntityData().set(CARRY_DATA_KEY, nbt);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CarryOnData getCarryOnData()
|
||||||
|
{
|
||||||
|
CompoundTag data = this.getEntityData().get(CARRY_DATA_KEY);
|
||||||
|
return new CarryOnData(data.copy());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Shadow
|
||||||
|
public abstract Inventory getInventory();
|
||||||
|
|
||||||
|
|
||||||
private PlayerMixin(EntityType<? extends LivingEntity> type, Level level) {
|
private PlayerMixin(EntityType<? extends LivingEntity> type, Level level) {
|
||||||
super(type, level);
|
super(type, level);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Inject(method = "defineSynchedData(Lnet/minecraft/network/syncher/SynchedEntityData$Builder;)V", at = @At("RETURN"))
|
@Inject(method = "defineSynchedData(Lnet/minecraft/network/syncher/SynchedEntityData$Builder;)V", at = @At("RETURN"))
|
||||||
private void onDefineSynchedData(SynchedEntityData.Builder builder, CallbackInfo ci) {
|
private void onDefineSynchedData(SynchedEntityData.Builder builder, CallbackInfo ci) {
|
||||||
builder.define(CarryOnDataManager.CARRY_DATA_KEY, new CompoundTag());
|
builder.define(CARRY_DATA_KEY, new CompoundTag());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Inject(method = "addAdditionalSaveData(Lnet/minecraft/nbt/CompoundTag;)V", at = @At("RETURN"))
|
@Inject(method = "addAdditionalSaveData(Lnet/minecraft/nbt/CompoundTag;)V", at = @At("RETURN"))
|
||||||
private void onAddAdditionalSaveData(CompoundTag tag, CallbackInfo info)
|
private void onAddAdditionalSaveData(CompoundTag tag, CallbackInfo info)
|
||||||
{
|
{
|
||||||
|
|
@ -58,7 +88,7 @@ public abstract class PlayerMixin extends LivingEntity {
|
||||||
{
|
{
|
||||||
if (tag.contains("CarryOnData")) {
|
if (tag.contains("CarryOnData")) {
|
||||||
CarryOnData data = new CarryOnData(tag.getCompound("CarryOnData"));
|
CarryOnData data = new CarryOnData(tag.getCompound("CarryOnData"));
|
||||||
CarryOnDataManager.setCarryData((Player) (Object) this, data);
|
setCarryOnData(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,14 +21,14 @@
|
||||||
package tschipp.carryon.networking;
|
package tschipp.carryon.networking;
|
||||||
|
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
|
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||||
|
import net.minecraft.network.codec.StreamCodec;
|
||||||
|
import net.minecraft.network.protocol.Packet;
|
||||||
|
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
|
||||||
public interface PacketBase
|
public interface PacketBase extends CustomPacketPayload {
|
||||||
{
|
|
||||||
void write(FriendlyByteBuf buf);
|
|
||||||
|
|
||||||
void handle(Player player);
|
void handle(Player player);
|
||||||
|
|
||||||
ResourceLocation id();
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,10 @@
|
||||||
package tschipp.carryon.networking.clientbound;
|
package tschipp.carryon.networking.clientbound;
|
||||||
|
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
|
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||||
|
import net.minecraft.network.codec.ByteBufCodecs;
|
||||||
|
import net.minecraft.network.codec.StreamCodec;
|
||||||
|
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
|
@ -29,17 +33,13 @@ import tschipp.carryon.networking.PacketBase;
|
||||||
|
|
||||||
public record ClientboundStartRidingPacket(int iden, boolean ride) implements PacketBase
|
public record ClientboundStartRidingPacket(int iden, boolean ride) implements PacketBase
|
||||||
{
|
{
|
||||||
public ClientboundStartRidingPacket(FriendlyByteBuf buf)
|
public static final StreamCodec<RegistryFriendlyByteBuf, ClientboundStartRidingPacket> CODEC = StreamCodec.composite(
|
||||||
{
|
ByteBufCodecs.INT, ClientboundStartRidingPacket::iden,
|
||||||
this(buf.readInt(), buf.readBoolean());
|
ByteBufCodecs.BOOL, ClientboundStartRidingPacket::ride,
|
||||||
}
|
ClientboundStartRidingPacket::new
|
||||||
|
);
|
||||||
|
|
||||||
@Override
|
public static final CustomPacketPayload.Type<ClientboundStartRidingPacket> TYPE = new Type<>(Constants.PACKET_ID_START_RIDING);
|
||||||
public void write(FriendlyByteBuf buf)
|
|
||||||
{
|
|
||||||
buf.writeInt(iden);
|
|
||||||
buf.writeBoolean(ride);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(Player player)
|
public void handle(Player player)
|
||||||
|
|
@ -53,7 +53,7 @@ public record ClientboundStartRidingPacket(int iden, boolean ride) implements Pa
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResourceLocation id() {
|
public Type<ClientboundStartRidingPacket> type() {
|
||||||
return Constants.PACKET_ID_START_RIDING;
|
return TYPE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
package tschipp.carryon.networking.clientbound;
|
||||||
|
|
||||||
|
import tschipp.carryon.common.carry.CarryOnData;
|
||||||
|
|
||||||
|
public record ClientboundSyncCarryDataPacket(CarryOnData data) {
|
||||||
|
}
|
||||||
|
|
@ -26,6 +26,11 @@ import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.nbt.NbtOps;
|
import net.minecraft.nbt.NbtOps;
|
||||||
import net.minecraft.nbt.Tag;
|
import net.minecraft.nbt.Tag;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
|
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||||
|
import net.minecraft.network.codec.ByteBufCodecs;
|
||||||
|
import net.minecraft.network.codec.StreamCodec;
|
||||||
|
import net.minecraft.network.protocol.Packet;
|
||||||
|
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import tschipp.carryon.Constants;
|
import tschipp.carryon.Constants;
|
||||||
|
|
@ -37,18 +42,12 @@ import java.util.List;
|
||||||
|
|
||||||
public record ClientboundSyncScriptsPacket(Tag serialized) implements PacketBase
|
public record ClientboundSyncScriptsPacket(Tag serialized) implements PacketBase
|
||||||
{
|
{
|
||||||
public ClientboundSyncScriptsPacket(FriendlyByteBuf buf)
|
public static final StreamCodec<RegistryFriendlyByteBuf, ClientboundSyncScriptsPacket> CODEC = StreamCodec.composite(
|
||||||
{
|
ByteBufCodecs.TAG, ClientboundSyncScriptsPacket::serialized,
|
||||||
this(buf.readNbt().get("data"));
|
ClientboundSyncScriptsPacket::new
|
||||||
}
|
);
|
||||||
|
|
||||||
@Override
|
public static final CustomPacketPayload.Type<ClientboundSyncScriptsPacket> TYPE = new Type<>(Constants.PACKET_ID_SYNC_SCRIPTS);
|
||||||
public void write(FriendlyByteBuf buf)
|
|
||||||
{
|
|
||||||
CompoundTag tag = new CompoundTag();
|
|
||||||
tag.put("data", serialized);
|
|
||||||
buf.writeNbt(tag);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(Player player)
|
public void handle(Player player)
|
||||||
|
|
@ -60,7 +59,7 @@ public record ClientboundSyncScriptsPacket(Tag serialized) implements PacketBase
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResourceLocation id() {
|
public Type<ClientboundSyncScriptsPacket> type() {
|
||||||
return Constants.PACKET_ID_SYNC_SCRIPTS;
|
return TYPE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,10 @@
|
||||||
package tschipp.carryon.networking.serverbound;
|
package tschipp.carryon.networking.serverbound;
|
||||||
|
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
|
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||||
|
import net.minecraft.network.codec.ByteBufCodecs;
|
||||||
|
import net.minecraft.network.codec.StreamCodec;
|
||||||
|
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
|
@ -28,19 +32,17 @@ import tschipp.carryon.Constants;
|
||||||
import tschipp.carryon.common.carry.CarryOnData;
|
import tschipp.carryon.common.carry.CarryOnData;
|
||||||
import tschipp.carryon.common.carry.CarryOnDataManager;
|
import tschipp.carryon.common.carry.CarryOnDataManager;
|
||||||
import tschipp.carryon.networking.PacketBase;
|
import tschipp.carryon.networking.PacketBase;
|
||||||
|
import tschipp.carryon.networking.clientbound.ClientboundStartRidingPacket;
|
||||||
|
import tschipp.carryon.networking.clientbound.ClientboundSyncScriptsPacket;
|
||||||
|
|
||||||
public record ServerboundCarryKeyPressedPacket(boolean pressed) implements PacketBase
|
public record ServerboundCarryKeyPressedPacket(boolean pressed) implements PacketBase
|
||||||
{
|
{
|
||||||
public ServerboundCarryKeyPressedPacket(FriendlyByteBuf buf)
|
public static final StreamCodec<RegistryFriendlyByteBuf, ServerboundCarryKeyPressedPacket> CODEC = StreamCodec.composite(
|
||||||
{
|
ByteBufCodecs.BOOL, ServerboundCarryKeyPressedPacket::pressed,
|
||||||
this(buf.readBoolean());
|
ServerboundCarryKeyPressedPacket::new
|
||||||
}
|
);
|
||||||
|
|
||||||
@Override
|
public static final CustomPacketPayload.Type<ServerboundCarryKeyPressedPacket> TYPE = new Type<>(Constants.PACKET_ID_KEY_PRESSED);
|
||||||
public void write(FriendlyByteBuf buf)
|
|
||||||
{
|
|
||||||
buf.writeBoolean(pressed);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(Player player)
|
public void handle(Player player)
|
||||||
|
|
@ -51,7 +53,7 @@ public record ServerboundCarryKeyPressedPacket(boolean pressed) implements Packe
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResourceLocation id() {
|
public Type<ServerboundCarryKeyPressedPacket> type() {
|
||||||
return Constants.PACKET_ID_KEY_PRESSED;
|
return TYPE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,9 @@ package tschipp.carryon.platform.services;
|
||||||
|
|
||||||
import net.minecraft.core.HolderLookup;
|
import net.minecraft.core.HolderLookup;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
|
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||||
|
import net.minecraft.network.codec.StreamCodec;
|
||||||
|
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
|
@ -57,9 +60,9 @@ public interface IPlatformHelper {
|
||||||
|
|
||||||
void registerConfig(BuiltConfig cfg);
|
void registerConfig(BuiltConfig cfg);
|
||||||
|
|
||||||
<T extends PacketBase> void registerServerboundPacket(ResourceLocation id, int numericalId, Class<T> clazz, BiConsumer<T, FriendlyByteBuf> writer, Function<FriendlyByteBuf, T> reader, BiConsumer<T, Player> handler, Object... args);
|
<T extends PacketBase, B extends FriendlyByteBuf> void registerServerboundPacket(CustomPacketPayload.Type<T> type, Class<T> clazz, StreamCodec<B, T> codec, BiConsumer<T, Player> handler, Object... args);
|
||||||
|
|
||||||
<T extends PacketBase> void registerClientboundPacket(ResourceLocation id, int numericalId, Class<T> clazz, BiConsumer<T, FriendlyByteBuf> writer, Function<FriendlyByteBuf, T> reader, BiConsumer<T, Player> handler, Object... args);
|
<T extends PacketBase, B extends FriendlyByteBuf> void registerClientboundPacket(CustomPacketPayload.Type<T> type, Class<T> clazz, StreamCodec<B, T> codec, BiConsumer<T, Player> handler, Object... args);
|
||||||
|
|
||||||
void sendPacketToServer(ResourceLocation id, PacketBase packet);
|
void sendPacketToServer(ResourceLocation id, PacketBase packet);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,11 @@ import net.fabricmc.api.ClientModInitializer;
|
||||||
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
|
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
|
||||||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
||||||
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
|
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
|
||||||
|
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
||||||
|
import net.minecraft.core.RegistryAccess;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
|
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||||
|
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import tschipp.carryon.client.keybinds.CarryOnKeybinds;
|
import tschipp.carryon.client.keybinds.CarryOnKeybinds;
|
||||||
|
|
@ -44,19 +48,16 @@ public class CarryOnFabricClientMod implements ClientModInitializer
|
||||||
CarryOnCommon.registerClientPackets();
|
CarryOnCommon.registerClientPackets();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendPacketToServer(ResourceLocation id, PacketBase packet)
|
public static void sendPacketToServer(PacketBase packet)
|
||||||
{
|
{
|
||||||
FriendlyByteBuf buf = PacketByteBufs.create();
|
ClientPlayNetworking.send(packet);
|
||||||
packet.write(buf);
|
|
||||||
ClientPlayNetworking.send(id, buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T extends PacketBase> void registerClientboundPacket(ResourceLocation id, Function<FriendlyByteBuf, T> reader, BiConsumer<T, Player> handler)
|
public static <T extends PacketBase> void registerClientboundPacket(CustomPacketPayload.Type<T> id, BiConsumer<T, Player> handler)
|
||||||
{
|
{
|
||||||
ClientPlayNetworking.registerGlobalReceiver(id, (client, packetHandler, buf, responseSender) -> {
|
ClientPlayNetworking.registerGlobalReceiver(id, (T packet, ClientPlayNetworking.Context context) -> {
|
||||||
T packet = reader.apply(buf);
|
context.client().execute(() -> {
|
||||||
client.execute(() -> {
|
handler.accept(packet, context.player());
|
||||||
handler.accept(packet, client.player);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@
|
||||||
|
|
||||||
package tschipp.carryon.mixin;
|
package tschipp.carryon.mixin;
|
||||||
|
|
||||||
|
import com.llamalad7.mixinextras.sugar.Local;
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
import net.minecraft.client.Camera;
|
import net.minecraft.client.Camera;
|
||||||
import net.minecraft.client.renderer.GameRenderer;
|
import net.minecraft.client.renderer.GameRenderer;
|
||||||
|
|
@ -35,9 +36,9 @@ import tschipp.carryon.client.render.CarriedObjectRender;
|
||||||
@Mixin(LevelRenderer.class)
|
@Mixin(LevelRenderer.class)
|
||||||
public class LevelRendererMixin
|
public class LevelRendererMixin
|
||||||
{
|
{
|
||||||
@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/particle/ParticleEngine;render(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;Lnet/minecraft/client/renderer/LightTexture;Lnet/minecraft/client/Camera;F)V"), method = "Lnet/minecraft/client/renderer/LevelRenderer;renderLevel(Lcom/mojang/blaze3d/vertex/PoseStack;FJZLnet/minecraft/client/Camera;Lnet/minecraft/client/renderer/GameRenderer;Lnet/minecraft/client/renderer/LightTexture;Lorg/joml/Matrix4f;)V")
|
@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/particle/ParticleEngine;render(Lnet/minecraft/client/renderer/LightTexture;Lnet/minecraft/client/Camera;F)V"), method = "renderLevel(FJZLnet/minecraft/client/Camera;Lnet/minecraft/client/renderer/GameRenderer;Lnet/minecraft/client/renderer/LightTexture;Lorg/joml/Matrix4f;Lorg/joml/Matrix4f;)V")
|
||||||
private void onRenderLevel(PoseStack poseStack, float f, long l, boolean bl, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f matrix4f, CallbackInfo ci)
|
private void onRenderLevel(float partialTick, long nanoTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f frustumMatrix, Matrix4f projectionMatrix, CallbackInfo ci, @Local PoseStack poseStack)
|
||||||
{
|
{
|
||||||
CarriedObjectRender.drawThirdPerson(gameRenderer.getMinecraft().getFrameTime(), poseStack);
|
CarriedObjectRender.drawThirdPerson(gameRenderer.getMinecraft().getFrameTime(), poseStack.last().pose());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,9 +21,16 @@
|
||||||
package tschipp.carryon.platform;
|
package tschipp.carryon.platform;
|
||||||
|
|
||||||
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
|
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
|
||||||
|
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
|
||||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
||||||
|
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking.PlayPayloadHandler;
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
|
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||||
|
import net.minecraft.network.codec.StreamCodec;
|
||||||
|
import net.minecraft.network.codec.StreamDecoder;
|
||||||
|
import net.minecraft.network.codec.StreamMemberEncoder;
|
||||||
|
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
|
@ -61,33 +68,34 @@ public class FabricPlatformHelper implements IPlatformHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T extends PacketBase> void registerServerboundPacket(ResourceLocation id, int numericalId, Class<T> clazz, BiConsumer<T, FriendlyByteBuf> writer, Function<FriendlyByteBuf, T> reader, BiConsumer<T, Player> handler, Object... args)
|
public <T extends PacketBase, B extends FriendlyByteBuf> void registerServerboundPacket(CustomPacketPayload.Type<T> type, Class<T> clazz, StreamCodec<B, T> codec, BiConsumer<T, Player> handler, Object... args)
|
||||||
{
|
{
|
||||||
ServerPlayNetworking.registerGlobalReceiver(id, (server, player, packetHandler, buf, responseSender) -> {
|
PayloadTypeRegistry.playC2S().register(type, (StreamCodec<RegistryFriendlyByteBuf, T>)codec);
|
||||||
T packet = reader.apply(buf);
|
|
||||||
server.execute(() -> {
|
ServerPlayNetworking.registerGlobalReceiver(type, (T packet, ServerPlayNetworking.Context context) -> {
|
||||||
handler.accept(packet, player);
|
context.server().execute(() -> {
|
||||||
|
handler.accept(packet, context.player());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T extends PacketBase> void registerClientboundPacket(ResourceLocation id, int numericalId, Class<T> clazz, BiConsumer<T, FriendlyByteBuf> writer, Function<FriendlyByteBuf, T> reader, BiConsumer<T, Player> handler, Object... args)
|
public <T extends PacketBase, B extends FriendlyByteBuf> void registerClientboundPacket(CustomPacketPayload.Type<T> type, Class<T> clazz, StreamCodec<B, T> codec, BiConsumer<T, Player> handler, Object... args)
|
||||||
{
|
{
|
||||||
CarryOnFabricClientMod.registerClientboundPacket(id, reader, handler);
|
PayloadTypeRegistry.playS2C().register(type, (StreamCodec<RegistryFriendlyByteBuf, T>)codec);
|
||||||
|
|
||||||
|
CarryOnFabricClientMod.registerClientboundPacket(type, handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendPacketToServer(ResourceLocation id, PacketBase packet)
|
public void sendPacketToServer(ResourceLocation id, PacketBase packet)
|
||||||
{
|
{
|
||||||
CarryOnFabricClientMod.sendPacketToServer(id, packet);
|
CarryOnFabricClientMod.sendPacketToServer(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendPacketToPlayer(ResourceLocation id, PacketBase packet, ServerPlayer player)
|
public void sendPacketToPlayer(ResourceLocation id, PacketBase packet, ServerPlayer player)
|
||||||
{
|
{
|
||||||
FriendlyByteBuf buf = PacketByteBufs.create();
|
ServerPlayNetworking.send(player, packet);
|
||||||
packet.write(buf);
|
|
||||||
ServerPlayNetworking.send(player, id, buf);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -102,10 +102,10 @@ repositories {
|
||||||
dependencies {
|
dependencies {
|
||||||
minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"
|
minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"
|
||||||
compileOnly project(":Common")
|
compileOnly project(":Common")
|
||||||
implementation(annotationProcessor("io.github.llamalad7:mixinextras-common:${mixinextras_version}"))
|
compileOnly(annotationProcessor("io.github.llamalad7:mixinextras-common:${mixinextras_version}"))
|
||||||
implementation(jarJar("io.github.llamalad7:mixinextras-forge:${mixinextras_version}")) {
|
runtimeOnly(annotationProcessor("io.github.llamalad7:mixinextras-forge:${mixinextras_version}"))
|
||||||
jarJar.ranged(it, "[${mixinextras_version},)")
|
jarJar(group: 'io.github.llamalad7', name: 'mixinextras-forge', version: "[${mixinextras_version},)")
|
||||||
}
|
|
||||||
//implementation fg.deobf("net.darkhax.gamestages:GameStages-Forge-1.19.2:11.0.2")
|
//implementation fg.deobf("net.darkhax.gamestages:GameStages-Forge-1.19.2:11.0.2")
|
||||||
//implementation fg.deobf("net.darkhax.bookshelf:Bookshelf-Forge-1.19.3:17.0.2")
|
//implementation fg.deobf("net.darkhax.bookshelf:Bookshelf-Forge-1.19.3:17.0.2")
|
||||||
annotationProcessor 'org.spongepowered:mixin:0.8.5-SNAPSHOT:processor'
|
annotationProcessor 'org.spongepowered:mixin:0.8.5-SNAPSHOT:processor'
|
||||||
|
|
|
||||||
|
|
@ -61,26 +61,26 @@ public class ConfigLoaderImpl {
|
||||||
public static void onConfigLoad(ModConfigEvent.Loading loading) {
|
public static void onConfigLoad(ModConfigEvent.Loading loading) {
|
||||||
loadConfig(loading.getConfig().getSpec());
|
loadConfig(loading.getConfig().getSpec());
|
||||||
|
|
||||||
|
//
|
||||||
DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> () -> {
|
// DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> () -> {
|
||||||
ConfigLoader.onConfigLoaded(Minecraft.getInstance().level.registryAccess());
|
// ConfigLoader.onConfigLoaded(Minecraft.getInstance().level.registryAccess());
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
DistExecutor.safeRunWhenOn(Dist.DEDICATED_SERVER, () -> () -> {
|
// DistExecutor.safeRunWhenOn(Dist.DEDICATED_SERVER, () -> () -> {
|
||||||
ConfigLoader.onConfigLoaded(ServerLifecycleHooks.getCurrentServer().registryAccess());
|
// ConfigLoader.onConfigLoaded(ServerLifecycleHooks.getCurrentServer().registryAccess());
|
||||||
});
|
// });
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void onConfigReload(ModConfigEvent.Reloading loading) {
|
public static void onConfigReload(ModConfigEvent.Reloading loading) {
|
||||||
loadConfig(loading.getConfig().getSpec());
|
loadConfig(loading.getConfig().getSpec());
|
||||||
|
//
|
||||||
DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> () -> {
|
// DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> () -> {
|
||||||
ConfigLoader.onConfigLoaded(Minecraft.getInstance().level.registryAccess());
|
// ConfigLoader.onConfigLoaded(Minecraft.getInstance().level.registryAccess());
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
DistExecutor.safeRunWhenOn(Dist.DEDICATED_SERVER, () -> () -> {
|
// DistExecutor.safeRunWhenOn(Dist.DEDICATED_SERVER, () -> () -> {
|
||||||
ConfigLoader.onConfigLoaded(ServerLifecycleHooks.getCurrentServer().registryAccess());
|
// ConfigLoader.onConfigLoaded(ServerLifecycleHooks.getCurrentServer().registryAccess());
|
||||||
});
|
// });
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void loadConfig(IConfigSpec<ForgeConfigSpec> spec) {
|
private static void loadConfig(IConfigSpec<ForgeConfigSpec> spec) {
|
||||||
|
|
|
||||||
|
|
@ -42,10 +42,9 @@ import tschipp.carryon.client.render.CarryRenderHelper;
|
||||||
import tschipp.carryon.common.carry.CarryOnData;
|
import tschipp.carryon.common.carry.CarryOnData;
|
||||||
import tschipp.carryon.common.carry.CarryOnDataManager;
|
import tschipp.carryon.common.carry.CarryOnDataManager;
|
||||||
|
|
||||||
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE, modid = Constants.MOD_ID, value = Dist.CLIENT)
|
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE, modid = Constants.MOD_ID)
|
||||||
public class ClientEvents {
|
public class ClientEvents {
|
||||||
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void renderHand(RenderHandEvent event)
|
public static void renderHand(RenderHandEvent event)
|
||||||
{
|
{
|
||||||
|
|
@ -59,7 +58,6 @@ public class ClientEvents {
|
||||||
event.setCanceled(true);
|
event.setCanceled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onRenderLevel(RenderLevelStageEvent event)
|
public static void onRenderLevel(RenderLevelStageEvent event)
|
||||||
{
|
{
|
||||||
|
|
@ -67,7 +65,6 @@ public class ClientEvents {
|
||||||
CarriedObjectRender.drawThirdPerson(event.getPartialTick(), event.getPoseStack());
|
CarriedObjectRender.drawThirdPerson(event.getPartialTick(), event.getPoseStack());
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onGuiInit(ScreenEvent.Init.Pre event)
|
public static void onGuiInit(ScreenEvent.Init.Pre event)
|
||||||
{
|
{
|
||||||
|
|
@ -91,7 +88,6 @@ public class ClientEvents {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onClientTick(ClientTickEvent.Post event)
|
public static void onClientTick(ClientTickEvent.Post event)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -29,10 +29,9 @@ import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
|
||||||
import tschipp.carryon.Constants;
|
import tschipp.carryon.Constants;
|
||||||
import tschipp.carryon.client.keybinds.CarryOnKeybinds;
|
import tschipp.carryon.client.keybinds.CarryOnKeybinds;
|
||||||
|
|
||||||
@Mod.EventBusSubscriber(bus = Bus.MOD, modid = Constants.MOD_ID, value = Dist.CLIENT)
|
@Mod.EventBusSubscriber(bus = Bus.MOD, modid = Constants.MOD_ID)
|
||||||
public class ModClientEvents
|
public class ModClientEvents
|
||||||
{
|
{
|
||||||
@OnlyIn(Dist.CLIENT)
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void registerKeybinds(RegisterKeyMappingsEvent event)
|
public static void registerKeybinds(RegisterKeyMappingsEvent event)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,9 @@
|
||||||
package tschipp.carryon.platform;
|
package tschipp.carryon.platform;
|
||||||
|
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
|
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||||
|
import net.minecraft.network.codec.StreamCodec;
|
||||||
|
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
|
@ -65,10 +68,10 @@ public class ForgePlatformHelper implements IPlatformHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T extends PacketBase> void registerServerboundPacket(ResourceLocation id, int numericalId, Class<T> clazz, BiConsumer<T, FriendlyByteBuf> writer, Function<FriendlyByteBuf, T> reader, BiConsumer<T, Player> handler, Object... args)
|
public <T extends PacketBase, B extends FriendlyByteBuf> void registerServerboundPacket(CustomPacketPayload.Type<T> type, Class<T> clazz, StreamCodec<B, T> codec, BiConsumer<T, Player> handler, Object... args)
|
||||||
{
|
{
|
||||||
BiConsumer<T, CustomPayloadEvent.Context> serverHandler = (packet, ctx) -> {
|
BiConsumer<T, CustomPayloadEvent.Context> serverHandler = (packet, ctx) -> {
|
||||||
if(ctx.getDirection().getReceptionSide().isServer())
|
if(ctx.isServerSide())
|
||||||
{
|
{
|
||||||
ctx.setPacketHandled(true);
|
ctx.setPacketHandled(true);
|
||||||
ctx.enqueueWork(() -> {
|
ctx.enqueueWork(() -> {
|
||||||
|
|
@ -77,18 +80,14 @@ public class ForgePlatformHelper implements IPlatformHelper {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
CarryOnForge.network.messageBuilder(clazz, numericalId, NetworkDirection.PLAY_TO_SERVER)
|
CarryOnForge.network.messageBuilder(clazz).codec((StreamCodec<FriendlyByteBuf, T>) codec).consumerMainThread(serverHandler).add();
|
||||||
.encoder(writer)
|
|
||||||
.decoder(reader)
|
|
||||||
.consumerMainThread(serverHandler)
|
|
||||||
.add();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T extends PacketBase> void registerClientboundPacket(ResourceLocation id, int numericalId, Class<T> clazz, BiConsumer<T, FriendlyByteBuf> writer, Function<FriendlyByteBuf, T> reader, BiConsumer<T, Player> handler, Object... args)
|
public <T extends PacketBase, B extends FriendlyByteBuf> void registerClientboundPacket(CustomPacketPayload.Type<T> type, Class<T> clazz, StreamCodec<B, T> codec, BiConsumer<T, Player> handler, Object... args)
|
||||||
{
|
{
|
||||||
BiConsumer<T, CustomPayloadEvent.Context> clientHandler = (packet, ctx) -> {
|
BiConsumer<T, CustomPayloadEvent.Context> clientHandler = (packet, ctx) -> {
|
||||||
if(ctx.getDirection().getReceptionSide().isClient())
|
if(ctx.isClientSide())
|
||||||
{
|
{
|
||||||
ctx.setPacketHandled(true);
|
ctx.setPacketHandled(true);
|
||||||
ctx.enqueueWork(() -> {
|
ctx.enqueueWork(() -> {
|
||||||
|
|
@ -97,11 +96,7 @@ public class ForgePlatformHelper implements IPlatformHelper {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
CarryOnForge.network.messageBuilder(clazz, numericalId, NetworkDirection.PLAY_TO_CLIENT)
|
CarryOnForge.network.messageBuilder(clazz).codec((StreamCodec<FriendlyByteBuf, T>)codec).consumerMainThread(clientHandler).add();
|
||||||
.encoder(writer)
|
|
||||||
.decoder(reader)
|
|
||||||
.consumerMainThread(clientHandler)
|
|
||||||
.add();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,8 @@ import net.neoforged.bus.api.SubscribeEvent;
|
||||||
import net.neoforged.fml.common.Mod;
|
import net.neoforged.fml.common.Mod;
|
||||||
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
|
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||||
import net.neoforged.neoforge.common.NeoForge;
|
import net.neoforged.neoforge.common.NeoForge;
|
||||||
import net.neoforged.neoforge.network.event.RegisterPayloadHandlerEvent;
|
import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent;
|
||||||
import net.neoforged.neoforge.network.registration.IPayloadRegistrar;
|
import net.neoforged.neoforge.network.registration.PayloadRegistrar;
|
||||||
import tschipp.carryon.config.neoforge.ConfigLoaderImpl;
|
import tschipp.carryon.config.neoforge.ConfigLoaderImpl;
|
||||||
|
|
||||||
@Mod(Constants.MOD_ID)
|
@Mod(Constants.MOD_ID)
|
||||||
|
|
@ -49,10 +49,9 @@ public class CarryOnNeoForge {
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerPackets(final RegisterPayloadHandlerEvent event) {
|
public void registerPackets(final RegisterPayloadHandlersEvent event) {
|
||||||
|
|
||||||
final IPayloadRegistrar registrar = event.registrar(Constants.MOD_ID)
|
final PayloadRegistrar registrar = event.registrar("1.0.0");
|
||||||
.versioned("1.0.0");
|
|
||||||
|
|
||||||
CarryOnCommon.registerServerPackets(registrar);
|
CarryOnCommon.registerServerPackets(registrar);
|
||||||
CarryOnCommon.registerClientPackets(registrar);
|
CarryOnCommon.registerClientPackets(registrar);
|
||||||
|
|
|
||||||
|
|
@ -26,20 +26,21 @@ import net.minecraft.client.Minecraft;
|
||||||
import net.neoforged.api.distmarker.Dist;
|
import net.neoforged.api.distmarker.Dist;
|
||||||
import net.neoforged.bus.api.IEventBus;
|
import net.neoforged.bus.api.IEventBus;
|
||||||
import net.neoforged.bus.api.SubscribeEvent;
|
import net.neoforged.bus.api.SubscribeEvent;
|
||||||
import net.neoforged.fml.DistExecutor;
|
|
||||||
import net.neoforged.fml.ModLoadingContext;
|
import net.neoforged.fml.ModLoadingContext;
|
||||||
|
import net.neoforged.fml.common.EventBusSubscriber;
|
||||||
import net.neoforged.fml.common.Mod;
|
import net.neoforged.fml.common.Mod;
|
||||||
import net.neoforged.fml.config.IConfigSpec;
|
import net.neoforged.fml.config.IConfigSpec;
|
||||||
import net.neoforged.fml.config.ModConfig;
|
import net.neoforged.fml.config.ModConfig;
|
||||||
import net.neoforged.fml.event.config.ModConfigEvent;
|
import net.neoforged.fml.event.config.ModConfigEvent;
|
||||||
import net.neoforged.neoforge.common.ModConfigSpec;
|
import net.neoforged.neoforge.common.ModConfigSpec;
|
||||||
import net.neoforged.neoforge.common.NeoForge;
|
import net.neoforged.neoforge.common.NeoForge;
|
||||||
|
import net.neoforged.neoforge.server.ServerLifecycleHooks;
|
||||||
import tschipp.carryon.Constants;
|
import tschipp.carryon.Constants;
|
||||||
import tschipp.carryon.config.*;
|
import tschipp.carryon.config.*;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@Mod.EventBusSubscriber(modid = Constants.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
|
@EventBusSubscriber(modid = Constants.MOD_ID, bus = EventBusSubscriber.Bus.MOD)
|
||||||
public class ConfigLoaderImpl {
|
public class ConfigLoaderImpl {
|
||||||
|
|
||||||
public static final Map<ModConfigSpec, BuiltConfig> CONFIGS = new HashMap<>();
|
public static final Map<ModConfigSpec, BuiltConfig> CONFIGS = new HashMap<>();
|
||||||
|
|
@ -57,24 +58,25 @@ public class ConfigLoaderImpl {
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onConfigLoad(ModConfigEvent.Loading loading) {
|
public static void onConfigLoad(ModConfigEvent.Loading loading) {
|
||||||
loadConfig(loading.getConfig().getSpec());
|
loadConfig(loading.getConfig().getSpec());
|
||||||
DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> () -> {
|
|
||||||
ConfigLoader.onConfigLoaded(Minecraft.getInstance().level.registryAccess());
|
|
||||||
});
|
|
||||||
|
|
||||||
DistExecutor.safeRunWhenOn(Dist.DEDICATED_SERVER, () -> () -> {
|
// DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> () -> {
|
||||||
ConfigLoader.onConfigLoaded(ServerLifecycleHooks.getCurrentServer().registryAccess());
|
// ConfigLoader.onConfigLoaded(Minecraft.getInstance().level.registryAccess());
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
|
// DistExecutor.safeRunWhenOn(Dist.DEDICATED_SERVER, () -> () -> {
|
||||||
|
// ConfigLoader.onConfigLoaded(ServerLifecycleHooks.getCurrentServer().registryAccess());
|
||||||
|
// });
|
||||||
}
|
}
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onConfigReload(ModConfigEvent.Reloading loading) {
|
public static void onConfigReload(ModConfigEvent.Reloading loading) {
|
||||||
loadConfig(loading.getConfig().getSpec());
|
loadConfig(loading.getConfig().getSpec());
|
||||||
DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> () -> {
|
// DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> () -> {
|
||||||
ConfigLoader.onConfigLoaded(Minecraft.getInstance().level.registryAccess());
|
// ConfigLoader.onConfigLoaded(Minecraft.getInstance().level.registryAccess());
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
DistExecutor.safeRunWhenOn(Dist.DEDICATED_SERVER, () -> () -> {
|
// DistExecutor.safeRunWhenOn(Dist.DEDICATED_SERVER, () -> () -> {
|
||||||
ConfigLoader.onConfigLoaded(ServerLifecycleHooks.getCurrentServer().registryAccess());
|
// ConfigLoader.onConfigLoaded(ServerLifecycleHooks.getCurrentServer().registryAccess());
|
||||||
});
|
// });
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void loadConfig(IConfigSpec<ModConfigSpec> spec) {
|
private static void loadConfig(IConfigSpec<ModConfigSpec> spec) {
|
||||||
|
|
|
||||||
|
|
@ -28,11 +28,12 @@ import net.minecraft.world.entity.player.Player;
|
||||||
import net.neoforged.api.distmarker.Dist;
|
import net.neoforged.api.distmarker.Dist;
|
||||||
import net.neoforged.api.distmarker.OnlyIn;
|
import net.neoforged.api.distmarker.OnlyIn;
|
||||||
import net.neoforged.bus.api.SubscribeEvent;
|
import net.neoforged.bus.api.SubscribeEvent;
|
||||||
|
import net.neoforged.fml.common.EventBusSubscriber;
|
||||||
import net.neoforged.fml.common.Mod;
|
import net.neoforged.fml.common.Mod;
|
||||||
|
import net.neoforged.neoforge.client.event.ClientTickEvent;
|
||||||
import net.neoforged.neoforge.client.event.RenderHandEvent;
|
import net.neoforged.neoforge.client.event.RenderHandEvent;
|
||||||
import net.neoforged.neoforge.client.event.RenderLevelStageEvent;
|
import net.neoforged.neoforge.client.event.RenderLevelStageEvent;
|
||||||
import net.neoforged.neoforge.client.event.ScreenEvent;
|
import net.neoforged.neoforge.client.event.ScreenEvent;
|
||||||
import net.neoforged.neoforge.event.TickEvent;
|
|
||||||
import tschipp.carryon.CarryOnCommonClient;
|
import tschipp.carryon.CarryOnCommonClient;
|
||||||
import tschipp.carryon.Constants;
|
import tschipp.carryon.Constants;
|
||||||
import tschipp.carryon.client.render.CarriedObjectRender;
|
import tschipp.carryon.client.render.CarriedObjectRender;
|
||||||
|
|
@ -40,7 +41,7 @@ import tschipp.carryon.client.render.CarryRenderHelper;
|
||||||
import tschipp.carryon.common.carry.CarryOnData;
|
import tschipp.carryon.common.carry.CarryOnData;
|
||||||
import tschipp.carryon.common.carry.CarryOnDataManager;
|
import tschipp.carryon.common.carry.CarryOnDataManager;
|
||||||
|
|
||||||
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE, modid = Constants.MOD_ID, value = Dist.CLIENT)
|
@EventBusSubscriber(bus = EventBusSubscriber.Bus.GAME, modid = Constants.MOD_ID, value = Dist.CLIENT)
|
||||||
public class ClientEvents {
|
public class ClientEvents {
|
||||||
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
|
|
@ -62,7 +63,7 @@ public class ClientEvents {
|
||||||
public static void onRenderLevel(RenderLevelStageEvent event)
|
public static void onRenderLevel(RenderLevelStageEvent event)
|
||||||
{
|
{
|
||||||
if(event.getStage() == RenderLevelStageEvent.Stage.AFTER_PARTICLES)
|
if(event.getStage() == RenderLevelStageEvent.Stage.AFTER_PARTICLES)
|
||||||
CarriedObjectRender.drawThirdPerson(event.getPartialTick(), event.getPoseStack());
|
CarriedObjectRender.drawThirdPerson(event.getPartialTick(), event.getPoseStack().last().pose());
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
|
|
@ -91,13 +92,9 @@ public class ClientEvents {
|
||||||
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onClientTick(TickEvent.ClientTickEvent event)
|
public static void onClientTick(ClientTickEvent.Post event)
|
||||||
{
|
{
|
||||||
if(event.phase == TickEvent.Phase.END)
|
CarryOnCommonClient.checkForKeybinds();
|
||||||
{
|
CarryOnCommonClient.onCarryClientTick();
|
||||||
CarryOnCommonClient.checkForKeybinds();
|
|
||||||
CarryOnCommonClient.onCarryClientTick();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,9 +32,11 @@ import net.minecraft.world.level.ServerLevelAccessor;
|
||||||
import net.neoforged.bus.api.Event;
|
import net.neoforged.bus.api.Event;
|
||||||
import net.neoforged.bus.api.EventPriority;
|
import net.neoforged.bus.api.EventPriority;
|
||||||
import net.neoforged.bus.api.SubscribeEvent;
|
import net.neoforged.bus.api.SubscribeEvent;
|
||||||
|
import net.neoforged.fml.common.EventBusSubscriber;
|
||||||
import net.neoforged.fml.common.Mod;
|
import net.neoforged.fml.common.Mod;
|
||||||
import net.neoforged.neoforge.common.NeoForge;
|
import net.neoforged.neoforge.common.NeoForge;
|
||||||
import net.neoforged.neoforge.common.util.BlockSnapshot;
|
import net.neoforged.neoforge.common.util.BlockSnapshot;
|
||||||
|
import net.neoforged.neoforge.common.util.TriState;
|
||||||
import net.neoforged.neoforge.event.*;
|
import net.neoforged.neoforge.event.*;
|
||||||
import net.neoforged.neoforge.event.entity.living.LivingAttackEvent;
|
import net.neoforged.neoforge.event.entity.living.LivingAttackEvent;
|
||||||
import net.neoforged.neoforge.event.entity.living.MobSpawnEvent;
|
import net.neoforged.neoforge.event.entity.living.MobSpawnEvent;
|
||||||
|
|
@ -42,6 +44,7 @@ import net.neoforged.neoforge.event.entity.player.AttackEntityEvent;
|
||||||
import net.neoforged.neoforge.event.entity.player.PlayerEvent;
|
import net.neoforged.neoforge.event.entity.player.PlayerEvent;
|
||||||
import net.neoforged.neoforge.event.entity.player.PlayerInteractEvent;
|
import net.neoforged.neoforge.event.entity.player.PlayerInteractEvent;
|
||||||
import net.neoforged.neoforge.event.level.BlockEvent;
|
import net.neoforged.neoforge.event.level.BlockEvent;
|
||||||
|
import net.neoforged.neoforge.event.tick.ServerTickEvent;
|
||||||
import tschipp.carryon.CarryOnCommon;
|
import tschipp.carryon.CarryOnCommon;
|
||||||
import tschipp.carryon.Constants;
|
import tschipp.carryon.Constants;
|
||||||
import tschipp.carryon.common.carry.CarryOnData;
|
import tschipp.carryon.common.carry.CarryOnData;
|
||||||
|
|
@ -52,7 +55,7 @@ import tschipp.carryon.common.carry.PlacementHandler;
|
||||||
import tschipp.carryon.common.scripting.ScriptReloadListener;
|
import tschipp.carryon.common.scripting.ScriptReloadListener;
|
||||||
import tschipp.carryon.config.ConfigLoader;
|
import tschipp.carryon.config.ConfigLoader;
|
||||||
|
|
||||||
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE, modid = Constants.MOD_ID)
|
@EventBusSubscriber(bus = EventBusSubscriber.Bus.GAME, modid = Constants.MOD_ID)
|
||||||
public class CommonEvents
|
public class CommonEvents
|
||||||
{
|
{
|
||||||
@SubscribeEvent(priority = EventPriority.HIGH)
|
@SubscribeEvent(priority = EventPriority.HIGH)
|
||||||
|
|
@ -90,9 +93,10 @@ public class CommonEvents
|
||||||
} else {
|
} else {
|
||||||
PlacementHandler.tryPlaceEntity((ServerPlayer) player, pos, event.getFace(), (pPos, toPlace) -> {
|
PlacementHandler.tryPlaceEntity((ServerPlayer) player, pos, event.getFace(), (pPos, toPlace) -> {
|
||||||
if (toPlace instanceof Mob mob) {
|
if (toPlace instanceof Mob mob) {
|
||||||
MobSpawnEvent.FinalizeSpawn checkSpawn = new MobSpawnEvent.FinalizeSpawn(mob, (ServerLevelAccessor) level, pPos.x, pPos.y, pPos.z, level.getCurrentDifficultyAt(new BlockPos((int) pPos.x, (int) pPos.y, (int) pPos.z)), MobSpawnType.EVENT, null, null, null);
|
mob.setPos(pPos.x, pPos.y, pPos.z);
|
||||||
|
MobSpawnEvent.PositionCheck checkSpawn = new MobSpawnEvent.PositionCheck(mob, (ServerLevelAccessor) level, MobSpawnType.EVENT, null);
|
||||||
NeoForge.EVENT_BUS.post(checkSpawn);
|
NeoForge.EVENT_BUS.post(checkSpawn);
|
||||||
return event.getResult() != Event.Result.DENY;
|
return checkSpawn.getResult() != MobSpawnEvent.PositionCheck.Result.FAIL;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
@ -101,8 +105,8 @@ public class CommonEvents
|
||||||
}
|
}
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
event.setUseBlock(Event.Result.DENY);
|
event.setUseBlock(TriState.FALSE);
|
||||||
event.setUseItem(Event.Result.DENY);
|
event.setUseItem(TriState.FALSE);
|
||||||
event.setCancellationResult(InteractionResult.SUCCESS);
|
event.setCancellationResult(InteractionResult.SUCCESS);
|
||||||
event.setCanceled(true);
|
event.setCanceled(true);
|
||||||
}
|
}
|
||||||
|
|
@ -163,15 +167,14 @@ public class CommonEvents
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onTagsUpdate(TagsUpdatedEvent event)
|
public static void onTagsUpdate(TagsUpdatedEvent event)
|
||||||
{
|
{
|
||||||
ConfigLoader.onConfigLoaded();
|
ConfigLoader.onConfigLoaded(event.getRegistryAccess());
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onServerTick(TickEvent.ServerTickEvent event)
|
public static void onServerTick(ServerTickEvent.Post event)
|
||||||
{
|
{
|
||||||
if (event.phase == TickEvent.Phase.END)
|
for (ServerPlayer player : event.getServer().getPlayerList().getPlayers())
|
||||||
for (ServerPlayer player : event.getServer().getPlayerList().getPlayers())
|
CarryOnCommon.onCarryTick(player);
|
||||||
CarryOnCommon.onCarryTick(player);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ package tschipp.carryon.events;
|
||||||
import net.neoforged.bus.api.EventPriority;
|
import net.neoforged.bus.api.EventPriority;
|
||||||
import net.neoforged.bus.api.SubscribeEvent;
|
import net.neoforged.bus.api.SubscribeEvent;
|
||||||
import net.neoforged.fml.InterModComms;
|
import net.neoforged.fml.InterModComms;
|
||||||
|
import net.neoforged.fml.common.EventBusSubscriber;
|
||||||
import net.neoforged.fml.common.Mod;
|
import net.neoforged.fml.common.Mod;
|
||||||
import net.neoforged.fml.event.lifecycle.InterModProcessEvent;
|
import net.neoforged.fml.event.lifecycle.InterModProcessEvent;
|
||||||
import tschipp.carryon.Constants;
|
import tschipp.carryon.Constants;
|
||||||
|
|
@ -31,7 +32,7 @@ import tschipp.carryon.common.config.ListHandler;
|
||||||
|
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD, modid = Constants.MOD_ID)
|
@EventBusSubscriber(bus = EventBusSubscriber.Bus.MOD, modid = Constants.MOD_ID)
|
||||||
public class ModBusEvents {
|
public class ModBusEvents {
|
||||||
|
|
||||||
@SubscribeEvent(priority = EventPriority.LOW)
|
@SubscribeEvent(priority = EventPriority.LOW)
|
||||||
|
|
@ -68,7 +69,7 @@ public class ModBusEvents {
|
||||||
ListHandler.addAllowedStacking(str);
|
ListHandler.addAllowedStacking(str);
|
||||||
break;
|
break;
|
||||||
case "addModelOverride":
|
case "addModelOverride":
|
||||||
ModelOverrideHandler.addFromString(str);
|
//ModelOverrideHandler.addFromString(str);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,12 +23,13 @@ package tschipp.carryon.events;
|
||||||
import net.neoforged.api.distmarker.Dist;
|
import net.neoforged.api.distmarker.Dist;
|
||||||
import net.neoforged.api.distmarker.OnlyIn;
|
import net.neoforged.api.distmarker.OnlyIn;
|
||||||
import net.neoforged.bus.api.SubscribeEvent;
|
import net.neoforged.bus.api.SubscribeEvent;
|
||||||
|
import net.neoforged.fml.common.EventBusSubscriber;
|
||||||
import net.neoforged.fml.common.Mod;
|
import net.neoforged.fml.common.Mod;
|
||||||
import net.neoforged.neoforge.client.event.RegisterKeyMappingsEvent;
|
import net.neoforged.neoforge.client.event.RegisterKeyMappingsEvent;
|
||||||
import tschipp.carryon.Constants;
|
import tschipp.carryon.Constants;
|
||||||
import tschipp.carryon.client.keybinds.CarryOnKeybinds;
|
import tschipp.carryon.client.keybinds.CarryOnKeybinds;
|
||||||
|
|
||||||
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD, modid = Constants.MOD_ID, value = Dist.CLIENT)
|
@EventBusSubscriber(bus = EventBusSubscriber.Bus.MOD, modid = Constants.MOD_ID, value = Dist.CLIENT)
|
||||||
public class ModClientEvents
|
public class ModClientEvents
|
||||||
{
|
{
|
||||||
@OnlyIn(Dist.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,12 @@
|
||||||
|
|
||||||
package tschipp.carryon.platform;
|
package tschipp.carryon.platform;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
|
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||||
|
import net.minecraft.network.codec.StreamCodec;
|
||||||
|
import net.minecraft.network.codec.StreamDecoder;
|
||||||
|
import net.minecraft.network.codec.StreamMemberEncoder;
|
||||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
|
@ -28,12 +33,13 @@ import net.minecraft.world.entity.player.Player;
|
||||||
import net.neoforged.fml.ModList;
|
import net.neoforged.fml.ModList;
|
||||||
import net.neoforged.fml.loading.FMLLoader;
|
import net.neoforged.fml.loading.FMLLoader;
|
||||||
import net.neoforged.neoforge.network.PacketDistributor;
|
import net.neoforged.neoforge.network.PacketDistributor;
|
||||||
import net.neoforged.neoforge.network.handling.IPlayPayloadHandler;
|
import net.neoforged.neoforge.network.handling.IPayloadHandler;
|
||||||
import net.neoforged.neoforge.network.registration.IPayloadRegistrar;
|
import net.neoforged.neoforge.network.registration.PayloadRegistrar;
|
||||||
import tschipp.carryon.CarryOnCommonClient;
|
import tschipp.carryon.CarryOnCommonClient;
|
||||||
import tschipp.carryon.config.BuiltConfig;
|
import tschipp.carryon.config.BuiltConfig;
|
||||||
import tschipp.carryon.config.neoforge.ConfigLoaderImpl;
|
import tschipp.carryon.config.neoforge.ConfigLoaderImpl;
|
||||||
import tschipp.carryon.networking.PacketBase;
|
import tschipp.carryon.networking.PacketBase;
|
||||||
|
import tschipp.carryon.networking.serverbound.ServerboundCarryKeyPressedPacket;
|
||||||
import tschipp.carryon.platform.services.IPlatformHelper;
|
import tschipp.carryon.platform.services.IPlatformHelper;
|
||||||
|
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
|
|
@ -64,61 +70,41 @@ public class NeoForgePlatformHelper implements IPlatformHelper {
|
||||||
ConfigLoaderImpl.registerConfig(cfg);
|
ConfigLoaderImpl.registerConfig(cfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
private record PacketBridge<T extends PacketBase>(T packet) implements CustomPacketPayload {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void write(FriendlyByteBuf pBuffer) {
|
|
||||||
packet.write(pBuffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ResourceLocation id() {
|
|
||||||
return packet.id();
|
|
||||||
}
|
|
||||||
|
|
||||||
public T original() {
|
|
||||||
return packet;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T extends PacketBase> void registerServerboundPacket(ResourceLocation id, int numericalId, Class<T> clazz, BiConsumer<T, FriendlyByteBuf> writer, Function<FriendlyByteBuf, T> reader, BiConsumer<T, Player> handler, Object... args) {
|
public <T extends PacketBase, B extends FriendlyByteBuf> void registerServerboundPacket(CustomPacketPayload.Type<T> type, Class<T> clazz, StreamCodec<B, T> codec, BiConsumer<T, Player> handler, Object... args) {
|
||||||
IPayloadRegistrar registrar = (IPayloadRegistrar) args[0];
|
PayloadRegistrar registrar = (PayloadRegistrar) args[0];
|
||||||
|
|
||||||
IPlayPayloadHandler<PacketBridge<T>> serverHandler = (packet, ctx) -> {
|
IPayloadHandler<T> serverHandler = (packet, ctx) -> {
|
||||||
ctx.workHandler().submitAsync(() -> {
|
ctx.enqueueWork(() -> {
|
||||||
handler.accept(packet.original(), ctx.player().get());
|
handler.accept(packet, ctx.player());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
FriendlyByteBuf.Reader<PacketBridge<T>> modifiedReader = (buf) -> new PacketBridge<T>(reader.apply(buf));
|
registrar.playToServer(type, (StreamCodec<RegistryFriendlyByteBuf, T>)codec, serverHandler);
|
||||||
|
|
||||||
registrar.play(id, modifiedReader, han -> han.server(serverHandler));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T extends PacketBase> void registerClientboundPacket(ResourceLocation id, int numericalId, Class<T> clazz, BiConsumer<T, FriendlyByteBuf> writer, Function<FriendlyByteBuf, T> reader, BiConsumer<T, Player> handler, Object... args) {
|
public <T extends PacketBase, B extends FriendlyByteBuf> void registerClientboundPacket(CustomPacketPayload.Type<T> type, Class<T> clazz, StreamCodec<B, T> codec, BiConsumer<T, Player> handler, Object... args)
|
||||||
IPayloadRegistrar registrar = (IPayloadRegistrar) args[0];
|
{
|
||||||
|
PayloadRegistrar registrar = (PayloadRegistrar) args[0];
|
||||||
|
|
||||||
IPlayPayloadHandler<PacketBridge<T>> clientHandler = (packet, ctx) -> {
|
IPayloadHandler<T> clientHandler = (packet, ctx) -> {
|
||||||
ctx.workHandler().submitAsync(() -> {
|
ctx.enqueueWork(() -> {
|
||||||
handler.accept(packet.original(), CarryOnCommonClient.getPlayer());
|
handler.accept(packet, CarryOnCommonClient.getPlayer());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
FriendlyByteBuf.Reader<PacketBridge<T>> modifiedReader = (buf) -> new PacketBridge<T>(reader.apply(buf));
|
registrar.playToClient(type, (StreamCodec<RegistryFriendlyByteBuf, T>)codec, clientHandler);
|
||||||
|
|
||||||
registrar.play(id, modifiedReader, han -> han.client(clientHandler));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendPacketToServer(ResourceLocation id, PacketBase packet) {
|
public void sendPacketToServer(ResourceLocation id, PacketBase packet) {
|
||||||
PacketDistributor.SERVER.noArg().send(new PacketBridge(packet));
|
PacketDistributor.sendToServer(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendPacketToPlayer(ResourceLocation id, PacketBase packet, ServerPlayer player) {
|
public void sendPacketToPlayer(ResourceLocation id, PacketBase packet, ServerPlayer player) {
|
||||||
PacketDistributor.PLAYER.with(player).send(new PacketBridge(packet));
|
PacketDistributor.sendToPlayer(player, packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ subprojects {
|
||||||
"refmap_target": "${mod_id}."
|
"refmap_target": "${mod_id}."
|
||||||
]
|
]
|
||||||
|
|
||||||
filesMatching(['pack.mcmeta', 'fabric.mod.json', 'META-INF/mods.toml', '*.mixins.json']) {
|
filesMatching(['pack.mcmeta', 'fabric.mod.json', 'META-INF/mods.toml', 'META-INF/neoforge.mods.toml', '*.mixins.json']) {
|
||||||
expand expandProps
|
expand expandProps
|
||||||
}
|
}
|
||||||
inputs.properties(expandProps)
|
inputs.properties(expandProps)
|
||||||
|
|
|
||||||
|
|
@ -34,4 +34,4 @@ neogradle.subsystems.parchment.mappingsVersion=2024.06.16
|
||||||
org.gradle.jvmargs=-Xmx3G
|
org.gradle.jvmargs=-Xmx3G
|
||||||
org.gradle.daemon=false
|
org.gradle.daemon=false
|
||||||
|
|
||||||
mixinextras_version=0.3.5
|
mixinextras_version=0.3.6
|
||||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
|
|
@ -1,6 +1,6 @@
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-all.zip
|
||||||
networkTimeout=10000
|
networkTimeout=10000
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,10 @@ pluginManagement {
|
||||||
gradlePluginPortal()
|
gradlePluginPortal()
|
||||||
mavenLocal()
|
mavenLocal()
|
||||||
|
|
||||||
|
maven {
|
||||||
|
url "https://plugins.gradle.org/m2/"
|
||||||
|
}
|
||||||
|
|
||||||
maven {
|
maven {
|
||||||
name = 'Fabric'
|
name = 'Fabric'
|
||||||
url = 'https://maven.fabricmc.net/'
|
url = 'https://maven.fabricmc.net/'
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user