Engineering table now can rotate it's crafting matrix

This commit is contained in:
Calclavia 2014-01-23 18:46:17 +08:00
parent 24079ee908
commit 8219fdfb11
9 changed files with 65 additions and 22 deletions

View file

@ -14,6 +14,7 @@ import net.minecraft.world.World;
import resonantinduction.core.prefab.block.BlockRIRotatable;
import universalelectricity.api.vector.Vector2;
import universalelectricity.api.vector.Vector3;
import calclavia.lib.utility.WorldUtility;
import calclavia.lib.utility.inventory.InventoryUtility;
import codechicken.multipart.ControlKeyModifer;
import cpw.mods.fml.relauncher.Side;
@ -58,10 +59,10 @@ public class BlockEngineeringTable extends BlockRIRotatable
{
IInventory inventory = (IInventory) tileEntity;
// PREVENTS OUTPUT FROM DROPPING!
for (int var6 = 0; var6 < inventory.getSizeInventory() - 1; ++var6)
// Don't drop the output, so subtract by one.
for (int i = 0; i < inventory.getSizeInventory() - 1; ++i)
{
ItemStack var7 = inventory.getStackInSlot(var6);
ItemStack var7 = inventory.getStackInSlot(i);
if (var7 != null)
{
@ -92,6 +93,11 @@ public class BlockEngineeringTable extends BlockRIRotatable
var12.motionY = ((float) random.nextGaussian() * var13 + 0.2F);
var12.motionZ = ((float) random.nextGaussian() * var13);
world.spawnEntityInWorld(var12);
if (var7.stackSize <= 0)
{
inventory.setInventorySlotContents(i, null);
}
}
}
}
@ -114,9 +120,14 @@ public class BlockEngineeringTable extends BlockRIRotatable
{
if (!world.isRemote)
{
Vector2 hitVector = new Vector2(hitX, hitZ);
Vector3 hitVector = new Vector3(hitX, 0, hitZ);
final double regionLength = 1d / 3d;
// Rotate the hit vector baed on direction of the tile.
hitVector.translate(new Vector3(-0.5, 0, -0.5));
hitVector.rotate(WorldUtility.getAngleFromForgeDirection(tile.getDirection()), Vector3.UP());
hitVector.translate(new Vector3(0.5, 0, 0.5));
/**
* Crafting Matrix
*/
@ -127,7 +138,7 @@ public class BlockEngineeringTable extends BlockRIRotatable
{
Vector2 check = new Vector2(j, k).scale(regionLength);
if (check.distance(hitVector) < regionLength)
if (check.distance(hitVector.toVector2()) < regionLength)
{
int slotID = j * 3 + k;
interactCurrentItem(tile, slotID, player);
@ -143,6 +154,9 @@ public class BlockEngineeringTable extends BlockRIRotatable
}
else if (hitSide != 0)
{
/**
* Take out of engineering table.
*/
if (!world.isRemote && player.inventory.getCurrentItem() == null)
{
tile.setPlayerInventory(player.inventory);

View file

@ -22,7 +22,7 @@ public class RenderEngineeringTable extends RenderItemOverlayTile
{
TileEngineeringTable tile = (TileEngineeringTable) tileEntity;
renderItemOnSides(tileEntity, tile.getStackInSlot(9), x, y, z);
renderTopOverlay(tileEntity, tile.craftingMatrix, x, y, z);
renderTopOverlay(tileEntity, tile.craftingMatrix, tile.getDirection(), x, y, z);
}
}
}

View file

@ -29,6 +29,7 @@ import universalelectricity.api.vector.Vector3;
import calclavia.lib.network.IPacketReceiver;
import calclavia.lib.network.PacketHandler;
import calclavia.lib.prefab.slot.ISlotPickResult;
import calclavia.lib.prefab.tile.IRotatable;
import calclavia.lib.prefab.tile.TileAdvanced;
import calclavia.lib.utility.inventory.AutoCraftingManager;
import calclavia.lib.utility.inventory.AutoCraftingManager.IAutoCrafter;
@ -36,7 +37,7 @@ import calclavia.lib.utility.inventory.AutoCraftingManager.IAutoCrafter;
import com.builtbroken.common.Pair;
import com.google.common.io.ByteArrayDataInput;
public class TileEngineeringTable extends TileAdvanced implements IPacketReceiver, ISidedInventory, IArmbotUseable, ISlotPickResult, IAutoCrafter
public class TileEngineeringTable extends TileAdvanced implements IPacketReceiver, IRotatable, ISidedInventory, IArmbotUseable, ISlotPickResult, IAutoCrafter
{
public static final int CRAFTING_MATRIX_END = 9;
public static final int CRAFTING_OUTPUT_END = CRAFTING_MATRIX_END + 1;
@ -530,4 +531,16 @@ public class TileEngineeringTable extends TileAdvanced implements IPacketReceive
return slots;
}
@Override
public ForgeDirection getDirection()
{
return ForgeDirection.getOrientation(getBlockMetadata());
}
@Override
public void setDirection(ForgeDirection direction)
{
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, direction.ordinal(), 3);
}
}

View file

@ -2,6 +2,7 @@ package resonantinduction.archaic.firebox;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import resonantinduction.core.render.RenderItemOverlayTile;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@ -17,7 +18,7 @@ public class RenderHotPlate extends RenderItemOverlayTile
if (tileEntity instanceof TileHotPlate)
{
TileHotPlate tile = (TileHotPlate) tileEntity;
renderTopOverlay(tileEntity, tile.getInventory().getContainedItems(), 2, 2, x, y - 0.8, z);
renderTopOverlay(tileEntity, tile.getInventory().getContainedItems(), ForgeDirection.EAST, 2, 2, x, y - 0.8, z);
}
}
}

