Created portal render layer

Changes to be committed:
	modified:   src/main/java/org/dimdev/dimdoors/block/DimensionalDoorBlock.java
	modified:   src/main/java/org/dimdev/dimdoors/client/DimensionalPortalRenderer.java
	modified:   src/main/java/org/dimdev/dimdoors/client/EntranceRiftBlockEntityRenderer.java
	modified:   src/main/java/org/dimdev/dimdoors/client/MyRenderLayer.java
This commit is contained in:
SD 2020-08-22 21:24:22 +05:30
parent 4840001a46
commit ce201f3b14
No known key found for this signature in database
GPG key ID: E36B57EE08544BC5
4 changed files with 106 additions and 39 deletions

View file

@ -80,7 +80,7 @@ public class DimensionalDoorBlock extends DoorBlock implements RiftProvider<Entr
// TODO: Also notify player in case of error, don't crash
if (bottomEntity instanceof EntranceRiftBlockEntity && topEntity instanceof EntranceRiftBlockEntity) {
LOGGER.error("Dimensional door at " + pos + " in world " + world + " contained two rifts, please report this. Defaulting to bottom.");
LOGGER.warn("Dimensional door at " + pos + " in world " + world + " contained two rifts, please report this. Defaulting to bottom.");
return (EntranceRiftBlockEntity) bottomEntity;
} else if (bottomEntity instanceof EntranceRiftBlockEntity) {
return (EntranceRiftBlockEntity) bottomEntity;

View file

@ -50,24 +50,27 @@ import static org.lwjgl.opengl.GL11.*;
@Environment(EnvType.CLIENT)
public final class DimensionalPortalRenderer {
private static final FloatBuffer BUFFER = GlAllocationUtils.allocateFloatBuffer(16);
private static final Identifier WARP_PATH = new Identifier("dimdoors:textures/other/warp.png");
private static final BooleanProperty OPEN_PROPERTY = BooleanProperty.of("open");
private static final EnumProperty<DoorHinge> HINGE_PROPERTY = EnumProperty.of("hinge", DoorHinge.class);
private static final DirectionProperty FACING_PROPERTY = DirectionProperty.of("facing", Arrays.asList(DirectionAccessor.getHorizontal()));
private static final FloatBuffer buffer = GlAllocationUtils.allocateFloatBuffer(16);
private static final Identifier warpPath = new Identifier("dimdoors:textures/other/warp.png");
private static final BooleanProperty openProperty = BooleanProperty.of("open");
private static final EnumProperty<DoorHinge> hingeProperty = EnumProperty.of("hinge", DoorHinge.class);
private static final DirectionProperty facingProperty = DirectionProperty.of("facing", Arrays.asList(DirectionAccessor.getHorizontal()));
private static final TextureManager textureManager = MinecraftClient.getInstance().getTextureManager();
private static final BlockModels blockModelShapes = MinecraftClient.getInstance().getBlockRenderManager().getModels();
private static final BakedModelManager modelManager = blockModelShapes.getModelManager();
private static final TextureManager TEXTURE_MANAGER = MinecraftClient.getInstance().getTextureManager();
private static final BlockModels BLOCK_MODELS = MinecraftClient.getInstance().getBlockRenderManager().getModels();
private static final BakedModelManager MODEL_MANAGER = BLOCK_MODELS.getModelManager();
private static final VectorNi COLORLESS = new VectorNi(255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255);
public static Identifier getWarpPath() {
return WARP_PATH;
}
// TODO: any render angle
/**
* Renders a dimensional portal, for use in various situations. Code is mostly based
* on vanilla's TileEntityEndGatewayRenderer.
* on vanilla's EndGatewayBlockEntityRenderer.
*
* @param x The x coordinate of the wall's center.
* @param y The y coordinate of the wall's center.
@ -90,7 +93,7 @@ public final class DimensionalPortalRenderer {
float scale = 0.2625F;
float colorMultiplier = 1.0F / (translationScale + .80F);
MinecraftClient.getInstance().getTextureManager().bindTexture(warpPath);
MinecraftClient.getInstance().getTextureManager().bindTexture(WARP_PATH);
RenderSystem.enableBlend();
if (pass == 0) {
@ -389,7 +392,7 @@ public final class DimensionalPortalRenderer {
RenderSystem.enableTexture();
//RenderSystem.disableDepth();
textureManager.bindTexture(SpriteAtlasTexture.BLOCK_ATLAS_TEX);
TEXTURE_MANAGER.bindTexture(SpriteAtlasTexture.BLOCK_ATLAS_TEX);
Block stonebrick = Blocks.STONE_BRICKS;
BlockState stonebrickState = stonebrick.getDefaultState();
Map<BlockState, ModelIdentifier> stonebrickMap = Maps.newHashMap();
@ -448,7 +451,7 @@ public final class DimensionalPortalRenderer {
RenderSystem.translated(pos.getX(), pos.getY(), pos.getZ());
textureManager.bindTexture(SpriteAtlasTexture.BLOCK_ATLAS_TEX);
TEXTURE_MANAGER.bindTexture(SpriteAtlasTexture.BLOCK_ATLAS_TEX);
Map<BlockState, ModelIdentifier> doorMap = Maps.newHashMap();
@ -459,13 +462,13 @@ public final class DimensionalPortalRenderer {
BlockState doorBottomState = blockEntity.getWorld().getBlockState(blockEntity.getPos());
BlockState doorTopState = blockEntity.getWorld().getBlockState(blockEntity.getPos().up());
if (doorBottomState.getBlock() instanceof DoorBlock && doorTopState.getBlock() instanceof DoorBlock) {
doorBottomState = doorBottomState.with(hingeProperty, doorTopState.get(hingeProperty));
doorBottomState = doorBottomState.with(HINGE_PROPERTY, doorTopState.get(HINGE_PROPERTY));
// System.out.println();
// System.out.println("---------------------------------------------");
// System.out.println(doorBottomState.getProperties());
// System.out.println("---------------------------------------------");
doorTopState = doorTopState.with(openProperty, doorBottomState.get(openProperty))
.with(facingProperty, doorBottomState.get(facingProperty));
doorTopState = doorTopState.with(OPEN_PROPERTY, doorBottomState.get(OPEN_PROPERTY))
.with(FACING_PROPERTY, doorBottomState.get(FACING_PROPERTY));
//System.out.println(doorTopState);
//System.out.println(doorBottomState);
//System.out.println(doorBottomState.getProperties());
@ -474,7 +477,7 @@ public final class DimensionalPortalRenderer {
//System.out.println(doorBottomState.getValue(PropertyEnum.create("hinge", BlockDoor.EnumHingePosition.class)));
//RenderSystem.activeTexture(OpenGlHelper.defaultTexUnit);
RenderSystem.enableTexture();
if (doorBottomState.get(openProperty)) {
if (doorBottomState.get(OPEN_PROPERTY)) {
//RenderSystem.activeTexture(OpenGlHelper.lightmapTexUnit);
// if (!personal) {
// RenderSystem.enableTexture2D();
@ -493,9 +496,9 @@ public final class DimensionalPortalRenderer {
Vector3d doorDepth = depth.mul(doorDistanceMul);
RenderSystem.translated(doorDepth.getX(), doorDepth.getY(), doorDepth.getZ());
drawState(tessellator, worldRenderer, doorMap, doorBottomState.with(openProperty, false), orientation);
drawState(tessellator, worldRenderer, doorMap, doorBottomState.with(OPEN_PROPERTY, false), orientation);
RenderSystem.translated(0, 1, 0);
drawState(tessellator, worldRenderer, doorMap, doorTopState.with(openProperty, false), orientation);
drawState(tessellator, worldRenderer, doorMap, doorTopState.with(OPEN_PROPERTY, false), orientation);
}
@ -532,7 +535,7 @@ public final class DimensionalPortalRenderer {
BakedModel model;
List<BakedQuad> quads;
location = map.get(blockState);
model = modelManager.getModel(location);
model = MODEL_MANAGER.getModel(location);
quads = model.getQuads(null, side, new Random(1));
if (!quads.isEmpty()) {
bufferBuilder.begin(GL_QUADS, VertexFormats.POSITION);
@ -595,9 +598,9 @@ public final class DimensionalPortalRenderer {
}
private static FloatBuffer getBuffer(float f1, float f2, float f3, float f4) {
buffer.clear();
buffer.put(f1).put(f2).put(f3).put(f4);
buffer.flip();
return buffer;
BUFFER.clear();
BUFFER.put(f1).put(f2).put(f3).put(f4);
BUFFER.flip();
return BUFFER;
}
}

View file

@ -1,7 +1,14 @@
package org.dimdev.dimdoors.client;
import java.util.List;
import java.util.Random;
import java.util.stream.IntStream;
import com.google.common.collect.ImmutableList;
import org.dimdev.dimdoors.block.entity.EntranceRiftBlockEntity;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher;
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
@ -9,15 +16,19 @@ import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.client.util.math.Vector3f;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.Matrix4f;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
@Environment(EnvType.CLIENT)
public class EntranceRiftBlockEntityRenderer extends BlockEntityRenderer<EntranceRiftBlockEntity> {
private final Identifier keyPath = new Identifier("dimdoors:textures/other/keyhole.png");
private final Identifier keyholeLight = new Identifier("dimdoors:textures/other/keyhole_light.png");
private static final Identifier KEY_PATH = new Identifier("dimdoors:textures/other/keyhole.png");
private static final Identifier KEYHOLE_LIGHT = new Identifier("dimdoors:textures/other/keyhole_light.png");
private static final Random RANDOM = new Random(31100L);
private static final List<RenderLayer> LAYERS = IntStream.range(0, 16).mapToObj((i) -> {
return MyRenderLayer.getDimensionalPortal(i + 1);
}).collect(ImmutableList.toImmutableList());
public EntranceRiftBlockEntityRenderer(BlockEntityRenderDispatcher blockEntityRenderDispatcher) {
super(blockEntityRenderDispatcher);
@ -28,16 +39,64 @@ public class EntranceRiftBlockEntityRenderer extends BlockEntityRenderer<Entranc
Direction orientation = entrance.getOrientation();
Vector3f vec = orientation.getOpposite().getUnitVector();
vec.scale((float) (orientation == Direction.NORTH || orientation == Direction.WEST || orientation == Direction.UP ? 0.01 : 0.01 - 1));
Vec3d offset = new Vec3d(vec);
DimensionalPortalRenderer.renderDimensionalPortal(
entrance.getPos().getX() + offset.x,
entrance.getPos().getY() + offset.y,
entrance.getPos().getZ() + offset.z,
//entrance.orientation.getHorizontalAngle(),
//entrance.orientation.getDirectionVec().getY() * 90,
orientation,
16,
16,
entrance.getColors(16));
double d = entrance.getPos().getSquaredDistance(this.dispatcher.camera.getPos(), true);
int k = this.method_3592(d);
float g = 0.75F;
Matrix4f matrix4f = matrixStack.peek().getModel();
this.drawAllVertices(entrance, g, 0.15F, matrix4f, vertexConsumerProvider.getBuffer(LAYERS.get(0)));
for(int l = 1; l < k; ++l) {
this.drawAllVertices(entrance, g, 2.0F / (float)(18 - l), matrix4f, vertexConsumerProvider.getBuffer(LAYERS.get(l)));
}
// Vec3d offset = new Vec3d(vec);
// DimensionalPortalRenderer.renderDimensionalPortal(
// entrance.getPos().getX() + offset.x,
// entrance.getPos().getY() + offset.y,
// entrance.getPos().getZ() + offset.z,
// //entrance.orientation.getHorizontalAngle(),
// //entrance.orientation.getDirectionVec().getY() * 90,
// orientation,
// 16,
// 16,
// entrance.getColors(16));
}
protected int method_3592(double d) {
if (d > 36864.0D) {
return 1;
} else if (d > 25600.0D) {
return 3;
} else if (d > 16384.0D) {
return 5;
} else if (d > 9216.0D) {
return 7;
} else if (d > 4096.0D) {
return 9;
} else if (d > 1024.0D) {
return 11;
} else if (d > 576.0D) {
return 13;
} else {
return d > 256.0D ? 14 : 15;
}
}
private void drawAllVertices(EntranceRiftBlockEntity blockEntity, float f, float g, Matrix4f matrix4f, VertexConsumer vertexConsumer) {
float h = (RANDOM.nextFloat() * 0.5F + 0.1F) * g;
float i = (RANDOM.nextFloat() * 0.5F + 0.4F) * g;
float j = (RANDOM.nextFloat() * 0.5F + 0.5F) * g;
this.drawVertices(blockEntity, matrix4f, vertexConsumer, 0.0F, 1.0F, 0.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, h, i, j, Direction.SOUTH);
this.drawVertices(blockEntity, matrix4f, vertexConsumer, 0.0F, 1.0F, 1.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, h, i, j, Direction.NORTH);
this.drawVertices(blockEntity, matrix4f, vertexConsumer, 1.0F, 1.0F, 1.0F, 0.0F, 0.0F, 1.0F, 1.0F, 0.0F, h, i, j, Direction.EAST);
this.drawVertices(blockEntity, matrix4f, vertexConsumer, 0.0F, 0.0F, 0.0F, 1.0F, 0.0F, 1.0F, 1.0F, 0.0F, h, i, j, Direction.WEST);
this.drawVertices(blockEntity, matrix4f, vertexConsumer, 0.0F, 1.0F, 0.0F, 0.0F, 0.0F, 0.0F, 1.0F, 1.0F, h, i, j, Direction.DOWN);
this.drawVertices(blockEntity, matrix4f, vertexConsumer, 0.0F, 1.0F, f, f, 1.0F, 1.0F, 0.0F, 0.0F, h, i, j, Direction.UP);
}
private void drawVertices(EntranceRiftBlockEntity endPortalBlockEntity, 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 direction) {
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();
}
}

View file

@ -35,4 +35,9 @@ public class MyRenderLayer extends RenderLayer {
.lightmap(RenderPhase.DISABLE_LIGHTMAP)
.texture(new Texture(new Identifier("dimdoors:textures/other/tesseract.png"), false, false))
.build(false));
public static RenderLayer getDimensionalPortal(int phase) {
Texture tex = new Texture(DimensionalPortalRenderer.getWarpPath(), false, false);
return of("dimensional_portal", VertexFormats.POSITION_COLOR, 7, 256, false, true, RenderLayer.MultiPhaseParameters.builder().transparency(TRANSLUCENT_TRANSPARENCY).texture(tex).texturing(new RenderPhase.PortalTexturing(phase)).fog(FOG).build(false));
}
}