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 Project: GregTech   Author: GregTechCE   File: BlockPipe.java    License: 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 Project: enderutilities   Author: maruohon   File: BlockDrawbridge.java    License: 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 #3
Source Project: Wurst7   Author: Wurst-Imperium   File: PathFinder.java    License: 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 Project: enderutilities   Author: maruohon   File: ItemNullifier.java    License: 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 Project: ExNihiloAdscensio   Author: MikeLydeamore   File: MessageFluidUpdate.java    License: 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 #6
Source Project: TofuCraftReload   Author: 0999312   File: BlockSoyMilk.java    License: 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 #7
Source Project: Wurst7   Author: Wurst-Imperium   File: PathCmd.java    License: 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 #8
Source Project: litematica   Author: maruohon   File: EasyPlaceUtils.java    License: 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 #9
Source Project: enderutilities   Author: maruohon   File: PositionUtils.java    License: 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 #10
Source Project: litematica   Author: maruohon   File: ToolUtils.java    License: 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 Project: Kettle   Author: KettleFoundation   File: CraftNoteBlock.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean play(byte instrument, byte note) {
    Block block = getBlock();

    if (block.getType() == Material.NOTE_BLOCK) {
        CraftWorld world = (CraftWorld) this.getWorld();
        world.getHandle().addBlockEvent(new BlockPos(getX(), getY(), getZ()), CraftMagicNumbers.getBlock(block), instrument, note);
        return true;
    } else {
        return false;
    }
}
 
Example #12
Source Project: enderutilities   Author: maruohon   File: ItemBuildersWand.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
public void onLeftClickBlock(EntityPlayer player, World world, ItemStack stack, BlockPos pos, int dimension, EnumFacing side)
{
    if (world.isRemote)
    {
        return;
    }

    // Hack to work around the fact that when the NBT changes, the left click event will fire again the next tick,
    // so it would easily result in the state toggling multiple times per left click
    Long last = this.lastLeftClick.get(player.getUniqueID());

    if (last == null || (world.getTotalWorldTime() - last) >= 4)
    {
        Mode mode = Mode.getMode(stack);

        // Sneak + left click: Set the selected block type (in the appropriate modes)
        if (player.isSneaking() && (mode.isAreaMode() == false ||
                (mode == Mode.REPLACE_3D && WandOption.BIND_MODE.isEnabled(stack, mode))))
        {
            this.setSelectedFixedBlockType(stack, player, world, pos, false);
        }
        else if (mode == Mode.REPLACE)
        {
            if (WandOption.REPLACE_MODE_IS_AREA.isEnabled(stack, mode))
            {
                this.setPosition(new BlockPosEU(pos, world.provider.getDimension(), side), POS_START, stack, player);
            }
        }
        else
        {
            BlockPosEU posEU = new BlockPosEU(player.isSneaking() ? pos : pos.offset(side), world.provider.getDimension(), side);
            this.setPosition(posEU, POS_START, stack, player);
        }
    }

    this.lastLeftClick.put(player.getUniqueID(), world.getTotalWorldTime());
}
 
Example #13
Source Project: the-hallow   Author: fabric-community   File: WitchWaterBubbleColumnBlock.java    License: 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 #14
Source Project: bleachhack-1.14   Author: BleachDrinker420   File: WorldUtils.java    License: 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 #15
Source Project: AdvancedRocketry   Author: zmaster587   File: TileRocketLoader.java    License: 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 #16
Source Project: EmergingTechnology   Author: MoonManModding   File: Shredder.java    License: 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 #17
Source Project: ToroQuest   Author: ToroCraft   File: Canvas.java    License: 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 #18
Source Project: YouTubeModdingTutorial   Author: McJty   File: WorldMana.java    License: 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 #19
Source Project: TofuCraftReload   Author: 0999312   File: BlockSaltFurnace.java    License: 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());

        }
    }
}
 
Example #20
Source Project: GregTech   Author: GregTechCE   File: ScannerBehavior.java    License: 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 #21
Source Project: litematica   Author: maruohon   File: EasyPlaceUtils.java    License: 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 #22
Source Project: Cyberware   Author: Flaxbeard   File: SurgeryRemovePacket.java    License: 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 #23
Source Project: Signals   Author: MineMaarten   File: BlockTeleportRail.java    License: 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 #24
Source Project: GregTech   Author: GregTechCE   File: BlockCrusherBlade.java    License: 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 #25
Source Project: GT-Classic   Author: e99999   File: GTTileBedrockMiner.java    License: 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 #26
Source Project: fabric-carpet   Author: gnembon   File: RedstoneWireBlockMixin.java    License: 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 #27
Source Project: GT-Classic   Author: e99999   File: GTBlockQuantumChest.java    License: 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 #28
Source Project: ToroQuest   Author: ToroCraft   File: QuestEnemyEncampment.java    License: 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 #29
Source Project: TFC2   Author: Deadrik   File: BlockVegDesert.java    License: GNU General Public License v3.0 5 votes vote down vote up
/*******************************************************************************
 * 3. Blockstate 
 *******************************************************************************/

@Override
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos)
{
	return state.withProperty(IS_ON_STONE, Core.isStone(world.getBlockState(pos.down())));
}
 
Example #30
Source Project: Valkyrien-Skies   Author: ValkyrienSkies   File: BlockRotationAxle.java    License: 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();
    }
}