View file

@ -2,6 +2,7 @@ package resonantinduction.archaic.imprint;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import resonantinduction.core.render.RenderItemOverlayTile;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@ -17,7 +18,7 @@ public class RenderImprinter extends RenderItemOverlayTile
if (tileEntity instanceof TileImprinter)
{
TileImprinter tile = (TileImprinter) tileEntity;
renderTopOverlay(tileEntity, tile.inventory, x, y, z);
renderTopOverlay(tileEntity, tile.inventory, ForgeDirection.EAST, x, y, z);
renderItemOnSides(tileEntity, tile.getStackInSlot(9), x, y, z);
}
}

View file

@ -1,5 +1,7 @@
package resonantinduction.core.prefab.block;
import codechicken.multipart.ControlKeyModifer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.common.Configuration;
import resonantinduction.core.Reference;
import resonantinduction.core.ResonantInductionTabs;
@ -26,4 +28,10 @@ public class BlockRIRotatable extends BlockRotatable
this.setTextureName(Reference.PREFIX + name);
this.setHardness(1f);
}
@Override
public boolean isControlDown(EntityPlayer player)
{
return ControlKeyModifer.isControlDown(player);
}
}

View file

@ -10,6 +10,7 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MovingObjectPosition;
import resonantinduction.archaic.imprint.ItemBlockImprint;
import resonantinduction.core.prefab.tile.TileEntityFilterable;
import universalelectricity.api.vector.Vector3;
import calclavia.lib.render.RenderUtility;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@ -47,11 +48,11 @@ public abstract class RenderImprintable extends TileEntitySpecialRenderer
{
if (((TileEntityFilterable) tileEntity).isInverted())
{
RenderUtility.renderFloatingText(filterStack.getTooltip(player, Minecraft.getMinecraft().gameSettings.advancedItemTooltips).get(0).toString(), (float) x + 0.5f, ((float) y + (i * 0.25f)) - 1f, (float) z + 0.5f, 0xFF8888);
RenderUtility.renderFloatingText(filterStack.getTooltip(player, Minecraft.getMinecraft().gameSettings.advancedItemTooltips).get(0).toString(), new Vector3(x, y, z).translate(0.5, i * 0.25f - 1f, z + 0.5f), 0xFF8888);
}
else
{
RenderUtility.renderFloatingText(filterStack.getTooltip(player, Minecraft.getMinecraft().gameSettings.advancedItemTooltips).get(0).toString(), (float) x + 0.5f, ((float) y + (i * 0.25f)) - 1f, (float) z + 0.5f, 0x88FF88);
RenderUtility.renderFloatingText(filterStack.getTooltip(player, Minecraft.getMinecraft().gameSettings.advancedItemTooltips).get(0).toString(), new Vector3(x, y, z).translate(0.5, i * 0.25f - 1f, z + 0.5f), 0x88FF88);
}
i++;
}

View file

