net.minecraft.util.math.BlockPos Java Examples

The following examples show how to use net.minecraft.util.math.BlockPos. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BlockPipe.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) {
    IPipeTile<PipeType, NodeDataType> pipeTile = getPipeTileEntity(world, pos);
    if (pipeTile == null) {
        return ItemStack.EMPTY;
    }
    if (target instanceof CuboidRayTraceResult) {
        CuboidRayTraceResult result = (CuboidRayTraceResult) target;
        if (result.cuboid6.data instanceof CoverSideData) {
            EnumFacing coverSide = ((CoverSideData) result.cuboid6.data).side;
            CoverBehavior coverBehavior = pipeTile.getCoverableImplementation().getCoverAtSide(coverSide);
            return coverBehavior == null ? ItemStack.EMPTY : coverBehavior.getPickItem();
        }
    }
    return getDropItem(pipeTile);
}
 
Example #2
Source File: MessageFluidUpdate.java    From ExNihiloAdscensio with MIT License 6 votes vote down vote up
@Override
public IMessage onMessage(final MessageFluidUpdate msg, MessageContext ctx)
{
	Minecraft.getMinecraft().addScheduledTask(new Runnable() {
		@Override
		public void run()
		{
			TileEntity entity =  Minecraft.getMinecraft().player.world.getTileEntity(new BlockPos(msg.x, msg.y, msg.z));
			if (entity instanceof TileBarrel)
			{
				TileBarrel te = (TileBarrel) entity;
				Fluid fluid = FluidRegistry.getFluid(msg.fluidName);
				FluidStack f = fluid == null ? null : new FluidStack(fluid, msg.fillAmount);
				te.getTank().setFluid(f);
			}
		}
	});
	return null;
}
 
Example #3
Source File: PathFinder.java    From Wurst7 with GNU General Public License v3.0 6 votes vote down vote up
private boolean canMoveSidewaysInMidairAt(BlockPos pos)
{
	// check feet
	Block blockFeet = BlockUtils.getBlock(pos);
	if(BlockUtils.getState(pos).getMaterial().isLiquid()
		|| blockFeet instanceof LadderBlock
		|| blockFeet instanceof VineBlock
		|| blockFeet instanceof CobwebBlock)
		return true;
	
	// check head
	Block blockHead = BlockUtils.getBlock(pos.up());
	if(BlockUtils.getState(pos.up()).getMaterial().isLiquid()
		|| blockHead instanceof CobwebBlock)
		return true;
	
	return false;
}
 
Example #4
Source File: ItemNullifier.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos,
        EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
    ItemStack stack = player.getHeldItem(hand);
    ItemStack useStack = this.getItemForUse(stack, player);

    if (useStack.isEmpty() == false && world.isBlockModifiable(player, pos.offset(facing)))
    {
        EntityUtils.setHeldItemWithoutEquipSound(player, hand, useStack);
        EnumActionResult result = useStack.onItemUse(player, world, pos, hand, facing, hitX, hitY, hitZ);

        if (world.isRemote == false && player.capabilities.isCreativeMode == false && useStack.isEmpty() == false)
        {
            tryInsertItemsToNullifier(useStack, stack, player);
        }

        EntityUtils.setHeldItemWithoutEquipSound(player, hand, stack);

        return result;
    }

    return super.onItemUse(player, world, pos, hand, facing, hitX, hitY, hitZ);
}
 
Example #5
Source File: BlockSoyMilk.java    From TofuCraftReload with MIT License 6 votes vote down vote up
@Override
@SideOnly(Side.CLIENT)
public void randomDisplayTick(IBlockState state, World world, BlockPos pos, Random rand) {
    super.randomDisplayTick(state, world, pos, rand);
    if (world.getBlockState(pos.up()).getMaterial() != Material.WATER && rand.nextInt(3) == 0)
    {
        if (this.getHeatStrength(world, pos) > 0)
        {
            float steamX = pos.getX() + 0.5F;
            float steamY = pos.getY() + 0.9F;
            float steamZ = pos.getZ() + 0.5F;
            float steamRandX = rand.nextFloat() * 0.6F - 0.3F;
            float steamRandZ = rand.nextFloat() * 0.6F - 0.3F;
            double gRand1 = rand.nextGaussian() * 0.01D;
            double gRand2 = rand.nextGaussian() * 0.01D;
            double gRand3 = rand.nextGaussian() * 0.01D;
            world.spawnParticle(EnumParticleTypes.EXPLOSION_NORMAL, (steamX + steamRandX), steamY, (steamZ + steamRandZ), gRand1, gRand2, gRand3);
        }
    }
}
 
