Search in sources :

Example 71 with EnumFacing

use of net.minecraft.util.EnumFacing in project BetterWithAddons by DaedalusGame.

the class BlockWeight method measureBlock.

public int measureBlock(World world, BlockPos pos, IBlockState state) {
    BlockPos checkpos = pos.up();
    IBlockState checkstate = world.getBlockState(checkpos);
    TileEntity te = world.getTileEntity(checkpos);
    boolean isFull = true;
    boolean isEmpty = true;
    int delay = 20;
    if (te != null) {
        boolean foundAnyMeasurable = false;
        for (EnumFacing facing : EnumFacing.VALUES) {
            if (te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing)) {
                IItemHandler inventory = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing);
                if (!InventoryUtil.isEmpty(inventory))
                    isEmpty = false;
                if (!InventoryUtil.isFull(inventory))
                    isFull = false;
                foundAnyMeasurable = true;
            }
            if (te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing)) {
                IFluidHandler tank = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing);
                FluidStack fluid = tank.drain(Integer.MAX_VALUE, false);
                if (fluid != null && tank.fill(fluid, false) > 0)
                    isFull = false;
                if (fluid != null && fluid.amount != 0)
                    isEmpty = false;
                foundAnyMeasurable = true;
            }
        }
        if (foundAnyMeasurable)
            delay = 1;
        else
            isFull = false;
    } else if (SPECIAL_BEHAVIOR.containsKey(checkstate.getBlock())) {
        ISpecialMeasuringBehavior behavior = SPECIAL_BEHAVIOR.get(checkstate.getBlock());
        isEmpty = behavior.isEmpty(world, checkpos, checkstate);
        isFull = behavior.isFull(world, checkpos, checkstate);
        delay = behavior.getDelay(world, checkpos, checkstate);
    } else {
        isFull = false;
    }
    boolean active = decideActivity(isEmpty, isFull);
    if (active != state.getValue(ACTIVE)) {
        world.setBlockState(pos, state.withProperty(ACTIVE, active));
        float f = active ? 0.6F : 0.5F;
        world.playSound(null, pos, SoundEvents.BLOCK_LEVER_CLICK, SoundCategory.BLOCKS, 1.0F, f);
    }
    return delay;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) IItemHandler(net.minecraftforge.items.IItemHandler) FluidStack(net.minecraftforge.fluids.FluidStack) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) ISpecialMeasuringBehavior(betterwithaddons.util.ISpecialMeasuringBehavior)

Example 72 with EnumFacing

use of net.minecraft.util.EnumFacing in project BetterWithAddons by DaedalusGame.

the class BlockLoom method spinUpAllAttached.

public void spinUpAllAttached(World world, BlockPos pos, IBlockState state) {
    if (world.isRemote)
        return;
    for (EnumFacing facing : EnumFacing.VALUES) {
        if (facing == state.getValue(FACING))
            continue;
        BlockPos spinPos = pos.offset(facing);
        IBlockState spinState = world.getBlockState(spinPos);
        if (spinState.getBlock() instanceof ISpindle)
            ((ISpindle) spinState.getBlock()).spinUp(world, spinPos, spinState, facing);
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos)

Example 73 with EnumFacing

use of net.minecraft.util.EnumFacing in project BetterWithAddons by DaedalusGame.

the class BlockRopeSideways method isSupported.

private boolean isSupported(World world, BlockPos pos, IBlockState state, Axis axis) {
    EnumRopeShape shape = state.getValue(SHAPE);
    EnumFacing forward = EnumFacing.getFacingFromAxis(AxisDirection.POSITIVE, axis);
    EnumFacing back = EnumFacing.getFacingFromAxis(AxisDirection.NEGATIVE, axis);
    IBlockState state1 = world.getBlockState(pos.offset(forward));
    IBlockState state2 = world.getBlockState(pos.offset(back));
    return (canFastenBlock(state1.getBlock()) || (state1.getBlock() == this && state1.getValue(SHAPE).has(shape))) && (canFastenBlock(state2.getBlock()) || (state2.getBlock() == this && state2.getValue(SHAPE).has(shape)));
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing)

Example 74 with EnumFacing

use of net.minecraft.util.EnumFacing in project BetterWithAddons by DaedalusGame.

the class AssortedHandler method attachRopeEvent.

@SubscribeEvent
public void attachRopeEvent(PlayerInteractEvent.RightClickBlock event) {
    World world = event.getWorld();
    BlockPos pos = event.getPos();
    IBlockState state = world.getBlockState(pos);
    ItemStack stack = event.getItemStack();
    EnumFacing facing = event.getFace();
    EntityPlayer player = event.getEntityPlayer();
    if (stack.getItem() == Item.getItemFromBlock(BWMBlocks.ROPE) && state.getBlock() instanceof BlockFence && state.getBlock() != ModBlocks.ropePost) {
        ModBlocks.ropePost.placeFencePost(world, pos);
        state = world.getBlockState(pos);
        int consumedRope = 1;
        if (BlockRopeSideways.canFastenBlock(state.getBlock())) {
            consumedRope += attachRope(world, pos, facing, Math.min(stack.getCount() - 1, ropeLimit));
        }
        if (!player.isCreative())
            stack.shrink(consumedRope);
        event.setCancellationResult(EnumActionResult.SUCCESS);
        event.setCanceled(true);
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) BlockFence(net.minecraft.block.BlockFence) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 75 with EnumFacing

use of net.minecraft.util.EnumFacing in project BetterWithAddons by DaedalusGame.

the class TileEntityInvertedGearbox method onChanged.

public void onChanged() {
    if (this.getBlockWorld().getTotalWorldTime() % 20L != 0L)
        return;
    EnumFacing gearfacing = getFacing();
    int findPower = 0;
    for (EnumFacing facing : EnumFacing.values()) {
        if (facing == gearfacing || facing.getOpposite() == gearfacing)
            continue;
        int power = getMechanicalInput(facing);
        if (power > findPower) {
            findPower = power;
        }
    }
    if (overpowerChance() && findPower > getMaximumInput(EnumFacing.UP)) {
        overpower();
        return;
    }
    if (findPower > 0) {
        setPower(0);
        markDirty();
        return;
    }
    super.onChanged();
}
Also used : EnumFacing(net.minecraft.util.EnumFacing)

Aggregations

EnumFacing (net.minecraft.util.EnumFacing)1673 BlockPos (net.minecraft.util.math.BlockPos)491 IBlockState (net.minecraft.block.state.IBlockState)403 TileEntity (net.minecraft.tileentity.TileEntity)392 ItemStack (net.minecraft.item.ItemStack)192 Block (net.minecraft.block.Block)158 ArrayList (java.util.ArrayList)121 World (net.minecraft.world.World)114 Vec3d (net.minecraft.util.math.Vec3d)104 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)98 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)88 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)73 EntityPlayer (net.minecraft.entity.player.EntityPlayer)65 FluidStack (net.minecraftforge.fluids.FluidStack)65 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)63 Nullable (javax.annotation.Nullable)51 List (java.util.List)48 Nonnull (javax.annotation.Nonnull)47 HashSet (java.util.HashSet)43 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)43