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