Example #6
Source File: BlockDrawbridge.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand,
        EnumFacing side, float hitX, float hitY, float hitZ)
{
    TileEntityDrawbridge te = getTileEntitySafely(world, pos, TileEntityDrawbridge.class);

    if (te != null && this.isTileEntityValid(te))
    {
        if (te.onRightClickBlock(player, hand, side, hitX, hitY, hitZ))
        {
            return true;
        }
        else
        {
            if (world.isRemote == false)
            {
                player.openGui(EnderUtilities.instance, ReferenceGuiIds.GUI_ID_TILE_ENTITY_GENERIC, world, pos.getX(), pos.getY(), pos.getZ());
            }

            return true;
        }
    }

    return false;
}
 
Example #7
Source File: PositionUtils.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void getPositionsInBoxSpiralingOutwards(List<BlockPos> positions, int vertR, int horizR, int yLevel, int centerX, int centerZ)
{
    getPositionsOnPlaneSpiralingOutwards(positions, horizR, yLevel, centerX, centerZ);

    for (int y = 1; y <= vertR; y++)
    {
        getPositionsOnPlaneSpiralingOutwards(positions, horizR, yLevel + y, centerX, centerZ);
        getPositionsOnPlaneSpiralingOutwards(positions, horizR, yLevel - y, centerX, centerZ);
    }
}
 
Example #8
Source File: BiomeTofuHills.java    From TofuCraftReload with MIT License 5 votes vote down vote up
@Override
    public void decorate(World worldIn, Random randomIn, BlockPos pos)
    {
        super.decorate(worldIn, randomIn, pos);
        
        BlockPos.MutableBlockPos mutable = new BlockPos.MutableBlockPos();
        for (int k = 0; k < 1; ++k)
        {
            int x = pos.getX() + randomIn.nextInt(16) + 8;
            int z = pos.getZ() + randomIn.nextInt(16) + 8;

            int y = worldIn.getHeight(x, z) - 1;
            
            mutable.setPos(x, y, z);
//            TOO LAG
//            if (y > 80 && worldIn.getBlockState(mutable).getBlock() == BlockLoader.tofuTerrain)
//            {
//                if (worldIn.getBlockState(mutable.east()).getBlock() == BlockLoader.tofuTerrain
//                        && worldIn.getBlockState(mutable.south()).getBlock() == BlockLoader.tofuTerrain
//                        && worldIn.getBlockState(mutable.west()).getBlock() == BlockLoader.tofuTerrain
//                        && worldIn.getBlockState(mutable.north()).getBlock() == BlockLoader.tofuTerrain)
//                {
//                    int h = randomIn.nextInt(3) + 3;
//                    for (int i = 0; i < h; i++)
//                    {
//                        worldIn.setBlockState(new BlockPos(mutable.setPos(x, y + i, z)), BlockLoader.SOYMILK.getDefaultState(), 2);
//                    }
//                }
//            }
        }

    }
 
Example #9
Source File: GTBlockQuantumChest.java    From GT-Classic with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public List<ItemStack> getWrenchDrops(World world, BlockPos pos, IBlockState state, TileEntity te,
		EntityPlayer player, int fortune) {
	List<ItemStack> items = new ArrayList<>();
	if (te instanceof IGTItemContainerTile) {
		items.addAll(((IGTItemContainerTile) te).getDrops());
	}
	return items;
}
 
