添加命中提示
This commit is contained in:
parent
b274a0c39f
commit
ab66a937e0
2 changed files with 25 additions and 7 deletions
|
@ -1,8 +1,11 @@
|
||||||
package net.mcreator.target.entity;
|
package net.mcreator.target.entity;
|
||||||
|
|
||||||
|
import net.mcreator.target.TargetMod;
|
||||||
import net.mcreator.target.init.TargetModDamageTypes;
|
import net.mcreator.target.init.TargetModDamageTypes;
|
||||||
import net.mcreator.target.init.TargetModEntities;
|
import net.mcreator.target.init.TargetModEntities;
|
||||||
import net.mcreator.target.init.TargetModItems;
|
import net.mcreator.target.init.TargetModItems;
|
||||||
|
import net.mcreator.target.init.TargetModSounds;
|
||||||
|
import net.mcreator.target.network.message.ClientIndicatorMessage;
|
||||||
import net.mcreator.target.tools.CustomExplosion;
|
import net.mcreator.target.tools.CustomExplosion;
|
||||||
import net.mcreator.target.tools.ParticleTool;
|
import net.mcreator.target.tools.ParticleTool;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
|
@ -10,6 +13,8 @@ import net.minecraft.core.particles.ParticleTypes;
|
||||||
import net.minecraft.network.protocol.Packet;
|
import net.minecraft.network.protocol.Packet;
|
||||||
import net.minecraft.network.protocol.game.ClientGamePacketListener;
|
import net.minecraft.network.protocol.game.ClientGamePacketListener;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.minecraft.sounds.SoundSource;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.EntityType;
|
import net.minecraft.world.entity.EntityType;
|
||||||
import net.minecraft.world.entity.LivingEntity;
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
|
@ -20,6 +25,7 @@ import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.phys.BlockHitResult;
|
import net.minecraft.world.phys.BlockHitResult;
|
||||||
import net.minecraft.world.phys.EntityHitResult;
|
import net.minecraft.world.phys.EntityHitResult;
|
||||||
import net.minecraftforge.network.NetworkHooks;
|
import net.minecraftforge.network.NetworkHooks;
|
||||||
|
import net.minecraftforge.network.PacketDistributor;
|
||||||
import net.minecraftforge.network.PlayMessages;
|
import net.minecraftforge.network.PlayMessages;
|
||||||
|
|
||||||
public class CannonShellEntity extends ThrowableItemProjectile {
|
public class CannonShellEntity extends ThrowableItemProjectile {
|
||||||
|
@ -68,8 +74,16 @@ public class CannonShellEntity extends ThrowableItemProjectile {
|
||||||
@Override
|
@Override
|
||||||
public void onHitEntity(EntityHitResult entityHitResult) {
|
public void onHitEntity(EntityHitResult entityHitResult) {
|
||||||
Entity entity = entityHitResult.getEntity();
|
Entity entity = entityHitResult.getEntity();
|
||||||
|
|
||||||
entity.hurt(this.level().damageSources().thrown(this, this.getOwner()), this.damage);
|
entity.hurt(this.level().damageSources().thrown(this, this.getOwner()), this.damage);
|
||||||
|
entity.invulnerableTime = 0;
|
||||||
|
|
||||||
|
if (this.getOwner() instanceof LivingEntity living) {
|
||||||
|
if (!living.level().isClientSide() && living instanceof ServerPlayer player) {
|
||||||
|
living.level().playSound(null, living.blockPosition(), TargetModSounds.INDICATION.get(), SoundSource.VOICE, 1, 1);
|
||||||
|
|
||||||
|
TargetMod.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> player), new ClientIndicatorMessage(0, 5));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (this.level() instanceof ServerLevel) {
|
if (this.level() instanceof ServerLevel) {
|
||||||
causeExplode();
|
causeExplode();
|
||||||
|
|
|
@ -240,6 +240,15 @@ public class Mk42Entity extends PathfinderMob implements GeoEntity {
|
||||||
cannonShoot(player);
|
cannonShoot(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.getPersistentData().getBoolean("shot")) {
|
||||||
|
gunner.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||||
|
capability.recoilHorizon = 2 * Math.random() - 1;
|
||||||
|
capability.cannonFiring = 1;
|
||||||
|
capability.syncPlayerVariables(gunner);
|
||||||
|
});
|
||||||
|
this.getPersistentData().putBoolean("shot", false);
|
||||||
|
}
|
||||||
|
|
||||||
this.refreshDimensions();
|
this.refreshDimensions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -280,12 +289,7 @@ public class Mk42Entity extends PathfinderMob implements GeoEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.getPersistentData().putInt("fire_cooldown", 30);
|
this.getPersistentData().putInt("fire_cooldown", 30);
|
||||||
|
this.getPersistentData().putBoolean("shot", true);
|
||||||
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,
|
server.sendParticles(ParticleTypes.CAMPFIRE_COSY_SMOKE,
|
||||||
this.getX() + 5 * this.getLookAngle().x,
|
this.getX() + 5 * this.getLookAngle().x,
|
||||||
|
|
Loading…
Add table
Reference in a new issue