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

The following examples show how to use net.minecraft.util.ActionResult#SUCCESS . 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: ColoredPumpkinBlock.java    From the-hallow with MIT License 6 votes vote down vote up
@Override
public ActionResult onUse(BlockState blockState, World world, BlockPos blockPos, PlayerEntity playerEntity, Hand hand, BlockHitResult blockHitResult) {
	ItemStack stack = playerEntity.getStackInHand(hand);

	if (stack.getItem() == Items.SHEARS) {
		if (!world.isClient) {
			Direction side = blockHitResult.getSide();
			Direction facingTowardPlayer = side.getAxis() == Direction.Axis.Y ? playerEntity.getHorizontalFacing().getOpposite() : side;

			world.playSound(null, blockPos, SoundEvents.BLOCK_PUMPKIN_CARVE, SoundCategory.BLOCKS, 1.0F, 1.0F);
			world.setBlockState(blockPos, HallowedBlocks.CARVED_PUMPKIN_COLORS.get(this.color).getDefaultState().with(CarvedPumpkinBlock.FACING, facingTowardPlayer), 11);
			ItemEntity itemEntity = new ItemEntity(world, blockPos.getX() + 0.5D + facingTowardPlayer.getOffsetX() * 0.65D, blockPos.getY() + 0.1D, blockPos.getZ() + 0.5D + facingTowardPlayer.getOffsetZ() * 0.65D, new ItemStack(Items.PUMPKIN_SEEDS, 4));

			itemEntity.setVelocity(0.05D * (double) facingTowardPlayer.getOffsetX() + world.random.nextDouble() * 0.02D, 0.05D, 0.05D * (double) facingTowardPlayer.getOffsetZ() + world.random.nextDouble() * 0.02D);
			world.spawnEntity(itemEntity);
			stack.damage(1, playerEntity, (playerEntityVar) -> {
				playerEntityVar.sendToolBreakStatus(hand);
			});
		}

		return ActionResult.SUCCESS;
	}

	return super.onUse(blockState, world, blockPos, playerEntity, hand, blockHitResult);
}
 
Example 3
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 4
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 5
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 6
Source File: TrumpetItem.java    From the-hallow with MIT License 5 votes vote down vote up
@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
	ItemStack stack = player.getStackInHand(hand);
	
	float soundPitch = (((player.pitch - 90) * 1) / -90);
	
	if (player.isSneaking()) {
		player.playSound(HallowedSounds.MEGALADOOT, 0.8f, 1.0f);
	} else {
		player.playSound(HallowedSounds.DOOT, 0.8f, soundPitch);
	}
	
	return new TypedActionResult<>(ActionResult.SUCCESS, stack);
}
 
Example 7
Source File: ServerPlayerInteractionManager_cactusMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Redirect(method = "interactBlock", at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/block/BlockState;onUse(Lnet/minecraft/world/World;Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/Hand;Lnet/minecraft/util/hit/BlockHitResult;)Lnet/minecraft/util/ActionResult;"
))
private ActionResult activateWithOptionalCactus(BlockState blockState, World world_1, PlayerEntity playerEntity_1, Hand hand_1, BlockHitResult blockHitResult_1)
{
    boolean flipped = BlockRotator.flipBlockWithCactus(blockState, world_1, playerEntity_1, hand_1, blockHitResult_1);
    if (flipped)
        return ActionResult.SUCCESS;

    return blockState.onUse(world_1, playerEntity_1, hand_1, blockHitResult_1);
}
 
Example 8
Source File: InfusionAltarBlock.java    From the-hallow with MIT License 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public ActionResult onUse(BlockState blockState, World world, BlockPos blockPos, PlayerEntity playerEntity, Hand hand, BlockHitResult blockHitResult) {
	InfusionAltarBlockEntity altarEntity = (InfusionAltarBlockEntity) world.getBlockEntity(blockPos);
	if (playerEntity.isSneaking()) {
		if (altarEntity != null) {
			getLinkedPillars(altarEntity);
			getCombinedInventory(altarEntity);
			Optional<InfusionRecipe> recipe = world.getRecipeManager().getFirstMatch(InfusionRecipe.Type.INSTANCE, combinedInventory, world);
			if (recipe.isPresent()) {
				if (world.isClient()) {
					createParticles(altarEntity);
					createSound(altarEntity);
				}
				if (!altarEntity.storedStack.isEmpty()) {
					createDrop(altarEntity, recipe.get().getOutput());
					clearAllStacks(altarEntity);
				} else {
					altarEntity.storedStack = recipe.get().getOutput().copy();
					clearPillarStacks(altarEntity);
				}
			}
		}
	} else {
		if (altarEntity != null) {
			if (playerEntity.getStackInHand(hand).isEmpty()) {
				playerEntity.inventory.offerOrDrop(world, altarEntity.takeStack());
			} else {
				playerEntity.setStackInHand(hand, altarEntity.putStack(playerEntity.getStackInHand(hand)));
			}
		}
	}

	return ActionResult.SUCCESS;
}
 
