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;
}
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;
}
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);
}
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));
}
}
}
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);
}
Aggregations