Fix crash rendering biome-tinted blocks on contraptions

- Biome colors now line up with the world
This commit is contained in:
Jozufozu 2022-01-07 14:18:59 -08:00
parent 0ff67382ee
commit e6914b1a6f
3 changed files with 18 additions and 7 deletions

View file

@ -19,7 +19,7 @@ parchment_version = 2021.12.19
# dependency versions # dependency versions
registrate_version = MC1.18-1.0.21 registrate_version = MC1.18-1.0.21
flywheel_version = 1.18-0.5.1.40 flywheel_version = 1.18-0.5.1.42
jei_minecraft_version = 1.18 jei_minecraft_version = 1.18
jei_version = 9.0.0.40 jei_version = 9.0.0.40

View file

@ -5,6 +5,7 @@ import com.simibubi.create.foundation.utility.worldWrappers.WrappedWorld;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundSource; import net.minecraft.sounds.SoundSource;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Blocks;
@ -14,14 +15,24 @@ import net.minecraft.world.phys.Vec3;
public class ContraptionWorld extends WrappedWorld { public class ContraptionWorld extends WrappedWorld {
final Contraption contraption; final Contraption contraption;
private final int minY;
private final int height;
public ContraptionWorld(Level world, Contraption contraption) { public ContraptionWorld(Level world, Contraption contraption) {
super(world); super(world);
this.contraption = contraption; this.contraption = contraption;
}
@Override minY = nextMultipleOf16(contraption.bounds.minY);
height = nextMultipleOf16(contraption.bounds.maxY) - minY;
}
// https://math.stackexchange.com/questions/291468
private static int nextMultipleOf16(double a) {
return (((Math.abs((int) a) - 1) | 15) + 1) * Mth.sign(a);
}
@Override
public BlockState getBlockState(BlockPos pos) { public BlockState getBlockState(BlockPos pos) {
StructureTemplate.StructureBlockInfo blockInfo = contraption.getBlocks().get(pos); StructureTemplate.StructureBlockInfo blockInfo = contraption.getBlocks().get(pos);
@ -51,11 +62,11 @@ public class ContraptionWorld extends WrappedWorld {
@Override @Override
public int getHeight() { public int getHeight() {
return getMinBuildHeight() * (-2); return height;
} }
@Override @Override
public int getMinBuildHeight() { public int getMinBuildHeight() {
return - (int) contraption.bounds.getYsize(); return minY;
} }
} }

View file

@ -106,7 +106,7 @@ public class ContraptionRenderDispatcher {
public static VirtualRenderWorld setupRenderWorld(Level world, Contraption c) { public static VirtualRenderWorld setupRenderWorld(Level world, Contraption c) {
ContraptionWorld contraptionWorld = c.getContraptionWorld(); ContraptionWorld contraptionWorld = c.getContraptionWorld();
VirtualRenderWorld renderWorld = new VirtualRenderWorld(world, contraptionWorld.getHeight(), contraptionWorld.getMinBuildHeight()); VirtualRenderWorld renderWorld = new VirtualRenderWorld(world, c.anchor, contraptionWorld.getHeight(), contraptionWorld.getMinBuildHeight());
renderWorld.setBlockEntities(c.presentTileEntities.values()); renderWorld.setBlockEntities(c.presentTileEntities.values());