use of org.spongepowered.api.util.weighted.ChanceTable in project SpongeCommon by SpongePowered.
the class MixinBiome method buildPopulators.
@Override
public void buildPopulators(World world, SpongeBiomeGenerationSettings gensettings) {
BiomeDecorator theBiomeDecorator = this.decorator;
gensettings.getGroundCoverLayers().add(new GroundCoverLayer((BlockState) this.topBlock, SeededVariableAmount.fixed(1)));
gensettings.getGroundCoverLayers().add(new GroundCoverLayer((BlockState) this.fillerBlock, WorldGenConstants.GROUND_COVER_DEPTH));
String s = world.getWorldInfo().getGeneratorOptions();
ChunkGeneratorSettings settings = ChunkGeneratorSettings.Factory.jsonToFactory(s).build();
Ore dirt = Ore.builder().ore((BlockState) Blocks.DIRT.getDefaultState()).size(settings.dirtSize).perChunk(settings.dirtCount).height(VariableAmount.baseWithRandomAddition(settings.dirtMinHeight, settings.dirtMaxHeight - settings.dirtMinHeight)).build();
gensettings.getPopulators().add(dirt);
Ore gravel = Ore.builder().ore((BlockState) Blocks.GRAVEL.getDefaultState()).size(settings.gravelSize).perChunk(settings.gravelCount).height(VariableAmount.baseWithRandomAddition(settings.gravelMinHeight, settings.gravelMaxHeight - settings.gravelMinHeight)).build();
gensettings.getPopulators().add(gravel);
Ore diorite = Ore.builder().ore((BlockState) Blocks.STONE.getDefaultState().withProperty(BlockStone.VARIANT, BlockStone.EnumType.DIORITE)).size(settings.dioriteSize).perChunk(settings.dioriteCount).height(VariableAmount.baseWithRandomAddition(settings.dioriteMinHeight, settings.dioriteMaxHeight - settings.dioriteMinHeight)).build();
gensettings.getPopulators().add(diorite);
Ore granite = Ore.builder().ore((BlockState) Blocks.STONE.getDefaultState().withProperty(BlockStone.VARIANT, BlockStone.EnumType.GRANITE)).size(settings.graniteSize).perChunk(settings.graniteCount).height(VariableAmount.baseWithRandomAddition(settings.graniteMinHeight, settings.graniteMaxHeight - settings.graniteMinHeight)).build();
gensettings.getPopulators().add(granite);
Ore andesite = Ore.builder().ore((BlockState) Blocks.STONE.getDefaultState().withProperty(BlockStone.VARIANT, BlockStone.EnumType.ANDESITE)).size(settings.andesiteSize).perChunk(settings.andesiteCount).height(VariableAmount.baseWithRandomAddition(settings.andesiteMinHeight, settings.andesiteMaxHeight - settings.andesiteMinHeight)).build();
gensettings.getPopulators().add(andesite);
Ore coal = Ore.builder().ore((BlockState) Blocks.COAL_ORE.getDefaultState()).size(settings.coalSize).perChunk(settings.coalCount).height(VariableAmount.baseWithRandomAddition(settings.coalMinHeight, settings.coalMaxHeight - settings.coalMinHeight)).build();
gensettings.getPopulators().add(coal);
Ore iron = Ore.builder().ore((BlockState) Blocks.IRON_ORE.getDefaultState()).size(settings.ironSize).perChunk(settings.ironCount).height(VariableAmount.baseWithRandomAddition(settings.ironMinHeight, settings.ironMaxHeight - settings.ironMinHeight)).build();
gensettings.getPopulators().add(iron);
Ore gold = Ore.builder().ore((BlockState) Blocks.GOLD_ORE.getDefaultState()).size(settings.goldSize).perChunk(settings.goldCount).height(VariableAmount.baseWithRandomAddition(settings.goldMinHeight, settings.goldMaxHeight - settings.goldMinHeight)).build();
gensettings.getPopulators().add(gold);
Ore redstone = Ore.builder().ore((BlockState) Blocks.REDSTONE_ORE.getDefaultState()).size(settings.redstoneSize).perChunk(settings.redstoneCount).height(VariableAmount.baseWithRandomAddition(settings.redstoneMinHeight, settings.redstoneMaxHeight - settings.redstoneMinHeight)).build();
gensettings.getPopulators().add(redstone);
Ore diamond = Ore.builder().ore((BlockState) Blocks.DIAMOND_ORE.getDefaultState()).size(settings.diamondSize).perChunk(settings.diamondCount).height(VariableAmount.baseWithRandomAddition(settings.diamondMinHeight, settings.diamondMaxHeight - settings.diamondMinHeight)).build();
gensettings.getPopulators().add(diamond);
Ore lapis = Ore.builder().ore((BlockState) Blocks.LAPIS_ORE.getDefaultState()).size(settings.lapisSize).perChunk(settings.lapisCount).height(VariableAmount.baseWithVariance(settings.lapisCenterHeight, settings.lapisSpread)).build();
gensettings.getPopulators().add(lapis);
if (theBiomeDecorator.sandPatchesPerChunk > 0) {
SeaFloor sand = SeaFloor.builder().block((BlockState) Blocks.SAND.getDefaultState()).radius(VariableAmount.baseWithRandomAddition(2, 5)).depth(2).perChunk(theBiomeDecorator.sandPatchesPerChunk).replace(WorldGenConstants.DIRT_OR_GRASS).build();
gensettings.getPopulators().add(sand);
}
if (theBiomeDecorator.clayPerChunk > 0) {
SeaFloor clay = SeaFloor.builder().block((BlockState) Blocks.CLAY.getDefaultState()).radius(VariableAmount.baseWithRandomAddition(2, 2)).depth(1).perChunk(theBiomeDecorator.clayPerChunk).replace(WorldGenConstants.DIRT).build();
gensettings.getPopulators().add(clay);
}
if (theBiomeDecorator.gravelPatchesPerChunk > 0) {
SeaFloor gravelSeaFloor = SeaFloor.builder().block((BlockState) Blocks.GRAVEL.getDefaultState()).radius(VariableAmount.baseWithRandomAddition(2, 4)).depth(2).perChunk(theBiomeDecorator.gravelPatchesPerChunk).replace(WorldGenConstants.DIRT_OR_GRASS).build();
gensettings.getPopulators().add(gravelSeaFloor);
}
Forest forest = Forest.builder().type(BiomeTreeTypes.OAK.getPopulatorObject(), 9).type(BiomeTreeTypes.OAK.getLargePopulatorObject().get(), 1).perChunk(VariableAmount.baseWithOptionalAddition(theBiomeDecorator.treesPerChunk, 1, 0.1)).build();
gensettings.getPopulators().add(forest);
if (theBiomeDecorator.bigMushroomsPerChunk > 0) {
BigMushroom mushroom = BigMushroom.builder().mushroomsPerChunk(theBiomeDecorator.bigMushroomsPerChunk).type(MushroomTypes.BROWN.getPopulatorObject(), 1).type(MushroomTypes.RED.getPopulatorObject(), 1).build();
gensettings.getPopulators().add(mushroom);
}
if (theBiomeDecorator.flowersPerChunk > 0) {
Flower flower = Flower.builder().perChunk(theBiomeDecorator.flowersPerChunk * 64).type(PlantTypes.DANDELION, 2).type(PlantTypes.POPPY, 1).build();
gensettings.getPopulators().add(flower);
}
if (theBiomeDecorator.grassPerChunk > 0) {
Shrub grass = Shrub.builder().perChunk(theBiomeDecorator.grassPerChunk * 128).type(ShrubTypes.TALL_GRASS, 1).build();
gensettings.getPopulators().add(grass);
}
if (theBiomeDecorator.deadBushPerChunk > 0) {
DeadBush deadBush = DeadBush.builder().perChunk(theBiomeDecorator.deadBushPerChunk).build();
gensettings.getPopulators().add(deadBush);
}
if (theBiomeDecorator.waterlilyPerChunk > 0) {
WaterLily waterLily = WaterLily.builder().perChunk(theBiomeDecorator.waterlilyPerChunk * 10).build();
gensettings.getPopulators().add(waterLily);
}
ChanceTable<MushroomType> types = new ChanceTable<MushroomType>();
types.add(new WeightedObject<>(MushroomTypes.BROWN, 2));
types.add(new WeightedObject<>(MushroomTypes.RED, 1));
types.add(new EmptyObject<>(5));
Mushroom smallMushroom = Mushroom.builder().types(types).mushroomsPerChunk(theBiomeDecorator.mushroomsPerChunk + 1).build();
gensettings.getPopulators().add(smallMushroom);
Reed reed = Reed.builder().perChunk(theBiomeDecorator.reedsPerChunk + 10).reedHeight(VariableAmount.baseWithRandomAddition(2, VariableAmount.baseWithRandomAddition(1, 3))).build();
gensettings.getPopulators().add(reed);
Pumpkin pumpkin = Pumpkin.builder().perChunk(64).chance(1 / 32d).build();
gensettings.getPopulators().add(pumpkin);
if (theBiomeDecorator.cactiPerChunk > 0) {
Cactus cactus = Cactus.builder().cactiPerChunk(VariableAmount.baseWithOptionalAddition(0, VariableAmount.baseWithRandomAddition(1, VariableAmount.baseWithOptionalAddition(2, 3, 0.5)), 0.8)).build();
gensettings.getPopulators().add(cactus);
}
if (theBiomeDecorator.generateFalls) {
RandomBlock water = RandomBlock.builder().block((BlockState) Blocks.FLOWING_WATER.getDefaultState()).height(VariableAmount.baseWithRandomAddition(0, VariableAmount.baseWithRandomAddition(8, 248))).perChunk(50).placementTarget(WorldGenConstants.CAVE_LIQUIDS).build();
gensettings.getPopulators().add(water);
RandomBlock lava = RandomBlock.builder().block((BlockState) Blocks.FLOWING_LAVA.getDefaultState()).height(VariableAmount.baseWithRandomAddition(0, VariableAmount.baseWithRandomAddition(8, VariableAmount.baseWithRandomAddition(8, 240)))).perChunk(20).placementTarget(WorldGenConstants.CAVE_LIQUIDS).build();
gensettings.getPopulators().add(lava);
}
}
use of org.spongepowered.api.util.weighted.ChanceTable in project SpongeCommon by SpongePowered.
the class ItemStackData method register.
// @formatter:off
public static void register(final DataProviderRegistrator registrator) {
registrator.asMutable(ItemStack.class).create(Keys.APPLICABLE_POTION_EFFECTS).get(h -> {
if (h.isEdible()) {
final List<Pair<MobEffectInstance, Float>> itemEffects = h.getItem().getFoodProperties().getEffects();
final WeightedTable<PotionEffect> effects = new WeightedTable<>();
final ChanceTable<PotionEffect> chance = new ChanceTable<>();
for (final Pair<MobEffectInstance, Float> effect : itemEffects) {
chance.add((PotionEffect) effect.getFirst(), effect.getSecond());
}
effects.add(new NestedTableEntry<>(1, chance));
return effects;
}
return null;
}).create(Keys.BURN_TIME).get(h -> {
final Integer burnTime = AbstractFurnaceBlockEntity.getFuel().get(h.getItem());
if (burnTime != null && burnTime > 0) {
return burnTime;
}
return null;
}).create(Keys.CAN_HARVEST).get(h -> {
final Item item = h.getItem();
if (item instanceof DiggerItemAccessor && !(item instanceof PickaxeItem)) {
final Set<Block> blocks = ((DiggerItemAccessor) item).accessor$blocks();
return ImmutableSet.copyOf((Set<BlockType>) (Object) blocks);
}
final Set<BlockType> blockTypes = Registry.BLOCK.stream().filter(b -> item.isCorrectToolForDrops(b.defaultBlockState())).map(BlockType.class::cast).collect(ImmutableSet.toImmutableSet());
return blockTypes.isEmpty() ? null : blockTypes;
}).create(Keys.CONTAINER_ITEM).get(h -> (ItemType) h.getItem().getCraftingRemainingItem()).create(Keys.DISPLAY_NAME).get(h -> SpongeAdventure.asAdventure(h.getDisplayName())).create(Keys.CUSTOM_MODEL_DATA).get(h -> {
final CompoundTag tag = h.getTag();
if (tag == null || !tag.contains(Constants.Item.CUSTOM_MODEL_DATA, Constants.NBT.TAG_INT)) {
return null;
}
return tag.getInt(Constants.Item.CUSTOM_MODEL_DATA);
}).set((h, v) -> {
final CompoundTag tag = h.getOrCreateTag();
tag.putInt(Constants.Item.CUSTOM_MODEL_DATA, v);
}).delete(h -> {
final CompoundTag tag = h.getTag();
if (tag != null) {
tag.remove(Constants.Item.CUSTOM_MODEL_DATA);
}
}).create(Keys.CUSTOM_NAME).get(h -> {
if (h.hasCustomHoverName()) {
return SpongeAdventure.asAdventure(h.getHoverName());
}
if (h.getItem() == Items.WRITTEN_BOOK) {
// When no custom name is set on a written book fallback to its title
// The custom name has a higher priority than the title so no setter is needed.
final CompoundTag tag = h.getTag();
if (tag != null) {
final String title = tag.getString(Constants.Item.Book.ITEM_BOOK_TITLE);
return LegacyComponentSerializer.legacySection().deserialize(title);
}
}
return null;
}).set((h, v) -> h.setHoverName(SpongeAdventure.asVanilla(v))).delete(ItemStack::resetHoverName).create(Keys.IS_UNBREAKABLE).get(h -> {
final CompoundTag tag = h.getTag();
if (tag == null || !tag.contains(Constants.Item.ITEM_UNBREAKABLE, Constants.NBT.TAG_BYTE)) {
return false;
}
return tag.getBoolean(Constants.Item.ITEM_UNBREAKABLE);
}).set(ItemStackData::setIsUnbrekable).delete(h -> ItemStackData.setIsUnbrekable(h, false)).create(Keys.LORE).get(h -> {
final CompoundTag tag = h.getTag();
if (tag == null || !tag.contains(Constants.Item.ITEM_DISPLAY)) {
return null;
}
final CompoundTag displayCompound = tag.getCompound(Constants.Item.ITEM_DISPLAY);
final ListTag list = displayCompound.getList(Constants.Item.ITEM_LORE, Constants.NBT.TAG_STRING);
return list.isEmpty() ? null : SpongeAdventure.json(list.stream().collect(NBTCollectors.toStringList()));
}).set((h, v) -> {
if (v.isEmpty()) {
ItemStackData.deleteLore(h);
return;
}
final ListTag list = SpongeAdventure.listTagJson(v);
h.getOrCreateTagElement(Constants.Item.ITEM_DISPLAY).put(Constants.Item.ITEM_LORE, list);
}).delete(ItemStackData::deleteLore).create(Keys.MAX_DURABILITY).get(h -> h.getItem().canBeDepleted() ? h.getItem().getMaxDamage() : null).supports(h -> h.getItem().canBeDepleted()).create(Keys.ITEM_DURABILITY).get(stack -> stack.getMaxDamage() - stack.getDamageValue()).set((stack, durability) -> stack.setDamageValue(stack.getMaxDamage() - durability)).supports(h -> h.getItem().canBeDepleted()).create(Keys.ITEM_RARITY).get(stack -> (ItemRarity) (Object) stack.getRarity()).create(Keys.REPLENISHED_FOOD).get(h -> {
if (h.getItem().isEdible()) {
final FoodProperties food = h.getItem().getFoodProperties();
return food == null ? null : food.getNutrition();
}
return null;
}).supports(h -> h.getItem().isEdible()).create(Keys.REPLENISHED_SATURATION).get(h -> {
if (h.getItem().isEdible()) {
final FoodProperties food = h.getItem().getFoodProperties();
if (food != null) {
// Translate's Minecraft's weird internal value to the actual saturation value
return food.getSaturationModifier() * food.getNutrition() * 2.0;
}
}
return null;
}).supports(h -> h.getItem().isEdible());
}
use of org.spongepowered.api.util.weighted.ChanceTable in project SpongeCommon by SpongePowered.
the class MixinBiomeHell method buildPopulators.
@Override
public void buildPopulators(World world, SpongeBiomeGenerationSettings gensettings) {
RandomBlock lava1 = RandomBlock.builder().block((BlockState) Blocks.FLOWING_LAVA.getDefaultState()).perChunk(8).height(VariableAmount.baseWithRandomAddition(4, 120)).placementTarget(WorldGenConstants.HELL_LAVA).build();
gensettings.getPopulators().add(lava1);
NetherFire fire = NetherFire.builder().perChunk(VariableAmount.baseWithRandomAddition(1, VariableAmount.baseWithRandomAddition(1, 10))).perCluster(64).build();
gensettings.getPopulators().add(fire);
Glowstone glowstone1 = Glowstone.builder().blocksPerCluster(1500).clusterHeight(VariableAmount.baseWithRandomAddition(-11, 12)).perChunk(VariableAmount.baseWithRandomAddition(0, VariableAmount.baseWithRandomAddition(1, 10))).height(VariableAmount.baseWithRandomAddition(4, 120)).build();
gensettings.getPopulators().add(glowstone1);
Glowstone glowstone2 = Glowstone.builder().blocksPerCluster(1500).clusterHeight(VariableAmount.baseWithRandomAddition(0, 12)).perChunk(10).height(VariableAmount.baseWithRandomAddition(0, 128)).build();
gensettings.getPopulators().add(glowstone2);
ChanceTable<MushroomType> types = new ChanceTable<>();
types.add(new WeightedObject<>(MushroomTypes.BROWN, 1));
types.add(new EmptyObject<>(1));
HellMushroomPopulator smallMushroom = new HellMushroomPopulator();
smallMushroom.setMushroomsPerChunk(1);
smallMushroom.getTypes().addAll(types);
gensettings.getPopulators().add(smallMushroom);
ChanceTable<MushroomType> types2 = new ChanceTable<>();
types.add(new WeightedObject<>(MushroomTypes.RED, 1));
types.add(new EmptyObject<>(1));
HellMushroomPopulator smallMushroom2 = new HellMushroomPopulator();
smallMushroom2.setMushroomsPerChunk(1);
smallMushroom2.getTypes().addAll(types2);
gensettings.getPopulators().add(smallMushroom2);
Ore quartz = Ore.builder().height(VariableAmount.baseWithRandomAddition(10, 108)).ore(BlockTypes.QUARTZ_ORE.getDefaultState()).perChunk(16).placementCondition((o) -> o != null && o.getType() == BlockTypes.NETHERRACK).size(14).build();
gensettings.getPopulators().add(quartz);
int halfSeaLevel = world.getSeaLevel() / 2 + 1;
Ore magma = Ore.builder().height(VariableAmount.baseWithRandomAddition(halfSeaLevel - 5, 10)).ore(BlockTypes.MAGMA.getDefaultState()).perChunk(4).placementCondition((o) -> o != null && o.getType() == BlockTypes.NETHERRACK).size(33).build();
gensettings.getPopulators().add(magma);
RandomBlock lava2 = RandomBlock.builder().block((BlockState) Blocks.FLOWING_LAVA.getDefaultState()).perChunk(16).height(VariableAmount.baseWithRandomAddition(10, 108)).placementTarget(WorldGenConstants.HELL_LAVA_ENCLOSED).build();
gensettings.getPopulators().add(lava2);
}
Aggregations