添加无人机的自爆功能
This commit is contained in:
parent
1c90597c5c
commit
c94a39ea61
7 changed files with 1840 additions and 1433 deletions
|
@ -18,6 +18,7 @@ import net.minecraftforge.fml.common.Mod;
|
|||
import java.text.DecimalFormat;
|
||||
|
||||
import static net.mcreator.superbwarfare.entity.DroneEntity.AMMO;
|
||||
import static net.mcreator.superbwarfare.entity.DroneEntity.KAMIKAZE;
|
||||
|
||||
@Mod.EventBusSubscriber(value = Dist.CLIENT)
|
||||
public class DroneUIOverlay {
|
||||
|
@ -54,8 +55,11 @@ public class DroneUIOverlay {
|
|||
|
||||
event.getGuiGraphics().drawString(Minecraft.getInstance().font, "Distance:" + new DecimalFormat("##.#").format(distance) + "M", w / 2 + 10, h / 2 + 33, color, false);
|
||||
event.getGuiGraphics().drawString(Minecraft.getInstance().font, "Health:" + new DecimalFormat("##.#").format(entity.getHealth()) + "/" + new DecimalFormat("##").format(entity.getMaxHealth()), w / 2 - 77, h / 2 + 33, -1, false);
|
||||
event.getGuiGraphics().drawString(Minecraft.getInstance().font, "AMMO:" + new DecimalFormat("##.#").format(entity.getEntityData().get(AMMO)) + " / 6", w / 2 + 12, h / 2 + -37, -1, false);
|
||||
|
||||
if (!entity.getEntityData().get(KAMIKAZE)) {
|
||||
event.getGuiGraphics().drawString(Minecraft.getInstance().font, "AMMO:" + new DecimalFormat("##.#").format(entity.getEntityData().get(AMMO)) + " / 6", w / 2 + 12, h / 2 + -37, -1, false);
|
||||
} else {
|
||||
event.getGuiGraphics().drawString(Minecraft.getInstance().font, "KAMIKAZE", w / 2 + 12, h / 2 + -37, -65536, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
RenderSystem.depthMask(true);
|
||||
|
|
|
@ -1,13 +1,17 @@
|
|||
package net.mcreator.superbwarfare.entity;
|
||||
|
||||
import net.mcreator.superbwarfare.init.ModDamageTypes;
|
||||
import net.mcreator.superbwarfare.init.ModEntities;
|
||||
import net.mcreator.superbwarfare.init.ModItems;
|
||||
import net.mcreator.superbwarfare.init.ModSounds;
|
||||
import net.mcreator.superbwarfare.item.Monitor;
|
||||
import net.mcreator.superbwarfare.tools.CustomExplosion;
|
||||
import net.mcreator.superbwarfare.tools.ParticleTool;
|
||||
import net.mcreator.superbwarfare.tools.SoundTool;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
|
@ -23,6 +27,7 @@ import net.minecraft.util.Mth;
|
|||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.damagesource.DamageTypes;
|
||||
import net.minecraft.world.entity.*;
|
||||
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
|
||||
import net.minecraft.world.entity.ai.attributes.Attributes;
|
||||
|
@ -31,6 +36,7 @@ import net.minecraft.world.entity.ai.navigation.PathNavigation;
|
|||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.world.level.Explosion;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
@ -64,6 +70,7 @@ public class DroneEntity extends PathfinderMob implements GeoEntity {
|
|||
public static final EntityDataAccessor<Boolean> LINKED = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.BOOLEAN);
|
||||
public static final EntityDataAccessor<String> CONTROLLER = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.STRING);
|
||||
public static final EntityDataAccessor<Integer> AMMO = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.INT);
|
||||
public static final EntityDataAccessor<Boolean> KAMIKAZE = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.BOOLEAN);
|
||||
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
||||
private float moveX = 0;
|
||||
private float moveY = 0;
|
||||
|
@ -97,6 +104,7 @@ public class DroneEntity extends PathfinderMob implements GeoEntity {
|
|||
this.entityData.define(CONTROLLER, "undefined");
|
||||
this.entityData.define(LINKED, false);
|
||||
this.entityData.define(AMMO, 0);
|
||||
this.entityData.define(KAMIKAZE, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -136,6 +144,7 @@ public class DroneEntity extends PathfinderMob implements GeoEntity {
|
|||
compound.putBoolean("Linked", this.entityData.get(LINKED));
|
||||
compound.putString("Controller", this.entityData.get(CONTROLLER));
|
||||
compound.putInt("ammo", this.entityData.get(AMMO));
|
||||
compound.putBoolean("Kamikaze", this.entityData.get(KAMIKAZE));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -148,6 +157,8 @@ public class DroneEntity extends PathfinderMob implements GeoEntity {
|
|||
this.entityData.set(CONTROLLER, compound.getString("Controller"));
|
||||
if (compound.contains("ammo"))
|
||||
this.entityData.set(AMMO, compound.getInt("ammo"));
|
||||
if (compound.contains("Kamikaze"))
|
||||
this.entityData.set(KAMIKAZE, compound.getBoolean("Kamikaze"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -232,6 +243,9 @@ public class DroneEntity extends PathfinderMob implements GeoEntity {
|
|||
this.entityData.set(AMMO,this.entityData.get(AMMO) - 1);
|
||||
droneDrop(player);
|
||||
}
|
||||
if (this.entityData.get(KAMIKAZE)) {
|
||||
kamikazeExplosion(player);
|
||||
}
|
||||
}
|
||||
this.getPersistentData().putBoolean("firing", false);
|
||||
}
|
||||
|
@ -249,6 +263,17 @@ public class DroneEntity extends PathfinderMob implements GeoEntity {
|
|||
}
|
||||
}
|
||||
|
||||
private void kamikazeExplosion(Player player) {
|
||||
CustomExplosion explosion = new CustomExplosion(this.level(), this,
|
||||
ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), player, player), 150,
|
||||
this.getX(), this.getY(), this.getZ(), 12.5f, Explosion.BlockInteraction.KEEP).setDamageMultiplier(1);
|
||||
explosion.explode();
|
||||
net.minecraftforge.event.ForgeEventFactory.onExplosionStart(this.level(), explosion);
|
||||
explosion.finalizeExplosion(false);
|
||||
ParticleTool.spawnMediumExplosionParticles(this.level(), this.position());
|
||||
this.hurt(new DamageSource(level().registryAccess().registryOrThrow(Registries.DAMAGE_TYPE).getHolderOrThrow(DamageTypes.EXPLOSION)), 10000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionResult mobInteract(Player player, InteractionHand hand) {
|
||||
super.mobInteract(player, hand);
|
||||
|
@ -298,17 +323,24 @@ public class DroneEntity extends PathfinderMob implements GeoEntity {
|
|||
ItemHandlerHelper.giveItemToPlayer(player, new ItemStack(ModItems.GRENADE_40MM.get()));
|
||||
}
|
||||
if (!this.level().isClientSide()) this.discard();
|
||||
} else if (stack.getItem() == ModItems.GRENADE_40MM.get()) {
|
||||
} else if (stack.getItem() == ModItems.GRENADE_40MM.get() && !this.entityData.get(KAMIKAZE)) {
|
||||
if (!player.isCreative()) {
|
||||
stack.shrink(1);
|
||||
}
|
||||
if (this.entityData.get(AMMO) < 6) {
|
||||
this.entityData.set(AMMO,this.entityData.get(AMMO) + 1);
|
||||
player.displayClientMessage(Component.literal("AMMO:" + this.entityData.get(AMMO)), true);
|
||||
if (player instanceof ServerPlayer serverPlayer) {
|
||||
serverPlayer.level().playSound(null, serverPlayer.getOnPos(), ModSounds.BULLET_SUPPLY.get(), SoundSource.PLAYERS, 0.5F, 1);
|
||||
}
|
||||
}
|
||||
} else if (stack.getItem() == ModItems.MORTAR_SHELLS.get() && this.entityData.get(AMMO) == 0 && !this.entityData.get(KAMIKAZE)) {
|
||||
if (!player.isCreative()) {
|
||||
stack.shrink(1);
|
||||
}
|
||||
this.entityData.set(KAMIKAZE,true);
|
||||
if (player instanceof ServerPlayer serverPlayer) {
|
||||
serverPlayer.level().playSound(null, serverPlayer.getOnPos(), ModSounds.BULLET_SUPPLY.get(), SoundSource.PLAYERS, 0.5F, 1);
|
||||
}
|
||||
}
|
||||
|
||||
return InteractionResult.sidedSuccess(this.level().isClientSide());
|
||||
|
@ -322,12 +354,12 @@ public class DroneEntity extends PathfinderMob implements GeoEntity {
|
|||
if (control != null) {
|
||||
ItemStack stack = control.getMainHandItem();
|
||||
if (stack.getOrCreateTag().getBoolean("Using")) {
|
||||
this.setYRot(control.getYRot() + 180);
|
||||
this.setYRot(control.getYRot());
|
||||
this.yRotO = this.getYRot();
|
||||
this.setXRot(Mth.clamp(control.getXRot(), -25, 90));
|
||||
this.setRot(this.getYRot(), this.getXRot());
|
||||
this.yBodyRot = control.getYRot() + 180;
|
||||
this.yHeadRot = control.getYRot() + 180;
|
||||
this.yBodyRot = control.getYRot();
|
||||
this.yHeadRot = control.getYRot();
|
||||
this.setMaxUpStep(1.0F);
|
||||
this.setSpeed(4 * (float) this.getAttributeValue(Attributes.MOVEMENT_SPEED));
|
||||
float forward = -moveZ;
|
||||
|
@ -369,11 +401,40 @@ public class DroneEntity extends PathfinderMob implements GeoEntity {
|
|||
Monitor.disLink(stack);
|
||||
}
|
||||
});
|
||||
if (this.entityData.get(KAMIKAZE)){
|
||||
destroyExplosion(player);
|
||||
}
|
||||
} else {
|
||||
if (this.entityData.get(KAMIKAZE)){
|
||||
destroyExplosion2();
|
||||
}
|
||||
}
|
||||
|
||||
if (level() instanceof ServerLevel) {
|
||||
level().explode(null, this.getX(), this.getY(), this.getZ(), 0, Level.ExplosionInteraction.NONE);
|
||||
}
|
||||
this.discard();
|
||||
|
||||
}
|
||||
|
||||
private void destroyExplosion(Player player) {
|
||||
CustomExplosion explosion = new CustomExplosion(this.level(), this,
|
||||
ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), player, player), 40,
|
||||
this.getX(), this.getY(), this.getZ(), 10f, Explosion.BlockInteraction.KEEP).setDamageMultiplier(1);
|
||||
explosion.explode();
|
||||
net.minecraftforge.event.ForgeEventFactory.onExplosionStart(this.level(), explosion);
|
||||
explosion.finalizeExplosion(false);
|
||||
ParticleTool.spawnMediumExplosionParticles(this.level(), this.position());
|
||||
}
|
||||
|
||||
private void destroyExplosion2() {
|
||||
CustomExplosion explosion = new CustomExplosion(this.level(), this,
|
||||
ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), this, this), 40,
|
||||
this.getX(), this.getY(), this.getZ(), 10f, Explosion.BlockInteraction.KEEP).setDamageMultiplier(1);
|
||||
explosion.explode();
|
||||
net.minecraftforge.event.ForgeEventFactory.onExplosionStart(this.level(), explosion);
|
||||
explosion.finalizeExplosion(false);
|
||||
ParticleTool.spawnMediumExplosionParticles(this.level(), this.position());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -10,6 +10,7 @@ import net.minecraft.resources.ResourceLocation;
|
|||
import net.mcreator.superbwarfare.entity.DroneEntity;
|
||||
|
||||
import static net.mcreator.superbwarfare.entity.DroneEntity.AMMO;
|
||||
import static net.mcreator.superbwarfare.entity.DroneEntity.KAMIKAZE;
|
||||
|
||||
public class DroneModel extends GeoModel<DroneEntity> {
|
||||
@Override
|
||||
|
@ -35,6 +36,7 @@ public class DroneModel extends GeoModel<DroneEntity> {
|
|||
CoreGeoBone ammo4 = getAnimationProcessor().getBone("ammo4");
|
||||
CoreGeoBone ammo5 = getAnimationProcessor().getBone("ammo5");
|
||||
CoreGeoBone ammo6 = getAnimationProcessor().getBone("ammo6");
|
||||
CoreGeoBone shell = getAnimationProcessor().getBone("shell");
|
||||
|
||||
ammo6.setHidden(animatable.getEntityData().get(AMMO) <= 5);
|
||||
ammo5.setHidden(animatable.getEntityData().get(AMMO) <= 4);
|
||||
|
@ -42,5 +44,6 @@ public class DroneModel extends GeoModel<DroneEntity> {
|
|||
ammo3.setHidden(animatable.getEntityData().get(AMMO) <= 2);
|
||||
ammo2.setHidden(animatable.getEntityData().get(AMMO) <= 1);
|
||||
ammo1.setHidden(animatable.getEntityData().get(AMMO) <= 0);
|
||||
shell.setHidden(!animatable.getEntityData().get(KAMIKAZE));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ public class ModEntities {
|
|||
EntityType.Builder.<Mk42Entity>of(Mk42Entity::new, MobCategory.CREATURE).setShouldReceiveVelocityUpdates(true).setTrackingRange(64).setUpdateInterval(3).setCustomClientFactory(Mk42Entity::new).fireImmune().sized(5.4f, 3.5f));
|
||||
|
||||
public static final RegistryObject<EntityType<DroneEntity>> DRONE = register("drone",
|
||||
EntityType.Builder.<DroneEntity>of(DroneEntity::new, MobCategory.CREATURE).setShouldReceiveVelocityUpdates(true).setTrackingRange(64).setUpdateInterval(3).setCustomClientFactory(DroneEntity::new).sized(0.4f, 0.175f));
|
||||
EntityType.Builder.<DroneEntity>of(DroneEntity::new, MobCategory.CREATURE).setShouldReceiveVelocityUpdates(true).setTrackingRange(64).setUpdateInterval(3).setCustomClientFactory(DroneEntity::new).sized(0.7f, 0.175f));
|
||||
|
||||
public static final RegistryObject<EntityType<TaserBulletProjectileEntity>> TASER_BULLET_PROJECTILE = register("projectile_taser_bullet_projectile",
|
||||
EntityType.Builder.<TaserBulletProjectileEntity>of(TaserBulletProjectileEntity::new, MobCategory.MISC).setCustomClientFactory(TaserBulletProjectileEntity::new).setShouldReceiveVelocityUpdates(true).setTrackingRange(64)
|
||||
|
|
|
@ -69,7 +69,7 @@ public class Monitor extends Item {
|
|||
if (equipmentSlot == EquipmentSlot.MAINHAND) {
|
||||
ImmutableMultimap.Builder<Attribute, AttributeModifier> builder = ImmutableMultimap.builder();
|
||||
builder.putAll(super.getDefaultAttributeModifiers(equipmentSlot));
|
||||
builder.put(Attributes.ATTACK_DAMAGE, new AttributeModifier(BASE_ATTACK_DAMAGE_UUID, "Item modifier", 4d, AttributeModifier.Operation.ADDITION));
|
||||
builder.put(Attributes.ATTACK_DAMAGE, new AttributeModifier(BASE_ATTACK_DAMAGE_UUID, "Item modifier", 2d, AttributeModifier.Operation.ADDITION));
|
||||
builder.put(Attributes.ATTACK_SPEED, new AttributeModifier(BASE_ATTACK_SPEED_UUID, "Item modifier", -2.4, AttributeModifier.Operation.ADDITION));
|
||||
return builder.build();
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
Binary file not shown.
Before Width: | Height: | Size: 4.6 KiB After Width: | Height: | Size: 8.7 KiB |
Loading…
Add table
Reference in a new issue