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);
}
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();
}
}
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;
}
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());
}
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);
}
}
Aggregations