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)
|
||||
{
|
||||
Services.PLATFORM.registerServerboundPacket(
|
||||
Constants.PACKET_ID_KEY_PRESSED,
|
||||
0,
|
||||
ServerboundCarryKeyPressedPacket.TYPE,
|
||||
ServerboundCarryKeyPressedPacket.class,
|
||||
ServerboundCarryKeyPressedPacket::write,
|
||||
ServerboundCarryKeyPressedPacket::new,
|
||||
ServerboundCarryKeyPressedPacket.CODEC,
|
||||
ServerboundCarryKeyPressedPacket::handle,
|
||||
args
|
||||
);
|
||||
|
|
@ -71,21 +69,17 @@ public class CarryOnCommon
|
|||
public static void registerClientPackets(Object... args)
|
||||
{
|
||||
Services.PLATFORM.registerClientboundPacket(
|
||||
Constants.PACKET_ID_START_RIDING,
|
||||
1,
|
||||
ClientboundStartRidingPacket.TYPE,
|
||||
ClientboundStartRidingPacket.class,
|
||||
ClientboundStartRidingPacket::write,
|
||||
ClientboundStartRidingPacket::new,
|
||||
ClientboundStartRidingPacket.CODEC,
|
||||
ClientboundStartRidingPacket::handle,
|
||||
args
|
||||
);
|
||||
|
||||
Services.PLATFORM.registerClientboundPacket(
|
||||
Constants.PACKET_ID_SYNC_SCRIPTS,
|
||||
2,
|
||||
ClientboundSyncScriptsPacket.TYPE,
|
||||
ClientboundSyncScriptsPacket.class,
|
||||
ClientboundSyncScriptsPacket::write,
|
||||
ClientboundSyncScriptsPacket::new,
|
||||
ClientboundSyncScriptsPacket.CODEC,
|
||||
ClientboundSyncScriptsPacket::handle,
|
||||
args
|
||||
);
|
||||
|
|
|
|||
|
|
@ -202,6 +202,10 @@ public class CarryOnData {
|
|||
this.activeScript = null;
|
||||
}
|
||||
|
||||
public CarryOnData clone() {
|
||||
return new CarryOnData(nbt.copy());
|
||||
}
|
||||
|
||||
public int getTick()
|
||||
{
|
||||
if(!this.nbt.contains("tick"))
|
||||
|
|
|
|||
|
|
@ -28,21 +28,21 @@ import net.minecraft.world.entity.player.Player;
|
|||
|
||||
public class CarryOnDataManager {
|
||||
|
||||
public static final EntityDataAccessor<CompoundTag> CARRY_DATA_KEY = SynchedEntityData.defineId(Player.class, EntityDataSerializers.COMPOUND_TAG);
|
||||
|
||||
|
||||
public static CarryOnData getCarryData(Player player)
|
||||
{
|
||||
CompoundTag data = player.getEntityData().get(CARRY_DATA_KEY);
|
||||
return new CarryOnData(data.copy());
|
||||
return ((ICarrying)player).getCarryOnData();
|
||||
}
|
||||
|
||||
public static void setCarryData(Player player, CarryOnData data)
|
||||
{
|
||||
data.setSelected(player.getInventory().selected);
|
||||
CompoundTag nbt = data.getNbt();
|
||||
nbt.putInt("tick", player.tickCount);
|
||||
player.getEntityData().set(CARRY_DATA_KEY, nbt);
|
||||
((ICarrying)player).setCarryOnData(data);
|
||||
}
|
||||
|
||||
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 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.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
|
@ -38,6 +39,7 @@ import tschipp.carryon.common.carry.CarryOnDataManager;
|
|||
@Mixin(Inventory.class)
|
||||
public class InventoryMixin
|
||||
{
|
||||
@Unique
|
||||
private static final ItemStack DUMMY_STACK = new ItemStack(Blocks.COBBLESTONE, 1);
|
||||
|
||||
@Shadow
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
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.world.entity.player.Inventory;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
|
|
|||
|
|
@ -22,12 +22,17 @@ package tschipp.carryon.mixin;
|
|||
|
||||
|
||||
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.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.Level;
|
||||
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.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
|
@ -35,17 +40,42 @@ import tschipp.carryon.common.carry.CarryOnData;
|
|||
import tschipp.carryon.common.carry.CarryOnDataManager;
|
||||
|
||||
@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) {
|
||||
super(type, level);
|
||||
}
|
||||
|
||||
|
||||
@Inject(method = "defineSynchedData(Lnet/minecraft/network/syncher/SynchedEntityData$Builder;)V", at = @At("RETURN"))
|
||||
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"))
|
||||
private void onAddAdditionalSaveData(CompoundTag tag, CallbackInfo info)
|
||||
{
|
||||
|
|
@ -58,7 +88,7 @@ public abstract class PlayerMixin extends LivingEntity {
|
|||
{
|
||||
if (tag.contains("CarryOnData")) {
|
||||
CarryOnData data = new CarryOnData(tag.getCompound("CarryOnData"));
|
||||
CarryOnDataManager.setCarryData((Player) (Object) this, data);
|
||||
setCarryOnData(data);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,14 +21,14 @@
|
|||
package tschipp.carryon.networking;
|
||||
|
||||
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.world.entity.player.Player;
|
||||
|
||||
public interface PacketBase
|
||||
{
|
||||
void write(FriendlyByteBuf buf);
|
||||
public interface PacketBase extends CustomPacketPayload {
|
||||
|
||||
void handle(Player player);
|
||||
|
||||
ResourceLocation id();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,10 @@
|
|||
package tschipp.carryon.networking.clientbound;
|
||||
|
||||
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.world.entity.Entity;
|
||||
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 ClientboundStartRidingPacket(FriendlyByteBuf buf)
|
||||
{
|
||||
this(buf.readInt(), buf.readBoolean());
|
||||
}
|
||||
public static final StreamCodec<RegistryFriendlyByteBuf, ClientboundStartRidingPacket> CODEC = StreamCodec.composite(
|
||||
ByteBufCodecs.INT, ClientboundStartRidingPacket::iden,
|
||||
ByteBufCodecs.BOOL, ClientboundStartRidingPacket::ride,
|
||||
ClientboundStartRidingPacket::new
|
||||
);
|
||||
|
||||
@Override
|
||||
public void write(FriendlyByteBuf buf)
|
||||
{
|
||||
buf.writeInt(iden);
|
||||
buf.writeBoolean(ride);
|
||||
}
|
||||
public static final CustomPacketPayload.Type<ClientboundStartRidingPacket> TYPE = new Type<>(Constants.PACKET_ID_START_RIDING);
|
||||
|
||||
@Override
|
||||
public void handle(Player player)
|
||||
|
|
@ -53,7 +53,7 @@ public record ClientboundStartRidingPacket(int iden, boolean ride) implements Pa
|
|||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation id() {
|
||||
return Constants.PACKET_ID_START_RIDING;
|
||||
public Type<ClientboundStartRidingPacket> type() {
|
||||
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.Tag;
|
||||
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.world.entity.player.Player;
|
||||
import tschipp.carryon.Constants;
|
||||
|
|
@ -37,18 +42,12 @@ import java.util.List;
|
|||
|
||||
public record ClientboundSyncScriptsPacket(Tag serialized) implements PacketBase
|
||||
{
|
||||
public ClientboundSyncScriptsPacket(FriendlyByteBuf buf)
|
||||
{
|
||||
this(buf.readNbt().get("data"));
|
||||
}
|
||||
public static final StreamCodec<RegistryFriendlyByteBuf, ClientboundSyncScriptsPacket> CODEC = StreamCodec.composite(
|
||||
ByteBufCodecs.TAG, ClientboundSyncScriptsPacket::serialized,
|
||||
ClientboundSyncScriptsPacket::new
|
||||
);
|
||||
|
||||
@Override
|
||||
public void write(FriendlyByteBuf buf)
|
||||
{
|
||||
CompoundTag tag = new CompoundTag();
|
||||
tag.put("data", serialized);
|
||||
buf.writeNbt(tag);
|
||||
}
|
||||
public static final CustomPacketPayload.Type<ClientboundSyncScriptsPacket> TYPE = new Type<>(Constants.PACKET_ID_SYNC_SCRIPTS);
|
||||
|
||||
@Override
|
||||
public void handle(Player player)
|
||||
|
|
@ -60,7 +59,7 @@ public record ClientboundSyncScriptsPacket(Tag serialized) implements PacketBase
|
|||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation id() {
|
||||
return Constants.PACKET_ID_SYNC_SCRIPTS;
|
||||
public Type<ClientboundSyncScriptsPacket> type() {
|
||||
return TYPE;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,10 @@
|
|||
package tschipp.carryon.networking.serverbound;
|
||||
|
||||
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.server.level.ServerPlayer;
|
||||
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.CarryOnDataManager;
|
||||
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 ServerboundCarryKeyPressedPacket(FriendlyByteBuf buf)
|
||||
{
|
||||
this(buf.readBoolean());
|
||||
}
|
||||
public static final StreamCodec<RegistryFriendlyByteBuf, ServerboundCarryKeyPressedPacket> CODEC = StreamCodec.composite(
|
||||
ByteBufCodecs.BOOL, ServerboundCarryKeyPressedPacket::pressed,
|
||||
ServerboundCarryKeyPressedPacket::new
|
||||
);
|
||||
|
||||
@Override
|
||||
public void write(FriendlyByteBuf buf)
|
||||
{
|
||||
buf.writeBoolean(pressed);
|
||||
}
|
||||
public static final CustomPacketPayload.Type<ServerboundCarryKeyPressedPacket> TYPE = new Type<>(Constants.PACKET_ID_KEY_PRESSED);
|
||||
|
||||
@Override
|
||||
public void handle(Player player)
|
||||
|
|
@ -51,7 +53,7 @@ public record ServerboundCarryKeyPressedPacket(boolean pressed) implements Packe
|
|||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation id() {
|
||||
return Constants.PACKET_ID_KEY_PRESSED;
|
||||
public Type<ServerboundCarryKeyPressedPacket> type() {
|
||||
return TYPE;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,9 @@ package tschipp.carryon.platform.services;
|
|||
|
||||
import net.minecraft.core.HolderLookup;
|
||||
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.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
|
@ -57,9 +60,9 @@ public interface IPlatformHelper {
|
|||
|
||||
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);
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,11 @@ import net.fabricmc.api.ClientModInitializer;
|
|||
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
|
||||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
||||
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.RegistryFriendlyByteBuf;
|
||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import tschipp.carryon.client.keybinds.CarryOnKeybinds;
|
||||
|
|
@ -44,19 +48,16 @@ public class CarryOnFabricClientMod implements ClientModInitializer
|
|||
CarryOnCommon.registerClientPackets();
|
||||
}
|
||||
|
||||
public static void sendPacketToServer(ResourceLocation id, PacketBase packet)
|
||||
public static void sendPacketToServer(PacketBase packet)
|
||||
{
|
||||
FriendlyByteBuf buf = PacketByteBufs.create();
|
||||
packet.write(buf);
|
||||
ClientPlayNetworking.send(id, buf);
|
||||
ClientPlayNetworking.send(packet);
|
||||
}
|
||||
|
||||
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) -> {
|
||||
T packet = reader.apply(buf);
|
||||
client.execute(() -> {
|
||||
handler.accept(packet, client.player);
|
||||
ClientPlayNetworking.registerGlobalReceiver(id, (T packet, ClientPlayNetworking.Context context) -> {
|
||||
context.client().execute(() -> {
|
||||
handler.accept(packet, context.player());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
package tschipp.carryon.mixin;
|
||||
|
||||
import com.llamalad7.mixinextras.sugar.Local;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.Camera;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
|
|
@ -35,9 +36,9 @@ import tschipp.carryon.client.render.CarriedObjectRender;
|
|||
@Mixin(LevelRenderer.class)
|
||||
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")
|
||||
private void onRenderLevel(PoseStack poseStack, float f, long l, boolean bl, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f matrix4f, CallbackInfo ci)
|
||||
@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(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;
|
||||
|
||||
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.PlayPayloadHandler;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
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.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
|
@ -61,33 +68,34 @@ public class FabricPlatformHelper implements IPlatformHelper {
|
|||
}
|
||||
|
||||
@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) -> {
|
||||
T packet = reader.apply(buf);
|
||||
server.execute(() -> {
|
||||
handler.accept(packet, player);
|
||||
PayloadTypeRegistry.playC2S().register(type, (StreamCodec<RegistryFriendlyByteBuf, T>)codec);
|
||||
|
||||
ServerPlayNetworking.registerGlobalReceiver(type, (T packet, ServerPlayNetworking.Context context) -> {
|
||||
context.server().execute(() -> {
|
||||
handler.accept(packet, context.player());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@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
|
||||
public void sendPacketToServer(ResourceLocation id, PacketBase packet)
|
||||
{
|
||||
CarryOnFabricClientMod.sendPacketToServer(id, packet);
|
||||
CarryOnFabricClientMod.sendPacketToServer(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPacketToPlayer(ResourceLocation id, PacketBase packet, ServerPlayer player)
|
||||
{
|
||||
FriendlyByteBuf buf = PacketByteBufs.create();
|
||||
packet.write(buf);
|
||||
ServerPlayNetworking.send(player, id, buf);
|
||||
ServerPlayNetworking.send(player, packet);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -102,10 +102,10 @@ repositories {
|
|||
dependencies {
|
||||
minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"
|
||||
compileOnly project(":Common")
|
||||
implementation(annotationProcessor("io.github.llamalad7:mixinextras-common:${mixinextras_version}"))
|
||||
implementation(jarJar("io.github.llamalad7:mixinextras-forge:${mixinextras_version}")) {
|
||||
jarJar.ranged(it, "[${mixinextras_version},)")
|
||||
}
|
||||
compileOnly(annotationProcessor("io.github.llamalad7:mixinextras-common:${mixinextras_version}"))
|
||||
runtimeOnly(annotationProcessor("io.github.llamalad7:mixinextras-forge:${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.bookshelf:Bookshelf-Forge-1.19.3:17.0.2")
|
||||
annotationProcessor 'org.spongepowered:mixin:0.8.5-SNAPSHOT:processor'
|
||||
|
|
|
|||
|
|
@ -61,26 +61,26 @@ public class ConfigLoaderImpl {
|
|||
public static void onConfigLoad(ModConfigEvent.Loading loading) {
|
||||
loadConfig(loading.getConfig().getSpec());
|
||||
|
||||
|
||||
DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> () -> {
|
||||
ConfigLoader.onConfigLoaded(Minecraft.getInstance().level.registryAccess());
|
||||
});
|
||||
|
||||
DistExecutor.safeRunWhenOn(Dist.DEDICATED_SERVER, () -> () -> {
|
||||
ConfigLoader.onConfigLoaded(ServerLifecycleHooks.getCurrentServer().registryAccess());
|
||||
});
|
||||
//
|
||||
// DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> () -> {
|
||||
// ConfigLoader.onConfigLoaded(Minecraft.getInstance().level.registryAccess());
|
||||
// });
|
||||
//
|
||||
// DistExecutor.safeRunWhenOn(Dist.DEDICATED_SERVER, () -> () -> {
|
||||
// ConfigLoader.onConfigLoaded(ServerLifecycleHooks.getCurrentServer().registryAccess());
|
||||
// });
|
||||
}
|
||||
|
||||
public static void onConfigReload(ModConfigEvent.Reloading loading) {
|
||||
loadConfig(loading.getConfig().getSpec());
|
||||
|
||||
DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> () -> {
|
||||
ConfigLoader.onConfigLoaded(Minecraft.getInstance().level.registryAccess());
|
||||
});
|
||||
|
||||
DistExecutor.safeRunWhenOn(Dist.DEDICATED_SERVER, () -> () -> {
|
||||
ConfigLoader.onConfigLoaded(ServerLifecycleHooks.getCurrentServer().registryAccess());
|
||||
});
|
||||
//
|
||||
// DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> () -> {
|
||||
// ConfigLoader.onConfigLoaded(Minecraft.getInstance().level.registryAccess());
|
||||
// });
|
||||
//
|
||||
// DistExecutor.safeRunWhenOn(Dist.DEDICATED_SERVER, () -> () -> {
|
||||
// ConfigLoader.onConfigLoaded(ServerLifecycleHooks.getCurrentServer().registryAccess());
|
||||
// });
|
||||
}
|
||||
|
||||
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.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 {
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
@SubscribeEvent
|
||||
public static void renderHand(RenderHandEvent event)
|
||||
{
|
||||
|
|
@ -59,7 +58,6 @@ public class ClientEvents {
|
|||
event.setCanceled(true);
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
@SubscribeEvent
|
||||
public static void onRenderLevel(RenderLevelStageEvent event)
|
||||
{
|
||||
|
|
@ -67,7 +65,6 @@ public class ClientEvents {
|
|||
CarriedObjectRender.drawThirdPerson(event.getPartialTick(), event.getPoseStack());
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
@SubscribeEvent
|
||||
public static void onGuiInit(ScreenEvent.Init.Pre event)
|
||||
{
|
||||
|
|
@ -91,7 +88,6 @@ public class ClientEvents {
|
|||
}
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
@SubscribeEvent
|
||||
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.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
|
||||
{
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
@SubscribeEvent
|
||||
public static void registerKeybinds(RegisterKeyMappingsEvent event)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -21,6 +21,9 @@
|
|||
package tschipp.carryon.platform;
|
||||
|
||||
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.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
|
@ -65,10 +68,10 @@ public class ForgePlatformHelper implements IPlatformHelper {
|
|||
}
|
||||
|
||||
@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) -> {
|
||||
if(ctx.getDirection().getReceptionSide().isServer())
|
||||
if(ctx.isServerSide())
|
||||
{
|
||||
ctx.setPacketHandled(true);
|
||||
ctx.enqueueWork(() -> {
|
||||
|
|
@ -77,18 +80,14 @@ public class ForgePlatformHelper implements IPlatformHelper {
|
|||
}
|
||||
};
|
||||
|
||||
CarryOnForge.network.messageBuilder(clazz, numericalId, NetworkDirection.PLAY_TO_SERVER)
|
||||
.encoder(writer)
|
||||
.decoder(reader)
|
||||
.consumerMainThread(serverHandler)
|
||||
.add();
|
||||
CarryOnForge.network.messageBuilder(clazz).codec((StreamCodec<FriendlyByteBuf, T>) codec).consumerMainThread(serverHandler).add();
|
||||
}
|
||||
|
||||
@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) -> {
|
||||
if(ctx.getDirection().getReceptionSide().isClient())
|
||||
if(ctx.isClientSide())
|
||||
{
|
||||
ctx.setPacketHandled(true);
|
||||
ctx.enqueueWork(() -> {
|
||||
|
|
@ -97,11 +96,7 @@ public class ForgePlatformHelper implements IPlatformHelper {
|
|||
}
|
||||
};
|
||||
|
||||
CarryOnForge.network.messageBuilder(clazz, numericalId, NetworkDirection.PLAY_TO_CLIENT)
|
||||
.encoder(writer)
|
||||
.decoder(reader)
|
||||
.consumerMainThread(clientHandler)
|
||||
.add();
|
||||
CarryOnForge.network.messageBuilder(clazz).codec((StreamCodec<FriendlyByteBuf, T>)codec).consumerMainThread(clientHandler).add();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ import net.neoforged.bus.api.SubscribeEvent;
|
|||
import net.neoforged.fml.common.Mod;
|
||||
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import net.neoforged.neoforge.common.NeoForge;
|
||||
import net.neoforged.neoforge.network.event.RegisterPayloadHandlerEvent;
|
||||
import net.neoforged.neoforge.network.registration.IPayloadRegistrar;
|
||||
import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent;
|
||||
import net.neoforged.neoforge.network.registration.PayloadRegistrar;
|
||||
import tschipp.carryon.config.neoforge.ConfigLoaderImpl;
|
||||
|
||||
@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)
|
||||
.versioned("1.0.0");
|
||||
final PayloadRegistrar registrar = event.registrar("1.0.0");
|
||||
|
||||
CarryOnCommon.registerServerPackets(registrar);
|
||||
CarryOnCommon.registerClientPackets(registrar);
|
||||
|
|
|
|||
|
|
@ -26,20 +26,21 @@ import net.minecraft.client.Minecraft;
|
|||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.bus.api.IEventBus;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.DistExecutor;
|
||||
import net.neoforged.fml.ModLoadingContext;
|
||||
import net.neoforged.fml.common.EventBusSubscriber;
|
||||
import net.neoforged.fml.common.Mod;
|
||||
import net.neoforged.fml.config.IConfigSpec;
|
||||
import net.neoforged.fml.config.ModConfig;
|
||||
import net.neoforged.fml.event.config.ModConfigEvent;
|
||||
import net.neoforged.neoforge.common.ModConfigSpec;
|
||||
import net.neoforged.neoforge.common.NeoForge;
|
||||
import net.neoforged.neoforge.server.ServerLifecycleHooks;
|
||||
import tschipp.carryon.Constants;
|
||||
import tschipp.carryon.config.*;
|
||||
|
||||
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 static final Map<ModConfigSpec, BuiltConfig> CONFIGS = new HashMap<>();
|
||||
|
|
@ -57,24 +58,25 @@ public class ConfigLoaderImpl {
|
|||
@SubscribeEvent
|
||||
public static void onConfigLoad(ModConfigEvent.Loading loading) {
|
||||
loadConfig(loading.getConfig().getSpec());
|
||||
DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> () -> {
|
||||
ConfigLoader.onConfigLoaded(Minecraft.getInstance().level.registryAccess());
|
||||
});
|
||||
|
||||
DistExecutor.safeRunWhenOn(Dist.DEDICATED_SERVER, () -> () -> {
|
||||
ConfigLoader.onConfigLoaded(ServerLifecycleHooks.getCurrentServer().registryAccess());
|
||||
});
|
||||
// DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> () -> {
|
||||
// ConfigLoader.onConfigLoaded(Minecraft.getInstance().level.registryAccess());
|
||||
// });
|
||||
//
|
||||
// DistExecutor.safeRunWhenOn(Dist.DEDICATED_SERVER, () -> () -> {
|
||||
// ConfigLoader.onConfigLoaded(ServerLifecycleHooks.getCurrentServer().registryAccess());
|
||||
// });
|
||||
}
|
||||
@SubscribeEvent
|
||||
public static void onConfigReload(ModConfigEvent.Reloading loading) {
|
||||
loadConfig(loading.getConfig().getSpec());
|
||||
DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> () -> {
|
||||
ConfigLoader.onConfigLoaded(Minecraft.getInstance().level.registryAccess());
|
||||
});
|
||||
|
||||
DistExecutor.safeRunWhenOn(Dist.DEDICATED_SERVER, () -> () -> {
|
||||
ConfigLoader.onConfigLoaded(ServerLifecycleHooks.getCurrentServer().registryAccess());
|
||||
});
|
||||
loadConfig(loading.getConfig().getSpec());
|
||||
// DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> () -> {
|
||||
// ConfigLoader.onConfigLoaded(Minecraft.getInstance().level.registryAccess());
|
||||
// });
|
||||
//
|
||||
// DistExecutor.safeRunWhenOn(Dist.DEDICATED_SERVER, () -> () -> {
|
||||
// ConfigLoader.onConfigLoaded(ServerLifecycleHooks.getCurrentServer().registryAccess());
|
||||
// });
|
||||
}
|
||||
|
||||
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.OnlyIn;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.common.EventBusSubscriber;
|
||||
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.RenderLevelStageEvent;
|
||||
import net.neoforged.neoforge.client.event.ScreenEvent;
|
||||
import net.neoforged.neoforge.event.TickEvent;
|
||||
import tschipp.carryon.CarryOnCommonClient;
|
||||
import tschipp.carryon.Constants;
|
||||
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.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 {
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
|
|
@ -62,7 +63,7 @@ public class ClientEvents {
|
|||
public static void onRenderLevel(RenderLevelStageEvent event)
|
||||
{
|
||||
if(event.getStage() == RenderLevelStageEvent.Stage.AFTER_PARTICLES)
|
||||
CarriedObjectRender.drawThirdPerson(event.getPartialTick(), event.getPoseStack());
|
||||
CarriedObjectRender.drawThirdPerson(event.getPartialTick(), event.getPoseStack().last().pose());
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
|
|
@ -91,13 +92,9 @@ public class ClientEvents {
|
|||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
@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.EventPriority;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.common.EventBusSubscriber;
|
||||
import net.neoforged.fml.common.Mod;
|
||||
import net.neoforged.neoforge.common.NeoForge;
|
||||
import net.neoforged.neoforge.common.util.BlockSnapshot;
|
||||
import net.neoforged.neoforge.common.util.TriState;
|
||||
import net.neoforged.neoforge.event.*;
|
||||
import net.neoforged.neoforge.event.entity.living.LivingAttackEvent;
|
||||
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.PlayerInteractEvent;
|
||||
import net.neoforged.neoforge.event.level.BlockEvent;
|
||||
import net.neoforged.neoforge.event.tick.ServerTickEvent;
|
||||
import tschipp.carryon.CarryOnCommon;
|
||||
import tschipp.carryon.Constants;
|
||||
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.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
|
||||
{
|
||||
@SubscribeEvent(priority = EventPriority.HIGH)
|
||||
|
|
@ -90,9 +93,10 @@ public class CommonEvents
|
|||
} else {
|
||||
PlacementHandler.tryPlaceEntity((ServerPlayer) player, pos, event.getFace(), (pPos, toPlace) -> {
|
||||
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);
|
||||
return event.getResult() != Event.Result.DENY;
|
||||
return checkSpawn.getResult() != MobSpawnEvent.PositionCheck.Result.FAIL;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
|
@ -101,8 +105,8 @@ public class CommonEvents
|
|||
}
|
||||
|
||||
if (success) {
|
||||
event.setUseBlock(Event.Result.DENY);
|
||||
event.setUseItem(Event.Result.DENY);
|
||||
event.setUseBlock(TriState.FALSE);
|
||||
event.setUseItem(TriState.FALSE);
|
||||
event.setCancellationResult(InteractionResult.SUCCESS);
|
||||
event.setCanceled(true);
|
||||
}
|
||||
|
|
@ -163,15 +167,14 @@ public class CommonEvents
|
|||
@SubscribeEvent
|
||||
public static void onTagsUpdate(TagsUpdatedEvent event)
|
||||
{
|
||||
ConfigLoader.onConfigLoaded();
|
||||
ConfigLoader.onConfigLoaded(event.getRegistryAccess());
|
||||
}
|
||||
|
||||
@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())
|
||||
CarryOnCommon.onCarryTick(player);
|
||||
for (ServerPlayer player : event.getServer().getPlayerList().getPlayers())
|
||||
CarryOnCommon.onCarryTick(player);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ package tschipp.carryon.events;
|
|||
import net.neoforged.bus.api.EventPriority;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.InterModComms;
|
||||
import net.neoforged.fml.common.EventBusSubscriber;
|
||||
import net.neoforged.fml.common.Mod;
|
||||
import net.neoforged.fml.event.lifecycle.InterModProcessEvent;
|
||||
import tschipp.carryon.Constants;
|
||||
|
|
@ -31,7 +32,7 @@ import tschipp.carryon.common.config.ListHandler;
|
|||
|
||||
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 {
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.LOW)
|
||||
|
|
@ -68,7 +69,7 @@ public class ModBusEvents {
|
|||
ListHandler.addAllowedStacking(str);
|
||||
break;
|
||||
case "addModelOverride":
|
||||
ModelOverrideHandler.addFromString(str);
|
||||
//ModelOverrideHandler.addFromString(str);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,12 +23,13 @@ package tschipp.carryon.events;
|
|||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.api.distmarker.OnlyIn;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.common.EventBusSubscriber;
|
||||
import net.neoforged.fml.common.Mod;
|
||||
import net.neoforged.neoforge.client.event.RegisterKeyMappingsEvent;
|
||||
import tschipp.carryon.Constants;
|
||||
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
|
||||
{
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
|
|
|
|||
|
|
@ -20,7 +20,12 @@
|
|||
|
||||
package tschipp.carryon.platform;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
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.server.level.ServerPlayer;
|
||||
|
|
@ -28,12 +33,13 @@ import net.minecraft.world.entity.player.Player;
|
|||
import net.neoforged.fml.ModList;
|
||||
import net.neoforged.fml.loading.FMLLoader;
|
||||
import net.neoforged.neoforge.network.PacketDistributor;
|
||||
import net.neoforged.neoforge.network.handling.IPlayPayloadHandler;
|
||||
import net.neoforged.neoforge.network.registration.IPayloadRegistrar;
|
||||
import net.neoforged.neoforge.network.handling.IPayloadHandler;
|
||||
import net.neoforged.neoforge.network.registration.PayloadRegistrar;
|
||||
import tschipp.carryon.CarryOnCommonClient;
|
||||
import tschipp.carryon.config.BuiltConfig;
|
||||
import tschipp.carryon.config.neoforge.ConfigLoaderImpl;
|
||||
import tschipp.carryon.networking.PacketBase;
|
||||
import tschipp.carryon.networking.serverbound.ServerboundCarryKeyPressedPacket;
|
||||
import tschipp.carryon.platform.services.IPlatformHelper;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
|
|
@ -64,61 +70,41 @@ public class NeoForgePlatformHelper implements IPlatformHelper {
|
|||
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
|
||||
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) {
|
||||
IPayloadRegistrar registrar = (IPayloadRegistrar) args[0];
|
||||
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) {
|
||||
PayloadRegistrar registrar = (PayloadRegistrar) args[0];
|
||||
|
||||
IPlayPayloadHandler<PacketBridge<T>> serverHandler = (packet, ctx) -> {
|
||||
ctx.workHandler().submitAsync(() -> {
|
||||
handler.accept(packet.original(), ctx.player().get());
|
||||
IPayloadHandler<T> serverHandler = (packet, ctx) -> {
|
||||
ctx.enqueueWork(() -> {
|
||||
handler.accept(packet, ctx.player());
|
||||
});
|
||||
};
|
||||
|
||||
FriendlyByteBuf.Reader<PacketBridge<T>> modifiedReader = (buf) -> new PacketBridge<T>(reader.apply(buf));
|
||||
|
||||
registrar.play(id, modifiedReader, han -> han.server(serverHandler));
|
||||
registrar.playToServer(type, (StreamCodec<RegistryFriendlyByteBuf, T>)codec, serverHandler);
|
||||
}
|
||||
|
||||
@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) {
|
||||
IPayloadRegistrar registrar = (IPayloadRegistrar) args[0];
|
||||
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)
|
||||
{
|
||||
PayloadRegistrar registrar = (PayloadRegistrar) args[0];
|
||||
|
||||
IPlayPayloadHandler<PacketBridge<T>> clientHandler = (packet, ctx) -> {
|
||||
ctx.workHandler().submitAsync(() -> {
|
||||
handler.accept(packet.original(), CarryOnCommonClient.getPlayer());
|
||||
IPayloadHandler<T> clientHandler = (packet, ctx) -> {
|
||||
ctx.enqueueWork(() -> {
|
||||
handler.accept(packet, CarryOnCommonClient.getPlayer());
|
||||
});
|
||||
};
|
||||
|
||||
FriendlyByteBuf.Reader<PacketBridge<T>> modifiedReader = (buf) -> new PacketBridge<T>(reader.apply(buf));
|
||||
|
||||
registrar.play(id, modifiedReader, han -> han.client(clientHandler));
|
||||
registrar.playToClient(type, (StreamCodec<RegistryFriendlyByteBuf, T>)codec, clientHandler);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void sendPacketToServer(ResourceLocation id, PacketBase packet) {
|
||||
PacketDistributor.SERVER.noArg().send(new PacketBridge(packet));
|
||||
PacketDistributor.sendToServer(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
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}."
|
||||
]
|
||||
|
||||
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
|
||||
}
|
||||
inputs.properties(expandProps)
|
||||
|
|
|
|||
|
|
@ -34,4 +34,4 @@ neogradle.subsystems.parchment.mappingsVersion=2024.06.16
|
|||
org.gradle.jvmargs=-Xmx3G
|
||||
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
|
||||
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
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
|
|
|||
|
|
@ -3,6 +3,10 @@ pluginManagement {
|
|||
gradlePluginPortal()
|
||||
mavenLocal()
|
||||
|
||||
maven {
|
||||
url "https://plugins.gradle.org/m2/"
|
||||
}
|
||||
|
||||
maven {
|
||||
name = 'Fabric'
|
||||
url = 'https://maven.fabricmc.net/'
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user