fix: stuff
This commit is contained in:
parent
0c4c307c28
commit
743e7e3ea1
8 changed files with 72 additions and 14 deletions
|
@ -19,6 +19,7 @@ import net.minecraft.util.math.MathHelper;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
import net.minecraft.world.RaycastContext;
|
import net.minecraft.world.RaycastContext;
|
||||||
import ru.octol1ttle.knockdowns.common.KnockdownsClient;
|
import ru.octol1ttle.knockdowns.common.KnockdownsClient;
|
||||||
|
import ru.octol1ttle.knockdowns.common.KnockdownsCommon;
|
||||||
import ru.octol1ttle.knockdowns.common.api.IKnockableDown;
|
import ru.octol1ttle.knockdowns.common.api.IKnockableDown;
|
||||||
import ru.octol1ttle.knockdowns.common.api.RemotePlayer;
|
import ru.octol1ttle.knockdowns.common.api.RemotePlayer;
|
||||||
import ru.octol1ttle.knockdowns.common.network.KnockdownsNetwork;
|
import ru.octol1ttle.knockdowns.common.network.KnockdownsNetwork;
|
||||||
|
@ -37,7 +38,7 @@ public class KnockdownsClientEvents {
|
||||||
MinecraftClient client = MinecraftClient.getInstance();
|
MinecraftClient client = MinecraftClient.getInstance();
|
||||||
if (reviving == null) {
|
if (reviving == null) {
|
||||||
reviving = (IKnockableDown) client.player;
|
reviving = (IKnockableDown) client.player;
|
||||||
if (reviving == null || reviving.get_ReviverCount() == 0) {
|
if (reviving == null || reviving.get_ReviveTimer() == KnockdownsCommon.REVIVE_WAIT_TIME) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,7 +49,14 @@ public class KnockdownsClientEvents {
|
||||||
int timerX = (context.getScaledWindowWidth() - renderer.getWidth(timerText)) / 2;
|
int timerX = (context.getScaledWindowWidth() - renderer.getWidth(timerText)) / 2;
|
||||||
|
|
||||||
int reviverCount = reviving.get_ReviverCount();
|
int reviverCount = reviving.get_ReviverCount();
|
||||||
Integer color = reviverCount > 1 ? Formatting.GREEN.getColorValue() : Formatting.WHITE.getColorValue();
|
Integer color;
|
||||||
|
if (reviverCount == 0) {
|
||||||
|
color = Formatting.RED.getColorValue();
|
||||||
|
} else if (reviverCount == 1) {
|
||||||
|
color = Formatting.WHITE.getColorValue();
|
||||||
|
} else {
|
||||||
|
color = Formatting.GREEN.getColorValue();
|
||||||
|
}
|
||||||
|
|
||||||
String reviverCountText = "x" + reviverCount;
|
String reviverCountText = "x" + reviverCount;
|
||||||
int reviveCountX = (context.getScaledWindowWidth() - renderer.getWidth(reviverCountText)) / 2;
|
int reviveCountX = (context.getScaledWindowWidth() - renderer.getWidth(reviverCountText)) / 2;
|
||||||
|
@ -105,7 +113,7 @@ public class KnockdownsClientEvents {
|
||||||
int height = context.getScaledWindowHeight();
|
int height = context.getScaledWindowHeight();
|
||||||
int y = MathHelper.clamp(MathHelper.floor(result.vec().y - size * 0.5), size + 5, height - size - 5);
|
int y = MathHelper.clamp(MathHelper.floor(result.vec().y - size * 0.5), size + 5, height - size - 5);
|
||||||
|
|
||||||
if (result.type() != ScreenSpaceTransformResult.ScreenSpaceTransformType.ON_SCREEN
|
if (result.type() != ScreenSpaceTransformResult.TransformType.ON_SCREEN
|
||||||
|| client.player.getEyePos().distanceTo(eyePosition) > 64.0
|
|| client.player.getEyePos().distanceTo(eyePosition) > 64.0
|
||||||
|| client.world
|
|| client.world
|
||||||
.raycast(new RaycastContext(
|
.raycast(new RaycastContext(
|
||||||
|
|
|
@ -21,6 +21,8 @@ import ru.octol1ttle.knockdowns.common.KnockdownsUtils;
|
||||||
import ru.octol1ttle.knockdowns.common.api.IKnockableDown;
|
import ru.octol1ttle.knockdowns.common.api.IKnockableDown;
|
||||||
import ru.octol1ttle.knockdowns.common.network.KnockdownsNetwork;
|
import ru.octol1ttle.knockdowns.common.network.KnockdownsNetwork;
|
||||||
import ru.octol1ttle.knockdowns.common.network.packets.PlayKnockedDownSoundS2CPacket;
|
import ru.octol1ttle.knockdowns.common.network.packets.PlayKnockedDownSoundS2CPacket;
|
||||||
|
import ru.octol1ttle.knockdowns.common.network.packets.position.RemotePlayerDimensionChangeS2CPacket;
|
||||||
|
import ru.octol1ttle.knockdowns.common.network.packets.position.RemotePlayerS2CPacket;
|
||||||
|
|
||||||
public class KnockdownsEvents {
|
public class KnockdownsEvents {
|
||||||
private static final float KNOCKED_INVULNERABILITY_TICKS = 3.0f * SharedConstants.TICKS_PER_SECOND;
|
private static final float KNOCKED_INVULNERABILITY_TICKS = 3.0f * SharedConstants.TICKS_PER_SECOND;
|
||||||
|
@ -32,6 +34,7 @@ public class KnockdownsEvents {
|
||||||
registerOnPlayerTick();
|
registerOnPlayerTick();
|
||||||
registerOnPlayerInteractions();
|
registerOnPlayerInteractions();
|
||||||
registerOnEntityUse();
|
registerOnEntityUse();
|
||||||
|
registerOnDimensionChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void registerOnLivingDeath() {
|
private static void registerOnLivingDeath() {
|
||||||
|
@ -51,7 +54,6 @@ public class KnockdownsEvents {
|
||||||
|
|
||||||
entity.clearStatusEffects();
|
entity.clearStatusEffects();
|
||||||
entity.setInvulnerable(true);
|
entity.setInvulnerable(true);
|
||||||
entity.setGlowing(true);
|
|
||||||
entity.setHealth(entity.getMaxHealth());
|
entity.setHealth(entity.getMaxHealth());
|
||||||
entity.extinguish();
|
entity.extinguish();
|
||||||
entity.setAir(entity.getMaxAir());
|
entity.setAir(entity.getMaxAir());
|
||||||
|
@ -99,7 +101,6 @@ public class KnockdownsEvents {
|
||||||
KnockdownsUtils.resetKnockedState(knockable);
|
KnockdownsUtils.resetKnockedState(knockable);
|
||||||
|
|
||||||
player.setInvulnerable(false);
|
player.setInvulnerable(false);
|
||||||
player.setGlowing(false);
|
|
||||||
player.setHealth(player.getMaxHealth() * 0.3f);
|
player.setHealth(player.getMaxHealth() * 0.3f);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -115,6 +116,14 @@ public class KnockdownsEvents {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void registerOnDimensionChange() {
|
||||||
|
PlayerEvent.CHANGE_DIMENSION.register((player, oldLevel, newLevel) -> {
|
||||||
|
//noinspection DataFlowIssue
|
||||||
|
KnockdownsNetwork.sendToWorld(player.getServer().getWorld(oldLevel), new RemotePlayerDimensionChangeS2CPacket(player.getUuid()));
|
||||||
|
KnockdownsNetwork.sendToWorld(player.getServerWorld(), new RemotePlayerS2CPacket(player.getUuid(), player.getEyePos(), ((IKnockableDown)player).is_KnockedDown()));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private static void registerOnPlayerInteractions() {
|
private static void registerOnPlayerInteractions() {
|
||||||
InteractionEvent.LEFT_CLICK_BLOCK.register((player, hand, pos, direction) -> {
|
InteractionEvent.LEFT_CLICK_BLOCK.register((player, hand, pos, direction) -> {
|
||||||
if (KnockdownsUtils.isKnockedOrReviving(player)) {
|
if (KnockdownsUtils.isKnockedOrReviving(player)) {
|
||||||
|
|
|
@ -9,6 +9,7 @@ import net.minecraft.server.world.ServerWorld;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import ru.octol1ttle.knockdowns.common.KnockdownsCommon;
|
import ru.octol1ttle.knockdowns.common.KnockdownsCommon;
|
||||||
import ru.octol1ttle.knockdowns.common.network.packets.PlayKnockedDownSoundS2CPacket;
|
import ru.octol1ttle.knockdowns.common.network.packets.PlayKnockedDownSoundS2CPacket;
|
||||||
|
import ru.octol1ttle.knockdowns.common.network.packets.position.RemotePlayerDimensionChangeS2CPacket;
|
||||||
import ru.octol1ttle.knockdowns.common.network.packets.position.RemotePlayerS2CPacket;
|
import ru.octol1ttle.knockdowns.common.network.packets.position.RemotePlayerS2CPacket;
|
||||||
import ru.octol1ttle.knockdowns.common.network.packets.position.RequestRemotePlayerC2SPacket;
|
import ru.octol1ttle.knockdowns.common.network.packets.position.RequestRemotePlayerC2SPacket;
|
||||||
import ru.octol1ttle.knockdowns.common.network.packets.reviving.RequestStartRevivingC2SPacket;
|
import ru.octol1ttle.knockdowns.common.network.packets.reviving.RequestStartRevivingC2SPacket;
|
||||||
|
@ -24,6 +25,7 @@ public class KnockdownsNetwork {
|
||||||
|
|
||||||
CHANNEL.register(RequestRemotePlayerC2SPacket.class, RequestRemotePlayerC2SPacket::encode, RequestRemotePlayerC2SPacket::new, RequestRemotePlayerC2SPacket::apply);
|
CHANNEL.register(RequestRemotePlayerC2SPacket.class, RequestRemotePlayerC2SPacket::encode, RequestRemotePlayerC2SPacket::new, RequestRemotePlayerC2SPacket::apply);
|
||||||
CHANNEL.register(RemotePlayerS2CPacket.class, RemotePlayerS2CPacket::encode, RemotePlayerS2CPacket::new, RemotePlayerS2CPacket::apply);
|
CHANNEL.register(RemotePlayerS2CPacket.class, RemotePlayerS2CPacket::encode, RemotePlayerS2CPacket::new, RemotePlayerS2CPacket::apply);
|
||||||
|
CHANNEL.register(RemotePlayerDimensionChangeS2CPacket.class, RemotePlayerDimensionChangeS2CPacket::encode, RemotePlayerDimensionChangeS2CPacket::new, RemotePlayerDimensionChangeS2CPacket::apply);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> void sendToServer(T message) {
|
public static <T> void sendToServer(T message) {
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
package ru.octol1ttle.knockdowns.common.network.packets.position;
|
||||||
|
|
||||||
|
import dev.architectury.networking.NetworkManager;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
import net.minecraft.network.PacketByteBuf;
|
||||||
|
import ru.octol1ttle.knockdowns.common.events.KnockdownsClientEvents;
|
||||||
|
import ru.octol1ttle.knockdowns.common.network.packets.KnockdownsPacket;
|
||||||
|
|
||||||
|
public class RemotePlayerDimensionChangeS2CPacket extends KnockdownsPacket {
|
||||||
|
private final UUID targetUuid;
|
||||||
|
|
||||||
|
public RemotePlayerDimensionChangeS2CPacket(PacketByteBuf buf) {
|
||||||
|
this(buf.readUuid());
|
||||||
|
}
|
||||||
|
|
||||||
|
public RemotePlayerDimensionChangeS2CPacket(UUID targetUuid) {
|
||||||
|
this.targetUuid = targetUuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void encode(PacketByteBuf buf) {
|
||||||
|
buf.writeUuid(this.targetUuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void apply(Supplier<NetworkManager.PacketContext> contextSupplier) {
|
||||||
|
NetworkManager.PacketContext context = contextSupplier.get();
|
||||||
|
context.queue(() -> KnockdownsClientEvents.remotePlayers.put(targetUuid, Optional.empty()));
|
||||||
|
}
|
||||||
|
}
|
|
@ -55,7 +55,7 @@ public class RendererUtilsCopy {
|
||||||
target.x / client.getWindow().getScaleFactor(),
|
target.x / client.getWindow().getScaleFactor(),
|
||||||
(client.getWindow().getHeight() - target.y) / client.getWindow().getScaleFactor()
|
(client.getWindow().getHeight() - target.y) / client.getWindow().getScaleFactor()
|
||||||
),
|
),
|
||||||
ScreenSpaceTransformResult.ScreenSpaceTransformType.ON_SCREEN
|
ScreenSpaceTransformResult.TransformType.ON_SCREEN
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ public class RendererUtilsCopy {
|
||||||
|
|
||||||
return new ScreenSpaceTransformResult(
|
return new ScreenSpaceTransformResult(
|
||||||
new Vector2d(x, y),
|
new Vector2d(x, y),
|
||||||
ScreenSpaceTransformResult.ScreenSpaceTransformType.STUCK_TO_EDGES
|
ScreenSpaceTransformResult.TransformType.STUCK_TO_EDGES
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,8 +2,8 @@ package ru.octol1ttle.knockdowns.common.util;
|
||||||
|
|
||||||
import org.joml.Vector2d;
|
import org.joml.Vector2d;
|
||||||
|
|
||||||
public record ScreenSpaceTransformResult(Vector2d vec, ScreenSpaceTransformType type) {
|
public record ScreenSpaceTransformResult(Vector2d vec, TransformType type) {
|
||||||
public enum ScreenSpaceTransformType {
|
public enum TransformType {
|
||||||
ON_SCREEN,
|
ON_SCREEN,
|
||||||
STUCK_TO_EDGES
|
STUCK_TO_EDGES
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,16 @@
|
||||||
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.client.event.RenderGuiEvent;
|
||||||
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
import net.minecraftforge.eventbus.api.IEventBus;
|
import net.minecraftforge.eventbus.api.IEventBus;
|
||||||
|
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.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.KnockdownsClient;
|
||||||
import ru.octol1ttle.knockdowns.common.KnockdownsCommon;
|
import ru.octol1ttle.knockdowns.common.KnockdownsCommon;
|
||||||
|
import ru.octol1ttle.knockdowns.common.events.KnockdownsClientEvents;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@Mod(KnockdownsCommon.MOD_ID)
|
@Mod(KnockdownsCommon.MOD_ID)
|
||||||
|
@ -16,6 +20,7 @@ public class KnockdownsForge {
|
||||||
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
|
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||||
EventBuses.registerModEventBus(KnockdownsCommon.MOD_ID, modEventBus);
|
EventBuses.registerModEventBus(KnockdownsCommon.MOD_ID, modEventBus);
|
||||||
modEventBus.addListener(this::onInitializeClient);
|
modEventBus.addListener(this::onInitializeClient);
|
||||||
|
MinecraftForge.EVENT_BUS.register(this);
|
||||||
|
|
||||||
KnockdownsCommon.init();
|
KnockdownsCommon.init();
|
||||||
}
|
}
|
||||||
|
@ -23,4 +28,9 @@ public class KnockdownsForge {
|
||||||
public void onInitializeClient(FMLClientSetupEvent event) {
|
public void onInitializeClient(FMLClientSetupEvent event) {
|
||||||
KnockdownsClient.init();
|
KnockdownsClient.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public void onHudRender(RenderGuiEvent.Pre event) {
|
||||||
|
KnockdownsClientEvents.onHudRender(event.getGuiGraphics());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ minecraft_version=1.20.1
|
||||||
enabled_platforms=fabric,forge
|
enabled_platforms=fabric,forge
|
||||||
|
|
||||||
archives_base_name=knockdowns
|
archives_base_name=knockdowns
|
||||||
mod_version=2.2.2
|
mod_version=2.3.1
|
||||||
maven_group=ru.octol1ttle.knockdowns
|
maven_group=ru.octol1ttle.knockdowns
|
||||||
|
|
||||||
architectury_version=9.1.12
|
architectury_version=9.1.12
|
||||||
|
@ -12,6 +12,3 @@ fabric_api_version=0.90.4+1.20.1
|
||||||
|
|
||||||
fabric_loader_version=0.15.5
|
fabric_loader_version=0.15.5
|
||||||
forge_version=1.20.1-47.2.0
|
forge_version=1.20.1-47.2.0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue