添加爆炸效果的图标渲染
This commit is contained in:
parent
6541e94efa
commit
6f5a440d41
5 changed files with 37 additions and 9 deletions
|
@ -7,6 +7,7 @@ import net.mcreator.target.tools.PlayerKillRecord;
|
|||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.damagesource.DamageTypes;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.RenderGuiEvent;
|
||||
|
@ -18,6 +19,10 @@ import net.minecraftforge.fml.common.Mod;
|
|||
public class KillMessageOverlay {
|
||||
private static final ResourceLocation HEADSHOT = new ResourceLocation(TargetMod.MODID, "textures/screens/headshot.png");
|
||||
|
||||
private static final ResourceLocation KNIFE = new ResourceLocation(TargetMod.MODID, "textures/screens/knife.png");
|
||||
private static final ResourceLocation EXPLOSION = new ResourceLocation(TargetMod.MODID, "textures/screens/explosion.png");
|
||||
private static final ResourceLocation CLAYMORE = new ResourceLocation(TargetMod.MODID, "textures/screens/claymore.png");
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.NORMAL)
|
||||
public static void eventHandler(RenderGuiEvent.Pre event) {
|
||||
Player player = Minecraft.getInstance().player;
|
||||
|
@ -44,10 +49,7 @@ public class KillMessageOverlay {
|
|||
|
||||
Font font = Minecraft.getInstance().font;
|
||||
|
||||
String attackerName = record.attacker.getDisplayName().getString();
|
||||
String targetName = record.target.getDisplayName().getString();
|
||||
|
||||
int attackerNameWidth = font.width(attackerName);
|
||||
int targetNameWidth = font.width(targetName);
|
||||
|
||||
// 击杀提示是右对齐的,这里从右向左渲染
|
||||
|
@ -76,12 +78,27 @@ public class KillMessageOverlay {
|
|||
);
|
||||
}
|
||||
|
||||
// 如果是爆炸伤害,则渲染爆炸图标
|
||||
boolean explosion = false;
|
||||
if (record.damageType == DamageTypes.EXPLOSION || record.damageType == DamageTypes.PLAYER_EXPLOSION) {
|
||||
explosion = true;
|
||||
int explosionW = w - targetNameWidth - 26;
|
||||
event.getGuiGraphics().blit(EXPLOSION,
|
||||
explosionW,
|
||||
h - 2,
|
||||
0,
|
||||
0,
|
||||
12,
|
||||
12,
|
||||
12,
|
||||
12
|
||||
);
|
||||
}
|
||||
|
||||
// 如果是枪械击杀,则渲染枪械图标
|
||||
if (record.stack.getItem() instanceof GunItem gunItem) {
|
||||
ResourceLocation resourceLocation = gunItem.getGunIcon();
|
||||
|
||||
int gunIconW = record.headshot ? w - targetNameWidth - 64 : w - targetNameWidth - 46;
|
||||
|
||||
int gunIconW = (record.headshot || explosion) ? w - targetNameWidth - 64 : w - targetNameWidth - 46;
|
||||
event.getGuiGraphics().blit(resourceLocation,
|
||||
gunIconW,
|
||||
h,
|
||||
|
@ -95,7 +112,9 @@ public class KillMessageOverlay {
|
|||
}
|
||||
|
||||
// 渲染击杀者名称
|
||||
int nameW = record.headshot ? w - targetNameWidth - 68 - attackerNameWidth : w - targetNameWidth - 50 - attackerNameWidth;
|
||||
String attackerName = record.attacker.getDisplayName().getString();
|
||||
int attackerNameWidth = font.width(attackerName);
|
||||
int nameW = (record.headshot || explosion) ? w - targetNameWidth - 68 - attackerNameWidth : w - targetNameWidth - 50 - attackerNameWidth;
|
||||
|
||||
event.getGuiGraphics().drawString(
|
||||
Minecraft.getInstance().font,
|
||||
|
|
|
@ -24,6 +24,7 @@ import net.minecraft.world.entity.Entity;
|
|||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.entity.projectile.Projectile;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraftforge.event.entity.living.LivingAttackEvent;
|
||||
|
@ -220,11 +221,19 @@ public class LivingEntityEventHandler {
|
|||
|
||||
ResourceKey<DamageType> damageTypeResourceKey = source.typeHolder().unwrapKey().isPresent() ? source.typeHolder().unwrapKey().get() : DamageTypes.GENERIC;
|
||||
|
||||
ServerPlayer attacker = null;
|
||||
if (source.getDirectEntity() instanceof ServerPlayer player) {
|
||||
attacker = player;
|
||||
}
|
||||
if (source.getDirectEntity() instanceof Projectile projectile && projectile.getOwner() instanceof ServerPlayer player) {
|
||||
attacker = player;
|
||||
}
|
||||
|
||||
if (attacker != null) {
|
||||
if (source.is(TargetModDamageTypes.GUN_FIRE_HEADSHOT) || source.is(TargetModDamageTypes.ARROW_IN_BRAIN)) {
|
||||
TargetMod.PACKET_HANDLER.send(PacketDistributor.ALL.noArg(), new PlayerGunKillMessage(player.getId(), entity.getId(), true, damageTypeResourceKey));
|
||||
TargetMod.PACKET_HANDLER.send(PacketDistributor.ALL.noArg(), new PlayerGunKillMessage(attacker.getId(), entity.getId(), true, damageTypeResourceKey));
|
||||
} else {
|
||||
TargetMod.PACKET_HANDLER.send(PacketDistributor.ALL.noArg(), new PlayerGunKillMessage(player.getId(), entity.getId(), false, damageTypeResourceKey));
|
||||
TargetMod.PACKET_HANDLER.send(PacketDistributor.ALL.noArg(), new PlayerGunKillMessage(attacker.getId(), entity.getId(), false, damageTypeResourceKey));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
BIN
src/main/resources/assets/target/textures/screens/claymore.png
Normal file
BIN
src/main/resources/assets/target/textures/screens/claymore.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 199 B |
BIN
src/main/resources/assets/target/textures/screens/explosion.png
Normal file
BIN
src/main/resources/assets/target/textures/screens/explosion.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 363 B |
BIN
src/main/resources/assets/target/textures/screens/knife.png
Normal file
BIN
src/main/resources/assets/target/textures/screens/knife.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 548 B |
Loading…
Add table
Reference in a new issue