Example 9
Source File: InfusionPillarBlock.java    From the-hallow with MIT License 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public ActionResult onUse(BlockState blockState, World world, BlockPos blockPos, PlayerEntity playerEntity, Hand hand, BlockHitResult blockHitResult) {
	InfusionPillarBlockEntity pillarEntity = (InfusionPillarBlockEntity) world.getBlockEntity(blockPos);
	if (pillarEntity != null) {
		if (playerEntity.getStackInHand(hand).isEmpty()) {
			playerEntity.inventory.insertStack(pillarEntity.takeStack());
		} else {
			playerEntity.setStackInHand(hand, pillarEntity.putStack(playerEntity.getStackInHand(hand)));
		}
	}
	return ActionResult.SUCCESS;
}
 
Example 10
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 11
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 12
Source File: HallowCharmItem.java    From the-hallow with MIT License 5 votes vote down vote up
@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
	if (world.getDimension().getType() == HallowedDimensions.THE_HALLOW) {
		player.setCurrentHand(hand);
		player.playSound(SoundEvents.BLOCK_PORTAL_TRIGGER, 1F, 1F);
		return new TypedActionResult<>(ActionResult.SUCCESS, player.getActiveItem());
	} else {
		return ITrinket.equipTrinket(player, hand);
	}
}
 
Example 13
Source File: OxygenMaskItem.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
    if (((GCPlayerAccessor) user).getGearInventory().getStack(4).isEmpty()) {
        ((GCPlayerAccessor) user).getGearInventory().setStack(4, user.getStackInHand(hand));
        return new TypedActionResult<>(ActionResult.SUCCESS, ItemStack.EMPTY);
    }
    return super.use(world, user, hand);
}
 
Example 14
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 15
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 16
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 17
Source File: ThermalArmorItem.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override //should sync with server
public TypedActionResult<ItemStack> use(World world_1, PlayerEntity playerEntity_1, Hand hand_1) {
    SimpleInventoryComponent inv = ((GCPlayerAccessor) playerEntity_1).getGearInventory();
    ItemStack thermalPiece = inv.getStack(getSlotIdForType(getSlotType()));
    if (thermalPiece.isEmpty()) {
        inv.setStack(getSlotIdForType(getSlotType()), playerEntity_1.getStackInHand(hand_1));
        return new TypedActionResult<>(ActionResult.SUCCESS, ItemStack.EMPTY);
    }
    return super.use(world_1, playerEntity_1, hand_1);
}
 
Example 18
Source File: BasicSolarPanelPartBlock.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
public ActionResult onUse(BlockState blockState_1, World world_1, BlockPos blockPos_1, PlayerEntity playerEntity_1, Hand hand_1, BlockHitResult blockHitResult_1) {
    BlockEntity partEntity = world_1.getBlockEntity(blockPos_1);
    if (world_1.isAir(blockPos_1) || !(partEntity instanceof BasicSolarPanelPartBlockEntity)) {
        return ActionResult.SUCCESS;
    }

    if (world_1.isClient) return ActionResult.SUCCESS;

    BlockPos basePos = ((BasicSolarPanelPartBlockEntity) partEntity).basePos;

    BlockState base = world_1.getBlockState(basePos);
    Block baseBlock = base.getBlock();
    return ((BasicSolarPanelBlock) baseBlock).onUse(base, world_1, basePos, playerEntity_1, hand_1, blockHitResult_1);
}
 
Example 19
Source File: MoonBerryBushBlock.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
public ActionResult onUse(BlockState blockState, World world, BlockPos blockPos, PlayerEntity playerEntity, Hand hand, BlockHitResult blockHitResult) {
    int age = blockState.get(AGE);
    boolean mature = age == 3;

    if (mature) {
        int amount = 1 + world.random.nextInt(3);
        dropStack(world, blockPos, new ItemStack(GalacticraftItems.MOON_BERRIES, amount));
        world.playSound(null, blockPos, SoundEvents.ITEM_SWEET_BERRIES_PICK_FROM_BUSH, SoundCategory.BLOCKS, 1.0F, 0.8F + world.random.nextFloat() * 0.4F);
        world.setBlockState(blockPos, blockState.with(AGE, 1), 2);
        return ActionResult.SUCCESS;
    } else {
        return super.onUse(blockState, world, blockPos, playerEntity, hand, blockHitResult);
    }
}
 
Example 20
Source File: GuiBlock.java    From LibGui with MIT License 4 votes vote down vote up
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hitResult) {
	player.openHandledScreen(state.createScreenHandlerFactory(world, pos));
	return ActionResult.SUCCESS;
}