Break GG onLivingUpdate method apart a bit so it's easier to read

This commit is contained in:
Vincent Lee committed 2017-08-21 15:22:53 -05:00
1 parent df0d9efefc
commit fa5059a883
3 files changed
+162 -132

No files matched your search

@@ -129,8 +129,10 @@ public class EntityDoppleganger extends EntityLiving implements IBotaniaBoss {
new BlockPos(-4, 1, -4)
};
private static final List<String> CHEATY_BLOCKS = Arrays.asList("OpenBlocks:beartrap",
"ThaumicTinkerer:magnet");
private static final List<ResourceLocation> CHEATY_BLOCKS = Arrays.asList(
new ResourceLocation("openblocks", "beartrap"),
new ResourceLocation("thaumictinkerer", "magnet")
);
private boolean isPlayingMusic = false;
private boolean spawnLandmines = false;
@@ -231,7 +233,7 @@ public class EntityDoppleganger extends EntityLiving implements IBotaniaBoss {
}
private static boolean hasProperArena(World world, BlockPos startPos) {
List<BlockPos> trippedPositions = new ArrayList();
List<BlockPos> trippedPositions = new ArrayList<>();
boolean tripped = false;
int heightCheck = 3;
@@ -522,75 +524,57 @@ public class EntityDoppleganger extends EntityLiving implements IBotaniaBoss {
List l = world.getEntitiesWithinAABB(EntityDoppleganger.class, new AxisAlignedBB(source.getX() + 0.5 - range, source.getY() + 0.5 - range, source.getZ() + 0.5 - range, source.getX() + 0.5 + range, source.getY() + 0.5 + range, source.getZ() + 0.5 + range));
return l.size();
}
@Override
public void onLivingUpdate() {
super.onLivingUpdate();
private void particles() {
BlockPos source = getSource();
float range = ARENA_RANGE;
int invul = getInvulTime();
if (world.isRemote) {
for(int i = 0; i < 360; i += 8) {
float r = 0.6F;
float g = 0F;
float b = 0.2F;
float m = 0.15F;
float mv = 0.35F;
for(int i = 0; i < 360; i += 8) {
float r = 0.6F;
float g = 0F;
float b = 0.2F;
float m = 0.15F;
float mv = 0.35F;
float rad = i * (float) Math.PI / 180F;
double x = source.getX() + 0.5 - Math.cos(rad) * range;
double y = source.getY() + 0.5;
double z = source.getZ() + 0.5 - Math.sin(rad) * range;
float rad = i * (float) Math.PI / 180F;
double x = source.getX() + 0.5 - Math.cos(rad) * ARENA_RANGE;
double y = source.getY() + 0.5;
double z = source.getZ() + 0.5 - Math.sin(rad) * ARENA_RANGE;
Botania.proxy.wispFX(x, y, z, r, g, b, 0.5F, (float) (Math.random() - 0.5F) * m, (float) (Math.random() - 0.5F) * mv, (float) (Math.random() - 0.5F) * m);
}
EntityPlayer player = Botania.proxy.getClientPlayer();
player.capabilities.isFlying = player.capabilities.isFlying && player.capabilities.isCreativeMode;
if(invul > 10) {
Vector3 pos = Vector3.fromEntityCenter(this).subtract(new Vector3(0, 0.2, 0));
for (BlockPos arr : PYLON_LOCATIONS) {
Vector3 pylonPos = new Vector3(source.getX() + arr.getX(), source.getY() + arr.getY(), source.getZ() + arr.getZ());
double worldTime = ticksExisted;
worldTime /= 5;
float rad = 0.75F + (float) Math.random() * 0.05F;
double xp = pylonPos.x + 0.5 + Math.cos(worldTime) * rad;
double zp = pylonPos.z + 0.5 + Math.sin(worldTime) * rad;
Vector3 partPos = new Vector3(xp, pylonPos.y, zp);
Vector3 mot = pos.subtract(partPos).multiply(0.04);
float r = 0.7F + (float) Math.random() * 0.3F;
float g = (float) Math.random() * 0.3F;
float b = 0.7F + (float) Math.random() * 0.3F;
Botania.proxy.wispFX(partPos.x, partPos.y, partPos.z, r, g, b, 0.25F + (float) Math.random() * 0.1F, -0.075F - (float) Math.random() * 0.015F);
Botania.proxy.wispFX(partPos.x, partPos.y, partPos.z, r, g, b, 0.4F, (float) mot.x, (float) mot.y, (float) mot.z);
}
}
return;
Botania.proxy.wispFX(x, y, z, r, g, b, 0.5F, (float) (Math.random() - 0.5F) * m, (float) (Math.random() - 0.5F) * mv, (float) (Math.random() - 0.5F) * m);
}
if(getInvulTime() > 10) {
Vector3 pos = Vector3.fromEntityCenter(this).subtract(new Vector3(0, 0.2, 0));
for(BlockPos arr : PYLON_LOCATIONS) {
Vector3 pylonPos = new Vector3(source.getX() + arr.getX(), source.getY() + arr.getY(), source.getZ() + arr.getZ());
double worldTime = ticksExisted;
worldTime /= 5;
float rad = 0.75F + (float) Math.random() * 0.05F;
double xp = pylonPos.x + 0.5 + Math.cos(worldTime) * rad;
double zp = pylonPos.z + 0.5 + Math.sin(worldTime) * rad;
Vector3 partPos = new Vector3(xp, pylonPos.y, zp);
Vector3 mot = pos.subtract(partPos).multiply(0.04);
float r = 0.7F + (float) Math.random() * 0.3F;
float g = (float) Math.random() * 0.3F;
float b = 0.7F + (float) Math.random() * 0.3F;
Botania.proxy.wispFX(partPos.x, partPos.y, partPos.z, r, g, b, 0.25F + (float) Math.random() * 0.1F, -0.075F - (float) Math.random() * 0.015F);
Botania.proxy.wispFX(partPos.x, partPos.y, partPos.z, r, g, b, 0.4F, (float) mot.x, (float) mot.y, (float) mot.z);
}
}
}
private void playMusic() {
if(!isPlayingMusic && !isDead && !getPlayersAround().isEmpty()) {
world.playEvent(1010, source, Item.getIdFromItem(isHardMode() ? ModItems.recordGaia2 : ModItems.recordGaia1));
world.playEvent(1010, getSource(), Item.getIdFromItem(isHardMode() ? ModItems.recordGaia2 : ModItems.recordGaia1));
isPlayingMusic = true;
}
}
dataManager.set(BOSSINFO_ID, Optional.of(bossInfo.getUniqueId()));
bossInfo.setPercent(getHealth() / getMaxHealth());
if(!getPassengers().isEmpty())
dismountRidingEntity();
if(world.getDifficulty() == EnumDifficulty.PEACEFUL)
setDead();
private void smashCheatyBlocks() {
int radius = 1;
int posXInt = MathHelper.floor(posX);
int posYInt = MathHelper.floor(posY);
@@ -606,6 +590,113 @@ public class EntityDoppleganger extends EntityLiving implements IBotaniaBoss {
world.destroyBlock(posp, true);
}
}
}
private void clearPotions(EntityPlayer player) {
int posXInt = MathHelper.floor(posX);
int posZInt = MathHelper.floor(posZ);
List<Potion> potionsToRemove = player.getActivePotionEffects().stream()
.filter(effect -> effect.getDuration() < 160 && effect.getIsAmbient() && !effect.getPotion().isBadEffect())
.map(PotionEffect::getPotion)
.distinct()
.collect(Collectors.toList());
potionsToRemove.forEach(potion -> {
player.removePotionEffect(potion);
((WorldServer) world).getPlayerChunkMap().getEntry(posXInt >> 4, posZInt >> 4).sendPacket(new SPacketRemoveEntityEffect(player.getEntityId(), potion));
});
}
private void keepInsideArena(EntityPlayer player) {
BlockPos source = getSource();
if(vazkii.botania.common.core.helper.MathHelper.pointDistanceSpace(player.posX, player.posY, player.posZ, source.getX() + 0.5, source.getY() + 0.5, source.getZ() + 0.5) >= ARENA_RANGE) {
Vector3 sourceVector = new Vector3(source.getX() + 0.5, source.getY() + 0.5, source.getZ() + 0.5);
Vector3 playerVector = Vector3.fromEntityCenter(player);
Vector3 motion = sourceVector.subtract(playerVector).normalize();
player.motionX = motion.x;
player.motionY = 0.2;
player.motionZ = motion.z;
player.velocityChanged = true;
}
}
private void spawnMobs(List<EntityPlayer> players) {
int playerCount = getPlayerCount();
for(int pl = 0; pl < playerCount; pl++) {
for(int i = 0; i < 3 + world.rand.nextInt(2); i++) {
EntityLiving entity = null;
switch (world.rand.nextInt(2)) {
case 0: {
entity = new EntityZombie(world);
if(world.rand.nextInt(isHardMode() ? 3 : 12) == 0) {
entity = new EntityWitch(world);
}
break;
}
case 1: {
entity = new EntitySkeleton(world);
if(world.rand.nextInt(8) == 0) {
entity = new EntityWitherSkeleton(world);
}
break;
}
case 3: {
if(!players.isEmpty()) {
for(int j = 0; j < 1 + world.rand.nextInt(isHardMode() ? 8 : 5); j++) {
EntityPixie pixie = new EntityPixie(world);
pixie.setProps(players.get(rand.nextInt(players.size())), this, 1, 8);
pixie.setPosition(posX + width / 2, posY + 2, posZ + width / 2);
pixie.onInitialSpawn(world.getDifficultyForLocation(new BlockPos(pixie)), null);
world.spawnEntity(pixie);
}
}
break;
}
}
if(entity != null) {
if(!entity.isImmuneToFire())
entity.addPotionEffect(new PotionEffect(MobEffects.FIRE_RESISTANCE, 600, 0));
float range = 6F;
entity.setPosition(posX + 0.5 + Math.random() * range - range / 2, posY - 1, posZ + 0.5 + Math.random() * range - range / 2);
entity.onInitialSpawn(world.getDifficultyForLocation(new BlockPos(entity)), null);
if(entity instanceof EntityWitherSkeleton && isHardMode()) {
entity.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, new ItemStack(ModItems.elementiumSword));
}
world.spawnEntity(entity);
}
}
}
}
@Override
public void onLivingUpdate() {
super.onLivingUpdate();
BlockPos source = getSource();
int invul = getInvulTime();
if (world.isRemote) {
particles();
EntityPlayer player = Botania.proxy.getClientPlayer();
player.capabilities.isFlying = player.capabilities.isFlying && player.capabilities.isCreativeMode;
return;
}
playMusic();
dataManager.set(BOSSINFO_ID, Optional.of(bossInfo.getUniqueId()));
bossInfo.setPercent(getHealth() / getMaxHealth());
if(!getPassengers().isEmpty())
dismountRidingEntity();
if(world.getDifficulty() == EnumDifficulty.PEACEFUL)
setDead();
smashCheatyBlocks();
boolean hard = isHardMode();
List<EntityPlayer> players = getPlayersAround();
@@ -622,28 +713,9 @@ public class EntityDoppleganger extends EntityLiving implements IBotaniaBoss {
}
}
List<Potion> potionsToRemove = player.getActivePotionEffects().stream()
.filter(effect -> effect.getDuration() < 160 && effect.getIsAmbient() && !effect.getPotion().isBadEffect())
.map(PotionEffect::getPotion)
.distinct()
.collect(Collectors.toList());
potionsToRemove.forEach(potion -> {
player.removePotionEffect(potion);
((WorldServer) world).getPlayerChunkMap().getEntry(posXInt >> 4, posZInt >> 4).sendPacket(new SPacketRemoveEntityEffect(player.getEntityId(), potion));
});
clearPotions(player);
keepInsideArena(player);
player.capabilities.isFlying = player.capabilities.isFlying && player.capabilities.isCreativeMode;
if(vazkii.botania.common.core.helper.MathHelper.pointDistanceSpace(player.posX, player.posY, player.posZ, source.getX() + 0.5, source.getY() + 0.5, source.getZ() + 0.5) >= range) {
Vector3 sourceVector = new Vector3(source.getX() + 0.5, source.getY() + 0.5, source.getZ() + 0.5);
Vector3 playerVector = Vector3.fromEntityCenter(player);
Vector3 motion = sourceVector.subtract(playerVector).normalize();
player.motionX = motion.x;
player.motionY = 0.2;
player.motionZ = motion.z;
player.velocityChanged = true;
}
}
}
@@ -678,48 +750,7 @@ public class EntityDoppleganger extends EntityLiving implements IBotaniaBoss {
}
if(reverseTicks > MOB_SPAWN_START_TICKS * 2 && mobSpawnTicks > MOB_SPAWN_END_TICKS && mobSpawnTicks % MOB_SPAWN_WAVE_TIME == 0) {
for(int pl = 0; pl < playerCount; pl++)
for(int i = 0; i < 3 + world.rand.nextInt(2); i++) {
EntityLiving entity = null;
switch(world.rand.nextInt(2)) {
case 0 : {
entity = new EntityZombie(world);
if(world.rand.nextInt(hard ? 3 : 12) == 0)
entity = new EntityWitch(world);
break;
}
case 1 : {
entity = new EntitySkeleton(world);
if(world.rand.nextInt(8) == 0) {
entity = new EntityWitherSkeleton(world);
}
break;
}
case 3 : {
if(!players.isEmpty())
for(int j = 0; j < 1 + world.rand.nextInt(hard ? 8 : 5); j++) {
EntityPixie pixie = new EntityPixie(world);
pixie.setProps(players.get(rand.nextInt(players.size())), this, 1, 8);
pixie.setPosition(posX + width / 2, posY + 2, posZ + width / 2);
pixie.onInitialSpawn(world.getDifficultyForLocation(new BlockPos(pixie)), null);
world.spawnEntity(pixie);
}
}
}
if(entity != null) {
if(!entity.isImmuneToFire())
entity.addPotionEffect(new PotionEffect(MobEffects.FIRE_RESISTANCE, 600, 0));
range = 6F;
entity.setPosition(posX + 0.5 + Math.random() * range - range / 2, posY - 1, posZ + 0.5 + Math.random() * range - range / 2);
entity.onInitialSpawn(world.getDifficultyForLocation(new BlockPos(entity)), null);
if (entity instanceof EntityWitherSkeleton && hard) {
entity.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, new ItemStack(ModItems.elementiumSword));
}
world.spawnEntity(entity);
}
}
spawnMobs(players);
if(hard && ticksExisted % 3 < 2) {
for(int i = 0; i < playerCount; i++)
@@ -776,7 +807,7 @@ public class EntityDoppleganger extends EntityLiving implements IBotaniaBoss {
if(spawnMissiles)
spawnMissile();
} else {
range = 3F;
float range = 3F;
players = world.getEntitiesWithinAABB(EntityPlayer.class, new AxisAlignedBB(posX - range, posY - range, posZ - range, posX + range, posY + range, posZ + range));
if(!players.isEmpty())
damageEntity(DamageSource.causePlayerDamage(players.get(0)), 0);
@@ -818,7 +849,7 @@ public class EntityDoppleganger extends EntityLiving implements IBotaniaBoss {
private void spawnMissile() {
EntityMagicMissile missile = new EntityMagicMissile(this, true);
missile.setPosition(posX + (Math.random() - 0.5 * 0.1), posY + 2.4 + (Math.random() - 0.5 * 0.1), posZ + (Math.random() - 0.5 * 0.1));
if(missile.getTarget()) {
if(missile.findTarget()) {
playSound(ModSounds.missile, 0.6F, 0.8F + (float) Math.random() * 0.2F);
world.spawnEntity(missile);
}
@@ -826,8 +857,7 @@ public class EntityDoppleganger extends EntityLiving implements IBotaniaBoss {
private static boolean isCheatyBlock(World world, BlockPos pos) {
Block block = world.getBlockState(pos).getBlock();
String name = Block.REGISTRY.getNameForObject(block).toString();
return CHEATY_BLOCKS.contains(name);
return CHEATY_BLOCKS.contains(Block.REGISTRY.getNameForObject(block));
}
// [VanillaCopy] EntityEnderman.teleportRandomly, edits noted.
@@ -90,7 +90,7 @@ public class EntityMagicMissile extends EntityThrowable {
super.onUpdate();
if(!world.isRemote && (!getTarget() || time > 40)) {
if(!world.isRemote && (!findTarget() || time > 40)) {
setDead();
return;
}
@@ -131,7 +131,7 @@ public class EntityMagicMissile extends EntityThrowable {
motionZ = motionVec.z;
List<EntityLivingBase> targetList = world.getEntitiesWithinAABB(EntityLivingBase.class, new AxisAlignedBB(posX - 0.5, posY - 0.5, posZ - 0.5, posX + 0.5, posY + 0.5, posZ + 0.5));
if(targetList.contains(target) && target != null) {
if(targetList.contains(target)) {
EntityLivingBase thrower = getThrower();
if(thrower != null) {
EntityPlayer player = thrower instanceof EntityPlayer ? (EntityPlayer) thrower : null;
@@ -161,7 +161,7 @@ public class EntityMagicMissile extends EntityThrowable {
}
public boolean getTarget() {
public boolean findTarget() {
EntityLivingBase target = getTargetEntity();
if(target != null && target.getHealth() > 0 && !target.isDead && world.loadedEntityList.contains(target))
return true;
@@ -77,7 +77,7 @@ public class ItemMissileRod extends ItemMod implements IManaUsingItem, IAvatarWi
else missile = new EntityMagicMissile(world);
missile.setPosition(x, y, z);
if(missile.getTarget()) {
if(missile.findTarget()) {
if(!world.isRemote) {
missile.playSound(ModSounds.missile, 0.6F, 0.8F + (float) Math.random() * 0.2F);
world.spawnEntity(missile);