重构击中判定实现方式
This commit is contained in:
parent
195647dd9a
commit
44ec0df220
13 changed files with 163 additions and 133 deletions
|
@ -92,5 +92,6 @@ public class TargetMod {
|
||||||
addNetworkMessage(GunRecycleGuiButtonMessage.class, GunRecycleGuiButtonMessage::buffer, GunRecycleGuiButtonMessage::new, GunRecycleGuiButtonMessage::handler);
|
addNetworkMessage(GunRecycleGuiButtonMessage.class, GunRecycleGuiButtonMessage::buffer, GunRecycleGuiButtonMessage::new, GunRecycleGuiButtonMessage::handler);
|
||||||
addNetworkMessage(ReloadMessage.class, ReloadMessage::buffer, ReloadMessage::new, ReloadMessage::handler);
|
addNetworkMessage(ReloadMessage.class, ReloadMessage::buffer, ReloadMessage::new, ReloadMessage::handler);
|
||||||
addNetworkMessage(PlayerGunKillMessage.class, PlayerGunKillMessage::encode, PlayerGunKillMessage::decode, PlayerGunKillMessage::handler, Optional.of(NetworkDirection.PLAY_TO_CLIENT));
|
addNetworkMessage(PlayerGunKillMessage.class, PlayerGunKillMessage::encode, PlayerGunKillMessage::decode, PlayerGunKillMessage::handler, Optional.of(NetworkDirection.PLAY_TO_CLIENT));
|
||||||
|
addNetworkMessage(ClientIndicatorMessage.class, ClientIndicatorMessage::encode, ClientIndicatorMessage::decode, ClientIndicatorMessage::handler, Optional.of(NetworkDirection.PLAY_TO_CLIENT));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
import net.mcreator.target.init.TargetModAttributes;
|
import net.mcreator.target.init.TargetModAttributes;
|
||||||
import net.mcreator.target.init.TargetModItems;
|
import net.mcreator.target.init.TargetModItems;
|
||||||
import net.mcreator.target.init.TargetModTags;
|
import net.mcreator.target.init.TargetModTags;
|
||||||
import net.mcreator.target.network.TargetModVariables;
|
|
||||||
import net.minecraft.client.CameraType;
|
import net.minecraft.client.CameraType;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.renderer.GameRenderer;
|
import net.minecraft.client.renderer.GameRenderer;
|
||||||
|
@ -13,36 +12,39 @@ import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.minecraftforge.client.event.RenderGuiEvent;
|
import net.minecraftforge.client.event.RenderGuiEvent;
|
||||||
|
import net.minecraftforge.event.TickEvent;
|
||||||
import net.minecraftforge.eventbus.api.EventPriority;
|
import net.minecraftforge.eventbus.api.EventPriority;
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
|
||||||
import static net.mcreator.target.tools.RenderTool.preciseBlit;
|
import static net.mcreator.target.tools.RenderTool.preciseBlit;
|
||||||
|
|
||||||
@Mod.EventBusSubscriber({Dist.CLIENT})
|
@Mod.EventBusSubscriber(value = Dist.CLIENT)
|
||||||
public class CrossHairOverlay {
|
public class CrossHairOverlay {
|
||||||
|
public static int HIT_INDICATOR = 0;
|
||||||
|
public static int HEAD_INDICATOR = 0;
|
||||||
|
public static int KILL_INDICATOR = 0;
|
||||||
|
|
||||||
|
// TODO 使用partialTicks修改渲染
|
||||||
@SubscribeEvent(priority = EventPriority.NORMAL)
|
@SubscribeEvent(priority = EventPriority.NORMAL)
|
||||||
public static void eventHandler(RenderGuiEvent.Pre event) {
|
public static void eventHandler(RenderGuiEvent.Pre event) {
|
||||||
int w = event.getWindow().getGuiScaledWidth();
|
int w = event.getWindow().getGuiScaledWidth();
|
||||||
int h = event.getWindow().getGuiScaledHeight();
|
int h = event.getWindow().getGuiScaledHeight();
|
||||||
Player entity = Minecraft.getInstance().player;
|
Player entity = Minecraft.getInstance().player;
|
||||||
if (entity == null) return;
|
if (entity == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
double spread = entity.getAttribute(TargetModAttributes.SPREAD.get()).getBaseValue();
|
double spread = entity.getAttribute(TargetModAttributes.SPREAD.get()).getBaseValue();
|
||||||
|
|
||||||
double hitIndicator = (entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).hitIndicator;
|
|
||||||
|
|
||||||
double headIndicator = (entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).headIndicator;
|
|
||||||
|
|
||||||
double killIndicator = (entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).killIndicator;
|
|
||||||
|
|
||||||
RenderSystem.disableDepthTest();
|
RenderSystem.disableDepthTest();
|
||||||
RenderSystem.depthMask(false);
|
RenderSystem.depthMask(false);
|
||||||
RenderSystem.enableBlend();
|
RenderSystem.enableBlend();
|
||||||
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
||||||
RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
|
RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
|
||||||
RenderSystem.setShaderColor(1, 1, 1, 1);
|
RenderSystem.setShaderColor(1, 1, 1, 1);
|
||||||
if (shouldRenderCrosshair(entity)) {
|
|
||||||
|
if (shouldRenderCrossHair(entity)) {
|
||||||
preciseBlit(event.getGuiGraphics(), new ResourceLocation("target:textures/screens/point.png"), w / 2f - 7.5f, h / 2f - 8, 0, 0, 16, 16, 16, 16);
|
preciseBlit(event.getGuiGraphics(), new ResourceLocation("target:textures/screens/point.png"), w / 2f - 7.5f, h / 2f - 8, 0, 0, 16, 16, 16, 16);
|
||||||
|
|
||||||
preciseBlit(event.getGuiGraphics(), new ResourceLocation("target:textures/screens/rexheng.png"), w / 2f - 9.5f - 2.8f * (float) spread, h / 2f - 8, 0, 0, 16, 16, 16, 16);
|
preciseBlit(event.getGuiGraphics(), new ResourceLocation("target:textures/screens/rexheng.png"), w / 2f - 9.5f - 2.8f * (float) spread, h / 2f - 8, 0, 0, 16, 16, 16, 16);
|
||||||
|
@ -56,17 +58,17 @@ public class CrossHairOverlay {
|
||||||
|
|
||||||
float ww = w / 2f - 7.5f + (float) (2 * (Math.random() - 0.5f));
|
float ww = w / 2f - 7.5f + (float) (2 * (Math.random() - 0.5f));
|
||||||
float hh = h / 2f - 8 + (float) (2 * (Math.random() - 0.5f));
|
float hh = h / 2f - 8 + (float) (2 * (Math.random() - 0.5f));
|
||||||
float m = (float) ((40 - killIndicator) / 5.5f);
|
float m = (40 - KILL_INDICATOR * 5) / 5.5f;
|
||||||
|
|
||||||
if (hitIndicator > 0) {
|
if (HIT_INDICATOR > 0) {
|
||||||
preciseBlit(event.getGuiGraphics(), new ResourceLocation("target:textures/screens/hit_marker.png"), ww, hh, 0, 0, 16, 16, 16, 16);
|
preciseBlit(event.getGuiGraphics(), new ResourceLocation("target:textures/screens/hit_marker.png"), ww, hh, 0, 0, 16, 16, 16, 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (headIndicator > 0) {
|
if (HEAD_INDICATOR > 0) {
|
||||||
preciseBlit(event.getGuiGraphics(), new ResourceLocation("target:textures/screens/headshotmark.png"), ww, hh, 0, 0, 16, 16, 16, 16);
|
preciseBlit(event.getGuiGraphics(), new ResourceLocation("target:textures/screens/headshotmark.png"), ww, hh, 0, 0, 16, 16, 16, 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (killIndicator > 0) {
|
if (KILL_INDICATOR > 0) {
|
||||||
preciseBlit(event.getGuiGraphics(), new ResourceLocation("target:textures/screens/kill_mark1.png"), w / 2f - 7.5f - 2 + m, h / 2f - 8 - 2 + m, 0, 0, 16, 16, 16, 16);
|
preciseBlit(event.getGuiGraphics(), new ResourceLocation("target:textures/screens/kill_mark1.png"), w / 2f - 7.5f - 2 + m, h / 2f - 8 - 2 + m, 0, 0, 16, 16, 16, 16);
|
||||||
|
|
||||||
preciseBlit(event.getGuiGraphics(), new ResourceLocation("target:textures/screens/kill_mark2.png"), w / 2f - 7.5f + 2 - m, h / 2f - 8 - 2 + m, 0, 0, 16, 16, 16, 16);
|
preciseBlit(event.getGuiGraphics(), new ResourceLocation("target:textures/screens/kill_mark2.png"), w / 2f - 7.5f + 2 - m, h / 2f - 8 - 2 + m, 0, 0, 16, 16, 16, 16);
|
||||||
|
@ -83,7 +85,7 @@ public class CrossHairOverlay {
|
||||||
RenderSystem.setShaderColor(1, 1, 1, 1);
|
RenderSystem.setShaderColor(1, 1, 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean shouldRenderCrosshair(Player player) {
|
private static boolean shouldRenderCrossHair(Player player) {
|
||||||
if (player == null) return false;
|
if (player == null) return false;
|
||||||
|
|
||||||
if (player.isSpectator()) return false;
|
if (player.isSpectator()) return false;
|
||||||
|
@ -93,4 +95,19 @@ public class CrossHairOverlay {
|
||||||
return !(player.getMainHandItem().getItem() == TargetModItems.M_79.get())
|
return !(player.getMainHandItem().getItem() == TargetModItems.M_79.get())
|
||||||
&& Minecraft.getInstance().options.getCameraType() == CameraType.FIRST_PERSON;
|
&& Minecraft.getInstance().options.getCameraType() == CameraType.FIRST_PERSON;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onClientTick(TickEvent.ClientTickEvent event) {
|
||||||
|
if (event.phase != TickEvent.Phase.END) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
handleRenderDamageIndicator();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void handleRenderDamageIndicator() {
|
||||||
|
HEAD_INDICATOR = Math.max(0, HEAD_INDICATOR - 1);
|
||||||
|
HIT_INDICATOR = Math.max(0, HIT_INDICATOR - 1);
|
||||||
|
KILL_INDICATOR = Math.max(0, KILL_INDICATOR - 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
package net.mcreator.target.entity;
|
package net.mcreator.target.entity;
|
||||||
|
|
||||||
|
import net.mcreator.target.TargetMod;
|
||||||
import net.mcreator.target.headshot.BoundingBoxManager;
|
import net.mcreator.target.headshot.BoundingBoxManager;
|
||||||
import net.mcreator.target.headshot.IHeadshotBox;
|
import net.mcreator.target.headshot.IHeadshotBox;
|
||||||
import net.mcreator.target.init.TargetModDamageTypes;
|
import net.mcreator.target.init.TargetModDamageTypes;
|
||||||
import net.mcreator.target.init.TargetModEntities;
|
import net.mcreator.target.init.TargetModEntities;
|
||||||
import net.mcreator.target.init.TargetModSounds;
|
import net.mcreator.target.init.TargetModSounds;
|
||||||
import net.mcreator.target.network.TargetModVariables;
|
import net.mcreator.target.network.message.ClientIndicatorMessage;
|
||||||
import net.minecraft.network.protocol.Packet;
|
import net.minecraft.network.protocol.Packet;
|
||||||
import net.minecraft.network.protocol.game.ClientGamePacketListener;
|
import net.minecraft.network.protocol.game.ClientGamePacketListener;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.sounds.SoundEvents;
|
import net.minecraft.sounds.SoundEvents;
|
||||||
import net.minecraft.sounds.SoundSource;
|
import net.minecraft.sounds.SoundSource;
|
||||||
import net.minecraft.util.Mth;
|
import net.minecraft.util.Mth;
|
||||||
|
@ -27,6 +29,7 @@ import net.minecraft.world.phys.Vec3;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||||
import net.minecraftforge.network.NetworkHooks;
|
import net.minecraftforge.network.NetworkHooks;
|
||||||
|
import net.minecraftforge.network.PacketDistributor;
|
||||||
import net.minecraftforge.network.PlayMessages;
|
import net.minecraftforge.network.PlayMessages;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
@ -82,12 +85,10 @@ public class BocekArrowEntity extends AbstractArrow implements ItemSupplier {
|
||||||
protected void onHitEntity(EntityHitResult result) {
|
protected void onHitEntity(EntityHitResult result) {
|
||||||
Entity entity = result.getEntity();
|
Entity entity = result.getEntity();
|
||||||
if (this.getOwner() instanceof LivingEntity living) {
|
if (this.getOwner() instanceof LivingEntity living) {
|
||||||
living.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
if (!living.level().isClientSide() && living instanceof ServerPlayer player) {
|
||||||
capability.hitIndicator = 25;
|
|
||||||
capability.syncPlayerVariables(living);
|
|
||||||
});
|
|
||||||
if (!living.level().isClientSide() && living.getServer() != null) {
|
|
||||||
living.playSound(TargetModSounds.INDICATION.get());
|
living.playSound(TargetModSounds.INDICATION.get());
|
||||||
|
|
||||||
|
TargetMod.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> player), new ClientIndicatorMessage(0, 5));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,12 +126,10 @@ public class BocekArrowEntity extends AbstractArrow implements ItemSupplier {
|
||||||
}
|
}
|
||||||
if (headshot) {
|
if (headshot) {
|
||||||
if (this.getOwner() instanceof LivingEntity living) {
|
if (this.getOwner() instanceof LivingEntity living) {
|
||||||
living.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
if (!living.level().isClientSide() && living instanceof ServerPlayer player) {
|
||||||
capability.headIndicator = 25;
|
|
||||||
capability.syncPlayerVariables(living);
|
|
||||||
});
|
|
||||||
if (!living.level().isClientSide() && living.getServer() != null) {
|
|
||||||
living.playSound(TargetModSounds.HEADSHOT.get());
|
living.playSound(TargetModSounds.HEADSHOT.get());
|
||||||
|
|
||||||
|
TargetMod.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> player), new ClientIndicatorMessage(1, 5));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,19 @@
|
||||||
package net.mcreator.target.entity;
|
package net.mcreator.target.entity;
|
||||||
|
|
||||||
|
import net.mcreator.target.TargetMod;
|
||||||
import net.mcreator.target.headshot.BoundingBoxManager;
|
import net.mcreator.target.headshot.BoundingBoxManager;
|
||||||
import net.mcreator.target.headshot.IHeadshotBox;
|
import net.mcreator.target.headshot.IHeadshotBox;
|
||||||
import net.mcreator.target.init.TargetModDamageTypes;
|
import net.mcreator.target.init.TargetModDamageTypes;
|
||||||
import net.mcreator.target.init.TargetModEntities;
|
import net.mcreator.target.init.TargetModEntities;
|
||||||
import net.mcreator.target.init.TargetModItems;
|
import net.mcreator.target.init.TargetModItems;
|
||||||
import net.mcreator.target.init.TargetModSounds;
|
import net.mcreator.target.init.TargetModSounds;
|
||||||
import net.mcreator.target.network.TargetModVariables;
|
import net.mcreator.target.network.message.ClientIndicatorMessage;
|
||||||
import net.mcreator.target.tools.ParticleTool;
|
import net.mcreator.target.tools.ParticleTool;
|
||||||
import net.minecraft.core.particles.ParticleTypes;
|
import net.minecraft.core.particles.ParticleTypes;
|
||||||
import net.minecraft.network.protocol.Packet;
|
import net.minecraft.network.protocol.Packet;
|
||||||
import net.minecraft.network.protocol.game.ClientGamePacketListener;
|
import net.minecraft.network.protocol.game.ClientGamePacketListener;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.sounds.SoundSource;
|
import net.minecraft.sounds.SoundSource;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.EntityType;
|
import net.minecraft.world.entity.EntityType;
|
||||||
|
@ -24,6 +26,7 @@ import net.minecraft.world.phys.BlockHitResult;
|
||||||
import net.minecraft.world.phys.EntityHitResult;
|
import net.minecraft.world.phys.EntityHitResult;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import net.minecraftforge.network.NetworkHooks;
|
import net.minecraftforge.network.NetworkHooks;
|
||||||
|
import net.minecraftforge.network.PacketDistributor;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@ -57,12 +60,10 @@ public class GunGrenadeEntity extends ThrowableItemProjectile {
|
||||||
protected void onHitEntity(EntityHitResult result) {
|
protected void onHitEntity(EntityHitResult result) {
|
||||||
Entity entity = result.getEntity();
|
Entity entity = result.getEntity();
|
||||||
if (this.getOwner() instanceof LivingEntity living) {
|
if (this.getOwner() instanceof LivingEntity living) {
|
||||||
living.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
if (!living.level().isClientSide() && living instanceof ServerPlayer player) {
|
||||||
capability.hitIndicator = 25;
|
|
||||||
capability.syncPlayerVariables(living);
|
|
||||||
});
|
|
||||||
if (!living.level().isClientSide() && living.getServer() != null) {
|
|
||||||
living.level().playSound(null, living.blockPosition(), TargetModSounds.INDICATION.get(), SoundSource.VOICE, 1, 1);
|
living.level().playSound(null, living.blockPosition(), TargetModSounds.INDICATION.get(), SoundSource.VOICE, 1, 1);
|
||||||
|
|
||||||
|
TargetMod.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> player), new ClientIndicatorMessage(0, 5));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,12 +103,10 @@ public class GunGrenadeEntity extends ThrowableItemProjectile {
|
||||||
}
|
}
|
||||||
if (headshot) {
|
if (headshot) {
|
||||||
if (this.getOwner() instanceof LivingEntity living) {
|
if (this.getOwner() instanceof LivingEntity living) {
|
||||||
living.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
if (!living.level().isClientSide() && living instanceof ServerPlayer player) {
|
||||||
capability.headIndicator = 25;
|
|
||||||
capability.syncPlayerVariables(living);
|
|
||||||
});
|
|
||||||
if (!living.level().isClientSide()) {
|
|
||||||
living.level().playSound(null, living.getX(), living.getY(), living.getZ(), TargetModSounds.HEADSHOT.get(), SoundSource.VOICE, 1f, 1f);
|
living.level().playSound(null, living.getX(), living.getY(), living.getZ(), TargetModSounds.HEADSHOT.get(), SoundSource.VOICE, 1f, 1f);
|
||||||
|
|
||||||
|
TargetMod.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> player), new ClientIndicatorMessage(1, 5));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import net.mcreator.target.init.TargetModDamageTypes;
|
||||||
import net.mcreator.target.init.TargetModEntities;
|
import net.mcreator.target.init.TargetModEntities;
|
||||||
import net.mcreator.target.init.TargetModParticleTypes;
|
import net.mcreator.target.init.TargetModParticleTypes;
|
||||||
import net.mcreator.target.init.TargetModSounds;
|
import net.mcreator.target.init.TargetModSounds;
|
||||||
import net.mcreator.target.network.TargetModVariables;
|
import net.mcreator.target.network.message.ClientIndicatorMessage;
|
||||||
import net.mcreator.target.network.message.PlayerGunKillMessage;
|
import net.mcreator.target.network.message.PlayerGunKillMessage;
|
||||||
import net.mcreator.target.tools.ExtendedEntityRayTraceResult;
|
import net.mcreator.target.tools.ExtendedEntityRayTraceResult;
|
||||||
import net.mcreator.target.tools.ParticleTool;
|
import net.mcreator.target.tools.ParticleTool;
|
||||||
|
@ -314,10 +314,7 @@ public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnDa
|
||||||
if (living.isDeadOrDying()) return;
|
if (living.isDeadOrDying()) return;
|
||||||
|
|
||||||
if (this.shooter instanceof ServerPlayer player) {
|
if (this.shooter instanceof ServerPlayer player) {
|
||||||
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
TargetMod.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> player), new ClientIndicatorMessage(0, 5));
|
||||||
capability.hitIndicator = 25;
|
|
||||||
capability.syncPlayerVariables(living);
|
|
||||||
});
|
|
||||||
var holder = Holder.direct(TargetModSounds.INDICATION.get());
|
var holder = Holder.direct(TargetModSounds.INDICATION.get());
|
||||||
player.connection.send(new ClientboundSoundPacket(holder, SoundSource.PLAYERS, player.getX(), player.getY(), player.getZ(), 1f, 1f, player.level().random.nextLong()));
|
player.connection.send(new ClientboundSoundPacket(holder, SoundSource.PLAYERS, player.getX(), player.getY(), player.getZ(), 1f, 1f, player.level().random.nextLong()));
|
||||||
((ServerLevel) this.level()).sendParticles(ParticleTypes.DAMAGE_INDICATOR, living.getX(), living.getY() + .5, living.getZ(), 1000, .4, .7, .4, 0);
|
((ServerLevel) this.level()).sendParticles(ParticleTypes.DAMAGE_INDICATOR, living.getX(), living.getY() + .5, living.getZ(), 1000, .4, .7, .4, 0);
|
||||||
|
@ -349,25 +346,17 @@ public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnDa
|
||||||
if (!this.shooter.level().isClientSide() && this.shooter instanceof ServerPlayer player) {
|
if (!this.shooter.level().isClientSide() && this.shooter instanceof ServerPlayer player) {
|
||||||
var holder = Holder.direct(TargetModSounds.HEADSHOT.get());
|
var holder = Holder.direct(TargetModSounds.HEADSHOT.get());
|
||||||
player.connection.send(new ClientboundSoundPacket(holder, SoundSource.PLAYERS, player.getX(), player.getY(), player.getZ(), 1f, 1f, player.level().random.nextLong()));
|
player.connection.send(new ClientboundSoundPacket(holder, SoundSource.PLAYERS, player.getX(), player.getY(), player.getZ(), 1f, 1f, player.level().random.nextLong()));
|
||||||
|
|
||||||
|
TargetMod.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> player), new ClientIndicatorMessage(1, 5));
|
||||||
}
|
}
|
||||||
|
|
||||||
shooter.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
|
||||||
capability.headIndicator = 25;
|
|
||||||
capability.syncPlayerVariables(shooter);
|
|
||||||
});
|
|
||||||
|
|
||||||
entity.hurt(TargetModDamageTypes.causeGunFireHeadshotDamage(this.level().registryAccess(), this.shooter), this.damage * this.headShot);
|
entity.hurt(TargetModDamageTypes.causeGunFireHeadshotDamage(this.level().registryAccess(), this.shooter), this.damage * this.headShot);
|
||||||
} else {
|
} else {
|
||||||
if (!this.shooter.level().isClientSide() && this.shooter instanceof ServerPlayer player) {
|
if (!this.shooter.level().isClientSide() && this.shooter instanceof ServerPlayer player) {
|
||||||
var holder = Holder.direct(TargetModSounds.INDICATION.get());
|
var holder = Holder.direct(TargetModSounds.INDICATION.get());
|
||||||
player.connection.send(new ClientboundSoundPacket(holder, SoundSource.PLAYERS, player.getX(), player.getY(), player.getZ(), 1f, 1f, player.level().random.nextLong()));
|
player.connection.send(new ClientboundSoundPacket(holder, SoundSource.PLAYERS, player.getX(), player.getY(), player.getZ(), 1f, 1f, player.level().random.nextLong()));
|
||||||
|
|
||||||
|
TargetMod.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> player), new ClientIndicatorMessage(0, 5));
|
||||||
}
|
}
|
||||||
|
|
||||||
shooter.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
|
||||||
capability.hitIndicator = 25;
|
|
||||||
capability.syncPlayerVariables(shooter);
|
|
||||||
});
|
|
||||||
|
|
||||||
entity.hurt(TargetModDamageTypes.causeGunFireDamage(this.level().registryAccess(), this.shooter), this.damage);
|
entity.hurt(TargetModDamageTypes.causeGunFireDamage(this.level().registryAccess(), this.shooter), this.damage);
|
||||||
}
|
}
|
||||||
this.discard();
|
this.discard();
|
||||||
|
|
|
@ -1,17 +1,19 @@
|
||||||
package net.mcreator.target.entity;
|
package net.mcreator.target.entity;
|
||||||
|
|
||||||
|
import net.mcreator.target.TargetMod;
|
||||||
import net.mcreator.target.headshot.BoundingBoxManager;
|
import net.mcreator.target.headshot.BoundingBoxManager;
|
||||||
import net.mcreator.target.headshot.IHeadshotBox;
|
import net.mcreator.target.headshot.IHeadshotBox;
|
||||||
import net.mcreator.target.init.TargetModDamageTypes;
|
import net.mcreator.target.init.TargetModDamageTypes;
|
||||||
import net.mcreator.target.init.TargetModEntities;
|
import net.mcreator.target.init.TargetModEntities;
|
||||||
import net.mcreator.target.init.TargetModItems;
|
import net.mcreator.target.init.TargetModItems;
|
||||||
import net.mcreator.target.init.TargetModSounds;
|
import net.mcreator.target.init.TargetModSounds;
|
||||||
import net.mcreator.target.network.TargetModVariables;
|
import net.mcreator.target.network.message.ClientIndicatorMessage;
|
||||||
import net.mcreator.target.tools.ParticleTool;
|
import net.mcreator.target.tools.ParticleTool;
|
||||||
import net.minecraft.core.particles.ParticleTypes;
|
import net.minecraft.core.particles.ParticleTypes;
|
||||||
import net.minecraft.network.protocol.Packet;
|
import net.minecraft.network.protocol.Packet;
|
||||||
import net.minecraft.network.protocol.game.ClientGamePacketListener;
|
import net.minecraft.network.protocol.game.ClientGamePacketListener;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.sounds.SoundSource;
|
import net.minecraft.sounds.SoundSource;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.EntityType;
|
import net.minecraft.world.entity.EntityType;
|
||||||
|
@ -24,6 +26,7 @@ import net.minecraft.world.phys.BlockHitResult;
|
||||||
import net.minecraft.world.phys.EntityHitResult;
|
import net.minecraft.world.phys.EntityHitResult;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import net.minecraftforge.network.NetworkHooks;
|
import net.minecraftforge.network.NetworkHooks;
|
||||||
|
import net.minecraftforge.network.PacketDistributor;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@ -57,12 +60,10 @@ public class RpgRocketEntity extends ThrowableItemProjectile {
|
||||||
protected void onHitEntity(EntityHitResult result) {
|
protected void onHitEntity(EntityHitResult result) {
|
||||||
Entity entity = result.getEntity();
|
Entity entity = result.getEntity();
|
||||||
if (this.getOwner() instanceof LivingEntity living) {
|
if (this.getOwner() instanceof LivingEntity living) {
|
||||||
living.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
if (!living.level().isClientSide() && living instanceof ServerPlayer player) {
|
||||||
capability.hitIndicator = 25;
|
|
||||||
capability.syncPlayerVariables(living);
|
|
||||||
});
|
|
||||||
if (!living.level().isClientSide() && living.getServer() != null) {
|
|
||||||
living.level().playSound(null, living.blockPosition(), TargetModSounds.INDICATION.get(), SoundSource.VOICE, 1, 1);
|
living.level().playSound(null, living.blockPosition(), TargetModSounds.INDICATION.get(), SoundSource.VOICE, 1, 1);
|
||||||
|
|
||||||
|
TargetMod.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> player), new ClientIndicatorMessage(0, 5));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,12 +102,10 @@ public class RpgRocketEntity extends ThrowableItemProjectile {
|
||||||
}
|
}
|
||||||
if (headshot) {
|
if (headshot) {
|
||||||
if (this.getOwner() instanceof LivingEntity living) {
|
if (this.getOwner() instanceof LivingEntity living) {
|
||||||
living.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
if (!living.level().isClientSide() && living instanceof ServerPlayer player) {
|
||||||
capability.headIndicator = 25;
|
|
||||||
capability.syncPlayerVariables(living);
|
|
||||||
});
|
|
||||||
if (!living.level().isClientSide() && living.getServer() != null) {
|
|
||||||
living.playSound(TargetModSounds.HEADSHOT.get(), 1, 1);
|
living.playSound(TargetModSounds.HEADSHOT.get(), 1, 1);
|
||||||
|
|
||||||
|
TargetMod.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> player), new ClientIndicatorMessage(1, 5));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
package net.mcreator.target.entity;
|
package net.mcreator.target.entity;
|
||||||
|
|
||||||
|
import net.mcreator.target.TargetMod;
|
||||||
import net.mcreator.target.headshot.BoundingBoxManager;
|
import net.mcreator.target.headshot.BoundingBoxManager;
|
||||||
import net.mcreator.target.headshot.IHeadshotBox;
|
import net.mcreator.target.headshot.IHeadshotBox;
|
||||||
import net.mcreator.target.init.*;
|
import net.mcreator.target.init.*;
|
||||||
import net.mcreator.target.network.TargetModVariables;
|
import net.mcreator.target.network.message.ClientIndicatorMessage;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.network.protocol.Packet;
|
import net.minecraft.network.protocol.Packet;
|
||||||
import net.minecraft.network.protocol.game.ClientGamePacketListener;
|
import net.minecraft.network.protocol.game.ClientGamePacketListener;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.sounds.SoundSource;
|
import net.minecraft.sounds.SoundSource;
|
||||||
import net.minecraft.world.effect.MobEffectInstance;
|
import net.minecraft.world.effect.MobEffectInstance;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
|
@ -20,6 +22,7 @@ import net.minecraft.world.phys.AABB;
|
||||||
import net.minecraft.world.phys.EntityHitResult;
|
import net.minecraft.world.phys.EntityHitResult;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import net.minecraftforge.network.NetworkHooks;
|
import net.minecraftforge.network.NetworkHooks;
|
||||||
|
import net.minecraftforge.network.PacketDistributor;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@ -53,13 +56,10 @@ public class TaserBulletProjectileEntity extends ThrowableItemProjectile {
|
||||||
protected void onHitEntity(EntityHitResult result) {
|
protected void onHitEntity(EntityHitResult result) {
|
||||||
Entity entity = result.getEntity();
|
Entity entity = result.getEntity();
|
||||||
if (this.getOwner() instanceof LivingEntity living) {
|
if (this.getOwner() instanceof LivingEntity living) {
|
||||||
living.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
if (!living.level().isClientSide() && living instanceof ServerPlayer player) {
|
||||||
capability.hitIndicator = 25;
|
|
||||||
capability.syncPlayerVariables(living);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!living.level().isClientSide()) {
|
|
||||||
living.level().playSound(null, living.blockPosition(), TargetModSounds.INDICATION.get(), SoundSource.VOICE, 1, 1);
|
living.level().playSound(null, living.blockPosition(), TargetModSounds.INDICATION.get(), SoundSource.VOICE, 1, 1);
|
||||||
|
|
||||||
|
TargetMod.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> player), new ClientIndicatorMessage(0, 5));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (entity instanceof LivingEntity) {
|
if (entity instanceof LivingEntity) {
|
||||||
|
@ -86,12 +86,10 @@ public class TaserBulletProjectileEntity extends ThrowableItemProjectile {
|
||||||
headshot = true;
|
headshot = true;
|
||||||
}
|
}
|
||||||
if (headshot && this.getOwner() instanceof LivingEntity living) {
|
if (headshot && this.getOwner() instanceof LivingEntity living) {
|
||||||
living.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
if (!living.level().isClientSide() && living instanceof ServerPlayer player) {
|
||||||
capability.headIndicator = 25;
|
|
||||||
capability.syncPlayerVariables(living);
|
|
||||||
});
|
|
||||||
if (!living.level().isClientSide()) {
|
|
||||||
living.level().playSound(null, living.blockPosition(), TargetModSounds.HEADSHOT.get(), SoundSource.VOICE, 1, 1);
|
living.level().playSound(null, living.blockPosition(), TargetModSounds.HEADSHOT.get(), SoundSource.VOICE, 1, 1);
|
||||||
|
|
||||||
|
TargetMod.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> player), new ClientIndicatorMessage(1, 5));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,10 +33,11 @@ public class ClientEventHandler {
|
||||||
handleWeaponZoom(living);
|
handleWeaponZoom(living);
|
||||||
handleWeaponFire(event, living);
|
handleWeaponFire(event, living);
|
||||||
handleShockCamera(event, living);
|
handleShockCamera(event, living);
|
||||||
PlayerCameraShake(event, living);
|
handlePlayerCameraShake(event, living);
|
||||||
handleBowPullAnimation(living);
|
handleBowPullAnimation(living);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void handleWeaponSway(LivingEntity entity) {
|
private static void handleWeaponSway(LivingEntity entity) {
|
||||||
if (entity.getMainHandItem().is(TargetModTags.Items.GUN)) {
|
if (entity.getMainHandItem().is(TargetModTags.Items.GUN)) {
|
||||||
float fps = Minecraft.getInstance().getFps();
|
float fps = Minecraft.getInstance().getFps();
|
||||||
|
@ -426,7 +427,7 @@ public class ClientEventHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void PlayerCameraShake(ViewportEvent.ComputeCameraAngles event, LivingEntity entity) {
|
private static void handlePlayerCameraShake(ViewportEvent.ComputeCameraAngles event, LivingEntity entity) {
|
||||||
var data = entity.getPersistentData();
|
var data = entity.getPersistentData();
|
||||||
double yaw = event.getYaw();
|
double yaw = event.getYaw();
|
||||||
double pitch = event.getPitch();
|
double pitch = event.getPitch();
|
||||||
|
|
|
@ -8,12 +8,11 @@ import net.mcreator.target.init.TargetModSounds;
|
||||||
import net.mcreator.target.init.TargetModTags;
|
import net.mcreator.target.init.TargetModTags;
|
||||||
import net.mcreator.target.item.gun.GunItem;
|
import net.mcreator.target.item.gun.GunItem;
|
||||||
import net.mcreator.target.network.TargetModVariables;
|
import net.mcreator.target.network.TargetModVariables;
|
||||||
|
import net.mcreator.target.network.message.ClientIndicatorMessage;
|
||||||
import net.mcreator.target.network.message.PlayerGunKillMessage;
|
import net.mcreator.target.network.message.PlayerGunKillMessage;
|
||||||
import net.mcreator.target.tools.SoundTool;
|
import net.mcreator.target.tools.SoundTool;
|
||||||
import net.minecraft.core.registries.Registries;
|
|
||||||
import net.minecraft.network.protocol.game.ClientboundStopSoundPacket;
|
import net.minecraft.network.protocol.game.ClientboundStopSoundPacket;
|
||||||
import net.minecraft.resources.ResourceKey;
|
import net.minecraft.resources.ResourceKey;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.sounds.SoundSource;
|
import net.minecraft.sounds.SoundSource;
|
||||||
|
@ -126,12 +125,9 @@ public class LivingEventHandler {
|
||||||
|
|
||||||
if (!sourceEntity.level().isClientSide() && sourceEntity instanceof ServerPlayer player) {
|
if (!sourceEntity.level().isClientSide() && sourceEntity instanceof ServerPlayer player) {
|
||||||
SoundTool.playLocalSound(player, TargetModSounds.TARGET_DOWN.get(), 100f, 1f);
|
SoundTool.playLocalSound(player, TargetModSounds.TARGET_DOWN.get(), 100f, 1f);
|
||||||
}
|
|
||||||
|
|
||||||
sourceEntity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
TargetMod.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> player), new ClientIndicatorMessage(2, 8));
|
||||||
capability.killIndicator = 40;
|
}
|
||||||
capability.syncPlayerVariables(sourceEntity);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void renderDamageIndicator(LivingHurtEvent event) {
|
private static void renderDamageIndicator(LivingHurtEvent event) {
|
||||||
|
@ -140,20 +136,16 @@ public class LivingEventHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
var damagesource = event.getSource();
|
var damagesource = event.getSource();
|
||||||
var sourceEntity = event.getEntity();
|
var sourceEntity = damagesource.getDirectEntity();
|
||||||
|
|
||||||
if (damagesource == null || sourceEntity == null) {
|
if (sourceEntity == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sourceEntity instanceof Player && (damagesource.is(DamageTypes.EXPLOSION) || damagesource.is(DamageTypes.PLAYER_EXPLOSION) || damagesource.is(ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation("target:mine"))))) {
|
if (sourceEntity instanceof ServerPlayer player && (damagesource.is(DamageTypes.EXPLOSION) || damagesource.is(DamageTypes.PLAYER_EXPLOSION) || damagesource.is(TargetModDamageTypes.MINE))) {
|
||||||
if (sourceEntity.getServer() != null && sourceEntity instanceof ServerPlayer player) {
|
|
||||||
SoundTool.playLocalSound(player, TargetModSounds.INDICATION.get(), 1f, 1f);
|
SoundTool.playLocalSound(player, TargetModSounds.INDICATION.get(), 1f, 1f);
|
||||||
}
|
|
||||||
sourceEntity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
TargetMod.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> player), new ClientIndicatorMessage(0, 5));
|
||||||
capability.hitIndicator = 25;
|
|
||||||
capability.syncPlayerVariables(sourceEntity);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,6 @@ public class PlayerEventHandler {
|
||||||
handleSpecialWeaponAmmo(player);
|
handleSpecialWeaponAmmo(player);
|
||||||
handleChangeFireRate(player);
|
handleChangeFireRate(player);
|
||||||
handleDistantRange(player);
|
handleDistantRange(player);
|
||||||
handleRenderDamageIndicator(player);
|
|
||||||
handleBocekPulling(player);
|
handleBocekPulling(player);
|
||||||
handleGunRecoil(player);
|
handleGunRecoil(player);
|
||||||
}
|
}
|
||||||
|
@ -254,18 +253,6 @@ public class PlayerEventHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static void handleRenderDamageIndicator(Player player) {
|
|
||||||
if (player == null)
|
|
||||||
return;
|
|
||||||
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
|
||||||
capability.headIndicator = Math.max(0, capability.headIndicator - 5);
|
|
||||||
capability.hitIndicator = Math.max(0, capability.hitIndicator - 5);
|
|
||||||
capability.killIndicator = Math.max(0, capability.killIndicator - 5);
|
|
||||||
capability.syncPlayerVariables(player);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void handleBocekPulling(Player player) {
|
private static void handleBocekPulling(Player player) {
|
||||||
ItemStack mainHandItem = player.getMainHandItem();
|
ItemStack mainHandItem = player.getMainHandItem();
|
||||||
CompoundTag tag = mainHandItem.getOrCreateTag();
|
CompoundTag tag = mainHandItem.getOrCreateTag();
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package net.mcreator.target.network;
|
package net.mcreator.target.network;
|
||||||
|
|
||||||
|
import net.mcreator.target.client.screens.CrossHairOverlay;
|
||||||
import net.mcreator.target.event.KillMessageHandler;
|
import net.mcreator.target.event.KillMessageHandler;
|
||||||
|
import net.mcreator.target.network.message.ClientIndicatorMessage;
|
||||||
import net.mcreator.target.network.message.GunsDataMessage;
|
import net.mcreator.target.network.message.GunsDataMessage;
|
||||||
import net.mcreator.target.tools.GunsTool;
|
import net.mcreator.target.tools.GunsTool;
|
||||||
import net.mcreator.target.tools.PlayerKillRecord;
|
import net.mcreator.target.tools.PlayerKillRecord;
|
||||||
|
@ -29,4 +31,14 @@ public class ClientPacketHandler {
|
||||||
KillMessageHandler.QUEUE.offer(new PlayerKillRecord(attacker, target, attacker.getMainHandItem(), headshot, damageType));
|
KillMessageHandler.QUEUE.offer(new PlayerKillRecord(attacker, target, attacker.getMainHandItem(), headshot, damageType));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void handleClientIndicatorMessage(ClientIndicatorMessage message, Supplier<NetworkEvent.Context> ctx) {
|
||||||
|
if (ctx.get().getDirection().getReceptionSide() == LogicalSide.CLIENT) {
|
||||||
|
switch (message.type) {
|
||||||
|
case 1 -> CrossHairOverlay.HEAD_INDICATOR = message.value;
|
||||||
|
case 2 -> CrossHairOverlay.KILL_INDICATOR = message.value;
|
||||||
|
default -> CrossHairOverlay.HIT_INDICATOR = message.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,9 +90,9 @@ public class TargetModVariables {
|
||||||
clone.bowPullHold = original.bowPullHold;
|
clone.bowPullHold = original.bowPullHold;
|
||||||
clone.bowPull = original.bowPull;
|
clone.bowPull = original.bowPull;
|
||||||
clone.playerDoubleJump = original.playerDoubleJump;
|
clone.playerDoubleJump = original.playerDoubleJump;
|
||||||
clone.hitIndicator = original.hitIndicator;
|
// clone.hitIndicator = original.hitIndicator;
|
||||||
clone.headIndicator = original.headIndicator;
|
// clone.headIndicator = original.headIndicator;
|
||||||
clone.killIndicator = original.killIndicator;
|
// clone.killIndicator = original.killIndicator;
|
||||||
|
|
||||||
if (event.getEntity().level().isClientSide()) return;
|
if (event.getEntity().level().isClientSide()) return;
|
||||||
|
|
||||||
|
@ -280,9 +280,9 @@ public class TargetModVariables {
|
||||||
public boolean bowPullHold = false;
|
public boolean bowPullHold = false;
|
||||||
public boolean bowPull = false;
|
public boolean bowPull = false;
|
||||||
public boolean playerDoubleJump = false;
|
public boolean playerDoubleJump = false;
|
||||||
public int hitIndicator = 0;
|
// public int hitIndicator = 0;
|
||||||
public int headIndicator = 0;
|
// public int headIndicator = 0;
|
||||||
public int killIndicator = 0;
|
// public int killIndicator = 0;
|
||||||
|
|
||||||
public void syncPlayerVariables(Entity entity) {
|
public void syncPlayerVariables(Entity entity) {
|
||||||
if (entity instanceof ServerPlayer)
|
if (entity instanceof ServerPlayer)
|
||||||
|
@ -305,9 +305,9 @@ public class TargetModVariables {
|
||||||
nbt.putBoolean("bow_pull_hold", bowPullHold);
|
nbt.putBoolean("bow_pull_hold", bowPullHold);
|
||||||
nbt.putBoolean("bow_pull", bowPull);
|
nbt.putBoolean("bow_pull", bowPull);
|
||||||
nbt.putBoolean("player_double_jump", playerDoubleJump);
|
nbt.putBoolean("player_double_jump", playerDoubleJump);
|
||||||
nbt.putInt("hit_indicator", hitIndicator);
|
// nbt.putInt("hit_indicator", hitIndicator);
|
||||||
nbt.putInt("head_indicator", headIndicator);
|
// nbt.putInt("head_indicator", headIndicator);
|
||||||
nbt.putInt("kill_indicator", killIndicator);
|
// nbt.putInt("kill_indicator", killIndicator);
|
||||||
return nbt;
|
return nbt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -327,9 +327,9 @@ public class TargetModVariables {
|
||||||
bowPullHold = nbt.getBoolean("bow_pull_hold");
|
bowPullHold = nbt.getBoolean("bow_pull_hold");
|
||||||
bowPull = nbt.getBoolean("bow_pull");
|
bowPull = nbt.getBoolean("bow_pull");
|
||||||
playerDoubleJump = nbt.getBoolean("player_double_jump");
|
playerDoubleJump = nbt.getBoolean("player_double_jump");
|
||||||
hitIndicator = nbt.getInt("hit_indicator");
|
// hitIndicator = nbt.getInt("hit_indicator");
|
||||||
headIndicator = nbt.getInt("head_indicator");
|
// headIndicator = nbt.getInt("head_indicator");
|
||||||
killIndicator = nbt.getInt("kill_indicator");
|
// killIndicator = nbt.getInt("kill_indicator");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -386,9 +386,9 @@ public class TargetModVariables {
|
||||||
variables.bowPullHold = message.data.bowPullHold;
|
variables.bowPullHold = message.data.bowPullHold;
|
||||||
variables.bowPull = message.data.bowPull;
|
variables.bowPull = message.data.bowPull;
|
||||||
variables.playerDoubleJump = message.data.playerDoubleJump;
|
variables.playerDoubleJump = message.data.playerDoubleJump;
|
||||||
variables.hitIndicator = message.data.hitIndicator;
|
// variables.hitIndicator = message.data.hitIndicator;
|
||||||
variables.headIndicator = message.data.headIndicator;
|
// variables.headIndicator = message.data.headIndicator;
|
||||||
variables.killIndicator = message.data.killIndicator;
|
// variables.killIndicator = message.data.killIndicator;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
package net.mcreator.target.network.message;
|
||||||
|
|
||||||
|
import net.mcreator.target.network.ClientPacketHandler;
|
||||||
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
|
import net.minecraftforge.fml.DistExecutor;
|
||||||
|
import net.minecraftforge.network.NetworkEvent;
|
||||||
|
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
public class ClientIndicatorMessage {
|
||||||
|
public final int type;
|
||||||
|
public final int value;
|
||||||
|
|
||||||
|
public ClientIndicatorMessage(int type, int value) {
|
||||||
|
this.type = type;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void encode(ClientIndicatorMessage message, FriendlyByteBuf buffer) {
|
||||||
|
buffer.writeInt(message.type);
|
||||||
|
buffer.writeInt(message.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ClientIndicatorMessage decode(FriendlyByteBuf buffer) {
|
||||||
|
int type = buffer.readInt();
|
||||||
|
int value = buffer.readInt();
|
||||||
|
return new ClientIndicatorMessage(type, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void handler(ClientIndicatorMessage message, Supplier<NetworkEvent.Context> ctx) {
|
||||||
|
ctx.get().enqueueWork(() -> DistExecutor.unsafeRunWhenOn(Dist.CLIENT,
|
||||||
|
() -> () -> ClientPacketHandler.handleClientIndicatorMessage(message, ctx)));
|
||||||
|
ctx.get().setPacketHandled(true);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue