优化RPG相关代码

This commit is contained in:
Light_Quanta 2024-05-11 14:45:16 +08:00
parent b7d6209fd1
commit dccce360fc
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
13 changed files with 239 additions and 357 deletions

View file

@ -4,9 +4,7 @@ import net.mcreator.target.headshot.BoundingBoxManager;
import net.mcreator.target.headshot.IHeadshotBox; import net.mcreator.target.headshot.IHeadshotBox;
import net.mcreator.target.init.TargetModEntities; import net.mcreator.target.init.TargetModEntities;
import net.mcreator.target.network.TargetModVariables; import net.mcreator.target.network.TargetModVariables;
import net.mcreator.target.procedures.RocketHitProcedure; import net.mcreator.target.procedures.MedexpProcedure;
import net.mcreator.target.procedures.RpgRocketDanSheWuFeiXingShiMeiKeFaShengProcedure;
import net.mcreator.target.procedures.RpgRocketDanSheWuJiZhongFangKuaiShiProcedure;
import net.minecraft.commands.CommandSource; import net.minecraft.commands.CommandSource;
import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.CommandSourceStack;
import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.Packet;
@ -74,14 +72,23 @@ public class RpgRocketEntity extends AbstractArrow implements ItemSupplier {
entity.setArrowCount(entity.getArrowCount() - 1); entity.setArrowCount(entity.getArrowCount() - 1);
} }
public static RpgRocketEntity shoot(Level world, LivingEntity entity, RandomSource random, float power, double damage, int knockback) {
RpgRocketEntity entityArrow = new RpgRocketEntity(TargetModEntities.RPG_ROCKET.get(), entity, world);
entityArrow.shoot(entity.getViewVector(1).x, entity.getViewVector(1).y, entity.getViewVector(1).z, power * 2, 0);
entityArrow.setSilent(true);
entityArrow.setCritArrow(false);
entityArrow.setBaseDamage(damage);
entityArrow.setKnockback(knockback);
world.addFreshEntity(entityArrow);
return entityArrow;
}
@Override @Override
protected void onHitEntity(EntityHitResult result) { protected void onHitEntity(EntityHitResult result) {
final Vec3 position = this.position();
Entity entity = result.getEntity(); Entity entity = result.getEntity();
if (this.getOwner() instanceof LivingEntity living) { if (this.getOwner() instanceof LivingEntity living) {
double _setval = 25;
living.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> { living.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.hitind = _setval; capability.hitind = 25;
capability.syncPlayerVariables(living); capability.syncPlayerVariables(living);
}); });
if (!living.level().isClientSide() && living.getServer() != null) { if (!living.level().isClientSide() && living.getServer() != null) {
@ -89,7 +96,15 @@ public class RpgRocketEntity extends AbstractArrow implements ItemSupplier {
living.getName().getString(), living.getDisplayName(), living.level().getServer(), living), "playsound target:indication voice @a ~ ~ ~ 1 1"); living.getName().getString(), living.getDisplayName(), living.level().getServer(), living), "playsound target:indication voice @a ~ ~ ~ 1 1");
} }
} }
RocketHitProcedure.execute(this.level(), this); if (this.getPersistentData().getDouble("time") > 0) {
if (this.level() instanceof ServerLevel level) {
level.explode(this, this.getX(), this.getY(), this.getZ(), 4, Level.ExplosionInteraction.NONE);
MedexpProcedure.execute(level, this.getX(), this.getY(), this.getZ());
this.discard();
}
}
if (entity instanceof LivingEntity) { if (entity instanceof LivingEntity) {
entity.invulnerableTime = 0; entity.invulnerableTime = 0;
} }
@ -134,22 +149,21 @@ public class RpgRocketEntity extends AbstractArrow implements ItemSupplier {
this.discard(); this.discard();
} }
@Override
public void onHitBlock(BlockHitResult blockHitResult) {
super.onHitBlock(blockHitResult);
RpgRocketDanSheWuJiZhongFangKuaiShiProcedure.execute(this.level(), this);
}
@Override @Override
public boolean isNoGravity() { public boolean isNoGravity() {
return true; return true;
} }
@Override @Override
public void tick() { public void onHitBlock(BlockHitResult blockHitResult) {
super.tick(); super.onHitBlock(blockHitResult);
RpgRocketDanSheWuFeiXingShiMeiKeFaShengProcedure.execute(this);
if (this.tickCount > 100) { if (this.getPersistentData().getDouble("time") > 0) {
if (this.level() instanceof ServerLevel level) {
level.explode(this, this.getX(), this.getY(), this.getZ(), 6, Level.ExplosionInteraction.NONE);
MedexpProcedure.execute(level, this.getX(), this.getY(), this.getZ());
}
if (!this.level().isClientSide())
this.discard(); this.discard();
} }
} }
@ -158,15 +172,39 @@ public class RpgRocketEntity extends AbstractArrow implements ItemSupplier {
return shoot(world, entity, source, 1f, 5, 5); return shoot(world, entity, source, 1f, 5, 5);
} }
public static RpgRocketEntity shoot(Level world, LivingEntity entity, RandomSource random, float power, double damage, int knockback) { @Override
RpgRocketEntity entityarrow = new RpgRocketEntity(TargetModEntities.RPG_ROCKET.get(), entity, world); public void tick() {
entityarrow.shoot(entity.getViewVector(1).x, entity.getViewVector(1).y, entity.getViewVector(1).z, power * 2, 0); super.tick();
entityarrow.setSilent(true);
entityarrow.setCritArrow(false); this.getPersistentData().putDouble("time", (1 + this.getPersistentData().getDouble("time")));
entityarrow.setBaseDamage(damage); double life = this.getPersistentData().getDouble("time");
entityarrow.setKnockback(knockback); if (life == 4) {
world.addFreshEntity(entityarrow); if (!this.level().isClientSide() && this.getServer() != null) {
return entityarrow; this.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, this.position(), this.getRotationVector(), this.level() instanceof ServerLevel ? (ServerLevel) this.level() : null, 4,
this.getName().getString(), this.getDisplayName(), this.level().getServer(), this), "particle minecraft:campfire_cosy_smoke ~ ~ ~ 0.8 0.8 0.8 0.01 50 force");
}
}
if (life >= 4) {
this.setDeltaMovement(new Vec3((1.04 * this.getDeltaMovement().x()), (1.04 * this.getDeltaMovement().y() - 0.02), (1.04 * this.getDeltaMovement().z())));
if (!this.level().isClientSide() && this.getServer() != null) {
this.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, this.position(), this.getRotationVector(), this.level() instanceof ServerLevel ? (ServerLevel) this.level() : null, 4,
this.getName().getString(), this.getDisplayName(), this.level().getServer(), this), "particle minecraft:smoke ~ ~ ~ 0 0 0 0 2 force");
this.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, this.position(), this.getRotationVector(), this.level() instanceof ServerLevel ? (ServerLevel) this.level() : null, 4,
this.getName().getString(), this.getDisplayName(), this.level().getServer(), this), "particle minecraft:campfire_cosy_smoke ~ ~ ~ 0 0 0 0 2 force");
}
}
if (life >= 90) {
if (!this.level().isClientSide() && this.getServer() != null) {
MedexpProcedure.execute(this.level(), this.getX(), this.getY(), this.getZ());
}
if (!this.level().isClientSide())
this.discard();
}
if (this.tickCount > 100) {
this.discard();
}
} }
public static RpgRocketEntity shoot(LivingEntity entity, LivingEntity target) { public static RpgRocketEntity shoot(LivingEntity entity, LivingEntity target) {

View file

@ -3,15 +3,18 @@ package net.mcreator.target.item.common.ammo;
import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import net.mcreator.target.client.renderer.item.RocketItemRenderer; import net.mcreator.target.client.renderer.item.RocketItemRenderer;
import net.mcreator.target.init.TargetModItems;
import net.mcreator.target.item.AnimatedItem; import net.mcreator.target.item.AnimatedItem;
import net.mcreator.target.procedures.RocketShiTiBeiGongJuJiZhongShiProcedure; import net.mcreator.target.procedures.MedexpProcedure;
import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer; import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.attributes.Attribute; import net.minecraft.world.entity.ai.attributes.Attribute;
import net.minecraft.world.entity.ai.attributes.AttributeModifier; import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.*; import net.minecraft.world.item.*;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraftforge.client.extensions.common.IClientItemExtensions; import net.minecraftforge.client.extensions.common.IClientItemExtensions;
@ -111,7 +114,19 @@ public class Rocket extends Item implements GeoItem, AnimatedItem {
@Override @Override
public boolean hurtEnemy(ItemStack itemstack, LivingEntity entity, LivingEntity sourceentity) { public boolean hurtEnemy(ItemStack itemstack, LivingEntity entity, LivingEntity sourceentity) {
boolean retval = super.hurtEnemy(itemstack, entity, sourceentity); boolean retval = super.hurtEnemy(itemstack, entity, sourceentity);
RocketShiTiBeiGongJuJiZhongShiProcedure.execute(entity.level(), sourceentity);
if (Math.random() >= 0.25) return retval;
if (entity.level() instanceof ServerLevel level) {
level.explode(sourceentity, sourceentity.getX(), sourceentity.getY() + 1, sourceentity.getZ(), 6, Level.ExplosionInteraction.NONE);
level.explode(null, sourceentity.getX(), sourceentity.getY() + 1, sourceentity.getZ(), 6, Level.ExplosionInteraction.NONE);
MedexpProcedure.execute(level, sourceentity.getX(), sourceentity.getY(), sourceentity.getZ());
}
if (sourceentity instanceof Player player) {
player.getInventory().clearOrCountMatchingItems(p -> TargetModItems.ROCKET.get() == p.getItem(), 1, player.inventoryMenu.getCraftSlots());
}
return retval; return retval;
} }

View file

@ -1,52 +1,39 @@
package net.mcreator.target.procedures; package net.mcreator.target.procedures;
import net.mcreator.target.init.TargetModSounds;
import net.minecraft.commands.CommandSource; import net.minecraft.commands.CommandSource;
import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.CommandSourceStack;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundSource; import net.minecraft.sounds.SoundSource;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.phys.Vec2; import net.minecraft.world.phys.Vec2;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
import net.minecraftforge.registries.ForgeRegistries;
public class MedexpProcedure { public class MedexpProcedure {
public static void execute(LevelAccessor world, double x, double y, double z) { public static void execute(LevelAccessor world, double x, double y, double z) {
if (world instanceof Level _level) { if (world instanceof Level level) {
if (!_level.isClientSide()) { if (!level.isClientSide()) {
_level.playSound(null, BlockPos.containing(x, y + 1, z), ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("target:exp")), SoundSource.BLOCKS, 12, 1); level.playSound(null, BlockPos.containing(x, y + 1, z), TargetModSounds.EXP.get(), SoundSource.BLOCKS, 12, 1);
level.playSound(null, BlockPos.containing(x, y + 1, z), TargetModSounds.EXPFAR.get(), SoundSource.BLOCKS, 28, 1);
level.playSound(null, BlockPos.containing(x, y + 1, z), TargetModSounds.EXPVERYFAR.get(), SoundSource.BLOCKS, 48, 1);
} else { } else {
_level.playLocalSound(x, (y + 1), z, ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("target:exp")), SoundSource.BLOCKS, 12, 1, false); level.playLocalSound(x, (y + 1), z, TargetModSounds.EXP.get(), SoundSource.BLOCKS, 12, 1, false);
level.playLocalSound(x, (y + 1), z, TargetModSounds.EXPFAR.get(), SoundSource.BLOCKS, 28, 1, false);
level.playLocalSound(x, (y + 1), z, TargetModSounds.EXPVERYFAR.get(), SoundSource.BLOCKS, 48, 1, false);
} }
} }
if (world instanceof Level _level) { if (world instanceof ServerLevel level) {
if (!_level.isClientSide()) { level.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, new Vec3(x, (y + 1), z), Vec2.ZERO, level, 4, "", Component.literal(""), level.getServer(), null).withSuppressedOutput(),
_level.playSound(null, BlockPos.containing(x, y + 1, z), ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("target:expfar")), SoundSource.BLOCKS, 28, 1);
} else {
_level.playLocalSound(x, (y + 1), z, ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("target:expfar")), SoundSource.BLOCKS, 28, 1, false);
}
}
if (world instanceof Level _level) {
if (!_level.isClientSide()) {
_level.playSound(null, BlockPos.containing(x, y + 1, z), ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("target:expveryfar")), SoundSource.BLOCKS, 48, 1);
} else {
_level.playLocalSound(x, (y + 1), z, ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("target:expveryfar")), SoundSource.BLOCKS, 48, 1, false);
}
}
if (world instanceof ServerLevel _level)
_level.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, new Vec3(x, (y + 1), z), Vec2.ZERO, _level, 4, "", Component.literal(""), _level.getServer(), null).withSuppressedOutput(),
"particle minecraft:campfire_cosy_smoke ~ ~ ~ 0.4 1 0.4 0.02 80 force"); "particle minecraft:campfire_cosy_smoke ~ ~ ~ 0.4 1 0.4 0.02 80 force");
if (world instanceof ServerLevel _level) level.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, new Vec3(x, (y + 1), z), Vec2.ZERO, level, 4, "", Component.literal(""), level.getServer(), null).withSuppressedOutput(),
_level.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, new Vec3(x, (y + 1), z), Vec2.ZERO, _level, 4, "", Component.literal(""), _level.getServer(), null).withSuppressedOutput(),
"particle minecraft:large_smoke ~ ~1 ~ 0.4 1 0.4 0.02 100 force"); "particle minecraft:large_smoke ~ ~1 ~ 0.4 1 0.4 0.02 100 force");
if (world instanceof ServerLevel _level) level.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, new Vec3(x, (y + 1), z), Vec2.ZERO, level, 4, "", Component.literal(""), level.getServer(), null).withSuppressedOutput(),
_level.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, new Vec3(x, (y + 1), z), Vec2.ZERO, _level, 4, "", Component.literal(""), _level.getServer(), null).withSuppressedOutput(),
"particle minecraft:campfire_cosy_smoke ~ ~ ~ 2 0.001 2 0.01 100 force"); "particle minecraft:campfire_cosy_smoke ~ ~ ~ 2 0.001 2 0.01 100 force");
if (world instanceof ServerLevel _level) level.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, new Vec3(x, (y + 1), z), Vec2.ZERO, level, 4, "", Component.literal(""), level.getServer(), null).withSuppressedOutput(),
_level.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, new Vec3(x, (y + 1), z), Vec2.ZERO, _level, 4, "", Component.literal(""), _level.getServer(), null).withSuppressedOutput(),
"particle target:firestar ~ ~ ~ 0 0 0 0.2 100 force"); "particle target:firestar ~ ~ ~ 0 0 0 0.2 100 force");
} }
} }
}

View file

@ -14,7 +14,7 @@ public class PressFireProcedure {
TaserfireProcedure.execute(player); TaserfireProcedure.execute(player);
M79fireProcedure.execute(player); M79fireProcedure.execute(player);
M98bfireProcedure.execute(player); M98bfireProcedure.execute(player);
RpgfireProcedure.execute(player); RpgFireProcedure.execute(player);
KraberfireProcedure.execute(player); KraberfireProcedure.execute(player);
MinigunfireProcedure.execute(player); MinigunfireProcedure.execute(player);
SentinelFireProcedure.execute(player); SentinelFireProcedure.execute(player);

View file

@ -1,29 +0,0 @@
package net.mcreator.target.procedures;
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.entity.Entity;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.phys.Vec2;
import net.minecraft.world.phys.Vec3;
public class RocketHitProcedure {
public static void execute(LevelAccessor world, Entity immediatesourceentity) {
if (immediatesourceentity == null)
return;
if (immediatesourceentity.getPersistentData().getDouble("time") > 0) {
if (world instanceof Level _level && !_level.isClientSide())
_level.explode(immediatesourceentity, (immediatesourceentity.getX()), (immediatesourceentity.getY()), (immediatesourceentity.getZ()), 4, Level.ExplosionInteraction.NONE);
if (world instanceof ServerLevel _level)
_level.getServer().getCommands().performPrefixedCommand(
new CommandSourceStack(CommandSource.NULL, new Vec3((immediatesourceentity.getX()), (immediatesourceentity.getY()), (immediatesourceentity.getZ())), Vec2.ZERO, _level, 4, "", Component.literal(""), _level.getServer(), null)
.withSuppressedOutput(),
"target:mediumexp");
if (!immediatesourceentity.level().isClientSide())
immediatesourceentity.discard();
}
}
}

View file

@ -1,35 +0,0 @@
package net.mcreator.target.procedures;
import net.mcreator.target.init.TargetModItems;
import net.minecraft.commands.CommandSource;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
public class RocketShiTiBeiGongJuJiZhongShiProcedure {
public static void execute(LevelAccessor world, Entity sourceentity) {
if (sourceentity == null)
return;
if (Math.random() < 0.25) {
if (world instanceof Level _level && !_level.isClientSide())
_level.explode(sourceentity, (sourceentity.getX()), (sourceentity.getY() + 1), (sourceentity.getZ()), 6, Level.ExplosionInteraction.NONE);
if (world instanceof Level _level && !_level.isClientSide())
_level.explode(null, (sourceentity.getX()), (sourceentity.getY() + 1), (sourceentity.getZ()), 6, Level.ExplosionInteraction.NONE);
if (sourceentity instanceof Player _player) {
ItemStack _stktoremove = new ItemStack(TargetModItems.ROCKET.get());
_player.getInventory().clearOrCountMatchingItems(p -> _stktoremove.getItem() == p.getItem(), 1, _player.inventoryMenu.getCraftSlots());
}
{
Entity _ent = sourceentity;
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), "target:mediumexp");
}
}
}
}
}

View file

@ -0,0 +1,81 @@
package net.mcreator.target.procedures;
import net.mcreator.target.entity.RpgRocketEntity;
import net.mcreator.target.init.TargetModAttributes;
import net.mcreator.target.init.TargetModEntities;
import net.mcreator.target.init.TargetModItems;
import net.mcreator.target.init.TargetModSounds;
import net.mcreator.target.network.TargetModVariables;
import net.minecraft.commands.CommandSource;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.AbstractArrow;
import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
public class RpgFireProcedure {
public static void execute(Player player) {
if (player.isSpectator()) return;
ItemStack mainHandItem = player.getMainHandItem();
CompoundTag tag = mainHandItem.getOrCreateTag();
if (mainHandItem.getItem() == TargetModItems.RPG.get() && tag.getDouble("reloading") == 0 && !player.getCooldowns().isOnCooldown(mainHandItem.getItem())
&& tag.getDouble("ammo") > 0) {
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.recoilhorizon = Math.random() < 0.5 ? -1 : 1;
capability.recoil = 0.1;
capability.firing = 1;
capability.syncPlayerVariables(player);
});
Level projectileLevel = player.level();
if (!projectileLevel.isClientSide()) {
Projectile projectile = getArrow(player, projectileLevel, tag);
projectile.setPos(player.getX(), player.getEyeY() - 0.1, player.getZ());
projectile.shoot(player.getLookAngle().x, player.getLookAngle().y, player.getLookAngle().z, (float) tag.getDouble("velocity"),
(float) player.getAttribute(TargetModAttributes.SPREAD.get()).getBaseValue());
projectileLevel.addFreshEntity(projectile);
}
if (player.getServer() != null) {
player.getServer().getCommands().performPrefixedCommand(
new CommandSourceStack(CommandSource.NULL, player.position(), player.getRotationVector(), (ServerLevel) player.level(), 4, player.getName().getString(), player.getDisplayName(),
player.level().getServer(), player),
("particle minecraft:cloud" + (" " + (player.getX() + 1.8 * player.getLookAngle().x)) + (" " + (player.getY() + player.getBbHeight() - 0.1 + 1.8 * player.getLookAngle().y))
+ (" " + (player.getZ() + 1.8 * player.getLookAngle().z)) + " 0.4 0.4 0.4 0.005 30 force @s"));
}
if (tag.getDouble("ammo") == 1) {
tag.putDouble("empty", 1);
}
player.getCooldowns().addCooldown(mainHandItem.getItem(), 10);
if (!player.level().isClientSide() && player.getServer() != null) {
player.level().playSound(null, player.blockPosition(), TargetModSounds.RPG_FIRE_1P.get(), SoundSource.PLAYERS, 2, 1);
player.level().playSound(null, player.blockPosition(), TargetModSounds.RPG_FIRE_3P.get(), SoundSource.PLAYERS, 4, 1);
player.level().playSound(null, player.blockPosition(), TargetModSounds.RPG_FAR.get(), SoundSource.PLAYERS, 8, 1);
player.level().playSound(null, player.blockPosition(), TargetModSounds.RPG_VERYFAR.get(), SoundSource.PLAYERS, 16, 1);
}
tag.putDouble("fireanim", 2);
tag.putDouble("ammo", tag.getDouble("ammo") - 1);
}
}
private static Projectile getArrow(Player player, Level projectileLevel, CompoundTag tag) {
return new Object() {
public Projectile getArrow(Level level, Entity shooter, float damage, int knockback) {
AbstractArrow entityToSpawn = new RpgRocketEntity(TargetModEntities.RPG_ROCKET.get(), level);
entityToSpawn.setOwner(shooter);
entityToSpawn.setBaseDamage(damage);
entityToSpawn.setKnockback(knockback);
entityToSpawn.setSilent(true);
return entityToSpawn;
}
}.getArrow(projectileLevel, player, (float) ((tag.getDouble("damage") / tag.getDouble("velocity")) * (1 + 0.05 * tag.getDouble("level"))), 0);
}
}

