改炮
This commit is contained in:
parent
8bb6f0602a
commit
b274a0c39f
19 changed files with 443 additions and 104 deletions
|
@ -95,6 +95,7 @@ public class TargetMod {
|
|||
addNetworkMessage(DoubleJumpMessage.class, DoubleJumpMessage::buffer, DoubleJumpMessage::new, DoubleJumpMessage::handler);
|
||||
addNetworkMessage(GunsDataMessage.class, GunsDataMessage::encode, GunsDataMessage::decode, GunsDataMessage::handler, Optional.of(NetworkDirection.PLAY_TO_CLIENT));
|
||||
addNetworkMessage(FireMessage.class, FireMessage::buffer, FireMessage::new, FireMessage::handler);
|
||||
addNetworkMessage(VehicleFireMessage.class, VehicleFireMessage::buffer, VehicleFireMessage::new, VehicleFireMessage::handler);
|
||||
addNetworkMessage(FireModeMessage.class, FireModeMessage::buffer, FireModeMessage::new, FireModeMessage::handler);
|
||||
addNetworkMessage(GunRecycleGuiButtonMessage.class, GunRecycleGuiButtonMessage::buffer, GunRecycleGuiButtonMessage::new, GunRecycleGuiButtonMessage::handler);
|
||||
addNetworkMessage(ReloadMessage.class, ReloadMessage::encode, ReloadMessage::decode, ReloadMessage::handler);
|
||||
|
|
|
@ -3,15 +3,13 @@ package net.mcreator.target.client;
|
|||
import com.mojang.blaze3d.platform.InputConstants;
|
||||
import net.mcreator.target.TargetMod;
|
||||
import net.mcreator.target.client.gui.RangeHelper;
|
||||
import net.mcreator.target.entity.Mk42Entity;
|
||||
import net.mcreator.target.entity.MortarEntity;
|
||||
import net.mcreator.target.init.TargetModKeyMappings;
|
||||
import net.mcreator.target.init.TargetModMobEffects;
|
||||
import net.mcreator.target.init.TargetModTags;
|
||||
import net.mcreator.target.network.TargetModVariables;
|
||||
import net.mcreator.target.network.message.AdjustMortarAngleMessage;
|
||||
import net.mcreator.target.network.message.AdjustZoomFovMessage;
|
||||
import net.mcreator.target.network.message.FireMessage;
|
||||
import net.mcreator.target.network.message.ZoomMessage;
|
||||
import net.mcreator.target.network.message.*;
|
||||
import net.mcreator.target.tools.TraceTool;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
@ -46,6 +44,7 @@ public class ClickHandler {
|
|||
int button = event.getButton();
|
||||
if (button == GLFW.GLFW_MOUSE_BUTTON_LEFT) {
|
||||
TargetMod.PACKET_HANDLER.sendToServer(new FireMessage(1));
|
||||
TargetMod.PACKET_HANDLER.sendToServer(new VehicleFireMessage(1));
|
||||
}
|
||||
if (button == GLFW.GLFW_MOUSE_BUTTON_RIGHT) {
|
||||
if (Minecraft.getInstance().player.hasEffect(TargetModMobEffects.SHOCK.get())) {
|
||||
|
@ -72,6 +71,11 @@ public class ClickHandler {
|
|||
event.setCanceled(true);
|
||||
return;
|
||||
}
|
||||
if (player.getVehicle() != null && player.getVehicle() instanceof Mk42Entity) {
|
||||
event.setCanceled(true);
|
||||
TargetMod.PACKET_HANDLER.sendToServer(new VehicleFireMessage(0));
|
||||
return;
|
||||
}
|
||||
if (player.getMainHandItem().is(TargetModTags.Items.GUN)) {
|
||||
event.setCanceled(true);
|
||||
TargetMod.PACKET_HANDLER.sendToServer(new FireMessage(0));
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
package net.mcreator.target.client.renderer.entity;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import com.mojang.math.Axis;
|
||||
import net.mcreator.target.client.model.entity.ModelMortarShell;
|
||||
import net.mcreator.target.entity.CannonShellEntity;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.entity.EntityRenderer;
|
||||
import net.minecraft.client.renderer.entity.EntityRendererProvider;
|
||||
import net.minecraft.client.renderer.texture.OverlayTexture;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.Mth;
|
||||
|
||||
public class CannonShellRenderer extends EntityRenderer<CannonShellEntity> {
|
||||
private static final ResourceLocation texture = new ResourceLocation("target:textures/entity/mortar_shell.png");
|
||||
private final ModelMortarShell<CannonShellEntity> model;
|
||||
|
||||
public CannonShellRenderer(EntityRendererProvider.Context context) {
|
||||
super(context);
|
||||
model = new ModelMortarShell<>(context.bakeLayer(ModelMortarShell.LAYER_LOCATION));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(CannonShellEntity entityIn, float entityYaw, float partialTicks, PoseStack poseStack, MultiBufferSource bufferIn, int packedLightIn) {
|
||||
VertexConsumer vb = bufferIn.getBuffer(RenderType.entityCutout(this.getTextureLocation(entityIn)));
|
||||
poseStack.pushPose();
|
||||
poseStack.mulPose(Axis.YP.rotationDegrees(Mth.lerp(partialTicks, entityIn.yRotO, entityIn.getYRot()) - 90));
|
||||
poseStack.mulPose(Axis.ZP.rotationDegrees(90 + Mth.lerp(partialTicks, entityIn.xRotO, entityIn.getXRot())));
|
||||
model.renderToBuffer(poseStack, vb, packedLightIn, OverlayTexture.NO_OVERLAY, 1, 1, 1, 0.0625f);
|
||||
poseStack.popPose();
|
||||
super.render(entityIn, entityYaw, partialTicks, poseStack, bufferIn, packedLightIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getTextureLocation(CannonShellEntity entity) {
|
||||
return texture;
|
||||
}
|
||||
}
|
132
src/main/java/net/mcreator/target/entity/CannonShellEntity.java
Normal file
132
src/main/java/net/mcreator/target/entity/CannonShellEntity.java
Normal file
|
@ -0,0 +1,132 @@
|
|||
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.tools.CustomExplosion;
|
||||
import net.mcreator.target.tools.ParticleTool;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.particles.ParticleTypes;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.game.ClientGamePacketListener;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.projectile.ThrowableItemProjectile;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.level.Explosion;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.EntityHitResult;
|
||||
import net.minecraftforge.network.NetworkHooks;
|
||||
import net.minecraftforge.network.PlayMessages;
|
||||
|
||||
public class CannonShellEntity extends ThrowableItemProjectile {
|
||||
private float damage = 0;
|
||||
private float explosionRadius = 0;
|
||||
private float explosionDamage = 0;
|
||||
private float fireProbability = 0;
|
||||
private int fireTime = 0;
|
||||
|
||||
public CannonShellEntity(EntityType<? extends CannonShellEntity> type, Level world) {
|
||||
super(type, world);
|
||||
}
|
||||
|
||||
public CannonShellEntity(EntityType<? extends CannonShellEntity> type, double x, double y, double z, Level world) {
|
||||
super(type, x, y, z, world);
|
||||
}
|
||||
|
||||
public CannonShellEntity(EntityType<? extends CannonShellEntity> type, LivingEntity entity, Level world) {
|
||||
super(type, entity, world);
|
||||
}
|
||||
|
||||
public CannonShellEntity(EntityType<? extends CannonShellEntity> type, LivingEntity entity, Level world, float damage, float explosionRadius, float explosionDamage, float fireProbability, int fireTime) {
|
||||
super(type, entity, world);
|
||||
this.damage = damage;
|
||||
this.explosionRadius = explosionRadius;
|
||||
this.explosionDamage = explosionDamage;
|
||||
this.fireProbability = fireProbability;
|
||||
this.fireTime = fireTime;
|
||||
}
|
||||
|
||||
public CannonShellEntity(PlayMessages.SpawnEntity spawnEntity, Level level) {
|
||||
this(TargetModEntities.CANNON_SHELL.get(), level);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet<ClientGamePacketListener> getAddEntityPacket() {
|
||||
return NetworkHooks.getEntitySpawningPacket(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Item getDefaultItem() {
|
||||
return TargetModItems.HE_5_INCHES.get();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onHitEntity(EntityHitResult entityHitResult) {
|
||||
Entity entity = entityHitResult.getEntity();
|
||||
|
||||
entity.hurt(this.level().damageSources().thrown(this, this.getOwner()), this.damage);
|
||||
|
||||
if (this.level() instanceof ServerLevel) {
|
||||
causeExplode();
|
||||
}
|
||||
this.discard();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHitBlock(BlockHitResult blockHitResult) {
|
||||
super.onHitBlock(blockHitResult);
|
||||
|
||||
int x = blockHitResult.getBlockPos().getX();
|
||||
int y = blockHitResult.getBlockPos().getY();
|
||||
int z = blockHitResult.getBlockPos().getZ();
|
||||
|
||||
float hardness = this.level().getBlockState(BlockPos.containing(x, y, z)).getDestroySpeed(this.level(), BlockPos.containing(x, y, z));
|
||||
|
||||
|
||||
if (!this.level().isClientSide() && this.level() instanceof ServerLevel) {
|
||||
causeExplode();
|
||||
}
|
||||
this.discard();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
if (this.level() instanceof ServerLevel serverLevel) {
|
||||
ParticleTool.sendParticle(serverLevel, ParticleTypes.CAMPFIRE_COSY_SMOKE, this.getX(), this.getY(), this.getZ(),
|
||||
1, 0, 0, 0, 0.001, true);
|
||||
}
|
||||
if (this.tickCount > 600 || this.isInWater()) {
|
||||
if (this.level() instanceof ServerLevel) {
|
||||
causeExplode();
|
||||
}
|
||||
this.discard();
|
||||
}
|
||||
}
|
||||
|
||||
private void causeExplode() {
|
||||
|
||||
if (Math.random() > fireProbability){
|
||||
fireTime = 0;
|
||||
}
|
||||
|
||||
CustomExplosion explosion = new CustomExplosion(this.level(), this,
|
||||
TargetModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), this, this.getOwner()), explosionDamage,
|
||||
this.getX(), this.getY(), this.getZ(), explosionRadius, Explosion.BlockInteraction.KEEP).setDamageMultiplier(1).setFireTime(fireTime);
|
||||
explosion.explode();
|
||||
net.minecraftforge.event.ForgeEventFactory.onExplosionStart(this.level(), explosion);
|
||||
explosion.finalizeExplosion(false);
|
||||
|
||||
ParticleTool.spawnHugeExplosionParticles(this.level(), this.position());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float getGravity() {
|
||||
return 0.05F;
|
||||
}
|
||||
}
|
|
@ -2,12 +2,17 @@
|
|||
package net.mcreator.target.entity;
|
||||
|
||||
import net.mcreator.target.init.*;
|
||||
import net.mcreator.target.item.common.ammo.CannonShellItem;
|
||||
import net.mcreator.target.item.common.ammo.He5Inches;
|
||||
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.core.particles.ParticleTypes;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
|
@ -212,39 +217,103 @@ public class Mk42Entity extends PathfinderMob implements GeoEntity {
|
|||
|
||||
Entity gunner = this.getFirstPassenger();
|
||||
|
||||
float adjust_rateX = (float) Mth.clamp(Math.pow(gunner.getXRot() - this.getXRot(), 2),0,5f);
|
||||
float adjust_rateY = (float) Mth.clamp(Math.pow(gunner.getYRot() - this.getYRot(), 2),0,3f);
|
||||
// float adjust_rateX = (float) Mth.clamp(Math.pow(gunner.getXRot() - this.getXRot(), 2),0,5f);
|
||||
// float adjust_rateY = (float) Mth.clamp(Math.pow(gunner.getYRot() - this.getYRot(), 2),0,3f);
|
||||
//
|
||||
// if (RotY < gunner.getYRot()) {
|
||||
// RotY = (float) Mth.clamp(this.yHeadRot + adjust_rateY,Double.NEGATIVE_INFINITY, gunner.getYRot());
|
||||
// } else {
|
||||
// RotY = (float) Mth.clamp(this.yHeadRot- adjust_rateY,gunner.getYRot(),Double.POSITIVE_INFINITY);
|
||||
// }
|
||||
//
|
||||
// if (RotX < gunner.getXRot()) {
|
||||
// RotX = Mth.clamp((Mth.clamp(this.getXRot() + adjust_rateX,-85 ,15)),-85, gunner.getXRot());
|
||||
// } else {
|
||||
// RotX = Mth.clamp((Mth.clamp(this.getXRot() - adjust_rateX,-85 ,15)),gunner.getXRot(),15);
|
||||
// }
|
||||
|
||||
if (RotY < gunner.getYRot()) {
|
||||
RotY = (float) Mth.clamp(this.yHeadRot + adjust_rateY,Double.NEGATIVE_INFINITY, gunner.getYRot());
|
||||
} else {
|
||||
RotY = (float) Mth.clamp(this.yHeadRot- adjust_rateY,gunner.getYRot(),Double.POSITIVE_INFINITY);
|
||||
if (this.getPersistentData().getInt("fire_cooldown") > 0) {
|
||||
this.getPersistentData().putInt("fire_cooldown", this.getPersistentData().getInt("fire_cooldown") - 1);
|
||||
}
|
||||
|
||||
if (RotX < gunner.getXRot()) {
|
||||
RotX = Mth.clamp((Mth.clamp(this.getXRot() + adjust_rateX,-85 ,15)),-85, gunner.getXRot());
|
||||
} else {
|
||||
RotX = Mth.clamp((Mth.clamp(this.getXRot() - adjust_rateX,-85 ,15)),gunner.getXRot(),15);
|
||||
if (this.getPersistentData().getBoolean("firing") && gunner instanceof Player player && this.getPersistentData().getInt("fire_cooldown") == 0) {
|
||||
cannonShoot(player);
|
||||
}
|
||||
|
||||
this.refreshDimensions();
|
||||
}
|
||||
|
||||
public void cannonShoot(Player player) {
|
||||
|
||||
Level level = player.level();
|
||||
if (level instanceof ServerLevel server) {
|
||||
|
||||
if (!(player.getMainHandItem().getItem() instanceof CannonShellItem))
|
||||
return;
|
||||
|
||||
float hitDamage = 0;
|
||||
float explosionRadius = 0;
|
||||
float explosionDamage = 0;
|
||||
float fireProbability = 0;
|
||||
int fireTime = 0;
|
||||
|
||||
if (player.getMainHandItem().is(TargetModItems.HE_5_INCHES.get())) {
|
||||
hitDamage = 100;
|
||||
explosionRadius = 10;
|
||||
explosionDamage = 200;
|
||||
fireProbability = 0.3F;
|
||||
fireTime = 100;
|
||||
}
|
||||
|
||||
player.getMainHandItem().shrink(1);
|
||||
|
||||
CannonShellEntity entityToSpawn = new CannonShellEntity(TargetModEntities.CANNON_SHELL.get(), player, level, hitDamage, explosionRadius, explosionDamage, fireProbability, fireTime);
|
||||
entityToSpawn.setPos(this.getX(), this.getEyeY(), this.getZ());
|
||||
entityToSpawn.shoot(this.getLookAngle().x, this.getLookAngle().y, this.getLookAngle().z, 15, 0.1f);
|
||||
level.addFreshEntity(entityToSpawn);
|
||||
|
||||
if (player instanceof ServerPlayer serverPlayer) {
|
||||
SoundTool.playLocalSound(serverPlayer, TargetModSounds.MK_42_FIRE_1P.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);
|
||||
}
|
||||
|
||||
this.getPersistentData().putInt("fire_cooldown", 30);
|
||||
|
||||
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||
capability.recoilHorizon = 2 * Math.random() - 1;
|
||||
capability.cannonFiring = 1;
|
||||
capability.syncPlayerVariables(player);
|
||||
});
|
||||
|
||||
server.sendParticles(ParticleTypes.CAMPFIRE_COSY_SMOKE,
|
||||
this.getX() + 5 * this.getLookAngle().x,
|
||||
this.getY(),
|
||||
this.getZ() + 5 * this.getLookAngle().z,
|
||||
200, 5, 0.02, 5, 0.005);
|
||||
|
||||
server.sendParticles(ParticleTypes.CAMPFIRE_COSY_SMOKE,
|
||||
this.getX() + 9 * this.getLookAngle().x,
|
||||
this.getEyeY() + 9 * this.getLookAngle().y,
|
||||
this.getZ() + 9 * this.getLookAngle().z,
|
||||
70, 0.3, 0.3, 0.3, 0.01);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void travel(Vec3 dir) {
|
||||
|
||||
if (this.getFirstPassenger() == null) return;
|
||||
Entity gunner = this.getFirstPassenger();
|
||||
if (this.isVehicle()) {
|
||||
this.setYRot(RotY);
|
||||
this.setYRot(gunner.getYRot());
|
||||
this.yRotO = this.getYRot();
|
||||
this.setXRot(RotX);
|
||||
this.setXRot(Mth.clamp(gunner.getXRot() - 1.35f, -85, 15));
|
||||
this.setRot(this.getYRot(), this.getXRot());
|
||||
this.yBodyRot = RotY;
|
||||
this.yHeadRot = RotY;
|
||||
this.setMaxUpStep(0.5F);
|
||||
return;
|
||||
this.yBodyRot = gunner.getYRot();
|
||||
this.yHeadRot = gunner.getYRot();
|
||||
}
|
||||
this.setMaxUpStep(0.5F);
|
||||
super.travel(dir);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package net.mcreator.target.event;
|
||||
|
||||
import net.mcreator.target.entity.Mk42Entity;
|
||||
import net.mcreator.target.init.TargetModAttributes;
|
||||
import net.mcreator.target.init.TargetModMobEffects;
|
||||
import net.mcreator.target.init.TargetModTags;
|
||||
|
@ -42,12 +43,18 @@ public class ClientEventHandler {
|
|||
data.putDouble("xRot", Mth.clamp(0.05 * xRot, -5, 5) * (1 - 0.75 * data.getDouble("zoom_time")));
|
||||
data.putDouble("yRot", Mth.clamp(0.05 * yRot, -10, 10) * (1 - 0.75 * data.getDouble("zoom_time")));
|
||||
data.putDouble("zRot", Mth.clamp(0.1 * yRot, -10, 10) * (1 - data.getDouble("zoom_time")));
|
||||
|
||||
data.putDouble("Cannon_xRot", Mth.clamp(0.2 * xRot, -3, 3));
|
||||
data.putDouble("Cannon_yRot", Mth.clamp(1 * yRot, -15, 15));
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void computeCameraAngles(ViewportEvent.ComputeCameraAngles event) {
|
||||
ClientLevel level = Minecraft.getInstance().level;
|
||||
Entity entity = event.getCamera().getEntity();
|
||||
if (level != null && entity instanceof LivingEntity living) {
|
||||
handleCannonCamera(event, living);
|
||||
}
|
||||
if (level != null && entity instanceof LivingEntity living && living.getMainHandItem().is(TargetModTags.Items.GUN)) {
|
||||
handleWeaponCrossHair(living);
|
||||
handleWeaponSway(living);
|
||||
|
@ -60,6 +67,49 @@ public class ClientEventHandler {
|
|||
}
|
||||
}
|
||||
|
||||
private static void handleCannonCamera(ViewportEvent.ComputeCameraAngles event, LivingEntity entity) {
|
||||
var data = entity.getPersistentData();
|
||||
double yaw = event.getYaw();
|
||||
double pitch = event.getPitch();
|
||||
double roll = event.getRoll();
|
||||
|
||||
float fps = Minecraft.getInstance().getFps();
|
||||
if (fps <= 0) {
|
||||
fps = 1f;
|
||||
}
|
||||
|
||||
float times = 45f / fps;
|
||||
|
||||
if (entity.getVehicle() != null && entity.getVehicle() instanceof Mk42Entity) {
|
||||
|
||||
var capability = entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null);
|
||||
if (capability.orElse(new TargetModVariables.PlayerVariables()).cannonFiring > 0) {
|
||||
data.putDouble("cannon_fire_shake_time", 0.001);
|
||||
}
|
||||
|
||||
if (0 < data.getDouble("cannon_fire_shake_time") && data.getDouble("cannon_fire_shake_time") < 1.732) {
|
||||
data.putDouble("cannon_fire_shake_time", (data.getDouble("cannon_fire_shake_time") + 0.18 * (1.9 - data.getDouble("cannon_fire_shake_time")) * times));
|
||||
}
|
||||
|
||||
if (0 < data.getDouble("cannon_fire_shake_time") && data.getDouble("cannon_fire_shake_time") < 1.732) {
|
||||
|
||||
float shake = (float) ((1 / 6.3 * (data.getDouble("cannon_fire_shake_time") - 0.5)) * Math.sin(6.3 * (data.getDouble("cannon_fire_shake_time") - 0.5)) * (3 - Math.pow(data.getDouble("cannon_fire_shake_time"), 2)) + 1 * Mth.clamp(0.3 - data.getDouble("cannon_fire_shake_time"), 0, 1) * 0.25 * (2 * Math.random() - 1) * capability.orElse(new TargetModVariables.PlayerVariables()).recoilHorizon);
|
||||
|
||||
event.setYaw((float) (yaw - 13.3 * shake));
|
||||
event.setPitch((float) (pitch + 13.3 * shake));
|
||||
event.setRoll((float) (roll + 15.2 * shake));
|
||||
|
||||
} else {
|
||||
event.setPitch((float) (pitch + 1 * data.getDouble("Cannon_xRot")));
|
||||
event.setYaw((float) (yaw + 1 * data.getDouble("Cannon_yRot")));
|
||||
}
|
||||
|
||||
if (data.getDouble("cannon_fire_shake_time") >= 1.732) {
|
||||
data.putDouble("cannon_fire_shake_time", 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onRenderHand(RenderHandEvent event) {
|
||||
Player player = Minecraft.getInstance().player;
|
||||
|
|
|
@ -74,6 +74,13 @@ public class PlayerEventHandler {
|
|||
handleGunRecoil(player);
|
||||
}
|
||||
handleDistantRange(player);
|
||||
|
||||
if ((player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).cannonFiring > 0) {
|
||||
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||
capability.cannonFiring = (player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).cannonFiring - 0.5;
|
||||
capability.syncPlayerVariables(player);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,6 +45,8 @@ public class TargetModEntities {
|
|||
EntityType.Builder.<BocekArrowEntity>of(BocekArrowEntity::new, MobCategory.MISC).setShouldReceiveVelocityUpdates(true).setCustomClientFactory(BocekArrowEntity::new).setTrackingRange(64).setUpdateInterval(1).sized(0.5f, 0.5f));
|
||||
public static final RegistryObject<EntityType<ProjectileEntity>> PROJECTILE = register("projectile",
|
||||
EntityType.Builder.<ProjectileEntity>of(ProjectileEntity::new, MobCategory.MISC).setCustomClientFactory(ProjectileEntity::new).setTrackingRange(512).sized(0.5f, 0.5f));
|
||||
public static final RegistryObject<EntityType<CannonShellEntity>> CANNON_SHELL = register("projectile_cannon_shell",
|
||||
EntityType.Builder.<CannonShellEntity>of(CannonShellEntity::new, MobCategory.MISC).setShouldReceiveVelocityUpdates(true).setTrackingRange(64).setUpdateInterval(1).setCustomClientFactory(CannonShellEntity::new).sized(0.5f, 0.5f));
|
||||
|
||||
|
||||
private static <T extends Entity> RegistryObject<EntityType<T>> register(String registryname, EntityType.Builder<T> entityTypeBuilder) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package net.mcreator.target.init;
|
||||
|
||||
import net.mcreator.target.client.renderer.entity.*;
|
||||
import net.mcreator.target.entity.CannonShellEntity;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.EntityRenderersEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
|
@ -19,6 +20,7 @@ public class TargetModEntityRenderers {
|
|||
event.registerEntityRenderer(TargetModEntities.TARGET.get(), TargetRenderer::new);
|
||||
event.registerEntityRenderer(TargetModEntities.RPG_ROCKET.get(), RpgRocketRenderer::new);
|
||||
event.registerEntityRenderer(TargetModEntities.MORTAR_SHELL.get(), MortarShellRenderer::new);
|
||||
event.registerEntityRenderer(TargetModEntities.CANNON_SHELL.get(), CannonShellRenderer::new);
|
||||
event.registerEntityRenderer(TargetModEntities.BOCEK_ARROW.get(), BocekArrowRenderer::new);
|
||||
event.registerEntityRenderer(TargetModEntities.PROJECTILE.get(), ProjectileRenderer::new);
|
||||
event.registerEntityRenderer(TargetModEntities.FRAG.get(), FragRenderer::new);
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
package net.mcreator.target.item.common.ammo;
|
||||
|
||||
import net.minecraft.world.item.Item;
|
||||
|
||||
public abstract class CannonShellItem extends Item {
|
||||
public CannonShellItem(Properties properties) {
|
||||
super(properties);
|
||||
}
|
||||
}
|
|
@ -1,21 +1,6 @@
|
|||
package net.mcreator.target.item.common.ammo;
|
||||
|
||||
import net.mcreator.target.entity.Mk42Entity;
|
||||
import net.mcreator.target.entity.MortarShellEntity;
|
||||
import net.mcreator.target.init.TargetModEntities;
|
||||
import net.mcreator.target.init.TargetModItems;
|
||||
import net.mcreator.target.init.TargetModSounds;
|
||||
import net.mcreator.target.tools.SoundTool;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.core.particles.ParticleTypes;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResultHolder;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Rarity;
|
||||
|
@ -24,7 +9,7 @@ import net.minecraft.world.level.Level;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
public class He5Inches extends Item {
|
||||
public class He5Inches extends CannonShellItem {
|
||||
public He5Inches() {
|
||||
super(new Item.Properties().stacksTo(64).rarity(Rarity.RARE));
|
||||
}
|
||||
|
@ -33,69 +18,4 @@ public class He5Inches extends Item {
|
|||
public void appendHoverText(ItemStack itemstack, Level world, List<Component> list, TooltipFlag flag) {
|
||||
super.appendHoverText(itemstack, world, list, flag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionResultHolder<ItemStack> use(Level world, Player entity, InteractionHand hand) {
|
||||
InteractionResultHolder<ItemStack> ar = InteractionResultHolder.success(entity.getItemInHand(hand));
|
||||
entity.startUsingItem(hand);
|
||||
|
||||
|
||||
ItemStack stack = entity.getMainHandItem();
|
||||
|
||||
if (entity.getVehicle() != null && entity.getVehicle() instanceof Mk42Entity && stack.is(TargetModItems.HE_5_INCHES.get())) {
|
||||
Entity cannon = entity.getVehicle();
|
||||
entity.getCooldowns().addCooldown(stack.getItem(), 30);
|
||||
entity.getInventory().clearOrCountMatchingItems(p -> p.getItem() == TargetModItems.HE_5_INCHES.get(), 1, entity.inventoryMenu.getCraftSlots());
|
||||
cannonShoot(entity, cannon);
|
||||
|
||||
}
|
||||
return ar;
|
||||
}
|
||||
|
||||
public static void cannonShoot(Player player, Entity cannon) {
|
||||
|
||||
Level level = player.level();
|
||||
if (level instanceof ServerLevel server) {
|
||||
MortarShellEntity entityToSpawn = new MortarShellEntity(TargetModEntities.MORTAR_SHELL.get(), player, level);
|
||||
entityToSpawn.setPos(cannon.getX(), cannon.getEyeY(), cannon.getZ());
|
||||
entityToSpawn.shoot(cannon.getLookAngle().x, cannon.getLookAngle().y, cannon.getLookAngle().z, 10, 0.1f);
|
||||
level.addFreshEntity(entityToSpawn);
|
||||
|
||||
if (player instanceof ServerPlayer serverPlayer) {
|
||||
SoundTool.playLocalSound(serverPlayer, TargetModSounds.MK_42_FIRE_1P.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);
|
||||
}
|
||||
|
||||
server.sendParticles(ParticleTypes.CAMPFIRE_COSY_SMOKE,
|
||||
cannon.getX() + 5 * cannon.getLookAngle().x,
|
||||
cannon.getY(),
|
||||
cannon.getZ() + 5 * cannon.getLookAngle().z,
|
||||
200, 5, 0.02, 5, 0.005);
|
||||
|
||||
server.sendParticles(ParticleTypes.CAMPFIRE_COSY_SMOKE,
|
||||
cannon.getX() + 10 * cannon.getLookAngle().x,
|
||||
cannon.getEyeY() + 10 * cannon.getLookAngle().y,
|
||||
cannon.getZ() + 10 * cannon.getLookAngle().z,
|
||||
100, 0.5, 0.5, 0.5, 0.05);
|
||||
|
||||
// for (int index0 = 0; index0 < 40; index0++) {
|
||||
// level.addParticle(ParticleTypes.CAMPFIRE_COSY_SMOKE,
|
||||
// cannon.getX() + 8 * cannon.getLookAngle().x,
|
||||
// cannon.getEyeY() + 8 * cannon.getLookAngle().y,
|
||||
// cannon.getZ() + 8 * cannon.getLookAngle().z,
|
||||
// (2 + 0.5 * (Math.random() - 0.5)) * cannon.getLookAngle().x,
|
||||
// (2 + 0.5 * (Math.random() - 0.5)) * cannon.getLookAngle().y,
|
||||
// (2 + 0.5 * (Math.random() - 0.5)) * cannon.getLookAngle().z);
|
||||
// }
|
||||
|
||||
|
||||
// server.sendParticles(ParticleTypes.CAMPFIRE_COSY_SMOKE, (player.getX() + 3 * player.getLookAngle().x), (player.getY() + 0.1 + 3 * player.getLookAngle().y), (player.getZ() + 3 * player.getLookAngle().z), 40, 0.4, 0.4, 0.4,
|
||||
// 0.01);
|
||||
// server.sendParticles(ParticleTypes.CAMPFIRE_COSY_SMOKE, player.getX(), player.getY(), player.getZ(), 100, 2.5, 0.04, 2.5, 0.005);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package net.mcreator.target.mixins;
|
||||
|
||||
import net.mcreator.target.entity.Mk42Entity;
|
||||
import net.mcreator.target.init.TargetModMobEffects;
|
||||
import net.mcreator.target.init.TargetModTags;
|
||||
import net.mcreator.target.network.TargetModVariables;
|
||||
|
@ -36,6 +37,10 @@ public class MouseHandlerMixin {
|
|||
|
||||
ItemStack stack = mc.player.getMainHandItem();
|
||||
|
||||
if (player.getVehicle() != null && player.getVehicle() instanceof Mk42Entity) {
|
||||
return 0.23;
|
||||
}
|
||||
|
||||
if (!stack.is(TargetModTags.Items.GUN)) {
|
||||
return original;
|
||||
}
|
||||
|
|
|
@ -81,6 +81,7 @@ public class TargetModVariables {
|
|||
clone.recoil = original.recoil;
|
||||
clone.recoilHorizon = original.recoilHorizon;
|
||||
clone.firing = original.firing;
|
||||
clone.cannonFiring = original.cannonFiring;
|
||||
clone.targetAngle = original.targetAngle;
|
||||
clone.rifleAmmo = original.rifleAmmo;
|
||||
clone.refresh = original.refresh;
|
||||
|
@ -268,6 +269,7 @@ public class TargetModVariables {
|
|||
public double recoil = 0;
|
||||
public double recoilHorizon = 0;
|
||||
public double firing = 0;
|
||||
public double cannonFiring = 0;
|
||||
public double targetAngle = 0;
|
||||
public int rifleAmmo = 0;
|
||||
public boolean refresh = false;
|
||||
|
@ -290,6 +292,7 @@ public class TargetModVariables {
|
|||
nbt.putDouble("recoil", recoil);
|
||||
nbt.putDouble("recoil_horizon", recoilHorizon);
|
||||
nbt.putDouble("firing", firing);
|
||||
nbt.putDouble("cannonFiring", cannonFiring);
|
||||
nbt.putDouble("target_angle", targetAngle);
|
||||
nbt.putInt("rifle_ammo", rifleAmmo);
|
||||
nbt.putBoolean("refresh", refresh);
|
||||
|
@ -310,6 +313,7 @@ public class TargetModVariables {
|
|||
recoil = nbt.getDouble("recoil");
|
||||
recoilHorizon = nbt.getDouble("recoil_horizon");
|
||||
firing = nbt.getDouble("firing");
|
||||
cannonFiring = nbt.getDouble("cannonFiring");
|
||||
targetAngle = nbt.getDouble("target_angle");
|
||||
rifleAmmo = nbt.getInt("rifle_ammo");
|
||||
refresh = nbt.getBoolean("refresh");
|
||||
|
@ -366,6 +370,7 @@ public class TargetModVariables {
|
|||
variables.recoil = message.data.recoil;
|
||||
variables.recoilHorizon = message.data.recoilHorizon;
|
||||
variables.firing = message.data.firing;
|
||||
variables.cannonFiring = message.data.cannonFiring;
|
||||
variables.targetAngle = message.data.targetAngle;
|
||||
variables.rifleAmmo = message.data.rifleAmmo;
|
||||
variables.refresh = message.data.refresh;
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
package net.mcreator.target.network.message;
|
||||
|
||||
import net.mcreator.target.entity.*;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class VehicleFireMessage {
|
||||
private final int type;
|
||||
|
||||
public VehicleFireMessage(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public VehicleFireMessage(FriendlyByteBuf buffer) {
|
||||
this.type = buffer.readInt();
|
||||
}
|
||||
|
||||
public static void buffer(VehicleFireMessage message, FriendlyByteBuf buffer) {
|
||||
buffer.writeInt(message.type);
|
||||
}
|
||||
|
||||
public static void handler(VehicleFireMessage message, Supplier<NetworkEvent.Context> contextSupplier) {
|
||||
NetworkEvent.Context context = contextSupplier.get();
|
||||
context.enqueueWork(() -> {
|
||||
if (context.getSender() != null) {
|
||||
pressAction(context.getSender(), message.type);
|
||||
}
|
||||
});
|
||||
context.setPacketHandled(true);
|
||||
}
|
||||
|
||||
public static void pressAction(Player player, int type) {
|
||||
Level world = player.level();
|
||||
|
||||
if (!world.isLoaded(player.blockPosition())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.getVehicle() != null && player.getVehicle() instanceof Mk42Entity) {
|
||||
Entity cannon = player.getVehicle();
|
||||
cannon.getPersistentData().putBoolean("firing",true);
|
||||
if (type == 0) {
|
||||
cannon.getPersistentData().putBoolean("firing",true);
|
||||
} else if (type == 1) {
|
||||
cannon.getPersistentData().putBoolean("firing",false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -53,6 +53,7 @@ public class ParticleTool {
|
|||
sendParticle(serverLevel, ParticleTypes.FALLING_WATER, x, y + 3, z, 600, 1.5, 4, 1.5, 1, true);
|
||||
sendParticle(serverLevel, ParticleTypes.BUBBLE_COLUMN_UP, x, y, z, 1000, 3, 0.5, 3, 0.1, true);
|
||||
}
|
||||
sendParticle(serverLevel, ParticleTypes.EXPLOSION, x, y + 1, z, 100, 1, 1, 1, 1, true);
|
||||
sendParticle(serverLevel, ParticleTypes.CAMPFIRE_COSY_SMOKE, x, y, z, 80, 0.4, 1, 0.4, 0.02, true);
|
||||
sendParticle(serverLevel, ParticleTypes.LARGE_SMOKE, x, y + 1, z, 80, 0.4, 1, 0.4, 0.02, true);
|
||||
sendParticle(serverLevel, ParticleTypes.CAMPFIRE_COSY_SMOKE, x, y, z, 80, 2, 0.001, 2, 0.01, true);
|
||||
|
@ -60,4 +61,42 @@ public class ParticleTool {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
public static void spawnHugeExplosionParticles(Level level, Vec3 pos) {
|
||||
double x = pos.x;
|
||||
double y = pos.y;
|
||||
double z = pos.z;
|
||||
|
||||
if (!level.isClientSide()) {
|
||||
if ((level.getBlockState(BlockPos.containing(x, y, z))).getBlock() == Blocks.WATER) {
|
||||
level.playSound(null, BlockPos.containing(x, y + 1, z), TargetModSounds.EXPLOSION_WATER.get(), SoundSource.BLOCKS, 3, 1);
|
||||
}
|
||||
level.playSound(null, BlockPos.containing(x, y + 1, z), TargetModSounds.EXPLOSION_CLOSE.get(), SoundSource.BLOCKS, 8, 1);
|
||||
level.playSound(null, BlockPos.containing(x, y + 1, z), TargetModSounds.EXPLOSION_FAR.get(), SoundSource.BLOCKS, 16, 1);
|
||||
level.playSound(null, BlockPos.containing(x, y + 1, z), TargetModSounds.EXPLOSION_VERY_FAR.get(), SoundSource.BLOCKS, 32, 1);
|
||||
} else {
|
||||
if ((level.getBlockState(BlockPos.containing(x, y, z))).getBlock() == Blocks.WATER) {
|
||||
level.playLocalSound(x, (y + 1), z, TargetModSounds.EXPLOSION_WATER.get(), SoundSource.BLOCKS, 3, 1, false);
|
||||
}
|
||||
level.playLocalSound(x, (y + 1), z, TargetModSounds.EXPLOSION_CLOSE.get(), SoundSource.BLOCKS, 24, 1, false);
|
||||
level.playLocalSound(x, (y + 1), z, TargetModSounds.EXPLOSION_FAR.get(), SoundSource.BLOCKS, 24, 1, false);
|
||||
level.playLocalSound(x, (y + 1), z, TargetModSounds.EXPLOSION_VERY_FAR.get(), SoundSource.BLOCKS, 64, 1, false);
|
||||
}
|
||||
|
||||
if (level instanceof ServerLevel serverLevel) {
|
||||
if ((level.getBlockState(BlockPos.containing(x, y, z))).getBlock() == Blocks.WATER) {
|
||||
sendParticle(serverLevel, ParticleTypes.CLOUD, x, y + 3, z, 400, 2, 6, 2, 0.01, true);
|
||||
sendParticle(serverLevel, ParticleTypes.CLOUD, x, y + 3, z, 600, 4, 2, 4, 0.01, true);
|
||||
sendParticle(serverLevel, ParticleTypes.FALLING_WATER, x, y + 3, z, 2400, 3, 8, 3, 1, true);
|
||||
sendParticle(serverLevel, ParticleTypes.BUBBLE_COLUMN_UP, x, y, z, 2000, 6, 1, 6, 0.1, true);
|
||||
}
|
||||
sendParticle(serverLevel, ParticleTypes.EXPLOSION, x, y + 1, z, 500, 2.5, 2.5, 2.5, 1, true);
|
||||
sendParticle(serverLevel, ParticleTypes.FLASH, x, y + 1, z, 1000, 5, 5, 5, 20, true);
|
||||
sendParticle(serverLevel, TargetModParticleTypes.FIRE_STAR.get(), x, y + 1, z, 2000, 0, 0, 0, 1.5, true);
|
||||
sendParticle(serverLevel, ParticleTypes.CAMPFIRE_COSY_SMOKE, x, y + 1, z, 500, 2, 3, 2, 0.005, true);
|
||||
sendParticle(serverLevel, ParticleTypes.CAMPFIRE_COSY_SMOKE, x, y, z, 1000, 7, 0.1, 7, 0.005, true);
|
||||
sendParticle(serverLevel, ParticleTypes.CLOUD, x, y + 1, z, 1000, 3, 4, 3, 0.4, true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Add table
Reference in a new issue