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,30 +35,23 @@ 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)
|
TileEntity tile = world.getBlockTileEntity(pos.x, pos.y, pos.z);
|
||||||
|
|
||||||
|
if (tile instanceof TileMultipart)
|
||||||
{
|
{
|
||||||
if (ControlKeyModifer.isControlDown(player))
|
TMultiPart occupyingPart = ((TileMultipart) tile).partMap(side);
|
||||||
pos.offset(side ^ 1, -1);
|
TMultiPart centerPart = ((TileMultipart) tile).partMap(PartMap.CENTER.ordinal());
|
||||||
|
boolean clickedCenter = hit.mag() < 1;
|
||||||
|
|
||||||
TileEntity tile = world.getBlockTileEntity(pos.x, pos.y, pos.z);
|
if ((clickedCenter && centerPart instanceof PartGearShaft))
|
||||||
|
|
||||||
if (tile instanceof TileMultipart)
|
|
||||||
{
|
{
|
||||||
TMultiPart occupyingPart = ((TileMultipart) tile).partMap(side);
|
side ^= 1;
|
||||||
TMultiPart centerPart = ((TileMultipart) tile).partMap(PartMap.CENTER.ordinal());
|
|
||||||
|
|
||||||
boolean clickedCenter = hit.mag() < 1;
|
|
||||||
|
|
||||||
if ((clickedCenter && centerPart instanceof PartGearShaft))
|
|
||||||
{
|
|
||||||
side = ForgeDirection.getOrientation(side).getOpposite().ordinal();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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,10 +19,9 @@ 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 (tier)
|
||||||
switch (metadata)
|
|
||||||
{
|
{
|
||||||
default:
|
default:
|
||||||
RenderUtility.bind(Reference.BLOCK_TEXTURE_DIRECTORY + "planks_oak.png");
|
RenderUtility.bind(Reference.BLOCK_TEXTURE_DIRECTORY + "planks_oak.png");
|
||||||
|
@ -33,7 +33,24 @@ public class RenderGear
|
||||||
RenderUtility.bind(Reference.BLOCK_TEXTURE_DIRECTORY + "iron_block.png");
|
RenderUtility.bind(Reference.BLOCK_TEXTURE_DIRECTORY + "iron_block.png");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
MODEL.renderOnly("SmallGear");
|
|
||||||
|
RenderUtility.rotateFaceBlockToSide(ForgeDirection.getOrientation(side));
|
||||||
|
GL11.glRotated(angle, 0, 1, 0);
|
||||||
|
|
||||||
|
if (isLarge)
|
||||||
|
{
|
||||||
|
MODEL.renderOnly("LargeGear");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
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)
|
public void renderDynamic(PartGear part, double x, double y, double z, int tier)
|
||||||
|
@ -44,33 +61,7 @@ public class RenderGear
|
||||||
// Center the model first.
|
// Center the model first.
|
||||||
GL11.glTranslatef((float) x + 0.5f, (float) y + 0.5f, (float) z + 0.5f);
|
GL11.glTranslatef((float) x + 0.5f, (float) y + 0.5f, (float) z + 0.5f);
|
||||||
GL11.glPushMatrix();
|
GL11.glPushMatrix();
|
||||||
|
renderGear(part.placementSide.ordinal(), part.tier, part.getMultiBlock().isConstructed(), Math.toDegrees(part.angle));
|
||||||
RenderUtility.rotateFaceBlockToSide(part.placementSide);
|
|
||||||
|
|
||||||
GL11.glRotatef((float) Math.toDegrees(part.angle), 0, 1, 0);
|
|
||||||
|
|
||||||
switch (tier)
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (part.getMultiBlock().isConstructed())
|
|
||||||
{
|
|
||||||
MODEL.renderOnly("LargeGear");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
MODEL.renderOnly("SmallGear");
|
|
||||||
}
|
|
||||||
|
|
||||||
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