Search in sources :

Example 76 with Vec3i

use of net.minecraft.util.math.Vec3i in project CatServer by Luohuayu.

the class TRSRTransformation method rotate.

public static EnumFacing rotate(Matrix4f matrix, EnumFacing facing) {
    Vec3i dir = facing.getDirectionVec();
    Vector4f vec = new Vector4f(dir.getX(), dir.getY(), dir.getZ(), 0);
    matrix.transform(vec);
    return EnumFacing.getFacingFromVector(vec.x, vec.y, vec.z);
}
Also used : Vec3i(net.minecraft.util.math.Vec3i) Vector4f(javax.vecmath.Vector4f)

Example 77 with Vec3i

use of net.minecraft.util.math.Vec3i in project Crossroads by Crossroads-Development.

the class FatFeederTileEntity method update.

@Override
public void update() {
    if (world.isRemote) {
        return;
    }
    IAxleHandler upAxle = world.getTileEntity(pos.offset(EnumFacing.UP)) != null ? world.getTileEntity(pos.offset(EnumFacing.UP)).getCapability(Capabilities.AXLE_HANDLER_CAPABILITY, EnumFacing.DOWN) : null;
    IAxleHandler downAxle = world.getTileEntity(pos.offset(EnumFacing.DOWN)) != null ? world.getTileEntity(pos.offset(EnumFacing.DOWN)).getCapability(Capabilities.AXLE_HANDLER_CAPABILITY, EnumFacing.UP) : null;
    if (upAxle != null && downAxle != null && content != null) {
        int range = (int) (downAxle.getMotionData()[0] == 0 ? 0 : Math.abs(upAxle.getMotionData()[0] / downAxle.getMotionData()[0]));
        List<EntityPlayer> players = world.getEntitiesWithinAABB(EntityPlayer.class, new AxisAlignedBB(pos.subtract(new Vec3i(range, range, range)), pos.add(new Vec3i(range, range, range))), EntitySelectors.IS_ALIVE);
        if (players != null) {
            for (EntityPlayer play : players) {
                FoodStats food = play.getFoodStats();
                int added = (int) Math.min(content.amount / EnergyConverters.FAT_PER_VALUE, Math.min(Math.abs(upAxle.getMotionData()[1]) / ENERGY_PER_VALUE, 40 - (food.getFoodLevel() + food.getSaturationLevel())));
                if (added <= 0) {
                    continue;
                }
                content.amount -= added * EnergyConverters.FAT_PER_VALUE;
                upAxle.addEnergy(-added * ENERGY_PER_VALUE, false, false);
                downAxle.addEnergy(added * ENERGY_PER_VALUE, false, false);
                int hungerAdded = Math.min(20 - food.getFoodLevel(), added);
                // The way saturation is coded is weird, and the best way to do this is through nbt.
                NBTTagCompound nbt = new NBTTagCompound();
                food.writeNBT(nbt);
                nbt.setInteger("foodLevel", hungerAdded + food.getFoodLevel());
                nbt.setFloat("foodSaturationLevel", Math.min(20F - food.getSaturationLevel(), added - hungerAdded) + food.getSaturationLevel());
                food.readNBT(nbt);
                if (content.amount <= 0) {
                    content = null;
                    markDirty();
                    return;
                }
            }
        }
        markDirty();
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) IAxleHandler(com.Da_Technomancer.crossroads.API.rotary.IAxleHandler) Vec3i(net.minecraft.util.math.Vec3i) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EntityPlayer(net.minecraft.entity.player.EntityPlayer) FoodStats(net.minecraft.util.FoodStats)

Example 78 with Vec3i

use of net.minecraft.util.math.Vec3i in project Advent-Of-Ascension by Tslat.

the class AoAPortalFrame method testEastWestPortalFrame.

public static PortalDirection testEastWestPortalFrame(World world, BlockPos basePos, PortalBlock portalBlock) {
    Block carvedRuneTravel = null;
    Block carvedRuneReality = null;
    Block carvedRuneSpace = null;
    Block carvedRuneDirection = null;
    int ancientRockCount = 0;
    for (Vec3i pos : eastWestPattern) {
        Block testBlock = world.getBlockState(basePos.add(pos)).getBlock();
        if (testBlock == BlockRegister.ANCIENT_ROCK) {
            ancientRockCount++;
        } else if (testBlock instanceof CarvedRunicPortalBlock) {
            if (testBlock == BlockRegister.CARVED_RUNE_TRAVEL) {
                if (carvedRuneTravel != null)
                    return INVALID;
                carvedRuneTravel = testBlock;
            } else if (testBlock == BlockRegister.CARVED_RUNE_REALITY) {
                if (carvedRuneReality != null)
                    return INVALID;
                carvedRuneReality = testBlock;
            } else if (testBlock == BlockRegister.CARVED_RUNE_SPACE) {
                if (carvedRuneSpace != null)
                    return INVALID;
                carvedRuneSpace = testBlock;
            } else if (testBlock == BlockRegister.CARVED_RUNE_DIRECTION) {
                if (carvedRuneDirection != null)
                    return INVALID;
                carvedRuneDirection = testBlock;
            }
        }
    }
    if (ancientRockCount == 13 && carvedRuneDirection != null && carvedRuneReality != null && carvedRuneSpace != null && carvedRuneTravel != null) {
        for (int z = -1; z < 2; z++) {
            for (int y = 1; y < 5; y++) {
                IBlockState state = world.getBlockState(basePos.add(0, y, z));
                if (state.getBlock() instanceof PortalBlock) {
                    if (state.getBlock() == portalBlock)
                        return EXISTING;
                } else if (!state.getMaterial().isReplaceable()) {
                    return INVALID;
                }
            }
        }
        return EAST_WEST;
    }
    return INVALID;
}
Also used : Vec3i(net.minecraft.util.math.Vec3i) IBlockState(net.minecraft.block.state.IBlockState) CarvedRunicPortalBlock(net.tslat.aoa3.block.functional.misc.CarvedRunicPortalBlock) Block(net.minecraft.block.Block) PortalBlock(net.tslat.aoa3.block.functional.portal.PortalBlock) CarvedRunicPortalBlock(net.tslat.aoa3.block.functional.misc.CarvedRunicPortalBlock) CarvedRunicPortalBlock(net.tslat.aoa3.block.functional.misc.CarvedRunicPortalBlock) PortalBlock(net.tslat.aoa3.block.functional.portal.PortalBlock)

Example 79 with Vec3i

use of net.minecraft.util.math.Vec3i in project 3arthh4ck by 3arthqu4ke.

the class AutoTrap method getPositions.

/**
 * Gets the positions to trap
 * for the given player. Takes extend
 * and the noScaffold... etc. settings into
 * account.
 *
 * @param player the player to trap.
 * @return trapping positions.
 */
private List<BlockPos> getPositions(EntityPlayer player) {
    List<BlockPos> blocked = new ArrayList<>();
    BlockPos playerPos = new BlockPos(player);
    if (HoleUtil.isHole(playerPos, false)[0] || extend.getValue() == 1) {
        blocked.add(playerPos.up());
    } else {
        List<BlockPos> unfiltered = new ArrayList<>(PositionUtil.getBlockedPositions(player)).stream().sorted(Comparator.comparingDouble(BlockUtil::getDistanceSq)).collect(Collectors.toList());
        List<BlockPos> filtered = new ArrayList<>(unfiltered).stream().filter(pos -> mc.world.getBlockState(pos).getMaterial().isReplaceable() && mc.world.getBlockState(pos.up()).getMaterial().isReplaceable()).collect(Collectors.toList());
        if (extend.getValue() == 3 && filtered.size() == 2 && unfiltered.size() == 4) {
            /*
                    Prevents that a pos like this
                   (x == block, o == air, i = player):

                    o x                              x
                    x i     can extend to this:    x o x
                                                     x i
                */
            if (unfiltered.get(0).equals(filtered.get(0)) && unfiltered.get(3).equals(filtered.get(1))) {
                filtered.clear();
            }
        }
        if (extend.getValue() == 2 && filtered.size() > 2 || extend.getValue() == 3 && filtered.size() == 3) {
            /*
                    Prevents that a pos like this
                   (x == block, o == air, i = player):

                    x  o                               x
                     i      can extend to this:    x   o  x
                                                 x   i    x
                                                   x   x

                   we should, unless he phased in, be able to place on o
                */
            while (filtered.size() > 2) {
                filtered.remove(filtered.size() - 1);
            }
        }
        for (BlockPos pos : filtered) {
            blocked.add(pos.up());
        }
    }
    if (blocked.isEmpty()) {
        blocked.add(playerPos.up());
    }
    List<BlockPos> positions = positionsFromBlocked(blocked);
    // sort so we start placing behind (furthest away) first.
    positions.sort(Comparator.comparingDouble(pos -> -BlockUtil.getDistanceSq(pos)));
    // sort by y so we start placing from bottom up.
    positions.sort(Comparator.comparingInt(Vec3i::getY));
    return positions.stream().filter(pos -> BlockUtil.getDistanceSq(pos) <= MathUtil.square(range.getValue())).collect(Collectors.toList());
}
Also used : Managers(me.earth.earthhack.impl.managers.Managers) EntityEnderCrystal(net.minecraft.entity.item.EntityEnderCrystal) BooleanSetting(me.earth.earthhack.api.setting.settings.BooleanSetting) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) ObbyListenerModule(me.earth.earthhack.impl.util.helpers.blocks.ObbyListenerModule) BlockUtil(me.earth.earthhack.impl.util.minecraft.blocks.BlockUtil) HoleUtil(me.earth.earthhack.impl.util.minecraft.blocks.HoleUtil) Setting(me.earth.earthhack.api.setting.Setting) HashMap(java.util.HashMap) Trap(me.earth.earthhack.impl.modules.combat.autotrap.util.Trap) ArrayList(java.util.ArrayList) MathUtil(me.earth.earthhack.impl.util.math.MathUtil) PositionUtil(me.earth.earthhack.impl.util.math.position.PositionUtil) Vec3i(net.minecraft.util.math.Vec3i) Category(me.earth.earthhack.api.module.util.Category) Map(java.util.Map) TrapTarget(me.earth.earthhack.impl.modules.combat.autotrap.modes.TrapTarget) Entity(net.minecraft.entity.Entity) TargetResult(me.earth.earthhack.impl.util.helpers.blocks.util.TargetResult) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) NumberSetting(me.earth.earthhack.api.setting.settings.NumberSetting) DamageUtil(me.earth.earthhack.impl.util.minecraft.DamageUtil) Collectors(java.util.stream.Collectors) List(java.util.List) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EnumSetting(me.earth.earthhack.api.setting.settings.EnumSetting) Comparator(java.util.Comparator) EntityUtil(me.earth.earthhack.impl.util.minecraft.entity.EntityUtil) ArrayList(java.util.ArrayList) BlockPos(net.minecraft.util.math.BlockPos) BlockUtil(me.earth.earthhack.impl.util.minecraft.blocks.BlockUtil)

