修改武器损坏方法

This commit is contained in:
17146 2024-05-09 23:03:54 +08:00
parent 00c16b0b23
commit 01d286abca

View file

@ -4,7 +4,7 @@ import net.mcreator.target.init.TargetModItems;
import net.minecraft.commands.CommandSource; import net.minecraft.commands.CommandSource;
import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.CommandSourceStack;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.RandomSource; import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
@ -19,10 +19,9 @@ public class AbkrfireProcedure {
for (int index0 = 0; index0 < 8; index0++) { for (int index0 = 0; index0 < 8; index0++) {
BulletFireNormalProcedure.execute(entity); BulletFireNormalProcedure.execute(entity);
} }
if (!player.isCreative() && usehand.hurt(1, RandomSource.create(), null)) {
usehand.shrink(1); usehand.hurtAndBreak(1, player, p -> p.broadcastBreakEvent(InteractionHand.MAIN_HAND));
usehand.setDamageValue(0);
}
if (!entity.level().isClientSide() && entity.getServer() != null) { if (!entity.level().isClientSide() && entity.getServer() != null) {
entity.getServer().getCommands().performPrefixedCommand( entity.getServer().getCommands().performPrefixedCommand(
new CommandSourceStack(CommandSource.NULL, entity.position(), entity.getRotationVector(), entity.level() instanceof ServerLevel ? (ServerLevel) entity.level() : null, 4, entity.getName().getString(), entity.getDisplayName(), new CommandSourceStack(CommandSource.NULL, entity.position(), entity.getRotationVector(), entity.level() instanceof ServerLevel ? (ServerLevel) entity.level() : null, 4, entity.getName().getString(), entity.getDisplayName(),