Java Code Examples for net.minecraft.util.ActionResult#PASS

The following examples show how to use net.minecraft.util.ActionResult#PASS . 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: HallowCharmItem.java    From the-hallow with MIT License 7 votes vote down vote up
@Override
public ActionResult useOnBlock(ItemUsageContext context) {
	PlayerEntity player = context.getPlayer();
	if (context.getWorld().isClient) return ActionResult.PASS;
	BlockState state = context.getWorld().getBlockState(context.getBlockPos());
	if(state.getBlock() == HallowedBlocks.HALLOWED_GATE) {
		if (context.getWorld().getDimension().getType() == DimensionType.OVERWORLD) {
			if (HallowedGateBlock.isValid(context.getWorld(), context.getBlockPos(), state)) {
				BlockPos pos = player.getBlockPos();
				CompoundTag tag = new CompoundTag();
				tag.putInt("x", pos.getX());
				tag.putInt("y", pos.getY());
				tag.putInt("z", pos.getZ());
				context.getStack().putSubTag("PortalLoc", tag);
				FabricDimensions.teleport(player, HallowedDimensions.THE_HALLOW);
				return ActionResult.SUCCESS;
			} else {
				player.addChatMessage(new TranslatableText("text.thehallow.gate_incomplete"), true);
			}
		} else {
			player.addChatMessage(new TranslatableText("text.thehallow.gate_in_wrong_dimension"), true);
		}
	}
	return ActionResult.PASS;
}
 
Example 2
Source File: HallowedLogBlock.java    From the-hallow with MIT License 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
	ItemStack stack = player.getStackInHand(hand);
	if (stack.isEmpty() || !(stack.getItem() instanceof MiningToolItem)) {
		return ActionResult.PASS;
	}
	
	MiningToolItem tool = (MiningToolItem) stack.getItem();
	if (stripped != null && (tool.isEffectiveOn(state) || tool.getMiningSpeed(stack, state) > 1.0F)) {
		world.playSound(player, pos, SoundEvents.ITEM_AXE_STRIP, SoundCategory.BLOCKS, 1.0F, 1.0F);
		if (!world.isClient) {
			BlockState target = stripped.getDefaultState().with(LogBlock.AXIS, state.get(LogBlock.AXIS));
			world.setBlockState(pos, target);
			stack.damage(1, player, consumedPlayer -> consumedPlayer.sendToolBreakStatus(hand));
		}
		return ActionResult.SUCCESS;
	}
	return ActionResult.PASS;
}
 
Example 3
Source File: PumpkinPieBlock.java    From the-hallow with MIT License 6 votes vote down vote up
private ActionResult tryEat(IWorld iWorld, BlockPos pos, BlockState state, PlayerEntity player) {
	if (!player.canConsume(false)) {
		return ActionResult.PASS;
	}
	float saturation = 0.1F;
	TrinketComponent trinketPlayer = TrinketsApi.getTrinketComponent(player);
	ItemStack mainHandStack = trinketPlayer.getStack("hand:ring");
	ItemStack offHandStack = trinketPlayer.getStack("offhand:ring");
	if (mainHandStack.getItem().equals(HallowedItems.PUMPKIN_RING) || offHandStack.getItem().equals(HallowedItems.PUMPKIN_RING)) {
		saturation = 0.3F;
	}
	player.getHungerManager().add(2, saturation);
	int bites = state.get(BITES);
	if (bites > 1) {
		iWorld.setBlockState(pos, state.with(BITES, bites - 1), 3);
	} else {
		iWorld.removeBlock(pos, false);
	}
	return ActionResult.SUCCESS;
}
 
Example 4
Source File: HallowedTreasureChestBlock.java    From the-hallow with MIT License 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public ActionResult onUse(BlockState blockState, World world, BlockPos pos, PlayerEntity playerEntity, Hand hand, BlockHitResult blockHitResult) {
	if (hand == Hand.MAIN_HAND) {
		float x = pos.getX() + .49f;
		float y = pos.getY();
		float z = pos.getZ() + .51f;
		
		HallowedTreasureChestEntity entity = new HallowedTreasureChestEntity(world, x, y, z, true, blockState.get(FACING).asRotation());
		entity.updatePosition(x, y, z);
		world.spawnEntity(entity);
		
		return ActionResult.SUCCESS;
	}
	
	return ActionResult.PASS;
}
 
Example 5
Source File: OxygenTankItem.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) { //should sync with server
    if (((GCPlayerAccessor) player).getGearInventory().getStack(6).isEmpty()) {
        ((GCPlayerAccessor) player).getGearInventory().setStack(6, player.getStackInHand(hand).copy());
        return new TypedActionResult<>(ActionResult.SUCCESS, ItemStack.EMPTY);
    } else if (((GCPlayerAccessor) player).getGearInventory().getStack(7).isEmpty()) {
        ((GCPlayerAccessor) player).getGearInventory().setStack(7, player.getStackInHand(hand).copy());
        return new TypedActionResult<>(ActionResult.SUCCESS, ItemStack.EMPTY);
    }
    return new TypedActionResult<>(ActionResult.PASS, player.getStackInHand(hand));
}
 
Example 6
Source File: TinyPumpkinBlock.java    From the-hallow with MIT License 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
	BlockEntity be = world.getBlockEntity(pos);
	if (be instanceof TinyPumpkinBlockEntity) {
		return ((TinyPumpkinBlockEntity) be).use(player, hand, hit);
	}
	return ActionResult.PASS;
}
 
Example 7
Source File: TinyPumpkinBlockEntity.java    From the-hallow with MIT License 5 votes vote down vote up
public ActionResult use(PlayerEntity player, Hand hand, BlockHitResult hit) {
	Direction facing = getCachedState().get(HorizontalFacingBlock.FACING);
	Direction hitSide = hit.getSide();
	if (hitSide != facing.rotateYClockwise() && hitSide != facing.rotateYCounterclockwise()) {
		return ActionResult.PASS;
	}
	
	if (!world.isClient) {
		ItemStack handStack = player.getStackInHand(hand);
		boolean isLeft = hitSide == facing.rotateYCounterclockwise();
		ItemStack heldItem = isLeft ? leftItem : rightItem;
		if (!heldItem.isEmpty()) {
			ItemScatterer.spawn(world, pos, DefaultedList.copyOf(ItemStack.EMPTY, heldItem));
			if (isLeft) {
				leftItem = ItemStack.EMPTY;
			} else {
				rightItem = ItemStack.EMPTY;
			}
			sync();
			markDirty();
		} else if (!handStack.isEmpty()) {
			if (isLeft) {
				leftItem = handStack.copy();
				leftItem.setCount(1);
			} else {
				rightItem = handStack.copy();
				rightItem.setCount(1);
			}
			handStack.decrement(1);
			sync();
			markDirty();
		}
	}
	
	return ActionResult.SUCCESS;
}
 
Example 8
Source File: PumpkinPieBlock.java    From the-hallow with MIT License 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hitResult) {
	if (!world.isClient) {
		return this.tryEat(world, pos, state, player);
	}
	ItemStack stack = player.getStackInHand(hand);
	if(stack.isEmpty()) {
		return ActionResult.PASS;
	}
	return this.tryEat(world, pos, state, player);
}
 
Example 9
Source File: WrappingUtil.java    From Sandbox with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static ActionResult convert(InteractionResult result) {
    switch (result) {
        case SUCCESS:
            return ActionResult.SUCCESS;
        case CONSUME:
            return ActionResult.CONSUME;
        case FAILURE:
            return ActionResult.FAIL;
        default:
        case IGNORE:
            return ActionResult.PASS;
    }
}
 
Example 10
Source File: ItemWrapper.java    From Sandbox with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public ActionResult useOnBlock(ItemUsageContext itemUsageContext_1) {
    InteractionResult result = iItem.onItemUsed(
            (World) itemUsageContext_1.getWorld(),
            (Position) itemUsageContext_1.getBlockPos(),
            WrappingUtil.cast(itemUsageContext_1.getStack(), ItemStack.class)
    );
    return result == InteractionResult.SUCCESS ? ActionResult.SUCCESS : result == InteractionResult.FAILURE ? ActionResult.FAIL : ActionResult.PASS;
}
 
Example 11
Source File: ItemWrapper.java    From Sandbox with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public ActionResult useOnBlock(ItemUsageContext itemUsageContext_1) {
    InteractionResult result = item.onItemUsed(
            (World) itemUsageContext_1.getWorld(),
            (Position) itemUsageContext_1.getBlockPos(),
            WrappingUtil.cast(itemUsageContext_1.getStack(), ItemStack.class)
    );
    if (result == InteractionResult.IGNORE)
        return super.useOnBlock(itemUsageContext_1);
    return result == InteractionResult.SUCCESS ? ActionResult.SUCCESS : result == InteractionResult.FAILURE ? ActionResult.FAIL : ActionResult.PASS;
}
 
Example 12
Source File: ItemWrapper.java    From Sandbox with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public ActionResult useOnBlock(ItemUsageContext itemUsageContext_1) {
    InteractionResult result = item.onItemUsed(
            (World) itemUsageContext_1.getWorld(),
            (Position) itemUsageContext_1.getBlockPos(),
            WrappingUtil.cast(itemUsageContext_1.getStack(), ItemStack.class)
    );
    if (result == InteractionResult.IGNORE)
        return super.useOnBlock(itemUsageContext_1);
    return result == InteractionResult.SUCCESS ? ActionResult.SUCCESS : result == InteractionResult.FAILURE ? ActionResult.FAIL : ActionResult.PASS;
}
 
Example 13
Source File: IForgeItem.java    From patchwork-api with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * This is called when the item is used, before the block is activated.
 *
 * @return Return PASS to allow vanilla handling, any other to skip normal code.
 */
default ActionResult onItemUseFirst(ItemStack stack, ItemUsageContext context) {
	return ActionResult.PASS;
}