Example 80 with Vec3i

use of net.minecraft.util.math.Vec3i in project 3arthh4ck by 3arthqu4ke.

the class HoleFinder method calcHole.

/**
 * Checks if {@link #pos} is the bottom left air block of a hole.
 */
public void calcHole() {
    Boolean safe = checkAirAndFloor(pos, true, false);
    if (safe == null) {
        return;
    }
    boolean _2x1 = false;
    boolean _2x2;
    // -> x a
    pos.setX(pos.getX() - 1);
    IBlockState state = mc.world.getBlockState(pos);
    if (state.getBlock() != Blocks.BEDROCK) {
        if (!HoleUtil.UNSAFE.contains(state.getBlock())) {
            return;
        }
        safe = false;
    }
    // x a
    // x <-
    pos.setX(pos.getX() + 1);
    pos.setZ(pos.getZ() - 1);
    state = mc.world.getBlockState(pos);
    if (state.getBlock() != Blocks.BEDROCK) {
        if (!HoleUtil.UNSAFE.contains(state.getBlock())) {
            return;
        }
        safe = false;
    }
    // x a x <-
    // x
    pos.setX(pos.getX() + 1);
    pos.setZ(pos.getZ() + 1);
    state = mc.world.getBlockState(pos);
    if (state.getBlock() != Blocks.BEDROCK) {
        if (state.getBlock() == Blocks.AIR) {
            safe = checkAirAndFloor(pos, safe, true);
            if (safe == null) {
                return;
            }
            _2x1 = true;
            // x a a
            // x x <-
            pos.setZ(pos.getZ() - 1);
            state = mc.world.getBlockState(pos);
            // noinspection DuplicatedCode
            if (!HoleUtil.NO_BLAST.contains(state.getBlock())) {
                return;
            }
            pos.setZ(pos.getZ() + 1);
            pos.setX(pos.getX() + 1);
            // x a a x <-
            // x x
            state = mc.world.getBlockState(pos);
            if (!HoleUtil.NO_BLAST.contains(state.getBlock())) {
                return;
            }
            // Go back here v
            // x a a x
            // x x
            pos.setX(pos.getX() - 1);
        } else if (!HoleUtil.UNSAFE.contains(state.getBlock())) {
            return;
        }
        safe = false;
    }
    // -> x
    // x a x
    // x
    pos.setX(pos.getX() - 1);
    pos.setZ(pos.getZ() + 1);
    state = mc.world.getBlockState(pos);
    if (state.getBlock() != Blocks.BEDROCK) {
        if (state.getBlock() == Blocks.AIR) {
            safe = checkAirAndFloor(pos, safe, true);
            if (safe == null) {
                return;
            }
            _2x2 = _2x1;
            // 
            // -> x a
            // x a x
            // x
            pos.setX(pos.getX() - 1);
            // noinspection DuplicatedCode
            state = mc.world.getBlockState(pos);
            if (!HoleUtil.NO_BLAST.contains(state.getBlock())) {
                return;
            }
            // -> x
            // x a
            // x a x
            // x
            pos.setZ(pos.getZ() + 1);
            pos.setX(pos.getX() + 1);
            state = mc.world.getBlockState(pos);
            if (!HoleUtil.NO_BLAST.contains(state.getBlock())) {
                return;
            }
            // x                   x
            // x a x <-    or      x a a <-
            // x a x               x a a x
            // x                   x x
            pos.setX(pos.getX() + 1);
            pos.setZ(pos.getZ() - 1);
            state = mc.world.getBlockState(pos);
            if (!HoleUtil.NO_BLAST.contains(state.getBlock())) {
                if (state.getBlock() == Blocks.AIR && _2x2) {
                    safe = checkAirAndFloor(pos, safe, true);
                    if (safe == null) {
                        return;
                    }
                    // x x <-
                    // x a a
                    // x a a x
                    // x x
                    pos.setZ(pos.getZ() + 1);
                    state = mc.world.getBlockState(pos);
                    if (!HoleUtil.NO_BLAST.contains(state.getBlock())) {
                        return;
                    }
                    // x x
                    // x a a x <-
                    // x a a x
                    // x x
                    pos.setZ(pos.getZ() - 1);
                    pos.setX(pos.getX() + 1);
                    state = mc.world.getBlockState(pos);
                    if (!HoleUtil.NO_BLAST.contains(state.getBlock())) {
                        return;
                    }
                    Hole hole = new HoleImpl(getChunk(), pos.getX() - 2, pos.getY(), pos.getZ() - 1, pos.getX(), pos.getZ() + 1, false, true, false);
                    this._2x2.add(hole);
                    for (Vec3i offset : OFFSETS_2x2) {
                        putHole(pos.add(offset), hole);
                    }
                }
                return;
            }
            if (_2x1) {
                return;
            }
            // x
            // x a x <- reminder, we are here
            // x a x
            // x
            Hole hole = new HoleImpl(getChunk(), pos.getX() - 1, pos.getY(), pos.getZ() - 1, pos.getX(), pos.getZ() + 1, true, false, false);
            this._2x1.add(hole);
            for (Vec3i offset : OFFSETS_2x1_z) {
                putHole(pos.add(offset), hole);
            }
            return;
        } else if (!HoleUtil.UNSAFE.contains(state.getBlock())) {
            return;
        }
        safe = false;
    }
    if (_2x1) {
        // x x <-
        // x a a x
        // x x
        pos.setX(pos.getX() + 1);
        state = mc.world.getBlockState(pos);
        if (HoleUtil.NO_BLAST.contains(state.getBlock())) {
            Hole hole = new HoleImpl(getChunk(), pos.getX() - 1, pos.getY(), pos.getZ() - 1, pos.getX() + 1, pos.getZ(), true, false, false);
            this._2x1.add(hole);
            for (Vec3i offset : OFFSETS_2x1_x) {
                putHole(pos.add(offset), hole);
            }
        }
        return;
    }
    // x <- reminder, we are here rn
    // x a x
    // x
    Hole hole = new HoleImpl(getChunk(), pos.getX(), pos.getY(), pos.getZ() - 1, pos.getX() + 1, pos.getZ(), false, false, safe);
    (safe ? _1x1_safe : _1x1_unsafe).add(hole);
    for (Vec3i offset : OFFSETS_1x1) {
        putHole(pos.add(offset), hole);
    }
}
Also used : Vec3i(net.minecraft.util.math.Vec3i) IBlockState(net.minecraft.block.state.IBlockState)

Aggregations

Vec3i (net.minecraft.util.math.Vec3i)161 BlockPos (net.minecraft.util.math.BlockPos)88 IBlockState (net.minecraft.block.state.IBlockState)29 Vec3d (net.minecraft.util.math.Vec3d)25 EnumFacing (net.minecraft.util.EnumFacing)18 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)15 Block (net.minecraft.block.Block)12 Entity (net.minecraft.entity.Entity)11 ArrayList (java.util.ArrayList)10 World (net.minecraft.world.World)10 TileEntity (net.minecraft.tileentity.TileEntity)8 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)7 HashSet (java.util.HashSet)6 Tessellator (net.minecraft.client.renderer.Tessellator)6 EntityEnderCrystal (net.minecraft.entity.item.EntityEnderCrystal)6 EntityPlayer (net.minecraft.entity.player.EntityPlayer)6 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)6 HashMap (java.util.HashMap)5 Random (java.util.Random)5 Direction (net.minecraft.util.math.Direction)5