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