修复服务器问题
This commit is contained in:
parent
1305b5e4e8
commit
b71666300c
6 changed files with 89 additions and 40 deletions
|
@ -124,6 +124,7 @@ public class ModUtils {
|
|||
addNetworkMessage(ModVariables.PlayerVariablesSyncMessage.class, ModVariables.PlayerVariablesSyncMessage::buffer, ModVariables.PlayerVariablesSyncMessage::new, ModVariables.PlayerVariablesSyncMessage::handler);
|
||||
addNetworkMessage(ShootMessage.class, ShootMessage::encode, ShootMessage::decode, ShootMessage::handler);
|
||||
addNetworkMessage(ShootClientMessage.class, ShootClientMessage::encode, ShootClientMessage::decode, ShootClientMessage::handle, Optional.of(NetworkDirection.PLAY_TO_CLIENT));
|
||||
addNetworkMessage(DrawClientMessage.class, DrawClientMessage::encode, DrawClientMessage::decode, DrawClientMessage::handle, Optional.of(NetworkDirection.PLAY_TO_CLIENT));
|
||||
|
||||
event.enqueueWork(() -> BrewingRecipeRegistry.addRecipe(Ingredient.of(PotionUtils.setPotion(new ItemStack(Items.POTION), Potions.WATER)),
|
||||
Ingredient.of(Items.LIGHTNING_ROD), PotionUtils.setPotion(new ItemStack(Items.POTION), ModPotion.SHOCK.get())));
|
||||
|
|
|
@ -7,7 +7,6 @@ import net.mcreator.superbwarfare.entity.ICannonEntity;
|
|||
import net.mcreator.superbwarfare.init.ModItems;
|
||||
import net.mcreator.superbwarfare.init.ModMobEffects;
|
||||
import net.mcreator.superbwarfare.init.ModTags;
|
||||
import net.mcreator.superbwarfare.item.gun.GunItem;
|
||||
import net.mcreator.superbwarfare.network.ModVariables;
|
||||
import net.mcreator.superbwarfare.network.message.ShootMessage;
|
||||
import net.mcreator.superbwarfare.perk.AmmoPerk;
|
||||
|
@ -24,7 +23,6 @@ import net.minecraft.util.Mth;
|
|||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.entity.HumanoidArm;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
@ -37,7 +35,6 @@ import net.minecraftforge.client.event.RenderHandEvent;
|
|||
import net.minecraftforge.client.event.ViewportEvent;
|
||||
import net.minecraftforge.client.gui.overlay.VanillaGuiOverlay;
|
||||
import net.minecraftforge.event.TickEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingEquipmentChangeEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
@ -817,26 +814,35 @@ public class ClientEventHandler {
|
|||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void handleChangeSlot(LivingEquipmentChangeEvent event) {
|
||||
if (event.getEntity() instanceof Player && event.getSlot() == EquipmentSlot.MAINHAND) {
|
||||
ItemStack oldStack = event.getFrom();
|
||||
ItemStack newStack = event.getTo();
|
||||
// @SubscribeEvent
|
||||
// public static void handleChangeSlot(LivingEquipmentChangeEvent event) {
|
||||
// if (event.getEntity() instanceof Player && event.getSlot() == EquipmentSlot.MAINHAND) {
|
||||
// ItemStack oldStack = event.getFrom();
|
||||
// ItemStack newStack = event.getTo();
|
||||
//
|
||||
// if (newStack.getItem() != oldStack.getItem()
|
||||
// || newStack.getTag() == null || oldStack.getTag() == null
|
||||
// || !newStack.getTag().hasUUID("gun_uuid") || !oldStack.getTag().hasUUID("gun_uuid")
|
||||
// || !newStack.getTag().getUUID("gun_uuid").equals(oldStack.getTag().getUUID("gun_uuid"))
|
||||
// ) {
|
||||
// if (newStack.getItem() instanceof GunItem) {
|
||||
// drawTime = 1;
|
||||
// for (int i = 0; i < 5; i++) {
|
||||
// shellIndexTime[i] = 0;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
if (newStack.getItem() != oldStack.getItem()
|
||||
|| newStack.getTag() == null || oldStack.getTag() == null
|
||||
|| !newStack.getTag().hasUUID("gun_uuid") || !oldStack.getTag().hasUUID("gun_uuid")
|
||||
|| !newStack.getTag().getUUID("gun_uuid").equals(oldStack.getTag().getUUID("gun_uuid"))
|
||||
) {
|
||||
if (newStack.getItem() instanceof GunItem) {
|
||||
public static void handleDrawMessage(boolean draw, Supplier<NetworkEvent.Context> ctx) {
|
||||
if (ctx.get().getDirection().getReceptionSide() == LogicalSide.CLIENT) {
|
||||
drawTime = 1;
|
||||
for (int i = 0; i < 5; i++) {
|
||||
shellIndexTime[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void handleWeaponDraw(LivingEntity entity) {
|
||||
float times = Minecraft.getInstance().getDeltaFrameTime();
|
||||
|
|
|
@ -8,6 +8,7 @@ import net.mcreator.superbwarfare.init.*;
|
|||
import net.mcreator.superbwarfare.item.gun.GunItem;
|
||||
import net.mcreator.superbwarfare.network.ModVariables;
|
||||
import net.mcreator.superbwarfare.network.message.ClientIndicatorMessage;
|
||||
import net.mcreator.superbwarfare.network.message.DrawClientMessage;
|
||||
import net.mcreator.superbwarfare.network.message.PlayerGunKillMessage;
|
||||
import net.mcreator.superbwarfare.perk.AmmoPerk;
|
||||
import net.mcreator.superbwarfare.perk.Perk;
|
||||
|
@ -319,6 +320,10 @@ public class LivingEventHandler {
|
|||
newStack.getOrCreateTag().putInt("KillingTally", 0);
|
||||
}
|
||||
|
||||
if (player.level() instanceof ServerLevel) {
|
||||
ModUtils.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> serverPlayer), new DrawClientMessage(true));
|
||||
}
|
||||
|
||||
player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||
capability.tacticalSprint = false;
|
||||
capability.syncPlayerVariables(player);
|
||||
|
|
|
@ -4,8 +4,7 @@ import com.google.common.collect.ImmutableMultimap;
|
|||
import com.google.common.collect.Multimap;
|
||||
import net.mcreator.superbwarfare.entity.DroneEntity;
|
||||
import net.mcreator.superbwarfare.tools.ItemNBTTool;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.mcreator.superbwarfare.tools.TooltipTool;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResultHolder;
|
||||
|
@ -20,7 +19,6 @@ import net.minecraft.world.item.ItemStack;
|
|||
import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.List;
|
||||
|
||||
public class Monitor extends Item {
|
||||
|
@ -67,39 +65,28 @@ public class Monitor extends Item {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Multimap<Attribute, AttributeModifier> getAttributeModifiers(EquipmentSlot slot, ItemStack stack) {
|
||||
if (slot == EquipmentSlot.MAINHAND) {
|
||||
public Multimap<Attribute, AttributeModifier> getDefaultAttributeModifiers(EquipmentSlot equipmentSlot) {
|
||||
if (equipmentSlot == EquipmentSlot.MAINHAND) {
|
||||
ImmutableMultimap.Builder<Attribute, AttributeModifier> builder = ImmutableMultimap.builder();
|
||||
builder.putAll(super.getAttributeModifiers(slot, stack));
|
||||
builder.putAll(super.getDefaultAttributeModifiers(equipmentSlot));
|
||||
builder.put(Attributes.ATTACK_DAMAGE, new AttributeModifier(BASE_ATTACK_DAMAGE_UUID, "Item modifier", 2d, AttributeModifier.Operation.ADDITION));
|
||||
builder.put(Attributes.ATTACK_SPEED, new AttributeModifier(BASE_ATTACK_SPEED_UUID, "Item modifier", -2.4, AttributeModifier.Operation.ADDITION));
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
return super.getAttributeModifiers(slot, stack);
|
||||
return super.getDefaultAttributeModifiers(equipmentSlot);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void appendHoverText(ItemStack stack, Level world, List<Component> list, TooltipFlag flag) {
|
||||
if (stack.getOrCreateTag().getString(LINKED_DRONE).equals("none")) return;
|
||||
|
||||
Player player = Minecraft.getInstance().player;
|
||||
if (player == null) return;
|
||||
|
||||
DroneEntity entity = player.level().getEntitiesOfClass(DroneEntity.class, player.getBoundingBox().inflate(512))
|
||||
.stream().filter(e -> e.getStringUUID().equals(stack.getOrCreateTag().getString(LINKED_DRONE))).findFirst().orElse(null);
|
||||
if (entity == null) return;
|
||||
|
||||
list.add(Component.translatable("des.superbwarfare.tips.distance").withStyle(ChatFormatting.GRAY)
|
||||
.append(Component.literal("").withStyle(ChatFormatting.RESET))
|
||||
.append(Component.literal("Distance:" + new DecimalFormat("##.#").format(player.distanceTo(entity)) + "M").withStyle(ChatFormatting.GRAY)));
|
||||
TooltipTool.addMonitorTips(list, stack.getOrCreateTag().getString(LINKED_DRONE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inventoryTick(ItemStack itemstack, Level world, Entity entity, int slot, boolean selected) {
|
||||
super.inventoryTick(itemstack, world, entity, slot, selected);
|
||||
if (!selected) {
|
||||
itemstack.getOrCreateTag().putBoolean("Using", false);
|
||||
itemstack.getOrCreateTag().putBoolean("Using",false);
|
||||
DroneEntity drone = entity.level().getEntitiesOfClass(DroneEntity.class, entity.getBoundingBox().inflate(512))
|
||||
.stream().filter(e -> e.getStringUUID().equals(itemstack.getOrCreateTag().getString("LinkedDrone"))).findFirst().orElse(null);
|
||||
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
package net.mcreator.superbwarfare.network.message;
|
||||
|
||||
import net.mcreator.superbwarfare.event.ClientEventHandler;
|
||||
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 DrawClientMessage {
|
||||
public boolean draw;
|
||||
|
||||
public DrawClientMessage(boolean draw) {
|
||||
this.draw = draw;
|
||||
}
|
||||
|
||||
public static void encode(DrawClientMessage message, FriendlyByteBuf buffer) {
|
||||
buffer.writeBoolean(message.draw);
|
||||
}
|
||||
|
||||
public static DrawClientMessage decode(FriendlyByteBuf buffer) {
|
||||
return new DrawClientMessage(buffer.readBoolean());
|
||||
}
|
||||
|
||||
public static void handle(DrawClientMessage message, Supplier<NetworkEvent.Context> context) {
|
||||
context.get().enqueueWork(() -> DistExecutor.unsafeRunWhenOn(Dist.CLIENT,
|
||||
() -> () -> ClientEventHandler.handleDrawMessage(message.draw, context)));
|
||||
context.get().setPacketHandled(true);
|
||||
}
|
||||
}
|
|
@ -1,15 +1,18 @@
|
|||
package net.mcreator.superbwarfare.tools;
|
||||
|
||||
import net.mcreator.superbwarfare.entity.DroneEntity;
|
||||
import net.mcreator.superbwarfare.init.ModPerks;
|
||||
import net.mcreator.superbwarfare.init.ModTags;
|
||||
import net.mcreator.superbwarfare.perk.AmmoPerk;
|
||||
import net.mcreator.superbwarfare.perk.Perk;
|
||||
import net.mcreator.superbwarfare.perk.PerkHelper;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.common.capabilities.ForgeCapabilities;
|
||||
|
||||
|
@ -305,4 +308,20 @@ public class TooltipTool {
|
|||
|
||||
}
|
||||
|
||||
public static void addMonitorTips(List<Component> tooltip, String id) {
|
||||
if (id.equals("none")) return;
|
||||
|
||||
Player player = Minecraft.getInstance().player;
|
||||
if (player == null) return;
|
||||
|
||||
DroneEntity entity = player.level().getEntitiesOfClass(DroneEntity.class, player.getBoundingBox().inflate(512))
|
||||
.stream().filter(e -> e.getStringUUID().equals(id)).findFirst().orElse(null);
|
||||
|
||||
if (entity == null) return;
|
||||
|
||||
tooltip.add(Component.translatable("des.superbwarfare.tips.distance").withStyle(ChatFormatting.GRAY)
|
||||
.append(Component.literal("").withStyle(ChatFormatting.RESET))
|
||||
.append(Component.literal("Distance:" + new DecimalFormat("##.#").format(player.distanceTo(entity)) + "M").withStyle(ChatFormatting.GRAY)));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue