优化载具捡起物品,添加载具队伍显示
This commit is contained in:
parent
a6885e5ba0
commit
222a9707a7
3 changed files with 102 additions and 27 deletions
|
@ -0,0 +1,62 @@
|
|||
package com.atsuishio.superbwarfare.client.overlay;
|
||||
|
||||
import com.atsuishio.superbwarfare.ModUtils;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.VehicleEntity;
|
||||
import com.atsuishio.superbwarfare.tools.TraceTool;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.RenderGuiEvent;
|
||||
import net.minecraftforge.eventbus.api.EventPriority;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
@Mod.EventBusSubscriber(value = Dist.CLIENT)
|
||||
public class VehicleTeamOverlay {
|
||||
|
||||
private static final ResourceLocation TRIANGLE = ModUtils.loc("textures/screens/red_triangle.png");
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.NORMAL)
|
||||
public static void eventHandler(RenderGuiEvent.Pre event) {
|
||||
int w = event.getWindow().getGuiScaledWidth();
|
||||
int h = event.getWindow().getGuiScaledHeight();
|
||||
Player player = Minecraft.getInstance().player;
|
||||
PoseStack poseStack = event.getGuiGraphics().pose();
|
||||
if (player == null) return;
|
||||
|
||||
boolean lookAtEntity = false;
|
||||
|
||||
double entityRange = 0;
|
||||
Entity lookingEntity = TraceTool.findLookingEntity(player, 520);
|
||||
|
||||
if (lookingEntity instanceof VehicleEntity) {
|
||||
lookAtEntity = true;
|
||||
entityRange = player.distanceTo(lookingEntity);
|
||||
}
|
||||
|
||||
if (lookAtEntity) {
|
||||
|
||||
poseStack.pushPose();
|
||||
poseStack.scale(0.8f, 0.8f, 1);
|
||||
if (lookingEntity.getFirstPassenger() instanceof Player player1) {
|
||||
event.getGuiGraphics().drawString(Minecraft.getInstance().font,
|
||||
Component.literal(player1.getDisplayName().getString() + (player1.getTeam() == null ? "" : " <" + (player1.getTeam().getName()) + ">")),
|
||||
w / 2 + 90, h / 2 - 4, player1.getTeamColor(), false);
|
||||
event.getGuiGraphics().drawString(Minecraft.getInstance().font,
|
||||
Component.literal(lookingEntity.getDisplayName().getString() + " " + new DecimalFormat("##.#").format(entityRange) + "M"),
|
||||
w / 2 + 90, h / 2 + 5, player1.getTeamColor(), false);
|
||||
} else {
|
||||
event.getGuiGraphics().drawString(Minecraft.getInstance().font,
|
||||
Component.literal(lookingEntity.getDisplayName().getString() + " " + new DecimalFormat("##.#").format(entityRange) + "M"),
|
||||
w / 2 + 90, h / 2 + 5, -1, false);
|
||||
}
|
||||
poseStack.popPose();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -12,14 +12,12 @@ import net.minecraft.world.InteractionHand;
|
|||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.HasCustomInventoryScreen;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.entity.vehicle.ContainerEntity;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.HopperBlockEntity;
|
||||
import net.minecraft.world.level.gameevent.GameEvent;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.capabilities.ForgeCapabilities;
|
||||
|
@ -29,8 +27,6 @@ import net.minecraftforge.items.wrapper.InvWrapper;
|
|||
import org.jetbrains.annotations.Nullable;
|
||||
import org.joml.Math;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ContainerMobileEntity extends MobileVehicleEntity implements HasCustomInventoryScreen, ContainerEntity {
|
||||
|
||||
public static final int CONTAINER_SIZE = 102;
|
||||
|
@ -84,7 +80,7 @@ public class ContainerMobileEntity extends MobileVehicleEntity implements HasCus
|
|||
@Override
|
||||
public void baseTick() {
|
||||
super.baseTick();
|
||||
pickUpItem();
|
||||
// pickUpItem();
|
||||
|
||||
this.getItemStacks().stream().filter(stack -> stack.is(ModItems.CELL.get()) && stack.getCapability(ForgeCapabilities.ENERGY).map(IEnergyStorage::getEnergyStored).orElse(0) > 0)
|
||||
.forEach(stack ->
|
||||
|
@ -100,16 +96,16 @@ public class ContainerMobileEntity extends MobileVehicleEntity implements HasCus
|
|||
this.refreshDimensions();
|
||||
}
|
||||
|
||||
public void pickUpItem() {
|
||||
List<ItemEntity> list = this.level().getEntitiesOfClass(ItemEntity.class, this.getBoundingBox().inflate(0.2F, 0.1, 0.2F));
|
||||
if (!list.isEmpty()) {
|
||||
for (ItemEntity entity : list) {
|
||||
if (!this.level().isClientSide) {
|
||||
HopperBlockEntity.addItem(this, entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// public void pickUpItem() {
|
||||
// List<ItemEntity> list = this.level().getEntitiesOfClass(ItemEntity.class, this.getBoundingBox().inflate(0.2F, 0.1, 0.2F));
|
||||
// if (!list.isEmpty()) {
|
||||
// for (ItemEntity entity : list) {
|
||||
// if (!this.level().isClientSide) {
|
||||
// HopperBlockEntity.addItem(this, entity);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void openCustomInventoryScreen(Player pPlayer) {
|
||||
|
|
|
@ -7,6 +7,7 @@ import com.atsuishio.superbwarfare.config.common.GameplayConfig;
|
|||
import com.atsuishio.superbwarfare.entity.ICustomKnockback;
|
||||
import com.atsuishio.superbwarfare.entity.TargetEntity;
|
||||
import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.ContainerMobileEntity;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.IArmedVehicleEntity;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.VehicleEntity;
|
||||
import com.atsuishio.superbwarfare.init.*;
|
||||
|
@ -38,11 +39,11 @@ import net.minecraft.world.entity.LivingEntity;
|
|||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.entity.projectile.Projectile;
|
||||
import net.minecraft.world.entity.vehicle.ContainerEntity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.GameRules;
|
||||
import net.minecraft.world.level.block.entity.HopperBlockEntity;
|
||||
import net.minecraftforge.event.entity.living.*;
|
||||
import net.minecraftforge.event.entity.player.EntityItemPickupEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.network.PacketDistributor;
|
||||
|
@ -730,6 +731,17 @@ public class LivingEventHandler {
|
|||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onPickup(EntityItemPickupEvent event) {
|
||||
if (event.getEntity().getVehicle() instanceof ContainerMobileEntity containerMobileEntity) {
|
||||
var pickUp = event.getItem();
|
||||
if (!containerMobileEntity.level().isClientSide) {
|
||||
HopperBlockEntity.addItem(containerMobileEntity, pickUp);
|
||||
}
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onLivingDrops(LivingDropsEvent event) {
|
||||
DamageSource source = event.getSource();
|
||||
|
@ -738,18 +750,16 @@ public class LivingEventHandler {
|
|||
if (!(sourceEntity instanceof Player player)) return;
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
|
||||
if (sourceEntity.getVehicle() instanceof IArmedVehicleEntity vehicle && source.is(ModDamageTypes.VEHICLE_STRIKE)) {
|
||||
if (player.getVehicle() instanceof ContainerMobileEntity containerMobileEntity && source.is(ModDamageTypes.VEHICLE_STRIKE)) {
|
||||
var drops = event.getDrops();
|
||||
if (vehicle instanceof ContainerEntity containerEntity) {
|
||||
drops.forEach(itemEntity -> {
|
||||
ItemStack item = itemEntity.getItem();
|
||||
if (!HopperBlockEntity.addItem(containerEntity, itemEntity)) {
|
||||
player.drop(item, false);
|
||||
}
|
||||
});
|
||||
event.setCanceled(true);
|
||||
return;
|
||||
}
|
||||
drops.forEach(itemEntity -> {
|
||||
ItemStack item = itemEntity.getItem();
|
||||
if (!HopperBlockEntity.addItem(containerMobileEntity, itemEntity)) {
|
||||
player.drop(item, false);
|
||||
}
|
||||
});
|
||||
event.setCanceled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (stack.is(ModTags.Items.GUN) && PerkHelper.getItemPerkLevel(ModPerks.POWERFUL_ATTRACTION.get(), stack) > 0) {
|
||||
|
@ -768,6 +778,13 @@ public class LivingEventHandler {
|
|||
public static void onLivingExperienceDrop(LivingExperienceDropEvent event) {
|
||||
Player player = event.getAttackingPlayer();
|
||||
if (player == null) return;
|
||||
|
||||
if (player.getVehicle() instanceof IArmedVehicleEntity) {
|
||||
player.giveExperiencePoints(event.getDroppedExperience());
|
||||
event.setCanceled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) return;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue