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