完善火炮

This commit is contained in:
Atsuihsio 2024-07-17 22:10:18 +08:00
parent a19bb9c040
commit 5629dc5f88
14 changed files with 88 additions and 6 deletions

View file

@ -1,14 +1,13 @@
package net.mcreator.target.entity;
import net.mcreator.target.init.TargetModDamageTypes;
import net.mcreator.target.init.TargetModEntities;
import net.mcreator.target.init.TargetModItems;
import net.mcreator.target.init.TargetModSounds;
import net.mcreator.target.init.*;
import net.mcreator.target.item.common.ammo.CannonShellItem;
import net.mcreator.target.network.TargetModVariables;
import net.mcreator.target.tools.CustomExplosion;
import net.mcreator.target.tools.ParticleTool;
import net.mcreator.target.tools.SoundTool;
import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.protocol.Packet;
@ -237,6 +236,7 @@ public class Mk42Entity extends PathfinderMob implements GeoEntity {
gunner.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.recoilHorizon = 2 * Math.random() - 1;
capability.cannonFiring = 1;
capability.cannonRecoil = 10;
capability.syncPlayerVariables(gunner);
});
}
@ -295,6 +295,7 @@ public class Mk42Entity extends PathfinderMob implements GeoEntity {
if (player instanceof ServerPlayer serverPlayer) {
SoundTool.playLocalSound(serverPlayer, TargetModSounds.MK_42_FIRE_1P.get(), 2, 1);
SoundTool.playLocalSound(serverPlayer, TargetModSounds.MK_42_RELOAD.get(), 2, 1);
serverPlayer.level().playSound(null, serverPlayer.getOnPos(), TargetModSounds.MK_42_FIRE_3P.get(), SoundSource.PLAYERS, 6, 1);
serverPlayer.level().playSound(null, serverPlayer.getOnPos(), TargetModSounds.MK_42_FAR.get(), SoundSource.PLAYERS, 16, 1);
serverPlayer.level().playSound(null, serverPlayer.getOnPos(), TargetModSounds.MK_42_VERYFAR.get(), SoundSource.PLAYERS, 32, 1);
@ -357,6 +358,15 @@ public class Mk42Entity extends PathfinderMob implements GeoEntity {
private PlayState movementPredicate(AnimationState event) {
if (this.animationprocedure.equals("empty")) {
if (this.getFirstPassenger() != null) {
Entity gunner = this.getFirstPassenger();
var capability = gunner.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null);
if (capability.orElse(new TargetModVariables.PlayerVariables()).cannonRecoil > 0) {
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.mk42.fire"));
}
}
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.mk42.idle"));
}
return PlayState.STOP;
@ -394,8 +404,8 @@ public class Mk42Entity extends PathfinderMob implements GeoEntity {
@Override
public void registerControllers(AnimatableManager.ControllerRegistrar data) {
data.add(new AnimationController<>(this, "movement", 4, this::movementPredicate));
data.add(new AnimationController<>(this, "procedure", 4, this::procedurePredicate));
data.add(new AnimationController<>(this, "movement", 0, this::movementPredicate));
data.add(new AnimationController<>(this, "procedure", 0, this::procedurePredicate));
}
@Override

View file

@ -1,8 +1,10 @@
package net.mcreator.target.entity.model;
import net.mcreator.target.entity.Mk42Entity;
import net.mcreator.target.network.TargetModVariables;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import software.bernie.geckolib.constant.DataTickets;
import software.bernie.geckolib.core.animatable.model.CoreGeoBone;
import software.bernie.geckolib.core.animation.AnimationState;
@ -30,5 +32,12 @@ public class Mk42Model extends GeoModel<Mk42Entity> {
CoreGeoBone barrle = getAnimationProcessor().getBone("maingun");
EntityModelData entityData = (EntityModelData) animationState.getData(DataTickets.ENTITY_MODEL_DATA);
barrle.setRotX((entityData.headPitch()) * Mth.DEG_TO_RAD);
// CoreGeoBone paoguan = getAnimationProcessor().getBone("paoguan");
// if (animatable.getFirstPassenger() == null) return;
// Entity gunner = animatable.getFirstPassenger();
// var capability = gunner.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null);
// paoguan.setPosZ(capability.orElse(new TargetModVariables.PlayerVariables()).cannonRecoil);
}
}

View file

@ -81,6 +81,12 @@ public class PlayerEventHandler {
capability.syncPlayerVariables(player);
});
}
if ((player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).cannonRecoil > 0) {
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.cannonRecoil = (player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).cannonRecoil - 1;
capability.syncPlayerVariables(player);
});
}
}
}

