Polished gear placement, grid now renders for gear placing
This commit is contained in:
parent
506e3bbeba
commit
d359e6b46b
5 changed files with 73 additions and 53 deletions
|
@ -0,0 +1,36 @@
|
||||||
|
package resonantinduction.core;
|
||||||
|
|
||||||
|
import net.minecraft.util.EnumMovingObjectType;
|
||||||
|
import net.minecraftforge.client.event.DrawBlockHighlightEvent;
|
||||||
|
import net.minecraftforge.event.ForgeSubscribe;
|
||||||
|
|
||||||
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
|
import calclavia.lib.render.RenderUtility;
|
||||||
|
import resonantinduction.mechanical.Mechanical;
|
||||||
|
import resonantinduction.mechanical.gear.RenderGear;
|
||||||
|
import codechicken.lib.render.CCRenderState;
|
||||||
|
import codechicken.lib.render.RenderUtils;
|
||||||
|
import codechicken.lib.render.TextureUtils;
|
||||||
|
import codechicken.lib.vec.Vector3;
|
||||||
|
import codechicken.microblock.FacePlacementGrid$;
|
||||||
|
import cpw.mods.fml.relauncher.Side;
|
||||||
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
|
public class MicroblockHighlightHandler
|
||||||
|
{
|
||||||
|
@ForgeSubscribe
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
public void drawBlockHighlight(DrawBlockHighlightEvent event)
|
||||||
|
{
|
||||||
|
if (event.currentItem != null && event.currentItem.getItem() == Mechanical.itemGear && event.target != null && event.target.typeOfHit == EnumMovingObjectType.TILE)
|
||||||
|
{
|
||||||
|
GL11.glPushMatrix();
|
||||||
|
RenderUtils.translateToWorldCoords(event.player, event.partialTicks);
|
||||||
|
Vector3 hit = new Vector3(event.target.hitVec);
|
||||||
|
FacePlacementGrid$.MODULE$.render(hit, event.target.sideHit);
|
||||||
|
event.setCanceled(true);
|
||||||
|
GL11.glPopMatrix();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -96,6 +96,7 @@ public class ResonantInduction
|
||||||
// Register Forge Events
|
// Register Forge Events
|
||||||
MinecraftForge.EVENT_BUS.register(ResourceGenerator.INSTANCE);
|
MinecraftForge.EVENT_BUS.register(ResourceGenerator.INSTANCE);
|
||||||
MinecraftForge.EVENT_BUS.register(new TextureHookHandler());
|
MinecraftForge.EVENT_BUS.register(new TextureHookHandler());
|
||||||
|
MinecraftForge.EVENT_BUS.register(new MicroblockHighlightHandler());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Melting dusts
|
* Melting dusts
|
||||||
|
|
|
@ -8,10 +8,9 @@ import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
import resonantinduction.core.Settings;
|
|
||||||
import codechicken.lib.vec.BlockCoord;
|
import codechicken.lib.vec.BlockCoord;
|
||||||
import codechicken.lib.vec.Vector3;
|
import codechicken.lib.vec.Vector3;
|
||||||
import codechicken.multipart.ControlKeyModifer;
|
import codechicken.microblock.FacePlacementGrid$;
|
||||||
import codechicken.multipart.JItemMultiPart;
|
import codechicken.multipart.JItemMultiPart;
|
||||||
import codechicken.multipart.MultiPartRegistry;
|
import codechicken.multipart.MultiPartRegistry;
|
||||||
import codechicken.multipart.PartMap;
|
import codechicken.multipart.PartMap;
|
||||||
|
@ -36,11 +35,7 @@ public class ItemGear extends JItemMultiPart
|
||||||
public TMultiPart newPart(ItemStack itemStack, EntityPlayer player, World world, BlockCoord pos, int side, Vector3 hit)
|
public TMultiPart newPart(ItemStack itemStack, EntityPlayer player, World world, BlockCoord pos, int side, Vector3 hit)
|
||||||
{
|
{
|
||||||
PartGear part = (PartGear) MultiPartRegistry.createPart("resonant_induction_gear", false);
|
PartGear part = (PartGear) MultiPartRegistry.createPart("resonant_induction_gear", false);
|
||||||
|
side = FacePlacementGrid$.MODULE$.getHitSlot(hit, side);
|
||||||
if (part != null)
|
|
||||||
{
|
|
||||||
if (ControlKeyModifer.isControlDown(player))
|
|
||||||
pos.offset(side ^ 1, -1);
|
|
||||||
|
|
||||||
TileEntity tile = world.getBlockTileEntity(pos.x, pos.y, pos.z);
|
TileEntity tile = world.getBlockTileEntity(pos.x, pos.y, pos.z);
|
||||||
|
|
||||||
|
@ -48,18 +43,15 @@ public class ItemGear extends JItemMultiPart
|
||||||
{
|
{
|
||||||
TMultiPart occupyingPart = ((TileMultipart) tile).partMap(side);
|
TMultiPart occupyingPart = ((TileMultipart) tile).partMap(side);
|
||||||
TMultiPart centerPart = ((TileMultipart) tile).partMap(PartMap.CENTER.ordinal());
|
TMultiPart centerPart = ((TileMultipart) tile).partMap(PartMap.CENTER.ordinal());
|
||||||
|
|
||||||
boolean clickedCenter = hit.mag() < 1;
|
boolean clickedCenter = hit.mag() < 1;
|
||||||
|
|
||||||
if ((clickedCenter && centerPart instanceof PartGearShaft))
|
if ((clickedCenter && centerPart instanceof PartGearShaft))
|
||||||
{
|
{
|
||||||
side = ForgeDirection.getOrientation(side).getOpposite().ordinal();
|
side ^= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
part.preparePlacement(side, itemStack.getItemDamage());
|
part.preparePlacement(side, itemStack.getItemDamage());
|
||||||
}
|
|
||||||
|
|
||||||
return part;
|
return part;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import net.minecraft.block.Block;
|
||||||
import net.minecraft.client.renderer.RenderBlocks;
|
import net.minecraft.client.renderer.RenderBlocks;
|
||||||
import net.minecraftforge.client.model.AdvancedModelLoader;
|
import net.minecraftforge.client.model.AdvancedModelLoader;
|
||||||
import net.minecraftforge.client.model.IModelCustom;
|
import net.minecraftforge.client.model.IModelCustom;
|
||||||
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
|
|
||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
|
@ -18,37 +19,8 @@ public class RenderGear
|
||||||
public static final RenderGear INSTANCE = new RenderGear();
|
public static final RenderGear INSTANCE = new RenderGear();
|
||||||
public final IModelCustom MODEL = AdvancedModelLoader.loadModel(Reference.MODEL_DIRECTORY + "gears.obj");
|
public final IModelCustom MODEL = AdvancedModelLoader.loadModel(Reference.MODEL_DIRECTORY + "gears.obj");
|
||||||
|
|
||||||
public void renderInventory(Block block, int metadata, int modelID, RenderBlocks renderer)
|
public void renderGear(int side, int tier, boolean isLarge, double angle)
|
||||||
{
|
{
|
||||||
GL11.glRotatef(90, 1, 0, 0);
|
|
||||||
switch (metadata)
|
|
||||||
{
|
|
||||||
default:
|
|
||||||
RenderUtility.bind(Reference.BLOCK_TEXTURE_DIRECTORY + "planks_oak.png");
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
RenderUtility.bind(Reference.BLOCK_TEXTURE_DIRECTORY + "cobblestone.png");
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
RenderUtility.bind(Reference.BLOCK_TEXTURE_DIRECTORY + "iron_block.png");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
MODEL.renderOnly("SmallGear");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void renderDynamic(PartGear part, double x, double y, double z, int tier)
|
|
||||||
{
|
|
||||||
if (part.getMultiBlock().isPrimary())
|
|
||||||
{
|
|
||||||
GL11.glPushMatrix();
|
|
||||||
// Center the model first.
|
|
||||||
GL11.glTranslatef((float) x + 0.5f, (float) y + 0.5f, (float) z + 0.5f);
|
|
||||||
GL11.glPushMatrix();
|
|
||||||
|
|
||||||
RenderUtility.rotateFaceBlockToSide(part.placementSide);
|
|
||||||
|
|
||||||
GL11.glRotatef((float) Math.toDegrees(part.angle), 0, 1, 0);
|
|
||||||
|
|
||||||
switch (tier)
|
switch (tier)
|
||||||
{
|
{
|
||||||
default:
|
default:
|
||||||
|
@ -62,7 +34,10 @@ public class RenderGear
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (part.getMultiBlock().isConstructed())
|
RenderUtility.rotateFaceBlockToSide(ForgeDirection.getOrientation(side));
|
||||||
|
GL11.glRotated(angle, 0, 1, 0);
|
||||||
|
|
||||||
|
if (isLarge)
|
||||||
{
|
{
|
||||||
MODEL.renderOnly("LargeGear");
|
MODEL.renderOnly("LargeGear");
|
||||||
}
|
}
|
||||||
|
@ -70,7 +45,23 @@ public class RenderGear
|
||||||
{
|
{
|
||||||
MODEL.renderOnly("SmallGear");
|
MODEL.renderOnly("SmallGear");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void renderInventory(Block block, int metadata, int modelID, RenderBlocks renderer)
|
||||||
|
{
|
||||||
|
GL11.glRotatef(90, 1, 0, 0);
|
||||||
|
renderGear(-1, metadata, false, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void renderDynamic(PartGear part, double x, double y, double z, int tier)
|
||||||
|
{
|
||||||
|
if (part.getMultiBlock().isPrimary())
|
||||||
|
{
|
||||||
|
GL11.glPushMatrix();
|
||||||
|
// Center the model first.
|
||||||
|
GL11.glTranslatef((float) x + 0.5f, (float) y + 0.5f, (float) z + 0.5f);
|
||||||
|
GL11.glPushMatrix();
|
||||||
|
renderGear(part.placementSide.ordinal(), part.tier, part.getMultiBlock().isConstructed(), Math.toDegrees(part.angle));
|
||||||
GL11.glPopMatrix();
|
GL11.glPopMatrix();
|
||||||
GL11.glPopMatrix();
|
GL11.glPopMatrix();
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ public abstract class PartMechanical extends JCuboidPart implements JNormalOcclu
|
||||||
|
|
||||||
public void preparePlacement(int side, int itemDamage)
|
public void preparePlacement(int side, int itemDamage)
|
||||||
{
|
{
|
||||||
this.placementSide = ForgeDirection.getOrientation((byte) (side ^ 1));
|
this.placementSide = ForgeDirection.getOrientation((byte) (side));
|
||||||
this.tier = itemDamage;
|
this.tier = itemDamage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue