Skip to content

Commit

Permalink
check level instanceof instead of isClientSide
Browse files Browse the repository at this point in the history
Closes #645
  • Loading branch information
ThatGravyBoat committed Nov 9, 2024
1 parent 348b02b commit a45bf41
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static FlagContent fromTag(CompoundTag tag) {
String type = tag.getString("type");
Tag content = tag.get("content");
if (content == null) return null;
return switch (type) {
return switch (type.intern()) {
case ImageContent.TYPE -> ImageContent.of(content.getAsString());
case UrlContent.TYPE -> UrlContent.of(content.getAsString());
default -> null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, Block
tickable.tick(entityLevel, time, blockState, pos);
if (level.isClientSide()) {
tickable.clientTick((ClientLevel) level, time, state, pos);
} else {
tickable.serverTick((ServerLevel) level, time, state, pos);
tickable.internalServerTick((ServerLevel) level, time, state, pos);
} else if (level instanceof ServerLevel serverLevel) {
tickable.serverTick(serverLevel, time, state, pos);
tickable.internalServerTick(serverLevel, time, state, pos);
}
if (!tickable.isInitialized()) tickable.firstTick(level, pos, state);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public float getGravity(ResourceKey<Level> level) {

@Override
public float getGravity(Level level, BlockPos pos) {
if (level.isClientSide()) return getGravity(level);
return PlanetHandler.getGravity((ServerLevel) level, pos);
if (!(level instanceof ServerLevel serverLevel)) return getGravity(level);
return PlanetHandler.getGravity(serverLevel, pos);
}

@Override
Expand All @@ -48,14 +48,14 @@ public float getGravity(Entity entity) {

@Override
public void setGravity(Level level, BlockPos pos, float gravity) {
if (level.isClientSide()) return;
PlanetHandler.setGravity((ServerLevel) level, pos, gravity);
if (!(level instanceof ServerLevel serverLevel)) return;
PlanetHandler.setGravity(serverLevel, pos, gravity);
}

@Override
public void setGravity(Level level, Collection<BlockPos> positions, float gravity) {
if (level.isClientSide()) return;
PlanetHandler.setGravity((ServerLevel) level, positions, gravity);
if (!(level instanceof ServerLevel serverLevel)) return;
PlanetHandler.setGravity(serverLevel, positions, gravity);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public boolean hasOxygen(ResourceKey<Level> level) {

@Override
public boolean hasOxygen(Level level, BlockPos pos) {
if (level.isClientSide()) return hasOxygen(level);
return PlanetHandler.hasOxygen((ServerLevel) level, pos);
if (!(level instanceof ServerLevel serverLevel)) return hasOxygen(level);
return PlanetHandler.hasOxygen(serverLevel, pos);
}

@Override
Expand All @@ -45,14 +45,14 @@ public boolean hasOxygen(Entity entity) {

@Override
public void setOxygen(Level level, BlockPos pos, boolean oxygen) {
if (level.isClientSide()) return;
PlanetHandler.setOxygen((ServerLevel) level, pos, oxygen);
if (!(level instanceof ServerLevel serverLevel)) return;
PlanetHandler.setOxygen(serverLevel, pos, oxygen);
}

@Override
public void setOxygen(Level level, Collection<BlockPos> positions, boolean oxygen) {
if (level.isClientSide()) return;
PlanetHandler.setOxygen((ServerLevel) level, positions, oxygen);
if (!(level instanceof ServerLevel serverLevel)) return;
PlanetHandler.setOxygen(serverLevel, positions, oxygen);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public short getTemperature(ResourceKey<Level> level) {

@Override
public short getTemperature(Level level, BlockPos pos) {
if (level.isClientSide()) return getTemperature(level);
return PlanetHandler.getTemperature((ServerLevel) level, pos);
if (!(level instanceof ServerLevel serverLevel)) return getTemperature(level);
return PlanetHandler.getTemperature(serverLevel, pos);
}

@Override
Expand All @@ -48,14 +48,14 @@ public short getTemperature(Entity entity) {

@Override
public void setTemperature(Level level, BlockPos pos, short temperature) {
if (level.isClientSide()) return;
PlanetHandler.setTemperature((ServerLevel) level, pos, temperature);
if (!(level instanceof ServerLevel serverLevel)) return;
PlanetHandler.setTemperature(serverLevel, pos, temperature);
}

@Override
public void setTemperature(Level level, Collection<BlockPos> positions, short temperature) {
if (level.isClientSide()) return;
PlanetHandler.setTemperature((ServerLevel) level, positions, temperature);
if (!(level instanceof ServerLevel serverLevel)) return;
PlanetHandler.setTemperature(serverLevel, positions, temperature);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ public static boolean hasStation(String url) {
private static JsonObject readLocalStations() {
String stationsFile = System.getProperty("adastra.stations");
if (stationsFile != null) {
String fileName = stationsFile.indexOf('/') == -1 ? stationsFile : stationsFile.substring(stationsFile.lastIndexOf('/') + 1);
try {
String fileName = stationsFile.indexOf('/') == -1 ? stationsFile : stationsFile.substring(stationsFile.lastIndexOf('/') + 1);
AdAstra.LOGGER.info("Loading stations from {}", fileName);
return GsonHelpers.parseJson(Files.readString(Path.of(stationsFile))).orElse(null);
} catch (Exception ignored) {
} catch (Exception exception) {
AdAstra.LOGGER.error("Failed loading stations from {}", fileName, exception);
return null;
}
}
Expand Down

0 comments on commit a45bf41

Please sign in to comment.