Java Code Examples for net.minecraft.util.math.BlockPointer#getWorld()

The following examples show how to use net.minecraft.util.math.BlockPointer#getWorld() . 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: CarpetDispenserBehaviours.java    From carpet-extra with GNU Lesser General Public License v3.0 7 votes vote down vote up
@Override
protected ItemStack dispenseSilently(BlockPointer source, ItemStack stack) {
    if(!CarpetExtraSettings.dispensersToggleThings) {
        return super.dispenseSilently(source, stack);
    }

    World world = source.getWorld();
    Direction direction = (Direction) source.getBlockState().get(DispenserBlock.FACING);
    BlockPos pos = source.getBlockPos().offset(direction);
    BlockState state = world.getBlockState(pos);  
    if(toggleable.contains(state.getBlock())) {
        ActionResult result = state.onUse(
            world, 
            null,
            Hand.MAIN_HAND,
            new BlockHitResult(
                new Vec3d(new Vec3i(pos.getX(), pos.getY(), pos.getZ())), 
                direction, 
                pos,
                false
            )
        );
        if(result.isAccepted()) return stack; // success or consume
    }
    return super.dispenseSilently(source, stack);
}
 
Example 2
Source File: DispenserBehaviorFireChargeMixin.java    From carpet-extra with GNU Lesser General Public License v3.0 7 votes vote down vote up
@SuppressWarnings("UnresolvedMixinReference")
@Inject(method = "dispenseSilently(Lnet/minecraft/util/math/BlockPointer;Lnet/minecraft/item/ItemStack;)Lnet/minecraft/item/ItemStack;", at = @At("HEAD"), cancellable = true)
private void convertNetherrack(BlockPointer pointer, ItemStack stack, CallbackInfoReturnable<ItemStack> cir)
{
    if (!CarpetExtraSettings.fireChargeConvertsToNetherrack)
        return;
    World world = pointer.getWorld();
    Direction direction = pointer.getBlockState().get(DispenserBlock.FACING);
    BlockPos front = pointer.getBlockPos().offset(direction);
    BlockState state = world.getBlockState(front);
    if (state.getBlock() == Blocks.COBBLESTONE)
    {
        world.setBlockState(front, Blocks.NETHERRACK.getDefaultState());
        stack.decrement(1);
        cir.setReturnValue(stack);
        cir.cancel();
    }
}
 
Example 3
Source File: CarpetDispenserBehaviours.java    From carpet-extra with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected ItemStack dispenseSilently(BlockPointer source, ItemStack stack)
{
    if (!CarpetExtraSettings.dispensersPlayRecords)
        return super.dispenseSilently(source, stack);
    
    Direction direction = source.getBlockState().get(DispenserBlock.FACING);
    BlockPos pos = source.getBlockPos().offset(direction);
    World world = source.getWorld();
    BlockState state = world.getBlockState(pos);
    
    if (state.getBlock() == Blocks.JUKEBOX)
    {
        JukeboxBlockEntity jukebox = (JukeboxBlockEntity) world.getBlockEntity(pos);
        if (jukebox != null)
        {
            ItemStack itemStack = jukebox.getRecord();
            ((JukeboxBlock) state.getBlock()).setRecord(world, pos, state, stack);
            world.playLevelEvent(null, 1010, pos, Item.getRawId(stack.getItem()));
            
            return itemStack;
        }
    }
    
    return super.dispenseSilently(source, stack);
}
 
Example 4
Source File: CarpetDispenserBehaviours.java    From carpet-extra with GNU Lesser General Public License v3.0 6 votes vote down vote up
private ItemStack defaultBehaviour(BlockPointer source, ItemStack stack)
{
    if (this.minecartType == AbstractMinecartEntity.Type.TNT)
    {
        World world = source.getWorld();
        BlockPos pos = source.getBlockPos().offset((Direction) source.getBlockState().get(DispenserBlock.FACING));
        TntEntity tntEntity = new TntEntity(world, (double)pos.getX() + 0.5D, (double)pos.getY(), (double)pos.getZ() + 0.5D, (LivingEntity)null);
        world.spawnEntity(tntEntity);
        world.playSound((PlayerEntity)null, tntEntity.getX(), tntEntity.getY(), tntEntity.getZ(), SoundEvents.ENTITY_TNT_PRIMED, SoundCategory.BLOCKS, 1.0F, 1.0F);
        stack.decrement(1);
        return stack;
    }
    else
    {
        return super.dispenseSilently(source, stack);
    }
}
 