@ -21,6 +21,7 @@ import org.lwjgl.opengl.GL11;
import universalelectricity.api.vector.Vector3;
import calclavia.lib.render.RenderUtility;
import calclavia.lib.utility.WorldUtility;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@ -29,19 +30,15 @@ public abstract class RenderItemOverlayTile extends TileEntitySpecialRenderer
{
private final RenderBlocks renderBlocks = new RenderBlocks();
public void renderTopOverlay(TileEntity tileEntity, ItemStack[] inventory, double x, double y, double z)
public void renderTopOverlay(TileEntity tileEntity, ItemStack[] inventory, ForgeDirection dir, double x, double y, double z)
{
renderTopOverlay(tileEntity, inventory, 3, 3, x, y, z);
renderTopOverlay(tileEntity, inventory, dir, 3, 3, x, y, z);
}
public void renderTopOverlay(TileEntity tileEntity, ItemStack[] inventory, int matrixX, int matrixZ, double x, double y, double z)
public void renderTopOverlay(TileEntity tileEntity, ItemStack[] inventory, ForgeDirection dir, int matrixX, int matrixZ, double x, double y, double z)
{
GL11.glPushMatrix();
GL11.glTranslated(x + 0.5f, y + 0.5f, z + 0.5f);
RenderUtility.rotateBlockBasedOnDirection(ForgeDirection.getOrientation(tileEntity.getBlockMetadata()));
GL11.glTranslated(-0.5f, -0.5f, -0.5f);
/**
* Render the Crafting Matrix
*/
@ -51,15 +48,17 @@ public abstract class RenderItemOverlayTile extends TileEntitySpecialRenderer
if (objectPosition != null)
{
isLooking |= objectPosition.blockX == tileEntity.xCoord && objectPosition.blockY == tileEntity.yCoord && objectPosition.blockZ == tileEntity.zCoord;
isLooking = objectPosition.blockX == tileEntity.xCoord && objectPosition.blockY == tileEntity.yCoord && objectPosition.blockZ == tileEntity.zCoord;
}
for (int i = 0; i < (matrixX * matrixZ); i++)
{
if (inventory[i] != null)
{
Vector3 translation = new Vector3((double) (i / matrixX) / ((double) matrixX) + (0.5 / (matrixX)), 1.1, (double) (i % matrixZ) / ((double) matrixZ) + (0.5 / (matrixZ)));
Vector3 translation = new Vector3((double) (i / matrixX) / ((double) matrixX) + (0.5 / (matrixX)), 1.1, (double) (i % matrixZ) / ((double) matrixZ) + (0.5 / (matrixZ))).translate(-0.5);
GL11.glPushMatrix();
GL11.glTranslated(x + 0.5f, y + 0.5f, z + 0.5f);
RenderUtility.rotateBlockBasedOnDirection(dir);
GL11.glTranslated(translation.x, translation.y, translation.z);
GL11.glScalef(0.7f, 0.7f, 0.7f);
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240);
@ -67,7 +66,13 @@ public abstract class RenderItemOverlayTile extends TileEntitySpecialRenderer
GL11.glPopMatrix();
if (isLooking)
RenderUtility.renderFloatingText("" + inventory[i].stackSize, (float) translation.x, (float) translation.y - 2f, (float) translation.z);
{
GL11.glPushMatrix();
GL11.glTranslated(x, y, z);
int angle = WorldUtility.getAngleFromForgeDirection(WorldUtility.invertX(dir));
RenderUtility.renderFloatingText("" + inventory[i].stackSize, translation.rotate(angle, Vector3.UP()).translate(0.5).translate(0, 0.3, 0));
GL11.glPopMatrix();
}
}
}
GL11.glPopMatrix();

View file

@ -46,7 +46,7 @@ public class RenderArmbot extends TileEntitySpecialRenderer implements ICustomBl
{
if (objectPosition.blockX == tileEntity.xCoord && (objectPosition.blockY == tileEntity.yCoord || objectPosition.blockY == tileEntity.yCoord + 1) && objectPosition.blockZ == tileEntity.zCoord)
{
RenderUtility.renderFloatingText(cmdText, (float) x + 0.5f, ((float) y) + 0.25f, (float) z + 0.5f, 0xFFFFFF);
RenderUtility.renderFloatingText(cmdText, new Vector3(x, y, z).add(0.5), 0xFFFFFF);
}
}
}