View file

@ -185,6 +185,7 @@ public class TargetModSounds {
public static final RegistryObject<SoundEvent> MK_42_FIRE_3P = REGISTRY.register("mk_42_fire_3p", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation("target", "mk_42_fire_3p")));
public static final RegistryObject<SoundEvent> MK_42_FAR = REGISTRY.register("mk_42_far", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation("target", "mk_42_far")));
public static final RegistryObject<SoundEvent> MK_42_VERYFAR = REGISTRY.register("mk_42_veryfar", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation("target", "mk_42_veryfar")));
public static final RegistryObject<SoundEvent> MK_42_RELOAD = REGISTRY.register("mk_42_reload", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation("target", "mk_42_reload")));
public static final RegistryObject<SoundEvent> BULLET_SUPPLY = REGISTRY.register("bullet_supply", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation("target", "bullet_supply")));
public static final RegistryObject<SoundEvent> ADJUST_FOV = REGISTRY.register("adjust_fov", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation("target", "adjust_fov")));

View file

@ -270,6 +270,7 @@ public class TargetModVariables {
public double recoilHorizon = 0;
public double firing = 0;
public double cannonFiring = 0;
public int cannonRecoil = 0;
public double targetAngle = 0;
public int rifleAmmo = 0;
public boolean refresh = false;
@ -293,6 +294,7 @@ public class TargetModVariables {
nbt.putDouble("recoil_horizon", recoilHorizon);
nbt.putDouble("firing", firing);
nbt.putDouble("cannonFiring", cannonFiring);
nbt.putInt("cannonRecoil", cannonRecoil);
nbt.putDouble("target_angle", targetAngle);
nbt.putInt("rifle_ammo", rifleAmmo);
nbt.putBoolean("refresh", refresh);
@ -314,6 +316,7 @@ public class TargetModVariables {
recoilHorizon = nbt.getDouble("recoil_horizon");
firing = nbt.getDouble("firing");
cannonFiring = nbt.getDouble("cannonFiring");
cannonRecoil = nbt.getInt("cannonRecoil");
targetAngle = nbt.getDouble("target_angle");
rifleAmmo = nbt.getInt("rifle_ammo");
refresh = nbt.getBoolean("refresh");
@ -371,6 +374,7 @@ public class TargetModVariables {
variables.recoilHorizon = message.data.recoilHorizon;
variables.firing = message.data.firing;
variables.cannonFiring = message.data.cannonFiring;
variables.cannonRecoil = message.data.cannonRecoil;
variables.targetAngle = message.data.targetAngle;
variables.rifleAmmo = message.data.rifleAmmo;
variables.refresh = message.data.refresh;

View file

@ -3,6 +3,42 @@
"animations": {
"animation.mk42.idle": {
"loop": true
},
"animation.mk42.fire": {
"loop": "hold_on_last_frame",
"animation_length": 0.5,
"bones": {
"paoguan": {
"position": {
"0.0": {
"vector": [0, 0, 11],
"easing": "easeInElastic"
},
"0.4917": {
"vector": [0, 0, 0],
"easing": "easeInQuad"
}
}
}
}
},
"animation.mk42.fire2": {
"loop": "hold_on_last_frame",
"animation_length": 0.5,
"bones": {
"paoguan": {
"position": {
"0.0": {
"vector": [0, 0, 11],
"easing": "easeInElastic"
},
"0.4917": {
"vector": [0, 0, 0],
"easing": "easeInQuad"
}
}
}
}
}
},
"geckolib_format_version": 2

View file

@ -1542,5 +1542,21 @@
"stream": false
}
]
},
"mk_42_reload": {
"sounds": [
{
"name": "target:mk_42/mk_42_reload_01",
"stream": false
},
{
"name": "target:mk_42/mk_42_reload_02",
"stream": false
},
{
"name": "target:mk_42/mk_42_reload_03",
"stream": false
}
]
}
}