Search in sources :

Example 1 with CampfireBlock

use of net.minecraft.block.CampfireBlock in project MCDoom by AzureDoom.

the class ArgentPaxel method useOnBlock.

@Override
public ActionResult useOnBlock(ItemUsageContext context) {
    World world = context.getWorld();
    BlockPos blockpos = context.getBlockPos();
    PlayerEntity player = context.getPlayer();
    BlockState blockstate = world.getBlockState(blockpos);
    BlockState resultToSet = null;
    Block strippedResult = BLOCK_STRIPPING_MAP.get(blockstate.getBlock());
    if (strippedResult != null) {
        world.playSound(player, blockpos, SoundEvents.ITEM_AXE_STRIP, SoundCategory.BLOCKS, 1.0F, 1.0F);
        resultToSet = strippedResult.getDefaultState().with(PillarBlock.AXIS, blockstate.get(PillarBlock.AXIS));
    } else {
        if (context.getSide() == Direction.DOWN) {
            return ActionResult.PASS;
        }
        BlockState foundResult = SHOVEL_LOOKUP.get(blockstate.getBlock());
        if (foundResult != null && world.isAir(blockpos.up())) {
            world.playSound(player, blockpos, SoundEvents.ITEM_SHOVEL_FLATTEN, SoundCategory.BLOCKS, 1.0F, 1.0F);
            resultToSet = foundResult;
        } else if (blockstate.getBlock() instanceof CampfireBlock && blockstate.get(CampfireBlock.LIT)) {
            resultToSet = blockstate.with(CampfireBlock.LIT, false);
        }
    }
    if (resultToSet == null) {
        return ActionResult.PASS;
    }
    if (!world.isClient) {
        world.setBlockState(blockpos, resultToSet, 11);
        if (player != null) {
            context.getStack().damage(1, (LivingEntity) player, (Consumer<LivingEntity>) ((p) -> {
                ((LivingEntity) p).sendToolBreakStatus(context.getHand());
            }));
        }
    }
    return ActionResult.SUCCESS;
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) BlockState(net.minecraft.block.BlockState) CampfireBlock(net.minecraft.block.CampfireBlock) PillarBlock(net.minecraft.block.PillarBlock) Block(net.minecraft.block.Block) CampfireBlock(net.minecraft.block.CampfireBlock) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 2 with CampfireBlock

use of net.minecraft.block.CampfireBlock in project AntimatterAPI by GregTech-Intergalactical.

the class BehaviourVanillaShovel method onItemUse.

@Override
public ActionResultType onItemUse(IAntimatterTool instance, ItemUseContext c) {
    if (c.getFace() == Direction.DOWN)
        return ActionResultType.PASS;
    BlockState state = c.getWorld().getBlockState(c.getPos());
    BlockState changedState = null;
    if (state.getBlock() == Blocks.GRASS_BLOCK && c.getWorld().isAirBlock(c.getPos().up())) {
        SoundEvent soundEvent = instance.getType().getUseSound() == null ? SoundEvents.ITEM_SHOVEL_FLATTEN : instance.getType().getUseSound();
        c.getWorld().playSound(c.getPlayer(), c.getPos(), soundEvent, SoundCategory.BLOCKS, 1.0F, 1.0F);
        changedState = Blocks.GRASS_PATH.getDefaultState();
    } else if (state.getBlock() instanceof CampfireBlock && state.get(CampfireBlock.LIT)) {
        c.getWorld().playEvent(c.getPlayer(), 1009, c.getPos(), 0);
        changedState = state.with(CampfireBlock.LIT, false);
    }
    if (changedState != null) {
        c.getWorld().setBlockState(c.getPos(), changedState, 11);
        c.getItem().damageItem(instance.getType().getUseDurability(), c.getPlayer(), (p) -> p.sendBreakAnimation(c.getHand()));
        return ActionResultType.SUCCESS;
    } else
        return ActionResultType.PASS;
}
Also used : BlockState(net.minecraft.block.BlockState) CampfireBlock(net.minecraft.block.CampfireBlock)

Example 3 with CampfireBlock

use of net.minecraft.block.CampfireBlock in project ChaosAwakens by ChaosAwakens.

the class UltimateShovelItem method useOn.

