mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-11-10 20:11:35 +01:00
More porty
- Ported blockzapper beams - Terrainzapper now uses outliner utility
This commit is contained in:
parent
57edbe0c38
commit
68b656c6be
13 changed files with 106 additions and 190 deletions
|
@ -4,11 +4,10 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.simibubi.create.content.contraptions.KineticDebugger;
|
||||
import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer;
|
||||
import com.simibubi.create.content.contraptions.components.turntable.TurntableHandler;
|
||||
import com.simibubi.create.content.contraptions.relays.belt.item.BeltConnectorHandler;
|
||||
import com.simibubi.create.content.curiosities.zapper.terrainzapper.TerrainZapperRenderHandler;
|
||||
import com.simibubi.create.foundation.config.AllConfigs;
|
||||
import com.simibubi.create.foundation.gui.ScreenOpener;
|
||||
import com.simibubi.create.foundation.item.TooltipHelper;
|
||||
|
@ -18,6 +17,7 @@ import com.simibubi.create.foundation.utility.AnimationTickHolder;
|
|||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.ActiveRenderInfo;
|
||||
import net.minecraft.client.renderer.Atlases;
|
||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
||||
import net.minecraft.client.renderer.texture.OverlayTexture;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
@ -59,13 +59,7 @@ public class ClientEvents {
|
|||
}
|
||||
|
||||
ScreenOpener.tick();
|
||||
onGameTick();
|
||||
}
|
||||
|
||||
public static void onGameTick() {
|
||||
CreateClient.gameTick();
|
||||
BeltConnectorHandler.gameTick();
|
||||
TerrainZapperRenderHandler.tick();
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
@ -76,18 +70,14 @@ public class ClientEvents {
|
|||
|
||||
ms.push();
|
||||
ms.translate(-view.getX(), -view.getY(), -view.getZ());
|
||||
|
||||
IRenderTypeBuffer.Impl buffer = Minecraft.getInstance()
|
||||
.getBufferBuilders()
|
||||
.getEntityVertexConsumers();
|
||||
|
||||
|
||||
CreateClient.schematicHandler.render(ms, buffer, 0xF000F0, OverlayTexture.DEFAULT_UV);
|
||||
CreateClient.outliner.renderOutlines(ms, buffer);
|
||||
KineticDebugger.renderSourceOutline(ms, buffer);
|
||||
TerrainZapperRenderHandler.render(ms, buffer);
|
||||
|
||||
ms.pop();
|
||||
|
||||
buffer.draw();
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,9 @@ import java.util.function.Function;
|
|||
import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.ChassisRangeDisplay;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionRenderer;
|
||||
import com.simibubi.create.content.contraptions.relays.belt.item.BeltConnectorHandler;
|
||||
import com.simibubi.create.content.curiosities.zapper.ZapperRenderHandler;
|
||||
import com.simibubi.create.content.curiosities.zapper.terrainzapper.TerrainZapperRenderHandler;
|
||||
import com.simibubi.create.content.schematics.ClientSchematicLoader;
|
||||
import com.simibubi.create.content.schematics.client.SchematicAndQuillHandler;
|
||||
import com.simibubi.create.content.schematics.client.SchematicHandler;
|
||||
|
@ -89,11 +92,14 @@ public class CreateClient {
|
|||
schematicSender.tick();
|
||||
schematicAndQuillHandler.tick();
|
||||
schematicHandler.tick();
|
||||
BeltConnectorHandler.gameTick();
|
||||
FilteringRenderer.tick();
|
||||
LinkRenderer.tick();
|
||||
ScrollValueRenderer.tick();
|
||||
ChassisRangeDisplay.tick();
|
||||
EdgeInteractionRenderer.tick();
|
||||
TerrainZapperRenderHandler.tick();
|
||||
ZapperRenderHandler.tick();
|
||||
outliner.tickOutlines();
|
||||
}
|
||||
|
||||
|
|
|
@ -84,11 +84,6 @@ public abstract class KineticBlock extends Block implements IRotate {
|
|||
kte.updateSpeed = true;
|
||||
}
|
||||
|
||||
// @Override // TODO 1.15 register layer
|
||||
// public boolean canRenderInLayer(BlockState state, BlockRenderLayer layer) {
|
||||
// return hasStaticPart() && layer == getRenderLayer();
|
||||
// }
|
||||
|
||||
protected abstract boolean hasStaticPart();
|
||||
|
||||
@Override
|
||||
|
|
|
@ -16,9 +16,9 @@ import com.simibubi.create.content.contraptions.relays.belt.BeltBlock.Slope;
|
|||
import com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack;
|
||||
import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer;
|
||||
import com.simibubi.create.foundation.utility.AnimationTickHolder;
|
||||
import com.simibubi.create.foundation.utility.MatrixStacker;
|
||||
import com.simibubi.create.foundation.utility.ShadowRenderHelper;
|
||||
import com.simibubi.create.foundation.utility.SuperByteBuffer;
|
||||
import com.simibubi.create.foundation.utility.TessellatorHelper;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
@ -36,7 +36,6 @@ import net.minecraft.util.math.MathHelper;
|
|||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class BeltRenderer extends SafeTileEntityRenderer<BeltTileEntity> {
|
||||
|
||||
public BeltRenderer(TileEntityRendererDispatcher dispatcher) {
|
||||
|
@ -112,7 +111,7 @@ public class BeltRenderer extends SafeTileEntityRenderer<BeltTileEntity> {
|
|||
|
||||
for (TransportedItemStack transported : te.getInventory().getItems()) {
|
||||
ms.push();
|
||||
TessellatorHelper.fightZFighting(transported.angle, ms);
|
||||
MatrixStacker.of(ms).nudge(transported.angle);
|
||||
float offset = MathHelper.lerp(partialTicks, transported.prevBeltPosition, transported.beltPosition);
|
||||
float sideOffset = MathHelper.lerp(partialTicks, transported.prevSideOffset, transported.sideOffset);
|
||||
float verticalMovement = verticality;
|
||||
|
|
|
@ -5,23 +5,19 @@ import java.util.List;
|
|||
import java.util.Random;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.simibubi.create.AllSoundEvents;
|
||||
import com.simibubi.create.foundation.utility.TessellatorHelper;
|
||||
import com.simibubi.create.CreateClient;
|
||||
import com.simibubi.create.foundation.utility.AnimationTickHolder;
|
||||
import com.simibubi.create.foundation.utility.ColorHelper;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.player.AbstractClientPlayerEntity;
|
||||
import net.minecraft.client.entity.player.ClientPlayerEntity;
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
import net.minecraft.client.renderer.FirstPersonRenderer;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.Vector3f;
|
||||
import net.minecraft.client.renderer.entity.PlayerRenderer;
|
||||
import net.minecraft.client.renderer.model.ItemCameraTransforms;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.client.world.ClientWorld;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.particles.ParticleTypes;
|
||||
|
@ -33,13 +29,9 @@ import net.minecraft.util.math.MathHelper;
|
|||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.RenderHandEvent;
|
||||
import net.minecraftforge.client.event.RenderWorldLastEvent;
|
||||
import net.minecraftforge.event.TickEvent.ClientTickEvent;
|
||||
import net.minecraftforge.event.TickEvent.Phase;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@EventBusSubscriber(value = Dist.CLIENT)
|
||||
public class ZapperRenderHandler {
|
||||
|
||||
|
@ -79,7 +71,8 @@ public class ZapperRenderHandler {
|
|||
}
|
||||
|
||||
public static Vec3d getExactBarrelPos(boolean mainHand) {
|
||||
float partialTicks = Minecraft.getInstance().getRenderPartialTicks();
|
||||
float partialTicks = Minecraft.getInstance()
|
||||
.getRenderPartialTicks();
|
||||
ClientPlayerEntity player = Minecraft.getInstance().player;
|
||||
float yaw = (float) ((player.getYaw(partialTicks)) / -180 * Math.PI);
|
||||
float pitch = (float) ((player.getPitch(partialTicks)) / -180 * Math.PI);
|
||||
|
@ -87,22 +80,14 @@ public class ZapperRenderHandler {
|
|||
float zOffset = ((float) Minecraft.getInstance().gameSettings.fov - 70) / -100;
|
||||
Vec3d barrelPosNoTransform = new Vec3d(rightHand ? -.35f : .35f, -0.115f, .75f + zOffset);
|
||||
Vec3d barrelPos = player.getEyePosition(partialTicks)
|
||||
.add(barrelPosNoTransform.rotatePitch(pitch).rotateYaw(yaw));
|
||||
.add(barrelPosNoTransform.rotatePitch(pitch)
|
||||
.rotateYaw(yaw));
|
||||
return barrelPos;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onClientTick(ClientTickEvent event) {
|
||||
if (event.phase == Phase.START)
|
||||
return;
|
||||
public static void tick() {
|
||||
if (cachedBeams == null)
|
||||
cachedBeams = new LinkedList<>();
|
||||
ClientWorld world = Minecraft.getInstance().world;
|
||||
if (world == null)
|
||||
return;
|
||||
ClientPlayerEntity player = Minecraft.getInstance().player;
|
||||
if (player == null)
|
||||
return;
|
||||
cachedBeams.removeIf(b -> b.itensity < .1f);
|
||||
cachedBeams.forEach(b -> b.itensity *= .4f);
|
||||
|
||||
|
@ -110,28 +95,16 @@ public class ZapperRenderHandler {
|
|||
lastRightHandAnimation = rightHandAnimation;
|
||||
leftHandAnimation *= 0.8f;
|
||||
rightHandAnimation *= 0.8f;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onRenderWorld(RenderWorldLastEvent event) {
|
||||
if (cachedBeams == null || cachedBeams.isEmpty())
|
||||
return;
|
||||
|
||||
cachedBeams.forEach(beam -> {
|
||||
// TODO 1.15 buffered render
|
||||
TessellatorHelper.prepareForDrawing();
|
||||
RenderSystem.disableTexture();
|
||||
RenderSystem.lineWidth(beam.itensity * 40);
|
||||
|
||||
BufferBuilder bufferBuilder = Tessellator.getInstance().getBuffer();
|
||||
bufferBuilder.begin(GL11.GL_LINE_STRIP, DefaultVertexFormats.POSITION);
|
||||
bufferBuilder.vertex(beam.getStart().x, beam.getStart().y, beam.getStart().z).endVertex();
|
||||
bufferBuilder.vertex(beam.end.x, beam.end.y, beam.end.z).endVertex();
|
||||
Tessellator.getInstance().draw();
|
||||
|
||||
RenderSystem.lineWidth(1);
|
||||
RenderSystem.enableTexture();
|
||||
TessellatorHelper.cleanUpAfterDrawing();
|
||||
CreateClient.outliner.showLine(beam, beam.getStart(), beam.end)
|
||||
.disableNormals()
|
||||
.colored(ColorHelper.mixColors(0xffffff, ColorHelper.rainbowColor(AnimationTickHolder.ticks),
|
||||
MathHelper.clamp(beam.itensity * 3, 0, 1)))
|
||||
.lineWidth(beam.itensity * 1 / 4f);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -150,7 +123,8 @@ public class ZapperRenderHandler {
|
|||
|
||||
public static void playSound(Hand hand, BlockPos position) {
|
||||
float pitch = hand == Hand.MAIN_HAND ? 2f : 0.9f;
|
||||
Minecraft.getInstance().world.playSound(position, AllSoundEvents.BLOCKZAPPER_PLACE.get(), SoundCategory.BLOCKS, 0.8f, pitch, false);
|
||||
Minecraft.getInstance().world.playSound(position, AllSoundEvents.BLOCKZAPPER_PLACE.get(), SoundCategory.BLOCKS,
|
||||
0.8f, pitch, false);
|
||||
}
|
||||
|
||||
public static void addBeam(LaserBeam beam) {
|
||||
|
@ -164,7 +138,7 @@ public class ZapperRenderHandler {
|
|||
for (int i = 0; i < 10; i++) {
|
||||
world.addParticle(ParticleTypes.END_ROD, x, y, z, randomSpeed.get(), randomSpeed.get(), randomSpeed.get());
|
||||
world.addParticle(ParticleTypes.FIREWORK, x + randomOffset.get(), y + randomOffset.get(),
|
||||
z + randomOffset.get(), 0, 0, 0);
|
||||
z + randomOffset.get(), 0, 0, 0);
|
||||
}
|
||||
|
||||
cachedBeams.add(beam);
|
||||
|
@ -178,14 +152,12 @@ public class ZapperRenderHandler {
|
|||
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
boolean rightHand = event.getHand() == Hand.MAIN_HAND ^ mc.player.getPrimaryHand() == HandSide.LEFT;
|
||||
|
||||
|
||||
MatrixStack ms = event.getMatrixStack();
|
||||
|
||||
// TODO 1.15 buffered render
|
||||
ms.push();
|
||||
|
||||
float recoil = rightHand ? MathHelper.lerp(event.getPartialTicks(), lastRightHandAnimation, rightHandAnimation)
|
||||
: MathHelper.lerp(event.getPartialTicks(), lastLeftHandAnimation, leftHandAnimation);
|
||||
: MathHelper.lerp(event.getPartialTicks(), lastLeftHandAnimation, leftHandAnimation);
|
||||
|
||||
float equipProgress = event.getEquipProgress();
|
||||
|
||||
|
@ -193,7 +165,7 @@ public class ZapperRenderHandler {
|
|||
equipProgress = 0;
|
||||
if (!rightHand && (leftHandAnimation > .01f || dontReequipLeft))
|
||||
equipProgress = 0;
|
||||
|
||||
|
||||
// Render arm
|
||||
float f = rightHand ? 1.0F : -1.0F;
|
||||
float f1 = MathHelper.sqrt(event.getSwingProgress());
|
||||
|
@ -201,32 +173,36 @@ public class ZapperRenderHandler {
|
|||
float f3 = 0.4F * MathHelper.sin(f1 * ((float) Math.PI * 2F));
|
||||
float f4 = -0.4F * MathHelper.sin(event.getSwingProgress() * (float) Math.PI);
|
||||
ms.translate(f * (f2 + 0.64000005F - .1f), f3 + -0.4F + equipProgress * -0.6F,
|
||||
f4 + -0.71999997F + .3f + recoil);
|
||||
f4 + -0.71999997F + .3f + recoil);
|
||||
ms.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(f * 75.0F));
|
||||
float f5 = MathHelper.sin(event.getSwingProgress() * event.getSwingProgress() * (float) Math.PI);
|
||||
float f6 = MathHelper.sin(f1 * (float) Math.PI);
|
||||
ms.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(f * f6 * 70.0F));
|
||||
ms.multiply(Vector3f.POSITIVE_Z.getDegreesQuaternion(f * f5 * -20.0F));
|
||||
AbstractClientPlayerEntity abstractclientplayerentity = mc.player;
|
||||
mc.getTextureManager().bindTexture(abstractclientplayerentity.getLocationSkin());
|
||||
mc.getTextureManager()
|
||||
.bindTexture(abstractclientplayerentity.getLocationSkin());
|
||||
ms.translate(f * -1.0F, 3.6F, 3.5F);
|
||||
ms.multiply(Vector3f.POSITIVE_Z.getDegreesQuaternion(f * 120.0F));
|
||||
ms.multiply(Vector3f.POSITIVE_X.getDegreesQuaternion(200.0F));
|
||||
ms.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(f * -135.0F));
|
||||
ms.translate(f * 5.6F, 0.0F, 0.0F);
|
||||
ms.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(f * 40.0F));
|
||||
PlayerRenderer playerrenderer = (PlayerRenderer) mc.getRenderManager().getRenderer(abstractclientplayerentity);
|
||||
PlayerRenderer playerrenderer = (PlayerRenderer) mc.getRenderManager()
|
||||
.getRenderer(abstractclientplayerentity);
|
||||
if (rightHand) {
|
||||
playerrenderer.renderRightArm(event.getMatrixStack(), event.getBuffers(), event.getLight(), abstractclientplayerentity);
|
||||
playerrenderer.renderRightArm(event.getMatrixStack(), event.getBuffers(), event.getLight(),
|
||||
abstractclientplayerentity);
|
||||
} else {
|
||||
playerrenderer.renderLeftArm(event.getMatrixStack(), event.getBuffers(), event.getLight(), abstractclientplayerentity);
|
||||
playerrenderer.renderLeftArm(event.getMatrixStack(), event.getBuffers(), event.getLight(),
|
||||
abstractclientplayerentity);
|
||||
}
|
||||
ms.pop();
|
||||
|
||||
// Render gun
|
||||
ms.push();
|
||||
ms.translate(f * (f2 + 0.64000005F - .1f), f3 + -0.4F + equipProgress * -0.6F,
|
||||
f4 + -0.71999997F - 0.1f + recoil);
|
||||
f4 + -0.71999997F - 0.1f + recoil);
|
||||
ms.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(f * f6 * 70.0F));
|
||||
ms.multiply(Vector3f.POSITIVE_Z.getDegreesQuaternion(f * f5 * -20.0F));
|
||||
|
||||
|
@ -235,9 +211,9 @@ public class ZapperRenderHandler {
|
|||
|
||||
FirstPersonRenderer firstPersonRenderer = mc.getFirstPersonRenderer();
|
||||
firstPersonRenderer.renderItem(mc.player, heldItem,
|
||||
rightHand ? ItemCameraTransforms.TransformType.FIRST_PERSON_RIGHT_HAND
|
||||
: ItemCameraTransforms.TransformType.FIRST_PERSON_LEFT_HAND,
|
||||
!rightHand, event.getMatrixStack(), event.getBuffers(), event.getLight());
|
||||
rightHand ? ItemCameraTransforms.TransformType.FIRST_PERSON_RIGHT_HAND
|
||||
: ItemCameraTransforms.TransformType.FIRST_PERSON_LEFT_HAND,
|
||||
!rightHand, event.getMatrixStack(), event.getBuffers(), event.getLight());
|
||||
ms.pop();
|
||||
|
||||
event.setCanceled(true);
|
||||
|
|
|
@ -8,6 +8,7 @@ import com.mojang.blaze3d.platform.GlStateManager.SourceFactor;
|
|||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.simibubi.create.foundation.gui.AbstractSimiScreen;
|
||||
import com.simibubi.create.foundation.gui.AllGuiTextures;
|
||||
import com.simibubi.create.foundation.gui.GuiGameElement;
|
||||
import com.simibubi.create.foundation.gui.widgets.IconButton;
|
||||
import com.simibubi.create.foundation.networking.AllPackets;
|
||||
import com.simibubi.create.foundation.networking.NbtPacket;
|
||||
|
@ -167,9 +168,7 @@ public class ZapperScreen extends AbstractSimiScreen {
|
|||
|
||||
RenderSystem.translated(0, -5, 0);
|
||||
|
||||
minecraft.getBlockRendererDispatcher().renderBlock(state, new MatrixStack(),
|
||||
getMinecraft().getBufferBuilders().getEffectVertexConsumers(), 0xF000F0, OverlayTexture.DEFAULT_UV,
|
||||
EmptyModelData.INSTANCE);
|
||||
GuiGameElement.of(state).render();
|
||||
|
||||
RenderSystem.popMatrix();
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ import com.simibubi.create.foundation.utility.Lang;
|
|||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.math.shapes.VoxelShape;
|
||||
|
||||
public abstract class Brush {
|
||||
|
||||
|
@ -47,8 +46,6 @@ public abstract class Brush {
|
|||
return BlockPos.ZERO;
|
||||
}
|
||||
|
||||
abstract VoxelShape getSelectionBox();
|
||||
|
||||
abstract List<BlockPos> getIncludedPositions();
|
||||
|
||||
}
|
||||
|
|
|
@ -6,21 +6,16 @@ import java.util.stream.Collectors;
|
|||
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Direction.AxisDirection;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.math.shapes.VoxelShape;
|
||||
import net.minecraft.util.math.shapes.VoxelShapes;
|
||||
|
||||
public class CuboidBrush extends Brush {
|
||||
|
||||
public static final int MAX_SIZE = 32;
|
||||
private VoxelShape shape;
|
||||
private List<BlockPos> positions;
|
||||
|
||||
public CuboidBrush() {
|
||||
super(3);
|
||||
shape = VoxelShapes.empty();
|
||||
positions = new ArrayList<>();
|
||||
}
|
||||
|
||||
|
@ -28,16 +23,13 @@ public class CuboidBrush extends Brush {
|
|||
public void set(int param0, int param1, int param2) {
|
||||
boolean updateShape = this.param0 != param0 || this.param1 != param1 || this.param2 != param2;
|
||||
super.set(param0, param1, param2);
|
||||
|
||||
if (updateShape) {
|
||||
BlockPos zero = BlockPos.ZERO;
|
||||
shape = VoxelShapes.create(new AxisAlignedBB(zero).grow(1 / 32f)
|
||||
.grow(((param0 - 1) / 2f), ((param1 - 1) / 2f), ((param2 - 1) / 2f))
|
||||
.offset((1 - param0 % 2) * .5f, (1 - param1 % 2) * .5f, (1 - param2 % 2) * .5f));
|
||||
positions = BlockPos
|
||||
.getAllInBox(zero.add((param0 - 1) / -2, (param1 - 1) / -2, (param2 - 1) / -2),
|
||||
zero.add((param0) / 2, (param1) / 2, (param2) / 2))
|
||||
.map(BlockPos::new).collect(Collectors.toList());
|
||||
.getAllInBox(zero.add((param0 - 1) / -2, (param1 - 1) / -2, (param2 - 1) / -2),
|
||||
zero.add((param0) / 2, (param1) / 2, (param2) / 2))
|
||||
.map(BlockPos::new)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,8 +54,8 @@ public class CuboidBrush extends Brush {
|
|||
int y = (param1 + (param1 == 0 ? 0 : offset)) / 2;
|
||||
int z = (param2 + (param2 == 0 ? 0 : offset)) / 2;
|
||||
|
||||
return BlockPos.ZERO.offset(face,
|
||||
face.getAxis().getCoordinate(x, y, z) * (option == PlacementOptions.Attached ? 1 : -1));
|
||||
return BlockPos.ZERO.offset(face, face.getAxis()
|
||||
.getCoordinate(x, y, z) * (option == PlacementOptions.Attached ? 1 : -1));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -71,9 +63,4 @@ public class CuboidBrush extends Brush {
|
|||
return positions;
|
||||
}
|
||||
|
||||
@Override
|
||||
VoxelShape getSelectionBox() {
|
||||
return shape;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,46 +11,37 @@ import org.apache.commons.lang3.tuple.Pair;
|
|||
import com.simibubi.create.foundation.utility.Lang;
|
||||
import com.simibubi.create.foundation.utility.VecHelper;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Direction.AxisDirection;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.math.shapes.VoxelShape;
|
||||
import net.minecraft.util.math.shapes.VoxelShapes;
|
||||
|
||||
public class CylinderBrush extends Brush {
|
||||
|
||||
public static final int MAX_RADIUS = 6;
|
||||
public static final int MAX_RADIUS = 8;
|
||||
public static final int MAX_HEIGHT = 8;
|
||||
private Map<Pair<Integer, Integer>, Pair<List<BlockPos>, VoxelShape>> cachedBrushes;
|
||||
private Map<Pair<Integer, Integer>, List<BlockPos>> cachedBrushes;
|
||||
|
||||
public CylinderBrush() {
|
||||
super(2);
|
||||
|
||||
cachedBrushes = new HashMap<>();
|
||||
VoxelShape fullCube = Block.makeCuboidShape(-.5f, -.5f, -.5f, 16.5f, 16.5f, 16.5f);
|
||||
|
||||
for (int i = 0; i <= MAX_RADIUS; i++) {
|
||||
int radius = i;
|
||||
VoxelShape shape = VoxelShapes.empty();
|
||||
List<BlockPos> positions =
|
||||
BlockPos.getAllInBox(BlockPos.ZERO.add(-i - 1, 0, -i - 1), BlockPos.ZERO.add(i + 1, 0, i + 1))
|
||||
.map(BlockPos::new).filter(p -> VecHelper.getCenterOf(p)
|
||||
.distanceTo(VecHelper.getCenterOf(BlockPos.ZERO)) < radius + .42f)
|
||||
.collect(Collectors.toList());
|
||||
for (BlockPos p : positions)
|
||||
shape = VoxelShapes.or(shape, fullCube.withOffset(p.getX(), p.getY(), p.getZ()));
|
||||
.map(BlockPos::new)
|
||||
.filter(p -> VecHelper.getCenterOf(p)
|
||||
.distanceTo(VecHelper.getCenterOf(BlockPos.ZERO)) < radius + .42f)
|
||||
.collect(Collectors.toList());
|
||||
for (int h = 0; h <= MAX_HEIGHT; h++) {
|
||||
List<BlockPos> stackedPositions = new ArrayList<>();
|
||||
VoxelShape stackedShape = shape.simplify();
|
||||
for (int layer = 0; layer < h; layer++) {
|
||||
int yOffset = layer - h / 2;
|
||||
stackedShape = VoxelShapes.or(stackedShape, shape.withOffset(0, yOffset, 0));
|
||||
for (BlockPos p : positions)
|
||||
stackedPositions.add(p.up(yOffset));
|
||||
}
|
||||
cachedBrushes.put(Pair.of(i, h), Pair.of(stackedPositions, stackedShape.simplify()));
|
||||
cachedBrushes.put(Pair.of(i, h), stackedPositions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -66,8 +57,8 @@ public class CylinderBrush extends Brush {
|
|||
int r = (param0 + 1 + offset);
|
||||
int y = (param1 + (param1 == 0 ? 0 : yOffset)) / 2;
|
||||
|
||||
return BlockPos.ZERO.offset(face,
|
||||
(face.getAxis().isVertical() ? y : r) * (option == PlacementOptions.Attached ? 1 : -1));
|
||||
return BlockPos.ZERO.offset(face, (face.getAxis()
|
||||
.isVertical() ? y : r) * (option == PlacementOptions.Attached ? 1 : -1));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -85,18 +76,9 @@ public class CylinderBrush extends Brush {
|
|||
return paramIndex == 0 ? Lang.translate("generic.radius") : super.getParamLabel(paramIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
VoxelShape getSelectionBox() {
|
||||
return getEntry(param0, param1).getRight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BlockPos> getIncludedPositions() {
|
||||
return getEntry(param0, param1).getLeft();
|
||||
}
|
||||
|
||||
protected Pair<List<BlockPos>, VoxelShape> getEntry(int radius, int height) {
|
||||
return cachedBrushes.get(Pair.of(Integer.valueOf(radius), Integer.valueOf(height)));
|
||||
return cachedBrushes.get(Pair.of(Integer.valueOf(param0), Integer.valueOf(param1)));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,22 +5,17 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import com.simibubi.create.foundation.utility.Lang;
|
||||
import com.simibubi.create.foundation.utility.VecHelper;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.math.shapes.VoxelShape;
|
||||
import net.minecraft.util.math.shapes.VoxelShapes;
|
||||
|
||||
public class SphereBrush extends Brush {
|
||||
|
||||
public static final int MAX_RADIUS = 6;
|
||||
private Map<Integer, Pair<List<BlockPos>, VoxelShape>> cachedBrushes;
|
||||
public static final int MAX_RADIUS = 10;
|
||||
private Map<Integer, List<BlockPos>> cachedBrushes;
|
||||
|
||||
public SphereBrush() {
|
||||
super(1);
|
||||
|
@ -28,17 +23,12 @@ public class SphereBrush extends Brush {
|
|||
cachedBrushes = new HashMap<>();
|
||||
for (int i = 0; i <= MAX_RADIUS; i++) {
|
||||
int radius = i;
|
||||
VoxelShape shape = VoxelShapes.empty();
|
||||
List<BlockPos> positions =
|
||||
BlockPos.getAllInBox(BlockPos.ZERO.add(-i - 1, -i - 1, -i - 1), BlockPos.ZERO.add(i + 1, i + 1, i + 1))
|
||||
.map(BlockPos::new).filter(p -> VecHelper.getCenterOf(p)
|
||||
.distanceTo(VecHelper.getCenterOf(BlockPos.ZERO)) < radius + .5f)
|
||||
.collect(Collectors.toList());
|
||||
VoxelShape fullCube = Block.makeCuboidShape(-.5f, -.5f, -.5f, 16.5f, 16.5f, 16.5f);
|
||||
for (BlockPos p : positions)
|
||||
shape = VoxelShapes.or(shape, fullCube.withOffset(p.getX(), p.getY(), p.getZ()));
|
||||
shape = shape.simplify();
|
||||
cachedBrushes.put(i, Pair.of(positions, shape));
|
||||
cachedBrushes.put(i, positions);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,11 +48,6 @@ public class SphereBrush extends Brush {
|
|||
return MAX_RADIUS;
|
||||
}
|
||||
|
||||
@Override
|
||||
VoxelShape getSelectionBox() {
|
||||
return getEntry(param0).getRight();
|
||||
}
|
||||
|
||||
@Override
|
||||
String getParamLabel(int paramIndex) {
|
||||
return Lang.translate("generic.radius");
|
||||
|
@ -70,11 +55,7 @@ public class SphereBrush extends Brush {
|
|||
|
||||
@Override
|
||||
List<BlockPos> getIncludedPositions() {
|
||||
return getEntry(param0).getLeft();
|
||||
}
|
||||
|
||||
protected Pair<List<BlockPos>, VoxelShape> getEntry(int size) {
|
||||
return cachedBrushes.get(Integer.valueOf(size));
|
||||
return cachedBrushes.get(Integer.valueOf(param0));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
package com.simibubi.create.content.curiosities.zapper.terrainzapper;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.simibubi.create.AllItems;
|
||||
import com.simibubi.create.AllSpecialTextures;
|
||||
import com.simibubi.create.CreateClient;
|
||||
import com.simibubi.create.foundation.utility.NBTHelper;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.player.ClientPlayerEntity;
|
||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.WorldRenderer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.NBTUtil;
|
||||
|
@ -19,14 +20,27 @@ import net.minecraft.util.math.RayTraceContext.BlockMode;
|
|||
import net.minecraft.util.math.RayTraceContext.FluidMode;
|
||||
import net.minecraft.util.math.RayTraceResult.Type;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.math.shapes.VoxelShape;
|
||||
|
||||
public class TerrainZapperRenderHandler {
|
||||
|
||||
private static VoxelShape renderedShape;
|
||||
private static Iterable<BlockPos> renderedShape;
|
||||
private static BlockPos renderedPosition;
|
||||
|
||||
public static void tick() {
|
||||
gatherSelectedBlocks();
|
||||
if (renderedPosition == null)
|
||||
return;
|
||||
List<BlockPos> shape = (List<BlockPos>) renderedShape;
|
||||
|
||||
CreateClient.outliner.showCluster("terrainZapper", shape.stream()
|
||||
.map(pos -> pos.add(renderedPosition))
|
||||
.collect(Collectors.toList()))
|
||||
.disableNormals()
|
||||
.lineWidth(1 / 32f)
|
||||
.withFaceTexture(AllSpecialTextures.CHECKERED);
|
||||
}
|
||||
|
||||
protected static void gatherSelectedBlocks() {
|
||||
ClientPlayerEntity player = Minecraft.getInstance().player;
|
||||
ItemStack heldMain = player.getHeldItemMainhand();
|
||||
ItemStack heldOff = player.getHeldItemOffhand();
|
||||
|
@ -56,16 +70,19 @@ public class TerrainZapperRenderHandler {
|
|||
return;
|
||||
}
|
||||
|
||||
Brush brush = NBTHelper.readEnum(tag.getString("Brush"), TerrainBrushes.class).get();
|
||||
Brush brush = NBTHelper.readEnum(tag.getString("Brush"), TerrainBrushes.class)
|
||||
.get();
|
||||
PlacementOptions placement = NBTHelper.readEnum(tag.getString("Placement"), PlacementOptions.class);
|
||||
BlockPos params = NBTUtil.readBlockPos(tag.getCompound("BrushParams"));
|
||||
brush.set(params.getX(), params.getY(), params.getZ());
|
||||
renderedShape = brush.getSelectionBox();
|
||||
renderedShape = brush.getIncludedPositions();
|
||||
|
||||
Vec3d start = player.getPositionVec().add(0, player.getEyeHeight(), 0);
|
||||
Vec3d range = player.getLookVec().scale(128);
|
||||
BlockRayTraceResult raytrace = player.world.rayTraceBlocks(
|
||||
new RayTraceContext(start, start.add(range), BlockMode.OUTLINE, FluidMode.NONE, player));
|
||||
Vec3d start = player.getPositionVec()
|
||||
.add(0, player.getEyeHeight(), 0);
|
||||
Vec3d range = player.getLookVec()
|
||||
.scale(128);
|
||||
BlockRayTraceResult raytrace = player.world
|
||||
.rayTraceBlocks(new RayTraceContext(start, start.add(range), BlockMode.OUTLINE, FluidMode.NONE, player));
|
||||
if (raytrace == null || raytrace.getType() == Type.MISS) {
|
||||
renderedPosition = null;
|
||||
return;
|
||||
|
@ -75,24 +92,4 @@ public class TerrainZapperRenderHandler {
|
|||
renderedPosition = pos.add(brush.getOffset(player.getLookVec(), raytrace.getFace(), placement));
|
||||
}
|
||||
|
||||
public static void render(MatrixStack ms, IRenderTypeBuffer buffer) {
|
||||
if (renderedPosition == null)
|
||||
return;
|
||||
|
||||
// TODO 1.15 buffered render
|
||||
// RenderSystem.lineWidth(2);
|
||||
// TessellatorHelper.prepareForDrawing();
|
||||
// RenderSystem.disableTexture();
|
||||
|
||||
ms.push();
|
||||
ms.translate(renderedPosition.getX(), renderedPosition.getY(), renderedPosition.getZ());
|
||||
WorldRenderer.func_228431_a_(ms, buffer.getBuffer(RenderType.getLines()), renderedShape, 0, 0, 0, 0f, 0f, 0f, 0.5f);
|
||||
|
||||
// RenderSystem.enableTexture();
|
||||
// TessellatorHelper.cleanUpAfterDrawing();
|
||||
// RenderSystem.lineWidth(1);
|
||||
|
||||
ms.pop();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,11 +17,6 @@ public class MoveTool extends PlacementToolBase {
|
|||
@Override
|
||||
public void updateSelection() {
|
||||
super.updateSelection();
|
||||
|
||||
if (!schematicSelected)
|
||||
return;
|
||||
|
||||
renderSelectedFace = selectedFace.getAxis().isHorizontal();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -15,6 +15,7 @@ import net.minecraft.client.renderer.IRenderTypeBuffer;
|
|||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
public class Outliner {
|
||||
|
||||
|
@ -27,6 +28,17 @@ public class Outliner {
|
|||
return box.getParams();
|
||||
}
|
||||
|
||||
public OutlineParams showLine(Object slot, Vec3d start, Vec3d end) {
|
||||
if (!outlines.containsKey(slot)) {
|
||||
LineOutline outline = new LineOutline();
|
||||
outlines.put(slot, new OutlineEntry(outline));
|
||||
}
|
||||
OutlineEntry entry = outlines.get(slot);
|
||||
entry.ticksTillRemoval = 1;
|
||||
((LineOutline) entry.outline).set(start, end);
|
||||
return entry.outline.getParams();
|
||||
}
|
||||
|
||||
public OutlineParams showAABB(Object slot, AxisAlignedBB bb) {
|
||||
createAABBOutlineIfMissing(slot, bb);
|
||||
ChasingAABBOutline outline = getAndRefreshAABB(slot);
|
||||
|
|
Loading…
Reference in a new issue