Testing a new block preview
This commit is contained in:
@@ -47,7 +47,7 @@ public class BuildConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class Visuals {
|
public static class Visuals {
|
||||||
@Comment({"Shows a white block outline for the block you manually place,",
|
@Comment({"Shows a block preview for the block you manually place,",
|
||||||
"in addition to blocks placed by the mirror or array."})
|
"in addition to blocks placed by the mirror or array."})
|
||||||
public boolean showOutlineOnCurrentBlock = false;
|
public boolean showOutlineOnCurrentBlock = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,26 @@
|
|||||||
package nl.requios.effortlessbuilding.helper;
|
package nl.requios.effortlessbuilding.helper;
|
||||||
|
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.renderer.BufferBuilder;
|
import net.minecraft.client.renderer.*;
|
||||||
import net.minecraft.client.renderer.RenderGlobal;
|
import net.minecraft.client.renderer.texture.TextureMap;
|
||||||
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.item.ItemBlock;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.ItemTool;
|
import net.minecraft.item.ItemTool;
|
||||||
|
import net.minecraft.util.EnumFacing;
|
||||||
|
import net.minecraft.util.EnumHand;
|
||||||
import net.minecraft.util.math.*;
|
import net.minecraft.util.math.*;
|
||||||
import net.minecraftforge.client.event.RenderWorldLastEvent;
|
import net.minecraftforge.client.event.RenderWorldLastEvent;
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||||
import net.minecraftforge.fml.relauncher.Side;
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
import nl.requios.effortlessbuilding.*;
|
import nl.requios.effortlessbuilding.*;
|
||||||
|
import nl.requios.effortlessbuilding.item.ItemRandomizerBag;
|
||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
|
import org.lwjgl.opengl.GL14;
|
||||||
import org.lwjgl.util.Color;
|
import org.lwjgl.util.Color;
|
||||||
|
|
||||||
@Mod.EventBusSubscriber(Side.CLIENT)
|
@Mod.EventBusSubscriber(Side.CLIENT)
|
||||||
@@ -115,17 +121,29 @@ public class RenderHelper {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Render block outlines
|
//Render block previews
|
||||||
RayTraceResult objectMouseOver = Minecraft.getMinecraft().objectMouseOver;
|
RayTraceResult objectMouseOver = Minecraft.getMinecraft().objectMouseOver;
|
||||||
//Checking for null is necessary! Even in vanilla when looking down ladders it is occasionally null (instead of Type MISS)
|
//Checking for null is necessary! Even in vanilla when looking down ladders it is occasionally null (instead of Type MISS)
|
||||||
if (objectMouseOver != null && objectMouseOver.typeOfHit == RayTraceResult.Type.BLOCK)
|
if (objectMouseOver != null && objectMouseOver.typeOfHit == RayTraceResult.Type.BLOCK)
|
||||||
{
|
{
|
||||||
BlockPos blockPos = objectMouseOver.getBlockPos();
|
BlockPos blockPos = objectMouseOver.getBlockPos();
|
||||||
|
ItemStack stack = ItemStack.EMPTY;
|
||||||
|
ItemStack mainhand = player.getHeldItemMainhand();
|
||||||
|
IBlockState blockState = null;
|
||||||
|
if (mainhand.getItem() instanceof ItemBlock) {
|
||||||
|
stack = mainhand;
|
||||||
|
Block block = ((ItemBlock) stack.getItem()).getBlock();
|
||||||
|
Vec3d hitVec = objectMouseOver.hitVec;
|
||||||
|
hitVec = new Vec3d(Math.abs(hitVec.x - ((int) hitVec.x)), Math.abs(hitVec.y - ((int) hitVec.y)), Math.abs(hitVec.z - ((int) hitVec.z)));
|
||||||
|
blockState = block.getStateForPlacement(player.world, blockPos, objectMouseOver.sideHit,
|
||||||
|
((float) hitVec.x), ((float) hitVec.y), ((float) hitVec.z), stack.getMetadata(), player, EnumHand.MAIN_HAND);
|
||||||
|
}
|
||||||
|
if (mainhand.getItem() instanceof ItemRandomizerBag) {
|
||||||
|
//TODO figure this out
|
||||||
|
}
|
||||||
|
//TODO check offhand
|
||||||
|
|
||||||
//Check if tool (or none) in hand
|
//Check if tool (or none) in hand
|
||||||
ItemStack mainhand = player.getHeldItemMainhand();
|
|
||||||
//ItemStack offhand = player.getHeldItemOffhand();
|
|
||||||
//boolean noneInHand = mainhand.isEmpty() && (offhand.isEmpty() || offhand.getItem() instanceof ItemTool);
|
|
||||||
boolean toolInHand = !mainhand.isEmpty() && mainhand.getItem() instanceof ItemTool;
|
boolean toolInHand = !mainhand.isEmpty() && mainhand.getItem() instanceof ItemTool;
|
||||||
if (!buildSettings.doQuickReplace() && !toolInHand) {
|
if (!buildSettings.doQuickReplace() && !toolInHand) {
|
||||||
blockPos = blockPos.offset(objectMouseOver.sideHit);
|
blockPos = blockPos.offset(objectMouseOver.sideHit);
|
||||||
@@ -143,6 +161,26 @@ public class RenderHelper {
|
|||||||
RenderHelper.renderBlockOutline(blockPos);
|
RenderHelper.renderBlockOutline(blockPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO testing
|
||||||
|
if (blockState != null) {
|
||||||
|
BlockRendererDispatcher dispatcher = Minecraft.getMinecraft().getBlockRendererDispatcher();
|
||||||
|
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
|
||||||
|
GlStateManager.pushMatrix();//Push matrix again just because
|
||||||
|
GL11.glEnable(GL11.GL_CULL_FACE);
|
||||||
|
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||||
|
Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
|
||||||
|
GlStateManager.enableBlend();
|
||||||
|
GlStateManager.blendFunc(GL11.GL_CONSTANT_ALPHA, GL11.GL_ONE_MINUS_CONSTANT_ALPHA);
|
||||||
|
GlStateManager.translate(blockPos.getX(), blockPos.getY(), blockPos.getZ());
|
||||||
|
GlStateManager.rotate(-90.0F, 0.0F, 1.0F, 0.0F);
|
||||||
|
GlStateManager.translate(-0.005f, -0.005f, 0.005f);
|
||||||
|
GlStateManager.scale(1.01f, 1.01f, 1.01f);
|
||||||
|
GL14.glBlendColor(1F, 1F, 1F, 0.6f);
|
||||||
|
dispatcher.renderBlockBrightness(blockState, 1f);
|
||||||
|
GlStateManager.popMatrix();
|
||||||
|
GL11.glPopAttrib();
|
||||||
|
}
|
||||||
|
|
||||||
//Mirror
|
//Mirror
|
||||||
if (m != null && m.enabled && (m.mirrorX || m.mirrorY || m.mirrorZ) &&
|
if (m != null && m.enabled && (m.mirrorX || m.mirrorY || m.mirrorZ) &&
|
||||||
!(blockPos.getX() + 0.5 < m.position.x - m.radius) && !(blockPos.getX() + 0.5 > m.position.x + m.radius) &&
|
!(blockPos.getX() + 0.5 < m.position.x - m.radius) && !(blockPos.getX() + 0.5 > m.position.x + m.radius) &&
|
||||||
|
|||||||
@@ -71,7 +71,6 @@ public class QuickReplaceMessage implements IMessage {
|
|||||||
//Send back your info
|
//Send back your info
|
||||||
return new QuickReplaceMessage(ClientProxy.previousLookAt);
|
return new QuickReplaceMessage(ClientProxy.previousLookAt);
|
||||||
|
|
||||||
//TODO break block then return
|
|
||||||
// Minecraft.getMinecraft().addScheduledTask(() -> {
|
// Minecraft.getMinecraft().addScheduledTask(() -> {
|
||||||
// EffortlessBuilding.packetHandler.sendToServer(new QuickReplaceMessage(Minecraft.getMinecraft().objectMouseOver));
|
// EffortlessBuilding.packetHandler.sendToServer(new QuickReplaceMessage(Minecraft.getMinecraft().objectMouseOver));
|
||||||
// });
|
// });
|
||||||
|
|||||||
Reference in New Issue
Block a user