use of net.minecraft.world.phys.Vec3 in project Tropicraft by Tropicraft.
the class EntityAIPartyTime method tick.
@Override
public void tick() {
super.tick();
boolean isClose = false;
BlockPos blockposGoal = null;
if (this.entityObj.listPosDrums.size() > assignedDrumIndex) {
blockposGoal = entityObj.listPosDrums.get(assignedDrumIndex);
}
if (entityObj.level.getGameTime() % 200 == 0) {
if (this.entityObj.listPosDrums.size() > 0) {
assignedDrumIndex = entityObj.level.random.nextInt(entityObj.listPosDrums.size());
}
// if (wasClose) {
bangDrum = entityObj.level.random.nextBoolean();
// }
}
if (blockposGoal == null) {
stop();
return;
}
// prevent walking onto source
double dist = entityObj.position().distanceTo(new Vec3(blockposGoal.getX(), blockposGoal.getY(), blockposGoal.getZ()));
if (dist < 8D) {
wasClose = true;
}
if (dist < 3D && entityObj.isOnGround()) {
isClose = true;
entityObj.getNavigation().stop();
if (!bangDrum) {
// entityObj.setSitting(true);
entityObj.setDancing(true);
this.entityObj.getJumpControl().jump();
this.entityObj.setYRot(entityObj.level.random.nextInt(360));
} else {
entityObj.setDancing(false);
if (true || lookUpdateTimer <= 0) {
entityObj.setItemSlot(EquipmentSlot.MAINHAND, ItemStack.EMPTY);
// keep for testing, was neat sounding
// entityObj.level.random.nextInt(10) + 1;
int amp = 1;
int rate = 4 + (entityObj.getId() % 7);
int index1 = 0;
HashMap<Integer, List<Integer>> lookupStateToSequence = new HashMap<>();
List<Integer> listDelays = Lists.newArrayList(9, 3, 3, 3, 6);
lookupStateToSequence.put(index1++, listDelays);
lookupStateToSequence.put(index1++, listDelays);
lookupStateToSequence.put(index1++, listDelays);
lookupStateToSequence.put(index1++, Lists.newArrayList(9, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 12));
int nightStart = 12500;
int nightEnd = 23500;
int phases = 4;
int phaseSplit = (nightEnd - nightStart) / phases;
int timeOfDay = (int) (entityObj.level.getDayTime() % 24000);
int nightTime = (timeOfDay - nightStart);
if (nightTime > phaseSplit * 3) {
amp = 1;
} else if (nightTime > phaseSplit * 2) {
amp = 2;
} else if (nightTime > phaseSplit * 1) {
amp = 3;
} else {
amp = 4;
}
if (entityObj.hitIndex2 >= lookupStateToSequence.get(entityObj.hitIndex).size()) {
entityObj.hitIndex2 = 0;
entityObj.hitIndex++;
}
if (entityObj.hitIndex >= lookupStateToSequence.size()) {
entityObj.hitIndex = 0;
}
rate = lookupStateToSequence.get(entityObj.hitIndex).get(entityObj.hitIndex2);
if (entityObj.hitDelay > 0) {
entityObj.hitDelay--;
}
boolean perEntDelay = false;
boolean hit = false;
if (perEntDelay) {
if (entityObj.hitDelay <= 0) {
entityObj.hitDelay = (amp * rate);
hit = true;
}
} else {
hit = entityObj.level.getGameTime() % (amp * rate) == 0;
}
if (hit) {
// System.out.println("stage: " + entityObj.hitIndex + " - " + entityObj.hitIndex2);
entityObj.hitIndex2++;
BlockState state = entityObj.level.getBlockState(blockposGoal);
/*if (state.getBlock() instanceof BlockBongoDrum) {
//((BlockBongoDrum) state.getOwner()).playBongoSound(entityObj.world, null, blockposGoal, state);
TropicraftBongos bongo = ((BlockBongoDrum) state.getOwner()).getVariant(state);
float pitch = (entityObj.level.random.nextFloat() * 1F) + 0F;
entityObj.world.playSound(null, blockposGoal.getX(), blockposGoal.getY() + 0.5D, blockposGoal.getZ(),
bongo.getSoundEvent(), SoundCategory.BLOCKS, 2.5F, pitch);
entityObj.swingArm(Hand.MAIN_HAND);
} else */
if (state.getBlock() instanceof NoteBlock) {
if (entityObj.level.random.nextInt(10) == 0) {
for (int i = 0; i < 1 + entityObj.level.random.nextInt(4); i++) {
// note.changePitch();
state.cycle(NoteBlock.NOTE).getValue(NoteBlock.NOTE);
}
} else {
// note.triggerNote(entityObj.world, blockposGoal);
state.getBlock().attack(state, entityObj.level, blockposGoal, FakePlayerFactory.get((ServerLevel) entityObj.level, new GameProfile(UUID.fromString(" e517cf6a-ce31-4ac8-b48d-44b4f0f918a7"), "tropicraftKoa")));
}
entityObj.swing(InteractionHand.MAIN_HAND);
}
}
entityObj.syncBPM();
}
this.entityObj.getLookControl().setLookAt(blockposGoal.getX() + randXPos, blockposGoal.getY() + randYPos + 1D, blockposGoal.getZ() + randZPos, 8F, 8F);
}
} else {
wasClose = false;
entityObj.setSitting(false);
}
if (!isClose) {
entityObj.setDancing(true);
if ((this.entityObj.getNavigation().isDone() || walkingTimeout <= 0) && repathPentalty <= 0) {
int i = blockposGoal.getX();
int j = blockposGoal.getY();
int k = blockposGoal.getZ();
boolean success = false;
if (this.entityObj.distanceToSqr(Vec3.atCenterOf(blockposGoal)) > 256.0) {
Vec3 Vector3d = DefaultRandomPos.getPosTowards(this.entityObj, 14, 3, new Vec3((double) i + 0.5D, (double) j, (double) k + 0.5D), (float) Math.PI / 2F);
if (Vector3d != null) {
success = this.entityObj.getNavigation().moveTo(Vector3d.x, Vector3d.y, Vector3d.z, 1.0D);
} else {
success = Util.tryMoveToXYZLongDist(this.entityObj, new BlockPos(i, j, k), 1);
// System.out.println("success? " + success);
}
} else {
success = this.entityObj.getNavigation().moveTo((double) i + 0.5D, j, (double) k + 0.5D, 1.0D);
}
if (!success) {
repathPentalty = 40;
} else {
walkingTimeout = walkingTimeoutMax;
}
} else {
if (walkingTimeout > 0) {
walkingTimeout--;
} else {
}
}
}
if (repathPentalty > 0) {
repathPentalty--;
}
if (lookUpdateTimer > 0) {
lookUpdateTimer--;
}
}
use of net.minecraft.world.phys.Vec3 in project Tropicraft by Tropicraft.
the class MonkeyStealDrinkGoal method leapTowardTarget.
private void leapTowardTarget() {
LivingEntity leapTarget = entity.getTarget();
if (leapTarget == null)
return;
double d0 = leapTarget.getX() - entity.getX();
double d1 = leapTarget.getZ() - entity.getZ();
float f = Mth.sqrt((float) (d0 * d0 + d1 * d1));
final Vec3 motion = entity.getDeltaMovement();
if ((double) f >= 1.0E-4D) {
entity.setDeltaMovement(motion.add(d0 / (double) f * 0.5D * 0.800000011920929D + motion.x * 0.20000000298023224D, 0, d1 / (double) f * 0.5D * 0.800000011920929D + motion.z * 0.20000000298023224D));
}
entity.setDeltaMovement(new Vec3(motion.x, 0.25, motion.z));
}
use of net.minecraft.world.phys.Vec3 in project Tropicraft by Tropicraft.
the class AvoidWallsGoal method tick.
@Override
public void tick() {
super.tick();
// Wall correction
Vec3 angle = entity.getHeading();
double frontDist = 1 + rand.nextInt(4);
Vec3 diff = new Vec3(entity.getX() + (angle.x * frontDist), entity.getY() + angle.y, entity.getZ() + (angle.z * frontDist));
BlockPos bp = new BlockPos((int) diff.x, (int) entity.getY(), (int) diff.z);
if (!entity.level.getBlockState(bp).getMaterial().isLiquid() && !entity.isMovingAwayFromWall) {
entity.setRandomTargetHeadingForce(32);
entity.isMovingAwayFromWall = true;
}
if (entity.tickCount % 20 == 0 && entity.isMovingAwayFromWall)
entity.isMovingAwayFromWall = false;
if (entity.targetVector != null && entity.isMovingAwayFromWall) {
bp = new BlockPos((int) entity.targetVector.x, (int) entity.targetVector.y, (int) entity.targetVector.z);
if (entity.blockPosition().equals(bp) && entity.tickCount % 80 == 0) {
entity.isMovingAwayFromWall = false;
}
}
// Near surface check
bp = entity.blockPosition();
if (!entity.level.getBlockState(bp).getMaterial().isLiquid()) {
if (entity.swimPitch > 0f) {
entity.isPanicking = false;
entity.setRandomTargetHeadingForce(32);
}
}
bp = new BlockPos(entity.blockPosition().below(2));
// Hitting bottom check
if (!entity.level.getBlockState(bp).getMaterial().isLiquid()) {
if (entity.swimPitch < 0f) {
entity.swimPitch += 2f;
}
}
}
use of net.minecraft.world.phys.Vec3 in project Tropicraft by Tropicraft.
the class AshenMaskEntity method tick.
@Override
public void tick() {
if (!level.isClientSide) {
// Remove masks that have been on the ground abandoned for over a day
if (tickCount >= MAX_TICKS_ALIVE) {
remove(RemovalReason.DISCARDED);
}
}
final Vec3 motion = getDeltaMovement();
if (onGround) {
setDeltaMovement(motion.multiply(0.5, 0, 0.5));
}
if (isInWater()) {
setDeltaMovement(motion.x * 0.95f, 0.02f, motion.z * 0.95f);
} else {
setDeltaMovement(motion.subtract(0, 0.05f, 0));
}
move(MoverType.SELF, motion);
}
use of net.minecraft.world.phys.Vec3 in project Tropicraft by Tropicraft.
the class TreeFrogEntity method customServerAiStep.
@Override
protected void customServerAiStep() {
super.customServerAiStep();
if (!getNavigation().isDone() || this.getTarget() != null) {
if (onGround || isInWater()) {
if (jumpDelay > 0)
jumpDelay--;
if (jumpDelay <= 0) {
jumpDelay = 5 + random.nextInt(4);
// this.jump();
// this.motionY += -0.01D + rand.nextDouble() * 0.1D;
final Vec3 motion = getDeltaMovement();
double speed = Math.sqrt(motion.x * motion.x + motion.z * motion.z);
if (speed > 0.02D) {
final double motionY = motion.y + 0.4d;
final double motionX = motion.x * 1.1d;
final double motionZ = motion.z * 1.1d;
setDeltaMovement(motionX, motionY, motionZ);
}
}
}
}
if (attackTime > 0)
attackTime--;
}
Aggregations