添加无人机的UI
This commit is contained in:
parent
1c57d5c051
commit
7dde921f67
10 changed files with 2944 additions and 198 deletions
|
@ -0,0 +1,67 @@
|
|||
package net.mcreator.target.client.screens;
|
||||
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.mcreator.target.entity.DroneEntity;
|
||||
import net.mcreator.target.init.TargetModItems;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.RenderGuiEvent;
|
||||
import net.minecraftforge.eventbus.api.EventPriority;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
import static net.mcreator.target.entity.DroneEntity.AMMO;
|
||||
|
||||
@Mod.EventBusSubscriber(value = Dist.CLIENT)
|
||||
public class DroneUIOverlay {
|
||||
|
||||
private static int color = -1;
|
||||
@SubscribeEvent(priority = EventPriority.NORMAL)
|
||||
public static void eventHandler(RenderGuiEvent.Pre event) {
|
||||
int w = event.getWindow().getGuiScaledWidth();
|
||||
int h = event.getWindow().getGuiScaledHeight();
|
||||
Player player = Minecraft.getInstance().player;
|
||||
if (player != null) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
RenderSystem.disableDepthTest();
|
||||
RenderSystem.depthMask(false);
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
||||
RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
|
||||
RenderSystem.setShaderColor(1, 1, 1, 1);
|
||||
if (stack.is(TargetModItems.MONITOR.get()) && stack.getOrCreateTag().getBoolean("Using") && stack.getOrCreateTag().getBoolean("Linked")) {
|
||||
event.getGuiGraphics().blit(new ResourceLocation("target:textures/screens/drone.png"), w / 2 - 16, h / 2 - 16, 0, 0, 32, 32, 32, 32);
|
||||
|
||||
DroneEntity entity = player.level().getEntitiesOfClass(DroneEntity.class, player.getBoundingBox().inflate(512))
|
||||
.stream().filter(e -> e.getStringUUID().equals(stack.getOrCreateTag().getString("LinkedDrone"))).findFirst().orElse(null);
|
||||
|
||||
if (entity != null) {
|
||||
double distance = player.distanceTo(entity);
|
||||
if (distance > 450) {
|
||||
event.getGuiGraphics().drawString(Minecraft.getInstance().font,"WARNING", w / 2 + -18, h / 2 + -47, -65536, false);
|
||||
color = -65536;
|
||||
} else {
|
||||
color = -1;
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
RenderSystem.depthMask(true);
|
||||
RenderSystem.defaultBlendFunc();
|
||||
RenderSystem.enableDepthTest();
|
||||
RenderSystem.disableBlend();
|
||||
RenderSystem.setShaderColor(1, 1, 1, 1);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -199,7 +199,7 @@ public class DroneEntity extends PathfinderMob implements GeoEntity {
|
|||
|| this.getPersistentData().getBoolean("up")
|
||||
|| this.getPersistentData().getBoolean("down");
|
||||
|
||||
if (this.move || !this.onGround()) {
|
||||
if (!this.onGround()) {
|
||||
this.level().playSound(null, this.getOnPos(), TargetModSounds.DRONE_SOUND.get(), SoundSource.AMBIENT, 3, 1);
|
||||
if (control != null) {
|
||||
ItemStack stack = control.getMainHandItem();
|
||||
|
@ -283,13 +283,16 @@ public class DroneEntity extends PathfinderMob implements GeoEntity {
|
|||
}
|
||||
}
|
||||
} else if (stack.isEmpty() && player.isCrouching()) {
|
||||
if (!this.level().isClientSide()) this.discard();
|
||||
ItemHandlerHelper.giveItemToPlayer(player, new ItemStack(TargetModItems.DRONE_SPAWN_EGG.get()));
|
||||
for (int index0 = 0; index0 < this.entityData.get(AMMO); index0++) {
|
||||
ItemHandlerHelper.giveItemToPlayer(player, new ItemStack(TargetModItems.GRENADE_40MM.get()));
|
||||
}
|
||||
if (!this.level().isClientSide()) this.discard();
|
||||
} else if (stack.getItem() == TargetModItems.GRENADE_40MM.get()) {
|
||||
if (!player.isCreative()) {
|
||||
stack.shrink(1);
|
||||
}
|
||||
if (this.entityData.get(AMMO) < 4) {
|
||||
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) {
|
||||
|
@ -311,7 +314,7 @@ public class DroneEntity extends PathfinderMob implements GeoEntity {
|
|||
if (stack.getOrCreateTag().getBoolean("Using")) {
|
||||
this.setYRot(control.getYRot() + 180);
|
||||
this.yRotO = this.getYRot();
|
||||
this.setXRot(Mth.clamp(control.getXRot(), -25, 95));
|
||||
this.setXRot(Mth.clamp(control.getXRot(), -25, 90));
|
||||
this.setRot(this.getYRot(), this.getXRot());
|
||||
this.yBodyRot = control.getYRot() + 180;
|
||||
this.yHeadRot = control.getYRot() + 180;
|
||||
|
@ -357,6 +360,10 @@ public class DroneEntity extends PathfinderMob implements GeoEntity {
|
|||
}
|
||||
});
|
||||
}
|
||||
if (level() instanceof ServerLevel) {
|
||||
level().explode(null, this.getX(), this.getY(), this.getZ(), 0, Level.ExplosionInteraction.NONE);
|
||||
}
|
||||
this.discard();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -396,7 +403,7 @@ public class DroneEntity extends PathfinderMob implements GeoEntity {
|
|||
|
||||
private PlayState movementPredicate(AnimationState event) {
|
||||
if (this.animationprocedure.equals("empty")) {
|
||||
if (this.entityData.get(LINKED) || !this.onGround()) {
|
||||
if (!this.onGround()) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.drone.fly"));
|
||||
}
|
||||
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.drone.idle"));
|
||||
|
@ -417,18 +424,6 @@ public class DroneEntity extends PathfinderMob implements GeoEntity {
|
|||
return PlayState.CONTINUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tickDeath() {
|
||||
++this.deathTime;
|
||||
if (this.deathTime >= 100 || this.onGround()) {
|
||||
this.remove(DroneEntity.RemovalReason.KILLED);
|
||||
if (level() instanceof ServerLevel) {
|
||||
level().explode(null, this.getX(), this.getY(), this.getZ(), 0.1F, Level.ExplosionInteraction.NONE);
|
||||
}
|
||||
}
|
||||
this.setDeltaMovement(new Vec3(this.getDeltaMovement().x(), this.getDeltaMovement().y() - 0.02, this.getDeltaMovement().z()));
|
||||
}
|
||||
|
||||
public String getSyncedAnimation() {
|
||||
return this.entityData.get(ANIMATION);
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ public class DroneGrenadeEntity extends ThrowableItemProjectile {
|
|||
if (entity instanceof LivingEntity) {
|
||||
entity.invulnerableTime = 0;
|
||||
}
|
||||
entity.hurt(TargetModDamageTypes.causeGunFireHeadshotDamage(this.level().registryAccess(), this, this.getOwner()), 50);
|
||||
entity.hurt(TargetModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), this, this.getOwner()), 5);
|
||||
if (this.level() instanceof ServerLevel) {
|
||||
causeExplode();
|
||||
this.discard();
|
||||
|
@ -102,8 +102,8 @@ public class DroneGrenadeEntity extends ThrowableItemProjectile {
|
|||
|
||||
private void causeExplode() {
|
||||
CustomExplosion explosion = new CustomExplosion(this.level(), this,
|
||||
TargetModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), this, this.getOwner()), 90,
|
||||
this.getX(), this.getY(), this.getZ(), 7.5f, Explosion.BlockInteraction.KEEP).setDamageMultiplier(1);
|
||||
TargetModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), this, this.getOwner()), 60,
|
||||
this.getX(), this.getY(), this.getZ(), 5f, Explosion.BlockInteraction.KEEP).setDamageMultiplier(1);
|
||||
explosion.explode();
|
||||
net.minecraftforge.event.ForgeEventFactory.onExplosionStart(this.level(), explosion);
|
||||
explosion.finalizeExplosion(false);
|
||||
|
@ -112,6 +112,6 @@ public class DroneGrenadeEntity extends ThrowableItemProjectile {
|
|||
|
||||
@Override
|
||||
protected float getGravity() {
|
||||
return 0.08F;
|
||||
return 0.07F;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,18 @@
|
|||
package net.mcreator.target.entity.model;
|
||||
|
||||
import net.mcreator.target.entity.MortarEntity;
|
||||
import net.minecraft.util.Mth;
|
||||
import software.bernie.geckolib.constant.DataTickets;
|
||||
import software.bernie.geckolib.core.animatable.model.CoreGeoBone;
|
||||
import software.bernie.geckolib.core.animation.AnimationState;
|
||||
import software.bernie.geckolib.model.GeoModel;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
import net.mcreator.target.entity.DroneEntity;
|
||||
import software.bernie.geckolib.model.data.EntityModelData;
|
||||
|
||||
import static net.mcreator.target.entity.DroneEntity.AMMO;
|
||||
|
||||
public class DroneModel extends GeoModel<DroneEntity> {
|
||||
@Override
|
||||
|
@ -22,4 +30,20 @@ public class DroneModel extends GeoModel<DroneEntity> {
|
|||
return new ResourceLocation("target", "textures/entity/drone.png");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCustomAnimations(DroneEntity animatable, long instanceId, AnimationState animationState) {
|
||||
CoreGeoBone ammo1 = getAnimationProcessor().getBone("ammo1");
|
||||
CoreGeoBone ammo2 = getAnimationProcessor().getBone("ammo2");
|
||||
CoreGeoBone ammo3 = getAnimationProcessor().getBone("ammo3");
|
||||
CoreGeoBone ammo4 = getAnimationProcessor().getBone("ammo4");
|
||||
CoreGeoBone ammo5 = getAnimationProcessor().getBone("ammo5");
|
||||
CoreGeoBone ammo6 = getAnimationProcessor().getBone("ammo6");
|
||||
|
||||
ammo6.setHidden(animatable.getEntityData().get(AMMO) <= 5);
|
||||
ammo5.setHidden(animatable.getEntityData().get(AMMO) <= 4);
|
||||
ammo4.setHidden(animatable.getEntityData().get(AMMO) <= 3);
|
||||
ammo3.setHidden(animatable.getEntityData().get(AMMO) <= 2);
|
||||
ammo2.setHidden(animatable.getEntityData().get(AMMO) <= 1);
|
||||
ammo1.setHidden(animatable.getEntityData().get(AMMO) <= 0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -456,6 +456,11 @@ public class ClientEventHandler {
|
|||
if (mc.player.getMainHandItem().is(TargetModTags.Items.GUN) || (mc.player.getVehicle() != null && mc.player.getVehicle() instanceof Mk42Entity)) {
|
||||
event.setCanceled(true);
|
||||
}
|
||||
|
||||
ItemStack stack = mc.player.getMainHandItem();
|
||||
if (stack.is(TargetModItems.MONITOR.get()) && stack.getOrCreateTag().getBoolean("Using") && stack.getOrCreateTag().getBoolean("Linked")) {
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -42,16 +42,7 @@ public class Monitor extends Item {
|
|||
return super.use(world, player, hand);
|
||||
}
|
||||
|
||||
if (world.isClientSide) {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
if (!stack.getOrCreateTag().getBoolean("Using")) {
|
||||
mc.options.setCameraType(CameraType.THIRD_PERSON_BACK);
|
||||
} else {
|
||||
mc.options.setCameraType(CameraType.FIRST_PERSON);
|
||||
}
|
||||
} else {
|
||||
stack.getOrCreateTag().putBoolean("Using", !stack.getOrCreateTag().getBoolean("Using"));
|
||||
}
|
||||
|
||||
DroneEntity drone = player.level().getEntitiesOfClass(DroneEntity.class, player.getBoundingBox().inflate(512))
|
||||
.stream().filter(e -> e.getStringUUID().equals(stack.getOrCreateTag().getString("LinkedDrone"))).findFirst().orElse(null);
|
||||
|
|
|
@ -40,7 +40,7 @@ public abstract class CameraMixin {
|
|||
|
||||
if (drone != null) {
|
||||
setRotation(drone.getViewYRot(partialTicks), drone.getViewXRot(partialTicks));
|
||||
setPosition(Mth.lerp(partialTicks, drone.xo, drone.getX()) + 0.18 * drone.getLookAngle().x, Mth.lerp(partialTicks, drone.yo, drone.getY()) + 0.075, Mth.lerp(partialTicks, drone.zo, drone.getZ()) + 0.18 * drone.getLookAngle().z);
|
||||
setPosition(Mth.lerp(partialTicks, drone.xo, drone.getX()) + 0.3 * drone.getLookAngle().x, Mth.lerp(partialTicks, drone.yo, drone.getY()) + 0.08, Mth.lerp(partialTicks, drone.zo, drone.getZ()) + 0.3 * drone.getLookAngle().z);
|
||||
info.cancel();
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
Binary file not shown.
Before Width: | Height: | Size: 4.1 KiB After Width: | Height: | Size: 4.6 KiB |
BIN
src/main/resources/assets/target/textures/screens/drone.png
Normal file
BIN
src/main/resources/assets/target/textures/screens/drone.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 287 B |
Loading…
Add table
Reference in a new issue