Example #10
Source File: ToolUtils.java    From litematica with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void setToolModeBlockState(ToolMode mode, boolean primary, Minecraft mc)
{
    IBlockState state = Blocks.AIR.getDefaultState();
    double reach = mc.playerController.getBlockReachDistance();
    Entity entity = fi.dy.masa.malilib.util.EntityUtils.getCameraEntity();
    RayTraceWrapper wrapper = RayTraceUtils.getGenericTrace(mc.world, entity, reach, true);

    if (wrapper != null)
    {
        RayTraceResult trace = wrapper.getRayTraceResult();

        if (trace != null)
        {
            BlockPos pos = trace.getBlockPos();

            if (wrapper.getHitType() == HitType.SCHEMATIC_BLOCK)
            {
                state = SchematicWorldHandler.getSchematicWorld().getBlockState(pos);
            }
            else if (wrapper.getHitType() == HitType.VANILLA)
            {
                state = mc.world.getBlockState(pos).getActualState(mc.world, pos);
            }
        }
    }

    if (primary)
    {
        mode.setPrimaryBlock(state);
    }
    else
    {
        mode.setSecondaryBlock(state);
    }
}
 
Example #11
Source File: TreeHandler.java    From BetterChests with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean canHandlePlant(Collection<ItemStack> items, World world, BlockPos pos, IBlockState state) {
	if (!WorldUtil.isBlockAir(state)) {
		return false;
	}
	Optional<ItemStack> sapling = items.stream().filter(this::isAcceptedSapling).filter(stack -> world.mayPlace(Block.getBlockFromItem(stack.getItem()), pos, true, EnumFacing.UP, null)).findFirst();
	return sapling.isPresent();
}
 
Example #12
Source File: Nuker.java    From ForgeHax with MIT License 5 votes vote down vote up
private void updateBlockBreaking(BlockPos target) {
  if (target == null && currentTarget != null) {
    resetBlockBreaking();
  } else if (target != null && currentTarget == null) {
    getPlayerController().resetBlockRemoving();
    currentTarget = target;
  }
}
 
Example #13
Source File: PathCmd.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
private BlockPos argsToPos(String... args) throws CmdException
{
	switch(args.length)
	{
		default:
		throw new CmdSyntaxError("Invalid coordinates.");
		
		case 1:
		return argsToEntityPos(args[0]);
		
		case 3:
		return argsToXyzPos(args);
	}
}
 
Example #14
Source File: EasyPlaceUtils.java    From litematica with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Nullable
private static HitPosition getAdjacentClickPositionForSlab(BlockPos targetBlockPos, IBlockState stateSchematic, boolean isTop, World worldClient)
{
    EnumFacing clickSide = isTop ? EnumFacing.DOWN : EnumFacing.UP;
    EnumFacing clickSideOpposite = clickSide.getOpposite();
    BlockPos posSide = targetBlockPos.offset(clickSideOpposite);

    // Can click on the existing block above or below
    if (canClickOnAdjacentBlockToPlaceSingleSlabAt(targetBlockPos, stateSchematic, clickSideOpposite, worldClient))
    {
        return HitPosition.of(posSide, getHitPositionForSidePosition(posSide, clickSideOpposite), clickSide);
    }
    // Try the sides
    else
    {
        for (EnumFacing side : PositionUtils.HORIZONTAL_DIRECTIONS)
        {
            if (canClickOnAdjacentBlockToPlaceSingleSlabAt(targetBlockPos, stateSchematic, side, worldClient))
            {
                posSide = targetBlockPos.offset(side);
                Vec3d hitPos = getHitPositionForSidePosition(posSide, side);
                double y = isTop ? 0.9 : 0.1;
                return HitPosition.of(posSide, new Vec3d(hitPos.x, posSide.getY() + y, hitPos.z), side.getOpposite());
            }
        }
    }

    return null;
}
 
Example #15
Source File: QuestEnemyEncampment.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
private BlockPos getSpawnPosition(QuestData data) {
	NBTTagCompound c = getCustomNbtTag(data);
	if (c.getInteger("locationFound") != 1) {
		return null;
	}
	return new BlockPos(c.getInteger("pos_x"), c.getInteger("pos_y"), c.getInteger("pos_z"));
}
 
Example #16
Source File: WitchWaterBubbleColumnBlock.java    From the-hallow with MIT License 5 votes vote down vote up
private static boolean calculateDrag(BlockView view, BlockPos pos) {
	BlockState state = view.getBlockState(pos);
	Block block = state.getBlock();
	if (block == HallowedBlocks.WITCH_WATER_BUBBLE_COLUMN) {
		return state.get(DRAG);
	} else {
		return block != HallowedBlocks.COARSE_TAINTED_SAND;
	}
}
 
