添加烟雾颜色提示

This commit is contained in:
17146 2025-07-07 20:16:19 +08:00 committed by Light_Quanta
parent cc1f635ad1
commit a1f4d689ec
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
3 changed files with 27 additions and 0 deletions

View file

@ -4,10 +4,14 @@ import com.atsuishio.superbwarfare.entity.projectile.M18SmokeGrenadeEntity;
import com.atsuishio.superbwarfare.init.ModEntities;
import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.tools.NBTTool;
import net.minecraft.ChatFormatting;
import net.minecraft.core.Direction;
import net.minecraft.core.Position;
import net.minecraft.core.dispenser.BlockSource;
import net.minecraft.core.dispenser.ProjectileDispenseBehavior;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.Style;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionHand;
@ -20,6 +24,7 @@ import net.minecraft.world.level.Level;
import org.jetbrains.annotations.NotNull;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.List;
public class M18SmokeGrenade extends Item implements ProjectileItem {
@ -27,6 +32,26 @@ public class M18SmokeGrenade extends Item implements ProjectileItem {
super(new Properties().rarity(Rarity.UNCOMMON));
}
public static final String TAG_COLOR = "Color";
public void setColor(ItemStack stack, int color) {
NBTTool.getTag(stack).putInt(TAG_COLOR, color);
}
public int getColor(ItemStack stack) {
var tag = NBTTool.getTag(stack);
return tag.contains(TAG_COLOR) ? tag.getInt(TAG_COLOR) : 0xFFFFFF;
}
@Override
@ParametersAreNonnullByDefault
public void appendHoverText(ItemStack stack, TooltipContext context, List<Component> tooltipComponents, TooltipFlag tooltipFlag) {
tooltipComponents.add(Component.translatable("des.superbwarfare.m18_smoke_grenade").withStyle(ChatFormatting.GRAY)
.append(Component.empty().withStyle(ChatFormatting.RESET))
.append(Component.literal("#" + Integer.toHexString(this.getColor(stack))).withStyle(Style.EMPTY.withColor(this.getColor(stack))))
);
}
@Override
@ParametersAreNonnullByDefault
public @NotNull InteractionResultHolder<ItemStack> use(Level worldIn, Player playerIn, InteractionHand handIn) {

View file

@ -241,6 +241,7 @@
"item.superbwarfare.hand_grenade": "Hand Grenade",
"item.superbwarfare.rgo_grenade": "RGO Grenade",
"item.superbwarfare.m18_smoke_grenade": "M18 Smoke Grenade",
"des.superbwarfare.m18_smoke_grenade": "Smoke Color: ",
"item.superbwarfare.transcript": "Transcript",
"des.superbwarfare.transcript": "Recent 10 shooting records:",
"des.superbwarfare.transcript.score": "Score: ",

View file

@ -241,6 +241,7 @@
"item.superbwarfare.hand_grenade": "M67手榴弹",
"item.superbwarfare.rgo_grenade": "RGO手榴弹",
"item.superbwarfare.m18_smoke_grenade": "M18烟雾弹",
"des.superbwarfare.m18_smoke_grenade": "烟雾颜色:",
"item.superbwarfare.transcript": "成绩单",
"des.superbwarfare.transcript": "最近10次的射击成绩",
"des.superbwarfare.transcript.score": "环数:",