Search in sources :

Example 21 with ChunkCache

use of net.minecraft.world.ChunkCache in project Almura by AlmuraDev.

the class MixinBlockTallGrass method getDrops.

/**
 * @author Zidane - Chris Sanders
 * @reason Add in content seeds to drop list for Tall Grass
 */
@Overwrite(remap = false)
public void getDrops(final NonNullList<ItemStack> drops, final IBlockAccess access, final BlockPos pos, final IBlockState state, final int fortune) {
    World world;
    if (access instanceof ChunkCache) {
        world = ((ChunkCache) access).world;
    } else if (access instanceof World) {
        world = (World) access;
    } else {
        return;
    }
    final Random random = world.rand;
    // Roll 1 is Vanilla's 1/8 chance to drop a seed
    final int roll1 = random.nextInt(8);
    if (roll1 == 0) {
        // Forge Start - Lookup seed each time and then do random check. Almura handles its own chance code
        final ItemStack modSeed = net.minecraftforge.common.ForgeHooks.getGrassSeed(random, fortune);
        if (!modSeed.isEmpty()) {
            drops.add(modSeed);
            // Don't double up with Vanilla/mod drops
            return;
        }
        final Biome biome = world.getBiome(pos);
        // Roll 2 is shuffling Almura seeds and picking the first one after shuffling
        registry.getAllOf(ItemType.class).stream().filter(itemType -> itemType instanceof SeedItem && ((SeedItem) itemType).getGrass() != null).collect(Collectors.collectingAndThen(Collectors.toList(), collected -> {
            Collections.shuffle(collected);
            return collected.stream();
        })).findFirst().ifPresent((itemType) -> {
            final SeedItem seed = (SeedItem) itemType;
            final IntRange amountRange = seed.getGrass().getOrLoadAmountRequiredRangeForBiome(biome);
            if (amountRange != null) {
                final int stackSize = amountRange.random(random);
                final DoubleRange chanceRange = seed.getGrass().getOrLoadChanceRangeForBiome(biome);
                if (chanceRange != null) {
                    final double chance = chanceRange.random(random);
                    // Roll 3 is allowing the seed configuration to determine the chance for the drop
                    if (random.nextDouble() <= (chance / 100)) {
                        drops.add((ItemStack) (Object) org.spongepowered.api.item.inventory.ItemStack.of(itemType, stackSize));
                    }
                } else {
                    drops.add((ItemStack) (Object) org.spongepowered.api.item.inventory.ItemStack.of(itemType, stackSize));
                }
            }
        });
    }
// Almura End
}
Also used : ChunkCache(net.minecraft.world.ChunkCache) World(net.minecraft.world.World) BlockPos(net.minecraft.util.math.BlockPos) Random(java.util.Random) Overwrite(org.spongepowered.asm.mixin.Overwrite) SeedItem(com.almuradev.content.type.item.type.seed.SeedItem) BlockTallGrass(net.minecraft.block.BlockTallGrass) Collectors(java.util.stream.Collectors) GameRegistry(org.spongepowered.api.GameRegistry) Inject(javax.inject.Inject) IBlockState(net.minecraft.block.state.IBlockState) ItemStack(net.minecraft.item.ItemStack) Mixin(org.spongepowered.asm.mixin.Mixin) MixinBlock(com.almuradev.content.type.block.mixin.impl.MixinBlock) DoubleRange(com.almuradev.toolbox.util.math.DoubleRange) NonNullList(net.minecraft.util.NonNullList) ItemType(org.spongepowered.api.item.ItemType) Collections(java.util.Collections) IntRange(com.almuradev.toolbox.util.math.IntRange) IBlockAccess(net.minecraft.world.IBlockAccess) Biome(net.minecraft.world.biome.Biome) ChunkCache(net.minecraft.world.ChunkCache) ItemType(org.spongepowered.api.item.ItemType) IntRange(com.almuradev.toolbox.util.math.IntRange) World(net.minecraft.world.World) SeedItem(com.almuradev.content.type.item.type.seed.SeedItem) DoubleRange(com.almuradev.toolbox.util.math.DoubleRange) Biome(net.minecraft.world.biome.Biome) Random(java.util.Random) ItemStack(net.minecraft.item.ItemStack) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 22 with ChunkCache

use of net.minecraft.world.ChunkCache in project Almura by AlmuraDev.

the class GrassFeature method canPlace.

private boolean canPlace(final IBlockAccess access, final BlockPos pos, final IBlockState toPlaceState, final List<LazyBlockState> requires) {
    World world;
    if (access instanceof ChunkCache) {
        world = ((ChunkCacheAccessor) access).accessor$getWorld();
    } else {
        world = (World) access;
    }
    final Block toPlaceBlock = toPlaceState.getBlock();
    boolean canPlace = true;
    if (!requires.isEmpty()) {
        final IBlockState underState = access.getBlockState(pos.down());
        boolean found = false;
        for (final LazyBlockState lbs : requires) {
            if (lbs.partialTest(underState)) {
                found = true;
                break;
            }
        }
        canPlace = found;
    }
    if (canPlace) {
        if (toPlaceBlock instanceof BlockBush) {
            canPlace = ((BlockBush) toPlaceBlock).canBlockStay(world, pos, toPlaceState);
        }
    }
    return canPlace;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) ChunkCache(net.minecraft.world.ChunkCache) Block(net.minecraft.block.Block) World(net.minecraft.world.World) WeightedLazyBlockState(com.almuradev.content.util.WeightedLazyBlockState) LazyBlockState(com.almuradev.content.type.block.state.LazyBlockState) BlockBush(net.minecraft.block.BlockBush)