Example #17
Source File: BlockRotationAxle.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
    super.breakBlock(worldIn, pos, state);
    TileEntity tile = worldIn.getTileEntity(pos);
    if (tile != null) {
        tile.invalidate();
    }
}
 
Example #18
Source File: WorldUtils.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
public static boolean doesBoxTouchBlock(Box box, Block block) {
	for (int x = (int) Math.floor(box.x1); x < Math.ceil(box.x2); x++) {
		for (int y = (int) Math.floor(box.y1); y < Math.ceil(box.y2); y++) {
			for (int z = (int) Math.floor(box.z1); z < Math.ceil(box.z2); z++) {
				if (MinecraftClient.getInstance().world.getBlockState(new BlockPos(x, y, z)).getBlock() == block) {
					return true;
				}
			}
		}
	}
	return false;
}
 
Example #19
Source File: ScannerBehavior.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Pair<String, Integer> checkCanUseScanner(ItemStack itemStack, EntityPlayer player, boolean simulate) {
    Pair<BlockPos, IBlockState> hitBlock = getHitBlock(player);
    if (hitBlock == null) {
        return Pair.of("behavior.scanner.analyzing_failed", 0);
    }
    IBlockState state = hitBlock.getRight();
    long amount = ((IScannableBlock) state.getBlock()).getScanDuration(player.world, hitBlock.getLeft(), state, player);
    if (!dischargeItem(itemStack, amount, simulate)) {
        return Pair.of("metaitem.scanner.not_enough_energy", 0);
    }
    int maxHitUse = ((IScannableBlock) state.getBlock()).getScanDuration(player.world, hitBlock.getLeft(), state, player);
    return Pair.of(null, maxHitUse);
}
 
Example #20
Source File: RedstoneWireBlockMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Redirect(method = "neighborUpdate", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/RedstoneWireBlock;update(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Lnet/minecraft/block/BlockState;"))
private BlockState redirectNeighborUpdateUpdate(
        RedstoneWireBlock self,
        World world_1,
        BlockPos blockPos_1,
        BlockState blockState_1,
        BlockState blockState_2,
        World world_2,
        BlockPos blockPos_2,
        Block block_1,
        BlockPos blockPos_3,
        boolean boolean_1) {
    return fastUpdate(world_1, blockPos_1, blockState_1, blockPos_3);
}
 
Example #21
Source File: TileRocketLoader.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
protected boolean getStrongPowerForSides(World world, BlockPos pos) {
	for(int i = 0; i < 6; i++) {
		if(sideSelectorModule.getStateForSide(i) == ALLOW_REDSTONEOUT && world.getRedstonePower(pos.offset(EnumFacing.VALUES[i]), EnumFacing.VALUES[i]) > 0)
			return true;
	}
	return false;
}
 
Example #22
Source File: GTTileBedrockMiner.java    From GT-Classic with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
@SideOnly(Side.CLIENT)
public void randomTickDisplay(IBlockState stateIn, World worldIn, BlockPos pos, Random rand) {
	if (this.isActive) {
		for (int i = 0; i < 3; ++i) {
			double d0 = (double) pos.getX() + rand.nextDouble();
			double d1 = (double) pos.getY() + .5D + rand.nextDouble() * 0.5D + 0.5D;
			double d2 = (double) pos.getZ() + rand.nextDouble();
			worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0, d1, d2, 0.0D, 0.0D, 0.0D);
		}
	}
}
 
Example #23
Source File: BlockCrusherBlade.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn) {
    if (state.getValue(ACTIVE)) {
        entityIn.attackEntityFrom(DamageSources.getCrusherDamage(), 5.0f);
        entityIn.motionY *= 0.04;
    }
}
 
Example #24
Source File: BlockTeleportRail.java    From Signals with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ){
    if(playerIn.isSneaking()) {
        if(!worldIn.isRemote) {
            worldIn.setBlockState(pos, state.cycleProperty(FORWARD));
            playerIn.sendMessage(new TextComponentTranslation("signals.message.teleport_rail_toggled_direction"));
        }
        return true;
    } else {
        return false;
    }
}
 
