use of net.tropicraft.core.common.enums.TropicraftBongos in project Tropicraft by Tropicraft.
the class EntityAIPartyTime method updateTask.
@Override
public void updateTask() {
super.updateTask();
boolean isClose = false;
BlockPos blockposGoal = null;
if (this.entityObj.listPosDrums.size() > assignedDrumIndex) {
blockposGoal = entityObj.listPosDrums.get(assignedDrumIndex);
}
if (entityObj.world.getTotalWorldTime() % 200 == 0) {
if (this.entityObj.listPosDrums.size() > 0) {
assignedDrumIndex = entityObj.world.rand.nextInt(entityObj.listPosDrums.size());
}
// if (wasClose) {
bangDrum = entityObj.world.rand.nextBoolean();
// }
}
if (blockposGoal == null) {
resetTask();
return;
}
// prevent walking onto source
double dist = entityObj.getPositionVector().distanceTo(new Vec3d(blockposGoal.getX(), blockposGoal.getY(), blockposGoal.getZ()));
if (dist < 8D) {
wasClose = true;
}
if (dist < 3D && entityObj.onGround) {
isClose = true;
entityObj.getNavigator().clearPath();
if (!bangDrum) {
// entityObj.setSitting(true);
entityObj.setDancing(true);
this.entityObj.getJumpHelper().setJumping();
this.entityObj.rotationYaw = entityObj.world.rand.nextInt(360);
} else {
entityObj.setDancing(false);
if (true || lookUpdateTimer <= 0) {
entityObj.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, ItemStack.EMPTY);
// keep for testing, was neat sounding
// entityObj.world.rand.nextInt(10) + 1;
int amp = 1;
int rate = 4 + (entityObj.getEntityId() % 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.world.getWorldTime() % 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.world.getTotalWorldTime() % (amp * rate) == 0;
}
if (hit) {
// System.out.println("stage: " + entityObj.hitIndex + " - " + entityObj.hitIndex2);
entityObj.hitIndex2++;
IBlockState state = entityObj.world.getBlockState(blockposGoal);
if (state.getBlock() instanceof BlockBongoDrum) {
// ((BlockBongoDrum) state.getBlock()).playBongoSound(entityObj.world, null, blockposGoal, state);
TropicraftBongos bongo = ((BlockBongoDrum) state.getBlock()).getVariant(state);
float pitch = (entityObj.world.rand.nextFloat() * 1F) + 0F;
entityObj.world.playSound(null, blockposGoal.getX(), blockposGoal.getY() + 0.5D, blockposGoal.getZ(), bongo.getSoundEvent(), SoundCategory.BLOCKS, 6.0F, pitch);
entityObj.swingArm(EnumHand.MAIN_HAND);
}
}
entityObj.syncBPM();
}
this.entityObj.getLookHelper().setLookPosition(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.getNavigator().noPath() || walkingTimeout <= 0) && repathPentalty <= 0) {
int i = blockposGoal.getX();
int j = blockposGoal.getY();
int k = blockposGoal.getZ();
boolean success = false;
if (this.entityObj.getDistanceSq(blockposGoal) > 256.0D) {
Vec3d vec3d = RandomPositionGenerator.findRandomTargetBlockTowards(this.entityObj, 14, 3, new Vec3d((double) i + 0.5D, (double) j, (double) k + 0.5D));
if (vec3d != null) {
success = this.entityObj.getNavigator().tryMoveToXYZ(vec3d.x, vec3d.y, vec3d.z, 1.0D);
} else {
success = Util.tryMoveToXYZLongDist(this.entityObj, new BlockPos(i, j, k), 1);
// System.out.println("success? " + success);
}
} else {
success = this.entityObj.getNavigator().tryMoveToXYZ((double) i + 0.5D, (double) 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.tropicraft.core.common.enums.TropicraftBongos in project Tropicraft by Tropicraft.
the class BlockBongoDrum method playBongoSound.
/**
* Play the bongo sound in game. Sound played determined by the {@link #size} attribute
*/
public void playBongoSound(World world, EntityPlayer entity, BlockPos pos, IBlockState state) {
TropicraftBongos bongo = this.getVariant(state);
world.playSound(entity, pos.getX(), pos.getY() + 0.5D, pos.getZ(), bongo.getSoundEvent(), SoundCategory.BLOCKS, 1.0F, 1.0F);
}
Aggregations