Tweak BER
All checks were successful
EnergonRelics/pipeline/head This commit looks good

This commit is contained in:
TheBrokenRail 2020-07-31 18:53:51 -04:00
parent 57ce8f7d78
commit 45e7a86674
5 changed files with 43 additions and 57 deletions

View File

@ -10,7 +10,6 @@ import net.minecraft.block.Block;
import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.ShapeContext;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher;
@ -21,8 +20,7 @@ import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.IntProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.util.math.Direction;
import net.minecraft.world.BlockView;
import java.util.function.Function;
@ -33,7 +31,7 @@ public class HolographicSkyBlock extends EnergyBlock {
public static final IntProperty LIGHT_LEVEL = IntProperty.of("light_level", 0, 15);
public HolographicSkyBlock() {
super(FabricBlockSettings.copy(Blocks.OBSIDIAN).sounds(BlockSoundGroup.GLASS).nonOpaque().allowsSpawning((state, world, pos, type) -> !state.get(POWERED)).solidBlock((state, world, pos) -> !state.get(POWERED)).suffocates((state, world, pos) -> !state.get(POWERED)).lightLevel(state -> state.get(POWERED) ? 7 : 0).blockVision((state, world, pos) -> !state.get(POWERED)));
super(FabricBlockSettings.copy(Blocks.OBSIDIAN).sounds(BlockSoundGroup.GLASS).nonOpaque().allowsSpawning((state, world, pos, type) -> !state.get(POWERED)).solidBlock((state, world, pos) -> !state.get(POWERED)).suffocates((state, world, pos) -> !state.get(POWERED)).lightLevel(state -> state.get(LIGHT_LEVEL)).blockVision((state, world, pos) -> !state.get(POWERED)));
setDefaultState(getDefaultState().with(POWERED, false).with(LIGHT_LEVEL, 0));
}
@ -44,12 +42,7 @@ public class HolographicSkyBlock extends EnergyBlock {
@Override
public boolean isTranslucent(BlockState state, BlockView world, BlockPos pos) {
return true;
}
@Override
public VoxelShape getVisualShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return VoxelShapes.empty();
return state.get(POWERED);
}
@Override
@ -57,6 +50,18 @@ public class HolographicSkyBlock extends EnergyBlock {
return state.get(POWERED) ? BlockRenderType.ENTITYBLOCK_ANIMATED : BlockRenderType.MODEL;
}
@Environment(EnvType.CLIENT)
@Override
public boolean isSideInvisible(BlockState state, BlockState stateFrom, Direction direction) {
return state == stateFrom || super.isSideInvisible(state, stateFrom, direction);
}
@Override
@Environment(EnvType.CLIENT)
public float getAmbientOcclusionLightLevel(BlockState state, BlockView world, BlockPos pos) {
return state.get(POWERED) ? 1f : super.getAmbientOcclusionLightLevel(state, world, pos);
}
@Override
protected Function<BlockEntityType<BlockEntity>, BlockEntity> getFactory() {
return HolographicSkyBlockEntity::new;

View File

@ -36,13 +36,4 @@ public class HolographicSkyBlockEntity extends EnergyReceiverBlockEntity {
getWorld().setBlockState(getPos(), getCachedState().with(HolographicSkyBlock.LIGHT_LEVEL, newLightLevel));
}
}
@Environment(EnvType.CLIENT)
public boolean shouldDrawSide(Direction direction) {
if (getWorld() != null) {
return Block.shouldDrawSide(getCachedState(), getWorld(), getPos(), direction);
} else {
return true;
}
}
}

View File

@ -29,7 +29,7 @@ public class HighlightBlockEntityRenderer extends BlockEntityRenderer<BlockEntit
}
private static RenderLayer getLayer(Identifier texture) {
return RenderLayer.of(EnergonRelics.NAMESPACE + ":highlight", VertexFormats.POSITION_COLOR, 7, 256, false, true, RenderLayer.MultiPhaseParameters.builder().transparency(RenderPhaseAccessor.getTRANSLUCENT_TRANSPARENCY()).layering(RenderPhaseAccessor.getVIEW_OFFSET_Z_LAYERING()).texture(new RenderPhase.Texture(texture, false, false)).fog(RenderPhaseAccessor.getNO_FOG()).target(RenderPhaseAccessor.getITEM_TARGET()).build(false));
return RenderLayer.of(EnergonRelics.NAMESPACE + ":highlight", VertexFormats.POSITION_COLOR, 7, 256, false, true, RenderLayer.MultiPhaseParameters.builder().transparency(RenderPhaseAccessor.getTRANSLUCENT_TRANSPARENCY()).layering(RenderPhaseAccessor.getVIEW_OFFSET_Z_LAYERING()).texture(new RenderPhase.Texture(texture, false, false)).fog(RenderPhaseAccessor.getNO_FOG()).cull(RenderPhaseAccessor.getENABLE_CULLING()).build(false));
}
private static final RenderLayer SELECTED_LAYER = getLayer(new Identifier(EnergonRelics.NAMESPACE, "textures/entity/selected_energy_block.png"));
@ -61,10 +61,10 @@ public class HighlightBlockEntityRenderer extends BlockEntityRenderer<BlockEntit
renderSide(entity, matrix4f, vertexConsumer, 1f, 1f, 1f, 0f, 0f, 1f, 1f, 0f, Direction.EAST);
renderSide(entity, matrix4f, vertexConsumer, 0f, 0f, 0f, 1f, 0f, 1f, 1f, 0f, Direction.WEST);
renderSide(entity, matrix4f, vertexConsumer, 0f, 1f, 0f, 0f, 0f, 0f, 1f, 1f, Direction.DOWN);
renderSide(entity, matrix4f, vertexConsumer, 0f, 1f, 1.0f, 1.0f, 1f, 1f, 0f, 0f, Direction.UP);
renderSide(entity, matrix4f, vertexConsumer, 0f, 1f, 1f, 1f, 1f, 1f, 0f, 0f, Direction.UP);
}
private boolean shouldDrawSide(BlockEntity entity, Direction side) {
protected boolean shouldDrawSide(BlockEntity entity, Direction side) {
BlockState state = entity.getCachedState();
return Block.shouldDrawSide(state, Objects.requireNonNull(entity.getWorld()), entity.getPos(), side);
}

View File

@ -4,6 +4,7 @@ import com.mojang.blaze3d.systems.RenderSystem;
import com.thebrokenrail.energonrelics.EnergonRelics;
import com.thebrokenrail.energonrelics.block.HolographicSkyBlock;
import com.thebrokenrail.energonrelics.block.entity.HolographicSkyBlockEntity;
import com.thebrokenrail.energonrelics.mixin.RenderPhaseAccessor;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.block.entity.BlockEntity;
@ -15,7 +16,6 @@ import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher;
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Matrix4f;
@ -23,24 +23,18 @@ import net.minecraft.util.math.Matrix4f;
@Environment(EnvType.CLIENT)
public class HolographicSkyBlockEntityRenderer extends HighlightBlockEntityRenderer {
@SuppressWarnings("deprecation")
private static final RenderPhase.Target SKY_TARGET = new RenderPhase.Target("fasterthanc_sky_target", () -> {
private static final RenderPhase.Texturing SKY_TEXTURING = new RenderPhase.Texturing(EnergonRelics.NAMESPACE + ":sky_texturing", () -> {
RenderSystem.pushMatrix();
RenderSystem.enableTexture();
WorldWithSky worldWithSky = (WorldWithSky) MinecraftClient.getInstance().worldRenderer;
worldWithSky.getSky().beginRead();
}, () -> {
WorldWithSky worldWithSky = (WorldWithSky) MinecraftClient.getInstance().worldRenderer;
worldWithSky.getSky().endRead();
RenderSystem.popMatrix();
});
@SuppressWarnings("deprecation")
private static final RenderPhase.Texturing SKY_TEXTURING = new RenderPhase.Texturing("fasterthanc_sky_texturing", () -> {
RenderSystem.pushMatrix();
RenderSystem.matrixMode(5890);
RenderSystem.pushMatrix();
RenderSystem.loadIdentity();
RenderSystem.translatef(0.5F, 0.5F, 0.0F);
RenderSystem.scalef(0.5F, 0.5F, 1.0F);
RenderSystem.translatef(0.5F, 0.5F, 0f);
RenderSystem.scalef(0.5F, 0.5F, 1f);
RenderSystem.mulTextureByProjModelView();
RenderSystem.matrixMode(5888);
RenderSystem.setupEndPortalTexGen();
@ -50,6 +44,10 @@ public class HolographicSkyBlockEntityRenderer extends HighlightBlockEntityRende
RenderSystem.matrixMode(5888);
RenderSystem.clearTexGen();
RenderSystem.popMatrix();
WorldWithSky worldWithSky = (WorldWithSky) MinecraftClient.getInstance().worldRenderer;
worldWithSky.getSky().endRead();
RenderSystem.popMatrix();
});
public interface WorldWithSky {
@ -61,7 +59,7 @@ public class HolographicSkyBlockEntityRenderer extends HighlightBlockEntityRende
}
private static RenderLayer getLayer() {
return RenderLayer.of(EnergonRelics.NAMESPACE + ":holographic_sky", VertexFormats.POSITION_COLOR, 7, 256, false, true, RenderLayer.MultiPhaseParameters.builder().target(SKY_TARGET).texturing(SKY_TEXTURING).build(false));
return RenderLayer.of(EnergonRelics.NAMESPACE + ":holographic_sky", VertexFormats.POSITION_COLOR, 7, 256, false, false, RenderLayer.MultiPhaseParameters.builder().texturing(SKY_TEXTURING).cull(RenderPhaseAccessor.getENABLE_CULLING()).layering(RenderPhaseAccessor.getVIEW_OFFSET_Z_LAYERING()).build(false));
}
private static final RenderLayer LAYER = getLayer();
@ -70,36 +68,28 @@ public class HolographicSkyBlockEntityRenderer extends HighlightBlockEntityRende
public void render(BlockEntity entity, float f, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, int j) {
if (entity instanceof HolographicSkyBlockEntity && entity.getCachedState().get(HolographicSkyBlock.POWERED)) {
matrixStack.push();
float g = getHeight();
Matrix4f matrix4f = matrixStack.peek().getModel();
renderLayer((HolographicSkyBlockEntity) entity, g, matrix4f, vertexConsumerProvider.getBuffer(LAYER));
renderLayer((HolographicSkyBlockEntity) entity, matrix4f, vertexConsumerProvider.getBuffer(LAYER));
matrixStack.pop();
}
super.render(entity, f, matrixStack, vertexConsumerProvider, i, j);
}
private void renderLayer(HolographicSkyBlockEntity entity, float f, Matrix4f matrix4f, VertexConsumer vertexConsumer) {
float h = 1f;
float i = 1f;
float j = 1f;
renderSide(entity, matrix4f, vertexConsumer, 0.0F, 1.0F, 0.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, h, i, j, Direction.SOUTH);
renderSide(entity, matrix4f, vertexConsumer, 0.0F, 1.0F, 1.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, h, i, j, Direction.NORTH);
renderSide(entity, matrix4f, vertexConsumer, 1.0F, 1.0F, 1.0F, 0.0F, 0.0F, 1.0F, 1.0F, 0.0F, h, i, j, Direction.EAST);
renderSide(entity, matrix4f, vertexConsumer, 0.0F, 0.0F, 0.0F, 1.0F, 0.0F, 1.0F, 1.0F, 0.0F, h, i, j, Direction.WEST);
renderSide(entity, matrix4f, vertexConsumer, 0.0F, 1.0F, 0.0F, 0.0F, 0.0F, 0.0F, 1.0F, 1.0F, h, i, j, Direction.DOWN);
renderSide(entity, matrix4f, vertexConsumer, 0.0F, 1.0F, f, f, 1.0F, 1.0F, 0.0F, 0.0F, h, i, j, Direction.UP);
private void renderLayer(HolographicSkyBlockEntity entity, Matrix4f matrix4f, VertexConsumer vertexConsumer) {
renderSide(entity, matrix4f, vertexConsumer, 0f, 1f, 0f, 1f, 1f, 1f, 1f, 1f, Direction.SOUTH);
renderSide(entity, matrix4f, vertexConsumer, 0f, 1f, 1f, 0f, 0f, 0f, 0f, 0f, Direction.NORTH);
renderSide(entity, matrix4f, vertexConsumer, 1f, 1f, 1f, 0f, 0f, 1f, 1f, 0f, Direction.EAST);
renderSide(entity, matrix4f, vertexConsumer, 0f, 0f, 0f, 1f, 0f, 1f, 1f, 0f, Direction.WEST);
renderSide(entity, matrix4f, vertexConsumer, 0f, 1f, 0f, 0f, 0f, 0f, 1f, 1f, Direction.DOWN);
renderSide(entity, matrix4f, vertexConsumer, 0f, 1f, 1f, 1f, 1f, 1f, 0f, 0f, Direction.UP);
}
private void renderSide(HolographicSkyBlockEntity entity, Matrix4f matrix4f, VertexConsumer vertexConsumer, float f, float g, float h, float i, float j, float k, float l, float m, float n, float o, float p, Direction side) {
if (entity.shouldDrawSide(side)) {
vertexConsumer.vertex(matrix4f, f, h, j).color(n, o, p, 1.0F).next();
vertexConsumer.vertex(matrix4f, g, h, k).color(n, o, p, 1.0F).next();
vertexConsumer.vertex(matrix4f, g, i, l).color(n, o, p, 1.0F).next();
vertexConsumer.vertex(matrix4f, f, i, m).color(n, o, p, 1.0F).next();
private void renderSide(HolographicSkyBlockEntity entity, Matrix4f matrix4f, VertexConsumer vertexConsumer, float f, float g, float h, float i, float j, float k, float l, float m, Direction side) {
if (shouldDrawSide(entity, side)) {
vertexConsumer.vertex(matrix4f, f, h, j).color(1f, 1f, 1f, 1f).next();
vertexConsumer.vertex(matrix4f, g, h, k).color(1f, 1f, 1f, 1f).next();
vertexConsumer.vertex(matrix4f, g, i, l).color(1f, 1f, 1f, 1f).next();
vertexConsumer.vertex(matrix4f, f, i, m).color(1f, 1f, 1f, 1f).next();
}
}
protected float getHeight() {
return 1f;
}
}

View File

@ -22,7 +22,7 @@ public interface RenderPhaseAccessor {
}
@Accessor
static RenderPhase.Target getITEM_TARGET() {
static RenderPhase.Cull getENABLE_CULLING() {
throw new UnsupportedOperationException();
}
}