添加雷达扫描基础部件
This commit is contained in:
parent
970420d94b
commit
a832317c25
8 changed files with 134 additions and 11 deletions
|
@ -159,6 +159,8 @@ public class ModUtils {
|
|||
addNetworkMessage(RadarChangeModeMessage.class, RadarChangeModeMessage::encode, RadarChangeModeMessage::decode, RadarChangeModeMessage::handler);
|
||||
addNetworkMessage(RadarSetParametersMessage.class, RadarSetParametersMessage::encode, RadarSetParametersMessage::decode, RadarSetParametersMessage::handler);
|
||||
addNetworkMessage(LungeMineAttackMessage.class, LungeMineAttackMessage::encode, LungeMineAttackMessage::decode, LungeMineAttackMessage::handler);
|
||||
addNetworkMessage(RadarMenuOpenMessage.class, RadarMenuOpenMessage::encode, RadarMenuOpenMessage::decode, RadarMenuOpenMessage::handler, Optional.of(NetworkDirection.PLAY_TO_CLIENT));
|
||||
addNetworkMessage(RadarMenuCloseMessage.class, RadarMenuCloseMessage::encode, RadarMenuCloseMessage::decode, RadarMenuCloseMessage::handler, 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())));
|
||||
|
|
|
@ -52,6 +52,10 @@ public class FuMO25Screen extends AbstractContainerScreen<FuMO25Menu> {
|
|||
private void renderScan(GuiGraphics guiGraphics, float partialTick) {
|
||||
if (FuMO25Screen.this.menu.getEnergy() <= 0) return;
|
||||
|
||||
var entities = FuMO25ScreenHelper.entities;
|
||||
if (entities.isEmpty()) return;
|
||||
|
||||
guiGraphics.drawString(this.font, Component.literal("Entity Count: " + entities.size()), 12, 10, 0xffffff, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
package com.atsuishio.superbwarfare.client.screens;
|
||||
|
||||
import com.atsuishio.superbwarfare.block.entity.FuMO25BlockEntity;
|
||||
import com.atsuishio.superbwarfare.menu.FuMO25Menu;
|
||||
import com.atsuishio.superbwarfare.tools.SeekTool;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.event.TickEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerContainerEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
@ -15,18 +16,12 @@ import net.minecraftforge.fml.common.Mod;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE)
|
||||
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT)
|
||||
public class FuMO25ScreenHelper {
|
||||
|
||||
public static BlockPos pos = null;
|
||||
public static List<Entity> entities = new ArrayList<>();
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onContainerClosed(PlayerContainerEvent.Close event) {
|
||||
if (event.getContainer() instanceof FuMO25Menu menu && event.getEntity() instanceof ServerPlayer serverPlayer) {
|
||||
serverPlayer.displayClientMessage(Component.literal("Closed!"), false);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onClientTick(TickEvent.ClientTickEvent event) {
|
||||
if (event.side != LogicalSide.CLIENT) return;
|
||||
|
@ -35,7 +30,22 @@ public class FuMO25ScreenHelper {
|
|||
if (player == null) return;
|
||||
var menu = player.containerMenu;
|
||||
if (!(menu instanceof FuMO25Menu fuMO25Menu)) return;
|
||||
if (pos == null) return;
|
||||
|
||||
if (fuMO25Menu.getEnergy() <= 0) {
|
||||
if (entities != null) {
|
||||
entities.clear();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
var funcType = fuMO25Menu.getFuncType();
|
||||
entities = SeekTool.getEntitiesWithinRange(pos, player.level(), funcType == 1 ? FuMO25BlockEntity.MAX_RANGE : FuMO25BlockEntity.DEFAULT_RANGE);
|
||||
}
|
||||
|
||||
public static void resetEntities() {
|
||||
if (entities != null) {
|
||||
entities.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,6 +56,7 @@ import static com.atsuishio.superbwarfare.entity.SpeedboatEntity.HEAT;
|
|||
|
||||
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT)
|
||||
public class ClientEventHandler {
|
||||
|
||||
public static double zoomTime = 0;
|
||||
public static double zoomPos = 0;
|
||||
public static double zoomPosZ = 0;
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
package com.atsuishio.superbwarfare.menu;
|
||||
|
||||
import com.atsuishio.superbwarfare.ModUtils;
|
||||
import com.atsuishio.superbwarfare.block.entity.FuMO25BlockEntity;
|
||||
import com.atsuishio.superbwarfare.init.ModBlocks;
|
||||
import com.atsuishio.superbwarfare.init.ModItems;
|
||||
import com.atsuishio.superbwarfare.init.ModMenuTypes;
|
||||
import com.atsuishio.superbwarfare.network.dataslot.ContainerEnergyData;
|
||||
import com.atsuishio.superbwarfare.network.dataslot.SimpleEnergyData;
|
||||
import com.atsuishio.superbwarfare.network.message.RadarMenuCloseMessage;
|
||||
import com.atsuishio.superbwarfare.network.message.RadarMenuOpenMessage;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.SimpleContainer;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
|
@ -14,9 +18,15 @@ import net.minecraft.world.entity.player.Player;
|
|||
import net.minecraft.world.inventory.ContainerLevelAccess;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.event.entity.player.PlayerContainerEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.network.PacketDistributor;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Optional;
|
||||
|
||||
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE)
|
||||
public class FuMO25Menu extends EnergyMenu {
|
||||
|
||||
protected final Container container;
|
||||
|
@ -94,6 +104,10 @@ public class FuMO25Menu extends EnergyMenu {
|
|||
return null;
|
||||
}
|
||||
|
||||
public Optional<BlockPos> getSelfPos() {
|
||||
return this.access.evaluate((level, pos) -> pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack quickMoveStack(Player pPlayer, int pIndex) {
|
||||
ItemStack itemstack = ItemStack.EMPTY;
|
||||
|
@ -182,4 +196,19 @@ public class FuMO25Menu extends EnergyMenu {
|
|||
return pStack.is(ModItems.FIRING_PARAMETERS.get());
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onContainerOpened(PlayerContainerEvent.Open event) {
|
||||
if (event.getContainer() instanceof FuMO25Menu fuMO25Menu && event.getEntity() instanceof ServerPlayer serverPlayer) {
|
||||
fuMO25Menu.getSelfPos().ifPresent(pos ->
|
||||
ModUtils.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> serverPlayer), new RadarMenuOpenMessage(pos)));
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onContainerClosed(PlayerContainerEvent.Close event) {
|
||||
if (event.getContainer() instanceof FuMO25Menu && event.getEntity() instanceof ServerPlayer serverPlayer) {
|
||||
ModUtils.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> serverPlayer), new RadarMenuCloseMessage(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,12 +2,14 @@ package com.atsuishio.superbwarfare.network;
|
|||
|
||||
import com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay;
|
||||
import com.atsuishio.superbwarfare.client.overlay.DroneUIOverlay;
|
||||
import com.atsuishio.superbwarfare.client.screens.FuMO25ScreenHelper;
|
||||
import com.atsuishio.superbwarfare.config.client.KillMessageConfig;
|
||||
import com.atsuishio.superbwarfare.event.KillMessageHandler;
|
||||
import com.atsuishio.superbwarfare.menu.EnergyMenu;
|
||||
import com.atsuishio.superbwarfare.network.message.ClientIndicatorMessage;
|
||||
import com.atsuishio.superbwarfare.network.message.ContainerDataMessage;
|
||||
import com.atsuishio.superbwarfare.network.message.GunsDataMessage;
|
||||
import com.atsuishio.superbwarfare.network.message.RadarMenuOpenMessage;
|
||||
import com.atsuishio.superbwarfare.tools.GunsTool;
|
||||
import com.atsuishio.superbwarfare.tools.PlayerKillRecord;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
@ -62,4 +64,14 @@ public class ClientPacketHandler {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void handleRadarMenuOpen(RadarMenuOpenMessage message, Supplier<NetworkEvent.Context> ctx) {
|
||||
FuMO25ScreenHelper.resetEntities();
|
||||
FuMO25ScreenHelper.pos = message.pos;
|
||||
}
|
||||
|
||||
public static void handleRadarMenuClose() {
|
||||
FuMO25ScreenHelper.resetEntities();
|
||||
FuMO25ScreenHelper.pos = null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
package com.atsuishio.superbwarfare.network.message;
|
||||
|
||||
import com.atsuishio.superbwarfare.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 RadarMenuCloseMessage {
|
||||
|
||||
public int type;
|
||||
|
||||
public RadarMenuCloseMessage(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public static void encode(RadarMenuCloseMessage message, FriendlyByteBuf buffer) {
|
||||
buffer.writeInt(message.type);
|
||||
}
|
||||
|
||||
public static RadarMenuCloseMessage decode(FriendlyByteBuf buffer) {
|
||||
return new RadarMenuCloseMessage(buffer.readInt());
|
||||
}
|
||||
|
||||
public static void handler(RadarMenuCloseMessage message, Supplier<NetworkEvent.Context> ctx) {
|
||||
ctx.get().enqueueWork(() -> DistExecutor.unsafeRunWhenOn(Dist.CLIENT,
|
||||
() -> ClientPacketHandler::handleRadarMenuClose));
|
||||
ctx.get().setPacketHandled(true);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package com.atsuishio.superbwarfare.network.message;
|
||||
|
||||
import com.atsuishio.superbwarfare.network.ClientPacketHandler;
|
||||
import net.minecraft.core.BlockPos;
|
||||
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 RadarMenuOpenMessage {
|
||||
|
||||
public BlockPos pos;
|
||||
|
||||
public RadarMenuOpenMessage(BlockPos pos) {
|
||||
this.pos = pos;
|
||||
}
|
||||
|
||||
public static void encode(RadarMenuOpenMessage message, FriendlyByteBuf buffer) {
|
||||
buffer.writeBlockPos(message.pos);
|
||||
}
|
||||
|
||||
public static RadarMenuOpenMessage decode(FriendlyByteBuf buffer) {
|
||||
return new RadarMenuOpenMessage(buffer.readBlockPos());
|
||||
}
|
||||
|
||||
public static void handler(RadarMenuOpenMessage message, Supplier<NetworkEvent.Context> ctx) {
|
||||
ctx.get().enqueueWork(() -> DistExecutor.unsafeRunWhenOn(Dist.CLIENT,
|
||||
() -> () -> ClientPacketHandler.handleRadarMenuOpen(message, ctx)));
|
||||
ctx.get().setPacketHandled(true);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue