Search in sources :

Example 61 with ActionResult

use of net.minecraft.util.ActionResult in project BuildCraft by BuildCraft.

the class PipeFlowFluids method tryExtractFluidInternal.

private ActionResult<FluidStack> tryExtractFluidInternal(int millibuckets, EnumFacing from, FluidExtractor extractor, boolean simulate) {
    if (from == null || millibuckets <= 0) {
        return FAILED_EXTRACT;
    }
    IFluidHandler fluidHandler = pipe.getHolder().getCapabilityFromPipe(from, CapUtil.CAP_FLUIDS);
    if (fluidHandler == null) {
        // FIXME: WRONG PLACE!!!
        return PASSED_EXTRACT;
    }
    Section section = sections.get(EnumPipePart.fromFacing(from));
    Section middle = sections.get(EnumPipePart.CENTER);
    millibuckets = Math.min(millibuckets, capacity * 2 - section.amount - middle.amount);
    if (millibuckets <= 0) {
        return FAILED_EXTRACT;
    }
    FluidStack toAdd = extractor.extract(millibuckets, currentFluid, fluidHandler);
    if (toAdd == null || toAdd.amount <= 0) {
        return FAILED_EXTRACT;
    }
    millibuckets = toAdd.amount;
    if (currentFluid == null && !simulate) {
        setFluid(toAdd);
    }
    int reallyFilled = section.fillInternal(millibuckets, !simulate);
    int leftOver = millibuckets - reallyFilled;
    reallyFilled += middle.fillInternal(leftOver, !simulate);
    if (!simulate) {
        section.ticksInDirection = COOLDOWN_INPUT;
    }
    if (reallyFilled != millibuckets) {
        BCLog.logger.warn(// 
        "[tryExtractFluidAdv] Filled " + reallyFilled + " != extracted " + millibuckets + " (handler = " + fluidHandler.getClass() + ") @" + pipe.getHolder().getPipePos());
    }
    return new ActionResult<>(EnumActionResult.SUCCESS, toAdd);
}
Also used : ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) FluidStack(net.minecraftforge.fluids.FluidStack) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler)

Example 62 with ActionResult

use of net.minecraft.util.ActionResult in project BuildCraft by BuildCraft.

the class ItemSchematicSingle method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
    ItemStack stack = StackUtil.asNonNull(player.getHeldItem(hand));
    if (world.isRemote) {
        return new ActionResult<>(EnumActionResult.PASS, stack);
    }
    if (player.isSneaking()) {
        NBTTagCompound itemData = NBTUtilBC.getItemData(stack);
        itemData.removeTag(NBT_KEY);
        if (itemData.hasNoTags()) {
            stack.setTagCompound(null);
        }
        stack.setItemDamage(DAMAGE_CLEAN);
        return new ActionResult<>(EnumActionResult.SUCCESS, stack);
    }
    return new ActionResult<>(EnumActionResult.PASS, stack);
}
Also used : ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack)

Example 63 with ActionResult

use of net.minecraft.util.ActionResult in project BuildCraft by BuildCraft.

the class ItemMapLocation method clearMarkerData.

private static ActionResult<ItemStack> clearMarkerData(@Nonnull ItemStack stack) {
    if (MapLocationType.getFromStack(stack) == MapLocationType.CLEAN) {
        return new ActionResult<>(EnumActionResult.PASS, stack);
    }
    NBTTagCompound nbt = NBTUtilBC.getItemData(stack);
    for (String key : STORAGE_TAGS) {
        nbt.removeTag(key);
    }
    if (nbt.hasNoTags()) {
        stack.setTagCompound(null);
    }
    MapLocationType.CLEAN.setToStack(stack);
    return new ActionResult<>(EnumActionResult.SUCCESS, stack);
}
Also used : ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 64 with ActionResult

use of net.minecraft.util.ActionResult in project Adventurers-Toolbox by the-realest-stu.

the class ItemRock method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
    ItemStack itemstack = playerIn.getHeldItem(handIn);
    playerIn.setActiveHand(handIn);
    return new ActionResult(EnumActionResult.SUCCESS, itemstack);
}
Also used : ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) ItemStack(net.minecraft.item.ItemStack)

Example 65 with ActionResult

use of net.minecraft.util.ActionResult in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class ItemShipTracker method onItemRightClick.

public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer player, EnumHand hand) {
    if (!worldIn.isRemote) {
        final ItemStack heldItemStack = player.getHeldItem(hand);
        final NBTTagCompound stackTagCompound;
        if (heldItemStack.hasTagCompound()) {
            stackTagCompound = heldItemStack.stackTagCompound;
        } else {
            stackTagCompound = new NBTTagCompound();
        }
        if (stackTagCompound.hasKey(NBT_DATA_KEY)) {
            // Tell the player the ship location
            final UUID shipUUID = UUID.fromString(stackTagCompound.getString(NBT_DATA_KEY));
            final Optional<ShipData> shipDataOptional = ValkyrienUtils.getQueryableData(worldIn).getShip(shipUUID);
            if (shipDataOptional.isPresent()) {
                final ShipData shipData = shipDataOptional.get();
                final ShipTransform currentTransform = shipData.getShipTransform();
                final Vector3d shipPosition = new Vector3d(currentTransform.getPosX(), currentTransform.getPosY(), currentTransform.getPosZ());
                // Only print up to 2 digits after the decimal place
                final String shipPositionString = shipPosition.toString(new DecimalFormat("############.##"));
                player.sendMessage(new TextComponentString(String.format("The ship %s is currently at %s.", shipData.getName(), shipPositionString)));
            } else {
                player.sendMessage(new TextComponentString(String.format("No ship with UUID %s found! Maybe it was destroyed.", shipUUID.toString())));
            }
        } else {
            player.sendMessage(new TextComponentString("Not tracking any ships. Right click on a ship to track it."));
        }
    }
    return new ActionResult<>(EnumActionResult.PASS, player.getHeldItem(hand));
}
Also used : ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) ShipTransform(org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform) Vector3d(org.joml.Vector3d) ShipData(org.valkyrienskies.mod.common.ships.ShipData) DecimalFormat(java.text.DecimalFormat) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) TextComponentString(net.minecraft.util.text.TextComponentString) ItemStack(net.minecraft.item.ItemStack) UUID(java.util.UUID) TextComponentString(net.minecraft.util.text.TextComponentString)

Aggregations

ActionResult (net.minecraft.util.ActionResult)148 EnumActionResult (net.minecraft.util.EnumActionResult)147 ItemStack (net.minecraft.item.ItemStack)124 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)39 BlockPos (net.minecraft.util.math.BlockPos)31 RayTraceResult (net.minecraft.util.math.RayTraceResult)25 Nonnull (javax.annotation.Nonnull)15 Vec3d (net.minecraft.util.math.Vec3d)14 IBlockState (net.minecraft.block.state.IBlockState)12 TextComponentString (net.minecraft.util.text.TextComponentString)12 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)11 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)8 Entity (net.minecraft.entity.Entity)7 Block (net.minecraft.block.Block)6 EntityPlayer (net.minecraft.entity.player.EntityPlayer)6 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)5 TileEntity (net.minecraft.tileentity.TileEntity)4 DimensionInformation (mcjty.rftoolsdim.dimensions.DimensionInformation)3 RfToolsDimensionManager (mcjty.rftoolsdim.dimensions.RfToolsDimensionManager)3 FluidStack (net.minecraftforge.fluids.FluidStack)3