Search in sources :

Example 36 with Pos

use of com.builtbroken.mc.lib.transform.vector.Pos in project Engine by VoltzEngine-Project.

the class Vector3Sorter method testClosestSorter.

public void testClosestSorter() {
    List<Pos> list = new ArrayList();
    Pos vec_1 = newVector(list, 1, 0, 1);
    Pos vec_2 = newVector(list, 2, 0, 2);
    Pos vec_3 = newVector(list, 3, 0, 3);
    Pos vec_4 = newVector(list, -1, 0, -2);
    Pos vec_5 = newVector(list, -4, 0, -4);
    Collections.sort(list, new Vector3DistanceComparator(new Pos(0, 0, 0)));
    assertEquals(list.get(0), vec_1);
    assertEquals(list.get(1), vec_4);
    assertEquals(list.get(2), vec_2);
    assertEquals(list.get(3), vec_3);
    assertEquals(list.get(4), vec_5);
}
Also used : Vector3DistanceComparator(com.builtbroken.mc.lib.transform.sorting.Vector3DistanceComparator) Pos(com.builtbroken.mc.lib.transform.vector.Pos) ArrayList(java.util.ArrayList)

Example 37 with Pos

use of com.builtbroken.mc.lib.transform.vector.Pos in project Engine by VoltzEngine-Project.

the class RenderTaggedTile method renderTileEntityAt.

@Override
public void renderTileEntityAt(TileEntity t, double x, double y, double z, float f) {
    if (t != null) {
        if (t instanceof ITagRender && this.getPlayer().getDistance(t.xCoord, t.yCoord, t.zCoord) <= RendererLivingEntity.NAME_TAG_RANGE) {
            HashMap<String, Integer> tags = new HashMap<>();
            float height = ((ITagRender) t).addInformation(tags, this.getPlayer());
            EntityPlayer player = Minecraft.getMinecraft().thePlayer;
            if (player.ridingEntity == null) {
                MovingObjectPosition objectPosition = player.rayTrace(8, 1);
                if (objectPosition != null) {
                    boolean isLooking = false;
                    for (int h = 0; h < height; h++) {
                        if (objectPosition.blockX == t.xCoord && objectPosition.blockY == t.yCoord + h && objectPosition.blockZ == t.zCoord) {
                            isLooking = true;
                        }
                    }
                    if (isLooking) {
                        Iterator<Entry<String, Integer>> it = tags.entrySet().iterator();
                        int i = 0;
                        while (it.hasNext()) {
                            Entry<String, Integer> entry = it.next();
                            if (entry.getKey() != null) {
                                RenderUtility.renderFloatingText(entry.getKey(), new Pos(x, y, z).add(new Pos(0.5, i * 0.25f + height, 0.5f)), entry.getValue());
                            }
                            i++;
                        }
                    }
                }
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) ITagRender(com.builtbroken.mc.api.tile.ITagRender) Entry(java.util.Map.Entry) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) Pos(com.builtbroken.mc.lib.transform.vector.Pos) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 38 with Pos

use of com.builtbroken.mc.lib.transform.vector.Pos in project Engine by VoltzEngine-Project.

the class RegionController method onPlayerInteract.

@SubscribeEvent
public void onPlayerInteract(PlayerInteractEvent event) {
    if (!event.world.isRemote && event.world.provider.dimensionId == dim) {
        EntityPlayer player = event.entityPlayer;
        List<Region> regionList = getRegionsAtLocation(new Pos(event.x, event.y, event.z));
        if (regionList != null && regionList.size() > 0) {
            for (Region region : regionList) {
                AccessUser user = region.getAccessProfile().getUserAccess(player);
                if (event.action == PlayerInteractEvent.Action.LEFT_CLICK_BLOCK) {
                    if (!user.hasNode(RegionManager.leftClick.toString())) {
                        event.setCanceled(true);
                        player.addChatComponentMessage(new ChatComponentText("You do not have the permission to do that here!"));
                    }
                } else if (event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) {
                    if (!user.hasNode(RegionManager.rightClick.toString())) {
                        event.setCanceled(true);
                        player.addChatComponentMessage(new ChatComponentText("You do not have the permission to do that here!"));
                    }
                }
            }
        }
    }
}
Also used : Pos(com.builtbroken.mc.lib.transform.vector.Pos) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ChatComponentText(net.minecraft.util.ChatComponentText) AccessUser(com.builtbroken.mc.lib.access.AccessUser) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 39 with Pos

use of com.builtbroken.mc.lib.transform.vector.Pos in project Engine by VoltzEngine-Project.

the class RenderItemOverlayUtility method renderTopOverlay.

public static void renderTopOverlay(TileEntity tileEntity, ItemStack[] inventory, ForgeDirection dir, int matrixX, int matrixZ, double x, double y, double z, float scale) {
    GL11.glPushMatrix();
    /**
     * Render the Crafting Matrix
     */
    EntityPlayer player = Minecraft.getMinecraft().thePlayer;
    boolean isLooking = false;
    MovingObjectPosition objectPosition = player.rayTrace(8, 1);
    if (objectPosition != null) {
        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) {
            Pos translation = new Pos((double) (i / matrixX) / ((double) matrixX) + (0.5 / (matrixX)), 1.1, (double) (i % matrixZ) / ((double) matrixZ) + (0.5 / (matrixZ))).add(-0.5);
            translation.multiply(0.85);
            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(scale, scale, scale);
            OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240);
            renderItem(tileEntity.getWorldObj(), ForgeDirection.UP, inventory[i], new Pos(0, 0, 0), 0, 4);
            GL11.glPopMatrix();
            if (isLooking) {
                GL11.glPushMatrix();
                GL11.glTranslated(x, y, z);
                int angle = WorldUtility.getAngleFromForgeDirection(WorldUtility.invertX(dir));
                RenderUtility.renderFloatingText("" + inventory[i].stackSize, new Pos(translation.transform(new Quaternion(angle, Pos.up))).add(0.5).add(new Pos(0, 0.3, 0)));
                GL11.glPopMatrix();
            }
        }
    }
    GL11.glPopMatrix();
}
Also used : MovingObjectPosition(net.minecraft.util.MovingObjectPosition) Pos(com.builtbroken.mc.lib.transform.vector.Pos) Quaternion(com.builtbroken.mc.lib.transform.rotation.Quaternion) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 40 with Pos

use of com.builtbroken.mc.lib.transform.vector.Pos in project Engine by VoltzEngine-Project.

the class FXElectricBolt method split.

/**
 * Slits a large segment into multiple smaller ones.
 *
 * @param splitAmount - The amount of splits
 * @param offset      - The multiplier multiply for the offset.
 * @param splitChance - The chance of creating a split.
 * @param splitLength - The length of each split.
 * @param splitAngle  - The angle of the split.
 */
public void split(int splitAmount, double offset, float splitChance, float splitLength, float splitAngle) {
    if (!this.isCalculated) {
        /**
         * Temporarily store old segments in a new array
         */
        ArrayList<BoltSegment> oldSegments = this.segments;
        this.segments = new ArrayList();
        /**
         * Previous segment
         */
        BoltSegment prev = null;
        for (BoltSegment segment : oldSegments) {
            prev = segment.prevSegment;
            Pos subSegment = segment.difference.multiply(1.0F / splitAmount);
            /**
             * Creates an array of new bolt points. The first and last points of the bolts are
             * the respected start and end points of the current segment.
             */
            BoltPoint[] newPoints = new BoltPoint[splitAmount + 1];
            Pos startPoint = segment.startBolt.point;
            newPoints[0] = segment.startBolt;
            newPoints[splitAmount] = segment.endBolt;
            for (int i = 1; i < splitAmount; i++) {
                // Vector3 offsetVec = segment.difference.perpendicular().rotate(this.rand.nextFloat() * 360.0F, segment.difference).multiply((this.rand.nextFloat() - 0.5F) * offset);
                Pos offsetVec = new Pos(segment.difference.perpendicular().transform(new Quaternion(this.rand.nextFloat() * 360.0F, segment.difference))).multiply((this.rand.nextFloat() - 0.5F) * offset);
                Pos basepoint = startPoint.clone().add(subSegment.clone().multiply(i));
                newPoints[i] = new BoltPoint(basepoint, offsetVec);
            }
            for (int i = 0; i < splitAmount; i++) {
                BoltSegment next = new BoltSegment(newPoints[i], newPoints[(i + 1)], segment.weight, segment.segmentID * splitAmount + i, segment.splitID);
                next.prevSegment = prev;
                if (prev != null) {
                    prev.nextSegment = next;
                }
                if ((i != 0) && (this.rand.nextFloat() < splitChance)) {
                    // Vector3 splitrot = next.difference.xCross().rotate(this.rand.nextFloat() * 360.0F, next.difference);
                    Pos splitrot = new Pos(next.difference.xCross().transform(new Quaternion(this.rand.nextFloat() * 360.0F, next.difference)));
                    // Vector3 diff = next.difference.clone().rotate((this.rand.nextFloat() * 0.66F + 0.33F) * splitAngle, splitrot).multiply(splitLength);
                    Pos diff = new Pos(next.difference.clone().transform(new Quaternion((this.rand.nextFloat() * 0.66F + 0.33F) * splitAngle, splitrot))).multiply(splitLength);
                    this.maxSplitID += 1;
                    this.splitparents.put(this.maxSplitID, next.splitID);
                    BoltSegment split = new BoltSegment(newPoints[i], new BoltPoint(newPoints[(i + 1)].basePoint, newPoints[(i + 1)].offSet.clone().add(diff)), segment.weight / 2.0F, next.segmentID, this.maxSplitID);
                    split.prevSegment = prev;
                    this.segments.add(split);
                }
                prev = next;
                this.segments.add(next);
            }
            if (segment.nextSegment != null) {
                segment.nextSegment.prevSegment = prev;
            }
        }
        this.segmentCount *= splitAmount;
    }
}
Also used : Pos(com.builtbroken.mc.lib.transform.vector.Pos) Quaternion(com.builtbroken.mc.lib.transform.rotation.Quaternion)

Aggregations

Pos (com.builtbroken.mc.lib.transform.vector.Pos)68 Block (net.minecraft.block.Block)11 TileEntity (net.minecraft.tileentity.TileEntity)8 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)8 FakeWorld (com.builtbroken.mc.testing.junit.world.FakeWorld)7 Cube (com.builtbroken.mc.lib.transform.region.Cube)6 Test (org.junit.Test)6 IPos3D (com.builtbroken.jlib.data.vector.IPos3D)5 BlockEdit (com.builtbroken.mc.lib.world.edit.BlockEdit)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 Vector3DistanceComparator (com.builtbroken.mc.lib.transform.sorting.Vector3DistanceComparator)4 BlockTile (com.builtbroken.mc.prefab.tile.BlockTile)4 Tile (com.builtbroken.mc.prefab.tile.Tile)4 EntityPlayer (net.minecraft.entity.player.EntityPlayer)4 World (net.minecraft.world.World)4 Pair (com.builtbroken.jlib.type.Pair)3 PacketTile (com.builtbroken.mc.core.network.packet.PacketTile)3 Quaternion (com.builtbroken.mc.lib.transform.rotation.Quaternion)3 AbstractTest (com.builtbroken.mc.testing.junit.AbstractTest)3