View file

@ -1,54 +0,0 @@
package net.mcreator.target.procedures;
import net.minecraft.commands.CommandSource;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.phys.Vec3;
public class RpgRocketDanSheWuFeiXingShiMeiKeFaShengProcedure {
public static void execute(Entity immediatesourceentity) {
if (immediatesourceentity == null)
return;
double life = 0;
immediatesourceentity.getPersistentData().putDouble("time", (1 + immediatesourceentity.getPersistentData().getDouble("time")));
life = immediatesourceentity.getPersistentData().getDouble("time");
if (life == 4) {
{
Entity _ent = immediatesourceentity;
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), "particle minecraft:campfire_cosy_smoke ~ ~ ~ 0.8 0.8 0.8 0.01 50 force");
}
}
}
if (life >= 4) {
immediatesourceentity.setDeltaMovement(new Vec3((1.04 * immediatesourceentity.getDeltaMovement().x()), (1.04 * immediatesourceentity.getDeltaMovement().y() - 0.02), (1.04 * immediatesourceentity.getDeltaMovement().z())));
{
Entity _ent = immediatesourceentity;
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), "particle minecraft:smoke ~ ~ ~ 0 0 0 0 2 force");
}
}
{
Entity _ent = immediatesourceentity;
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), "particle minecraft:campfire_cosy_smoke ~ ~ ~ 0 0 0 0 2 force");
}
}
}
if (life >= 90) {
{
Entity _ent = immediatesourceentity;
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), "target:mediumexp");
}
}
if (!immediatesourceentity.level().isClientSide())
immediatesourceentity.discard();
}
}
}