Example 23 with ChunkCache

use of net.minecraft.world.ChunkCache in project Almura by AlmuraDev.

the class CactusFeature method canPlace.

private boolean canPlace(final IBlockAccess access, final BlockPos pos, final IBlockState toPlaceState, final List<LazyBlockState> requires) {
    World world;
    if (access instanceof ChunkCache) {
        world = ((ChunkCacheAccessor) access).accessor$getWorld();
    } else {
        world = (World) access;
    }
    final Block toPlaceBlock = toPlaceState.getBlock();
    boolean canPlace = true;
    if (!requires.isEmpty()) {
        final IBlockState underState = access.getBlockState(pos.down());
        boolean found = false;
        for (final LazyBlockState lbs : requires) {
            if (lbs.partialTest(underState)) {
                found = true;
                break;
            }
        }
        canPlace = found;
    }
    if (canPlace) {
        // Why Vanilla lol
        if (toPlaceBlock instanceof BlockCactus) {
            canPlace = ((BlockCactus) toPlaceBlock).canBlockStay(world, pos);
        } else if (toPlaceBlock instanceof BlockBush) {
            canPlace = ((BlockBush) toPlaceBlock).canBlockStay(world, pos, toPlaceState);
        }
    }
    return canPlace;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) ChunkCache(net.minecraft.world.ChunkCache) Block(net.minecraft.block.Block) World(net.minecraft.world.World) BlockCactus(net.minecraft.block.BlockCactus) WeightedLazyBlockState(com.almuradev.content.util.WeightedLazyBlockState) LazyBlockState(com.almuradev.content.type.block.state.LazyBlockState) BlockBush(net.minecraft.block.BlockBush)

Example 24 with ChunkCache

use of net.minecraft.world.ChunkCache in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class PhysicsObject method updateChunkCache.

public void updateChunkCache() {
    BlockPos min = new BlockPos(collisionBB.minX, Math.max(collisionBB.minY, 0), collisionBB.minZ);
    BlockPos max = new BlockPos(collisionBB.maxX, Math.min(collisionBB.maxY, 255), collisionBB.maxZ);
    surroundingWorldChunksCache = new ChunkCache(worldObj, min, max, 0);
}
Also used : ChunkCache(net.minecraft.world.ChunkCache) VWChunkCache(ValkyrienWarfareBase.Relocation.VWChunkCache) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos) BlockPos(net.minecraft.util.math.BlockPos)

Example 25 with ChunkCache

use of net.minecraft.world.ChunkCache in project BetterWithAddons by DaedalusGame.

the class BlockRopeSideways method getExtendedState.

@Override
public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) {
    TileEntity te = world instanceof ChunkCache ? ((ChunkCache) world).getTileEntity(pos, Chunk.EnumCreateEntityType.CHECK) : world.getTileEntity(pos);
    ItemStack planks = ItemStack.EMPTY;
    if (te instanceof TileEntityRopeSideways) {
        TileEntityRopeSideways tile = (TileEntityRopeSideways) te;
        planks = tile.getPlanks();
    }
    return ((IExtendedBlockState) state).withProperty(HELD_PLANKS, planks);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityRopeSideways(betterwithaddons.tileentity.TileEntityRopeSideways) ChunkCache(net.minecraft.world.ChunkCache) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ChunkCache (net.minecraft.world.ChunkCache)36 TileEntity (net.minecraft.tileentity.TileEntity)16 BlockPos (net.minecraft.util.math.BlockPos)9 IBlockState (net.minecraft.block.state.IBlockState)8 Block (net.minecraft.block.Block)5 World (net.minecraft.world.World)5 LazyBlockState (com.almuradev.content.type.block.state.LazyBlockState)4 WeightedLazyBlockState (com.almuradev.content.util.WeightedLazyBlockState)4 ArrayList (java.util.ArrayList)4 BlockBush (net.minecraft.block.BlockBush)4 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)4 IBlockAccess (net.minecraft.world.IBlockAccess)4 TIntArrayList (gnu.trove.list.array.TIntArrayList)3 BlockCactus (net.minecraft.block.BlockCactus)3 ItemStack (net.minecraft.item.ItemStack)3 PathEntity (net.minecraft.pathfinding.PathEntity)3 PathPoint (net.minecraft.pathfinding.PathPoint)3 MutableBlockPos (net.minecraft.util.math.BlockPos.MutableBlockPos)3 Chunk (net.minecraft.world.chunk.Chunk)3 ExtendedBlockStorage (net.minecraft.world.chunk.storage.ExtendedBlockStorage)3