Moved all rendering code to RenderHelper to resolve #3 Crash on stand alone server startup.
Made sure getBuildSettings never returns null to resolve #4 Client Crash W/ OpenBlocks. Now compatible with block placers and breakers from OpenBlocks (even the Randomizer Bag works in the placer). Fixed the breakEvent in mirror for array synergy to use the blockstate of the new position. Resolves #5 Crash after destorying blocks with hand.
This commit is contained in:
@@ -11,7 +11,7 @@ apply plugin: 'net.minecraftforge.gradle.forge'
|
|||||||
//Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.
|
//Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.
|
||||||
|
|
||||||
|
|
||||||
version = "0.3"
|
version = "0.3.2"
|
||||||
group = "nl.requios.effortlessbuilding" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
|
group = "nl.requios.effortlessbuilding" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
|
||||||
archivesBaseName = "effortlessbuilding"
|
archivesBaseName = "effortlessbuilding"
|
||||||
|
|
||||||
|
|||||||
@@ -2,25 +2,17 @@ package nl.requios.effortlessbuilding;
|
|||||||
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.EnumHand;
|
import net.minecraft.util.EnumHand;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.RayTraceResult;
|
|
||||||
import net.minecraft.util.math.Vec3i;
|
import net.minecraft.util.math.Vec3i;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.client.event.RenderWorldLastEvent;
|
|
||||||
import net.minecraftforge.event.world.BlockEvent;
|
import net.minecraftforge.event.world.BlockEvent;
|
||||||
import net.minecraftforge.fml.common.Mod;
|
|
||||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.relauncher.Side;
|
|
||||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
|
||||||
import net.minecraftforge.items.IItemHandler;
|
import net.minecraftforge.items.IItemHandler;
|
||||||
import nl.requios.effortlessbuilding.item.ItemRandomizerBag;
|
import nl.requios.effortlessbuilding.item.ItemRandomizerBag;
|
||||||
|
|
||||||
@Mod.EventBusSubscriber
|
|
||||||
public class Array {
|
public class Array {
|
||||||
//TODO config file
|
//TODO config file
|
||||||
public static final int MAX_COUNT = 100;
|
public static final int MAX_COUNT = 100;
|
||||||
@@ -109,42 +101,4 @@ public class Array {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
@SideOnly(Side.CLIENT)
|
|
||||||
public static void onRender(RenderWorldLastEvent event) {
|
|
||||||
EntityPlayer player = Minecraft.getMinecraft().player;
|
|
||||||
BuildSettingsManager.BuildSettings buildSettings = BuildSettingsManager.getBuildSettings(player);
|
|
||||||
if (buildSettings == null) return;
|
|
||||||
ArraySettings a = buildSettings.getArraySettings();
|
|
||||||
|
|
||||||
if (a == null || !a.enabled || (a.offset.getX() == 0 && a.offset.getY() == 0 && a.offset.getZ() == 0)) return;
|
|
||||||
|
|
||||||
RenderHelper.begin(event.getPartialTicks());
|
|
||||||
|
|
||||||
//Render block outlines
|
|
||||||
RayTraceResult objectMouseOver = Minecraft.getMinecraft().objectMouseOver;
|
|
||||||
if (objectMouseOver.typeOfHit == RayTraceResult.Type.BLOCK)
|
|
||||||
{
|
|
||||||
BlockPos blockPos = objectMouseOver.getBlockPos();
|
|
||||||
if (!buildSettings.doQuickReplace()) blockPos = blockPos.offset(objectMouseOver.sideHit);
|
|
||||||
|
|
||||||
drawBlockOutlines(a, blockPos);
|
|
||||||
}
|
|
||||||
|
|
||||||
RenderHelper.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
|
||||||
public static void drawBlockOutlines(ArraySettings a, BlockPos pos) {
|
|
||||||
if (a == null || !a.enabled || (a.offset.getX() == 0 && a.offset.getY() == 0 && a.offset.getZ() == 0)) return;
|
|
||||||
|
|
||||||
Vec3i offset = new Vec3i(a.offset.getX(), a.offset.getY(), a.offset.getZ());
|
|
||||||
|
|
||||||
//RenderHelper.renderBlockOutline(blockPos);
|
|
||||||
for (int i = 0; i < a.count; i++)
|
|
||||||
{
|
|
||||||
pos = pos.add(offset);
|
|
||||||
RenderHelper.renderBlockOutline(pos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,13 +11,17 @@ import nl.requios.effortlessbuilding.network.BuildSettingsMessage;
|
|||||||
@Mod.EventBusSubscriber
|
@Mod.EventBusSubscriber
|
||||||
public class BuildSettingsManager {
|
public class BuildSettingsManager {
|
||||||
|
|
||||||
|
//Retrieves the buildsettings of a player through the buildModifier capability
|
||||||
|
//Never returns null
|
||||||
public static BuildSettings getBuildSettings(EntityPlayer player){
|
public static BuildSettings getBuildSettings(EntityPlayer player){
|
||||||
if (player.hasCapability(BuildModifierCapability.buildModifier, null)) {
|
if (player.hasCapability(BuildModifierCapability.buildModifier, null)) {
|
||||||
BuildModifierCapability.IBuildModifier capability = player.getCapability(BuildModifierCapability.buildModifier, null);
|
BuildModifierCapability.IBuildModifier capability = player.getCapability(BuildModifierCapability.buildModifier, null);
|
||||||
|
if (capability.getBuildModifierData() == null) {
|
||||||
|
capability.setBuildModifierData(new BuildSettings());
|
||||||
|
}
|
||||||
return capability.getBuildModifierData();
|
return capability.getBuildModifierData();
|
||||||
}
|
}
|
||||||
EffortlessBuilding.log("buildsettings is null");
|
throw new IllegalArgumentException("Player does not have buildModifier capability");
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setBuildSettings(EntityPlayer player, BuildSettings buildSettings) {
|
public static void setBuildSettings(EntityPlayer player, BuildSettings buildSettings) {
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ public class EffortlessBuilding
|
|||||||
{
|
{
|
||||||
public static final String MODID = "effortlessbuilding";
|
public static final String MODID = "effortlessbuilding";
|
||||||
public static final String NAME = "Effortless Building";
|
public static final String NAME = "Effortless Building";
|
||||||
public static final String VERSION = "0.3";
|
public static final String VERSION = "0.3.2";
|
||||||
|
|
||||||
@Mod.Instance(EffortlessBuilding.MODID)
|
@Mod.Instance(EffortlessBuilding.MODID)
|
||||||
public static EffortlessBuilding instance;
|
public static EffortlessBuilding instance;
|
||||||
|
|||||||
@@ -2,45 +2,23 @@ package nl.requios.effortlessbuilding;
|
|||||||
|
|
||||||
import net.minecraft.block.*;
|
import net.minecraft.block.*;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.entity.EntityPlayerSP;
|
|
||||||
import net.minecraft.client.renderer.BufferBuilder;
|
|
||||||
import net.minecraft.client.renderer.Tessellator;
|
|
||||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.EnumHand;
|
import net.minecraft.util.EnumHand;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.RayTraceResult;
|
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.client.event.RenderWorldLastEvent;
|
|
||||||
import net.minecraftforge.common.util.BlockSnapshot;
|
import net.minecraftforge.common.util.BlockSnapshot;
|
||||||
import net.minecraftforge.event.world.BlockEvent;
|
import net.minecraftforge.event.world.BlockEvent;
|
||||||
import net.minecraftforge.fml.common.Mod;
|
|
||||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.relauncher.Side;
|
|
||||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
|
||||||
import net.minecraftforge.items.IItemHandler;
|
import net.minecraftforge.items.IItemHandler;
|
||||||
import nl.requios.effortlessbuilding.item.ItemRandomizerBag;
|
import nl.requios.effortlessbuilding.item.ItemRandomizerBag;
|
||||||
import org.lwjgl.opengl.GL11;
|
|
||||||
import org.lwjgl.util.Color;
|
|
||||||
|
|
||||||
@Mod.EventBusSubscriber
|
|
||||||
public class Mirror {
|
public class Mirror {
|
||||||
|
|
||||||
//TODO config file
|
//TODO config file
|
||||||
public static final int MAX_RADIUS = 200;
|
public static final int MAX_RADIUS = 200;
|
||||||
|
|
||||||
private static final Color colorX = new Color(255, 72, 52);
|
|
||||||
private static final Color colorY = new Color(67, 204, 51);
|
|
||||||
private static final Color colorZ = new Color(52, 247, 255);
|
|
||||||
private static final int lineAlpha = 200;
|
|
||||||
private static final int planeAlpha = 75;
|
|
||||||
private static final Vec3d epsilon = new Vec3d(0.001, 0.001, 0.001); //prevents z-fighting
|
|
||||||
|
|
||||||
|
|
||||||
public static class MirrorSettings {
|
public static class MirrorSettings {
|
||||||
public boolean enabled = false;
|
public boolean enabled = false;
|
||||||
public Vec3d position = new Vec3d(0.5, 64.5, 0.5);
|
public Vec3d position = new Vec3d(0.5, 64.5, 0.5);
|
||||||
@@ -289,192 +267,8 @@ public class Mirror {
|
|||||||
SurvivalHelper.breakBlock(event.getWorld(), event.getPlayer(), newBlockPos);
|
SurvivalHelper.breakBlock(event.getWorld(), event.getPlayer(), newBlockPos);
|
||||||
|
|
||||||
//Array synergy
|
//Array synergy
|
||||||
BlockEvent.BreakEvent breakEvent = new BlockEvent.BreakEvent(event.getWorld(), newBlockPos, event.getState(), event.getPlayer());
|
BlockEvent.BreakEvent breakEvent = new BlockEvent.BreakEvent(event.getWorld(), newBlockPos, event.getWorld().getBlockState(newBlockPos), event.getPlayer());
|
||||||
Array.onBlockBroken(breakEvent);
|
Array.onBlockBroken(breakEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
@SideOnly(Side.CLIENT)
|
|
||||||
public static void onRender(RenderWorldLastEvent event) {
|
|
||||||
EntityPlayer player = Minecraft.getMinecraft().player;
|
|
||||||
BuildSettingsManager.BuildSettings buildSettings = BuildSettingsManager.getBuildSettings(player);
|
|
||||||
if (buildSettings == null) return;
|
|
||||||
MirrorSettings m = buildSettings.getMirrorSettings();
|
|
||||||
|
|
||||||
if (m == null || !m.enabled || (!m.mirrorX && !m.mirrorY && !m.mirrorZ)) return;
|
|
||||||
|
|
||||||
RenderHelper.begin(event.getPartialTicks());
|
|
||||||
|
|
||||||
Vec3d pos = m.position.add(epsilon);
|
|
||||||
int radius = m.radius;
|
|
||||||
|
|
||||||
if (m.mirrorX) {
|
|
||||||
Vec3d posA = new Vec3d(pos.x, pos.y - radius, pos.z - radius);
|
|
||||||
Vec3d posB = new Vec3d(pos.x, pos.y + radius, pos.z + radius);
|
|
||||||
|
|
||||||
drawMirrorPlane(posA, posB, colorX, m.drawLines, m.drawPlanes);
|
|
||||||
}
|
|
||||||
if (m.mirrorY) {
|
|
||||||
Vec3d posA = new Vec3d(pos.x - radius, pos.y, pos.z - radius);
|
|
||||||
Vec3d posB = new Vec3d(pos.x + radius, pos.y, pos.z + radius);
|
|
||||||
|
|
||||||
drawMirrorPlaneY(posA, posB, colorY, m.drawLines, m.drawPlanes);
|
|
||||||
}
|
|
||||||
if (m.mirrorZ) {
|
|
||||||
Vec3d posA = new Vec3d(pos.x - radius, pos.y - radius, pos.z);
|
|
||||||
Vec3d posB = new Vec3d(pos.x + radius, pos.y + radius, pos.z);
|
|
||||||
|
|
||||||
drawMirrorPlane(posA, posB, colorZ, m.drawLines, m.drawPlanes);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Draw axis coordinated colors if two or more axes are enabled
|
|
||||||
//(If only one is enabled the lines are that planes color)
|
|
||||||
if (m.drawLines && ((m.mirrorX && m.mirrorY) || (m.mirrorX && m.mirrorZ) || (m.mirrorY && m.mirrorZ))) {
|
|
||||||
drawMirrorLines(m);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Render block outlines
|
|
||||||
RayTraceResult objectMouseOver = Minecraft.getMinecraft().objectMouseOver;
|
|
||||||
if (objectMouseOver.typeOfHit == RayTraceResult.Type.BLOCK)
|
|
||||||
{
|
|
||||||
BlockPos blockPos = objectMouseOver.getBlockPos();
|
|
||||||
if (!buildSettings.doQuickReplace()) blockPos = blockPos.offset(objectMouseOver.sideHit);
|
|
||||||
|
|
||||||
//RenderHelper.renderBlockOutline(blockPos);
|
|
||||||
if (m.mirrorX) drawBlockOutlineX(buildSettings, blockPos);
|
|
||||||
if (m.mirrorY) drawBlockOutlineY(buildSettings, blockPos);
|
|
||||||
if (m.mirrorZ) drawBlockOutlineZ(buildSettings, blockPos);
|
|
||||||
}
|
|
||||||
|
|
||||||
RenderHelper.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
|
||||||
public static void drawMirrorPlane(Vec3d posA, Vec3d posB, Color c, boolean drawLines, boolean drawPlanes) {
|
|
||||||
|
|
||||||
GL11.glColor4d(c.getRed(), c.getGreen(), c.getBlue(), planeAlpha);
|
|
||||||
Tessellator tessellator = Tessellator.getInstance();
|
|
||||||
BufferBuilder bufferBuilder = tessellator.getBuffer();
|
|
||||||
|
|
||||||
if (drawPlanes) {
|
|
||||||
bufferBuilder.begin(GL11.GL_TRIANGLE_STRIP, DefaultVertexFormats.POSITION_COLOR);
|
|
||||||
|
|
||||||
bufferBuilder.pos(posA.x, posA.y, posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), planeAlpha).endVertex();
|
|
||||||
bufferBuilder.pos(posA.x, posB.y, posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), planeAlpha).endVertex();
|
|
||||||
bufferBuilder.pos(posB.x, posA.y, posB.z).color(c.getRed(), c.getGreen(), c.getBlue(), planeAlpha).endVertex();
|
|
||||||
bufferBuilder.pos(posB.x, posB.y, posB.z).color(c.getRed(), c.getGreen(), c.getBlue(), planeAlpha).endVertex();
|
|
||||||
|
|
||||||
tessellator.draw();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (drawLines) {
|
|
||||||
Vec3d middle = posA.add(posB).scale(0.5);
|
|
||||||
bufferBuilder.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION_COLOR);
|
|
||||||
|
|
||||||
bufferBuilder.pos(posA.x, middle.y, posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), lineAlpha).endVertex();
|
|
||||||
bufferBuilder.pos(posB.x, middle.y, posB.z).color(c.getRed(), c.getGreen(), c.getBlue(), lineAlpha).endVertex();
|
|
||||||
bufferBuilder.pos(middle.x, posA.y, middle.z).color(c.getRed(), c.getGreen(), c.getBlue(), lineAlpha).endVertex();
|
|
||||||
bufferBuilder.pos(middle.x, posB.y, middle.z).color(c.getRed(), c.getGreen(), c.getBlue(), lineAlpha).endVertex();
|
|
||||||
|
|
||||||
tessellator.draw();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
|
||||||
public static void drawMirrorPlaneY(Vec3d posA, Vec3d posB, Color c, boolean drawLines, boolean drawPlanes) {
|
|
||||||
|
|
||||||
GL11.glColor4d(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
|
|
||||||
Tessellator tessellator = Tessellator.getInstance();
|
|
||||||
BufferBuilder bufferBuilder = tessellator.getBuffer();
|
|
||||||
|
|
||||||
if (drawPlanes) {
|
|
||||||
bufferBuilder.begin(GL11.GL_TRIANGLE_STRIP, DefaultVertexFormats.POSITION_COLOR);
|
|
||||||
|
|
||||||
bufferBuilder.pos(posA.x, posA.y, posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), planeAlpha).endVertex();
|
|
||||||
bufferBuilder.pos(posA.x, posA.y, posB.z).color(c.getRed(), c.getGreen(), c.getBlue(), planeAlpha).endVertex();
|
|
||||||
bufferBuilder.pos(posB.x, posA.y, posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), planeAlpha).endVertex();
|
|
||||||
bufferBuilder.pos(posB.x, posA.y, posB.z).color(c.getRed(), c.getGreen(), c.getBlue(), planeAlpha).endVertex();
|
|
||||||
|
|
||||||
tessellator.draw();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (drawLines) {
|
|
||||||
Vec3d middle = posA.add(posB).scale(0.5);
|
|
||||||
bufferBuilder.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION_COLOR);
|
|
||||||
|
|
||||||
bufferBuilder.pos(middle.x, middle.y, posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), lineAlpha).endVertex();
|
|
||||||
bufferBuilder.pos(middle.x, middle.y, posB.z).color(c.getRed(), c.getGreen(), c.getBlue(), lineAlpha).endVertex();
|
|
||||||
bufferBuilder.pos(posA.x, middle.y, middle.z).color(c.getRed(), c.getGreen(), c.getBlue(), lineAlpha).endVertex();
|
|
||||||
bufferBuilder.pos(posB.x, middle.y, middle.z).color(c.getRed(), c.getGreen(), c.getBlue(), lineAlpha).endVertex();
|
|
||||||
|
|
||||||
tessellator.draw();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
|
||||||
public static void drawMirrorLines(MirrorSettings m) {
|
|
||||||
|
|
||||||
Vec3d pos = m.position.add(epsilon);
|
|
||||||
|
|
||||||
GL11.glColor4d(100, 100, 100, 255);
|
|
||||||
GL11.glLineWidth(2);
|
|
||||||
Tessellator tessellator = Tessellator.getInstance();
|
|
||||||
BufferBuilder bufferBuilder = tessellator.getBuffer();
|
|
||||||
|
|
||||||
bufferBuilder.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION_COLOR);
|
|
||||||
|
|
||||||
bufferBuilder.pos(pos.x - m.radius, pos.y, pos.z).color(colorZ.getRed(), colorZ.getGreen(), colorZ.getBlue(), lineAlpha).endVertex();
|
|
||||||
bufferBuilder.pos(pos.x + m.radius, pos.y, pos.z).color(colorZ.getRed(), colorZ.getGreen(), colorZ.getBlue(), lineAlpha).endVertex();
|
|
||||||
bufferBuilder.pos(pos.x, pos.y - m.radius, pos.z).color(colorY.getRed(), colorY.getGreen(), colorY.getBlue(), lineAlpha).endVertex();
|
|
||||||
bufferBuilder.pos(pos.x, pos.y + m.radius, pos.z).color(colorY.getRed(), colorY.getGreen(), colorY.getBlue(), lineAlpha).endVertex();
|
|
||||||
bufferBuilder.pos(pos.x, pos.y, pos.z - m.radius).color(colorX.getRed(), colorX.getGreen(), colorX.getBlue(), lineAlpha).endVertex();
|
|
||||||
bufferBuilder.pos(pos.x, pos.y, pos.z + m.radius).color(colorX.getRed(), colorX.getGreen(), colorX.getBlue(), lineAlpha).endVertex();
|
|
||||||
|
|
||||||
tessellator.draw();
|
|
||||||
}
|
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
|
||||||
public static void drawBlockOutlineX(BuildSettingsManager.BuildSettings buildSettings, BlockPos oldBlockPos) {
|
|
||||||
MirrorSettings m = buildSettings.getMirrorSettings();
|
|
||||||
//find mirror position
|
|
||||||
double x = m.position.x + (m.position.x - oldBlockPos.getX() - 0.5);
|
|
||||||
BlockPos newBlockPos = new BlockPos(x, oldBlockPos.getY(), oldBlockPos.getZ());
|
|
||||||
|
|
||||||
RenderHelper.renderBlockOutline(newBlockPos);
|
|
||||||
|
|
||||||
//Array synergy
|
|
||||||
Array.drawBlockOutlines(buildSettings.getArraySettings(), newBlockPos);
|
|
||||||
|
|
||||||
if (m.mirrorY) drawBlockOutlineY(buildSettings, newBlockPos);
|
|
||||||
if (m.mirrorZ) drawBlockOutlineZ(buildSettings, newBlockPos);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
|
||||||
public static void drawBlockOutlineY(BuildSettingsManager.BuildSettings buildSettings, BlockPos oldBlockPos) {
|
|
||||||
MirrorSettings m = buildSettings.getMirrorSettings();
|
|
||||||
//find mirror position
|
|
||||||
double y = m.position.y + (m.position.y - oldBlockPos.getY() - 0.5);
|
|
||||||
BlockPos newBlockPos = new BlockPos(oldBlockPos.getX(), y, oldBlockPos.getZ());
|
|
||||||
|
|
||||||
RenderHelper.renderBlockOutline(newBlockPos);
|
|
||||||
|
|
||||||
//Array synergy
|
|
||||||
Array.drawBlockOutlines(buildSettings.getArraySettings(), newBlockPos);
|
|
||||||
|
|
||||||
if (m.mirrorZ) drawBlockOutlineZ(buildSettings, newBlockPos);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
|
||||||
public static void drawBlockOutlineZ(BuildSettingsManager.BuildSettings buildSettings, BlockPos oldBlockPos) {
|
|
||||||
MirrorSettings m = buildSettings.getMirrorSettings();
|
|
||||||
//find mirror position
|
|
||||||
double z = m.position.z + (m.position.z - oldBlockPos.getZ() - 0.5);
|
|
||||||
BlockPos newBlockPos = new BlockPos(oldBlockPos.getX(), oldBlockPos.getY(), z);
|
|
||||||
|
|
||||||
RenderHelper.renderBlockOutline(newBlockPos);
|
|
||||||
|
|
||||||
//Array synergy
|
|
||||||
Array.drawBlockOutlines(buildSettings.getArraySettings(), newBlockPos);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,8 +46,6 @@ public class QuickReplace {
|
|||||||
BuildSettingsManager.BuildSettings buildSettings = BuildSettingsManager.getBuildSettings(player);
|
BuildSettingsManager.BuildSettings buildSettings = BuildSettingsManager.getBuildSettings(player);
|
||||||
if (!buildSettings.doQuickReplace()) return;
|
if (!buildSettings.doQuickReplace()) return;
|
||||||
|
|
||||||
//TODO check for bedrock, end portal etc in survival
|
|
||||||
|
|
||||||
if (!message.isBlockHit() || message.getBlockPos() == null) return;
|
if (!message.isBlockHit() || message.getBlockPos() == null) return;
|
||||||
|
|
||||||
BlockPos placedAgainstBlockPos = message.getBlockPos();
|
BlockPos placedAgainstBlockPos = message.getBlockPos();
|
||||||
@@ -63,6 +61,7 @@ public class QuickReplace {
|
|||||||
SurvivalHelper.placeBlock(player.world, player, placedAgainstBlockPos, blockState, itemStack, message.getSideHit(), true, false);
|
SurvivalHelper.placeBlock(player.world, player, placedAgainstBlockPos, blockState, itemStack, message.getSideHit(), true, false);
|
||||||
|
|
||||||
//Mirror and Array synergy
|
//Mirror and Array synergy
|
||||||
|
blockState = player.world.getBlockState(placedAgainstBlockPos);
|
||||||
BlockSnapshot blockSnapshot = new BlockSnapshot(player.world, placedAgainstBlockPos, blockState);
|
BlockSnapshot blockSnapshot = new BlockSnapshot(player.world, placedAgainstBlockPos, blockState);
|
||||||
BlockEvent.PlaceEvent placeEvent = new BlockEvent.PlaceEvent(blockSnapshot, blockState, player, EnumHand.MAIN_HAND);
|
BlockEvent.PlaceEvent placeEvent = new BlockEvent.PlaceEvent(blockSnapshot, blockState, player, EnumHand.MAIN_HAND);
|
||||||
Mirror.onBlockPlaced(placeEvent);
|
Mirror.onBlockPlaced(placeEvent);
|
||||||
|
|||||||
@@ -6,16 +6,24 @@ import net.minecraft.client.renderer.RenderGlobal;
|
|||||||
import net.minecraft.client.renderer.Tessellator;
|
import net.minecraft.client.renderer.Tessellator;
|
||||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.util.math.AxisAlignedBB;
|
import net.minecraft.util.math.*;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraftforge.client.event.RenderWorldLastEvent;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||||
import net.minecraftforge.fml.relauncher.Side;
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
|
||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
import org.lwjgl.util.Color;
|
import org.lwjgl.util.Color;
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@Mod.EventBusSubscriber(Side.CLIENT)
|
||||||
public class RenderHelper {
|
public class RenderHelper {
|
||||||
|
|
||||||
|
private static final Color colorX = new Color(255, 72, 52);
|
||||||
|
private static final Color colorY = new Color(67, 204, 51);
|
||||||
|
private static final Color colorZ = new Color(52, 247, 255);
|
||||||
|
private static final int lineAlpha = 200;
|
||||||
|
private static final int planeAlpha = 75;
|
||||||
|
private static final Vec3d epsilon = new Vec3d(0.001, 0.001, 0.001); //prevents z-fighting
|
||||||
|
|
||||||
public static void begin(float partialTicks) {
|
public static void begin(float partialTicks) {
|
||||||
EntityPlayer player = Minecraft.getMinecraft().player;
|
EntityPlayer player = Minecraft.getMinecraft().player;
|
||||||
double playerX = player.prevPosX + (player.posX - player.prevPosX) * partialTicks;
|
double playerX = player.prevPosX + (player.posX - player.prevPosX) * partialTicks;
|
||||||
@@ -57,4 +65,221 @@ public class RenderHelper {
|
|||||||
RenderGlobal.drawSelectionBoundingBox(aabb, 1f, 1f, 1f, 0.6f);
|
RenderGlobal.drawSelectionBoundingBox(aabb, 1f, 1f, 1f, 0.6f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onRender(RenderWorldLastEvent event) {
|
||||||
|
EntityPlayer player = Minecraft.getMinecraft().player;
|
||||||
|
BuildSettingsManager.BuildSettings buildSettings = BuildSettingsManager.getBuildSettings(player);
|
||||||
|
if (buildSettings == null) return;
|
||||||
|
Mirror.MirrorSettings m = buildSettings.getMirrorSettings();
|
||||||
|
Array.ArraySettings a = buildSettings.getArraySettings();
|
||||||
|
|
||||||
|
begin(event.getPartialTicks());
|
||||||
|
|
||||||
|
//Mirror
|
||||||
|
if (m != null && m.enabled && (m.mirrorX || m.mirrorY || m.mirrorZ))
|
||||||
|
{
|
||||||
|
Vec3d pos = m.position.add(epsilon);
|
||||||
|
int radius = m.radius;
|
||||||
|
|
||||||
|
if (m.mirrorX)
|
||||||
|
{
|
||||||
|
Vec3d posA = new Vec3d(pos.x, pos.y - radius, pos.z - radius);
|
||||||
|
Vec3d posB = new Vec3d(pos.x, pos.y + radius, pos.z + radius);
|
||||||
|
|
||||||
|
drawMirrorPlane(posA, posB, colorX, m.drawLines, m.drawPlanes);
|
||||||
|
}
|
||||||
|
if (m.mirrorY)
|
||||||
|
{
|
||||||
|
Vec3d posA = new Vec3d(pos.x - radius, pos.y, pos.z - radius);
|
||||||
|
Vec3d posB = new Vec3d(pos.x + radius, pos.y, pos.z + radius);
|
||||||
|
|
||||||
|
drawMirrorPlaneY(posA, posB, colorY, m.drawLines, m.drawPlanes);
|
||||||
|
}
|
||||||
|
if (m.mirrorZ)
|
||||||
|
{
|
||||||
|
Vec3d posA = new Vec3d(pos.x - radius, pos.y - radius, pos.z);
|
||||||
|
Vec3d posB = new Vec3d(pos.x + radius, pos.y + radius, pos.z);
|
||||||
|
|
||||||
|
drawMirrorPlane(posA, posB, colorZ, m.drawLines, m.drawPlanes);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Draw axis coordinated colors if two or more axes are enabled
|
||||||
|
//(If only one is enabled the lines are that planes color)
|
||||||
|
if (m.drawLines && ((m.mirrorX && m.mirrorY) || (m.mirrorX && m.mirrorZ) || (m.mirrorY && m.mirrorZ)))
|
||||||
|
{
|
||||||
|
drawMirrorLines(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Render block outlines
|
||||||
|
RayTraceResult objectMouseOver = Minecraft.getMinecraft().objectMouseOver;
|
||||||
|
if (objectMouseOver.typeOfHit == RayTraceResult.Type.BLOCK)
|
||||||
|
{
|
||||||
|
BlockPos blockPos = objectMouseOver.getBlockPos();
|
||||||
|
if (!buildSettings.doQuickReplace()) blockPos = blockPos.offset(objectMouseOver.sideHit);
|
||||||
|
|
||||||
|
//RenderHelper.renderBlockOutline(blockPos);
|
||||||
|
if (m.mirrorX) drawMirrorBlockOutlineX(buildSettings, blockPos);
|
||||||
|
if (m.mirrorY) drawMirrorBlockOutlineY(buildSettings, blockPos);
|
||||||
|
if (m.mirrorZ) drawMirrorBlockOutlineZ(buildSettings, blockPos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Array
|
||||||
|
if (a != null && a.enabled && (a.offset.getX() != 0 || a.offset.getY() != 0 || a.offset.getZ() != 0))
|
||||||
|
{
|
||||||
|
//Render block outlines
|
||||||
|
RayTraceResult objectMouseOver = Minecraft.getMinecraft().objectMouseOver;
|
||||||
|
if (objectMouseOver.typeOfHit == RayTraceResult.Type.BLOCK)
|
||||||
|
{
|
||||||
|
BlockPos blockPos = objectMouseOver.getBlockPos();
|
||||||
|
if (!buildSettings.doQuickReplace()) blockPos = blockPos.offset(objectMouseOver.sideHit);
|
||||||
|
|
||||||
|
drawArrayBlockOutlines(a, blockPos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
end();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//----Mirror----
|
||||||
|
|
||||||
|
public static void drawMirrorPlane(Vec3d posA, Vec3d posB, Color c, boolean drawLines, boolean drawPlanes) {
|
||||||
|
|
||||||
|
GL11.glColor4d(c.getRed(), c.getGreen(), c.getBlue(), planeAlpha);
|
||||||
|
Tessellator tessellator = Tessellator.getInstance();
|
||||||
|
BufferBuilder bufferBuilder = tessellator.getBuffer();
|
||||||
|
|
||||||
|
if (drawPlanes) {
|
||||||
|
bufferBuilder.begin(GL11.GL_TRIANGLE_STRIP, DefaultVertexFormats.POSITION_COLOR);
|
||||||
|
|
||||||
|
bufferBuilder.pos(posA.x, posA.y, posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), planeAlpha).endVertex();
|
||||||
|
bufferBuilder.pos(posA.x, posB.y, posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), planeAlpha).endVertex();
|
||||||
|
bufferBuilder.pos(posB.x, posA.y, posB.z).color(c.getRed(), c.getGreen(), c.getBlue(), planeAlpha).endVertex();
|
||||||
|
bufferBuilder.pos(posB.x, posB.y, posB.z).color(c.getRed(), c.getGreen(), c.getBlue(), planeAlpha).endVertex();
|
||||||
|
|
||||||
|
tessellator.draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (drawLines) {
|
||||||
|
Vec3d middle = posA.add(posB).scale(0.5);
|
||||||
|
bufferBuilder.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION_COLOR);
|
||||||
|
|
||||||
|
bufferBuilder.pos(posA.x, middle.y, posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), lineAlpha).endVertex();
|
||||||
|
bufferBuilder.pos(posB.x, middle.y, posB.z).color(c.getRed(), c.getGreen(), c.getBlue(), lineAlpha).endVertex();
|
||||||
|
bufferBuilder.pos(middle.x, posA.y, middle.z).color(c.getRed(), c.getGreen(), c.getBlue(), lineAlpha).endVertex();
|
||||||
|
bufferBuilder.pos(middle.x, posB.y, middle.z).color(c.getRed(), c.getGreen(), c.getBlue(), lineAlpha).endVertex();
|
||||||
|
|
||||||
|
tessellator.draw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void drawMirrorPlaneY(Vec3d posA, Vec3d posB, Color c, boolean drawLines, boolean drawPlanes) {
|
||||||
|
|
||||||
|
GL11.glColor4d(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
|
||||||
|
Tessellator tessellator = Tessellator.getInstance();
|
||||||
|
BufferBuilder bufferBuilder = tessellator.getBuffer();
|
||||||
|
|
||||||
|
if (drawPlanes) {
|
||||||
|
bufferBuilder.begin(GL11.GL_TRIANGLE_STRIP, DefaultVertexFormats.POSITION_COLOR);
|
||||||
|
|
||||||
|
bufferBuilder.pos(posA.x, posA.y, posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), planeAlpha).endVertex();
|
||||||
|
bufferBuilder.pos(posA.x, posA.y, posB.z).color(c.getRed(), c.getGreen(), c.getBlue(), planeAlpha).endVertex();
|
||||||
|
bufferBuilder.pos(posB.x, posA.y, posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), planeAlpha).endVertex();
|
||||||
|
bufferBuilder.pos(posB.x, posA.y, posB.z).color(c.getRed(), c.getGreen(), c.getBlue(), planeAlpha).endVertex();
|
||||||
|
|
||||||
|
tessellator.draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (drawLines) {
|
||||||
|
Vec3d middle = posA.add(posB).scale(0.5);
|
||||||
|
bufferBuilder.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION_COLOR);
|
||||||
|
|
||||||
|
bufferBuilder.pos(middle.x, middle.y, posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), lineAlpha).endVertex();
|
||||||
|
bufferBuilder.pos(middle.x, middle.y, posB.z).color(c.getRed(), c.getGreen(), c.getBlue(), lineAlpha).endVertex();
|
||||||
|
bufferBuilder.pos(posA.x, middle.y, middle.z).color(c.getRed(), c.getGreen(), c.getBlue(), lineAlpha).endVertex();
|
||||||
|
bufferBuilder.pos(posB.x, middle.y, middle.z).color(c.getRed(), c.getGreen(), c.getBlue(), lineAlpha).endVertex();
|
||||||
|
|
||||||
|
tessellator.draw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void drawMirrorLines(Mirror.MirrorSettings m) {
|
||||||
|
|
||||||
|
Vec3d pos = m.position.add(epsilon);
|
||||||
|
|
||||||
|
GL11.glColor4d(100, 100, 100, 255);
|
||||||
|
GL11.glLineWidth(2);
|
||||||
|
Tessellator tessellator = Tessellator.getInstance();
|
||||||
|
BufferBuilder bufferBuilder = tessellator.getBuffer();
|
||||||
|
|
||||||
|
bufferBuilder.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION_COLOR);
|
||||||
|
|
||||||
|
bufferBuilder.pos(pos.x - m.radius, pos.y, pos.z).color(colorZ.getRed(), colorZ.getGreen(), colorZ.getBlue(), lineAlpha).endVertex();
|
||||||
|
bufferBuilder.pos(pos.x + m.radius, pos.y, pos.z).color(colorZ.getRed(), colorZ.getGreen(), colorZ.getBlue(), lineAlpha).endVertex();
|
||||||
|
bufferBuilder.pos(pos.x, pos.y - m.radius, pos.z).color(colorY.getRed(), colorY.getGreen(), colorY.getBlue(), lineAlpha).endVertex();
|
||||||
|
bufferBuilder.pos(pos.x, pos.y + m.radius, pos.z).color(colorY.getRed(), colorY.getGreen(), colorY.getBlue(), lineAlpha).endVertex();
|
||||||
|
bufferBuilder.pos(pos.x, pos.y, pos.z - m.radius).color(colorX.getRed(), colorX.getGreen(), colorX.getBlue(), lineAlpha).endVertex();
|
||||||
|
bufferBuilder.pos(pos.x, pos.y, pos.z + m.radius).color(colorX.getRed(), colorX.getGreen(), colorX.getBlue(), lineAlpha).endVertex();
|
||||||
|
|
||||||
|
tessellator.draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void drawMirrorBlockOutlineX(BuildSettingsManager.BuildSettings buildSettings, BlockPos oldBlockPos) {
|
||||||
|
Mirror.MirrorSettings m = buildSettings.getMirrorSettings();
|
||||||
|
//find mirror position
|
||||||
|
double x = m.position.x + (m.position.x - oldBlockPos.getX() - 0.5);
|
||||||
|
BlockPos newBlockPos = new BlockPos(x, oldBlockPos.getY(), oldBlockPos.getZ());
|
||||||
|
|
||||||
|
RenderHelper.renderBlockOutline(newBlockPos);
|
||||||
|
|
||||||
|
//Array synergy
|
||||||
|
drawArrayBlockOutlines(buildSettings.getArraySettings(), newBlockPos);
|
||||||
|
|
||||||
|
if (m.mirrorY) drawMirrorBlockOutlineY(buildSettings, newBlockPos);
|
||||||
|
if (m.mirrorZ) drawMirrorBlockOutlineZ(buildSettings, newBlockPos);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void drawMirrorBlockOutlineY(BuildSettingsManager.BuildSettings buildSettings, BlockPos oldBlockPos) {
|
||||||
|
Mirror.MirrorSettings m = buildSettings.getMirrorSettings();
|
||||||
|
//find mirror position
|
||||||
|
double y = m.position.y + (m.position.y - oldBlockPos.getY() - 0.5);
|
||||||
|
BlockPos newBlockPos = new BlockPos(oldBlockPos.getX(), y, oldBlockPos.getZ());
|
||||||
|
|
||||||
|
RenderHelper.renderBlockOutline(newBlockPos);
|
||||||
|
|
||||||
|
//Array synergy
|
||||||
|
drawArrayBlockOutlines(buildSettings.getArraySettings(), newBlockPos);
|
||||||
|
|
||||||
|
if (m.mirrorZ) drawMirrorBlockOutlineZ(buildSettings, newBlockPos);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void drawMirrorBlockOutlineZ(BuildSettingsManager.BuildSettings buildSettings, BlockPos oldBlockPos) {
|
||||||
|
Mirror.MirrorSettings m = buildSettings.getMirrorSettings();
|
||||||
|
//find mirror position
|
||||||
|
double z = m.position.z + (m.position.z - oldBlockPos.getZ() - 0.5);
|
||||||
|
BlockPos newBlockPos = new BlockPos(oldBlockPos.getX(), oldBlockPos.getY(), z);
|
||||||
|
|
||||||
|
RenderHelper.renderBlockOutline(newBlockPos);
|
||||||
|
|
||||||
|
//Array synergy
|
||||||
|
drawArrayBlockOutlines(buildSettings.getArraySettings(), newBlockPos);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//----Array----
|
||||||
|
|
||||||
|
public static void drawArrayBlockOutlines(Array.ArraySettings a, BlockPos pos) {
|
||||||
|
if (a == null || !a.enabled || (a.offset.getX() == 0 && a.offset.getY() == 0 && a.offset.getZ() == 0)) return;
|
||||||
|
|
||||||
|
Vec3i offset = new Vec3i(a.offset.getX(), a.offset.getY(), a.offset.getZ());
|
||||||
|
|
||||||
|
//RenderHelper.renderBlockOutline(blockPos);
|
||||||
|
for (int i = 0; i < a.count; i++)
|
||||||
|
{
|
||||||
|
pos = pos.add(offset);
|
||||||
|
RenderHelper.renderBlockOutline(pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user