net.minecraft.item.ItemUsageContext Java Examples

The following examples show how to use net.minecraft.item.ItemUsageContext. 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: StandardWrenchItem.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
public ActionResult useOnBlock(ItemUsageContext itemUsageContext_1) {
    PlayerEntity player = itemUsageContext_1.getPlayer();
    World world_1 = itemUsageContext_1.getWorld();
    if (!world_1.isClient && player != null) {
        BlockPos pos = itemUsageContext_1.getBlockPos();
        this.use(player, world_1.getBlockState(pos), world_1, pos, itemUsageContext_1.getStack());
    }

    return ActionResult.SUCCESS;
}
 
Example #3
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 #4
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 #5
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 #6
Source File: SameBlockContext.java    From Sandbox with GNU Lesser General Public License v3.0 4 votes vote down vote up
public SameBlockContext(ItemUsageContext itemUsageContext_1) {
    super(itemUsageContext_1);
    this.canReplaceExisting = true;
}
 
Example #7
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;
}