移除弹药盒procedure
This commit is contained in:
parent
28a8f71508
commit
2dfaf8fe14
4 changed files with 22 additions and 49 deletions
|
@ -1,8 +1,10 @@
|
||||||
package net.mcreator.target.item.common.ammo;
|
package net.mcreator.target.item.common.ammo;
|
||||||
|
|
||||||
import net.mcreator.target.procedures.SniperAmmoBoxWanJiaWanChengShiYongWuPinShiProcedure;
|
import net.mcreator.target.init.TargetModSounds;
|
||||||
|
import net.mcreator.target.network.TargetModVariables;
|
||||||
import net.minecraft.ChatFormatting;
|
import net.minecraft.ChatFormatting;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.sounds.SoundSource;
|
||||||
import net.minecraft.world.InteractionHand;
|
import net.minecraft.world.InteractionHand;
|
||||||
import net.minecraft.world.InteractionResultHolder;
|
import net.minecraft.world.InteractionResultHolder;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
@ -32,9 +34,22 @@ public class SniperAmmoBox extends Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InteractionResultHolder<ItemStack> use(Level world, Player entity, InteractionHand hand) {
|
public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) {
|
||||||
InteractionResultHolder<ItemStack> ar = super.use(world, entity, hand);
|
ItemStack stack = player.getItemInHand(hand);
|
||||||
SniperAmmoBoxWanJiaWanChengShiYongWuPinShiProcedure.execute(entity, ar.getObject());
|
player.getCooldowns().addCooldown(this, 20);
|
||||||
return ar;
|
stack.shrink(1);
|
||||||
|
|
||||||
|
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||||
|
capability.sniperammo = (player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).sniperammo + 12;
|
||||||
|
capability.syncPlayerVariables(player);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!level.isClientSide()) {
|
||||||
|
level.playSound(player, player.getOnPos(), TargetModSounds.BULLETSUPPLY.get(), SoundSource.VOICE, 1f, 1f);
|
||||||
|
|
||||||
|
player.displayClientMessage(Component.translatable("des.target.sniper_ammo_box.use"), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return InteractionResultHolder.consume(stack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,44 +0,0 @@
|
||||||
package net.mcreator.target.procedures;
|
|
||||||
|
|
||||||
import net.mcreator.target.init.TargetModItems;
|
|
||||||
import net.mcreator.target.network.TargetModVariables;
|
|
||||||
import net.minecraft.commands.CommandSource;
|
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
|
||||||
import net.minecraft.network.chat.Component;
|
|
||||||
import net.minecraft.server.level.ServerLevel;
|
|
||||||
import net.minecraft.world.InteractionHand;
|
|
||||||
import net.minecraft.world.entity.Entity;
|
|
||||||
import net.minecraft.world.entity.LivingEntity;
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
|
||||||
|
|
||||||
public class SniperAmmoBoxWanJiaWanChengShiYongWuPinShiProcedure {
|
|
||||||
public static void execute(Entity entity, ItemStack itemstack) {
|
|
||||||
if (entity == null)
|
|
||||||
return;
|
|
||||||
if (entity instanceof Player _player)
|
|
||||||
_player.getCooldowns().addCooldown(itemstack.getItem(), 20);
|
|
||||||
if (entity instanceof LivingEntity _entity)
|
|
||||||
_entity.swing(InteractionHand.MAIN_HAND, true);
|
|
||||||
if (entity instanceof Player _player) {
|
|
||||||
ItemStack _stktoremove = new ItemStack(TargetModItems.SNIPER_AMMO_BOX.get());
|
|
||||||
_player.getInventory().clearOrCountMatchingItems(p -> _stktoremove.getItem() == p.getItem(), 1, _player.inventoryMenu.getCraftSlots());
|
|
||||||
}
|
|
||||||
{
|
|
||||||
double _setval = (entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).sniperammo + 12;
|
|
||||||
entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
|
||||||
capability.sniperammo = _setval;
|
|
||||||
capability.syncPlayerVariables(entity);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (entity instanceof Player _player && !_player.level().isClientSide())
|
|
||||||
_player.displayClientMessage(Component.literal("Sniper Ammo +12"), false);
|
|
||||||
{
|
|
||||||
Entity _ent = entity;
|
|
||||||
if (!_ent.level().isClientSide() && _ent.getServer() != null) {
|
|
||||||
_ent.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, _ent.position(), _ent.getRotationVector(), _ent.level() instanceof ServerLevel ? (ServerLevel) _ent.level() : null, 4,
|
|
||||||
_ent.getName().getString(), _ent.getDisplayName(), _ent.level().getServer(), _ent), "playsound target:bulletsupply voice @a ~ ~ ~ 1 1");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -89,6 +89,7 @@
|
||||||
"item.target.sniper_ammo": "Sniper Ammo *2",
|
"item.target.sniper_ammo": "Sniper Ammo *2",
|
||||||
"item.target.sniper_ammo_box": "Sniper Ammo Box",
|
"item.target.sniper_ammo_box": "Sniper Ammo Box",
|
||||||
"des.target.sniper_ammo_box": "Sniper Ammo *12",
|
"des.target.sniper_ammo_box": "Sniper Ammo *12",
|
||||||
|
"des.target.sniper_ammo_box.use": "Sniper Ammo +12",
|
||||||
"item.target.rifle_ammo": "Rifle Ammo *5",
|
"item.target.rifle_ammo": "Rifle Ammo *5",
|
||||||
"item.target.rifle_ammo_box": "Rifle Ammo Box",
|
"item.target.rifle_ammo_box": "Rifle Ammo Box",
|
||||||
"des.target.rifle_ammo_box": "Rifle Ammo *30",
|
"des.target.rifle_ammo_box": "Rifle Ammo *30",
|
||||||
|
|
|
@ -89,6 +89,7 @@
|
||||||
"item.target.sniper_ammo": "狙击枪弹药 *2",
|
"item.target.sniper_ammo": "狙击枪弹药 *2",
|
||||||
"item.target.sniper_ammo_box": "狙击枪弹药盒",
|
"item.target.sniper_ammo_box": "狙击枪弹药盒",
|
||||||
"des.target.sniper_ammo_box": "狙击枪弹药 *12",
|
"des.target.sniper_ammo_box": "狙击枪弹药 *12",
|
||||||
|
"des.target.sniper_ammo_box.use": "狙击枪弹药 +12",
|
||||||
"item.target.rifle_ammo": "步枪弹药 *5",
|
"item.target.rifle_ammo": "步枪弹药 *5",
|
||||||
"item.target.rifle_ammo_box": "步枪弹药盒",
|
"item.target.rifle_ammo_box": "步枪弹药盒",
|
||||||
"des.target.rifle_ammo_box": "步枪弹药 *30",
|
"des.target.rifle_ammo_box": "步枪弹药 *30",
|
||||||
|
|
Loading…
Add table
Reference in a new issue