Example 5
Source File: CarpetDispenserBehaviours.java    From carpet-extra with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected ItemStack dispenseSilently(BlockPointer source, ItemStack stack)
{
    if (!CarpetExtraSettings.dragonsBreathConvertsCobbleToEndstone)
        return super.dispenseSilently(source, stack);
    
    World world = source.getWorld();
    Direction direction = source.getBlockState().get(DispenserBlock.FACING);
    BlockPos front = source.getBlockPos().offset(direction);
    BlockState state = world.getBlockState(front);
    
    if (state.getBlock() == Blocks.COBBLESTONE)
    {
        world.setBlockState(front, Blocks.END_STONE.getDefaultState());
        stack.decrement(1);
        return stack;
    }
    return super.dispenseSilently(source, stack);
}
 
Example 6
Source File: CarpetDispenserBehaviours.java    From carpet-extra with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected ItemStack dispenseSilently(BlockPointer blockPointer_1, ItemStack itemStack_1)
{
    if (!CarpetExtraSettings.dispensersTillSoil)
        return super.dispenseSilently(blockPointer_1, itemStack_1);
    
    World world = blockPointer_1.getWorld();
    Direction direction = blockPointer_1.getBlockState().get(DispenserBlock.FACING);
    BlockPos front = blockPointer_1.getBlockPos().offset(direction);
    BlockPos down = blockPointer_1.getBlockPos().down().offset(direction);
    BlockState frontState = world.getBlockState(front);
    BlockState downState = world.getBlockState(down);
    
    if (isFarmland(frontState) || isFarmland(downState))
        return itemStack_1;
    
    if (canDirectlyTurnToFarmland(frontState))
        world.setBlockState(front, Blocks.FARMLAND.getDefaultState());
    else if (canDirectlyTurnToFarmland(downState))
        world.setBlockState(down, Blocks.FARMLAND.getDefaultState());
    else if (frontState.getBlock() == Blocks.COARSE_DIRT)
        world.setBlockState(front, Blocks.DIRT.getDefaultState());
    else if (downState.getBlock() == Blocks.COARSE_DIRT)
        world.setBlockState(down, Blocks.DIRT.getDefaultState());
    
    if (itemStack_1.damage(1, world.random, null))
        itemStack_1.setCount(0);
    
    return itemStack_1;
}
 
Example 7
Source File: DispenserBehaviorBucketCowsMixin.java    From carpet-extra with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Inject(
        method = "dispenseSilently(Lnet/minecraft/util/math/BlockPointer;Lnet/minecraft/item/ItemStack;)Lnet/minecraft/item/ItemStack;",
        at = @At("HEAD"), cancellable = true
)
private void milkCow(BlockPointer pointer, ItemStack stack, CallbackInfoReturnable<ItemStack> cir)
{
    if (!CarpetExtraSettings.dispensersMilkCows)
        return;
    World world = pointer.getWorld();
    
    if (!world.isClient)
    {
        BlockPos pos = pointer.getBlockPos().offset(pointer.getBlockState().get(DispenserBlock.FACING));
        List<CowEntity> cows = world.getEntities(CowEntity.class, new Box(pos), e -> e.isAlive() && !e.isBaby());
        if (!cows.isEmpty())
        {
            stack.decrement(1);
            if (stack.isEmpty())
            {
                cir.setReturnValue(new ItemStack(Items.MILK_BUCKET));
            }
            else
            {
                if (((DispenserBlockEntity)pointer.getBlockEntity()).addToFirstFreeSlot(new ItemStack(Items.MILK_BUCKET)) < 0)
                {
                    this.dispense(pointer, new ItemStack(Items.MILK_BUCKET));
                }
                cir.setReturnValue(stack);
            }
        }
    }
}