Example #25
Source File: SurgeryRemovePacket.java    From Cyberware with MIT License 5 votes vote down vote up
public SurgeryRemovePacket(BlockPos pos, int dimensionId, int slotNumber, boolean isNull)
{
	this.pos = pos;
	this.dimensionId = dimensionId;
	this.slotNumber = slotNumber;
	this.isNull = isNull;
}
 
Example #26
Source File: Shredder.java    From EmergingTechnology with MIT License 5 votes vote down vote up
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
        EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {

    if (worldIn.isRemote) {
        return true;
    }

    playerIn.openGui(EmergingTechnology.instance, Reference.GUI_SHREDDER, worldIn, pos.getX(), pos.getY(),
            pos.getZ());

    return true;
}
 
Example #27
Source File: EasyPlaceUtils.java    From litematica with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static boolean isPositionWithinRangeOfSchematicRegions(BlockPos pos, int range)
{
    SchematicPlacementManager manager = DataManager.getSchematicPlacementManager();
    final int minCX = (pos.getX() - range) >> 4;
    final int minCY = (pos.getY() - range) >> 4;
    final int minCZ = (pos.getZ() - range) >> 4;
    final int maxCX = (pos.getX() + range) >> 4;
    final int maxCY = (pos.getY() + range) >> 4;
    final int maxCZ = (pos.getZ() + range) >> 4;
    final int x = pos.getX();
    final int y = pos.getY();
    final int z = pos.getZ();

    for (int cy = minCY; cy <= maxCY; ++cy)
    {
        for (int cz = minCZ; cz <= maxCZ; ++cz)
        {
            for (int cx = minCX; cx <= maxCX; ++cx)
            {
                List<IntBoundingBox> boxes = manager.getTouchedBoxesInSubChunk(new SubChunkPos(cx, cy, cz));

                for (int i = 0; i < boxes.size(); ++i)
                {
                    IntBoundingBox box = boxes.get(i);

                    if (x >= box.minX - range && x <= box.maxX + range &&
                        y >= box.minY - range && y <= box.maxY + range &&
                        z >= box.minZ - range && z <= box.maxZ + range)
                    {
                        return true;
                    }
                }
            }
        }
    }

    return false;
}
 
Example #28
Source File: Canvas.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void cuboid(BlockPos pos, int width, int height, int depth) {
	moveTo(pos);
	for(x = pos.getX(); x < width; x++){
		for(y = pos.getY(); y < height; y++){
			for(z = pos.getZ(); z < depth; z++){
				
				fillBlock();
			}
		}
	}
}
 
Example #29
Source File: WorldMana.java    From YouTubeModdingTutorial with MIT License 5 votes vote down vote up
public float extractMana(World world, BlockPos pos) {
    float manaInfluence = getManaInfluence(world, pos);
    if (manaInfluence <= 0) {
        return 0;
    }
    ChunkPos chunkPos = new ChunkPos(pos);
    float extracted = 0.0f;
    for (int dx = -4 ; dx <= 4 ; dx++) {
        for (int dz = -4 ; dz <= 4 ; dz++) {
            ChunkPos cp = new ChunkPos(chunkPos.x + dx, chunkPos.z + dz);
            ManaSphere sphere = getOrCreateSphereAt(world, cp);
            if (sphere.getRadius() > 0) {
                double distanceSq = pos.distanceSq(sphere.getCenter());
                if (distanceSq < sphere.getRadius() * sphere.getRadius()) {
                    double distance = Math.sqrt(distanceSq);
                    double influence = (sphere.getRadius() - distance) / sphere.getRadius();
                    float currentMana = sphere.getCurrentMana();
                    if (influence > currentMana) {
                        influence = currentMana;
                    }
                    currentMana -= influence;
                    extracted += influence;
                    sphere.setCurrentMana(currentMana);
                    markDirty();
                }
            }
        }
    }
    return extracted;
}
 
Example #30
Source File: BlockSaltFurnace.java    From TofuCraftReload with MIT License 5 votes vote down vote up
@Override
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
    worldIn.setBlockState(pos, state.withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2);

    if (stack.hasDisplayName())
    {
        TileEntity tileentity = worldIn.getTileEntity(pos);
        if (tileentity instanceof TileEntitySaltFurnace)
        {
            ((TileEntitySaltFurnace)tileentity).setCustomInventoryName(stack.getDisplayName());

        }
    }
}