Skip to content

Commit

Permalink
Work around always day dimensions not being properly recognized as be…
Browse files Browse the repository at this point in the history
…ing day mekanism#6801
  • Loading branch information
pupnewfster committed Jan 28, 2021
1 parent 78785cc commit bd4b592
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import net.minecraft.block.BlockState;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

public class TileEntityAdvancedSolarGenerator extends TileEntitySolarGenerator implements IBoundingBlock, IEvaporationSolar {

Expand Down Expand Up @@ -60,9 +59,8 @@ public void onBreak(BlockState oldState) {
}

@Override
protected boolean canSeeSky() {
World world = getWorld();
return world != null && world.canBlockSeeSky(getPos().up(2));
protected BlockPos getSkyCheckPos() {
return pos.up(2);
}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import mekanism.common.util.WorldUtils;
import mekanism.generators.common.config.MekanismGeneratorsConfig;
import mekanism.generators.common.registries.GeneratorsBlocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.Biome.RainType;
Expand Down Expand Up @@ -82,11 +83,7 @@ protected void onUpdateServer() {
// Sort out if the generator can see the sun; we no longer check if it's raining here,
// since under the new rules, we can still generate power when it's raining, albeit at a
// significant penalty.
World world = getWorld();
if (world != null) {
seesSun = world.isDaytime() && canSeeSky() && world.getDimensionType().hasSkyLight();
}

seesSun = WorldUtils.canSeeSun(world, getSkyCheckPos());
if (seesSun && MekanismUtils.canFunction(this) && !getEnergyContainer().getNeeded().isZero()) {
setActive(true);
FloatingLong production = getProduction();
Expand All @@ -97,9 +94,8 @@ protected void onUpdateServer() {
}
}

protected boolean canSeeSky() {
World world = getWorld();
return world != null && world.canBlockSeeSky(getPos());
protected BlockPos getSkyCheckPos() {
return pos;
}

public FloatingLong getProduction() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ public GasToGasRecipe getRecipe(int cacheIndex) {
private boolean canFunction() {
// Sort out if the solar neutron activator can see the sun; we no longer check if it's raining here,
// since under the new rules, we can still function when it's raining, albeit at a significant penalty.
boolean seesSun = world.isDaytime() && world.canBlockSeeSky(pos.up()) && world.getDimensionType().hasSkyLight();
return seesSun && MekanismUtils.canFunction(this);
return MekanismUtils.canFunction(this) && WorldUtils.canSeeSun(world, pos.up());
}

private float recalculateProductionRate() {
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/mekanism/common/util/WorldUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,22 @@ public static float getSunBrightness(World world, float partialTicks) {
return f1 * 0.8F + 0.2F;
}

/**
* Checks to see if the block at the position can see the sky and it is daytime.
*
* @param world World to check in.
* @param pos Position to check.
*
* @return {@code true} if it can.
*/
@Contract("null, _ -> false")
public static boolean canSeeSun(@Nullable World world, BlockPos pos) {
//Note: We manually handle the world#isDaytime check by just checking the subtracted skylight
// as vanilla returns false if the world's time is set to a fixed value even if that time
// would effectively be daytime
return world != null && world.getDimensionType().hasSkyLight() && world.getSkylightSubtracted() < 4 && world.canBlockSeeSky(pos);
}

/**
* Converts a {@link BlockPos} to a long representing the {@link ChunkPos} it is in without creating a temporary {@link ChunkPos} object.
*
Expand Down

0 comments on commit bd4b592

Please sign in to comment.