View file

@ -1,29 +0,0 @@
package net.mcreator.target.procedures;
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.entity.Entity;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.phys.Vec2;
import net.minecraft.world.phys.Vec3;
public class RpgRocketDanSheWuJiZhongFangKuaiShiProcedure {
public static void execute(LevelAccessor world, Entity immediatesourceentity) {
if (immediatesourceentity == null)
return;
if (immediatesourceentity.getPersistentData().getDouble("time") > 0) {
if (world instanceof Level _level && !_level.isClientSide())
_level.explode(immediatesourceentity, (immediatesourceentity.getX()), (immediatesourceentity.getY()), (immediatesourceentity.getZ()), 6, Level.ExplosionInteraction.NONE);
if (world instanceof ServerLevel _level)
_level.getServer().getCommands().performPrefixedCommand(
new CommandSourceStack(CommandSource.NULL, new Vec3((immediatesourceentity.getX()), (immediatesourceentity.getY()), (immediatesourceentity.getZ())), Vec2.ZERO, _level, 4, "", Component.literal(""), _level.getServer(), null)
.withSuppressedOutput(),
"target:mediumexp");
if (!immediatesourceentity.level().isClientSide())
immediatesourceentity.discard();
}
}
}

View file

@ -3,6 +3,7 @@ package net.mcreator.target.procedures;
import net.mcreator.target.init.TargetModItems; 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.nbt.CompoundTag;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.LivingEntity;
@ -11,50 +12,43 @@ import net.minecraft.world.item.ItemStack;
public class RpgWuPinZaiBeiBaoZhongShiMeiKeFaShengProcedure { public class RpgWuPinZaiBeiBaoZhongShiMeiKeFaShengProcedure {
public static void execute(Entity entity, ItemStack itemstack) { public static void execute(Entity entity, ItemStack itemstack) {
if (entity == null) if (entity == null) return;
return; CompoundTag tag = itemstack.getOrCreateTag();
double ammo1 = 0; double id = tag.getDouble("id");
double id = 0; if ((entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getOrCreateTag().getDouble("id") != tag.getDouble("id")) {
id = itemstack.getOrCreateTag().getDouble("id"); tag.putDouble("emptyreload", 0);
ammo1 = 1 - itemstack.getOrCreateTag().getDouble("ammo"); tag.putDouble("reloading", 0);
if ((entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getOrCreateTag().getDouble("id") != itemstack.getOrCreateTag().getDouble("id")) { tag.putDouble("reloadtime", 0);
itemstack.getOrCreateTag().putDouble("emptyreload", 0);
itemstack.getOrCreateTag().putDouble("reloading", 0);
itemstack.getOrCreateTag().putDouble("reloadtime", 0);
} }
if (itemstack.getOrCreateTag().getDouble("reloading") == 1) { if (tag.getDouble("reloading") == 1) {
if (itemstack.getOrCreateTag().getDouble("reloadtime") == 91) { if (tag.getDouble("reloadtime") == 91) {
entity.getPersistentData().putDouble("id", id); entity.getPersistentData().putDouble("id", id);
{ if (entity.getServer() != null) {
Entity _ent = entity; entity.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, entity.position(), entity.getRotationVector(), entity.level() instanceof ServerLevel ? (ServerLevel) entity.level() : null, 4,
if (!_ent.level().isClientSide() && _ent.getServer() != null) { entity.getName().getString(), entity.getDisplayName(), entity.level().getServer(), entity), "playsound target:rpg_reload player @s ~ ~ ~ 100 1");
_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:rpg_reload player @s ~ ~ ~ 100 1");
}
} }
} }
if ((entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getItem() == itemstack.getItem() if ((entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getItem() == itemstack.getItem()
&& (entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getOrCreateTag().getDouble("id") == id) { && (entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getOrCreateTag().getDouble("id") == id) {
if (itemstack.getOrCreateTag().getDouble("reloadtime") > 0) { if (tag.getDouble("reloadtime") > 0) {
itemstack.getOrCreateTag().putDouble("reloadtime", (itemstack.getOrCreateTag().getDouble("reloadtime") - 1)); tag.putDouble("reloadtime", (tag.getDouble("reloadtime") - 1));
} }
} else { } else {
itemstack.getOrCreateTag().putDouble("reloading", 0); tag.putDouble("reloading", 0);
itemstack.getOrCreateTag().putDouble("reloadtime", 0); tag.putDouble("reloadtime", 0);
itemstack.getOrCreateTag().putDouble("emptyreload", 0); tag.putDouble("emptyreload", 0);
} }
if (itemstack.getOrCreateTag().getDouble("reloadtime") == 84) { if (tag.getDouble("reloadtime") == 84) {
itemstack.getOrCreateTag().putDouble("empty", 0); tag.putDouble("empty", 0);
} }
if (itemstack.getOrCreateTag().getDouble("reloadtime") == 1 && (entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getOrCreateTag().getDouble("id") == id) { if (tag.getDouble("reloadtime") == 1 && (entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getOrCreateTag().getDouble("id") == id) {
if (itemstack.getOrCreateTag().getDouble("maxammo") >= 0) { if (tag.getDouble("maxammo") >= 0) {
itemstack.getOrCreateTag().putDouble("ammo", 1); tag.putDouble("ammo", 1);
if (entity instanceof Player _player) { if (entity instanceof Player _player) {
ItemStack _stktoremove = new ItemStack(TargetModItems.ROCKET.get()); _player.getInventory().clearOrCountMatchingItems(p -> TargetModItems.ROCKET.get() == p.getItem(), 1, _player.inventoryMenu.getCraftSlots());
_player.getInventory().clearOrCountMatchingItems(p -> _stktoremove.getItem() == p.getItem(), 1, _player.inventoryMenu.getCraftSlots());
} }
itemstack.getOrCreateTag().putDouble("reloading", 0); tag.putDouble("reloading", 0);
itemstack.getOrCreateTag().putDouble("emptyreload", 0); tag.putDouble("emptyreload", 0);
} }
} }
} }

View file

@ -1,77 +0,0 @@
package net.mcreator.target.procedures;
import net.mcreator.target.entity.RpgRocketEntity;
import net.mcreator.target.init.TargetModAttributes;
import net.mcreator.target.init.TargetModEntities;
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.server.level.ServerLevel;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.AbstractArrow;
import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
public class RpgfireProcedure {
public static void execute(Entity entity) {
if (entity == null) return;
if (entity instanceof Player player && !player.isSpectator()) {
ItemStack usehand = player.getMainHandItem();
if (usehand.getItem() == TargetModItems.RPG.get() && usehand.getOrCreateTag().getDouble("reloading") == 0 && !(entity instanceof Player _plrCldCheck4 && _plrCldCheck4.getCooldowns().isOnCooldown(usehand.getItem()))
&& usehand.getOrCreateTag().getDouble("ammo") > 0) {
entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.recoilhorizon = Math.random() < 0.5 ? -1 : 1;
capability.recoil = 0.1;
capability.firing = 1;
capability.syncPlayerVariables(entity);
});
Level projectileLevel = entity.level();
if (!projectileLevel.isClientSide()) {
Projectile _entityToSpawn = new Object() {
public Projectile getArrow(Level level, Entity shooter, float damage, int knockback) {
AbstractArrow entityToSpawn = new RpgRocketEntity(TargetModEntities.RPG_ROCKET.get(), level);
entityToSpawn.setOwner(shooter);
entityToSpawn.setBaseDamage(damage);
entityToSpawn.setKnockback(knockback);
entityToSpawn.setSilent(true);
return entityToSpawn;
}
}.getArrow(projectileLevel, entity, (float) ((usehand.getOrCreateTag().getDouble("damage") / usehand.getOrCreateTag().getDouble("velocity")) * (1 + 0.05 * usehand.getOrCreateTag().getDouble("level"))), 0);
_entityToSpawn.setPos(entity.getX(), entity.getEyeY() - 0.1, entity.getZ());
_entityToSpawn.shoot(entity.getLookAngle().x, entity.getLookAngle().y, entity.getLookAngle().z, (float) usehand.getOrCreateTag().getDouble("velocity"),
(float) ((LivingEntity) entity).getAttribute(TargetModAttributes.SPREAD.get()).getBaseValue());
projectileLevel.addFreshEntity(_entityToSpawn);
}
if (!entity.level().isClientSide() && entity.getServer() != null) {
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(),
entity.level().getServer(), entity),
("particle minecraft:cloud" + (" " + (entity.getX() + 1.8 * entity.getLookAngle().x)) + (" " + (entity.getY() + entity.getBbHeight() - 0.1 + 1.8 * entity.getLookAngle().y))
+ (" " + (entity.getZ() + 1.8 * entity.getLookAngle().z)) + " 0.4 0.4 0.4 0.005 30 force @s"));
}
if (usehand.getOrCreateTag().getDouble("ammo") == 1) {
usehand.getOrCreateTag().putDouble("empty", 1);
}
player.getCooldowns().addCooldown(usehand.getItem(), 10);
if (!entity.level().isClientSide() && entity.getServer() != null) {
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(), entity.level().getServer(), entity), "playsound target:rpg_fire_1p player @s ~ ~ ~ 2 1");
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(), entity.level().getServer(), entity), "playsound target:rpg_fire_3p player @a ~ ~ ~ 4 1");
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(), entity.level().getServer(), entity), "playsound target:rpg_far player @a ~ ~ ~ 8 1");
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(), entity.level().getServer(), entity), "playsound target:rpg_veryfar player @a ~ ~ ~ 16 1");
}
usehand.getOrCreateTag().putDouble("fireanim", 2);
usehand.getOrCreateTag().putDouble("ammo", (usehand.getOrCreateTag().getDouble("ammo") - 1));
}
}
}
}

