Forgot over stuff.
This commit is contained in:
parent
c5e78e3185
commit
25ebb8b0e6
4 changed files with 139 additions and 79 deletions
|
@ -13,25 +13,22 @@ public class MonolithModel extends EntityModel<MonolithEntity> {
|
|||
private final ModelPart body;
|
||||
|
||||
public MonolithModel() {
|
||||
super();
|
||||
textureWidth = 256;
|
||||
textureHeight = 256;
|
||||
|
||||
body = new ModelPart(this, 0, 0);
|
||||
body.addCuboid(-24F, -108F / 1.3F, -6F, 48, 108, 12);
|
||||
body = new ModelPart(this);
|
||||
body.setPivot(0.0F, 24.0F, 0.0F);
|
||||
body.setTextureOffset(0, 0).addCuboid(-24.0F, -54.0F, -6.0F, 48.0F, 108.0F, 12.0F, 0.0F, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAngles(MonolithEntity entity, float f, float g, float h, float i, float j) {
|
||||
|
||||
public void render(MatrixStack matrixStack, VertexConsumer buffer, int packedLight, int packedOverlay, float red, float green, float blue, float alpha){
|
||||
body.render(matrixStack, buffer, packedLight, packedOverlay);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void animateModel(MonolithEntity entity, float f, float g, float h) {
|
||||
public void setAngles(MonolithEntity entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch){
|
||||
body.yaw = netHeadYaw * 0.017453292F;
|
||||
body.pitch = headPitch * 0.017453292F;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(MatrixStack matrixStack, VertexConsumer vertexConsumer, int i, int j, float f, float g, float h, float k) {
|
||||
this.body.render(matrixStack, vertexConsumer, i, j, f, g, h, k);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,15 +1,11 @@
|
|||
package org.dimdev.dimdoors.entity;
|
||||
|
||||
import com.flowpowered.math.vector.Vector3f;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.MovementType;
|
||||
import net.minecraft.entity.*;
|
||||
import net.minecraft.entity.ai.control.LookControl;
|
||||
import net.minecraft.entity.damage.DamageSource;
|
||||
import net.minecraft.entity.data.DataTracker;
|
||||
import net.minecraft.entity.data.TrackedData;
|
||||
import net.minecraft.entity.data.TrackedDataHandlerRegistry;
|
||||
import net.minecraft.entity.decoration.ArmorStandEntity;
|
||||
import net.minecraft.entity.mob.MobEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
@ -20,22 +16,22 @@ import net.minecraft.util.math.Box;
|
|||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
import org.dimdev.dimdoors.ModConfig;
|
||||
import org.dimdev.dimdoors.entity.ai.MonolithTask;
|
||||
import org.dimdev.dimdoors.sound.ModSoundEvents;
|
||||
import org.dimdev.dimdoors.world.limbo.LimboDimension;
|
||||
import org.dimdev.dimdoors.world.pocketdimension.DungeonPocketDimension;
|
||||
import org.dimdev.util.Location;
|
||||
import org.dimdev.util.TeleportUtil;
|
||||
|
||||
import static net.minecraft.entity.attribute.EntityAttributes.MAX_HEALTH;
|
||||
|
||||
public class MonolithEntity extends MobEntity {
|
||||
private static final int MAX_AGGRO = 250;
|
||||
public final EntityDimensions DIMENSIONS = EntityDimensions.fixed(3f, 3f);
|
||||
|
||||
public static final int MAX_AGGRO = 250;
|
||||
private static final int MAX_AGGRO_CAP = 100;
|
||||
private static final int MIN_AGGRO_CAP = 25;
|
||||
private static final int MAX_TEXTURE_STATE = 18;
|
||||
private static final int MAX_SOUND_COOLDOWN = 200;
|
||||
private static final int MAX_AGGRO_RANGE = 35;
|
||||
public static final int MAX_AGGRO_RANGE = 35;
|
||||
private static final TrackedData<Integer> AGGRO = DataTracker.registerData(MonolithEntity.class, TrackedDataHandlerRegistry.INTEGER);
|
||||
private static final float EYE_HEIGHT = 1.5f;
|
||||
|
||||
|
@ -49,10 +45,23 @@ public class MonolithEntity extends MobEntity {
|
|||
noClip = true;
|
||||
aggroCap = MathHelper.nextInt(getRandom(), MIN_AGGRO_CAP, MAX_AGGRO_CAP);
|
||||
setNoGravity(true);
|
||||
lookControl = new LookControl(this) {
|
||||
@Override
|
||||
protected boolean shouldStayHorizontal() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
setInvulnerable(true);
|
||||
}
|
||||
|
||||
public EntityDimensions getDimensions(EntityPose entityPose) {
|
||||
return DIMENSIONS;
|
||||
}
|
||||
|
||||
|
||||
public boolean isDangerous() {
|
||||
return false; //return ModConfig.MONOLITHS.monolithTeleportation && (world.dimension instanceof LimboDimension || ModConfig.MONOLITHS.dangerousLimboMonoliths);
|
||||
return true; //return ModConfig.MONOLITHS.monolithTeleportation && (world.dimension instanceof LimboDimension || ModConfig.MONOLITHS.dangerousLimboMonoliths);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -63,6 +72,11 @@ public class MonolithEntity extends MobEntity {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LookControl getLookControl() {
|
||||
return super.getLookControl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxAir() {
|
||||
return super.getMaxAir();
|
||||
|
@ -137,45 +151,15 @@ public class MonolithEntity extends MobEntity {
|
|||
super.mobTick();
|
||||
|
||||
// Check for players and update aggro levels even if there are no players in range
|
||||
PlayerEntity player = world.getClosestPlayer(this, MAX_AGGRO_RANGE);
|
||||
boolean visibility = player != null && player.canSee(this);
|
||||
updateAggroLevel(player, visibility);
|
||||
|
||||
System.out.println(String.format("Player is %s.", player));
|
||||
|
||||
// Change orientation and face a player if one is in range
|
||||
if (player != null) {
|
||||
facePlayer(player);
|
||||
if (!world.isClient && isDangerous()) {
|
||||
// Play sounds on the server side, if the player isn't in Limbo.
|
||||
// Limbo is excluded to avoid drowning out its background music.
|
||||
// Also, since it's a large open area with many Monoliths, some
|
||||
// of the sounds that would usually play for a moment would
|
||||
// keep playing constantly and would get very annoying.
|
||||
playSounds(player.getPos());
|
||||
}
|
||||
|
||||
if (visibility) {
|
||||
// Only spawn particles on the client side and outside Limbo
|
||||
if (world.isClient && isDangerous()) {
|
||||
spawnParticles(player);
|
||||
}
|
||||
|
||||
// Teleport the target player if various conditions are met
|
||||
if (aggro >= MAX_AGGRO && !world.isClient && ModConfig.MONOLITHS.monolithTeleportation && !player.isCreative() && isDangerous()) {
|
||||
aggro = 0;
|
||||
// Location destination = LimboDimension.getLimboSkySpawn(player);
|
||||
// TeleportUtil.teleport(player, destination, 0, 0);
|
||||
player.world.playSound(null, new BlockPos(player.getPos()), ModSoundEvents.CRACK, SoundCategory.HOSTILE, 13, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
}*/
|
||||
}
|
||||
|
||||
private void updateAggroLevel(PlayerEntity player, boolean visibility) {
|
||||
public void updateAggroLevel(PlayerEntity player, boolean visibility) {
|
||||
// If we're working on the server side, adjust aggro level
|
||||
// If we're working on the client side, retrieve aggro level from dataWatcher
|
||||
if (!world.isClient) {
|
||||
int aggro = dataTracker.get(AGGRO);
|
||||
// Server side...
|
||||
// Rapidly increase the aggro level if this Monolith can see the player
|
||||
if (visibility) {
|
||||
|
@ -206,15 +190,12 @@ public class MonolithEntity extends MobEntity {
|
|||
int maxAggro = isDangerous() ? MAX_AGGRO : 180;
|
||||
aggro = (short) MathHelper.clamp(aggro, 0, maxAggro);
|
||||
dataTracker.set(AGGRO, aggro);
|
||||
} else {
|
||||
// Client side...
|
||||
aggro = dataTracker.get(AGGRO);
|
||||
}
|
||||
}
|
||||
|
||||
public int getTextureState() {
|
||||
// Determine texture state from aggro progress
|
||||
return MathHelper.clamp(MAX_TEXTURE_STATE * aggro / MAX_AGGRO, 0, MAX_TEXTURE_STATE);
|
||||
return MathHelper.clamp(MAX_TEXTURE_STATE * dataTracker.get(AGGRO) / MAX_AGGRO, 0, MAX_TEXTURE_STATE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -222,7 +203,7 @@ public class MonolithEntity extends MobEntity {
|
|||
*
|
||||
* @param pos The position to play the sounds at
|
||||
*/
|
||||
private void playSounds(Vec3d pos) {
|
||||
public void playSounds(Vec3d pos) {
|
||||
float aggroPercent = getAggroProgress();
|
||||
if (soundTime <= 0) {
|
||||
playSound(ModSoundEvents.MONK, 1F, 1F);
|
||||
|
@ -239,6 +220,11 @@ public class MonolithEntity extends MobEntity {
|
|||
soundTime--;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getEyeHeight(EntityPose entityPose) {
|
||||
return EYE_HEIGHT;
|
||||
}
|
||||
|
||||
private void spawnParticles(PlayerEntity player) {
|
||||
int count = 10 * aggro / MAX_AGGRO;
|
||||
for (int i = 1; i < count; ++i) {
|
||||
|
@ -254,16 +240,14 @@ public class MonolithEntity extends MobEntity {
|
|||
return (float) aggro / MAX_AGGRO;
|
||||
}
|
||||
|
||||
private void facePlayer(PlayerEntity player) {
|
||||
double d0 = player.getX() - getX();
|
||||
double d1 = player.getZ() - getY();
|
||||
double d2 = player.getY() + player.getEyeHeight(player.getPose()) - (getY() + EYE_HEIGHT);
|
||||
double d3 = MathHelper.sqrt(d0 * d0 + d1 * d1);
|
||||
float f2 = (float) (Math.atan2(d1, d0) * 180.0D / Math.PI) - 90.0F;
|
||||
setRotation((float) -(Math.atan(d2 / d3) * 180.0D / Math.PI), f2);
|
||||
setYaw(f2);
|
||||
setHeadYaw(f2);
|
||||
//renderYawOffset = rotationYaw;
|
||||
@Override
|
||||
protected void initGoals() {
|
||||
super.initGoals();
|
||||
goalSelector.add(0, new MonolithTask(this, MAX_AGGRO_RANGE));
|
||||
}
|
||||
|
||||
public void facePlayer(PlayerEntity player) {
|
||||
lookControl.lookAt(player, 1.0f, 1.0f);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -278,4 +262,12 @@ public class MonolithEntity extends MobEntity {
|
|||
super.fromTag(nbt);
|
||||
aggro = nbt.getInt("Aggro");
|
||||
}
|
||||
|
||||
public int getAggro() {
|
||||
return dataTracker.get(AGGRO);
|
||||
}
|
||||
|
||||
public void setAggro(int aggro) {
|
||||
dataTracker.set(AGGRO, aggro);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,8 @@
|
|||
package org.dimdev.dimdoors.entity;
|
||||
|
||||
import net.fabricmc.fabric.api.client.rendereregistry.v1.EntityRendererRegistry;
|
||||
import net.minecraft.client.render.OverlayTexture;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.entity.EntityRenderDispatcher;
|
||||
import net.minecraft.client.render.entity.EntityRenderer;
|
||||
import net.minecraft.client.render.entity.LivingEntityRenderer;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.Identifier;
|
||||
import org.dimdev.dimdoors.client.MonolithModel;
|
||||
|
||||
|
@ -42,6 +37,8 @@ public class MonolithRenderer extends LivingEntityRenderer<MonolithEntity, Monol
|
|||
|
||||
@Override
|
||||
public Identifier getTexture(MonolithEntity entity) {
|
||||
System.out.println(entity.getTextureState());
|
||||
|
||||
return MONOLITH_TEXTURES.get(entity.getTextureState());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,78 @@
|
|||
package org.dimdev.dimdoors.entity.ai;
|
||||
|
||||
public class MonolithTask {
|
||||
import net.minecraft.entity.ai.TargetPredicate;
|
||||
import net.minecraft.entity.ai.goal.Goal;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import org.dimdev.dimdoors.ModConfig;
|
||||
import org.dimdev.dimdoors.entity.MonolithEntity;
|
||||
import org.dimdev.dimdoors.sound.ModSoundEvents;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import static net.minecraft.predicate.entity.EntityPredicates.EXCEPT_SPECTATOR;
|
||||
import static org.dimdev.dimdoors.entity.MonolithEntity.MAX_AGGRO;
|
||||
|
||||
public class MonolithTask extends Goal {
|
||||
protected final MonolithEntity mob;
|
||||
protected PlayerEntity target;
|
||||
protected final float range;
|
||||
protected final TargetPredicate targetPredicate;
|
||||
|
||||
public MonolithTask(MonolithEntity mobEntity, float f) {
|
||||
this.mob = mobEntity;
|
||||
this.range = f;
|
||||
this.setControls(EnumSet.of(Goal.Control.LOOK));
|
||||
this.targetPredicate = (new TargetPredicate()).setBaseMaxDistance(range).includeTeammates().includeInvulnerable().ignoreEntityTargetRules().setPredicate(EXCEPT_SPECTATOR::test);
|
||||
}
|
||||
|
||||
public boolean canStart() {
|
||||
this.target = this.mob.world.getClosestPlayer(this.targetPredicate, this.mob, this.mob.getX(), this.mob.getEyeY(), this.mob.getZ());
|
||||
return this.target != null;
|
||||
}
|
||||
|
||||
public boolean shouldContinue() {
|
||||
return this.mob.squaredDistanceTo(this.target) > (double)(this.range * this.range);
|
||||
}
|
||||
|
||||
public void start() {
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
this.target = null;
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
boolean visibility = target != null && mob.canSee(mob);
|
||||
mob.updateAggroLevel(target, visibility);
|
||||
|
||||
// Change orientation and face a player if one is in range
|
||||
if (target != null) {
|
||||
mob.facePlayer(target);
|
||||
if (mob.isDangerous()) {
|
||||
// Play sounds on the server side, if the player isn't in Limbo.
|
||||
// Limbo is excluded to avoid drowning out its background music.
|
||||
// Also, since it's a large open area with many Monoliths, some
|
||||
// of the sounds that would usually play for a moment would
|
||||
// keep playing constantly and would get very annoying.
|
||||
mob.playSounds(target.getPos());
|
||||
}
|
||||
|
||||
if (visibility) {
|
||||
// Only spawn particles on the client side and outside Limbo
|
||||
/*(world.isClient && isDangerous()) {
|
||||
target.spawnParticles(player);
|
||||
}*/
|
||||
|
||||
// Teleport the target player if various conditions are met
|
||||
if (mob.getAggro() >= MAX_AGGRO && ModConfig.MONOLITHS.monolithTeleportation && !target.isCreative() && mob.isDangerous()) {
|
||||
mob.setAggro(0);
|
||||
//Location destination = LimboDimension.getLimboSkySpawn(player);
|
||||
//TeleportUtil.teleport(player, destination, 0, 0);
|
||||
target.world.playSound(null, new BlockPos(target.getPos()), ModSoundEvents.CRACK, SoundCategory.HOSTILE, 13, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue