使用撬棍标签代替撬棍物品判断

This commit is contained in:
Light_Quanta 2025-07-10 15:46:53 +08:00
parent 07950ecf6f
commit 1056bfc97b
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
14 changed files with 31 additions and 24 deletions

View file

@ -2,8 +2,8 @@ package com.atsuishio.superbwarfare.block;
import com.atsuishio.superbwarfare.block.entity.ContainerBlockEntity;
import com.atsuishio.superbwarfare.init.ModBlockEntities;
import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.init.ModTags;
import com.mojang.serialization.MapCodec;
import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos;
@ -64,7 +64,7 @@ public class ContainerBlock extends BaseEntityBlock {
|| !(level.getBlockEntity(pos) instanceof ContainerBlockEntity containerBlockEntity)
) return ItemInteractionResult.FAIL;
if (!stack.is(ModItems.CROWBAR.get())) {
if (!stack.is(ModTags.Items.CROWBAR)) {
player.displayClientMessage(Component.translatable("des.superbwarfare.container.fail.crowbar"), true);
return ItemInteractionResult.FAIL;
}

View file

@ -3,8 +3,8 @@ package com.atsuishio.superbwarfare.block;
import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.block.entity.SmallContainerBlockEntity;
import com.atsuishio.superbwarfare.init.ModBlockEntities;
import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.init.ModTags;
import com.mojang.serialization.MapCodec;
import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos;
@ -62,7 +62,7 @@ public class SmallContainerBlock extends BaseEntityBlock {
}
ItemStack stack = player.getItemInHand(player.getUsedItemHand());
if (!stack.is(ModItems.CROWBAR.get())) {
if (!stack.is(ModTags.Items.CROWBAR)) {
player.displayClientMessage(Component.translatable("des.superbwarfare.container.fail.crowbar"), true);
return InteractionResult.PASS;
}

View file

@ -2,7 +2,6 @@ package com.atsuishio.superbwarfare.block;
import com.atsuishio.superbwarfare.block.entity.SuperbItemInterfaceBlockEntity;
import com.atsuishio.superbwarfare.init.ModBlockEntities;
import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModTags;
import com.mojang.serialization.MapCodec;
import net.minecraft.ChatFormatting;
@ -82,7 +81,7 @@ public class SuperbItemInterfaceBlock extends BaseEntityBlock {
@Override
@ParametersAreNonnullByDefault
protected @NotNull ItemInteractionResult useItemOn(ItemStack stack, BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hitResult) {
if (stack.is(ModItems.CROWBAR.get()) || stack.is(ModTags.Items.WRENCHES_TAG) || stack.is(ModTags.Items.WRENCH_TAG)) {
if (stack.is(ModTags.Items.CROWBAR) || stack.is(ModTags.Items.WRENCHES) || stack.is(ModTags.Items.WRENCH)) {
var facing = hitResult.getDirection();
if (state.getValue(FACING) == facing) {
facing = facing.getOpposite();

View file

@ -75,6 +75,8 @@ public class ModItemTagProvider extends ItemTagsProvider {
this.tag(cTag("plates")).addTags(cTag("plates/copper"));
this.tag(cTag("plates/copper")).add(ModItems.COPPER_PLATE.get());
this.tag(cTag("tools/crowbar")).add(ModItems.CROWBAR.get());
// TODO 清理枪械Tag
ModItems.GUNS.getEntries().forEach(registryObject -> this.tag(ModTags.Items.GUN).add(registryObject.get()));
@ -86,7 +88,7 @@ public class ModItemTagProvider extends ItemTagsProvider {
this.tag(ModTags.Items.SNIPER_RIFLE).add(ModItems.HUNTING_RIFLE.get(), ModItems.SENTINEL.get(),
ModItems.SVD.get(), ModItems.M_98B.get(), ModItems.K_98.get(), ModItems.MOSIN_NAGANT.get());
this.tag(ModTags.Items.HEAVY_WEAPON).add(ModItems.NTW_20.get(),ModItems.M_2_HB.get());
this.tag(ModTags.Items.HEAVY_WEAPON).add(ModItems.NTW_20.get(), ModItems.M_2_HB.get());
this.tag(ModTags.Items.SHOTGUN).add(ModItems.HOMEMADE_SHOTGUN.get(), ModItems.M_870.get(), ModItems.AA_12.get());

View file

@ -4,6 +4,7 @@ import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.capability.energy.SyncedEntityEnergyStorage;
import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.init.ModTags;
import com.atsuishio.superbwarfare.tools.FormatTool;
import com.atsuishio.superbwarfare.tools.SoundTool;
import net.minecraft.commands.arguments.EntityAnchorArgument;
@ -35,8 +36,8 @@ import net.neoforged.neoforge.event.entity.living.LivingDeathEvent;
import org.jetbrains.annotations.NotNull;
import software.bernie.geckolib.animatable.GeoEntity;
import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache;
import software.bernie.geckolib.animation.AnimationState;
import software.bernie.geckolib.animation.*;
import software.bernie.geckolib.animation.AnimationState;
import software.bernie.geckolib.util.GeckoLibUtil;
@EventBusSubscriber(modid = Mod.MODID)
@ -161,7 +162,7 @@ public class DPSGeneratorEntity extends LivingEntity implements GeoEntity {
@Override
public @NotNull InteractionResult interact(Player player, @NotNull InteractionHand hand) {
if (player.getMainHandItem() != ItemStack.EMPTY && player.getMainHandItem().getItem() != ModItems.CROWBAR.get()) {
if (player.getMainHandItem() != ItemStack.EMPTY && player.getMainHandItem().is(ModTags.Items.CROWBAR)) {
return InteractionResult.PASS;
}

View file

@ -4,6 +4,7 @@ import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier;
import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.init.ModTags;
import com.atsuishio.superbwarfare.tools.FormatTool;
import com.atsuishio.superbwarfare.tools.SoundTool;
import net.minecraft.commands.arguments.EntityAnchorArgument;
@ -31,8 +32,8 @@ import net.neoforged.neoforge.event.entity.living.LivingDeathEvent;
import org.jetbrains.annotations.NotNull;
import software.bernie.geckolib.animatable.GeoEntity;
import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache;
import software.bernie.geckolib.animation.AnimationState;
import software.bernie.geckolib.animation.*;
import software.bernie.geckolib.animation.AnimationState;
import software.bernie.geckolib.util.GeckoLibUtil;
@EventBusSubscriber(modid = Mod.MODID)
@ -137,7 +138,7 @@ public class TargetEntity extends LivingEntity implements GeoEntity {
@Override
public @NotNull InteractionResult interact(Player player, @NotNull InteractionHand hand) {
if (player.getMainHandItem() != ItemStack.EMPTY && player.getMainHandItem().getItem() != ModItems.CROWBAR.get()) {
if (player.getMainHandItem() != ItemStack.EMPTY && !player.getMainHandItem().is(ModTags.Items.CROWBAR)) {
return InteractionResult.PASS;
}

View file

@ -15,6 +15,7 @@ import com.atsuishio.superbwarfare.event.ClientMouseHandler;
import com.atsuishio.superbwarfare.init.ModDamageTypes;
import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.init.ModTags;
import com.atsuishio.superbwarfare.network.message.receive.ShakeClientMessage;
import com.atsuishio.superbwarfare.tools.*;
import net.minecraft.ChatFormatting;
@ -50,8 +51,8 @@ import net.neoforged.neoforge.capabilities.Capabilities;
import net.neoforged.neoforge.event.EventHooks;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.joml.Math;
import org.joml.*;
import org.joml.Math;
import software.bernie.geckolib.animatable.GeoEntity;
import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache;
import software.bernie.geckolib.animation.*;
@ -143,7 +144,7 @@ public class AnnihilatorEntity extends EnergyVehicleEntity implements GeoEntity,
return InteractionResult.SUCCESS;
}
if (stack.is(ModItems.CROWBAR.get()) && !player.isCrouching()) {
if (stack.is(ModTags.Items.CROWBAR) && !player.isCrouching()) {
if (this.entityData.get(COOL_DOWN) == 0) {
vehicleShoot(player, 0);
entityData.set(SHOOTER_UUID, player.getStringUUID());

View file

@ -340,7 +340,7 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
}
}
} else if (player.isCrouching()) {
if (stack.is(ModItems.CROWBAR.get())) {
if (stack.is(ModTags.Items.CROWBAR)) {
// 无人机拆除
ItemHandlerHelper.giveItemToPlayer(player, new ItemStack(ModItems.DRONE.get()));

View file

@ -11,6 +11,7 @@ import com.atsuishio.superbwarfare.entity.vehicle.weapon.VehicleWeapon;
import com.atsuishio.superbwarfare.event.ClientMouseHandler;
import com.atsuishio.superbwarfare.init.ModDamageTypes;
import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModTags;
import com.atsuishio.superbwarfare.item.ContainerBlockItem;
import com.atsuishio.superbwarfare.tools.*;
import com.mojang.math.Axis;
@ -155,7 +156,7 @@ public class Hpj11Entity extends ContainerMobileVehicleEntity implements GeoEnti
public @NotNull InteractionResult interact(Player player, @NotNull InteractionHand hand) {
ItemStack stack = player.getMainHandItem();
if (player.isCrouching()) {
if (stack.is(ModItems.CROWBAR.get()) && (getOwner() == null || player == getOwner())) {
if (stack.is(ModTags.Items.CROWBAR) && (getOwner() == null || player == getOwner())) {
ItemStack container = ContainerBlockItem.createInstance(this);
if (!player.addItem(container)) {
player.drop(container, false);

View file

@ -7,8 +7,8 @@ import com.atsuishio.superbwarfare.entity.vehicle.base.AutoAimable;
import com.atsuishio.superbwarfare.entity.vehicle.base.EnergyVehicleEntity;
import com.atsuishio.superbwarfare.init.ModDamageTypes;
import com.atsuishio.superbwarfare.init.ModEntities;
import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.init.ModTags;
import com.atsuishio.superbwarfare.item.ContainerBlockItem;
import com.atsuishio.superbwarfare.tools.CustomExplosion;
import com.atsuishio.superbwarfare.tools.EntityFindUtil;
@ -41,8 +41,8 @@ import org.jetbrains.annotations.Nullable;
import org.joml.Math;
import software.bernie.geckolib.animatable.GeoEntity;
import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache;
import software.bernie.geckolib.animation.AnimationState;
import software.bernie.geckolib.animation.*;
import software.bernie.geckolib.animation.AnimationState;
import software.bernie.geckolib.util.GeckoLibUtil;
import java.util.Optional;
@ -135,7 +135,7 @@ public class LaserTowerEntity extends EnergyVehicleEntity implements GeoEntity,
public @NotNull InteractionResult interact(Player player, @NotNull InteractionHand hand) {
ItemStack stack = player.getMainHandItem();
if (player.isCrouching()) {
if (stack.is(ModItems.CROWBAR.get()) && (getOwner() == null || player == getOwner())) {
if (stack.is(ModTags.Items.CROWBAR) && (getOwner() == null || player == getOwner())) {
ItemStack container = ContainerBlockItem.createInstance(this);
if (!player.addItem(container)) {
player.drop(container, false);

View file

@ -6,6 +6,7 @@ import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
import com.atsuishio.superbwarfare.init.ModEntities;
import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.init.ModTags;
import com.atsuishio.superbwarfare.item.ArtilleryIndicator;
import com.atsuishio.superbwarfare.item.Monitor;
import com.atsuishio.superbwarfare.item.common.ammo.MortarShell;
@ -181,7 +182,7 @@ public class MortarEntity extends VehicleEntity implements GeoEntity, Container
}
if (player.isShiftKeyDown()) {
if (mainHandItem.getItem() == ModItems.CROWBAR.get()) {
if (mainHandItem.is(ModTags.Items.CROWBAR)) {
this.discard();
ItemHandlerHelper.giveItemToPlayer(player, new ItemStack(ModItems.MORTAR_DEPLOYER.get()));
if (entityData.get(INTELLIGENT)) {

View file

@ -1,6 +1,6 @@
package com.atsuishio.superbwarfare.entity.vehicle.base;
import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModTags;
import com.atsuishio.superbwarfare.menu.VehicleMenu;
import com.atsuishio.superbwarfare.tools.InventoryTool;
import net.minecraft.core.NonNullList;
@ -54,7 +54,7 @@ public abstract class ContainerMobileVehicleEntity extends MobileVehicleEntity i
if (player.getVehicle() == this) return InteractionResult.PASS;
ItemStack stack = player.getMainHandItem();
if (player.isShiftKeyDown() && !stack.is(ModItems.CROWBAR.get())) {
if (player.isShiftKeyDown() && !stack.is(ModTags.Items.CROWBAR)) {
player.openMenu(this);
return !player.level().isClientSide ? InteractionResult.CONSUME : InteractionResult.SUCCESS;
}

View file

@ -416,7 +416,7 @@ public abstract class VehicleEntity extends Entity {
var data = data();
ItemStack stack = player.getMainHandItem();
if (player.isShiftKeyDown() && stack.is(ModItems.CROWBAR.get()) && this.getPassengers().isEmpty()) {
if (player.isShiftKeyDown() && stack.is(ModTags.Items.CROWBAR) && this.getPassengers().isEmpty()) {
ItemStack container = ContainerBlockItem.createInstance(this);
if (!player.addItem(container)) {
player.drop(container, false);

View file

@ -43,8 +43,9 @@ public class ModTags {
public static final TagKey<Item> LEGENDARY_BLUEPRINT = tag("blueprint/legendary");
public static final TagKey<Item> CANNON_BLUEPRINT = tag("blueprint/cannon");
public static final TagKey<Item> WRENCHES_TAG = ItemTags.create(ResourceLocation.fromNamespaceAndPath("c", "wrenches"));
public static final TagKey<Item> WRENCH_TAG = ItemTags.create(ResourceLocation.fromNamespaceAndPath("c", "tools/wrench"));
public static final TagKey<Item> WRENCHES = ItemTags.create(ResourceLocation.fromNamespaceAndPath("c", "wrenches"));
public static final TagKey<Item> WRENCH = ItemTags.create(ResourceLocation.fromNamespaceAndPath("c", "tools/wrench"));
public static final TagKey<Item> CROWBAR = ItemTags.create(ResourceLocation.fromNamespaceAndPath("c", "tools/crowbar"));
private static TagKey<Item> tag(String name) {
return ItemTags.create(Mod.loc(name));