Skip to content

Commit

Permalink
Codemod more Entity.level to Entity.getLevel
Browse files Browse the repository at this point in the history
Structural search and replace is magic
  • Loading branch information
williewillus committed May 29, 2023
1 parent 6decab3 commit 3c601bc
Show file tree
Hide file tree
Showing 21 changed files with 174 additions and 174 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ public boolean ignoreExplosion() {
public void tick() {
Entity thrower = getOwner();
if (!(thrower instanceof Player player) || !thrower.isAlive()) {
if (!level.isClientSide) {
if (!getLevel().isClientSide) {
discard();
}
return;
}
if (!level.isClientSide) {
if (!getLevel().isClientSide) {
ItemStack stack = PlayerHelper.getFirstHeldItem(player, BotaniaItems.kingKey);
boolean newCharging = !stack.isEmpty() && KeyOfTheKingsLawItem.isCharging(stack);
if (isCharging() != newCharging) {
Expand All @@ -111,8 +111,8 @@ public void tick() {
int chargeTime = getChargeTicks();
setChargeTicks(chargeTime + 1);

if (level.random.nextInt(20) == 0) {
level.playSound(null, getX(), getY(), getZ(), BotaniaSounds.babylonSpawn, SoundSource.PLAYERS, 0.1F, 1F + level.random.nextFloat() * 3F);
if (getLevel().random.nextInt(20) == 0) {
getLevel().playSound(null, getX(), getY(), getZ(), BotaniaSounds.babylonSpawn, SoundSource.PLAYERS, 0.1F, 1F + getLevel().random.nextFloat() * 3F);
}
} else {
if (liveTime < delay) {
Expand All @@ -129,13 +129,13 @@ public void tick() {
Vec3 thisVec = VecHelper.fromEntityCenter(this);

mot = playerLook.subtract(thisVec.x, thisVec.y, thisVec.z).normalize().scale(2);
level.playSound(null, getX(), getY(), getZ(), BotaniaSounds.babylonAttack, SoundSource.PLAYERS, 2F, 0.1F + level.random.nextFloat() * 3F);
getLevel().playSound(null, getX(), getY(), getZ(), BotaniaSounds.babylonAttack, SoundSource.PLAYERS, 2F, 0.1F + getLevel().random.nextFloat() * 3F);
}

if (!level.isClientSide) {
if (!getLevel().isClientSide) {
setLiveTicks(liveTime + 1);
AABB axis = new AABB(getX(), getY(), getZ(), xOld, yOld, zOld).inflate(2);
List<LivingEntity> entities = level.getEntitiesOfClass(LivingEntity.class, axis);
List<LivingEntity> entities = getLevel().getEntitiesOfClass(LivingEntity.class, axis);
for (LivingEntity living : entities) {
if (living == thrower) {
continue;
Expand All @@ -159,12 +159,12 @@ public void tick() {
// Apply after super tick so drag is not applied by super
setDeltaMovement(mot);

if (level.isClientSide && liveTime > delay) {
if (getLevel().isClientSide && liveTime > delay) {
WispParticleData data = WispParticleData.wisp(0.3F, 1F, 1F, 0F, 1);
level.addParticle(data, getX(), getY(), getZ(), 0, -0F, 0);
getLevel().addParticle(data, getX(), getY(), getZ(), 0, -0F, 0);
}

if (!level.isClientSide && liveTime > 200 + delay) {
if (!getLevel().isClientSide && liveTime > 200 + delay) {
discard();
}
}
Expand All @@ -184,8 +184,8 @@ protected void onHitEntity(@NotNull EntityHitResult hit) {
}

private void explodeAndDie() {
if (!level.isClientSide) {
level.explode(this, getX(), getY(), getZ(), 3F, Explosion.BlockInteraction.NONE);
if (!getLevel().isClientSide) {
getLevel().explode(this, getX(), getY(), getZ(), 3F, Explosion.BlockInteraction.NONE);
discard();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ public ItemStack getPickResult() {
public void tick() {
super.tick();

if (level.isClientSide) {
if (getLevel().isClientSide) {
return;
}

CorporeaNode node = getSparkNode();
if (node instanceof DummyCorporeaNode && !level.getBlockState(getAttachPos()).is(BotaniaTags.Blocks.CORPOREA_SPARK_OVERRIDE)) {
if (node instanceof DummyCorporeaNode && !getLevel().getBlockState(getAttachPos()).is(BotaniaTags.Blocks.CORPOREA_SPARK_OVERRIDE)) {
dropAndKill();
return;
}
Expand Down Expand Up @@ -149,7 +149,7 @@ public void introduceNearbyTo(Set<CorporeaSpark> network, CorporeaSpark master)

@SuppressWarnings("unchecked")
private List<CorporeaSpark> getNearbySparks() {
return (List) level.getEntitiesOfClass(Entity.class, new AABB(getX() - SCAN_RANGE, getY() - SCAN_RANGE, getZ() - SCAN_RANGE, getX() + SCAN_RANGE, getY() + SCAN_RANGE, getZ() + SCAN_RANGE), Predicates.instanceOf(CorporeaSpark.class));
return (List) getLevel().getEntitiesOfClass(Entity.class, new AABB(getX() - SCAN_RANGE, getY() - SCAN_RANGE, getZ() - SCAN_RANGE, getX() + SCAN_RANGE, getY() + SCAN_RANGE, getZ() + SCAN_RANGE), Predicates.instanceOf(CorporeaSpark.class));
}

private void restartNetwork() {
Expand Down Expand Up @@ -199,7 +199,7 @@ private static void displayRelatives(Player player, List<CorporeaSpark> checked,

@Override
public CorporeaNode getSparkNode() {
return CorporeaNodeDetectors.findNode(level, this);
return CorporeaNodeDetectors.findNode(getLevel(), this);
}

@Override
Expand All @@ -214,7 +214,7 @@ public List<CorporeaSpark> getRelatives() {

@Override
public void onItemExtracted(ItemStack stack) {
((ServerLevel) level).sendParticles(new ItemParticleOption(ParticleTypes.ITEM, stack), getX(), getY(), getZ(), 10, 0.125, 0.125, 0.125, 0.05);
((ServerLevel) getLevel()).sendParticles(new ItemParticleOption(ParticleTypes.ITEM, stack), getX(), getY(), getZ(), 10, 0.125, 0.125, 0.125, 0.05);
}

@Override
Expand All @@ -223,7 +223,7 @@ public void onItemsRequested(List<ItemStack> stacks) {
for (ItemStack stack : stacks) {
if (!shownItems.contains(stack.getItem())) {
shownItems.add(stack.getItem());
((ServerLevel) level).sendParticles(new ItemParticleOption(ParticleTypes.ITEM, stack), getX(), getY(), getZ(), 10, 0.125, 0.125, 0.125, 0.05);
((ServerLevel) getLevel()).sendParticles(new ItemParticleOption(ParticleTypes.ITEM, stack), getX(), getY(), getZ(), 10, 0.125, 0.125, 0.125, 0.05);
}
}
}
Expand Down Expand Up @@ -256,7 +256,7 @@ public InteractionResult interact(Player player, InteractionHand hand) {
ItemStack stack = player.getItemInHand(hand);
if (isAlive() && !stack.isEmpty()) {
if (stack.getItem() instanceof WandOfTheForestItem) {
if (!level.isClientSide) {
if (!getLevel().isClientSide) {
if (player.isShiftKeyDown()) {
dropAndKill();
if (isMaster()) {
Expand All @@ -266,23 +266,23 @@ public InteractionResult interact(Player player, InteractionHand hand) {
displayRelatives(player, new ArrayList<>(), master);
}
}
return InteractionResult.sidedSuccess(level.isClientSide);
return InteractionResult.sidedSuccess(getLevel().isClientSide);
} else if (stack.getItem() instanceof DyeItem dye) {
DyeColor color = dye.getDyeColor();
if (color != getNetwork()) {
if (!level.isClientSide) {
if (!getLevel().isClientSide) {
setNetwork(color);

stack.shrink(1);
}

return InteractionResult.sidedSuccess(level.isClientSide);
return InteractionResult.sidedSuccess(getLevel().isClientSide);
}
} else if (stack.is(BotaniaItems.phantomInk)) {
if (!level.isClientSide) {
if (!getLevel().isClientSide) {
setInvisible(true);
}
return InteractionResult.sidedSuccess(level.isClientSide);
return InteractionResult.sidedSuccess(getLevel().isClientSide);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private void convertBlock(@NotNull BlockPos pos) {
@Override
protected void onHitBlock(@NotNull BlockHitResult result) {
super.onHitBlock(result);
if (level.isClientSide) {
if (getLevel().isClientSide) {
return;
}
convertBlock(result.getBlockPos());
Expand Down Expand Up @@ -108,7 +108,7 @@ protected void onHitEntity(@NotNull EntityHitResult result) {
Math.abs(vec.z) + 0.15, 0.2, Math.abs(vec.x) + 0.15, 0.2);

LootTable table = this.getLevel().getServer().getLootTables().get(GHAST_LOOT_TABLE);
LootContext.Builder builder = new LootContext.Builder(((ServerLevel) level));
LootContext.Builder builder = new LootContext.Builder(((ServerLevel) getLevel()));
builder.withParameter(LootContextParams.THIS_ENTITY, entity);
builder.withParameter(LootContextParams.ORIGIN, entity.position());
builder.withParameter(LootContextParams.DAMAGE_SOURCE, source);
Expand All @@ -131,7 +131,7 @@ private List<BlockPos> getCoordsToPut(BlockPos pos) {

for (BlockPos bPos : BlockPos.betweenClosed(pos.offset(-range, -rangeY, -range),
pos.offset(range, rangeY, range))) {
BlockState state = level.getBlockState(bPos);
BlockState state = getLevel().getBlockState(bPos);
if (state.is(BotaniaTags.Blocks.ENDER_AIR_CONVERTABLE)) {
possibleCoords.add(bPos.immutable());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ public EnderAirEntity(EntityType<?> type, Level level) {
@Override
public void tick() {
super.tick();
if (!level.isClientSide && tickCount > MAX_AGE) {
if (!getLevel().isClientSide && tickCount > MAX_AGE) {
discard();
}
if (level.isClientSide && random.nextBoolean()) {
if (getLevel().isClientSide && random.nextBoolean()) {
float r = (EnderAirBottleEntity.PARTICLE_COLOR >> 16 & 0xFF) / 255.0F;
float g = (EnderAirBottleEntity.PARTICLE_COLOR >> 8 & 0xFF) / 255.0F;
float b = (EnderAirBottleEntity.PARTICLE_COLOR & 0xFF) / 255.0F;
for (int i = 0; i < 5; i++) {
double x = this.getX() + random.nextDouble();
double y = this.getY() + random.nextDouble();
double z = this.getZ() + random.nextDouble();
level.addAlwaysVisibleParticle(ParticleTypes.ENTITY_EFFECT, x, y, z, r, g, b);
getLevel().addAlwaysVisibleParticle(ParticleTypes.ENTITY_EFFECT, x, y, z, r, g, b);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected void defineSynchedData() {}
public void tick() {
super.tick();

if (!hasBeenInAir && !level.isClientSide) {
if (!hasBeenInAir && !getLevel().isClientSide) {
var bs = getFeetBlockState();
hasBeenInAir = bs.isAir() || isInWater() || isInLava();
}
Expand All @@ -65,13 +65,13 @@ public void tick() {
float xs = (float) (Math.random() - 0.5) * dist;
float ys = (float) (Math.random() - 0.5) * dist;
float zs = (float) (Math.random() - 0.5) * dist;
level.addAlwaysVisibleParticle(data, getX() + xs, getY() + ys, getZ() + zs, 0, 0, 0);
getLevel().addAlwaysVisibleParticle(data, getX() + xs, getY() + ys, getZ() + zs, 0, 0, 0);
}

Entity thrower = getOwner();
if (!level.isClientSide && thrower != null) {
if (!getLevel().isClientSide && thrower != null) {
AABB axis = new AABB(getX(), getY(), getZ(), xOld, yOld, zOld).inflate(2);
List<LivingEntity> entities = level.getEntitiesOfClass(LivingEntity.class, axis);
List<LivingEntity> entities = getLevel().getEntitiesOfClass(LivingEntity.class, axis);
for (LivingEntity living : entities) {
if (living == thrower) {
continue;
Expand All @@ -97,7 +97,7 @@ protected void onHitEntity(@NotNull EntityHitResult hit) {
if (e instanceof Villager) {
return;
}
if (!level.isClientSide) {
if (!getLevel().isClientSide) {
if (e != getOwner() && e.isAlive()) {
if (getOwner() instanceof Player player) {
e.hurt(DamageSource.playerAttack(player), Math.random() < 0.25 ? 10 : 5);
Expand All @@ -112,9 +112,9 @@ protected void onHitEntity(@NotNull EntityHitResult hit) {
@Override
protected void onHitBlock(BlockHitResult hit) {
super.onHitBlock(hit);
if (!level.isClientSide) {
if (!getLevel().isClientSide) {
BlockPos bpos = hit.getBlockPos();
BlockState state = level.getBlockState(bpos);
BlockState state = getLevel().getBlockState(bpos);
if (hasBeenInAir) {
if (BotaniaConfig.common().blockBreakParticles() && !state.isAir()) {
this.getLevel().levelEvent(2001, bpos, Block.getId(state));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,28 +48,28 @@ public void baseTick() {
a = 45 + a;
}

if (level.random.nextInt(tickCount < 90 ? 8 : 20) == 0) {
if (getLevel().random.nextInt(tickCount < 90 ? 8 : 20) == 0) {
float rad = (float) (a * 4 * Math.PI / 180F);
double x = Math.cos(rad) * renderRadius;
double z = Math.sin(rad) * renderRadius;

WispParticleData data1 = WispParticleData.wisp(0.65F + (float) Math.random() * 0.45F, 1F, (float) Math.random() * 0.25F, (float) Math.random() * 0.25F);
level.addParticle(data1, getX() + x, getY() - 0.2, getZ() + z, (float) (Math.random() - 0.5F) * 0.15F, 0.055F + (float) Math.random() * 0.025F, (float) (Math.random() - 0.5F) * 0.15F);
getLevel().addParticle(data1, getX() + x, getY() - 0.2, getZ() + z, (float) (Math.random() - 0.5F) * 0.15F, 0.055F + (float) Math.random() * 0.025F, (float) (Math.random() - 0.5F) * 0.15F);

float gs = (float) Math.random() * 0.15F;
float smokeRadius = (float) (renderRadius - Math.random() * renderRadius * 0.9);
x = Math.cos(rad) * smokeRadius;
z = Math.sin(rad) * smokeRadius;
WispParticleData data = WispParticleData.wisp(0.65F + (float) Math.random() * 0.45F, gs, gs, gs, 1);
level.addParticle(data, getX() + x, getY() - 0.2, getZ() + z, 0, -(-0.155F - (float) Math.random() * 0.025F), 0);
getLevel().addParticle(data, getX() + x, getY() - 0.2, getZ() + z, 0, -(-0.155F - (float) Math.random() * 0.025F), 0);
}
}

if (level.random.nextInt(20) == 0) {
level.playLocalSound(getX(), getY(), getZ(), SoundEvents.FIRE_AMBIENT, SoundSource.BLOCKS, 1F, 1F, false);
if (getLevel().random.nextInt(20) == 0) {
getLevel().playLocalSound(getX(), getY(), getZ(), SoundEvents.FIRE_AMBIENT, SoundSource.BLOCKS, 1F, 1F, false);
}

if (level.isClientSide) {
if (getLevel().isClientSide) {
return;
}

Expand All @@ -80,7 +80,7 @@ public void baseTick() {

if (tickCount > 45) {
AABB boundingBox = new AABB(getX(), getY(), getZ(), getX(), getY(), getZ()).inflate(radius, radius, radius);
List<LivingEntity> entities = level.getEntitiesOfClass(LivingEntity.class, boundingBox);
List<LivingEntity> entities = getLevel().getEntitiesOfClass(LivingEntity.class, boundingBox);

if (entities.isEmpty()) {
return;
Expand Down
Loading

0 comments on commit 3c601bc

Please sign in to comment.