Fabric is a terrible modding platform.
This commit is contained in:
parent
ae6d9095e3
commit
38939750e6
13 changed files with 73 additions and 39 deletions
|
@ -0,0 +1,19 @@
|
||||||
|
package ru.octol1ttle.knockdowns.common;
|
||||||
|
|
||||||
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
import net.minecraft.util.math.Vec3d;
|
||||||
|
import ru.octol1ttle.knockdowns.common.events.KnockdownsClientEvents;
|
||||||
|
import ru.octol1ttle.knockdowns.common.registries.KnockdownsSoundEvents;
|
||||||
|
import ru.octol1ttle.knockdowns.common.registries.KnockedDownSoundInstance;
|
||||||
|
|
||||||
|
public class KnockdownsClient {
|
||||||
|
public static void init() {
|
||||||
|
KnockdownsClientEvents.registerCallbacks();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void playKnockedDownSound(Vec3d pos) {
|
||||||
|
MinecraftClient.getInstance().getSoundManager().play(
|
||||||
|
new KnockedDownSoundInstance(KnockdownsSoundEvents.KNOCKED_DOWN.get(), pos)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
package ru.octol1ttle.knockdowns.common;
|
package ru.octol1ttle.knockdowns.common;
|
||||||
|
|
||||||
import ru.octol1ttle.knockdowns.common.events.KnockdownsClientEvents;
|
|
||||||
import ru.octol1ttle.knockdowns.common.events.KnockdownsEvents;
|
import ru.octol1ttle.knockdowns.common.events.KnockdownsEvents;
|
||||||
|
import ru.octol1ttle.knockdowns.common.network.KnockdownsNetwork;
|
||||||
import ru.octol1ttle.knockdowns.common.registries.KnockdownsSoundEvents;
|
import ru.octol1ttle.knockdowns.common.registries.KnockdownsSoundEvents;
|
||||||
|
|
||||||
public class KnockdownsCommon {
|
public class KnockdownsCommon {
|
||||||
|
@ -10,7 +10,6 @@ public class KnockdownsCommon {
|
||||||
public static void init() {
|
public static void init() {
|
||||||
KnockdownsSoundEvents.register();
|
KnockdownsSoundEvents.register();
|
||||||
KnockdownsNetwork.registerPackets();
|
KnockdownsNetwork.registerPackets();
|
||||||
KnockdownsClientEvents.registerCallbacks();
|
|
||||||
KnockdownsEvents.registerCallbacks();
|
KnockdownsEvents.registerCallbacks();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,10 +11,10 @@ import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.font.TextRenderer;
|
import net.minecraft.client.font.TextRenderer;
|
||||||
import net.minecraft.util.hit.EntityHitResult;
|
import net.minecraft.util.hit.EntityHitResult;
|
||||||
import net.minecraft.util.hit.HitResult;
|
import net.minecraft.util.hit.HitResult;
|
||||||
import ru.octol1ttle.knockdowns.common.KnockdownsNetwork;
|
import ru.octol1ttle.knockdowns.common.network.KnockdownsNetwork;
|
||||||
import ru.octol1ttle.knockdowns.common.api.IKnockableDown;
|
import ru.octol1ttle.knockdowns.common.api.IKnockableDown;
|
||||||
import ru.octol1ttle.knockdowns.common.packets.KnockedDownStatusPacket;
|
import ru.octol1ttle.knockdowns.common.network.packets.KnockedDownStatusPacket;
|
||||||
import ru.octol1ttle.knockdowns.common.packets.ReviveStatusPacket;
|
import ru.octol1ttle.knockdowns.common.network.packets.ReviveStatusPacket;
|
||||||
|
|
||||||
public class KnockdownsClientEvents {
|
public class KnockdownsClientEvents {
|
||||||
private static final int REVIVAL_WAIT_TIME = 10 * SharedConstants.TICKS_PER_SECOND;
|
private static final int REVIVAL_WAIT_TIME = 10 * SharedConstants.TICKS_PER_SECOND;
|
||||||
|
@ -22,13 +22,13 @@ public class KnockdownsClientEvents {
|
||||||
private static int revivalTimer = -1;
|
private static int revivalTimer = -1;
|
||||||
|
|
||||||
public static void registerCallbacks() {
|
public static void registerCallbacks() {
|
||||||
registerOnEntityLoad();
|
registerOnClientPlayerJoin();
|
||||||
registerOnEntityUse();
|
registerOnEntityUse();
|
||||||
registerOnWorldTick();
|
registerOnWorldTick();
|
||||||
registerOnHudRender();
|
registerOnHudRender();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void registerOnEntityLoad() {
|
private static void registerOnClientPlayerJoin() {
|
||||||
ClientPlayerEvent.CLIENT_PLAYER_JOIN.register(player -> {
|
ClientPlayerEvent.CLIENT_PLAYER_JOIN.register(player -> {
|
||||||
UUID playerUuid = player.getUuid();
|
UUID playerUuid = player.getUuid();
|
||||||
KnockdownsNetwork.sendToServer(new KnockedDownStatusPacket.RequestC2S(playerUuid));
|
KnockdownsNetwork.sendToServer(new KnockedDownStatusPacket.RequestC2S(playerUuid));
|
||||||
|
@ -38,7 +38,7 @@ public class KnockdownsClientEvents {
|
||||||
|
|
||||||
private static void registerOnEntityUse() {
|
private static void registerOnEntityUse() {
|
||||||
InteractionEvent.INTERACT_ENTITY.register((player, entity, hand) -> {
|
InteractionEvent.INTERACT_ENTITY.register((player, entity, hand) -> {
|
||||||
if (!(entity instanceof IKnockableDown knockableEntity) || !knockableEntity.knockdowns$isKnockedDown()
|
if (!player.getWorld().isClient() || !(entity instanceof IKnockableDown knockableEntity) || !knockableEntity.knockdowns$isKnockedDown()
|
||||||
|| knockableEntity.knockdowns$isBeingRevived()) {
|
|| knockableEntity.knockdowns$isBeingRevived()) {
|
||||||
return EventResult.pass();
|
return EventResult.pass();
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,10 +11,10 @@ import net.minecraft.text.Text;
|
||||||
import net.minecraft.text.TranslatableTextContent;
|
import net.minecraft.text.TranslatableTextContent;
|
||||||
import net.minecraft.util.Hand;
|
import net.minecraft.util.Hand;
|
||||||
import net.minecraft.world.GameRules;
|
import net.minecraft.world.GameRules;
|
||||||
import ru.octol1ttle.knockdowns.common.KnockdownsNetwork;
|
import ru.octol1ttle.knockdowns.common.network.KnockdownsNetwork;
|
||||||
import ru.octol1ttle.knockdowns.common.api.IKnockableDown;
|
import ru.octol1ttle.knockdowns.common.api.IKnockableDown;
|
||||||
import ru.octol1ttle.knockdowns.common.packets.KnockedDownStatusPacket;
|
import ru.octol1ttle.knockdowns.common.network.packets.KnockedDownStatusPacket;
|
||||||
import ru.octol1ttle.knockdowns.common.packets.PlayKnockedDownSoundS2CPacket;
|
import ru.octol1ttle.knockdowns.common.network.packets.PlayKnockedDownSoundS2CPacket;
|
||||||
|
|
||||||
public class KnockdownsEvents {
|
public class KnockdownsEvents {
|
||||||
public static void registerCallbacks() {
|
public static void registerCallbacks() {
|
||||||
|
|
|
@ -15,9 +15,9 @@ import ru.octol1ttle.knockdowns.common.api.IKnockableDown;
|
||||||
@Mixin(PlayerEntity.class)
|
@Mixin(PlayerEntity.class)
|
||||||
public abstract class PlayerEntityMixin implements IKnockableDown {
|
public abstract class PlayerEntityMixin implements IKnockableDown {
|
||||||
@Unique
|
@Unique
|
||||||
private boolean knockedDown;
|
private boolean knockdowns$knockedDown;
|
||||||
@Unique
|
@Unique
|
||||||
private boolean beingRevived;
|
private boolean knockdowns$beingRevived;
|
||||||
|
|
||||||
@ModifyExpressionValue(method = "updatePose", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;isSwimming()Z"))
|
@ModifyExpressionValue(method = "updatePose", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;isSwimming()Z"))
|
||||||
private boolean enterSwimmingIfKnockedDown(boolean original) {
|
private boolean enterSwimmingIfKnockedDown(boolean original) {
|
||||||
|
@ -36,32 +36,32 @@ public abstract class PlayerEntityMixin implements IKnockableDown {
|
||||||
|
|
||||||
@Inject(method = "readCustomDataFromNbt", at = @At("TAIL"))
|
@Inject(method = "readCustomDataFromNbt", at = @At("TAIL"))
|
||||||
public void readKnockedDownFromNbt(NbtCompound nbt, CallbackInfo ci) {
|
public void readKnockedDownFromNbt(NbtCompound nbt, CallbackInfo ci) {
|
||||||
this.knockedDown = nbt.getBoolean("KnockedDown");
|
this.knockdowns$knockedDown = nbt.getBoolean("KnockedDown");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "writeCustomDataToNbt", at = @At("TAIL"))
|
@Inject(method = "writeCustomDataToNbt", at = @At("TAIL"))
|
||||||
public void writeKnockedDownToNbt(NbtCompound nbt, CallbackInfo ci) {
|
public void writeKnockedDownToNbt(NbtCompound nbt, CallbackInfo ci) {
|
||||||
nbt.putBoolean("KnockedDown", this.knockedDown);
|
nbt.putBoolean("KnockedDown", this.knockdowns$knockedDown);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean knockdowns$isKnockedDown() {
|
public boolean knockdowns$isKnockedDown() {
|
||||||
return knockedDown;
|
return knockdowns$knockedDown;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void knockdowns$setKnockedDown(boolean knockedDown) {
|
public void knockdowns$setKnockedDown(boolean knockedDown) {
|
||||||
this.knockedDown = knockedDown;
|
this.knockdowns$knockedDown = knockedDown;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean knockdowns$isBeingRevived() {
|
public boolean knockdowns$isBeingRevived() {
|
||||||
return beingRevived;
|
return knockdowns$beingRevived;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void knockdowns$setBeingRevived(boolean beingRevived) {
|
public void knockdowns$setBeingRevived(boolean beingRevived) {
|
||||||
this.beingRevived = beingRevived;
|
this.knockdowns$beingRevived = beingRevived;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package ru.octol1ttle.knockdowns.common;
|
package ru.octol1ttle.knockdowns.common.network;
|
||||||
|
|
||||||
import dev.architectury.networking.NetworkChannel;
|
import dev.architectury.networking.NetworkChannel;
|
||||||
import dev.architectury.networking.NetworkManager;
|
import dev.architectury.networking.NetworkManager;
|
||||||
|
@ -11,9 +11,10 @@ import net.minecraft.server.world.ServerChunkManager;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
import net.minecraft.server.world.ThreadedAnvilChunkStorage;
|
import net.minecraft.server.world.ThreadedAnvilChunkStorage;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import ru.octol1ttle.knockdowns.common.packets.KnockedDownStatusPacket;
|
import ru.octol1ttle.knockdowns.common.KnockdownsCommon;
|
||||||
import ru.octol1ttle.knockdowns.common.packets.PlayKnockedDownSoundS2CPacket;
|
import ru.octol1ttle.knockdowns.common.network.packets.KnockedDownStatusPacket;
|
||||||
import ru.octol1ttle.knockdowns.common.packets.ReviveStatusPacket;
|
import ru.octol1ttle.knockdowns.common.network.packets.PlayKnockedDownSoundS2CPacket;
|
||||||
|
import ru.octol1ttle.knockdowns.common.network.packets.ReviveStatusPacket;
|
||||||
|
|
||||||
public class KnockdownsNetwork {
|
public class KnockdownsNetwork {
|
||||||
private static final NetworkChannel CHANNEL = NetworkChannel.create(new Identifier(KnockdownsCommon.MOD_ID, "main"));
|
private static final NetworkChannel CHANNEL = NetworkChannel.create(new Identifier(KnockdownsCommon.MOD_ID, "main"));
|
|
@ -1,14 +1,10 @@
|
||||||
package ru.octol1ttle.knockdowns.common.packets;
|
package ru.octol1ttle.knockdowns.common.network.packets;
|
||||||
|
|
||||||
import dev.architectury.networking.NetworkManager;
|
import dev.architectury.networking.NetworkManager;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import net.minecraft.network.PacketByteBuf;
|
import net.minecraft.network.PacketByteBuf;
|
||||||
|
|
||||||
public abstract class KnockdownsPacket {
|
public abstract class KnockdownsPacket {
|
||||||
public KnockdownsPacket(PacketByteBuf buf) {
|
|
||||||
// Decode data into a message
|
|
||||||
}
|
|
||||||
|
|
||||||
public KnockdownsPacket(/* args here */) {
|
public KnockdownsPacket(/* args here */) {
|
||||||
// Message creation
|
// Message creation
|
||||||
}
|
}
|
|
@ -1,10 +1,10 @@
|
||||||
package ru.octol1ttle.knockdowns.common.packets;
|
package ru.octol1ttle.knockdowns.common.network.packets;
|
||||||
|
|
||||||
import dev.architectury.networking.NetworkManager;
|
import dev.architectury.networking.NetworkManager;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import net.minecraft.network.PacketByteBuf;
|
import net.minecraft.network.PacketByteBuf;
|
||||||
import ru.octol1ttle.knockdowns.common.KnockdownsNetwork;
|
import ru.octol1ttle.knockdowns.common.network.KnockdownsNetwork;
|
||||||
import ru.octol1ttle.knockdowns.common.api.IKnockableDown;
|
import ru.octol1ttle.knockdowns.common.api.IKnockableDown;
|
||||||
|
|
||||||
public class KnockedDownStatusPacket {
|
public class KnockedDownStatusPacket {
|
|
@ -1,12 +1,10 @@
|
||||||
package ru.octol1ttle.knockdowns.common.packets;
|
package ru.octol1ttle.knockdowns.common.network.packets;
|
||||||
|
|
||||||
import dev.architectury.networking.NetworkManager;
|
import dev.architectury.networking.NetworkManager;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import net.minecraft.client.MinecraftClient;
|
|
||||||
import net.minecraft.network.PacketByteBuf;
|
import net.minecraft.network.PacketByteBuf;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
import ru.octol1ttle.knockdowns.common.registries.KnockdownsSoundEvents;
|
import ru.octol1ttle.knockdowns.common.KnockdownsClient;
|
||||||
import ru.octol1ttle.knockdowns.common.registries.KnockedDownSoundInstance;
|
|
||||||
|
|
||||||
public class PlayKnockedDownSoundS2CPacket extends KnockdownsPacket {
|
public class PlayKnockedDownSoundS2CPacket extends KnockdownsPacket {
|
||||||
private final double x;
|
private final double x;
|
||||||
|
@ -33,8 +31,6 @@ public class PlayKnockedDownSoundS2CPacket extends KnockdownsPacket {
|
||||||
@Override
|
@Override
|
||||||
public void apply(Supplier<NetworkManager.PacketContext> contextSupplier) {
|
public void apply(Supplier<NetworkManager.PacketContext> contextSupplier) {
|
||||||
NetworkManager.PacketContext context = contextSupplier.get();
|
NetworkManager.PacketContext context = contextSupplier.get();
|
||||||
context.queue(() -> MinecraftClient.getInstance().getSoundManager().play(
|
context.queue(() -> KnockdownsClient.playKnockedDownSound(new Vec3d(this.x, this.y, this.z)));
|
||||||
new KnockedDownSoundInstance(KnockdownsSoundEvents.KNOCKED_DOWN.get(), new Vec3d(this.x, this.y, this.z))
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,11 +1,11 @@
|
||||||
package ru.octol1ttle.knockdowns.common.packets;
|
package ru.octol1ttle.knockdowns.common.network.packets;
|
||||||
|
|
||||||
import dev.architectury.networking.NetworkManager;
|
import dev.architectury.networking.NetworkManager;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.network.PacketByteBuf;
|
import net.minecraft.network.PacketByteBuf;
|
||||||
import ru.octol1ttle.knockdowns.common.KnockdownsNetwork;
|
import ru.octol1ttle.knockdowns.common.network.KnockdownsNetwork;
|
||||||
import ru.octol1ttle.knockdowns.common.api.IKnockableDown;
|
import ru.octol1ttle.knockdowns.common.api.IKnockableDown;
|
||||||
|
|
||||||
public class ReviveStatusPacket {
|
public class ReviveStatusPacket {
|
|
@ -0,0 +1,11 @@
|
||||||
|
package ru.octol1ttle.knockdowns.fabric;
|
||||||
|
|
||||||
|
import net.fabricmc.api.ClientModInitializer;
|
||||||
|
import ru.octol1ttle.knockdowns.common.KnockdownsClient;
|
||||||
|
|
||||||
|
public class KnockdownsFabricClient implements ClientModInitializer {
|
||||||
|
@Override
|
||||||
|
public void onInitializeClient() {
|
||||||
|
KnockdownsClient.init();
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,6 +17,9 @@
|
||||||
"entrypoints": {
|
"entrypoints": {
|
||||||
"main": [
|
"main": [
|
||||||
"ru.octol1ttle.knockdowns.fabric.KnockdownsFabric"
|
"ru.octol1ttle.knockdowns.fabric.KnockdownsFabric"
|
||||||
|
],
|
||||||
|
"client": [
|
||||||
|
"ru.octol1ttle.knockdowns.fabric.KnockdownsFabricClient"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"mixins": [
|
"mixins": [
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
package ru.octol1ttle.knockdowns.forge;
|
package ru.octol1ttle.knockdowns.forge;
|
||||||
|
|
||||||
import dev.architectury.platform.forge.EventBuses;
|
import dev.architectury.platform.forge.EventBuses;
|
||||||
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
||||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||||
|
import ru.octol1ttle.knockdowns.common.KnockdownsClient;
|
||||||
import ru.octol1ttle.knockdowns.common.KnockdownsCommon;
|
import ru.octol1ttle.knockdowns.common.KnockdownsCommon;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
@Mod(KnockdownsCommon.MOD_ID)
|
@Mod(KnockdownsCommon.MOD_ID)
|
||||||
public class KnockdownsForge {
|
public class KnockdownsForge {
|
||||||
public KnockdownsForge() {
|
public KnockdownsForge() {
|
||||||
|
@ -12,4 +16,9 @@ public class KnockdownsForge {
|
||||||
EventBuses.registerModEventBus(KnockdownsCommon.MOD_ID, FMLJavaModLoadingContext.get().getModEventBus());
|
EventBuses.registerModEventBus(KnockdownsCommon.MOD_ID, FMLJavaModLoadingContext.get().getModEventBus());
|
||||||
KnockdownsCommon.init();
|
KnockdownsCommon.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public void onInitializeClient(FMLClientSetupEvent event) {
|
||||||
|
KnockdownsClient.init();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue