实现了村民恐慌功能
This commit is contained in:
parent
7476308b9b
commit
9882b065cd
5 changed files with 49 additions and 10 deletions
|
@ -163,6 +163,7 @@ public class ModUtils {
|
||||||
addNetworkMessage(RadarMenuCloseMessage.class, RadarMenuCloseMessage::encode, RadarMenuCloseMessage::decode, RadarMenuCloseMessage::handler, Optional.of(NetworkDirection.PLAY_TO_CLIENT));
|
addNetworkMessage(RadarMenuCloseMessage.class, RadarMenuCloseMessage::encode, RadarMenuCloseMessage::decode, RadarMenuCloseMessage::handler, Optional.of(NetworkDirection.PLAY_TO_CLIENT));
|
||||||
addNetworkMessage(RadarSetPosMessage.class, RadarSetPosMessage::encode, RadarSetPosMessage::decode, RadarSetPosMessage::handler);
|
addNetworkMessage(RadarSetPosMessage.class, RadarSetPosMessage::encode, RadarSetPosMessage::decode, RadarSetPosMessage::handler);
|
||||||
addNetworkMessage(PlayerStopRidingMessage.class, PlayerStopRidingMessage::encode, PlayerStopRidingMessage::decode, PlayerStopRidingMessage::handler);
|
addNetworkMessage(PlayerStopRidingMessage.class, PlayerStopRidingMessage::encode, PlayerStopRidingMessage::decode, PlayerStopRidingMessage::handler);
|
||||||
|
addNetworkMessage(AimVillagerMessage.class, AimVillagerMessage::encode, AimVillagerMessage::decode, AimVillagerMessage::handler);
|
||||||
|
|
||||||
event.enqueueWork(() -> BrewingRecipeRegistry.addRecipe(Ingredient.of(PotionUtils.setPotion(new ItemStack(Items.POTION), Potions.WATER)),
|
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())));
|
Ingredient.of(Items.LIGHTNING_ROD), PotionUtils.setPotion(new ItemStack(Items.POTION), ModPotion.SHOCK.get())));
|
||||||
|
|
|
@ -6,6 +6,7 @@ import com.atsuishio.superbwarfare.init.ModItems;
|
||||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||||
import com.atsuishio.superbwarfare.init.ModTags;
|
import com.atsuishio.superbwarfare.init.ModTags;
|
||||||
import com.atsuishio.superbwarfare.network.ModVariables;
|
import com.atsuishio.superbwarfare.network.ModVariables;
|
||||||
|
import com.atsuishio.superbwarfare.network.message.AimVillagerMessage;
|
||||||
import com.atsuishio.superbwarfare.network.message.SimulationDistanceMessage;
|
import com.atsuishio.superbwarfare.network.message.SimulationDistanceMessage;
|
||||||
import com.atsuishio.superbwarfare.tools.*;
|
import com.atsuishio.superbwarfare.tools.*;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
@ -17,7 +18,7 @@ import net.minecraft.world.effect.MobEffectInstance;
|
||||||
import net.minecraft.world.effect.MobEffects;
|
import net.minecraft.world.effect.MobEffects;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.EquipmentSlot;
|
import net.minecraft.world.entity.EquipmentSlot;
|
||||||
import net.minecraft.world.entity.npc.AbstractVillager;
|
import net.minecraft.world.entity.npc.Villager;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraftforge.event.AnvilUpdateEvent;
|
import net.minecraftforge.event.AnvilUpdateEvent;
|
||||||
|
@ -100,12 +101,11 @@ public class PlayerEventHandler {
|
||||||
public static void aimAtVillager(Player player) {
|
public static void aimAtVillager(Player player) {
|
||||||
if (player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables()).zoom) {
|
if (player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables()).zoom) {
|
||||||
Entity entity = TraceTool.findLookingEntity(player, 10);
|
Entity entity = TraceTool.findLookingEntity(player, 10);
|
||||||
if (entity instanceof AbstractVillager villager) {
|
if (entity instanceof Villager villager) {
|
||||||
List<Entity> gunner = SeekTool.seekLivingEntities(villager, villager.level(), 16, 120);
|
List<Entity> entities = SeekTool.seekLivingEntities(villager, villager.level(), 16, 120);
|
||||||
for (var e : gunner) {
|
for (var e : entities) {
|
||||||
if (e == player) {
|
if (e == player) {
|
||||||
// TODO 让村民恐慌并生气涨价
|
ModUtils.PACKET_HANDLER.sendToServer(new AimVillagerMessage(villager.getId()));
|
||||||
// villager.getBrain().addActivity(Activity.PANIC, );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,14 +61,11 @@ public class Cell extends Item {
|
||||||
return 0xFFFF00;
|
return 0xFFFF00;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) {
|
public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) {
|
||||||
super.inventoryTick(stack, world, entity, slot, selected);
|
super.inventoryTick(stack, world, entity, slot, selected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static ItemStack getGunInstance() {
|
public static ItemStack getGunInstance() {
|
||||||
ItemStack stack = new ItemStack(ModItems.TASER.get());
|
ItemStack stack = new ItemStack(ModItems.TASER.get());
|
||||||
stack.getCapability(ForgeCapabilities.ENERGY).ifPresent(
|
stack.getCapability(ForgeCapabilities.ENERGY).ifPresent(
|
||||||
|
@ -81,5 +78,4 @@ public class Cell extends Item {
|
||||||
public @NotNull Optional<TooltipComponent> getTooltipImage(@NotNull ItemStack pStack) {
|
public @NotNull Optional<TooltipComponent> getTooltipImage(@NotNull ItemStack pStack) {
|
||||||
return Optional.of(new CellImageComponent(pStack));
|
return Optional.of(new CellImageComponent(pStack));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,7 @@ import java.util.UUID;
|
||||||
|
|
||||||
@Mod.EventBusSubscriber
|
@Mod.EventBusSubscriber
|
||||||
public abstract class GunItem extends Item {
|
public abstract class GunItem extends Item {
|
||||||
|
|
||||||
public GunItem(Properties properties) {
|
public GunItem(Properties properties) {
|
||||||
super(properties);
|
super(properties);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
package com.atsuishio.superbwarfare.network.message;
|
||||||
|
|
||||||
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import net.minecraft.world.entity.ai.gossip.GossipType;
|
||||||
|
import net.minecraft.world.entity.npc.Villager;
|
||||||
|
import net.minecraft.world.entity.schedule.Activity;
|
||||||
|
import net.minecraftforge.network.NetworkEvent;
|
||||||
|
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
public class AimVillagerMessage {
|
||||||
|
|
||||||
|
private final int villagerId;
|
||||||
|
|
||||||
|
public AimVillagerMessage(int villagerId) {
|
||||||
|
this.villagerId = villagerId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void encode(AimVillagerMessage message, FriendlyByteBuf buffer) {
|
||||||
|
buffer.writeInt(message.villagerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AimVillagerMessage decode(FriendlyByteBuf buffer) {
|
||||||
|
return new AimVillagerMessage(buffer.readInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void handler(AimVillagerMessage message, Supplier<NetworkEvent.Context> context) {
|
||||||
|
context.get().enqueueWork(() -> {
|
||||||
|
var sender = context.get().getSender();
|
||||||
|
if (sender == null) return;
|
||||||
|
|
||||||
|
Entity entity = sender.level().getEntity(message.villagerId);
|
||||||
|
if (entity instanceof Villager villager) {
|
||||||
|
villager.getBrain().setActiveActivityIfPossible(Activity.PANIC);
|
||||||
|
villager.getGossips().add(sender.getUUID(), GossipType.MINOR_NEGATIVE, 10);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
context.get().setPacketHandled(true);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue