Schematics in 1.15

- Ported Schematic placement tools to a usable state (missing preview and noCull)
This commit is contained in:
simibubi 2020-05-26 14:40:15 +02:00
parent f9fc00855a
commit 57edbe0c38
14 changed files with 300 additions and 250 deletions

View file

@ -60,7 +60,6 @@ public class MechanicalCrafterRenderer extends SafeTileEntityRenderer<Mechanical
ms.pop();
renderFast(te, partialTicks, ms, buffer, light);
// TessellatorHelper.draw();
}
public void renderItems(MechanicalCrafterTileEntity te, float partialTicks, MatrixStack ms,

View file

@ -4,7 +4,6 @@ import java.util.List;
import com.google.common.collect.ImmutableList;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.platform.GlStateManager;
import com.simibubi.create.AllItems;
import com.simibubi.create.AllKeys;
import com.simibubi.create.content.schematics.SchematicWorld;
@ -14,7 +13,7 @@ import com.simibubi.create.content.schematics.packet.SchematicPlacePacket;
import com.simibubi.create.foundation.gui.ToolSelectionScreen;
import com.simibubi.create.foundation.networking.AllPackets;
import com.simibubi.create.foundation.networking.NbtPacket;
import com.simibubi.create.foundation.utility.TessellatorHelper;
import com.simibubi.create.foundation.utility.outliner.AABBOutline;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.player.ClientPlayerEntity;
@ -33,7 +32,7 @@ public class SchematicHandler {
private String displayedSchematic;
private SchematicTransformation transformation;
private AxisAlignedBB bounds;
private AxisAlignedBB bounds;
private boolean deployed;
private boolean active;
private Tools currentTool;
@ -42,6 +41,7 @@ public class SchematicHandler {
private int syncCooldown;
private int activeHotbarSlot;
private ItemStack activeSchematicItem;
private AABBOutline outline;
private SchematicRenderer renderer;
private SchematicHotbarSlotOverlay overlay;
@ -73,7 +73,9 @@ public class SchematicHandler {
return;
}
if (!active || !stack.getTag().getString("File").equals(displayedSchematic))
if (!active || !stack.getTag()
.getString("File")
.equals(displayedSchematic))
init(player, stack);
if (!active)
return;
@ -85,12 +87,14 @@ public class SchematicHandler {
sync();
selectionScreen.update();
currentTool.getTool().updateSelection();
currentTool.getTool()
.updateSelection();
}
private void init(ClientPlayerEntity player, ItemStack stack) {
loadSettings(stack);
displayedSchematic = stack.getTag().getString("File");
displayedSchematic = stack.getTag()
.getString("File");
active = true;
if (deployed) {
setupRenderer();
@ -106,7 +110,8 @@ public class SchematicHandler {
private void setupRenderer() {
Template schematic = SchematicItem.loadSchematic(activeSchematicItem);
if (schematic.getSize().equals(BlockPos.ZERO))
if (schematic.getSize()
.equals(BlockPos.ZERO))
return;
SchematicWorld w = new SchematicWorld(BlockPos.ZERO, Minecraft.getInstance().world);
@ -118,25 +123,21 @@ public class SchematicHandler {
boolean present = activeSchematicItem != null;
if (!active && !present)
return;
if (active) {
TessellatorHelper.prepareForDrawing();
currentTool.getTool().renderTool(ms, buffer, light, overlay);
TessellatorHelper.cleanUpAfterDrawing();
}
GlStateManager.pushMatrix();
TessellatorHelper.prepareForDrawing();
transformation.applyGLTransformations();
ms.push();
transformation.applyGLTransformations(ms);
renderer.render(ms, buffer);
GlStateManager.disableCull();
if (active)
currentTool.getTool()
.renderOnSchematic(ms, buffer, light, overlay);
ms.pop();
if (active)
currentTool.getTool().renderToolLocal(ms, buffer, light, overlay);
GlStateManager.enableCull();
GlStateManager.depthMask(true);
TessellatorHelper.cleanUpAfterDrawing();
GlStateManager.popMatrix();
if (active) {
ms.push();
currentTool.getTool()
.renderTool(ms, buffer, light, overlay);
ms.pop();
}
}
public void renderOverlay(MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) {
@ -145,8 +146,10 @@ public class SchematicHandler {
if (activeSchematicItem != null)
this.overlay.renderOn(activeHotbarSlot);
currentTool.getTool().renderOverlay(ms, buffer, light, overlay);
selectionScreen.renderPassive(Minecraft.getInstance().getRenderPartialTicks());
currentTool.getTool()
.renderOverlay(ms, buffer, light, overlay);
selectionScreen.renderPassive(Minecraft.getInstance()
.getRenderPartialTicks());
}
public void onMouseInput(int button, boolean pressed) {
@ -157,7 +160,8 @@ public class SchematicHandler {
if (Minecraft.getInstance().player.isSneaking())
return;
currentTool.getTool().handleRightClick();
currentTool.getTool()
.handleRightClick();
}
public void onKeyInput(int key, boolean pressed) {
@ -183,7 +187,8 @@ public class SchematicHandler {
return true;
}
if (AllKeys.ACTIVATE_TOOL.isPressed())
return currentTool.getTool().handleMouseWheel(delta);
return currentTool.getTool()
.handleMouseWheel(delta);
return false;
}
@ -201,7 +206,8 @@ public class SchematicHandler {
private boolean itemLost(PlayerEntity player) {
for (int i = 0; i < PlayerInventory.getHotbarSize(); i++) {
if (!player.inventory.getStackInSlot(i).isItemEqual(activeSchematicItem))
if (!player.inventory.getStackInSlot(i)
.isItemEqual(activeSchematicItem))
continue;
if (!ItemStack.areItemStackTagsEqual(player.inventory.getStackInSlot(i), activeSchematicItem))
continue;
@ -222,15 +228,18 @@ public class SchematicHandler {
CompoundNBT tag = activeSchematicItem.getTag();
tag.putBoolean("Deployed", deployed);
tag.put("Anchor", NBTUtil.writeBlockPos(transformation.getAnchor()));
tag.putString("Rotation", settings.getRotation().name());
tag.putString("Mirror", settings.getMirror().name());
tag.putString("Rotation", settings.getRotation()
.name());
tag.putString("Mirror", settings.getMirror()
.name());
AllPackets.channel.sendToServer(new NbtPacket(activeSchematicItem, activeHotbarSlot));
}
public void equip(Tools tool) {
this.currentTool = tool;
currentTool.getTool().init();
currentTool.getTool()
.init();
}
public void loadSettings(ItemStack blueprint) {
@ -245,8 +254,10 @@ public class SchematicHandler {
BlockPos size = NBTUtil.readBlockPos(tag.getCompound("Bounds"));
bounds = new AxisAlignedBB(BlockPos.ZERO, size);
// outline = new AABBOutline(bounds);
// outline.disableCull = true;
outline = new AABBOutline(bounds);
outline.getParams()
.lineWidth(1 / 16f)
.disableNormals();
transformation.init(anchor, settings, bounds);
}
@ -293,4 +304,8 @@ public class SchematicHandler {
return activeSchematicItem;
}
public AABBOutline getOutline() {
return outline;
}
}

View file

@ -1,22 +1,17 @@
package com.simibubi.create.content.schematics.client;
import java.nio.ByteBuffer;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import org.lwjgl.opengl.GL11;
import org.lwjgl.system.MemoryUtil;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.datafixers.util.Pair;
import com.simibubi.create.content.schematics.SchematicWorld;
import net.minecraft.block.BlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ActiveRenderInfo;
import net.minecraft.client.renderer.BlockRendererDispatcher;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.IRenderTypeBuffer;
@ -24,10 +19,7 @@ import net.minecraft.client.renderer.RegionRenderCacheBuilder;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.RenderTypeLookup;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.entity.Entity;
import net.minecraft.inventory.container.PlayerContainer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.client.ForgeHooksClient;
import net.minecraftforge.client.model.data.EmptyModelData;
@ -75,40 +67,40 @@ public class SchematicRenderer {
public void render(MatrixStack ms, IRenderTypeBuffer buffer) {
// TODO 1.15 buffered render
if (!active)
return;
final Entity entity = Minecraft.getInstance()
.getRenderViewEntity();
if (entity == null) {
return;
}
ActiveRenderInfo renderInfo = Minecraft.getInstance().gameRenderer.getActiveRenderInfo();
Vec3d view = renderInfo.getProjectedView();
double renderPosX = view.x;
double renderPosY = view.y;
double renderPosZ = view.z;
RenderSystem.enableAlphaTest();
RenderSystem.enableBlend();
Minecraft.getInstance()
.getTextureManager()
.bindTexture(PlayerContainer.BLOCK_ATLAS_TEXTURE);
for (RenderType layer : RenderType.getBlockLayers()) {
if (!usedBlockRenderLayers.contains(layer)) {
continue;
}
final BufferBuilder bufferBuilder = bufferCache.get(layer);
RenderSystem.pushMatrix();
RenderSystem.translated(-renderPosX, -renderPosY, -renderPosZ);
drawBuffer(bufferBuilder);
RenderSystem.popMatrix();
}
RenderSystem.disableAlphaTest();
RenderSystem.disableBlend();
// if (!active)
// return;
//
// final Entity entity = Minecraft.getInstance()
// .getRenderViewEntity();
//
// if (entity == null) {
// return;
// }
//
// ActiveRenderInfo renderInfo = Minecraft.getInstance().gameRenderer.getActiveRenderInfo();
// Vec3d view = renderInfo.getProjectedView();
// double renderPosX = view.x;
// double renderPosY = view.y;
// double renderPosZ = view.z;
//
// RenderSystem.enableAlphaTest();
// RenderSystem.enableBlend();
// Minecraft.getInstance()
// .getTextureManager()
// .bindTexture(PlayerContainer.BLOCK_ATLAS_TEXTURE);
//
// for (RenderType layer : RenderType.getBlockLayers()) {
// if (!usedBlockRenderLayers.contains(layer)) {
// continue;
// }
// final BufferBuilder bufferBuilder = bufferCache.get(layer);
// RenderSystem.pushMatrix();
// RenderSystem.translated(-renderPosX, -renderPosY, -renderPosZ);
// drawBuffer(bufferBuilder);
// RenderSystem.popMatrix();
// }
// RenderSystem.disableAlphaTest();
// RenderSystem.disableBlend();
}
private void redraw(Minecraft minecraft) {
@ -153,17 +145,17 @@ public class SchematicRenderer {
}
}
private static void drawBuffer(final BufferBuilder bufferBuilder) {
Pair<BufferBuilder.DrawState, ByteBuffer> pair = bufferBuilder.popData();
BufferBuilder.DrawState state = pair.getFirst();
if (state.getCount() > 0) {
state.getVertexFormat()
.startDrawing(MemoryUtil.memAddress(pair.getSecond()));
RenderSystem.drawArrays(state.getMode(), 0, state.getCount());
state.getVertexFormat()
.endDrawing();
}
}
// private static void drawBuffer(final BufferBuilder bufferBuilder) {
// Pair<BufferBuilder.DrawState, ByteBuffer> pair = bufferBuilder.popData();
// BufferBuilder.DrawState state = pair.getFirst();
//
// if (state.getCount() > 0) {
// state.getVertexFormat()
// .startDrawing(MemoryUtil.memAddress(pair.getSecond()));
// RenderSystem.drawArrays(state.getMode(), 0, state.getCount());
// state.getVertexFormat()
// .endDrawing();
// }
// }
}

View file

@ -1,8 +1,9 @@
package com.simibubi.create.content.schematics.client;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.simibubi.create.foundation.gui.widgets.InterpolatedChasingAngle;
import com.simibubi.create.foundation.gui.widgets.InterpolatedChasingValue;
import com.simibubi.create.foundation.utility.MatrixStacker;
import com.simibubi.create.foundation.utility.VecHelper;
import net.minecraft.client.Minecraft;
@ -38,7 +39,8 @@ public class SchematicTransformation {
xOrigin = bounds.getXSize() / 2f;
zOrigin = bounds.getZSize() / 2f;
int r = -(settings.getRotation().ordinal() * 90);
int r = -(settings.getRotation()
.ordinal() * 90);
rotation.start(r);
Vec3d vec = fromAnchor(anchor);
@ -47,21 +49,22 @@ public class SchematicTransformation {
z.start((float) vec.z);
}
public void applyGLTransformations() {
float pt = Minecraft.getInstance().getRenderPartialTicks();
public void applyGLTransformations(MatrixStack ms) {
float pt = Minecraft.getInstance()
.getRenderPartialTicks();
// Translation
RenderSystem.translated(x.get(pt), y.get(pt), z.get(pt));
ms.translate(x.get(pt), y.get(pt), z.get(pt));
Vec3d rotationOffset = getRotationOffset(true);
// Rotation & Mirror
RenderSystem.translated(xOrigin + rotationOffset.x, 0, zOrigin + rotationOffset.z);
RenderSystem.rotatef(rotation.get(pt), 0, 1, 0);
RenderSystem.translated(-rotationOffset.x, 0, -rotationOffset.z);
RenderSystem.scaled(scaleFrontBack.get(pt), 1, scaleLeftRight.get(pt));
RenderSystem.translated(-xOrigin, 0, -zOrigin);
ms.translate(xOrigin, 0, zOrigin);
MatrixStacker.of(ms)
.translate(rotationOffset)
.rotateY(rotation.get(pt))
.translateBack(rotationOffset);
ms.scale(scaleFrontBack.get(pt), 1, scaleLeftRight.get(pt));
ms.translate(-xOrigin, 0, -zOrigin);
}
@ -81,7 +84,8 @@ public class SchematicTransformation {
}
public Vec3d toLocalSpace(Vec3d vec) {
float pt = Minecraft.getInstance().getRenderPartialTicks();
float pt = Minecraft.getInstance()
.getRenderPartialTicks();
Vec3d rotationOffset = getRotationOffset(true);
vec = vec.subtract(x.get(pt), y.get(pt), z.get(pt));
@ -168,7 +172,8 @@ public class SchematicTransformation {
}
public float getCurrentRotation() {
float pt = Minecraft.getInstance().getRenderPartialTicks();
float pt = Minecraft.getInstance()
.getRenderPartialTicks();
return rotation.get(pt);
}

View file

@ -1,13 +1,14 @@
package com.simibubi.create.content.schematics.client.tools;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.systems.RenderSystem;
import com.simibubi.create.AllKeys;
import com.simibubi.create.AllSpecialTextures;
import com.simibubi.create.content.schematics.client.SchematicTransformation;
import com.simibubi.create.foundation.utility.MatrixStacker;
import com.simibubi.create.foundation.utility.outliner.AABBOutline;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTUtil;
import net.minecraft.util.math.AxisAlignedBB;
@ -26,7 +27,9 @@ public class DeployTool extends PlacementToolBase {
@Override
public void updateSelection() {
if (schematicHandler.isActive() && selectionRange == -1) {
selectionRange = (int) (schematicHandler.getBounds().getCenter().length() / 2);
selectionRange = (int) (schematicHandler.getBounds()
.getCenter()
.length() / 2);
selectionRange = MathHelper.clamp(selectionRange, 1, 100);
}
selectIgnoreBlocks = AllKeys.ACTIVATE_TOOL.isPressed();
@ -40,10 +43,9 @@ public class DeployTool extends PlacementToolBase {
if (selectedPos == null)
return;
RenderSystem.pushMatrix();
RenderHelper.disableStandardItemLighting();
RenderSystem.enableBlend();
float pt = Minecraft.getInstance().getRenderPartialTicks();
ms.push();
float pt = Minecraft.getInstance()
.getRenderPartialTicks();
double x = MathHelper.lerp(pt, lastChasingSelectedPos.x, chasingSelectedPos.x);
double y = MathHelper.lerp(pt, lastChasingSelectedPos.y, chasingSelectedPos.y);
double z = MathHelper.lerp(pt, lastChasingSelectedPos.z, chasingSelectedPos.z);
@ -56,17 +58,23 @@ public class DeployTool extends PlacementToolBase {
int centerZ = (int) center.z;
double xOrigin = bounds.getXSize() / 2f;
double zOrigin = bounds.getZSize() / 2f;
Vec3d origin = new Vec3d(xOrigin, 0, zOrigin);
RenderSystem.translated(x - centerX, y, z - centerZ);
RenderSystem.translated(xOrigin + rotationOffset.x, 0, zOrigin + rotationOffset.z);
RenderSystem.rotatef(transformation.getCurrentRotation(), 0, 1, 0);
RenderSystem.translated(-rotationOffset.x, 0, -rotationOffset.z);
RenderSystem.translated(-xOrigin, 0, -zOrigin);
ms.translate(x - centerX, y, z - centerZ);
MatrixStacker.of(ms)
.translate(origin)
.translate(rotationOffset)
.rotateY(transformation.getCurrentRotation())
.translateBack(rotationOffset)
.translateBack(origin);
// schematicHandler.getOutline().setTextures(AllSpecialTextures.CHECKERED, null);
// schematicHandler.getOutline().render(Tessellator.getInstance().getBuffer());TODO
// schematicHandler.getOutline().setTextures(null, null);
RenderSystem.popMatrix();
AABBOutline outline = schematicHandler.getOutline();
outline.getParams()
.withFaceTexture(AllSpecialTextures.CHECKERED);
outline.render(ms, buffer);
outline.getParams()
.clearTextures();
ms.pop();
}
@Override
@ -82,16 +90,20 @@ public class DeployTool extends PlacementToolBase {
public boolean handleRightClick() {
if (selectedPos == null)
return super.handleRightClick();
Vec3d center = schematicHandler.getBounds().getCenter();
Vec3d center = schematicHandler.getBounds()
.getCenter();
BlockPos target = selectedPos.add(-((int) center.x), 0, -((int) center.z));
ItemStack item = schematicHandler.getActiveSchematicItem();
if (item != null) {
item.getTag().putBoolean("Deployed", true);
item.getTag().put("Anchor", NBTUtil.writeBlockPos(target));
item.getTag()
.putBoolean("Deployed", true);
item.getTag()
.put("Anchor", NBTUtil.writeBlockPos(target));
}
schematicHandler.getTransformation().moveTo(target);
schematicHandler.getTransformation()
.moveTo(target);
schematicHandler.markDirty();
schematicHandler.deploy();
return true;

View file

@ -1,19 +1,20 @@
package com.simibubi.create.content.schematics.client.tools;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.platform.GlStateManager;
import com.simibubi.create.foundation.utility.ColorHelper;
import com.simibubi.create.foundation.utility.VecHelper;
import com.simibubi.create.AllSpecialTextures;
import com.simibubi.create.foundation.utility.outliner.AABBOutline;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.util.Direction;
import net.minecraft.util.Direction.Axis;
import net.minecraft.util.Direction.AxisDirection;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
public class FlipTool extends PlacementToolBase {
private AABBOutline outline = new AABBOutline(new AxisAlignedBB(BlockPos.ZERO));
@Override
public void init() {
super.init();
@ -38,67 +39,42 @@ public class FlipTool extends PlacementToolBase {
}
private void mirror() {
if (schematicSelected && selectedFace.getAxis().isHorizontal()) {
schematicHandler.getTransformation().flip(selectedFace.getAxis());
if (schematicSelected && selectedFace.getAxis()
.isHorizontal()) {
schematicHandler.getTransformation()
.flip(selectedFace.getAxis());
schematicHandler.markDirty();
}
}
@Override
public void renderToolLocal(MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) {
super.renderToolLocal(ms, buffer, light, overlay);
public void renderOnSchematic(MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) {
super.renderOnSchematic(ms, buffer, light, overlay);
if (!schematicSelected || !selectedFace.getAxis().isHorizontal())
if (!schematicSelected || !selectedFace.getAxis()
.isHorizontal())
return;
GlStateManager.pushMatrix();
RenderHelper.disableStandardItemLighting();
GlStateManager.enableBlend();
Direction facing = selectedFace.rotateY();
Axis axis = facing.getAxis();
Vec3d color = ColorHelper.getRGB(0x4d80e4);
AxisAlignedBB bounds = schematicHandler.getBounds();
Vec3d plane = VecHelper.planeByNormal(new Vec3d(facing.getDirectionVec()));
plane = plane.mul(bounds.getXSize() / 2f + 1, bounds.getYSize() / 2f + 1, bounds.getZSize() / 2f + 1);
Vec3d center = bounds.getCenter();
Vec3d directionVec = new Vec3d(Direction.getFacingFromAxis(AxisDirection.POSITIVE, facing.getAxis())
.getDirectionVec());
Vec3d boundsSize = new Vec3d(bounds.getXSize(), bounds.getYSize(), bounds.getZSize());
Vec3d vec = boundsSize.mul(directionVec);
bounds = bounds.contract(vec.x, vec.y, vec.z)
.grow(1 - directionVec.x, 1 - directionVec.y, 1 - directionVec.z);
bounds = bounds.offset(directionVec.scale(.5f)
.mul(boundsSize));
Vec3d v1 = plane.add(center);
plane = plane.mul(-1, 1, -1);
Vec3d v2 = plane.add(center);
plane = plane.mul(1, -1, 1);
Vec3d v3 = plane.add(center);
plane = plane.mul(-1, 1, -1);
Vec3d v4 = plane.add(center);
// BufferBuilder buffer = Tessellator.getInstance().getBuffer();TODO 1.15
// buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.PARTICLE_POSITION_TEX_COLOR_LMAP);
//
// AABBOutline outline = schematicHandler.getOutline();
// AllSpecialTextures.BLANK.bind();
// outline.renderAACuboidLine(v1, v2, color, 1, builder);
// outline.renderAACuboidLine(v2, v3, color, 1, builder);
// outline.renderAACuboidLine(v3, v4, color, 1, builder);
// outline.renderAACuboidLine(v4, v1, color, 1, builder);
//
// Tessellator.getInstance().draw();
// buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.PARTICLE_POSITION_TEX_COLOR_LMAP);
//
// GlHelper.enableTextureRepeat();
// GlStateManager.depthMask(false);
// Vec3d uDiff = v2.subtract(v1);
// Vec3d vDiff = v4.subtract(v1);
// float maxU = (float) Math.abs(axis == Axis.X ? uDiff.z : uDiff.x);
// float maxV = (float) Math.abs(axis == Axis.Y ? vDiff.z : vDiff.y);
//
// GlStateManager.enableCull();
// AllSpecialTextures.HIGHLIGHT_CHECKERED.bind();
// outline.putQuadUV(v1, v2, v3, v4, 0, 0, maxU, maxV, color, 1, builder);
// outline.putQuadUV(v2, v1, v4, v3, 0, 0, maxU, maxV, color, 1, builder);
// Tessellator.getInstance().draw();
// GlStateManager.popMatrix();
// GlHelper.disableTextureRepeat();
outline.setBounds(bounds);
AllSpecialTextures tex = AllSpecialTextures.HIGHLIGHT_CHECKERED;
outline.getParams()
.lineWidth(1 / 16f)
.disableNormals()
.colored(0x4d80e4)
.withFaceTextures(tex, tex);
outline.render(ms, buffer);
}
}

View file

@ -14,6 +14,6 @@ public interface ISchematicTool {
public void renderTool(MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay);
public void renderOverlay(MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay);
public void renderToolLocal(MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay);
public void renderOnSchematic(MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay);
}

View file

@ -1,39 +1,43 @@
package com.simibubi.create.content.schematics.client.tools;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.simibubi.create.foundation.utility.outliner.LineOutline;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.Vec3d;
public class RotateTool extends PlacementToolBase {
private LineOutline line = new LineOutline();
@Override
public boolean handleMouseWheel(double delta) {
schematicHandler.getTransformation().rotate90(delta > 0);
schematicHandler.getTransformation()
.rotate90(delta > 0);
schematicHandler.markDirty();
return true;
}
@Override
public void renderToolLocal(MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) {
super.renderToolLocal(ms, buffer, light, overlay);
public void renderOnSchematic(MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) {
super.renderOnSchematic(ms, buffer, light, overlay);
// GlStateManager.pushMatrix();TODO 1.15
// RenderHelper.disableStandardItemLighting();
// GlStateManager.enableBlend();
//
// Vec3d color = ColorHelper.getRGB(0x4d80e4);
// AxisAlignedBB bounds = schematicHandler.getBounds();
// double height = bounds.getYSize() + Math.max(20, bounds.getYSize());
//
// Vec3d center = bounds.getCenter().add(schematicHandler.getTransformation().getRotationOffset(false));
// Vec3d start = center.subtract(0, height / 2, 0);
// Vec3d end = center.add(0, height / 2, 0);
//
// BufferBuilder buffer = Tessellator.getInstance().getBuffer();
// buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.PARTICLE_POSITION_TEX_COLOR_LMAP);
// schematicHandler.getOutline().renderAACuboidLine(start, end, color, 1, buffer);
// Tessellator.getInstance().draw();
// GlStateManager.popMatrix();
AxisAlignedBB bounds = schematicHandler.getBounds();
double height = bounds.getYSize() + Math.max(20, bounds.getYSize());
Vec3d center = bounds.getCenter()
.add(schematicHandler.getTransformation()
.getRotationOffset(false));
Vec3d start = center.subtract(0, height / 2, 0);
Vec3d end = center.add(0, height / 2, 0);
line.getParams()
.colored(0x4d80e4)
.disableCull()
.disableNormals()
.lineWidth(1 / 16f);
line.set(start, end)
.render(ms, buffer);
}
}

View file

@ -4,18 +4,19 @@ import java.util.Arrays;
import java.util.List;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.systems.RenderSystem;
import com.simibubi.create.AllKeys;
import com.simibubi.create.AllSpecialTextures;
import com.simibubi.create.CreateClient;
import com.simibubi.create.content.schematics.client.SchematicHandler;
import com.simibubi.create.content.schematics.client.SchematicTransformation;
import com.simibubi.create.foundation.utility.RaycastHelper;
import com.simibubi.create.foundation.utility.RaycastHelper.PredicateTraceResult;
import com.simibubi.create.foundation.utility.VecHelper;
import com.simibubi.create.foundation.utility.outliner.AABBOutline;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.util.Direction;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
@ -63,7 +64,8 @@ public abstract class SchematicToolBase implements ISchematicTool {
return;
}
chasingSelectedPos = chasingSelectedPos.add(target.subtract(chasingSelectedPos).scale(1 / 2f));
chasingSelectedPos = chasingSelectedPos.add(target.subtract(chasingSelectedPos)
.scale(1 / 2f));
}
public void updateTargetPos() {
@ -88,8 +90,11 @@ public abstract class SchematicToolBase implements ISchematicTool {
// Select location at distance
if (selectIgnoreBlocks) {
float pt = Minecraft.getInstance().getRenderPartialTicks();
selectedPos = new BlockPos(player.getEyePosition(pt).add(player.getLookVec().scale(selectionRange)));
float pt = Minecraft.getInstance()
.getRenderPartialTicks();
selectedPos = new BlockPos(player.getEyePosition(pt)
.add(player.getLookVec()
.scale(selectionRange)));
if (snap)
lastChasingSelectedPos = chasingSelectedPos = new Vec3d(selectedPos);
return;
@ -102,8 +107,12 @@ public abstract class SchematicToolBase implements ISchematicTool {
return;
BlockPos hit = new BlockPos(trace.getHitVec());
boolean replaceable = player.world.getBlockState(hit).getMaterial().isReplaceable();
if (trace.getFace().getAxis().isVertical() && !replaceable)
boolean replaceable = player.world.getBlockState(hit)
.getMaterial()
.isReplaceable();
if (trace.getFace()
.getAxis()
.isVertical() && !replaceable)
hit = hit.offset(trace.getFace());
selectedPos = hit;
if (snap)
@ -111,30 +120,30 @@ public abstract class SchematicToolBase implements ISchematicTool {
}
@Override
public void renderTool(MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) {
if (!schematicHandler.isDeployed())
return;
// AABBOutline outline = schematicHandler.getOutline();
if (renderSelectedFace) {
// schematicHandler.getOutline().setTextures(null,
// AllKeys.ctrlDown() ? AllSpecialTextures.HIGHLIGHT_CHECKERED : AllSpecialTextures.CHECKERED);
// outline.highlightFace(selectedFace);
}
RenderHelper.disableStandardItemLighting();
RenderSystem.pushMatrix();
RenderSystem.enableBlend();
// outline.render(Tessellator.getInstance().getBuffer());TODO
RenderSystem.popMatrix();
// outline.setTextures(null, null);
}
public void renderTool(MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) {}
@Override
public void renderOverlay(MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) {}
@Override
public void renderToolLocal(MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) {}
public void renderOnSchematic(MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) {
if (!schematicHandler.isDeployed())
return;
ms.push();
AABBOutline outline = schematicHandler.getOutline();
if (renderSelectedFace) {
outline.getParams()
.highlightFace(selectedFace)
.withFaceTextures(AllSpecialTextures.CHECKERED,
AllKeys.ctrlDown() ? AllSpecialTextures.HIGHLIGHT_CHECKERED : AllSpecialTextures.CHECKERED);
}
outline.getParams()
.disableCull();
outline.render(ms, buffer);
outline.getParams()
.withFaceTextures(null, null);
ms.pop();
}
}

View file

@ -17,7 +17,7 @@ public class AABBOutline extends Outline {
protected AxisAlignedBB bb;
public AABBOutline(AxisAlignedBB bb) {
this.bb = bb;
this.setBounds(bb);
}
@Override
@ -28,8 +28,9 @@ public class AABBOutline extends Outline {
public void renderBB(MatrixStack ms, IRenderTypeBuffer buffer, AxisAlignedBB bb) {
Vec3d projectedView = Minecraft.getInstance().gameRenderer.getActiveRenderInfo()
.getProjectedView();
boolean inside = bb.contains(projectedView);
bb = bb.grow(inside ? -1 / 128d : 1 / 128d);
boolean noCull = bb.contains(projectedView);
bb = bb.grow(noCull ? -1 / 128d : 1 / 128d);
noCull |= params.disableCull;
Vec3d xyz = new Vec3d(bb.minX, bb.minY, bb.minZ);
Vec3d Xyz = new Vec3d(bb.maxX, bb.minY, bb.minZ);
@ -41,34 +42,35 @@ public class AABBOutline extends Outline {
Vec3d XYZ = new Vec3d(bb.maxX, bb.maxY, bb.maxZ);
Vec3d start = xyz;
renderAACuboidLine(ms, buffer, start, Xyz);
renderAACuboidLine(ms, buffer, start, xYz);
renderAACuboidLine(ms, buffer, start, xyZ);
renderAACuboidLine(ms, buffer, start, Xyz, noCull);
renderAACuboidLine(ms, buffer, start, xYz, noCull);
renderAACuboidLine(ms, buffer, start, xyZ, noCull);
start = XyZ;
renderAACuboidLine(ms, buffer, start, xyZ);
renderAACuboidLine(ms, buffer, start, XYZ);
renderAACuboidLine(ms, buffer, start, Xyz);
renderAACuboidLine(ms, buffer, start, xyZ, noCull);
renderAACuboidLine(ms, buffer, start, XYZ, noCull);
renderAACuboidLine(ms, buffer, start, Xyz, noCull);
start = XYz;
renderAACuboidLine(ms, buffer, start, xYz);
renderAACuboidLine(ms, buffer, start, Xyz);
renderAACuboidLine(ms, buffer, start, XYZ);
renderAACuboidLine(ms, buffer, start, xYz, noCull);
renderAACuboidLine(ms, buffer, start, Xyz, noCull);
renderAACuboidLine(ms, buffer, start, XYZ, noCull);
start = xYZ;
renderAACuboidLine(ms, buffer, start, XYZ);
renderAACuboidLine(ms, buffer, start, xyZ);
renderAACuboidLine(ms, buffer, start, xYz);
renderAACuboidLine(ms, buffer, start, XYZ, noCull);
renderAACuboidLine(ms, buffer, start, xyZ, noCull);
renderAACuboidLine(ms, buffer, start, xYz, noCull);
renderFace(ms, buffer, Direction.NORTH, xYz, XYz, Xyz, xyz, inside);
renderFace(ms, buffer, Direction.SOUTH, XYZ, xYZ, xyZ, XyZ, inside);
renderFace(ms, buffer, Direction.EAST, XYz, XYZ, XyZ, Xyz, inside);
renderFace(ms, buffer, Direction.WEST, xYZ, xYz, xyz, xyZ, inside);
renderFace(ms, buffer, Direction.UP, xYZ, XYZ, XYz, xYz, inside);
renderFace(ms, buffer, Direction.DOWN, xyz, Xyz, XyZ, xyZ, inside);
renderFace(ms, buffer, Direction.NORTH, xYz, XYz, Xyz, xyz, noCull);
renderFace(ms, buffer, Direction.SOUTH, XYZ, xYZ, xyZ, XyZ, noCull);
renderFace(ms, buffer, Direction.EAST, XYz, XYZ, XyZ, Xyz, noCull);
renderFace(ms, buffer, Direction.WEST, xYZ, xYz, xyz, xyZ, noCull);
renderFace(ms, buffer, Direction.UP, xYZ, XYZ, XYz, xYz, noCull);
renderFace(ms, buffer, Direction.DOWN, xyz, Xyz, XyZ, xyZ, noCull);
}
//TODO noCull has no effect
protected void renderFace(MatrixStack ms, IRenderTypeBuffer buffer, Direction direction, Vec3d p1, Vec3d p2,
Vec3d p3, Vec3d p4, boolean noCull) {
if (!params.faceTexture.isPresent())
@ -90,4 +92,8 @@ public class AABBOutline extends Outline {
putQuadUV(ms, builder, p1, p2, p3, p4, 0, 0, maxU, maxV, Direction.UP);
}
public void setBounds(AxisAlignedBB bb) {
this.bb = bb;
}
}

View file

@ -33,7 +33,7 @@ public class BlockClusterOutline extends Outline {
for (MergeEntry edge : cluster.visibleEdges) {
Vec3d start = new Vec3d(edge.pos);
Direction direction = Direction.getFacingFromAxis(AxisDirection.POSITIVE, edge.axis);
renderAACuboidLine(ms, buffer, start, new Vec3d(edge.pos.offset(direction)));
renderAACuboidLine(ms, buffer, start, new Vec3d(edge.pos.offset(direction)), false);
}
for (MergeEntry face : cluster.visibleFaces.keySet()) {

View file

@ -25,7 +25,7 @@ public class ChasingAABBOutline extends AABBOutline {
@Override
public void tick() {
prevBB = bb;
bb = interpolateBBs(bb, targetBB, .5f);
setBounds(interpolateBBs(bb, targetBB, .5f));
}
@Override

View file

@ -0,0 +1,24 @@
package com.simibubi.create.foundation.utility.outliner;
import com.mojang.blaze3d.matrix.MatrixStack;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.util.math.Vec3d;
public class LineOutline extends Outline {
private Vec3d start = Vec3d.ZERO;
private Vec3d end = Vec3d.ZERO;
public LineOutline set(Vec3d start, Vec3d end) {
this.start = start;
this.end = end;
return this;
}
@Override
public void render(MatrixStack ms, IRenderTypeBuffer buffer) {
renderAACuboidLine(ms, buffer, start, end, params.disableCull);
}
}

View file

@ -17,6 +17,7 @@ import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.util.Direction;
import net.minecraft.util.Direction.Axis;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.Vec3d;
public abstract class Outline {
@ -30,8 +31,11 @@ public abstract class Outline {
public abstract void render(MatrixStack ms, IRenderTypeBuffer buffer);
public void renderAACuboidLine(MatrixStack ms, IRenderTypeBuffer buffer, Vec3d start, Vec3d end) {
IVertexBuilder builder = buffer.getBuffer(RenderType.getEntitySolid(AllSpecialTextures.BLANK.getLocation()));
//TODO noCull has no effect
public void renderAACuboidLine(MatrixStack ms, IRenderTypeBuffer buffer, Vec3d start, Vec3d end, boolean noCull) {
ResourceLocation tex = AllSpecialTextures.BLANK.getLocation();
IVertexBuilder builder =
buffer.getBuffer(noCull ? RenderType.getCutoutNoCull(tex, true) : RenderType.getEntitySolid(tex));
Vec3d diff = end.subtract(start);
if (diff.x + diff.y + diff.z < 0) {
@ -181,6 +185,10 @@ public abstract class Outline {
return this;
}
public OutlineParams clearTextures() {
return this.withFaceTextures(null, null);
}
public OutlineParams withFaceTextures(AllSpecialTextures texture, AllSpecialTextures highlightTexture) {
this.faceTexture = Optional.ofNullable(texture);
this.hightlightedFaceTexture = Optional.ofNullable(highlightTexture);