类net.minecraft.util.math.BlockPointer源码实例Demo

下面列出了怎么用net.minecraft.util.math.BlockPointer的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: carpet-extra   文件: CarpetDispenserBehaviours.java
@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);
}
 
源代码2 项目: carpet-extra   文件: CarpetDispenserBehaviours.java
@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);
}
 
源代码3 项目: carpet-extra   文件: CarpetDispenserBehaviours.java
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);
    }
}
 
源代码4 项目: carpet-extra   文件: CarpetDispenserBehaviours.java
@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);
}
 
@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();
    }
}
 
源代码6 项目: carpet-extra   文件: CarpetDispenserBehaviours.java
@Override
protected ItemStack dispenseSilently(BlockPointer source, ItemStack stack)
{
    if (!CarpetExtraSettings.dispensersFillMinecarts)
    {
        return defaultBehaviour(source, stack);
    }
    else
    {
        BlockPos pos = source.getBlockPos().offset((Direction) source.getBlockState().get(DispenserBlock.FACING));
        List<MinecartEntity> list = source.getWorld().<MinecartEntity>getEntities(MinecartEntity.class, new Box(pos), null);
    
        if (list.isEmpty())
        {
            return defaultBehaviour(source, stack);
        }
        else
        {
            MinecartEntity minecart = list.get(0);
            minecart.remove();
            AbstractMinecartEntity minecartEntity = AbstractMinecartEntity.create(minecart.world, minecart.getX(), minecart.getY(), minecart.getZ(), this.minecartType);
            minecartEntity.setVelocity(minecart.getVelocity());
            minecartEntity.pitch = minecart.pitch;
            minecartEntity.yaw = minecart.yaw;
            
            minecart.world.spawnEntity(minecartEntity);
            stack.decrement(1);
            return stack;
        }
    }
}
 
源代码7 项目: carpet-extra   文件: CarpetDispenserBehaviours.java
@Override
protected ItemStack dispenseSilently(BlockPointer source, ItemStack stack) {
    BlockPos pos = source.getBlockPos().offset((Direction) source.getBlockState().get(DispenserBlock.FACING));
    List<AnimalEntity> list = source.getWorld().getEntities(AnimalEntity.class, new Box(pos),null);
    boolean failure = false;

    for(AnimalEntity mob : list) {
        if(!mob.isBreedingItem(stack)) continue;
        if(mob.getBreedingAge() != 0 || mob.isInLove()) {
            failure = true;
            continue;
        }
        stack.decrement(1);
        mob.lovePlayer(null);
        return stack;
    }
    if(failure) return stack;
    // fix here for now - if problem shows up next time, will need to fix it one level above.
    if(
            CarpetExtraSettings.dispenserPlacesBlocks &&
            stack.getItem() instanceof BlockItem &&
            PlaceBlockDispenserBehavior.canPlace(((BlockItem) stack.getItem()).getBlock())
    )
    {
        return PlaceBlockDispenserBehavior.getInstance().dispenseSilently(source, stack);
    }
    else
    {
        return super.dispenseSilently(source, stack);
    }
}
 
源代码8 项目: carpet-extra   文件: CarpetDispenserBehaviours.java
@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;
}
 
@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);
            }
        }
    }
}
 
源代码10 项目: fabric-carpet   文件: BlockRotator.java
@Override
protected ItemStack dispenseSilently(BlockPointer source, ItemStack stack)
{
    if (CarpetSettings.rotatorBlock)
    {
        return BlockRotator.dispenserRotate(source, stack);
    }
    else
    {
        return super.dispenseSilently(source, stack);
    }
}
 
源代码11 项目: carpet-extra   文件: CarpetDispenserBehaviours.java
@Override
protected void playSound(BlockPointer source)
{
    source.getWorld().playLevelEvent(1000, source.getBlockPos(), 0);
}
 
源代码12 项目: patchwork-api   文件: MixinDispenserBehavior.java
@Inject(method = DISPENSE_SILENTLY, at = @At(value = "INVOKE", target = "net/minecraft/entity/passive/SheepEntity.dropItems()V"))
private void assertThatThisIsTheShearingDispenserAction(BlockPointer pointer, ItemStack stack, CallbackInfoReturnable<ItemStack> callback) {
	// Make sure that the anonymous class numbers didn't move around by checking for a SheepEntity reference.
}
 
 类所在包
 类方法
 同包方法