View file

@ -9,10 +9,8 @@ import net.minecraft.world.item.ItemStack;
public class RpkWuPinZaiBeiBaoZhongShiMeiKeFaShengProcedure { public class RpkWuPinZaiBeiBaoZhongShiMeiKeFaShengProcedure {
public static void execute(Entity entity, ItemStack itemstack) { public static void execute(Entity entity, ItemStack itemstack) {
if (entity == null) if (entity == null) return;
return; double id = itemstack.getOrCreateTag().getDouble("id");
double id = 0;
id = itemstack.getOrCreateTag().getDouble("id");
if ((entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getOrCreateTag().getDouble("id") != itemstack.getOrCreateTag().getDouble("id")) { if ((entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getOrCreateTag().getDouble("id") != itemstack.getOrCreateTag().getDouble("id")) {
itemstack.getOrCreateTag().putDouble("emptyreload", 0); itemstack.getOrCreateTag().putDouble("emptyreload", 0);
itemstack.getOrCreateTag().putDouble("reloading", 0); itemstack.getOrCreateTag().putDouble("reloading", 0);
@ -21,12 +19,9 @@ public class RpkWuPinZaiBeiBaoZhongShiMeiKeFaShengProcedure {
if (itemstack.getOrCreateTag().getDouble("reloading") == 1 && itemstack.getOrCreateTag().getDouble("ammo") == 0) { if (itemstack.getOrCreateTag().getDouble("reloading") == 1 && itemstack.getOrCreateTag().getDouble("ammo") == 0) {
if (itemstack.getOrCreateTag().getDouble("reloadtime") == 57) { if (itemstack.getOrCreateTag().getDouble("reloadtime") == 57) {
entity.getPersistentData().putDouble("id", id); entity.getPersistentData().putDouble("id", id);
{ if (!entity.level().isClientSide() && entity.getServer() != null) {
Entity _ent = entity; entity.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, entity.position(), entity.getRotationVector(), entity.level() instanceof ServerLevel ? (ServerLevel) entity.level() : null, 4,
if (!_ent.level().isClientSide() && _ent.getServer() != null) { entity.getName().getString(), entity.getDisplayName(), entity.level().getServer(), entity), "playsound target:rpk_reload_empty player @s ~ ~ ~ 100 1");
_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:rpk_reload_empty player @s ~ ~ ~ 100 1");
}
} }
} }
if ((entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getItem() == itemstack.getItem() if ((entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getItem() == itemstack.getItem()
@ -45,12 +40,9 @@ public class RpkWuPinZaiBeiBaoZhongShiMeiKeFaShengProcedure {
} else if (itemstack.getOrCreateTag().getDouble("reloading") == 1 && itemstack.getOrCreateTag().getDouble("ammo") > 0) { } else if (itemstack.getOrCreateTag().getDouble("reloading") == 1 && itemstack.getOrCreateTag().getDouble("ammo") > 0) {
if (itemstack.getOrCreateTag().getDouble("reloadtime") == 41) { if (itemstack.getOrCreateTag().getDouble("reloadtime") == 41) {
entity.getPersistentData().putDouble("id", id); entity.getPersistentData().putDouble("id", id);
{ if (!entity.level().isClientSide() && entity.getServer() != null) {
Entity _ent = entity; entity.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, entity.position(), entity.getRotationVector(), entity.level() instanceof ServerLevel ? (ServerLevel) entity.level() : null, 4,
if (!_ent.level().isClientSide() && _ent.getServer() != null) { entity.getName().getString(), entity.getDisplayName(), entity.level().getServer(), entity), "playsound target:rpk_reload_normal player @s ~ ~ ~ 100 1");
_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:rpk_reload_normal player @s ~ ~ ~ 100 1");
}
} }
} }
if ((entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getItem() == itemstack.getItem() if ((entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getItem() == itemstack.getItem()

View file

@ -2,49 +2,48 @@ package net.mcreator.target.procedures;
import net.mcreator.target.init.TargetModItems; import net.mcreator.target.init.TargetModItems;
import net.mcreator.target.network.TargetModVariables; import net.mcreator.target.network.TargetModVariables;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
public class WeaponDrawProcedure { public class WeaponDrawProcedure {
public static void execute(Entity entity, ItemStack itemstack) { public static void execute(Entity entity, ItemStack itemStack) {
if (entity == null) if (entity == null) return;
return; CompoundTag tag = itemStack.getOrCreateTag();
ItemStack stack = ItemStack.EMPTY; Item mainHandItem = (entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getItem();
if ((entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getItem() == itemstack.getItem()) { if (mainHandItem == itemStack.getItem()) {
if (itemstack.getOrCreateTag().getDouble("draw") < 2) { if (tag.getDouble("draw") < 2) {
itemstack.getOrCreateTag().putDouble("draw", (itemstack.getOrCreateTag().getDouble("draw") + 1)); tag.putDouble("draw", (tag.getDouble("draw") + 1));
} }
} else { } else {
itemstack.getOrCreateTag().putDouble("draw", 0); tag.putDouble("draw", 0);
} }
if (itemstack.getOrCreateTag().getDouble("draw") == 1) { if (tag.getDouble("draw") == 1) {
{
boolean _setval = false;
entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> { entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.zooming = _setval; capability.zooming = false;
capability.syncPlayerVariables(entity); capability.syncPlayerVariables(entity);
}); });
}
if (entity instanceof Player _player) if (entity instanceof Player _player)
_player.getCooldowns().addCooldown(itemstack.getItem(), 16); _player.getCooldowns().addCooldown(itemStack.getItem(), 16);
if (itemstack.getItem() == TargetModItems.RPG.get() && itemstack.getOrCreateTag().getDouble("ammo") == 0) { if (itemStack.getItem() == TargetModItems.RPG.get() && tag.getDouble("ammo") == 0) {
itemstack.getOrCreateTag().putDouble("empty", 1); tag.putDouble("empty", 1);
} }
if (itemstack.getItem() == TargetModItems.SKS.get() && itemstack.getOrCreateTag().getDouble("ammo") == 0) { if (itemStack.getItem() == TargetModItems.SKS.get() && tag.getDouble("ammo") == 0) {
itemstack.getOrCreateTag().putDouble("gj", 1); tag.putDouble("gj", 1);
} }
} }
if ((entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getItem() == itemstack.getItem()) { if (mainHandItem == itemStack.getItem()) {
if (itemstack.getOrCreateTag().getDouble("drawtime") < 16) { if (tag.getDouble("drawtime") < 16) {
itemstack.getOrCreateTag().putDouble("drawtime", (itemstack.getOrCreateTag().getDouble("drawtime") + 1)); tag.putDouble("drawtime", (tag.getDouble("drawtime") + 1));
} }
} else { } else {
itemstack.getOrCreateTag().putDouble("drawtime", 0); tag.putDouble("drawtime", 0);
} }
if (itemstack.getOrCreateTag().getDouble("fireanim") > 0) { if (tag.getDouble("fireanim") > 0) {
itemstack.getOrCreateTag().putDouble("fireanim", (itemstack.getOrCreateTag().getDouble("fireanim") - 1)); tag.putDouble("fireanim", (tag.getDouble("fireanim") - 1));
} }
} }
} }