Java Code Examples for net.minecraft.entity.player.PlayerEntity#setStackInHand()
The following examples show how to use
net.minecraft.entity.player.PlayerEntity#setStackInHand() .
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: UnlitWallTorchBlock.java From Galacticraft-Rewoven with MIT License | 5 votes |
@Override public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { if (player.getStackInHand(hand).getItem() instanceof FlintAndSteelItem) { world.setBlockState(pos, Blocks.WALL_TORCH.getDefaultState().with(WallTorchBlock.FACING, state.get(WallTorchBlock.FACING))); ItemStack stack = player.getStackInHand(hand).copy(); stack.damage(1, player, (playerEntity -> { })); player.setStackInHand(hand, stack); } return super.onUse(state, world, pos, player, hand, hit); }
Example 2
Source File: UnlitTorchBlock.java From Galacticraft-Rewoven with MIT License | 5 votes |
@Override public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { if (player.getStackInHand(hand).getItem() instanceof FlintAndSteelItem) { world.setBlockState(pos, Blocks.TORCH.getDefaultState()); ItemStack stack = player.getStackInHand(hand).copy(); stack.damage(1, player, (playerEntity -> { })); player.setStackInHand(hand, stack); } return super.onUse(state, world, pos, player, hand, hit); }
Example 3
Source File: InfusionPillarBlock.java From the-hallow with MIT License | 5 votes |
@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 4
Source File: InfusionAltarBlock.java From the-hallow with MIT License | 5 votes |
@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 5
Source File: PumpcownEntity.java From the-hallow with MIT License | 4 votes |
@Override public boolean interactMob(PlayerEntity player, Hand hand) { ItemStack stack = player.getStackInHand(hand); if (stack.getItem() == Items.SHEARS && this.getBreedingAge() >= 0) { this.world.addParticle(ParticleTypes.EXPLOSION, this.getX(), this.getY() + (double) (this.getHeight() / 2.0F), this.getZ(), 0.0D, 0.0D, 0.0D); if (!this.world.isClient) { this.remove(); if (this.world.getDimension().getType() == HallowedDimensions.THE_HALLOW) { this.world.createExplosion(this, this.getX(), this.getY(), this.getZ(), 3.0F, Explosion.DestructionType.BREAK); } else { CowEntity cow = EntityType.COW.create(this.world); cow.updatePositionAndAngles(this.getX(), this.getY(), this.getZ(), this.yaw, this.pitch); cow.setHealth(this.getHealth()); cow.bodyYaw = this.bodyYaw; if (this.hasCustomName()) { cow.setCustomName(this.getCustomName()); } this.world.spawnEntity(cow); } for (int i = 0; i < 5; ++i) { this.world.spawnEntity(new ItemEntity(this.world, this.getX(), this.getY() + (double) this.getHeight(), this.getZ(), new ItemStack(STEM_FEATURE.getBlock()))); } stack.damage(1, player, ((player_1) -> { player_1.sendToolBreakStatus(hand); })); this.playSound(SoundEvents.ENTITY_MOOSHROOM_SHEAR, 1.0F, 1.0F); } return true; } else if (stack.getItem() == Items.BOWL && this.getBreedingAge() >= 0 && !player.abilities.creativeMode) { stack.decrement(1); ItemStack stew = new ItemStack(HallowedItems.PUMPKIN_STEW); if (stack.isEmpty()) { player.setStackInHand(hand, stew); } else if (!player.inventory.insertStack(stew)) { player.dropItem(stew, false); } this.playSound(SoundEvents.ENTITY_MOOSHROOM_MILK, 1.0F, 1.0F); return true; } else { return super.interactMob(player, hand); } }