修改武器发射逻辑
This commit is contained in:
parent
95b8fd3b59
commit
3ada31cdea
2 changed files with 63 additions and 64 deletions
|
@ -3,7 +3,6 @@ package net.mcreator.target.event;
|
|||
import net.mcreator.target.TargetMod;
|
||||
import net.mcreator.target.entity.ProjectileEntity;
|
||||
import net.mcreator.target.init.TargetModAttributes;
|
||||
import net.mcreator.target.init.TargetModItems;
|
||||
import net.mcreator.target.init.TargetModTags;
|
||||
import net.mcreator.target.network.TargetModVariables;
|
||||
import net.mcreator.target.tools.ItemNBTTool;
|
||||
|
@ -20,13 +19,8 @@ import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Mod.EventBusSubscriber
|
||||
public class GunEventHandler {
|
||||
private static final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onPlayerTick(TickEvent.PlayerTickEvent event) {
|
||||
|
@ -112,12 +106,15 @@ public class GunEventHandler {
|
|||
|
||||
private static void handleGunFire(Player player) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (stack.is(TargetModTags.Items.NORMAL_MAG_GUN)
|
||||
&& player.getPersistentData().getDouble("firing") == 1
|
||||
if (stack.is(TargetModTags.Items.NORMAL_MAG_GUN)) {
|
||||
double mode = stack.getOrCreateTag().getDouble("firemode");
|
||||
|
||||
if (player.getPersistentData().getDouble("firing") == 1
|
||||
&& stack.getOrCreateTag().getDouble("reloading") == 0
|
||||
&& stack.getOrCreateTag().getDouble("ammo") > 0
|
||||
&& !stack.getOrCreateTag().getBoolean("shootCooldown")
|
||||
&& stack.getOrCreateTag().getDouble("firemode") != 1) {
|
||||
&& mode != 1
|
||||
&& !player.getCooldowns().isOnCooldown(stack.getItem())) {
|
||||
|
||||
if (stack.getOrCreateTag().getDouble("firemode") == 0) {
|
||||
player.getPersistentData().putDouble("firing", 0);
|
||||
|
@ -138,17 +135,35 @@ public class GunEventHandler {
|
|||
stack.getOrCreateTag().putDouble("fireanim", 2);
|
||||
stack.getOrCreateTag().putDouble("empty", 1);
|
||||
|
||||
int cooldown = (int) Math.ceil(1000 * 60 / ItemNBTTool.getDouble(stack, "rpm", 60));
|
||||
double tick = (20 * 60 / ItemNBTTool.getDouble(stack, "rpm", 60));
|
||||
|
||||
if (mode == 0) {
|
||||
player.getCooldowns().addCooldown(stack.getItem(), (int) tick);
|
||||
for (int index0 = 0; index0 < (int) stack.getOrCreateTag().getDouble("projectileamount"); index0++) {
|
||||
gunShoot(player);
|
||||
}
|
||||
playGunSounds(player);
|
||||
stack.getOrCreateTag().putBoolean("shootCooldown", true);
|
||||
} else {
|
||||
double tickCount = player.getPersistentData().getDouble("target_tick_count");
|
||||
++tickCount;
|
||||
|
||||
// 使用线程池来处理发射,不保证能用
|
||||
Runnable reset = () -> stack.getOrCreateTag().putBoolean("shootCooldown", false);
|
||||
scheduler.schedule(reset, cooldown, TimeUnit.MILLISECONDS);
|
||||
if (tickCount >= tick) {
|
||||
player.getCooldowns().addCooldown(stack.getItem(), (int) tickCount);
|
||||
}
|
||||
|
||||
while (tickCount >= tick) {
|
||||
tickCount -= tick;
|
||||
for (int index0 = 0; index0 < (int) stack.getOrCreateTag().getDouble("projectileamount"); index0++) {
|
||||
gunShoot(player);
|
||||
}
|
||||
}
|
||||
playGunSounds(player);
|
||||
|
||||
player.getPersistentData().putDouble("target_tick_count", tickCount);
|
||||
}
|
||||
} else {
|
||||
player.getPersistentData().putDouble("target_tick_count", 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -204,29 +219,13 @@ public class GunEventHandler {
|
|||
|
||||
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||
capability.recoil = 0.1;
|
||||
capability.syncPlayerVariables(player);
|
||||
});
|
||||
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||
capability.firing = 1;
|
||||
capability.syncPlayerVariables(player);
|
||||
});
|
||||
|
||||
if (!player.level().isClientSide()) {
|
||||
float damage;
|
||||
float headshot = (float) heldItem.getOrCreateTag().getDouble("headshot");
|
||||
float velocity = 4 * (float) heldItem.getOrCreateTag().getDouble("speed");
|
||||
|
||||
if (heldItem.getItem() == TargetModItems.BOCEK.get()) {
|
||||
|
||||
damage = 0.2f * (float) heldItem.getOrCreateTag().getDouble("speed") * (float) heldItem.getOrCreateTag().getDouble("damageadd");
|
||||
|
||||
ProjectileEntity projectile = new ProjectileEntity(player.level(), player, damage, headshot);
|
||||
|
||||
projectile.setPos((player.getX() + (-0.5) * player.getLookAngle().x), (player.getEyeY() - 0.1 + (-0.5) * player.getLookAngle().y), (player.getZ() + (-0.5) * player.getLookAngle().z));
|
||||
projectile.shoot(player.getLookAngle().x, player.getLookAngle().y, player.getLookAngle().z, 1 * velocity, 2.5f);
|
||||
player.level().addFreshEntity(projectile);
|
||||
} else {
|
||||
damage = (float) (heldItem.getOrCreateTag().getDouble("damage") + heldItem.getOrCreateTag().getDouble("adddamage"))
|
||||
float damage = (float) (heldItem.getOrCreateTag().getDouble("damage") + heldItem.getOrCreateTag().getDouble("adddamage"))
|
||||
* (float) heldItem.getOrCreateTag().getDouble("damageadd");
|
||||
|
||||
ProjectileEntity projectile = new ProjectileEntity(player.level(), player, damage, headshot);
|
||||
|
@ -237,6 +236,5 @@ public class GunEventHandler {
|
|||
player.level().addFreshEntity(projectile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package net.mcreator.target.item.gun;
|
|||
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import net.mcreator.target.TargetMod;
|
||||
import net.mcreator.target.client.renderer.item.AK47ItemRenderer;
|
||||
import net.mcreator.target.init.TargetModItems;
|
||||
import net.mcreator.target.item.AnimatedItem;
|
||||
|
@ -155,7 +156,7 @@ public class AK47Item extends GunItem implements GeoItem, AnimatedItem {
|
|||
if (slot == EquipmentSlot.MAINHAND) {
|
||||
map = HashMultimap.create(map);
|
||||
map.put(Attributes.MOVEMENT_SPEED,
|
||||
new AttributeModifier(uuid, "henghengaaa", -0.04f, AttributeModifier.Operation.MULTIPLY_BASE));
|
||||
new AttributeModifier(uuid, TargetMod.ATTRIBUTE_MODIFIER, -0.04f, AttributeModifier.Operation.MULTIPLY_BASE));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue