Search in sources :

Example 11 with Holder

use of net.minecraft.core.Holder in project Botania by VazkiiMods.

the class ContributorList method load.

private static void load(Properties props) {
    Map<String, ItemStack> m = new HashMap<>();
    Map<Item, ItemStack> cachedStacks = new HashMap<>();
    for (String key : props.stringPropertyNames()) {
        String value = props.getProperty(key);
        ItemStack stack;
        try {
            int i = Integer.parseInt(value);
            if (i < 0 || i >= 16) {
                throw new NumberFormatException();
            }
            stack = cachedStacks.computeIfAbsent(ModBlocks.getFlower(DyeColor.byId(i)).asItem(), ContributorList::configureStack);
        } catch (NumberFormatException e) {
            String rawName = value.toLowerCase(Locale.ROOT);
            String flowerName = LEGACY_FLOWER_NAMES.getOrDefault(rawName, rawName);
            var item = StreamSupport.stream(Registry.ITEM.getTagOrEmpty(ModTags.Items.CONTRIBUTOR_HEADFLOWERS).spliterator(), false).filter(h -> h.is(resKey -> resKey.location().getPath().equals(flowerName))).findFirst().map(Holder::value).orElse(Items.POPPY);
            stack = cachedStacks.computeIfAbsent(item, ContributorList::configureStack);
        }
        m.put(key, stack);
    }
    flowerMap = m;
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) Enchantment(net.minecraft.world.item.enchantment.Enchantment) DyeColor(net.minecraft.world.item.DyeColor) Items(net.minecraft.world.item.Items) URL(java.net.URL) Item(net.minecraft.world.item.Item) DefaultUncaughtExceptionHandler(net.minecraft.DefaultUncaughtExceptionHandler) HashMap(java.util.HashMap) Registry(net.minecraft.core.Registry) Holder(net.minecraft.core.Holder) EnchantmentHelper(net.minecraft.world.item.enchantment.EnchantmentHelper) Locale(java.util.Locale) Map(java.util.Map) BotaniaAPI(vazkii.botania.api.BotaniaAPI) StreamSupport(java.util.stream.StreamSupport) Enchantments(net.minecraft.world.item.enchantment.Enchantments) Properties(java.util.Properties) ImmutableMap(com.google.common.collect.ImmutableMap) LibBlockNames(vazkii.botania.common.lib.LibBlockNames) IOException(java.io.IOException) ModBlocks(vazkii.botania.common.block.ModBlocks) InputStreamReader(java.io.InputStreamReader) StandardCharsets(java.nio.charset.StandardCharsets) ItemStack(net.minecraft.world.item.ItemStack) Collections(java.util.Collections) ModTags(vazkii.botania.common.lib.ModTags) Item(net.minecraft.world.item.Item) HashMap(java.util.HashMap) Holder(net.minecraft.core.Holder) ItemStack(net.minecraft.world.item.ItemStack)

Example 12 with Holder

use of net.minecraft.core.Holder in project Cyclic by Lothrazar.

the class EnderApple method finishUsingItem.

@Override
public ItemStack finishUsingItem(ItemStack stack, Level worldIn, LivingEntity entityLiving) {
    if (entityLiving instanceof Player == false) {
        return super.finishUsingItem(stack, worldIn, entityLiving);
    }
    Player player = (Player) entityLiving;
    if (player.getCooldowns().isOnCooldown(this)) {
        return super.finishUsingItem(stack, worldIn, entityLiving);
    }
    player.getCooldowns().addCooldown(this, COOLDOWN);
    if (worldIn instanceof ServerLevel) {
        final List<String> structIgnoreList = Arrays.asList(ignoreMe);
        // 
        ServerLevel serverWorld = (ServerLevel) worldIn;
        Map<String, Integer> distanceStructNames = new HashMap<>();
        Registry<ConfiguredStructureFeature<?, ?>> registry = worldIn.registryAccess().registryOrThrow(Registry.CONFIGURED_STRUCTURE_FEATURE_REGISTRY);
        // registry.getho
        IdMap<Holder<ConfiguredStructureFeature<?, ?>>> idmap = registry.asHolderIdMap();
        idmap.forEach(structureFeature -> {
            // is of type  Holder<ConfiguredStructureFeature<?, ?>>
            try {
                String name = structureFeature.value().feature.getRegistryName().toString();
                if (!structIgnoreList.contains(name)) {
                    // then we are allowed to look fori t, we are not in ignore list
                    BlockPos targetPos = entityLiving.blockPosition();
                    // LocateCommand y;
                    HolderSet<ConfiguredStructureFeature<?, ?>> holderSetOfFeature = HolderSet.direct(structureFeature);
                    Pair<BlockPos, Holder<ConfiguredStructureFeature<?, ?>>> searchResult = serverWorld.getChunkSource().getGenerator().findNearestMapFeature(serverWorld, holderSetOfFeature, targetPos, 100, false);
                    if (searchResult != null && searchResult.getFirst() != null) {
                        double distance = UtilWorld.distanceBetweenHorizontal(searchResult.getFirst(), targetPos);
                        distanceStructNames.put(name, (int) distance);
                    }
                }
            } catch (Exception e) {
                ModCyclic.LOGGER.error("", e);
            }
        });
        // for(int i=0;i<registry.asHolderIdMap().size();i++){
        // Holder<ConfiguredStructureFeature<?, ?>> thing = registry.asHolderIdMap().byId(i);
        // }
        // for (ConfiguredStructureFeature<?,?> structureFeature : registry){  //net.minecraftforge.registries.ForgeRegistries.STRUCTURE_FEATURES) {
        // 
        // }
        // done loopiong on features
        // 
        // SORT
        LinkedHashMap<String, Integer> sortedMap = new LinkedHashMap<>();
        distanceStructNames.entrySet().stream().sorted(Map.Entry.comparingByValue()).forEachOrdered(x -> sortedMap.put(x.getKey(), x.getValue()));
        // 
        // ModCyclic.LOGGER.info("Sorted Map   : " + sortedMap);
        int count = 0;
        // UtilChat.addServerChatMessage(player, "STARRT");
        for (Map.Entry<String, Integer> e : sortedMap.entrySet()) {
            UtilChat.addServerChatMessage(player, e.getValue() + "m | " + e.getKey());
            count++;
            // ?? is it sorted
            if (count >= NUM_PRINTED) {
                break;
            }
        }
    // 
    // String name = regName.replace("minecraft:", "");
    // literalargumentbuilder = literalargumentbuilder.then(Commands.literal(name)
    // .executes(ctx -> locate(ctx.getSource(), structureFeature)));
    // collections CUSTOM SORT by distance
    // 
    }
    return super.finishUsingItem(stack, worldIn, entityLiving);
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) Player(net.minecraft.world.entity.player.Player) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Holder(net.minecraft.core.Holder) LinkedHashMap(java.util.LinkedHashMap) ConfiguredStructureFeature(net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature) BlockPos(net.minecraft.core.BlockPos) IdMap(net.minecraft.core.IdMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 13 with Holder

use of net.minecraft.core.Holder in project blueprint by team-abnormals.

the class BiomeSourceModificationManager method onServerAboutToStart.

@SuppressWarnings("unchecked")
@SubscribeEvent
public static void onServerAboutToStart(ServerAboutToStartEvent event) {
    if (INSTANCE == null)
        return;
    List<BiomeSourceModifier> modifiers = INSTANCE.modifiers;
    if (modifiers.isEmpty())
        return;
    MinecraftServer server = event.getServer();
    WorldGenSettings worldGenSettings = server.getWorldData().worldGenSettings();
    var dimensions = worldGenSettings.dimensions();
    var keySet = dimensions.keySet();
    SelectionSpace selectionSpace = (consumer) -> keySet.forEach(location -> consumer.accept(location, null));
    HashMap<ResourceLocation, ArrayList<BiomeUtil.ModdedBiomeProvider>> map = new HashMap<>();
    for (BiomeSourceModifier modifier : modifiers) {
        BiomeUtil.ModdedBiomeProvider provider = modifier.provider();
        if (provider.getWeight() <= 0)
            return;
        modifier.targetSelector().getTargetNames(selectionSpace).forEach(location -> {
            map.computeIfAbsent(location, __ -> new ArrayList<>()).add(provider);
        });
    }
    long seed = worldGenSettings.seed();
    RegistryAccess registryAccess = server.registryAccess();
    Registry<Biome> biomeRegistry = registryAccess.registryOrThrow(Registry.BIOME_REGISTRY);
    Registry<NormalNoise.NoiseParameters> noiseParametersRegistry = registryAccess.registryOrThrow(Registry.NOISE_REGISTRY);
    Registry<DensityFunction> densityFunctionRegistry = registryAccess.registryOrThrow(Registry.DENSITY_FUNCTION_REGISTRY);
    NoiseSettings defaultNoiseSettings = registryAccess.registryOrThrow(Registry.NOISE_GENERATOR_SETTINGS_REGISTRY).getOrThrow(NoiseGeneratorSettings.OVERWORLD).noiseSettings();
    DensityFunction defaultModdedness = densityFunctionRegistry.getOrThrow(ModdedBiomeSource.DEFAULT_MODDEDNESS);
    for (Map.Entry<ResourceKey<LevelStem>, LevelStem> entry : dimensions.entrySet()) {
        ResourceLocation location = entry.getKey().location();
        ArrayList<BiomeUtil.ModdedBiomeProvider> providersForKey = map.get(location);
        if (providersForKey != null && !providersForKey.isEmpty()) {
            ChunkGenerator chunkGenerator = entry.getValue().generator();
            BiomeSource source = chunkGenerator.getBiomeSource();
            // TODO: Mostly experimental! Works with Terralith, Biomes O' Plenty, and more, but still needs more testing!
            if (!(source instanceof FixedBiomeSource) && !(source instanceof CheckerboardColumnBiomeSource)) {
                boolean legacy = false;
                boolean noiseBased = chunkGenerator instanceof NoiseBasedChunkGenerator;
                NoiseSettings noiseSettings = defaultNoiseSettings;
                if (noiseBased) {
                    try {
                        NoiseGeneratorSettings settings = ((Holder<NoiseGeneratorSettings>) NOISE_GENERATOR_SETTINGS.get(chunkGenerator)).value();
                        if (settings != null) {
                            legacy = settings.useLegacyRandomSource();
                            noiseSettings = settings.noiseSettings();
                        }
                    } catch (IllegalAccessException ignored) {
                    }
                }
                DensityFunction moddedness = densityFunctionRegistry.get(new ResourceLocation(Blueprint.MOD_ID, "moddedness/" + location.getNamespace() + "/" + location.getPath()));
                ModdedBiomeSource moddedBiomeSource = new ModdedBiomeSource(biomeRegistry, noiseParametersRegistry, densityFunctionRegistry, source, noiseSettings, seed, legacy, moddedness != null ? moddedness : defaultModdedness, new ModdedBiomeSource.WeightedBiomeSlices(providersForKey.toArray(new BiomeUtil.ModdedBiomeProvider[0])));
                chunkGenerator.biomeSource = moddedBiomeSource;
                chunkGenerator.runtimeBiomeSource = moddedBiomeSource;
                if (noiseBased)
                    ((ModdedSurfaceSystem) ((NoiseBasedChunkGenerator) chunkGenerator).surfaceSystem).setModdedBiomeSource(moddedBiomeSource);
            }
        }
    }
}
Also used : JsonParseException(com.google.gson.JsonParseException) SelectionSpace(com.teamabnormals.blueprint.core.util.modification.targeting.SelectionSpace) ResourceLocation(net.minecraft.resources.ResourceLocation) BiomeSource(net.minecraft.world.level.biome.BiomeSource) HashMap(java.util.HashMap) Biome(net.minecraft.world.level.biome.Biome) AddReloadListenerEvent(net.minecraftforge.event.AddReloadListenerEvent) ArrayList(java.util.ArrayList) JsonElement(com.google.gson.JsonElement) Registry(net.minecraft.core.Registry) FixedBiomeSource(net.minecraft.world.level.biome.FixedBiomeSource) NormalNoise(net.minecraft.world.level.levelgen.synth.NormalNoise) ObfuscationReflectionHelper(net.minecraftforge.fml.util.ObfuscationReflectionHelper) MinecraftServer(net.minecraft.server.MinecraftServer) Holder(net.minecraft.core.Holder) SimpleJsonResourceReloadListener(net.minecraft.server.packs.resources.SimpleJsonResourceReloadListener) Gson(com.google.gson.Gson) Map(java.util.Map) Mod(net.minecraftforge.fml.common.Mod) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent) DataUtil(com.teamabnormals.blueprint.core.util.DataUtil) ServerAboutToStartEvent(net.minecraftforge.event.server.ServerAboutToStartEvent) LinkedList(java.util.LinkedList) RegistryOps(net.minecraft.resources.RegistryOps) ProfilerFiller(net.minecraft.util.profiling.ProfilerFiller) net.minecraft.world.level.levelgen(net.minecraft.world.level.levelgen) ResourceManager(net.minecraft.server.packs.resources.ResourceManager) RegistryAccess(net.minecraft.core.RegistryAccess) Field(java.lang.reflect.Field) BiomeUtil(com.teamabnormals.blueprint.core.util.BiomeUtil) ResourceKey(net.minecraft.resources.ResourceKey) Blueprint(com.teamabnormals.blueprint.core.Blueprint) ChunkGenerator(net.minecraft.world.level.chunk.ChunkGenerator) List(java.util.List) CheckerboardColumnBiomeSource(net.minecraft.world.level.biome.CheckerboardColumnBiomeSource) LevelStem(net.minecraft.world.level.dimension.LevelStem) HashMap(java.util.HashMap) RegistryAccess(net.minecraft.core.RegistryAccess) ArrayList(java.util.ArrayList) Biome(net.minecraft.world.level.biome.Biome) ResourceLocation(net.minecraft.resources.ResourceLocation) BiomeSource(net.minecraft.world.level.biome.BiomeSource) FixedBiomeSource(net.minecraft.world.level.biome.FixedBiomeSource) CheckerboardColumnBiomeSource(net.minecraft.world.level.biome.CheckerboardColumnBiomeSource) SelectionSpace(com.teamabnormals.blueprint.core.util.modification.targeting.SelectionSpace) Holder(net.minecraft.core.Holder) BiomeUtil(com.teamabnormals.blueprint.core.util.BiomeUtil) CheckerboardColumnBiomeSource(net.minecraft.world.level.biome.CheckerboardColumnBiomeSource) MinecraftServer(net.minecraft.server.MinecraftServer) ResourceKey(net.minecraft.resources.ResourceKey) LevelStem(net.minecraft.world.level.dimension.LevelStem) ChunkGenerator(net.minecraft.world.level.chunk.ChunkGenerator) HashMap(java.util.HashMap) Map(java.util.Map) FixedBiomeSource(net.minecraft.world.level.biome.FixedBiomeSource) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 14 with Holder

use of net.minecraft.core.Holder in project Mohist by MohistMC.

the class CraftChunkSnapshot method getRawBiomeTemperature.

@Override
public final double getRawBiomeTemperature(int x, int y, int z) {
    Preconditions.checkState(biome != null, "ChunkSnapshot created without biome. Please call getSnapshot with includeBiome=true");
    validateChunkCoordinates(x, y, z);
    PalettedContainer<Holder<net.minecraft.world.level.biome.Biome>> biome = this.biome[getSectionIndex(y >> 2)];
    return biome.get(x >> 2, (y & 0xF) >> 2, z >> 2).value().getTemperature(new BlockPos((this.x << 4) | x, y, (this.z << 4) | z));
}
Also used : Holder(net.minecraft.core.Holder) BlockPos(net.minecraft.core.BlockPos)

Example 15 with Holder

use of net.minecraft.core.Holder in project Denizen-For-Bukkit by DenizenScript.

the class ChunkHelperImpl method setAllBiomes.

@Override
public void setAllBiomes(Chunk chunk, BiomeNMS biome) {
    Holder<Biome> nmsBiome = ((BiomeNMSImpl) biome).biomeBase;
    LevelChunk nmsChunk = ((CraftChunk) chunk).getHandle();
    ChunkPos chunkcoordintpair = nmsChunk.getPos();
    int i = QuartPos.fromBlock(chunkcoordintpair.getMinBlockX());
    int j = QuartPos.fromBlock(chunkcoordintpair.getMinBlockZ());
    LevelHeightAccessor levelheightaccessor = nmsChunk.getHeightAccessorForGeneration();
    for (int k = levelheightaccessor.getMinSection(); k < levelheightaccessor.getMaxSection(); ++k) {
        LevelChunkSection chunksection = nmsChunk.getSection(nmsChunk.getSectionIndexFromSectionY(k));
        PalettedContainer<Holder<Biome>> datapaletteblock = chunksection.getBiomes();
        datapaletteblock.acquire();
        for (int l = 0; l < 4; ++l) {
            for (int i1 = 0; i1 < 4; ++i1) {
                for (int j1 = 0; j1 < 4; ++j1) {
                    datapaletteblock.getAndSetUnchecked(l, i1, j1, nmsBiome);
                }
            }
        }
        datapaletteblock.release();
    }
}
Also used : LevelHeightAccessor(net.minecraft.world.level.LevelHeightAccessor) Biome(net.minecraft.world.level.biome.Biome) LevelChunk(net.minecraft.world.level.chunk.LevelChunk) LevelChunkSection(net.minecraft.world.level.chunk.LevelChunkSection) Holder(net.minecraft.core.Holder) ChunkPos(net.minecraft.world.level.ChunkPos) CraftChunk(org.bukkit.craftbukkit.v1_18_R2.CraftChunk) BiomeNMSImpl(com.denizenscript.denizen.nms.v1_18.impl.BiomeNMSImpl)

Aggregations

Holder (net.minecraft.core.Holder)19 BlockPos (net.minecraft.core.BlockPos)10 Biome (net.minecraft.world.level.biome.Biome)9 ArrayList (java.util.ArrayList)5 ChunkPos (net.minecraft.world.level.ChunkPos)5 Random (java.util.Random)4 Registry (net.minecraft.core.Registry)4 LevelChunk (net.minecraft.world.level.chunk.LevelChunk)4 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 ResourceLocation (net.minecraft.resources.ResourceLocation)3 LevelHeightAccessor (net.minecraft.world.level.LevelHeightAccessor)3 BlockState (net.minecraft.world.level.block.state.BlockState)3 LevelChunkSection (net.minecraft.world.level.chunk.LevelChunkSection)3 BiomeNMSImpl (com.denizenscript.denizen.nms.v1_18.impl.BiomeNMSImpl)2 Codec (com.mojang.serialization.Codec)2 Collections (java.util.Collections)2 Direction (net.minecraft.core.Direction)2 ResourceKey (net.minecraft.resources.ResourceKey)2