@Override
public ActionResultType useOn(ItemUseContext ctx) {
    World world = ctx.getLevel();
    BlockPos eventPos = ctx.getClickedPos();
    BlockState blockstate = world.getBlockState(eventPos);
    PlayerEntity playerentity = ctx.getPlayer();
    if (ctx.getClickedFace() == Direction.DOWN) {
        return ActionResultType.PASS;
    } else {
        if (!world.isClientSide && playerentity != null) {
            ctx.getItemInHand().hurtAndBreak(1, playerentity, (p_220041_1_) -> p_220041_1_.broadcastBreakEvent(ctx.getHand()));
        }
        for (int x = -1; x < 2; x++) {
            for (int y = -1; y < 2; y++) {
                for (int z = -1; z < 2; z++) {
                    BlockPos targetPos = new BlockPos(eventPos.getX() + x, eventPos.getY() + y, eventPos.getZ() + z);
                    BlockState blockstate1 = blockstate.getToolModifiedState(world, targetPos, playerentity, ctx.getItemInHand(), net.minecraftforge.common.ToolType.SHOVEL);
                    BlockState blockstate2 = null;
                    if (world.isEmptyBlock(targetPos.above())) {
                        if (world.getBlockState(targetPos).is(blockstate.getBlock())) {
                            if (blockstate1 != null) {
                                world.playSound(playerentity, targetPos, SoundEvents.SHOVEL_FLATTEN, SoundCategory.BLOCKS, 1.0F, 1.0F);
                                blockstate2 = blockstate1;
                            } else if (blockstate.getBlock() instanceof CampfireBlock && blockstate.getValue(CampfireBlock.LIT)) {
                                if (!world.isClientSide()) {
                                    world.levelEvent(null, 1009, targetPos, 0);
                                }
                                CampfireBlock.dowse(world, targetPos, blockstate);
                                blockstate2 = blockstate.setValue(CampfireBlock.LIT, Boolean.FALSE);
                            }
                            if (blockstate2 != null) {
                                if (!world.isClientSide) {
                                    world.setBlock(targetPos, blockstate2, 11);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return ActionResultType.sidedSuccess(world.isClientSide);
}
Also used : BlockState(net.minecraft.block.BlockState) CampfireBlock(net.minecraft.block.CampfireBlock) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 4 with CampfireBlock

use of net.minecraft.block.CampfireBlock in project Paradise-Lost by devs-immortal.

the class ShovelItemMixin method useOnBlock.

@Inject(at = @At("HEAD"), method = "useOnBlock", cancellable = true)
public void useOnBlock(ItemUsageContext context, CallbackInfoReturnable<ActionResult> cir) {
    World world = context.getWorld();
    BlockPos blockPos = context.getBlockPos();
    BlockState blockState = world.getBlockState(blockPos);
    Map<Block, BlockState> AETHER_PATH_STATES = new HashMap<>();
    AETHER_PATH_STATES.put(AetherBlocks.AETHER_GRASS_BLOCK, AetherBlocks.AETHER_DIRT_PATH.getDefaultState());
    AETHER_PATH_STATES.put(AetherBlocks.AETHER_DIRT, AetherBlocks.AETHER_DIRT_PATH.getDefaultState());
    if (context.getSide() == Direction.DOWN) {
        cir.setReturnValue(ActionResult.PASS);
    } else {
        PlayerEntity playerEntity = context.getPlayer();
        BlockState blockState2 = AETHER_PATH_STATES.get(blockState.getBlock());
        BlockState blockState3 = null;
        if (blockState2 != null && world.getBlockState(blockPos.up()).isAir()) {
            world.playSound(playerEntity, blockPos, SoundEvents.ITEM_SHOVEL_FLATTEN, SoundCategory.BLOCKS, 1.0F, 1.0F);
            blockState3 = blockState2;
        } else if (blockState.getBlock() instanceof CampfireBlock && blockState.get(CampfireBlock.LIT)) {
            if (!world.isClient())
                world.syncWorldEvent(null, 1009, blockPos, 0);
            CampfireBlock.extinguish(world, blockPos, blockState);
            blockState3 = blockState.with(CampfireBlock.LIT, false);
        }
        if (blockState3 != null) {
            if (!world.isClient) {
                world.setBlockState(blockPos, blockState3, 11);
                if (playerEntity != null)
                    context.getStack().damage(1, playerEntity, (p) -> p.sendToolBreakStatus(context.getHand()));
            }
            cir.setReturnValue(ActionResult.success(world.isClient));
        }
    }
}
Also used : AetherBlocks(com.aether.blocks.AetherBlocks) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ToolMaterial(net.minecraft.item.ToolMaterial) World(net.minecraft.world.World) Inject(org.spongepowered.asm.mixin.injection.Inject) Set(java.util.Set) BlockPos(net.minecraft.util.math.BlockPos) HashMap(java.util.HashMap) ActionResult(net.minecraft.util.ActionResult) CallbackInfoReturnable(org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable) Direction(net.minecraft.util.math.Direction) ItemUsageContext(net.minecraft.item.ItemUsageContext) Block(net.minecraft.block.Block) SoundEvents(net.minecraft.sound.SoundEvents) Mixin(org.spongepowered.asm.mixin.Mixin) ShovelItem(net.minecraft.item.ShovelItem) MiningToolItem(net.minecraft.item.MiningToolItem) Map(java.util.Map) BlockState(net.minecraft.block.BlockState) SoundCategory(net.minecraft.sound.SoundCategory) CampfireBlock(net.minecraft.block.CampfireBlock) At(org.spongepowered.asm.mixin.injection.At) BlockState(net.minecraft.block.BlockState) HashMap(java.util.HashMap) CampfireBlock(net.minecraft.block.CampfireBlock) Block(net.minecraft.block.Block) CampfireBlock(net.minecraft.block.CampfireBlock) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 5 with CampfireBlock

use of net.minecraft.block.CampfireBlock in project Mekanism by mekanism.

the class ItemMekanismPaxel method useOn.

/**
 * {@inheritDoc}
 *
 * Merged version of {@link AxeItem#useOn(ItemUseContext)} and {@link ShovelItem#useOn(ItemUseContext)}
 */
@Nonnull
@Override
public ActionResultType useOn(ItemUseContext context) {
    World world = context.getLevel();
    BlockPos blockpos = context.getClickedPos();
    PlayerEntity player = context.getPlayer();
    ItemStack stack = context.getItemInHand();
    BlockState blockstate = world.getBlockState(blockpos);
    BlockState resultToSet = blockstate.getToolModifiedState(world, blockpos, player, stack, ToolType.AXE);
    if (resultToSet != null) {
        // We can strip the item as an axe
        world.playSound(player, blockpos, SoundEvents.AXE_STRIP, SoundCategory.BLOCKS, 1.0F, 1.0F);
    } else {
        // We cannot strip the item that was right-clicked, so attempt to use the paxel as a shovel
        if (context.getClickedFace() == Direction.DOWN) {
            return ActionResultType.PASS;
        }
        BlockState foundResult = blockstate.getToolModifiedState(world, blockpos, player, stack, ToolType.SHOVEL);
        if (foundResult != null && world.isEmptyBlock(blockpos.above())) {
            // We can flatten the item as a shovel
            world.playSound(player, blockpos, SoundEvents.SHOVEL_FLATTEN, SoundCategory.BLOCKS, 1.0F, 1.0F);
            resultToSet = foundResult;
        } else if (blockstate.getBlock() instanceof CampfireBlock && blockstate.getValue(CampfireBlock.LIT)) {
            // We can use the paxel as a shovel to extinguish a campfire
            if (!world.isClientSide) {
                world.levelEvent(null, WorldEvents.FIRE_EXTINGUISH_SOUND, blockpos, 0);
            }
            CampfireBlock.dowse(world, blockpos, blockstate);
            resultToSet = blockstate.setValue(CampfireBlock.LIT, false);
        }
    }
    if (resultToSet == null) {
        return ActionResultType.PASS;
    }
    if (!world.isClientSide) {
        world.setBlock(blockpos, resultToSet, BlockFlags.DEFAULT_AND_RERENDER);
        if (player != null) {
            stack.hurtAndBreak(1, player, onBroken -> onBroken.broadcastBreakEvent(context.getHand()));
        }
    }
    return ActionResultType.sidedSuccess(world.isClientSide);
}
Also used : BlockState(net.minecraft.block.BlockState) CampfireBlock(net.minecraft.block.CampfireBlock) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Nonnull(javax.annotation.Nonnull)

Aggregations

BlockState (net.minecraft.block.BlockState)5 CampfireBlock (net.minecraft.block.CampfireBlock)5 PlayerEntity (net.minecraft.entity.player.PlayerEntity)4 BlockPos (net.minecraft.util.math.BlockPos)4 World (net.minecraft.world.World)4 Block (net.minecraft.block.Block)2 AetherBlocks (com.aether.blocks.AetherBlocks)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 Nonnull (javax.annotation.Nonnull)1 PillarBlock (net.minecraft.block.PillarBlock)1 LivingEntity (net.minecraft.entity.LivingEntity)1 ItemStack (net.minecraft.item.ItemStack)1 ItemUsageContext (net.minecraft.item.ItemUsageContext)1 MiningToolItem (net.minecraft.item.MiningToolItem)1 ShovelItem (net.minecraft.item.ShovelItem)1 ToolMaterial (net.minecraft.item.ToolMaterial)1 SoundCategory (net.minecraft.sound.SoundCategory)1 SoundEvents (net.minecraft.sound.SoundEvents)1