mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-22 13:09:59 +00:00
Forge 1.19
* Bump pack.mcmeta formats * 1.19 biome modifiers * Mark ClientPlayerNetworkEvent.LoggedOutEvent's getters as nullable * Add docs and package-info to client extension interfaces package * Move RenderBlockOverlayEvent hooks to ForgeHooksClient * Add package-infos to client events package * Rename SoundLoadEvent to SoundEngineLoadEvent This reduces confusion from consumers which may think the name SoundLoadEvent refers to an individual sound being loaded rather than the sound engine. * Document and change SoundLoadEvent to fire on mod bus Previously, it fired on both the mod bus and the Forge bus, which is confusing for consumers. * Delete SoundSetupEvent Looking at its original implementation shows that there isn't an appropriate place in the new sound code to reinsert the event, and the place of 'sound engine/manager initialization event' is taken already by SoundLoadEvent. * Perform some cleanup on client events - Removed nullable annotations from ClientPlayerNetworkEvent - Renamed #getPartialTicks methods to #getPartialTick, to be consistent with vanilla's naming of the partial tick - Cleanup documentation to remove line breaks, use the spelling 'cancelled' over 'canceled', and improve docs on existing and new methods. * Remove EntityEvent.CanUpdate Closes MinecraftForge/MinecraftForge#6394 * Switch to Jetbrains nullability annotations * New PlayLevelSoundEvent; replaces old PlaySoundAtEntityEvent * Remove ForgeWorldPresetScreens * Remove IForgeRegistryEntry * Remove use of List<Throwable> in FML's CompletableFutures * Add docs to mod loading stages, stages, and phases * Gradle 7.4.2 * Use SLF4J in FMLLoader and other subprojects * Switch dynamic versions in subprojects to pinned ones * Switch ForgeRoot and MDK to FG plugin markers * Configure Forge javadoc task The task now uses a custom stylesheet with MCForge elements, and configured to combine the generation from the four FML subprojects (fmlloader, fmlcore, javafmllanguage, mclanguage) and the Forge project into the javadoc output. * Update docs/md files, for 1.19 update and the move away from IRC to Discord. * Make "Potentially dangerous alternative prefix" a debug warning, not info. Co-authored-by: Curle <[email protected]> Co-authored-by: sciwhiz12 <[email protected]> Signed-off-by: SizableShrimp <[email protected]>
This commit is contained in:
1 parent
270e778ac5
commit
4ed9117799
1485 files changed
+14960
-15446
No files matched your search
@@ -5,10 +5,7 @@
|
||||
|
||||
package net.minecraftforge.common;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.npc.VillagerTrades.ItemListing;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
@@ -54,11 +51,9 @@ public class BasicItemListing implements ItemListing
|
||||
this(new ItemStack(Items.EMERALD, emeralds), forSale, maxTrades, xp, 1);
|
||||
}
|
||||
|
||||
@org.jetbrains.annotations.Nullable
|
||||
@Override
|
||||
@Nullable
|
||||
public MerchantOffer getOffer(Entity merchant, Random rand)
|
||||
{
|
||||
public MerchantOffer getOffer(Entity p_219693_, RandomSource p_219694_) {
|
||||
return new MerchantOffer(price, price2, forSale, maxTrades, xp, priceMult);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,389 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraftforge.event.world.BiomeLoadingEvent;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import net.minecraft.world.level.biome.Biomes;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.core.Registry;
|
||||
import static net.minecraftforge.common.BiomeDictionary.Type.*;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
|
||||
/**
|
||||
* Use {@link Tags.Biomes} when possible.
|
||||
* Note that tags are not usable yet during {@link BiomeLoadingEvent} so BiomeDictionary are still necessary there
|
||||
*/
|
||||
@Deprecated
|
||||
public class BiomeDictionary
|
||||
{
|
||||
private static final boolean DEBUG = false;
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
public static final class Type
|
||||
{
|
||||
private static final Map<String, Type> byName = new ConcurrentHashMap<>();
|
||||
private static Collection<Type> allTypes = Collections.unmodifiableCollection(byName.values());
|
||||
|
||||
/*Temperature-based tags. Specifying neither implies a biome is temperate*/
|
||||
public static final Type HOT = getType("HOT");
|
||||
public static final Type COLD = getType("COLD");
|
||||
|
||||
//Tags specifying the amount of vegetation a biome has. Specifying neither implies a biome to have moderate amounts*/
|
||||
public static final Type SPARSE = getType("SPARSE");
|
||||
public static final Type DENSE = getType("DENSE");
|
||||
|
||||
//Tags specifying how moist a biome is. Specifying neither implies the biome as having moderate humidity*/
|
||||
public static final Type WET = getType("WET");
|
||||
public static final Type DRY = getType("DRY");
|
||||
|
||||
/*Tree-based tags, SAVANNA refers to dry, desert-like trees (Such as Acacia), CONIFEROUS refers to snowy trees (Such as Spruce) and JUNGLE refers to jungle trees.
|
||||
* Specifying no tag implies a biome has temperate trees (Such as Oak)*/
|
||||
public static final Type SAVANNA = getType("SAVANNA");
|
||||
public static final Type CONIFEROUS = getType("CONIFEROUS");
|
||||
public static final Type JUNGLE = getType("JUNGLE");
|
||||
|
||||
/*Tags specifying the nature of a biome*/
|
||||
public static final Type SPOOKY = getType("SPOOKY");
|
||||
public static final Type DEAD = getType("DEAD");
|
||||
public static final Type LUSH = getType("LUSH");
|
||||
public static final Type MUSHROOM = getType("MUSHROOM");
|
||||
public static final Type MAGICAL = getType("MAGICAL");
|
||||
public static final Type RARE = getType("RARE");
|
||||
public static final Type PLATEAU = getType("PLATEAU");
|
||||
public static final Type MODIFIED = getType("MODIFIED");
|
||||
|
||||
public static final Type OCEAN = getType("OCEAN");
|
||||
public static final Type RIVER = getType("RIVER");
|
||||
/**
|
||||
* A general tag for all water-based biomes. Shown as present if OCEAN or RIVER are.
|
||||
**/
|
||||
public static final Type WATER = getType("WATER", OCEAN, RIVER);
|
||||
|
||||
/*Generic types which a biome can be*/
|
||||
public static final Type MESA = getType("MESA");
|
||||
public static final Type FOREST = getType("FOREST");
|
||||
public static final Type PLAINS = getType("PLAINS");
|
||||
public static final Type HILLS = getType("HILLS");
|
||||
public static final Type SWAMP = getType("SWAMP");
|
||||
public static final Type SANDY = getType("SANDY");
|
||||
public static final Type SNOWY = getType("SNOWY");
|
||||
public static final Type WASTELAND = getType("WASTELAND");
|
||||
public static final Type BEACH = getType("BEACH");
|
||||
public static final Type VOID = getType("VOID");
|
||||
public static final Type UNDERGROUND = getType("UNDERGROUND");
|
||||
|
||||
/*Mountain related tags*/
|
||||
public static final Type PEAK = getType("PEAK");
|
||||
public static final Type SLOPE = getType("SLOPE");
|
||||
public static final Type MOUNTAIN = getType("MOUNTAIN", PEAK, SLOPE);
|
||||
|
||||
/*Tags specifying the dimension a biome generates in. Specifying none implies a biome that generates in a modded dimension*/
|
||||
public static final Type OVERWORLD = getType("OVERWORLD");
|
||||
public static final Type NETHER = getType("NETHER");
|
||||
public static final Type END = getType("END");
|
||||
|
||||
private final String name;
|
||||
private final List<Type> subTypes;
|
||||
private final Set<ResourceKey<Biome>> biomes = ConcurrentHashMap.newKeySet();
|
||||
private final Set<ResourceKey<Biome>> biomesUn = Collections.unmodifiableSet(biomes);
|
||||
|
||||
private Type(String name, Type... subTypes)
|
||||
{
|
||||
this.name = name;
|
||||
this.subTypes = ImmutableList.copyOf(subTypes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name for this type.
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a Type instance by name,
|
||||
* if one does not exist already it creates one.
|
||||
* This can be used as intermediate measure for modders to
|
||||
* add their own Biome types.
|
||||
* <p>
|
||||
* There are <i>no</i> naming conventions besides:
|
||||
* <ul><li><b>Must</b> be all upper case (enforced by name.toUpper())</li>
|
||||
* <li><b>No</b> Special characters. {Unenforced, just don't be a pain, if it becomes a issue I WILL
|
||||
* make this RTE with no worry about backwards compatibility}</li></ul>
|
||||
* <p>
|
||||
* Note: For performance sake, the return value of this function SHOULD be cached.
|
||||
* Two calls with the same name SHOULD return the same value.
|
||||
*
|
||||
* @param name The name of this Type
|
||||
* @return An instance of Type for this name.
|
||||
*/
|
||||
public synchronized static Type getType(String name, Type... subTypes)
|
||||
{
|
||||
return byName.computeIfAbsent(name.toUpperCase(Locale.ENGLISH), n -> new Type(n, subTypes));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a type instance exists for a given name. Does not have any side effects if a type does not already exist.
|
||||
* This can be used for checking if a user-defined type is valid, for example, in a codec which accepts biome dictionary names.
|
||||
* @param name The name.
|
||||
* @return {@code true} if a type exists with this name.
|
||||
*
|
||||
* @see #getType(String, Type...) #getType for type naming conventions.
|
||||
*/
|
||||
public static boolean hasType(String name)
|
||||
{
|
||||
return byName.containsKey(name.toUpperCase(Locale.ENGLISH));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return An unmodifiable collection of all current biome types.
|
||||
*/
|
||||
public static Collection<Type> getAll()
|
||||
{
|
||||
return allTypes;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Type fromVanilla(Biome.BiomeCategory category)
|
||||
{
|
||||
if (category == Biome.BiomeCategory.NONE)
|
||||
return null;
|
||||
if (category == Biome.BiomeCategory.THEEND)
|
||||
return VOID;
|
||||
return getType(category.name());
|
||||
}
|
||||
}
|
||||
|
||||
private static final Map<ResourceKey<Biome>, BiomeInfo> biomeInfoMap = new HashMap<>();
|
||||
|
||||
private static class BiomeInfo
|
||||
{
|
||||
private final Set<Type> types = new HashSet<Type>();
|
||||
private final Set<Type> typesUn = Collections.unmodifiableSet(this.types);
|
||||
}
|
||||
|
||||
public static void init() {}
|
||||
static
|
||||
{
|
||||
registerVanillaBiomes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the given types to the biome.
|
||||
*
|
||||
*/
|
||||
public static void addTypes(ResourceKey<Biome> biome, Type... types)
|
||||
{
|
||||
Collection<Type> supertypes = listSupertypes(types);
|
||||
Collections.addAll(supertypes, types);
|
||||
|
||||
for (Type type : supertypes)
|
||||
{
|
||||
type.biomes.add(biome);
|
||||
}
|
||||
|
||||
BiomeInfo biomeInfo = getBiomeInfo(biome);
|
||||
Collections.addAll(biomeInfo.types, types);
|
||||
biomeInfo.types.addAll(supertypes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the set of biomes that have the given type.
|
||||
*
|
||||
*/
|
||||
@Nonnull
|
||||
public static Set<ResourceKey<Biome>> getBiomes(Type type)
|
||||
{
|
||||
return type.biomesUn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the set of types that have been added to the given biome.
|
||||
*
|
||||
*/
|
||||
@Nonnull
|
||||
public static Set<Type> getTypes(ResourceKey<Biome> biome)
|
||||
{
|
||||
return getBiomeInfo(biome).typesUn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the two given biomes have types in common.
|
||||
*
|
||||
* @return returns true if a common type is found, false otherwise
|
||||
*/
|
||||
public static boolean areSimilar(ResourceKey<Biome> biomeA, ResourceKey<Biome> biomeB)
|
||||
{
|
||||
Set<Type> typesA = getTypes(biomeA);
|
||||
Set<Type> typesB = getTypes(biomeB);
|
||||
return typesA.stream().anyMatch(typesB::contains);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given type has been added to the given biome.
|
||||
*
|
||||
*/
|
||||
public static boolean hasType(ResourceKey<Biome> biome, Type type)
|
||||
{
|
||||
return getTypes(biome).contains(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if any type has been added to the given biome.
|
||||
*
|
||||
*/
|
||||
public static boolean hasAnyType(ResourceKey<Biome> biome)
|
||||
{
|
||||
return !getBiomeInfo(biome).types.isEmpty();
|
||||
}
|
||||
|
||||
//Internal implementation
|
||||
private static BiomeInfo getBiomeInfo(ResourceKey<Biome> biome)
|
||||
{
|
||||
return biomeInfoMap.computeIfAbsent(biome, k -> new BiomeInfo());
|
||||
}
|
||||
|
||||
private static Collection<Type> listSupertypes(Type... types)
|
||||
{
|
||||
Set<Type> supertypes = new HashSet<Type>();
|
||||
Deque<Type> next = new ArrayDeque<Type>();
|
||||
Collections.addAll(next, types);
|
||||
|
||||
while (!next.isEmpty())
|
||||
{
|
||||
Type type = next.remove();
|
||||
|
||||
for (Type sType : Type.byName.values())
|
||||
{
|
||||
if (sType.subTypes.contains(type) && supertypes.add(sType))
|
||||
next.add(sType);
|
||||
}
|
||||
}
|
||||
|
||||
return supertypes;
|
||||
}
|
||||
|
||||
private static void registerVanillaBiomes()
|
||||
{
|
||||
addTypes(Biomes.OCEAN, OCEAN, OVERWORLD);
|
||||
addTypes(Biomes.PLAINS, PLAINS, OVERWORLD);
|
||||
addTypes(Biomes.DESERT, HOT, DRY, SANDY, OVERWORLD);
|
||||
addTypes(Biomes.WINDSWEPT_HILLS, HILLS, OVERWORLD);
|
||||
addTypes(Biomes.FOREST, FOREST, OVERWORLD);
|
||||
addTypes(Biomes.TAIGA, COLD, CONIFEROUS, FOREST, OVERWORLD);
|
||||
addTypes(Biomes.SWAMP, WET, SWAMP, OVERWORLD);
|
||||
addTypes(Biomes.RIVER, RIVER, OVERWORLD);
|
||||
addTypes(Biomes.NETHER_WASTES, HOT, DRY, NETHER);
|
||||
addTypes(Biomes.THE_END, COLD, DRY, END);
|
||||
addTypes(Biomes.FROZEN_OCEAN, COLD, OCEAN, SNOWY, OVERWORLD);
|
||||
addTypes(Biomes.FROZEN_RIVER, COLD, RIVER, SNOWY, OVERWORLD);
|
||||
addTypes(Biomes.SNOWY_PLAINS, COLD, SNOWY, WASTELAND, OVERWORLD);
|
||||
addTypes(Biomes.MUSHROOM_FIELDS, MUSHROOM, RARE, OVERWORLD);
|
||||
addTypes(Biomes.BEACH, BEACH, OVERWORLD);
|
||||
addTypes(Biomes.JUNGLE, HOT, WET, DENSE, JUNGLE, OVERWORLD);
|
||||
addTypes(Biomes.SPARSE_JUNGLE, HOT, WET, JUNGLE, FOREST, RARE, OVERWORLD);
|
||||
addTypes(Biomes.DEEP_OCEAN, OCEAN, OVERWORLD);
|
||||
addTypes(Biomes.STONY_SHORE, BEACH, OVERWORLD);
|
||||
addTypes(Biomes.SNOWY_BEACH, COLD, BEACH, SNOWY, OVERWORLD);
|
||||
addTypes(Biomes.BIRCH_FOREST, FOREST, OVERWORLD);
|
||||
addTypes(Biomes.DARK_FOREST, SPOOKY, DENSE, FOREST, OVERWORLD);
|
||||
addTypes(Biomes.SNOWY_TAIGA, COLD, CONIFEROUS, FOREST, SNOWY, OVERWORLD);
|
||||
addTypes(Biomes.OLD_GROWTH_PINE_TAIGA, COLD, CONIFEROUS, FOREST, OVERWORLD);
|
||||
addTypes(Biomes.WINDSWEPT_FOREST, HILLS, FOREST, SPARSE, OVERWORLD);
|
||||
addTypes(Biomes.SAVANNA, HOT, SAVANNA, PLAINS, SPARSE, OVERWORLD);
|
||||
addTypes(Biomes.SAVANNA_PLATEAU, HOT, SAVANNA, PLAINS, SPARSE, RARE, OVERWORLD, SLOPE, PLATEAU);
|
||||
addTypes(Biomes.BADLANDS, MESA, SANDY, DRY, OVERWORLD);
|
||||
addTypes(Biomes.WOODED_BADLANDS, MESA, SANDY, DRY, SPARSE, OVERWORLD, SLOPE, PLATEAU);
|
||||
addTypes(Biomes.MEADOW, PLAINS, PLATEAU, SLOPE, OVERWORLD);
|
||||
addTypes(Biomes.GROVE, COLD, CONIFEROUS, FOREST, SNOWY, SLOPE, OVERWORLD);
|
||||
addTypes(Biomes.SNOWY_SLOPES, COLD, SPARSE, SNOWY, SLOPE, OVERWORLD);
|
||||
addTypes(Biomes.JAGGED_PEAKS, COLD, SPARSE, SNOWY, PEAK, OVERWORLD);
|
||||
addTypes(Biomes.FROZEN_PEAKS, COLD, SPARSE, SNOWY, PEAK, OVERWORLD);
|
||||
addTypes(Biomes.STONY_PEAKS, HOT, PEAK, OVERWORLD);
|
||||
addTypes(Biomes.SMALL_END_ISLANDS, END);
|
||||
addTypes(Biomes.END_MIDLANDS, END);
|
||||
addTypes(Biomes.END_HIGHLANDS, END);
|
||||
addTypes(Biomes.END_BARRENS, END);
|
||||
addTypes(Biomes.WARM_OCEAN, OCEAN, HOT, OVERWORLD);
|
||||
addTypes(Biomes.LUKEWARM_OCEAN, OCEAN, OVERWORLD);
|
||||
addTypes(Biomes.COLD_OCEAN, OCEAN, COLD, OVERWORLD);
|
||||
addTypes(Biomes.DEEP_LUKEWARM_OCEAN, OCEAN, OVERWORLD);
|
||||
addTypes(Biomes.DEEP_COLD_OCEAN, OCEAN, COLD, OVERWORLD);
|
||||
addTypes(Biomes.DEEP_FROZEN_OCEAN, OCEAN, COLD, OVERWORLD);
|
||||
addTypes(Biomes.THE_VOID, VOID);
|
||||
addTypes(Biomes.SUNFLOWER_PLAINS, PLAINS, RARE, OVERWORLD);
|
||||
addTypes(Biomes.WINDSWEPT_GRAVELLY_HILLS, HILLS, SPARSE, RARE, OVERWORLD);
|
||||
addTypes(Biomes.FLOWER_FOREST, FOREST, RARE, OVERWORLD);
|
||||
addTypes(Biomes.ICE_SPIKES, COLD, SNOWY, RARE, OVERWORLD);
|
||||
addTypes(Biomes.OLD_GROWTH_BIRCH_FOREST, FOREST, DENSE, RARE, OVERWORLD);
|
||||
addTypes(Biomes.OLD_GROWTH_SPRUCE_TAIGA, DENSE, FOREST, RARE, OVERWORLD);
|
||||
addTypes(Biomes.WINDSWEPT_SAVANNA, HOT, DRY, SPARSE, SAVANNA, HILLS, RARE, OVERWORLD);
|
||||
addTypes(Biomes.ERODED_BADLANDS, MESA, HOT, DRY, SPARSE, RARE, OVERWORLD);
|
||||
addTypes(Biomes.BAMBOO_JUNGLE, HOT, WET, RARE, JUNGLE, OVERWORLD);
|
||||
addTypes(Biomes.LUSH_CAVES, UNDERGROUND, LUSH, WET, OVERWORLD);
|
||||
addTypes(Biomes.DRIPSTONE_CAVES, UNDERGROUND, SPARSE, OVERWORLD);
|
||||
addTypes(Biomes.SOUL_SAND_VALLEY, HOT, DRY, NETHER);
|
||||
addTypes(Biomes.CRIMSON_FOREST, HOT, DRY, NETHER, FOREST);
|
||||
addTypes(Biomes.WARPED_FOREST, HOT, DRY, NETHER, FOREST);
|
||||
addTypes(Biomes.BASALT_DELTAS, HOT, DRY, NETHER);
|
||||
|
||||
if (DEBUG)
|
||||
{
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append("BiomeDictionary:\n");
|
||||
|
||||
Type.getAll().stream()
|
||||
.sorted((l,r) -> l.getName().compareTo(r.getName()))
|
||||
.forEach(type ->
|
||||
buf.append(" ").append(type.name).append(": ")
|
||||
.append(type.biomes.stream()
|
||||
.map(ResourceKey::location)
|
||||
.sorted((a,b) -> a.compareNamespaced(b))
|
||||
.map(Object::toString)
|
||||
.collect(Collectors.joining(", "))
|
||||
)
|
||||
.append('\n')
|
||||
);
|
||||
|
||||
boolean missing = false;
|
||||
List<ResourceKey<Biome>> all = StreamSupport.stream(ForgeRegistries.BIOMES.spliterator(), false)
|
||||
.map(b -> ResourceKey.create(Registry.BIOME_REGISTRY, b.getRegistryName()))
|
||||
.sorted().collect(Collectors.toList());
|
||||
|
||||
for (ResourceKey<Biome> key : all) {
|
||||
if (!biomeInfoMap.containsKey(key)) {
|
||||
if (!missing) {
|
||||
buf.append("Missing:\n");
|
||||
missing = true;
|
||||
}
|
||||
buf.append(" ").append(key.location()).append('\n');
|
||||
}
|
||||
}
|
||||
LOGGER.debug(buf.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.util.random.WeightedEntry;
|
||||
import net.minecraft.util.random.WeightedRandom;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
@@ -78,7 +79,7 @@ public class DungeonHooks
|
||||
* @param rand World generation random number generator
|
||||
* @return The mob name
|
||||
*/
|
||||
public static EntityType<?> getRandomDungeonMob(Random rand)
|
||||
public static EntityType<?> getRandomDungeonMob(RandomSource rand)
|
||||
{
|
||||
DungeonMob mob = WeightedRandom.getRandomItem(rand, dungeonMobs).orElseThrow();
|
||||
return mob.type;
|
||||
|
||||
@@ -26,9 +26,6 @@ import java.util.function.Predicate;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraftforge.fml.config.IConfigSpec;
|
||||
import net.minecraftforge.fml.loading.FMLEnvironment;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
@@ -48,6 +45,8 @@ import com.google.common.base.Preconditions;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.ObjectArrays;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/*
|
||||
* Like {@link com.electronwill.nightconfig.core.ConfigSpec} except in builder format, and extended to accept comments, language keys,
|
||||
@@ -647,7 +646,7 @@ public class ForgeConfigSpec extends UnmodifiableConfigWrapper<UnmodifiableConfi
|
||||
|
||||
private static class BuilderContext
|
||||
{
|
||||
private @Nonnull String[] comment = new String[0];
|
||||
private @NotNull String[] comment = new String[0];
|
||||
private String langKey;
|
||||
private Range<?> range;
|
||||
private boolean worldRestart = false;
|
||||
|
||||
@@ -7,19 +7,7 @@ package net.minecraftforge.common;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Deque;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.regex.Matcher;
|
||||
@@ -36,21 +24,19 @@ import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.mojang.datafixers.kinds.App;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.Lifecycle;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder.Mu;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import it.unimi.dsi.fastutil.longs.LongSet;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import net.minecraft.ResourceLocationException;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.advancements.Advancement;
|
||||
import net.minecraft.core.*;
|
||||
import net.minecraft.network.chat.*;
|
||||
import net.minecraft.server.packs.PackType;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
import net.minecraft.tags.TagEntry;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.util.datafix.fixes.StructuresBecomeConfiguredFix;
|
||||
import net.minecraft.world.effect.MobEffect;
|
||||
@@ -64,14 +50,11 @@ import net.minecraft.world.item.*;
|
||||
import net.minecraft.world.item.crafting.Ingredient;
|
||||
import net.minecraft.world.item.crafting.RecipeType;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BannerPattern;
|
||||
import net.minecraft.world.level.gameevent.GameEvent;
|
||||
import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature;
|
||||
import net.minecraft.world.level.storage.WorldData;
|
||||
import net.minecraft.world.level.storage.loot.LootContext;
|
||||
import net.minecraft.world.level.storage.loot.LootTable;
|
||||
import net.minecraft.world.level.storage.loot.LootTables;
|
||||
import net.minecraft.tags.Tag;
|
||||
import net.minecraft.util.*;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -91,7 +74,6 @@ import net.minecraft.world.Container;
|
||||
import net.minecraft.world.item.context.UseOnContext;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.syncher.EntityDataSerializer;
|
||||
import net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket;
|
||||
@@ -100,8 +82,6 @@ import net.minecraft.world.item.alchemy.PotionUtils;
|
||||
import net.minecraft.stats.Stats;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraft.world.*;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraft.world.level.levelgen.WorldGenSettings;
|
||||
import net.minecraft.world.level.BaseSpawner;
|
||||
import net.minecraft.world.level.block.entity.FurnaceBlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
@@ -110,7 +90,6 @@ import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.EntityHitResult;
|
||||
import net.minecraft.network.chat.ClickEvent;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.BiomeSpecialEffects;
|
||||
import net.minecraft.world.level.biome.BiomeGenerationSettings;
|
||||
@@ -157,7 +136,6 @@ import net.minecraftforge.event.entity.player.CriticalHitEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingGetProjectileEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
import net.minecraftforge.event.world.BiomeLoadingEvent;
|
||||
import net.minecraftforge.event.world.BlockEvent;
|
||||
import net.minecraftforge.event.world.NoteBlockEvent;
|
||||
import net.minecraftforge.eventbus.api.Event.Result;
|
||||
@@ -166,23 +144,18 @@ import net.minecraftforge.fml.ModContainer;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
import net.minecraftforge.fml.ModLoader;
|
||||
import net.minecraftforge.resource.ResourcePackLoader;
|
||||
import net.minecraftforge.registries.DataSerializerEntry;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.ForgeRegistry;
|
||||
import net.minecraftforge.registries.GameData;
|
||||
import net.minecraftforge.registries.IRegistryDelegate;
|
||||
import net.minecraftforge.registries.RegistryManager;
|
||||
|
||||
import net.minecraftforge.server.ServerLifecycleHooks;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.Marker;
|
||||
import org.apache.logging.log4j.MarkerManager;
|
||||
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.network.chat.TextColor;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
@@ -195,6 +168,8 @@ import net.minecraft.world.level.material.EmptyFluid;
|
||||
import net.minecraft.world.level.material.Fluid;
|
||||
import net.minecraft.world.level.material.LavaFluid;
|
||||
import net.minecraft.world.level.material.WaterFluid;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class ForgeHooks
|
||||
{
|
||||
@@ -203,7 +178,7 @@ public class ForgeHooks
|
||||
private static final Marker FORGEHOOKS = MarkerManager.getMarker("FORGEHOOKS");
|
||||
private static final Marker WORLDPERSISTENCE = MarkerManager.getMarker("WP");
|
||||
|
||||
public static boolean canContinueUsing(@Nonnull ItemStack from, @Nonnull ItemStack to)
|
||||
public static boolean canContinueUsing(@NotNull ItemStack from, @NotNull ItemStack to)
|
||||
{
|
||||
if (!from.isEmpty() && !to.isEmpty())
|
||||
{
|
||||
@@ -212,7 +187,7 @@ public class ForgeHooks
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isCorrectToolForDrops(@Nonnull BlockState state, @Nonnull Player player)
|
||||
public static boolean isCorrectToolForDrops(@NotNull BlockState state, @NotNull Player player)
|
||||
{
|
||||
if (!state.requiresCorrectToolForDrops())
|
||||
return ForgeEventFactory.doPlayerHarvestCheck(player, state, true);
|
||||
@@ -244,7 +219,7 @@ public class ForgeHooks
|
||||
result = state.getCloneItemStack(target, level, pos, player);
|
||||
|
||||
if (result.isEmpty())
|
||||
LOGGER.warn("Picking on: [{}] {} gave null item", target.getType(), state.getBlock().getRegistryName());
|
||||
LOGGER.warn("Picking on: [{}] {} gave null item", target.getType(), ForgeRegistries.BLOCKS.getKey(state.getBlock()));
|
||||
}
|
||||
else if (target.getType() == HitResult.Type.ENTITY)
|
||||
{
|
||||
@@ -252,7 +227,7 @@ public class ForgeHooks
|
||||
result = entity.getPickedResult(target);
|
||||
|
||||
if (result.isEmpty())
|
||||
LOGGER.warn("Picking on: [{}] {} gave null item", target.getType(), entity.getType().getRegistryName());
|
||||
LOGGER.warn("Picking on: [{}] {} gave null item", target.getType(), ForgeRegistries.ENTITIES.getKey(entity.getType()));
|
||||
}
|
||||
|
||||
if (result.isEmpty())
|
||||
@@ -366,7 +341,7 @@ public class ForgeHooks
|
||||
return Math.max(0,event.getVisibilityModifier());
|
||||
}
|
||||
|
||||
public static Optional<BlockPos> isLivingOnLadder(@Nonnull BlockState state, @Nonnull Level level, @Nonnull BlockPos pos, @Nonnull LivingEntity entity)
|
||||
public static Optional<BlockPos> isLivingOnLadder(@NotNull BlockState state, @NotNull Level level, @NotNull BlockPos pos, @NotNull LivingEntity entity)
|
||||
{
|
||||
boolean isSpectator = (entity instanceof Player && entity.isSpectator());
|
||||
if (isSpectator) return Optional.empty();
|
||||
@@ -405,7 +380,7 @@ public class ForgeHooks
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ItemEntity onPlayerTossEvent(@Nonnull Player player, @Nonnull ItemStack item, boolean includeName)
|
||||
public static ItemEntity onPlayerTossEvent(@NotNull Player player, @NotNull ItemStack item, boolean includeName)
|
||||
{
|
||||
player.captureDrops(Lists.newArrayList());
|
||||
ItemEntity ret = player.drop(item, false, includeName);
|
||||
@@ -423,15 +398,15 @@ public class ForgeHooks
|
||||
return event.getEntityItem();
|
||||
}
|
||||
|
||||
public static boolean onVanillaGameEvent(Level level, @Nullable Entity cause, GameEvent vanillaEvent, BlockPos position)
|
||||
public static boolean onVanillaGameEvent(Level level, GameEvent vanillaEvent, Vec3 pos, GameEvent.Context context)
|
||||
{
|
||||
return !MinecraftForge.EVENT_BUS.post(new VanillaGameEvent(level, cause, vanillaEvent, position));
|
||||
return !MinecraftForge.EVENT_BUS.post(new VanillaGameEvent(level, vanillaEvent, pos, context));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Component onServerChatEvent(ServerGamePacketListenerImpl net, String raw, Component comp)
|
||||
public static Component onServerChatEvent(@Nullable ServerPlayer player, String raw, Component comp)
|
||||
{
|
||||
ServerChatEvent event = new ServerChatEvent(net.player, raw, comp);
|
||||
ServerChatEvent event = new ServerChatEvent(player, raw, comp);
|
||||
if (MinecraftForge.EVENT_BUS.post(event))
|
||||
{
|
||||
return null;
|
||||
@@ -467,13 +442,13 @@ public class ForgeHooks
|
||||
if (part.length() > 0)
|
||||
{
|
||||
if (ichat == null)
|
||||
ichat = new TextComponent(part);
|
||||
ichat = Component.literal(part);
|
||||
else
|
||||
ichat.append(part);
|
||||
}
|
||||
lastEnd = end;
|
||||
String url = string.substring(start, end);
|
||||
MutableComponent link = new TextComponent(url);
|
||||
MutableComponent link = Component.literal(url);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -483,7 +458,7 @@ public class ForgeHooks
|
||||
if (!allowMissingHeader)
|
||||
{
|
||||
if (ichat == null)
|
||||
ichat = new TextComponent(url);
|
||||
ichat = Component.literal(url);
|
||||
else
|
||||
ichat.append(url);
|
||||
continue;
|
||||
@@ -494,25 +469,25 @@ public class ForgeHooks
|
||||
catch (URISyntaxException e)
|
||||
{
|
||||
// Bad syntax bail out!
|
||||
if (ichat == null) ichat = new TextComponent(url);
|
||||
if (ichat == null) ichat = Component.literal(url);
|
||||
else ichat.append(url);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Set the click event and append the link.
|
||||
ClickEvent click = new ClickEvent(ClickEvent.Action.OPEN_URL, url);
|
||||
link.setStyle(link.getStyle().withClickEvent(click).setUnderlined(true).withColor(TextColor.fromLegacyFormat(ChatFormatting.BLUE)));
|
||||
link.setStyle(link.getStyle().withClickEvent(click).withUnderlined(true).withColor(TextColor.fromLegacyFormat(ChatFormatting.BLUE)));
|
||||
if (ichat == null)
|
||||
ichat = new TextComponent("");
|
||||
ichat = Component.literal("");
|
||||
ichat.append(link);
|
||||
}
|
||||
|
||||
// Append the rest of the message.
|
||||
String end = string.substring(lastEnd);
|
||||
if (ichat == null)
|
||||
ichat = new TextComponent(end);
|
||||
ichat = Component.literal(end);
|
||||
else if (end.length() > 0)
|
||||
ichat.append(new TextComponent(string.substring(lastEnd)));
|
||||
ichat.append(Component.literal(string.substring(lastEnd)));
|
||||
return ichat;
|
||||
}
|
||||
|
||||
@@ -570,7 +545,7 @@ public class ForgeHooks
|
||||
return event.isCanceled() ? -1 : event.getExpToDrop();
|
||||
}
|
||||
|
||||
public static InteractionResult onPlaceItemIntoWorld(@Nonnull UseOnContext context)
|
||||
public static InteractionResult onPlaceItemIntoWorld(@NotNull UseOnContext context)
|
||||
{
|
||||
ItemStack itemstack = context.getItemInHand();
|
||||
Level level = context.getLevel();
|
||||
@@ -660,7 +635,7 @@ public class ForgeHooks
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static boolean onAnvilChange(AnvilMenu container, @Nonnull ItemStack left, @Nonnull ItemStack right, Container outputSlot, String name, int baseCost, Player player)
|
||||
public static boolean onAnvilChange(AnvilMenu container, @NotNull ItemStack left, @NotNull ItemStack right, Container outputSlot, String name, int baseCost, Player player)
|
||||
{
|
||||
AnvilUpdateEvent e = new AnvilUpdateEvent(left, right, name, baseCost, player);
|
||||
if (MinecraftForge.EVENT_BUS.post(e)) return false;
|
||||
@@ -672,7 +647,7 @@ public class ForgeHooks
|
||||
return false;
|
||||
}
|
||||
|
||||
public static float onAnvilRepair(Player player, @Nonnull ItemStack output, @Nonnull ItemStack left, @Nonnull ItemStack right)
|
||||
public static float onAnvilRepair(Player player, @NotNull ItemStack output, @NotNull ItemStack left, @NotNull ItemStack right)
|
||||
{
|
||||
AnvilRepairEvent e = new AnvilRepairEvent(player, left, right, output);
|
||||
MinecraftForge.EVENT_BUS.post(e);
|
||||
@@ -688,8 +663,8 @@ public class ForgeHooks
|
||||
{
|
||||
return craftingPlayer.get();
|
||||
}
|
||||
@Nonnull
|
||||
public static ItemStack getContainerItem(@Nonnull ItemStack stack)
|
||||
@NotNull
|
||||
public static ItemStack getContainerItem(@NotNull ItemStack stack)
|
||||
{
|
||||
if (stack.getItem().hasContainerItem(stack))
|
||||
{
|
||||
@@ -769,12 +744,6 @@ public class ForgeHooks
|
||||
MinecraftForge.EVENT_BUS.post(new PlayerInteractEvent.LeftClickEmpty(player));
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true, since = "1.18")
|
||||
public static boolean onChangeGameMode(Player player, GameType currentGameMode, GameType newGameMode)
|
||||
{
|
||||
return onChangeGameType(player, currentGameMode, newGameMode) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null if game type should not be changed, desired new GameType otherwise
|
||||
*/
|
||||
@@ -864,7 +833,7 @@ public class ForgeHooks
|
||||
{
|
||||
ForgeWorldPreset def = ForgeWorldPreset.getDefaultWorldPreset();
|
||||
if (def != null)
|
||||
return def.getRegistryName().toString();
|
||||
return ForgeRegistries.WORLD_TYPES.get().getKey(def).toString();
|
||||
return "default";
|
||||
}
|
||||
|
||||
@@ -884,16 +853,7 @@ public class ForgeHooks
|
||||
@FunctionalInterface
|
||||
public interface BiomeCallbackFunction
|
||||
{
|
||||
Biome apply(final Biome.ClimateSettings climate, final Biome.BiomeCategory category, final BiomeSpecialEffects effects, final BiomeGenerationSettings gen, final MobSpawnSettings spawns);
|
||||
}
|
||||
|
||||
public static Biome enhanceBiome(@Nullable final ResourceLocation name, final Biome.ClimateSettings climate, final Biome.BiomeCategory category, final BiomeSpecialEffects effects, final BiomeGenerationSettings gen, final MobSpawnSettings spawns, final RecordCodecBuilder.Instance<Biome> codec, final BiomeCallbackFunction callback)
|
||||
{
|
||||
BiomeGenerationSettingsBuilder genBuilder = new BiomeGenerationSettingsBuilder(gen);
|
||||
MobSpawnSettingsBuilder spawnBuilder = new MobSpawnSettingsBuilder(spawns);
|
||||
BiomeLoadingEvent event = new BiomeLoadingEvent(name, climate, category, effects, genBuilder, spawnBuilder);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
return callback.apply(event.getClimate(), event.getCategory(), event.getEffects(), event.getGeneration().build(), event.getSpawns().build()).setRegistryName(name);
|
||||
Biome apply(final Biome.ClimateSettings climate, final BiomeSpecialEffects effects, final BiomeGenerationSettings gen, final MobSpawnSettings spawns);
|
||||
}
|
||||
|
||||
private static class LootTableContext
|
||||
@@ -1034,10 +994,10 @@ public class ForgeHooks
|
||||
* Used as the default implementation of {@link Item#getCreatorModId}. Call that method instead.
|
||||
*/
|
||||
@Nullable
|
||||
public static String getDefaultCreatorModId(@Nonnull ItemStack itemStack)
|
||||
public static String getDefaultCreatorModId(@NotNull ItemStack itemStack)
|
||||
{
|
||||
Item item = itemStack.getItem();
|
||||
ResourceLocation registryName = item.getRegistryName();
|
||||
ResourceLocation registryName = ForgeRegistries.ITEMS.getKey(item);
|
||||
String modId = registryName == null ? null : registryName.getNamespace();
|
||||
if ("minecraft".equals(modId))
|
||||
{
|
||||
@@ -1065,7 +1025,7 @@ public class ForgeHooks
|
||||
}
|
||||
else if (item instanceof SpawnEggItem)
|
||||
{
|
||||
ResourceLocation resourceLocation = ((SpawnEggItem)item).getType(null).getRegistryName();
|
||||
ResourceLocation resourceLocation = ForgeRegistries.ENTITIES.getKey(((SpawnEggItem) item).getType(null));
|
||||
if (resourceLocation != null)
|
||||
{
|
||||
return resourceLocation.getNamespace();
|
||||
@@ -1106,40 +1066,38 @@ public class ForgeHooks
|
||||
{
|
||||
//If we potentially added a barrier due to the ingredient being an empty tag, try and check if it is the stack we added
|
||||
ItemStack item = items[0];
|
||||
return item.getItem() == Items.BARRIER && item.getHoverName() instanceof TextComponent hoverName && hoverName.getText().startsWith("Empty Tag: ");
|
||||
return item.getItem() == Items.BARRIER && item.getHoverName() instanceof MutableComponent hoverName && hoverName.getString().startsWith("Empty Tag: ");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static <T> void deserializeTagAdditions(List<Tag.Entry> list, JsonObject json, List<Tag.BuilderEntry> allList)
|
||||
public static <T> void deserializeTagAdditions(List<TagEntry> list, JsonObject json, List<TagEntry> allList)
|
||||
{
|
||||
if (json.has("remove"))
|
||||
{
|
||||
for (JsonElement entry : GsonHelper.getAsJsonArray(json, "remove"))
|
||||
{
|
||||
String s = GsonHelper.convertToString(entry, "value");
|
||||
Tag.Entry dummy;
|
||||
TagEntry dummy;
|
||||
if (!s.startsWith("#"))
|
||||
dummy = new Tag.OptionalElementEntry(new ResourceLocation(s));
|
||||
dummy = TagEntry.optionalElement(new ResourceLocation(s));
|
||||
else
|
||||
dummy = new Tag.TagEntry(new ResourceLocation(s.substring(1)));
|
||||
allList.removeIf(e -> e.entry().equals(dummy));
|
||||
dummy = TagEntry.tag(new ResourceLocation(s.substring(1)));
|
||||
allList.removeIf(e -> e.equals(dummy));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<EntityDataSerializer<?>, DataSerializerEntry> serializerEntries = GameData.getSerializerMap();
|
||||
//private static final ForgeRegistry<DataSerializerEntry> serializerRegistry = (ForgeRegistry<DataSerializerEntry>) ForgeRegistries.DATA_SERIALIZERS;
|
||||
// Do not reimplement this ^ it introduces a chicken-egg scenario by classloading registries during bootstrap
|
||||
|
||||
@Nullable
|
||||
public static EntityDataSerializer<?> getSerializer(int id, CrudeIncrementalIntIdentityHashBiMap<EntityDataSerializer<?>> vanilla)
|
||||
{
|
||||
EntityDataSerializer<?> serializer = vanilla.byId(id);
|
||||
if (serializer == null)
|
||||
{
|
||||
DataSerializerEntry entry = ((ForgeRegistry<DataSerializerEntry>)ForgeRegistries.DATA_SERIALIZERS.get()).getValue(id);
|
||||
if (entry != null) serializer = entry.getSerializer();
|
||||
// ForgeRegistries.DATA_SERIALIZERS is a deferred register now, so if this method is called too early, the registry will be null
|
||||
ForgeRegistry<EntityDataSerializer<?>> registry = (ForgeRegistry<EntityDataSerializer<?>>) ForgeRegistries.DATA_SERIALIZERS.get();
|
||||
if (registry != null)
|
||||
serializer = registry.getValue(id);
|
||||
}
|
||||
return serializer;
|
||||
}
|
||||
@@ -1149,16 +1107,11 @@ public class ForgeHooks
|
||||
int id = vanilla.getId(serializer);
|
||||
if (id < 0)
|
||||
{
|
||||
// ForgeRegistries.DATA_SERIALIZERS is a deferred register now, so if this method is called too early, the serializer map will be null
|
||||
// This should keep checking until it's not null
|
||||
if (serializerEntries == null)
|
||||
serializerEntries = GameData.getSerializerMap();
|
||||
if (serializerEntries != null)
|
||||
{
|
||||
DataSerializerEntry entry = serializerEntries.get(serializer);
|
||||
if (entry != null)
|
||||
id = ((ForgeRegistry<DataSerializerEntry>) ForgeRegistries.DATA_SERIALIZERS.get()).getID(entry);
|
||||
}
|
||||
id = ((ForgeRegistry<EntityDataSerializer<?>>) ForgeRegistries.DATA_SERIALIZERS).getID(serializer);
|
||||
// ForgeRegistries.DATA_SERIALIZERS is a deferred register now, so if this method is called too early, the registry will be null
|
||||
ForgeRegistry<EntityDataSerializer<?>> registry = (ForgeRegistry<EntityDataSerializer<?>>) ForgeRegistries.DATA_SERIALIZERS.get();
|
||||
if (registry != null)
|
||||
id = registry.getID(serializer);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
@@ -1171,7 +1124,7 @@ public class ForgeHooks
|
||||
return ForgeEventFactory.getMobGriefingEvent(level, entity) && state.canEntityDestroy(level, pos, entity) && ForgeEventFactory.onEntityDestroyBlock(entity, pos, state);
|
||||
}
|
||||
|
||||
private static final Map<IRegistryDelegate<Item>, Integer> VANILLA_BURNS = new HashMap<>();
|
||||
private static final Map<Holder.Reference<Item>, Integer> VANILLA_BURNS = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Gets the burn time of this itemstack.
|
||||
@@ -1186,7 +1139,7 @@ public class ForgeHooks
|
||||
{
|
||||
Item item = stack.getItem();
|
||||
int ret = stack.getBurnTime(recipeType);
|
||||
return ForgeEventFactory.getItemBurnTime(stack, ret == -1 ? VANILLA_BURNS.getOrDefault(item.delegate, 0) : ret, recipeType);
|
||||
return ForgeEventFactory.getItemBurnTime(stack, ret == -1 ? VANILLA_BURNS.getOrDefault(ForgeRegistries.ITEMS.getDelegateOrThrow(item), 0) : ret, recipeType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1194,7 +1147,7 @@ public class ForgeHooks
|
||||
public static synchronized void updateBurns()
|
||||
{
|
||||
VANILLA_BURNS.clear();
|
||||
FurnaceBlockEntity.getFuel().entrySet().forEach(e -> VANILLA_BURNS.put(e.getKey().delegate, e.getValue()));
|
||||
FurnaceBlockEntity.getFuel().entrySet().forEach(e -> VANILLA_BURNS.put(ForgeRegistries.ITEMS.getDelegateOrThrow(e.getKey()), e.getValue()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1205,14 +1158,14 @@ public class ForgeHooks
|
||||
* @param context The loot context that generated that loot
|
||||
* @return The modified list
|
||||
*
|
||||
* @deprecated Use {@link #modifyLoot(ResourceLocation, List, LootContext)} instead.
|
||||
* @deprecated Use {@link #modifyLoot(ResourceLocation, ObjectArrayList, LootContext)} instead.
|
||||
*
|
||||
* @implNote This method will use the {@linkplain LootTableIdCondition#UNKNOWN_LOOT_TABLE
|
||||
* unknown loot table marker} when redirecting.
|
||||
*/
|
||||
@Deprecated
|
||||
public static List<ItemStack> modifyLoot(List<ItemStack> list, LootContext context) {
|
||||
return modifyLoot(LootTableIdCondition.UNKNOWN_LOOT_TABLE, list, context);
|
||||
return modifyLoot(LootTableIdCondition.UNKNOWN_LOOT_TABLE, ObjectArrayList.wrap((ItemStack[]) list.toArray()), context);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1229,7 +1182,7 @@ public class ForgeHooks
|
||||
* @apiNote The given context will be modified by this method to also store the ID of the
|
||||
* loot table being queried.
|
||||
*/
|
||||
public static List<ItemStack> modifyLoot(ResourceLocation lootTableId, List<ItemStack> generatedLoot, LootContext context) {
|
||||
public static ObjectArrayList<ItemStack> modifyLoot(ResourceLocation lootTableId, ObjectArrayList<ItemStack> generatedLoot, LootContext context) {
|
||||
context.setQueriedLootTableId(lootTableId); // In case the ID was set via copy constructor, this will be ignored: intended
|
||||
LootModifierManager man = ForgeInternalHandler.getLootModifierManager();
|
||||
for (IGlobalLootModifier mod : man.getAllLootMods()) {
|
||||
@@ -1253,20 +1206,6 @@ public class ForgeHooks
|
||||
return modpacks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixes MC-194811
|
||||
* When a structure mod is removed, this map may contain null keys. This will make the world unable to save if this persists.
|
||||
* If we remove a structure from the save data in this way, we then mark the chunk for saving
|
||||
*/
|
||||
public static void fixNullStructureReferences(ChunkAccess chunk, Map<ConfiguredStructureFeature<?, ?>, LongSet> structureReferences)
|
||||
{
|
||||
if (structureReferences.remove(null) != null)
|
||||
{
|
||||
chunk.setUnsaved(true);
|
||||
}
|
||||
chunk.setAllReferences(structureReferences);
|
||||
}
|
||||
|
||||
private static final Set<String> VANILLA_DIMS = Sets.newHashSet("minecraft:overworld", "minecraft:the_nether", "minecraft:the_end");
|
||||
private static final String DIMENSIONS_KEY = "dimensions";
|
||||
private static final String SEED_KEY = "seed";
|
||||
@@ -1310,50 +1249,6 @@ public class ForgeHooks
|
||||
return e;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when dimension jsons are parsed.
|
||||
* Creates a copy of the worldgen settings and its dimension registry,
|
||||
* where dimensions that specify that they should use the server seed will use the server seed
|
||||
* instead of the seed that mojang requires be specified in the json.
|
||||
**/
|
||||
public static WorldGenSettings loadDimensionsWithServerSeed(WorldGenSettings wgs)
|
||||
{
|
||||
// get the original worldgen settings' settings
|
||||
long seed = wgs.seed();
|
||||
boolean generateFeatures = wgs.generateFeatures();
|
||||
boolean generateBonusChest = wgs.generateBonusChest();
|
||||
Registry<LevelStem> originalRegistry = wgs.dimensions();
|
||||
Optional<String> legacyCustomOptions = wgs.legacyCustomOptions;
|
||||
|
||||
// make a copy of the dimension registry; for dimensions that specify that they should use the server seed instead
|
||||
// of the hardcoded json seed, recreate them with the correct seed
|
||||
MappedRegistry<LevelStem> seededRegistry = new MappedRegistry<>(Registry.LEVEL_STEM_REGISTRY, Lifecycle.experimental(), (Function<LevelStem, Holder.Reference<LevelStem>>)null);
|
||||
for (Entry<ResourceKey<LevelStem>, LevelStem> entry : originalRegistry.entrySet())
|
||||
{
|
||||
ResourceKey<LevelStem> key = entry.getKey();
|
||||
LevelStem dimension = entry.getValue();
|
||||
if (dimension.useServerSeed())
|
||||
{
|
||||
seededRegistry.register(key, new LevelStem(dimension.typeHolder(), dimension.generator().withSeed(seed), true), originalRegistry.lifecycle(entry.getValue()));
|
||||
}
|
||||
else
|
||||
{
|
||||
seededRegistry.register(key, dimension, originalRegistry.lifecycle(dimension));
|
||||
}
|
||||
}
|
||||
|
||||
return new WorldGenSettings(seed, generateFeatures, generateBonusChest, seededRegistry, legacyCustomOptions);
|
||||
}
|
||||
|
||||
/** Called in the LevelStem codec builder to add extra fields to dimension jsons **/
|
||||
public static App<Mu<LevelStem>, LevelStem> expandLevelStemCodec(RecordCodecBuilder.Instance<LevelStem> builder, Supplier<App<Mu<LevelStem>, LevelStem>> vanillaFieldsSupplier)
|
||||
{
|
||||
App<Mu<LevelStem>, LevelStem> vanillaFields = vanillaFieldsSupplier.get();
|
||||
return builder.group(vanillaFields).and(
|
||||
Codec.BOOL.optionalFieldOf("forge:use_server_seed", false).stable().forGetter(levelStem -> levelStem.useServerSeed()))
|
||||
.apply(builder, builder.stable((stem, useServerSeed) -> new LevelStem(stem.typeHolder(), stem.generator(), useServerSeed)));
|
||||
}
|
||||
|
||||
public static void writeAdditionalLevelSaveData(WorldData worldData, CompoundTag levelTag)
|
||||
{
|
||||
CompoundTag fmlData = new CompoundTag();
|
||||
@@ -1460,7 +1355,7 @@ public class ForgeHooks
|
||||
|
||||
public static void saveMobEffect(CompoundTag nbt, String key, MobEffect effect)
|
||||
{
|
||||
var registryName = effect.getRegistryName();
|
||||
var registryName = ForgeRegistries.MOB_EFFECTS.getKey(effect);
|
||||
if (registryName != null)
|
||||
{
|
||||
nbt.putString(key, registryName.toString());
|
||||
@@ -1484,37 +1379,7 @@ public class ForgeHooks
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
|
||||
private static BannerPattern[] nonPatternItems;
|
||||
private static int totalPatternRows;
|
||||
|
||||
static
|
||||
{
|
||||
refreshBannerPatternData();
|
||||
}
|
||||
public static void refreshBannerPatternData()
|
||||
{
|
||||
nonPatternItems = Arrays.stream(BannerPattern.values())
|
||||
.filter(p -> !p.hasPatternItem)
|
||||
.toArray(BannerPattern[]::new);
|
||||
totalPatternRows = (nonPatternItems.length + 2) / 4;
|
||||
}
|
||||
|
||||
public static int getTotalPatternRows()
|
||||
{
|
||||
return totalPatternRows;
|
||||
}
|
||||
|
||||
public static int getNonPatternItemCount()
|
||||
{
|
||||
return nonPatternItems.length;
|
||||
}
|
||||
|
||||
public static int getActualPatternIndex(int index)
|
||||
{
|
||||
return nonPatternItems[index].ordinal();
|
||||
}
|
||||
|
||||
public static boolean shouldSuppressEnderManAnger(EnderMan enderMan, Player player, ItemStack mask)
|
||||
{
|
||||
return mask.isEnderMask(player, enderMan) || MinecraftForge.EVENT_BUS.post(new EnderManAngerEvent(enderMan, player));
|
||||
|
||||
@@ -5,9 +5,11 @@
|
||||
|
||||
package net.minecraftforge.common;
|
||||
|
||||
import net.minecraft.commands.synchronization.EmptyArgumentSerializer;
|
||||
import net.minecraft.commands.synchronization.ArgumentTypes;
|
||||
import net.minecraft.commands.synchronization.ArgumentSerializer;
|
||||
import net.minecraft.commands.synchronization.ArgumentTypeInfo;
|
||||
import net.minecraft.commands.synchronization.ArgumentTypeInfos;
|
||||
import net.minecraft.commands.synchronization.SingletonArgumentInfo;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.ai.attributes.Attribute;
|
||||
import net.minecraft.world.entity.ai.attributes.RangedAttribute;
|
||||
import net.minecraft.world.item.crafting.Ingredient;
|
||||
@@ -16,7 +18,6 @@ import net.minecraft.world.item.Items;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.ForgeHooksClient;
|
||||
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
||||
import net.minecraftforge.common.capabilities.RegisterCapabilitiesEvent;
|
||||
import net.minecraftforge.common.crafting.PartialNBTIngredient;
|
||||
@@ -28,20 +29,20 @@ import net.minecraftforge.common.data.ForgeFluidTagsProvider;
|
||||
import net.minecraftforge.common.extensions.IForgeEntity;
|
||||
import net.minecraftforge.common.extensions.IForgePlayer;
|
||||
import net.minecraftforge.common.loot.CanToolPerformAction;
|
||||
import net.minecraftforge.common.loot.GlobalLootModifierSerializer;
|
||||
import net.minecraftforge.common.loot.LootTableIdCondition;
|
||||
import net.minecraftforge.common.world.BiomeModifier;
|
||||
import net.minecraftforge.common.world.NoneBiomeModifier;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fluids.FluidAttributes;
|
||||
import net.minecraftforge.fluids.ForgeFlowingFluid;
|
||||
import net.minecraftforge.fml.*;
|
||||
import net.minecraftforge.fml.config.ModConfig;
|
||||
import net.minecraftforge.fml.event.lifecycle.*;
|
||||
import net.minecraftforge.fml.loading.FMLEnvironment;
|
||||
import net.minecraftforge.registries.*;
|
||||
import net.minecraftforge.network.NetworkConstants;
|
||||
import net.minecraftforge.event.server.ServerStoppingEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.fml.loading.FMLEnvironment;
|
||||
import net.minecraftforge.forge.event.lifecycle.GatherDataEvent;
|
||||
import net.minecraftforge.network.filters.VanillaPacketSplitter;
|
||||
import net.minecraftforge.server.command.EnumArgument;
|
||||
@@ -53,8 +54,6 @@ import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.world.item.crafting.Recipe;
|
||||
import net.minecraft.world.item.crafting.RecipeSerializer;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.common.crafting.CompoundIngredient;
|
||||
import net.minecraftforge.common.crafting.ConditionalRecipe;
|
||||
@@ -74,13 +73,14 @@ import net.minecraftforge.common.data.ForgeItemTagsProvider;
|
||||
import net.minecraftforge.common.data.ForgeLootTableProvider;
|
||||
import net.minecraftforge.common.data.ForgeRecipeProvider;
|
||||
import net.minecraftforge.energy.CapabilityEnergy;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import org.apache.logging.log4j.Marker;
|
||||
import org.apache.logging.log4j.MarkerManager;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Mod("forge")
|
||||
@@ -91,6 +91,15 @@ public class ForgeMod
|
||||
private static final Marker FORGEMOD = MarkerManager.getMarker("FORGEMOD");
|
||||
|
||||
private static final DeferredRegister<Attribute> ATTRIBUTES = DeferredRegister.create(ForgeRegistries.Keys.ATTRIBUTES, "forge");
|
||||
private static final DeferredRegister<ArgumentTypeInfo<?, ?>> COMMAND_ARGUMENT_TYPES = DeferredRegister.create(Registry.COMMAND_ARGUMENT_TYPE_REGISTRY, "forge");
|
||||
private static final DeferredRegister<Codec<? extends BiomeModifier>> BIOME_MODIFIER_SERIALIZERS = DeferredRegister.create(ForgeRegistries.Keys.BIOME_MODIFIER_SERIALIZERS, "forge");
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
private static final RegistryObject<EnumArgument.Info> ENUM_COMMAND_ARGUMENT_TYPE = COMMAND_ARGUMENT_TYPES.register("enum", () ->
|
||||
ArgumentTypeInfos.registerByClass(EnumArgument.class, new EnumArgument.Info()));
|
||||
private static final RegistryObject<SingletonArgumentInfo<ModIdArgument>> MODID_COMMAND_ARGUMENT_TYPE = COMMAND_ARGUMENT_TYPES.register("modid", () ->
|
||||
ArgumentTypeInfos.registerByClass(ModIdArgument.class,
|
||||
SingletonArgumentInfo.contextFree(ModIdArgument::modIdArgument)));
|
||||
|
||||
public static final RegistryObject<Attribute> SWIM_SPEED = ATTRIBUTES.register("swim_speed", () -> new RangedAttribute("forge.swimSpeed", 1.0D, 0.0D, 1024.0D).setSyncable(true));
|
||||
public static final RegistryObject<Attribute> NAMETAG_DISTANCE = ATTRIBUTES.register("nametag_distance", () -> new RangedAttribute("forge.nameTagDistance", 64.0D, 0.0D, 64.0).setSyncable(true));
|
||||
@@ -117,6 +126,11 @@ public class ForgeMod
|
||||
*/
|
||||
public static final RegistryObject<Attribute> STEP_HEIGHT_ADDITION = ATTRIBUTES.register("step_height_addition", () -> new RangedAttribute("forge.stepHeight", 0.0D, -512.0D, 512.0D).setSyncable(true));
|
||||
|
||||
/**
|
||||
* Noop biome modifier. Can be used in a biome modifier json with "type": "forge:none".
|
||||
*/
|
||||
public static final RegistryObject<Codec<NoneBiomeModifier>> NONE_BIOME_MODIFIER_TYPE = BIOME_MODIFIER_SERIALIZERS.register("none", () -> Codec.unit(NoneBiomeModifier.INSTANCE));
|
||||
|
||||
|
||||
private static boolean enableMilkFluid = false;
|
||||
public static final RegistryObject<Fluid> MILK = RegistryObject.create(new ResourceLocation("milk"), ForgeRegistries.FLUIDS);
|
||||
@@ -156,11 +170,15 @@ public class ForgeMod
|
||||
modEventBus.addListener(this::preInit);
|
||||
modEventBus.addListener(this::gatherData);
|
||||
modEventBus.addListener(this::loadComplete);
|
||||
modEventBus.addGenericListener(Fluid.class, this::registerFluids);
|
||||
modEventBus.addListener(this::registerFluids);
|
||||
modEventBus.addListener(this::registerRecipeSerializers);
|
||||
modEventBus.addListener(this::registerLootData);
|
||||
modEventBus.register(this);
|
||||
ATTRIBUTES.register(modEventBus);
|
||||
COMMAND_ARGUMENT_TYPES.register(modEventBus);
|
||||
BIOME_MODIFIER_SERIALIZERS.register(modEventBus);
|
||||
MinecraftForge.EVENT_BUS.addListener(this::serverStopping);
|
||||
MinecraftForge.EVENT_BUS.addGenericListener(SoundEvent.class, this::missingSoundMapping);
|
||||
MinecraftForge.EVENT_BUS.addListener(this::missingSoundMapping);
|
||||
ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, ForgeConfig.clientSpec);
|
||||
ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, ForgeConfig.serverSpec);
|
||||
ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, ForgeConfig.commonSpec);
|
||||
@@ -173,9 +191,8 @@ public class ForgeMod
|
||||
MinecraftForge.EVENT_BUS.addListener(VillagerTradingManager::loadTrades);
|
||||
MinecraftForge.EVENT_BUS.register(MinecraftForge.INTERNAL_HANDLER);
|
||||
MinecraftForge.EVENT_BUS.addListener(this::mappingChanged);
|
||||
BiomeDictionary.init();
|
||||
|
||||
ForgeRegistries.ITEMS.tags().addOptionalTagDefaults(Tags.Items.ENCHANTING_FUELS, Set.of(Items.LAPIS_LAZULI.delegate));
|
||||
ForgeRegistries.ITEMS.tags().addOptionalTagDefaults(Tags.Items.ENCHANTING_FUELS, Set.of(ForgeRegistries.ITEMS.getDelegateOrThrow(Items.LAPIS_LAZULI)));
|
||||
|
||||
if (FMLEnvironment.dist == Dist.CLIENT)
|
||||
{
|
||||
@@ -193,22 +210,11 @@ public class ForgeMod
|
||||
public void preInit(FMLCommonSetupEvent evt)
|
||||
{
|
||||
VersionChecker.startVersionCheck();
|
||||
|
||||
registerArgumentTypes();
|
||||
VanillaPacketSplitter.register();
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
private void registerArgumentTypes()
|
||||
{
|
||||
ArgumentTypes.register("forge:enum", EnumArgument.class, (ArgumentSerializer) new EnumArgument.Serializer());
|
||||
ArgumentTypes.register("forge:modid", ModIdArgument.class, new EmptyArgumentSerializer<>(ModIdArgument::modIdArgument));
|
||||
}
|
||||
|
||||
public void loadComplete(FMLLoadCompleteEvent event)
|
||||
{
|
||||
if (FMLEnvironment.dist == Dist.CLIENT)
|
||||
ForgeHooksClient.registerForgeWorldPresetScreens();
|
||||
}
|
||||
|
||||
public void serverStopping(ServerStoppingEvent evt)
|
||||
@@ -216,7 +222,7 @@ public class ForgeMod
|
||||
WorldWorkerManager.clear();
|
||||
}
|
||||
|
||||
public void mappingChanged(RegistryEvent.IdMappingEvent evt)
|
||||
public void mappingChanged(IdMappingEvent evt)
|
||||
{
|
||||
Ingredient.invalidateAll();
|
||||
}
|
||||
@@ -225,26 +231,26 @@ public class ForgeMod
|
||||
{
|
||||
DataGenerator gen = event.getGenerator();
|
||||
|
||||
if (event.includeServer())
|
||||
{
|
||||
ExistingFileHelper existingFileHelper = event.getExistingFileHelper();
|
||||
ForgeBlockTagsProvider blockTags = new ForgeBlockTagsProvider(gen, existingFileHelper);
|
||||
gen.addProvider(blockTags);
|
||||
gen.addProvider(new ForgeItemTagsProvider(gen, blockTags, existingFileHelper));
|
||||
gen.addProvider(new ForgeFluidTagsProvider(gen, existingFileHelper));
|
||||
gen.addProvider(new ForgeRecipeProvider(gen));
|
||||
gen.addProvider(new ForgeLootTableProvider(gen));
|
||||
gen.addProvider(new ForgeBiomeTagsProvider(gen, existingFileHelper));
|
||||
}
|
||||
ExistingFileHelper existingFileHelper = event.getExistingFileHelper();
|
||||
ForgeBlockTagsProvider blockTags = new ForgeBlockTagsProvider(gen, existingFileHelper);
|
||||
gen.addProvider(event.includeServer(), blockTags);
|
||||
gen.addProvider(event.includeServer(), new ForgeItemTagsProvider(gen, blockTags, existingFileHelper));
|
||||
gen.addProvider(event.includeServer(), new ForgeFluidTagsProvider(gen, existingFileHelper));
|
||||
gen.addProvider(event.includeServer(), new ForgeRecipeProvider(gen));
|
||||
gen.addProvider(event.includeServer(), new ForgeLootTableProvider(gen));
|
||||
gen.addProvider(event.includeServer(), new ForgeBiomeTagsProvider(gen, existingFileHelper));
|
||||
}
|
||||
|
||||
public void missingSoundMapping(RegistryEvent.MissingMappings<SoundEvent> event)
|
||||
public void missingSoundMapping(MissingMappingsEvent event)
|
||||
{
|
||||
if (event.getKey() != ForgeRegistries.Keys.SOUND_EVENTS)
|
||||
return;
|
||||
|
||||
//Removed in 1.15, see https://minecraft.gamepedia.com/Parrot#History
|
||||
List<String> removedSounds = Arrays.asList("entity.parrot.imitate.panda", "entity.parrot.imitate.zombie_pigman", "entity.parrot.imitate.enderman", "entity.parrot.imitate.polar_bear", "entity.parrot.imitate.wolf");
|
||||
for (RegistryEvent.MissingMappings.Mapping<SoundEvent> mapping : event.getAllMappings())
|
||||
for (MissingMappingsEvent.Mapping<SoundEvent> mapping : event.getAllMappings(ForgeRegistries.Keys.SOUND_EVENTS))
|
||||
{
|
||||
ResourceLocation regName = mapping.key;
|
||||
ResourceLocation regName = mapping.getKey();
|
||||
if (regName != null && regName.getNamespace().equals("minecraft"))
|
||||
{
|
||||
String path = regName.getPath();
|
||||
@@ -258,48 +264,49 @@ public class ForgeMod
|
||||
}
|
||||
|
||||
// done in an event instead of deferred to only enable if a mod requests it
|
||||
public void registerFluids(RegistryEvent.Register<Fluid> event)
|
||||
public void registerFluids(RegisterEvent event)
|
||||
{
|
||||
if (enableMilkFluid)
|
||||
if (enableMilkFluid && event.getRegistryKey().equals(ForgeRegistries.Keys.FLUIDS))
|
||||
{
|
||||
// set up attributes
|
||||
FluidAttributes.Builder attributesBuilder = FluidAttributes.builder(new ResourceLocation("forge", "block/milk_still"), new ResourceLocation("forge", "block/milk_flowing")).density(1024).viscosity(1024);
|
||||
ForgeFlowingFluid.Properties properties = new ForgeFlowingFluid.Properties(MILK, FLOWING_MILK, attributesBuilder).bucket(() -> Items.MILK_BUCKET);
|
||||
// register fluids
|
||||
event.getRegistry().register(new ForgeFlowingFluid.Source(properties).setRegistryName(MILK.getId()));
|
||||
event.getRegistry().register(new ForgeFlowingFluid.Flowing(properties).setRegistryName(FLOWING_MILK.getId()));
|
||||
event.register(ForgeRegistries.Keys.FLUIDS, MILK.getId(), () -> new ForgeFlowingFluid.Source(properties));
|
||||
event.register(ForgeRegistries.Keys.FLUIDS, FLOWING_MILK.getId(), () -> new ForgeFlowingFluid.Flowing(properties));
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent //ModBus, can't use addListener due to nested genetics.
|
||||
public void registerRecipeSerialziers(RegistryEvent.Register<RecipeSerializer<?>> event)
|
||||
public void registerRecipeSerializers(RegisterEvent event)
|
||||
{
|
||||
CraftingHelper.register(AndCondition.Serializer.INSTANCE);
|
||||
CraftingHelper.register(FalseCondition.Serializer.INSTANCE);
|
||||
CraftingHelper.register(ItemExistsCondition.Serializer.INSTANCE);
|
||||
CraftingHelper.register(ModLoadedCondition.Serializer.INSTANCE);
|
||||
CraftingHelper.register(NotCondition.Serializer.INSTANCE);
|
||||
CraftingHelper.register(OrCondition.Serializer.INSTANCE);
|
||||
CraftingHelper.register(TrueCondition.Serializer.INSTANCE);
|
||||
CraftingHelper.register(TagEmptyCondition.Serializer.INSTANCE);
|
||||
if (event.getRegistryKey().equals(ForgeRegistries.Keys.RECIPE_SERIALIZERS))
|
||||
{
|
||||
CraftingHelper.register(AndCondition.Serializer.INSTANCE);
|
||||
CraftingHelper.register(FalseCondition.Serializer.INSTANCE);
|
||||
CraftingHelper.register(ItemExistsCondition.Serializer.INSTANCE);
|
||||
CraftingHelper.register(ModLoadedCondition.Serializer.INSTANCE);
|
||||
CraftingHelper.register(NotCondition.Serializer.INSTANCE);
|
||||
CraftingHelper.register(OrCondition.Serializer.INSTANCE);
|
||||
CraftingHelper.register(TrueCondition.Serializer.INSTANCE);
|
||||
CraftingHelper.register(TagEmptyCondition.Serializer.INSTANCE);
|
||||
|
||||
CraftingHelper.register(new ResourceLocation("forge", "compound"), CompoundIngredient.Serializer.INSTANCE);
|
||||
CraftingHelper.register(new ResourceLocation("forge", "nbt"), NBTIngredient.Serializer.INSTANCE);
|
||||
CraftingHelper.register(new ResourceLocation("forge", "partial_nbt"), PartialNBTIngredient.Serializer.INSTANCE);
|
||||
CraftingHelper.register(new ResourceLocation("forge", "difference"), DifferenceIngredient.Serializer.INSTANCE);
|
||||
CraftingHelper.register(new ResourceLocation("forge", "intersection"), IntersectionIngredient.Serializer.INSTANCE);
|
||||
CraftingHelper.register(new ResourceLocation("minecraft", "item"), VanillaIngredientSerializer.INSTANCE);
|
||||
|
||||
event.getRegistry().register(new ConditionalRecipe.Serializer<Recipe<?>>().setRegistryName(new ResourceLocation("forge", "conditional")));
|
||||
CraftingHelper.register(new ResourceLocation("forge", "compound"), CompoundIngredient.Serializer.INSTANCE);
|
||||
CraftingHelper.register(new ResourceLocation("forge", "nbt"), NBTIngredient.Serializer.INSTANCE);
|
||||
CraftingHelper.register(new ResourceLocation("forge", "partial_nbt"), PartialNBTIngredient.Serializer.INSTANCE);
|
||||
CraftingHelper.register(new ResourceLocation("forge", "difference"), DifferenceIngredient.Serializer.INSTANCE);
|
||||
CraftingHelper.register(new ResourceLocation("forge", "intersection"), IntersectionIngredient.Serializer.INSTANCE);
|
||||
CraftingHelper.register(new ResourceLocation("minecraft", "item"), VanillaIngredientSerializer.INSTANCE);
|
||||
|
||||
event.register(ForgeRegistries.Keys.RECIPE_SERIALIZERS, new ResourceLocation("forge", "conditional"), ConditionalRecipe.Serializer::new);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent //ModBus
|
||||
@SuppressWarnings("unused") // automatically called by Forge
|
||||
public void registerLootData(RegistryEvent.Register<GlobalLootModifierSerializer<?>> event)
|
||||
public void registerLootData(RegisterEvent event)
|
||||
{
|
||||
// Ignore the event itself: this is done only not to statically initialize our custom LootConditionType
|
||||
Registry.register(Registry.LOOT_CONDITION_TYPE, new ResourceLocation("forge:loot_table_id"), LootTableIdCondition.LOOT_TABLE_ID);
|
||||
Registry.register(Registry.LOOT_CONDITION_TYPE, new ResourceLocation("forge:can_tool_perform_action"), CanToolPerformAction.LOOT_CONDITION_TYPE);
|
||||
if (!event.getRegistryKey().equals(Registry.LOOT_ITEM_REGISTRY))
|
||||
return;
|
||||
|
||||
event.register(Registry.LOOT_ITEM_REGISTRY, new ResourceLocation("forge:loot_table_id"), () -> LootTableIdCondition.LOOT_TABLE_ID);
|
||||
event.register(Registry.LOOT_ITEM_REGISTRY, new ResourceLocation("forge:can_tool_perform_action"), () -> CanToolPerformAction.LOOT_CONDITION_TYPE);
|
||||
}
|
||||
}
|
||||
@@ -21,8 +21,8 @@ import net.minecraftforge.eventbus.api.EventPriority;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.List;
|
||||
@@ -81,7 +81,7 @@ public class ForgeSpawnEggItem extends SpawnEggItem
|
||||
}
|
||||
|
||||
stack.shrink(1);
|
||||
source.getLevel().gameEvent(GameEvent.ENTITY_PLACE, source.getPos());
|
||||
source.getLevel().gameEvent(GameEvent.ENTITY_PLACE, source.getPos(), GameEvent.Context.of(source.getBlockState()));
|
||||
return stack;
|
||||
};
|
||||
|
||||
|
||||
@@ -5,57 +5,30 @@
|
||||
|
||||
package net.minecraftforge.common;
|
||||
|
||||
import java.util.List;
|
||||
import net.minecraftforge.common.capabilities.CapabilityManager;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.fml.*;
|
||||
import net.minecraftforge.fml.event.IModBusEvent;
|
||||
import net.minecraftforge.fml.IModLoadingState;
|
||||
import net.minecraftforge.fml.IModStateProvider;
|
||||
import net.minecraftforge.fml.ModLoadingPhase;
|
||||
import net.minecraftforge.fml.ModLoadingState;
|
||||
import net.minecraftforge.network.NetworkRegistry;
|
||||
import net.minecraftforge.registries.GameData;
|
||||
import net.minecraftforge.registries.ObjectHolderRegistry;
|
||||
import net.minecraftforge.registries.RegistryManager;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Stream;
|
||||
public class ForgeStatesProvider implements IModStateProvider
|
||||
{
|
||||
final ModLoadingState CREATE_REGISTRIES = ModLoadingState.withInline("CREATE_REGISTRIES", "CONSTRUCT", ModLoadingPhase.GATHER, ml -> RegistryManager.postNewRegistryEvent());
|
||||
final ModLoadingState OBJECT_HOLDERS = ModLoadingState.withInline("OBJECT_HOLDERS", "CREATE_REGISTRIES", ModLoadingPhase.GATHER, ml -> ObjectHolderRegistry.findObjectHolders());
|
||||
final ModLoadingState INJECT_CAPABILITIES = ModLoadingState.withInline("INJECT_CAPABILITIES", "OBJECT_HOLDERS", ModLoadingPhase.GATHER, ml -> CapabilityManager.INSTANCE.injectCapabilities(ml.getAllScanData()));
|
||||
final ModLoadingState UNFREEZE = ModLoadingState.withInline("UNFREEZE_DATA", "INJECT_CAPABILITIES", ModLoadingPhase.GATHER, ml -> GameData.unfreezeData());
|
||||
final ModLoadingState LOAD_REGISTRIES = ModLoadingState.withInline("LOAD_REGISTRIES", "UNFREEZE_DATA", ModLoadingPhase.GATHER, ml -> GameData.postRegisterEvents());
|
||||
final ModLoadingState FREEZE = ModLoadingState.withInline("FREEZE_DATA", "COMPLETE", ModLoadingPhase.COMPLETE, ml -> GameData.freezeData());
|
||||
final ModLoadingState NETLOCK = ModLoadingState.withInline("NETWORK_LOCK", "FREEZE_DATA", ModLoadingPhase.COMPLETE, ml -> NetworkRegistry.lock());
|
||||
|
||||
public class ForgeStatesProvider implements IModStateProvider {
|
||||
final ModLoadingState CREATE_REGISTRIES = ModLoadingState.withTransition("CREATE_REGISTRIES", "CONSTRUCT", ModLoadingPhase.GATHER, new SerialTransition<>(() -> Stream.of(IModStateTransition.EventGenerator.fromFunction(RegistryManager.newRegistryEventGenerator())), RegistryManager::preNewRegistryEvent, RegistryManager::postNewRegistryEvent, (e, prev) -> prev.thenApplyAsync(Function.identity(), e)));
|
||||
final ModLoadingState OBJECT_HOLDERS = ModLoadingState.withInline("OBJECT_HOLDERS", "CREATE_REGISTRIES", ModLoadingPhase.GATHER, ml-> ObjectHolderRegistry.findObjectHolders());
|
||||
final ModLoadingState INJECT_CAPABILITIES = ModLoadingState.withInline("INJECT_CAPABILITIES", "OBJECT_HOLDERS", ModLoadingPhase.GATHER, ml-> CapabilityManager.INSTANCE.injectCapabilities(ml.getAllScanData()));
|
||||
final ModLoadingState UNFREEZE = ModLoadingState.withInline("UNFREEZE_DATA", "INJECT_CAPABILITIES", ModLoadingPhase.GATHER, ml->GameData.unfreezeData());
|
||||
final ModLoadingState LOAD_REGISTRIES = ModLoadingState.withTransition("LOAD_REGISTRIES", "UNFREEZE_DATA", ModLoadingPhase.GATHER, new SerialTransition<RegistryEvent.Register<?>>(GameData::generateRegistryEvents, GameData::preRegistryEventDispatch, GameData::postRegistryEventDispatch, GameData::checkForRevertToVanilla));
|
||||
final ModLoadingState FREEZE = ModLoadingState.withInline("FREEZE_DATA", "COMPLETE", ModLoadingPhase.COMPLETE, ml->GameData.freezeData());
|
||||
final ModLoadingState NETLOCK = ModLoadingState.withInline("NETWORK_LOCK", "FREEZE_DATA", ModLoadingPhase.COMPLETE, ml-> NetworkRegistry.lock());
|
||||
@Override
|
||||
public List<IModLoadingState> getAllStates() {
|
||||
public List<IModLoadingState> getAllStates()
|
||||
{
|
||||
return List.of(CREATE_REGISTRIES, OBJECT_HOLDERS, INJECT_CAPABILITIES, UNFREEZE, LOAD_REGISTRIES, FREEZE, NETLOCK);
|
||||
}
|
||||
|
||||
// TODO 1.19: Pass the event instances to the pre and post hooks rather than the event generators
|
||||
static record SerialTransition<T extends Event & IModBusEvent>(Supplier<Stream<EventGenerator<?>>> eventStream, BiFunction<Executor, ? extends EventGenerator<T>, CompletableFuture<List<Throwable>>> preDispatchHook, BiFunction<Executor, ? extends EventGenerator<T>, CompletableFuture<List<Throwable>>> postDispatchHook, BiFunction<Executor, CompletableFuture<List<Throwable>>, CompletableFuture<List<Throwable>>> finalActivityGenerator) implements IModStateTransition {
|
||||
public static <T extends Event & IModBusEvent> SerialTransition<T> of(Supplier<Stream<EventGenerator<?>>> eventStream) {
|
||||
return new SerialTransition<T>(eventStream, (t, f)->CompletableFuture.completedFuture(Collections.emptyList()), (t, f)->CompletableFuture.completedFuture(Collections.emptyList()), (e, prev) ->prev.thenApplyAsync(Function.identity(), e));
|
||||
}
|
||||
@Override
|
||||
public Supplier<Stream<EventGenerator<?>>> eventFunctionStream() {
|
||||
return eventStream;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ThreadSelector threadSelector() {
|
||||
return ThreadSelector.SYNC;
|
||||
}
|
||||
|
||||
// These never progress the ModLoadingStage..
|
||||
@Override
|
||||
public BiFunction<ModLoadingStage, Throwable, ModLoadingStage> nextModLoadingStage() {
|
||||
return ModLoadingStage::currentState;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,9 +9,8 @@ import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.item.Tier;
|
||||
import net.minecraft.world.item.crafting.Ingredient;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
@@ -25,13 +24,13 @@ public final class ForgeTier implements Tier
|
||||
private final float speed;
|
||||
private final float attackDamageBonus;
|
||||
private final int enchantmentValue;
|
||||
@Nonnull
|
||||
@NotNull
|
||||
private final TagKey<Block> tag;
|
||||
@Nonnull
|
||||
@NotNull
|
||||
private final Supplier<Ingredient> repairIngredient;
|
||||
|
||||
public ForgeTier(int level, int uses, float speed, float attackDamageBonus, int enchantmentValue,
|
||||
@Nonnull TagKey<Block> tag, @Nonnull Supplier<Ingredient> repairIngredient)
|
||||
@NotNull TagKey<Block> tag, @NotNull Supplier<Ingredient> repairIngredient)
|
||||
{
|
||||
this.level = level;
|
||||
this.uses = uses;
|
||||
@@ -72,13 +71,13 @@ public final class ForgeTier implements Tier
|
||||
return this.enchantmentValue;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@NotNull
|
||||
public TagKey<Block> getTag()
|
||||
{
|
||||
return this.tag;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@NotNull
|
||||
@Override
|
||||
public Ingredient getRepairIngredient()
|
||||
{
|
||||
|
||||
@@ -22,14 +22,14 @@ import java.util.function.Supplier;
|
||||
* <p>
|
||||
* For example, an enum with the constructor {@code MyEnum(Object foo)} would
|
||||
* require the method:
|
||||
*
|
||||
*
|
||||
* <pre>
|
||||
* public static MyEnum create(String name, Object foo)
|
||||
* {
|
||||
* throw new IllegalStateException("Enum not extended");
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* The method contents will be replaced with ASM at runtime. Multiple
|
||||
* {@code create} methods <strong>can</strong> be defined as long as each
|
||||
* matches a constructor.
|
||||
@@ -44,7 +44,7 @@ public interface IExtensibleEnum
|
||||
default void init() {}
|
||||
|
||||
/**
|
||||
* Use this instead of {@link StringRepresentable#fromEnum(Supplier, Function)} for extensible enums because this not cache the enum values on construction
|
||||
* Use this instead of {@link StringRepresentable#fromEnum(Supplier)} for extensible enums because this not cache the enum values on construction
|
||||
*/
|
||||
static <E extends Enum<E> & StringRepresentable> Codec<E> createCodecForExtensibleEnum(Supplier<E[]> valuesSupplier, Function<? super String, ? extends E> enumValueFromNameFunction) {
|
||||
return Codec.either(Codec.STRING, Codec.INT).comapFlatMap(
|
||||
|
||||
@@ -12,9 +12,8 @@ import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -35,7 +34,7 @@ public interface IForgeShearable
|
||||
* @param pos Block's position in level.
|
||||
* @return If this is shearable, and onSheared should be called.
|
||||
*/
|
||||
default boolean isShearable(@Nonnull ItemStack item, Level level, BlockPos pos)
|
||||
default boolean isShearable(@NotNull ItemStack item, Level level, BlockPos pos)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -58,8 +57,8 @@ public interface IForgeShearable
|
||||
* @param fortune The fortune level of the shears being used.
|
||||
* @return A List containing all items from this shearing. May be empty.
|
||||
*/
|
||||
@Nonnull
|
||||
default List<ItemStack> onSheared(@Nullable Player player, @Nonnull ItemStack item, Level level, BlockPos pos, int fortune)
|
||||
@NotNull
|
||||
default List<ItemStack> onSheared(@Nullable Player player, @NotNull ItemStack item, Level level, BlockPos pos, int fortune)
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@@ -19,10 +19,6 @@ import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.material.Fluid;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Set;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class Tags
|
||||
{
|
||||
public static void init ()
|
||||
|
||||
@@ -41,11 +41,10 @@ import net.minecraftforge.network.simple.SimpleChannel;
|
||||
import net.minecraftforge.server.ServerLifecycleHooks;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -246,14 +245,15 @@ public class TierSortingRegistry
|
||||
{
|
||||
final Gson gson = (new GsonBuilder()).create();
|
||||
|
||||
@Nonnull
|
||||
@NotNull
|
||||
@Override
|
||||
protected JsonObject prepare(@Nonnull ResourceManager resourceManager, ProfilerFiller p)
|
||||
protected JsonObject prepare(@NotNull ResourceManager resourceManager, ProfilerFiller p)
|
||||
{
|
||||
if (!resourceManager.hasResource(ITEM_TIER_ORDERING_JSON))
|
||||
Optional<Resource> res = resourceManager.getResource(ITEM_TIER_ORDERING_JSON);
|
||||
if (res.isEmpty())
|
||||
return new JsonObject();
|
||||
|
||||
try (Resource r = resourceManager.getResource(ITEM_TIER_ORDERING_JSON); InputStream stream = r.getInputStream(); Reader reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8)))
|
||||
try (Reader reader = res.get().openAsReader())
|
||||
{
|
||||
return gson.fromJson(reader, JsonObject.class);
|
||||
}
|
||||
@@ -265,7 +265,7 @@ public class TierSortingRegistry
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void apply(@Nonnull JsonObject data, @Nonnull ResourceManager resourceManager, ProfilerFiller p)
|
||||
protected void apply(@NotNull JsonObject data, @NotNull ResourceManager resourceManager, ProfilerFiller p)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -16,8 +16,6 @@ import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import net.minecraftforge.fml.loading.FMLLoader;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@@ -30,6 +28,7 @@ import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import org.apache.logging.log4j.Marker;
|
||||
import org.apache.logging.log4j.MarkerManager;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Caches player's last known usernames
|
||||
|
||||
@@ -7,14 +7,13 @@ package net.minecraftforge.common.brewing;
|
||||
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.crafting.Ingredient;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class BrewingRecipe implements IBrewingRecipe
|
||||
{
|
||||
@Nonnull private final Ingredient input;
|
||||
@Nonnull private final Ingredient ingredient;
|
||||
@Nonnull private final ItemStack output;
|
||||
@NotNull private final Ingredient input;
|
||||
@NotNull private final Ingredient ingredient;
|
||||
@NotNull private final ItemStack output;
|
||||
|
||||
public BrewingRecipe(Ingredient input, Ingredient ingredient, ItemStack output)
|
||||
{
|
||||
@@ -24,7 +23,7 @@ public class BrewingRecipe implements IBrewingRecipe
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInput(@Nonnull ItemStack stack)
|
||||
public boolean isInput(@NotNull ItemStack stack)
|
||||
{
|
||||
return this.input.test(stack);
|
||||
}
|
||||
|
||||
@@ -6,13 +6,12 @@
|
||||
package net.minecraftforge.common.capabilities;
|
||||
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* This is the core holder object Capabilities.
|
||||
* Each capability will have ONE instance of this class,
|
||||
@@ -28,7 +27,7 @@ public class Capability<T>
|
||||
*/
|
||||
public String getName() { return name; }
|
||||
|
||||
public @Nonnull <R> LazyOptional<R> orEmpty(Capability<R> toCheck, LazyOptional<T> inst)
|
||||
public @NotNull <R> LazyOptional<R> orEmpty(Capability<R> toCheck, LazyOptional<T> inst)
|
||||
{
|
||||
return this == toCheck ? inst.cast() : LazyOptional.empty();
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
package net.minecraftforge.common.capabilities;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import java.util.List;
|
||||
@@ -21,6 +20,7 @@ import net.minecraft.core.Direction;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.common.util.INBTSerializable;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* A high-speed implementation of a capability delegator.
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
|
||||
package net.minecraftforge.common.capabilities;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
@@ -17,6 +15,7 @@ import net.minecraft.world.level.chunk.LevelChunk;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@@ -27,7 +26,7 @@ public abstract class CapabilityProvider<B extends ICapabilityProviderImpl<B>> i
|
||||
@VisibleForTesting
|
||||
static boolean SUPPORTS_LAZY_CAPABILITIES = true;
|
||||
|
||||
private final @Nonnull Class<B> baseClass;
|
||||
private final @NotNull Class<B> baseClass;
|
||||
private @Nullable CapabilityDispatcher capabilities;
|
||||
private boolean valid = true;
|
||||
|
||||
@@ -176,8 +175,8 @@ public abstract class CapabilityProvider<B extends ICapabilityProviderImpl<B>> i
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side)
|
||||
@NotNull
|
||||
public <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable Direction side)
|
||||
{
|
||||
final CapabilityDispatcher disp = getCapabilities();
|
||||
return !valid || disp == null ? LazyOptional.empty() : disp.getCapability(cap, side);
|
||||
|
||||
@@ -5,11 +5,10 @@
|
||||
|
||||
package net.minecraftforge.common.capabilities;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface ICapabilityProvider
|
||||
{
|
||||
@@ -24,13 +23,13 @@ public interface ICapabilityProvider
|
||||
* <strong>CAN BE NULL</strong>. Null is defined to represent 'internal' or 'self'
|
||||
* @return The requested an optional holding the requested capability.
|
||||
*/
|
||||
@Nonnull <T> LazyOptional<T> getCapability(@Nonnull final Capability<T> cap, final @Nullable Direction side);
|
||||
@NotNull <T> LazyOptional<T> getCapability(@NotNull final Capability<T> cap, final @Nullable Direction side);
|
||||
|
||||
/*
|
||||
* Purely added as a bouncer to sided version, to make modders stop complaining about calling with a null value.
|
||||
* This should never be OVERRIDDEN, modders should only ever implement the sided version.
|
||||
*/
|
||||
@Nonnull default <T> LazyOptional<T> getCapability(@Nonnull final Capability<T> cap) {
|
||||
@NotNull default <T> LazyOptional<T> getCapability(@NotNull final Capability<T> cap) {
|
||||
return getCapability(cap, null);
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
package net.minecraftforge.common.capabilities;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface ICapabilityProviderImpl<B extends ICapabilityProviderImpl<B>> extends ICapabilityProvider
|
||||
{
|
||||
|
||||
@@ -12,8 +12,8 @@ import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.crafting.Ingredient;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,10 +12,6 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
@@ -28,6 +24,8 @@ import it.unimi.dsi.fastutil.ints.IntList;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.crafting.Ingredient;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/** Ingredient that matches if any of the child ingredients match */
|
||||
public class CompoundIngredient extends AbstractIngredient
|
||||
@@ -69,7 +67,7 @@ public class CompoundIngredient extends AbstractIngredient
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
@NotNull
|
||||
public ItemStack[] getItems()
|
||||
{
|
||||
if (stacks == null)
|
||||
@@ -84,7 +82,7 @@ public class CompoundIngredient extends AbstractIngredient
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
@NotNull
|
||||
public IntList getStackingIds()
|
||||
{
|
||||
boolean childrenNeedInvalidation = false;
|
||||
@@ -132,7 +130,7 @@ public class CompoundIngredient extends AbstractIngredient
|
||||
return Serializer.INSTANCE;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@NotNull
|
||||
public Collection<Ingredient> getChildren()
|
||||
{
|
||||
return this.children;
|
||||
|
||||
@@ -19,8 +19,7 @@ import net.minecraft.advancements.Advancement;
|
||||
import net.minecraft.data.recipes.FinishedRecipe;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import net.minecraftforge.common.crafting.conditions.ICondition;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class ConditionalAdvancement
|
||||
{
|
||||
@@ -29,15 +28,6 @@ public class ConditionalAdvancement
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Please use {@linkplain #processConditional(JsonObject, ICondition.IContext) the more general overload}.
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "1.18.2")
|
||||
@Nullable
|
||||
public static JsonObject processConditional(JsonObject json) {
|
||||
return processConditional(json, ICondition.IContext.EMPTY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the conditional advancement during loading.
|
||||
* @param json The incoming json from the advancement file.
|
||||
|
||||
@@ -23,12 +23,11 @@ import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.common.crafting.conditions.ICondition;
|
||||
import net.minecraftforge.registries.ObjectHolder;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class ConditionalRecipe
|
||||
{
|
||||
@ObjectHolder("forge:conditional")
|
||||
@ObjectHolder(registryName = "recipe_serializer", value = "forge:conditional")
|
||||
public static final RecipeSerializer<Recipe<?>> SERIALZIER = null;
|
||||
|
||||
public static Builder builder()
|
||||
@@ -38,33 +37,6 @@ public class ConditionalRecipe
|
||||
|
||||
public static class Serializer<T extends Recipe<?>> implements RecipeSerializer<T>
|
||||
{
|
||||
private ResourceLocation name;
|
||||
|
||||
@Override
|
||||
public RecipeSerializer<?> setRegistryName(ResourceLocation name)
|
||||
{
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getRegistryName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<RecipeSerializer<?>> getRegistryType()
|
||||
{
|
||||
return Serializer.<RecipeSerializer<?>>castClass(RecipeSerializer.class);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked") // Need this wrapper, because generics
|
||||
private static <G> Class<G> castClass(Class<?> cls)
|
||||
{
|
||||
return (Class<G>)cls;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T fromJson(ResourceLocation recipeId, JsonObject json)
|
||||
{
|
||||
|
||||
@@ -10,8 +10,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.google.common.collect.Lists;
|
||||
@@ -40,6 +38,7 @@ import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.Marker;
|
||||
import org.apache.logging.log4j.MarkerManager;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class CraftingHelper
|
||||
{
|
||||
@@ -199,29 +198,11 @@ public class CraftingHelper
|
||||
return new ItemStack(item, GsonHelper.getAsInt(json, "count", 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Please use the {@linkplain #processConditions(JsonObject, String, ICondition.IContext) other more general overload}.
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "1.18.2")
|
||||
public static boolean processConditions(JsonObject json, String memberName)
|
||||
{
|
||||
return processConditions(json, memberName, ICondition.IContext.EMPTY);
|
||||
}
|
||||
|
||||
public static boolean processConditions(JsonObject json, String memberName, ICondition.IContext context)
|
||||
{
|
||||
return !json.has(memberName) || processConditions(GsonHelper.getAsJsonArray(json, memberName), context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Please use the {@linkplain #processConditions(JsonArray, ICondition.IContext) other more general overload}.
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "1.18.2")
|
||||
public static boolean processConditions(JsonArray conditions)
|
||||
{
|
||||
return processConditions(conditions, ICondition.IContext.EMPTY);
|
||||
}
|
||||
|
||||
public static boolean processConditions(JsonArray conditions, ICondition.IContext context)
|
||||
{
|
||||
for (int x = 0; x < conditions.size(); x++)
|
||||
|
||||
@@ -14,8 +14,8 @@ import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.world.entity.player.StackedContents;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.crafting.Ingredient;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Arrays;
|
||||
|
||||
/** Ingredient that matches everything from the first ingredient that is not included in the second ingredient */
|
||||
|
||||
@@ -17,8 +17,8 @@ import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.world.entity.player.StackedContents;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.crafting.Ingredient;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.google.gson.JsonObject;
|
||||
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.crafting.Ingredient.Value;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
public class MultiItemValue implements Value
|
||||
{
|
||||
@@ -44,7 +45,7 @@ public class MultiItemValue implements Value
|
||||
private JsonObject toJson(ItemStack stack)
|
||||
{
|
||||
JsonObject ret = new JsonObject();
|
||||
ret.addProperty("item", stack.getItem().getRegistryName().toString());
|
||||
ret.addProperty("item", ForgeRegistries.ITEMS.getKey(stack.getItem()).toString());
|
||||
if (stack.getCount() != 1)
|
||||
ret.addProperty("count", stack.getCount());
|
||||
if (stack.getTag() != null)
|
||||
|
||||
@@ -7,14 +7,14 @@ package net.minecraftforge.common.crafting;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.crafting.Ingredient;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/** Ingredient that matches the given stack, performing an exact NBT match. Use {@link PartialNBTIngredient} if you need partial match. */
|
||||
public class NBTIngredient extends AbstractIngredient
|
||||
@@ -58,7 +58,7 @@ public class NBTIngredient extends AbstractIngredient
|
||||
{
|
||||
JsonObject json = new JsonObject();
|
||||
json.addProperty("type", CraftingHelper.getID(Serializer.INSTANCE).toString());
|
||||
json.addProperty("item", stack.getItem().getRegistryName().toString());
|
||||
json.addProperty("item", ForgeRegistries.ITEMS.getKey(stack.getItem()).toString());
|
||||
json.addProperty("count", stack.getCount());
|
||||
if (stack.hasTag())
|
||||
json.addProperty("nbt", stack.getTag().toString());
|
||||
|
||||
@@ -92,13 +92,13 @@ public class PartialNBTIngredient extends AbstractIngredient
|
||||
json.addProperty("type", CraftingHelper.getID(Serializer.INSTANCE).toString());
|
||||
if (items.size() == 1)
|
||||
{
|
||||
json.addProperty("item", items.iterator().next().getRegistryName().toString());
|
||||
json.addProperty("item", ForgeRegistries.ITEMS.getKey(items.iterator().next()).toString());
|
||||
}
|
||||
else
|
||||
{
|
||||
JsonArray items = new JsonArray();
|
||||
// ensure the order of items in the set is deterministic when saved to JSON
|
||||
this.items.stream().map(Item::getRegistryName).sorted().forEach(name -> items.add(name.toString()));
|
||||
this.items.stream().map(ForgeRegistries.ITEMS::getKey).sorted().forEach(name -> items.add(name.toString()));
|
||||
json.add("items", items);
|
||||
}
|
||||
json.addProperty("nbt", nbt.toString());
|
||||
|
||||
@@ -43,12 +43,6 @@ public class AndCondition implements ICondition
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test()
|
||||
{
|
||||
return test(IContext.EMPTY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(IContext context)
|
||||
{
|
||||
|
||||
@@ -6,12 +6,13 @@
|
||||
package net.minecraftforge.common.crafting.conditions;
|
||||
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.HolderSet;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.Tag;
|
||||
import net.minecraft.tags.TagManager;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.Map;
|
||||
@@ -19,15 +20,16 @@ import java.util.Map;
|
||||
public class ConditionContext implements ICondition.IContext
|
||||
{
|
||||
private final TagManager tagManager;
|
||||
private Map<ResourceKey<?>, Map<ResourceLocation, Tag<Holder<?>>>> loadedTags = null;
|
||||
private Map<ResourceKey<?>, Map<ResourceLocation, Collection<Holder<?>>>> loadedTags = null;
|
||||
|
||||
public ConditionContext(TagManager tagManager)
|
||||
{
|
||||
this.tagManager = tagManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Map<ResourceLocation, Tag<Holder<T>>> getAllTags(ResourceKey<? extends Registry<T>> registry)
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@Override
|
||||
public <T> Map<ResourceLocation, Collection<Holder<T>>> getAllTags(ResourceKey<? extends Registry<T>> registry)
|
||||
{
|
||||
if (loadedTags == null)
|
||||
{
|
||||
@@ -37,7 +39,8 @@ public class ConditionContext implements ICondition.IContext
|
||||
loadedTags = new IdentityHashMap<>();
|
||||
for (var loadResult : tags)
|
||||
{
|
||||
loadedTags.put(loadResult.key(), (Map) Collections.unmodifiableMap(loadResult.tags()));
|
||||
Map<ResourceLocation, Collection<? extends Holder<?>>> map = Collections.unmodifiableMap(loadResult.tags());
|
||||
loadedTags.put(loadResult.key(), (Map) map);
|
||||
}
|
||||
}
|
||||
return (Map) loadedTags.getOrDefault(registry, Collections.emptyMap());
|
||||
|
||||
@@ -22,7 +22,7 @@ public final class FalseCondition implements ICondition
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test()
|
||||
public boolean test(IContext condition)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -9,33 +9,25 @@ import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.Tag;
|
||||
import net.minecraft.tags.TagKey;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public interface ICondition
|
||||
{
|
||||
ResourceLocation getID();
|
||||
|
||||
default boolean test(IContext context)
|
||||
{
|
||||
return test();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@linkplain #test(IContext) the other more general overload}.
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "1.18.2")
|
||||
boolean test();
|
||||
boolean test(IContext context);
|
||||
|
||||
interface IContext
|
||||
{
|
||||
IContext EMPTY = new IContext()
|
||||
{
|
||||
@Override
|
||||
public <T> Map<ResourceLocation, Tag<Holder<T>>> getAllTags(ResourceKey<? extends Registry<T>> registry)
|
||||
public <T> Map<ResourceLocation, Collection<Holder<T>>> getAllTags(ResourceKey<? extends Registry<T>> registry)
|
||||
{
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
@@ -44,15 +36,15 @@ public interface ICondition
|
||||
/**
|
||||
* Return the requested tag if available, or an empty tag otherwise.
|
||||
*/
|
||||
default <T> Tag<Holder<T>> getTag(TagKey<T> key)
|
||||
default <T> Collection<Holder<T>> getTag(TagKey<T> key)
|
||||
{
|
||||
return getAllTags(key.registry()).getOrDefault(key.location(), Tag.empty());
|
||||
return getAllTags(key.registry()).getOrDefault(key.location(), Set.of());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all the loaded tags for the passed registry, or an empty map if none is available.
|
||||
* Note that the map and the tags are unmodifiable.
|
||||
*/
|
||||
<T> Map<ResourceLocation, Tag<Holder<T>>> getAllTags(ResourceKey<? extends Registry<T>> registry);
|
||||
<T> Map<ResourceLocation, Collection<Holder<T>>> getAllTags(ResourceKey<? extends Registry<T>> registry);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -38,7 +38,7 @@ public class ItemExistsCondition implements ICondition
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test()
|
||||
public boolean test(IContext context)
|
||||
{
|
||||
return ForgeRegistries.ITEMS.containsKey(item);
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public class ModLoadedCondition implements ICondition
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test()
|
||||
public boolean test(IContext context)
|
||||
{
|
||||
return ModList.get().isLoaded(modid);
|
||||
}
|
||||
|
||||
@@ -26,12 +26,6 @@ public class NotCondition implements ICondition
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test()
|
||||
{
|
||||
return test(IContext.EMPTY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(IContext context)
|
||||
{
|
||||
|
||||
@@ -43,12 +43,6 @@ public class OrCondition implements ICondition
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test()
|
||||
{
|
||||
return test(IContext.EMPTY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(IContext context)
|
||||
{
|
||||
|
||||
@@ -42,13 +42,7 @@ public class TagEmptyCondition implements ICondition
|
||||
@Override
|
||||
public boolean test(ICondition.IContext context)
|
||||
{
|
||||
return context.getTag(tag).getValues().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test()
|
||||
{
|
||||
return test(IContext.EMPTY);
|
||||
return context.getTag(tag).isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,7 +23,7 @@ public final class TrueCondition implements ICondition
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test()
|
||||
public boolean test(IContext context)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -37,8 +37,7 @@ import net.minecraftforge.fml.ModList;
|
||||
import net.minecraftforge.forge.event.lifecycle.GatherDataEvent;
|
||||
import net.minecraftforge.forgespi.language.IModFileInfo;
|
||||
import net.minecraftforge.resource.ResourcePackLoader;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Enables data providers to check if other data files currently exist. The
|
||||
@@ -147,7 +146,7 @@ public class ExistingFileHelper {
|
||||
if (!enable) {
|
||||
return true;
|
||||
}
|
||||
return generated.get(packType).contains(loc) || getManager(packType).hasResource(loc);
|
||||
return generated.get(packType).contains(loc) || getManager(packType).getResource(loc).isPresent();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -155,7 +154,7 @@ public class ExistingFileHelper {
|
||||
* convenience method to avoid repeating type/prefix/suffix and instead use the
|
||||
* common definitions in {@link ResourceType}, or a custom {@link IResourceType}
|
||||
* definition.
|
||||
*
|
||||
*
|
||||
* @param loc the base location of the resource, e.g.
|
||||
* {@code "minecraft:block/stone"}
|
||||
* @param type a {@link IResourceType} describing how to form the path to the
|
||||
@@ -169,7 +168,7 @@ public class ExistingFileHelper {
|
||||
|
||||
/**
|
||||
* Check if a given resource exists in the known resource packs.
|
||||
*
|
||||
*
|
||||
* @param loc the base location of the resource, e.g.
|
||||
* {@code "minecraft:block/stone"}
|
||||
* @param packType the type of resources to check
|
||||
@@ -190,13 +189,13 @@ public class ExistingFileHelper {
|
||||
* <p>
|
||||
* This should be called by data providers immediately when a new data object is
|
||||
* created, i.e. not during
|
||||
* {@link DataProvider#run(net.minecraft.data.HashCache) run} but instead
|
||||
* {@link DataProvider#run(net.minecraft.data.CachedOutput) run} but instead
|
||||
* when the "builder" (or whatever intermediate object) is created, such as a
|
||||
* {@link ModelBuilder}.
|
||||
* <p>
|
||||
* This represents a <em>promise</em> to generate the file later, since other
|
||||
* datagen may rely on this file existing.
|
||||
*
|
||||
*
|
||||
* @param loc the base location of the resource, e.g.
|
||||
* {@code "minecraft:block/stone"}
|
||||
* @param type a {@link IResourceType} describing how to form the path to the
|
||||
@@ -211,13 +210,13 @@ public class ExistingFileHelper {
|
||||
* <p>
|
||||
* This should be called by data providers immediately when a new data object is
|
||||
* created, i.e. not during
|
||||
* {@link DataProvider#run(HashCache) run} but instead
|
||||
* {@link DataProvider#run(net.minecraft.data.CachedOutput) run} but instead
|
||||
* when the "builder" (or whatever intermediate object) is created, such as a
|
||||
* {@link ModelBuilder}.
|
||||
* <p>
|
||||
* This represents a <em>promise</em> to generate the file later, since other
|
||||
* datagen may rely on this file existing.
|
||||
*
|
||||
*
|
||||
* @param loc the base location of the resource, e.g.
|
||||
* {@code "minecraft:block/stone"}
|
||||
* @param packType the type of resources to check
|
||||
@@ -236,7 +235,7 @@ public class ExistingFileHelper {
|
||||
|
||||
@VisibleForTesting
|
||||
public Resource getResource(ResourceLocation loc, PackType packType) throws IOException {
|
||||
return getManager(packType).getResource(loc);
|
||||
return getManager(packType).getResource(loc).orElseThrow();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,7 +9,6 @@ import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.tags.BlockTagsProvider;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
import net.minecraft.tags.Tag;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.item.DyeColor;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
|
||||
@@ -9,7 +9,6 @@ import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.tags.BlockTagsProvider;
|
||||
import net.minecraft.data.tags.ItemTagsProvider;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.Tag;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.item.DyeColor;
|
||||
import net.minecraft.world.item.Item;
|
||||
|
||||
@@ -6,14 +6,13 @@
|
||||
package net.minecraftforge.common.data;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.data.CachedOutput;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.HashCache;
|
||||
import net.minecraft.data.recipes.FinishedRecipe;
|
||||
import net.minecraft.data.recipes.RecipeProvider;
|
||||
import net.minecraft.data.recipes.ShapedRecipeBuilder;
|
||||
import net.minecraft.data.recipes.ShapelessRecipeBuilder;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.Tag;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
@@ -25,6 +24,8 @@ import net.minecraft.world.item.crafting.Ingredient.Value;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraftforge.common.Tags;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.nio.file.Path;
|
||||
@@ -33,8 +34,8 @@ import java.util.function.Consumer;
|
||||
|
||||
public final class ForgeRecipeProvider extends RecipeProvider
|
||||
{
|
||||
private Map<Item, TagKey<Item>> replacements = new HashMap<>();
|
||||
private Set<ResourceLocation> excludes = new HashSet<>();
|
||||
private final Map<Item, TagKey<Item>> replacements = new HashMap<>();
|
||||
private final Set<ResourceLocation> excludes = new HashSet<>();
|
||||
|
||||
public ForgeRecipeProvider(DataGenerator generatorIn)
|
||||
{
|
||||
@@ -43,7 +44,7 @@ public final class ForgeRecipeProvider extends RecipeProvider
|
||||
|
||||
private void exclude(ItemLike item)
|
||||
{
|
||||
excludes.add(item.asItem().getRegistryName());
|
||||
excludes.add(ForgeRegistries.ITEMS.getKey(item.asItem()));
|
||||
}
|
||||
|
||||
private void replace(ItemLike item, TagKey<Item> tag)
|
||||
@@ -54,15 +55,15 @@ public final class ForgeRecipeProvider extends RecipeProvider
|
||||
@Override
|
||||
protected void buildCraftingRecipes(Consumer<FinishedRecipe> consumer)
|
||||
{
|
||||
replace(Items.STICK, Tags.Items.RODS_WOODEN);
|
||||
replace(Items.GOLD_INGOT, Tags.Items.INGOTS_GOLD);
|
||||
replace(Items.IRON_INGOT, Tags.Items.INGOTS_IRON);
|
||||
replace(Items.STICK, Tags.Items.RODS_WOODEN);
|
||||
replace(Items.GOLD_INGOT, Tags.Items.INGOTS_GOLD);
|
||||
replace(Items.IRON_INGOT, Tags.Items.INGOTS_IRON);
|
||||
replace(Items.NETHERITE_INGOT, Tags.Items.INGOTS_NETHERITE);
|
||||
replace(Items.COPPER_INGOT, Tags.Items.INGOTS_COPPER);
|
||||
replace(Items.AMETHYST_SHARD, Tags.Items.GEMS_AMETHYST);
|
||||
replace(Items.DIAMOND, Tags.Items.GEMS_DIAMOND);
|
||||
replace(Items.EMERALD, Tags.Items.GEMS_EMERALD);
|
||||
replace(Items.CHEST, Tags.Items.CHESTS_WOODEN);
|
||||
replace(Items.DIAMOND, Tags.Items.GEMS_DIAMOND);
|
||||
replace(Items.EMERALD, Tags.Items.GEMS_EMERALD);
|
||||
replace(Items.CHEST, Tags.Items.CHESTS_WOODEN);
|
||||
replace(Blocks.COBBLESTONE, Tags.Items.COBBLESTONE_NORMAL);
|
||||
replace(Blocks.COBBLED_DEEPSLATE, Tags.Items.COBBLESTONE_DEEPSLATE);
|
||||
|
||||
@@ -90,20 +91,17 @@ public final class ForgeRecipeProvider extends RecipeProvider
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveAdvancement(HashCache cache, JsonObject advancementJson, Path pathIn) {
|
||||
//NOOP - We dont replace any of the advancement things yet...
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private FinishedRecipe enhance(FinishedRecipe vanilla)
|
||||
{
|
||||
if (vanilla instanceof ShapelessRecipeBuilder.Result)
|
||||
return enhance((ShapelessRecipeBuilder.Result)vanilla);
|
||||
if (vanilla instanceof ShapedRecipeBuilder.Result)
|
||||
return enhance((ShapedRecipeBuilder.Result)vanilla);
|
||||
if (vanilla instanceof ShapelessRecipeBuilder.Result shapeless)
|
||||
return enhance(shapeless);
|
||||
if (vanilla instanceof ShapedRecipeBuilder.Result shaped)
|
||||
return enhance(shaped);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private FinishedRecipe enhance(ShapelessRecipeBuilder.Result vanilla)
|
||||
{
|
||||
List<Ingredient> ingredients = getField(ShapelessRecipeBuilder.Result.class, vanilla, 4);
|
||||
@@ -120,6 +118,13 @@ public final class ForgeRecipeProvider extends RecipeProvider
|
||||
return modified ? vanilla : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveAdvancement(CachedOutput output, JsonObject advancementJson, Path pathIn)
|
||||
{
|
||||
//NOOP - We dont replace any of the advancement things yet...
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private FinishedRecipe enhance(ShapedRecipeBuilder.Result vanilla)
|
||||
{
|
||||
Map<Character, Ingredient> ingredients = getField(ShapedRecipeBuilder.Result.class, vanilla, 5);
|
||||
@@ -136,6 +141,7 @@ public final class ForgeRecipeProvider extends RecipeProvider
|
||||
return modified ? vanilla : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Ingredient enhance(ResourceLocation name, Ingredient vanilla)
|
||||
{
|
||||
if (excludes.contains(name))
|
||||
@@ -154,11 +160,9 @@ public final class ForgeRecipeProvider extends RecipeProvider
|
||||
{
|
||||
items.add(new TagValue(replacement));
|
||||
modified = true;
|
||||
}
|
||||
else
|
||||
} else
|
||||
items.add(entry);
|
||||
}
|
||||
else
|
||||
} else
|
||||
items.add(entry);
|
||||
}
|
||||
return modified ? Ingredient.fromValues(items.stream()) : null;
|
||||
@@ -171,9 +175,8 @@ public final class ForgeRecipeProvider extends RecipeProvider
|
||||
fld.setAccessible(true);
|
||||
try
|
||||
{
|
||||
return (R)fld.get(inst);
|
||||
}
|
||||
catch (IllegalArgumentException | IllegalAccessException e)
|
||||
return (R) fld.get(inst);
|
||||
} catch (IllegalArgumentException | IllegalAccessException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
@@ -11,12 +11,11 @@ import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.tags.TagsProvider;
|
||||
import net.minecraftforge.registries.GameData;
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
import net.minecraftforge.registries.IForgeRegistryEntry;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public abstract class ForgeRegistryTagsProvider<T extends IForgeRegistryEntry<T>> extends TagsProvider<T>
|
||||
public abstract class ForgeRegistryTagsProvider<T> extends TagsProvider<T>
|
||||
{
|
||||
private static <T extends IForgeRegistryEntry<T>> Registry<T> wrapRegistry(IForgeRegistry<T> forgeRegistry)
|
||||
private static <T> Registry<T> wrapRegistry(IForgeRegistry<T> forgeRegistry)
|
||||
{
|
||||
if (forgeRegistry.tags() == null)
|
||||
throw new IllegalArgumentException("Forge registry " + forgeRegistry.getRegistryName() + " does not have support for tags");
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonObject;
|
||||
import cpw.mods.modlauncher.api.LamdbaExceptionUtils;
|
||||
import net.minecraft.data.CachedOutput;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.HashCache;
|
||||
import net.minecraft.data.DataProvider;
|
||||
@@ -17,6 +18,7 @@ import net.minecraft.util.Tuple;
|
||||
import net.minecraftforge.common.loot.GlobalLootModifierSerializer;
|
||||
import net.minecraftforge.common.loot.IGlobalLootModifier;
|
||||
import net.minecraftforge.common.loot.LootModifier;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
@@ -59,7 +61,7 @@ public abstract class GlobalLootModifierProvider implements DataProvider
|
||||
protected abstract void start();
|
||||
|
||||
@Override
|
||||
public void run(HashCache cache) throws IOException
|
||||
public void run(CachedOutput cache) throws IOException
|
||||
{
|
||||
start();
|
||||
|
||||
@@ -73,16 +75,16 @@ public abstract class GlobalLootModifierProvider implements DataProvider
|
||||
Path modifierPath = gen.getOutputFolder().resolve(modPath + name + ".json");
|
||||
|
||||
JsonObject json = pair.getB();
|
||||
json.addProperty("type", pair.getA().getRegistryName().toString());
|
||||
json.addProperty("type", ForgeRegistries.LOOT_MODIFIER_SERIALIZERS.get().getKey(pair.getA()).toString());
|
||||
|
||||
DataProvider.save(GSON, cache, json, modifierPath);
|
||||
DataProvider.saveStable(cache, json, modifierPath);
|
||||
}));
|
||||
|
||||
JsonObject forgeJson = new JsonObject();
|
||||
forgeJson.addProperty("replace", this.replace);
|
||||
forgeJson.add("entries", GSON.toJsonTree(entries.stream().map(ResourceLocation::toString).collect(Collectors.toList())));
|
||||
|
||||
DataProvider.save(GSON, cache, forgeJson, forgePath);
|
||||
DataProvider.saveStable(cache, forgeJson, forgePath);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -14,6 +14,9 @@ import java.util.Objects;
|
||||
import java.util.TreeMap;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.google.common.hash.Hashing;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.data.CachedOutput;
|
||||
import org.apache.commons.lang3.text.translate.JavaUnicodeEscaper;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
@@ -31,7 +34,7 @@ import net.minecraft.world.effect.MobEffect;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public abstract class LanguageProvider implements DataProvider {
|
||||
private static final Gson GSON = (new GsonBuilder()).setPrettyPrinting().disableHtmlEscaping().create();
|
||||
private static final Gson GSON = (new GsonBuilder()).setPrettyPrinting().disableHtmlEscaping().setLenient().create();
|
||||
private final Map<String, String> data = new TreeMap<>();
|
||||
private final DataGenerator gen;
|
||||
private final String modid;
|
||||
@@ -46,7 +49,7 @@ public abstract class LanguageProvider implements DataProvider {
|
||||
protected abstract void addTranslations();
|
||||
|
||||
@Override
|
||||
public void run(HashCache cache) throws IOException {
|
||||
public void run(CachedOutput cache) throws IOException {
|
||||
addTranslations();
|
||||
if (!data.isEmpty())
|
||||
save(cache, data, this.gen.getOutputFolder().resolve("assets/" + modid + "/lang/" + locale + ".json"));
|
||||
@@ -57,19 +60,14 @@ public abstract class LanguageProvider implements DataProvider {
|
||||
return "Languages: " + locale;
|
||||
}
|
||||
|
||||
private void save(HashCache cache, Object object, Path target) throws IOException {
|
||||
String data = GSON.toJson(object);
|
||||
data = JavaUnicodeEscaper.outsideOf(0, 0x7f).translate(data); // Escape unicode after the fact so that it's not double escaped by GSON
|
||||
String hash = DataProvider.SHA1.hashUnencodedChars(data).toString();
|
||||
if (!Objects.equals(cache.getHash(target), hash) || !Files.exists(target)) {
|
||||
Files.createDirectories(target.getParent());
|
||||
|
||||
try (BufferedWriter bufferedwriter = Files.newBufferedWriter(target)) {
|
||||
bufferedwriter.write(data);
|
||||
}
|
||||
private void save(CachedOutput cache, Object object, Path target) throws IOException {
|
||||
// TODO: DataProvider.saveStable handles the caching and hashing already, but creating the JSON Object this way seems unreliable. -C
|
||||
JsonObject json = new JsonObject();
|
||||
for (Map.Entry<String, String> pair : data.entrySet()) {
|
||||
json.addProperty(pair.getKey(), pair.getValue());
|
||||
}
|
||||
|
||||
cache.putNew(target, hash);
|
||||
DataProvider.saveStable(cache, json, target);
|
||||
}
|
||||
|
||||
public void addBlock(Supplier<? extends Block> key, String name) {
|
||||
|
||||
@@ -10,8 +10,8 @@ import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@@ -8,6 +8,7 @@ package net.minecraftforge.common.data;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.data.CachedOutput;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.HashCache;
|
||||
import net.minecraft.data.DataProvider;
|
||||
@@ -60,7 +61,7 @@ public abstract class SoundDefinitionsProvider implements DataProvider
|
||||
public abstract void registerSounds();
|
||||
|
||||
@Override
|
||||
public void run(HashCache cache) throws IOException
|
||||
public void run(CachedOutput cache) throws IOException
|
||||
{
|
||||
this.sounds.clear();
|
||||
this.registerSounds();
|
||||
@@ -229,7 +230,7 @@ public abstract class SoundDefinitionsProvider implements DataProvider
|
||||
// Differently from all the other errors, this is not a 'missing sound' but rather something completely different
|
||||
// that has broken the invariants of this sound definitions provider. In fact, a sound may only be either of
|
||||
// SOUND or EVENT type. Any other values is somebody messing with the internals, reflectively adding something
|
||||
// to an enum or passing `null` to a parameter annotated with `@Nonnull`.
|
||||
// to an enum or passing `null` to a parameter annotated with `@NotNull`.
|
||||
throw new IllegalArgumentException("The given sound '" + sound.name() + "' does not have a valid type: expected either SOUND or EVENT, but found " + sound.type());
|
||||
}
|
||||
|
||||
@@ -254,9 +255,9 @@ public abstract class SoundDefinitionsProvider implements DataProvider
|
||||
return valid;
|
||||
}
|
||||
|
||||
private void save(final HashCache cache, final Path targetFile) throws IOException
|
||||
private void save(final CachedOutput cache, final Path targetFile) throws IOException
|
||||
{
|
||||
DataProvider.save(GSON, cache, this.mapToJson(this.sounds), targetFile);
|
||||
DataProvider.saveStable(cache, this.mapToJson(this.sounds), targetFile);
|
||||
}
|
||||
|
||||
private JsonObject mapToJson(final Map<String, SoundDefinition> map)
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
package net.minecraftforge.common.extensions;
|
||||
|
||||
import net.minecraft.world.entity.vehicle.AbstractMinecart;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.util.Mth;
|
||||
@@ -43,20 +41,6 @@ public interface IForgeAbstractMinecart
|
||||
*/
|
||||
void moveMinecartOnRail(BlockPos pos);
|
||||
|
||||
/**
|
||||
* This function returns an ItemStack that represents this cart.
|
||||
* This should be an ItemStack that can be used by the player to place the cart,
|
||||
* but is not necessary the item the cart drops when destroyed.
|
||||
* @return An ItemStack that can be used to place the cart.
|
||||
*
|
||||
* @deprecated TODO Remove in 1.19 - use {@link AbstractMinecart#getPickResult()} instead
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
default ItemStack getCartItem()
|
||||
{
|
||||
return new ItemStack(Items.MINECART);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this cart can currently use rails.
|
||||
* This function is mainly used to gracefully detach a minecart from a rail.
|
||||
|
||||
@@ -23,14 +23,15 @@ public interface IForgeAdvancementBuilder
|
||||
}
|
||||
|
||||
/**
|
||||
* save function for the {@link Advancement.Builder} which uses the {@link ExistingFileHelper} to check if the parent is already known
|
||||
* @param consumer A {@link Consumer} which the build {@link Advancement} is passed to
|
||||
* @param id The {@link ResourceLocation} for the new {@link Advancement}
|
||||
* @param fileHelper The {@link ExistingFileHelper} where all known {@link Advancement}s are registered
|
||||
* @return The build {@link Advancement}
|
||||
* @throws IllegalStateException is thrown if the parent of the {@link Advancement} is not known
|
||||
* Saves this builder with the given id using the {@link ExistingFileHelper} to check if the parent is already known.
|
||||
*
|
||||
* @param saver a {@link Consumer} which saves any advancements provided
|
||||
* @param id the {@link ResourceLocation} id for the new advancement
|
||||
* @param fileHelper the {@link ExistingFileHelper} where all known advancements are registered
|
||||
* @return the built advancement
|
||||
* @throws IllegalStateException if the parent of the advancement is not known
|
||||
*/
|
||||
default Advancement save(Consumer<Advancement> consumer ,ResourceLocation id, ExistingFileHelper fileHelper)
|
||||
default Advancement save(Consumer<Advancement> saver, ResourceLocation id, ExistingFileHelper fileHelper)
|
||||
{
|
||||
boolean canBuild = self().canBuild((advancementId) ->
|
||||
{
|
||||
@@ -46,7 +47,7 @@ public interface IForgeAdvancementBuilder
|
||||
}
|
||||
|
||||
Advancement advancement = self().build(id);
|
||||
consumer.accept(advancement);
|
||||
saver.accept(advancement);
|
||||
return advancement;
|
||||
}
|
||||
}
|
||||
@@ -11,8 +11,7 @@ import net.minecraft.world.level.block.state.properties.RailShape;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface IForgeBaseRailBlock
|
||||
{
|
||||
|
||||
@@ -6,10 +6,9 @@
|
||||
package net.minecraftforge.common.extensions;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.client.Camera;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.Mob;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
@@ -28,7 +27,6 @@ import net.minecraft.world.level.material.FluidState;
|
||||
import net.minecraft.world.level.pathfinder.BlockPathTypes;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
@@ -47,6 +45,7 @@ import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.common.ToolAction;
|
||||
import net.minecraftforge.common.ToolActions;
|
||||
import net.minecraftforge.fml.loading.FMLEnvironment;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public interface IForgeBlock
|
||||
@@ -375,12 +374,13 @@ public interface IForgeBlock
|
||||
*
|
||||
* @param state The current state
|
||||
* @param level The level
|
||||
* @param randomSource Random source to use for experience randomness
|
||||
* @param pos Block position
|
||||
* @param fortuneLevel fortune enchantment level of tool being used
|
||||
* @param silkTouchLevel silk touch enchantment level of tool being used
|
||||
* @return Amount of XP from breaking this block.
|
||||
*/
|
||||
default int getExpDrop(BlockState state, LevelReader level, BlockPos pos, int fortuneLevel, int silkTouchLevel)
|
||||
default int getExpDrop(BlockState state, LevelReader level, RandomSource randomSource, BlockPos pos, int fortuneLevel, int silkTouchLevel)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -533,7 +533,7 @@ public interface IForgeBlock
|
||||
*/
|
||||
default int getFlammability(BlockState state, BlockGetter level, BlockPos pos, Direction direction)
|
||||
{
|
||||
return ((FireBlock)Blocks.FIRE).getBurnOdd(state);
|
||||
return ((FireBlock)Blocks.FIRE).getBurnOdds(state);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -574,7 +574,7 @@ public interface IForgeBlock
|
||||
*/
|
||||
default int getFireSpreadSpeed(BlockState state, BlockGetter level, BlockPos pos, Direction direction)
|
||||
{
|
||||
return ((FireBlock)Blocks.FIRE).getFlameOdds(state);
|
||||
return ((FireBlock)Blocks.FIRE).getIgniteOdds(state);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -677,10 +677,23 @@ public interface IForgeBlock
|
||||
@Nullable
|
||||
default BlockState getToolModifiedState(BlockState state, UseOnContext context, ToolAction toolAction, boolean simulate)
|
||||
{
|
||||
BlockState toolModifiedState = getToolModifiedState(state, context.getLevel(), context.getClickedPos(),
|
||||
context.getPlayer(), context.getItemInHand(), toolAction);
|
||||
ItemStack itemStack = context.getItemInHand();
|
||||
if (!itemStack.canPerformAction(toolAction))
|
||||
return null;
|
||||
|
||||
if (toolModifiedState == null && ToolActions.HOE_TILL == toolAction && context.getItemInHand().canPerformAction(ToolActions.HOE_TILL))
|
||||
if (ToolActions.AXE_STRIP == toolAction)
|
||||
{
|
||||
return AxeItem.getAxeStrippingState(state);
|
||||
} else if (ToolActions.AXE_SCRAPE == toolAction)
|
||||
{
|
||||
return WeatheringCopper.getPrevious(state).orElse(null);
|
||||
} else if (ToolActions.AXE_WAX_OFF == toolAction)
|
||||
{
|
||||
return Optional.ofNullable(HoneycombItem.WAX_OFF_BY_BLOCK.get().get(state.getBlock())).map(block -> block.withPropertiesOf(state)).orElse(null);
|
||||
} else if (ToolActions.SHOVEL_FLATTEN == toolAction)
|
||||
{
|
||||
return ShovelItem.getShovelPathingState(state);
|
||||
} else if (ToolActions.HOE_TILL == toolAction)
|
||||
{
|
||||
// Logic copied from HoeItem#TILLABLES; needs to be kept in sync during updating
|
||||
Block block = state.getBlock();
|
||||
@@ -698,35 +711,6 @@ public interface IForgeBlock
|
||||
}
|
||||
}
|
||||
|
||||
return toolModifiedState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the state that this block should transform into when right-clicked by a tool.
|
||||
* For example: Used to determine if {@link ToolActions#AXE_STRIP an axe can strip} or {@link ToolActions#SHOVEL_FLATTEN a shovel can path}.
|
||||
* Returns {@code null} if nothing should happen.
|
||||
*
|
||||
* @param state The current state
|
||||
* @param level The level
|
||||
* @param pos The block position in level
|
||||
* @param player The player clicking the block
|
||||
* @param stack The stack being used by the player
|
||||
* @param toolAction The action being performed by the tool
|
||||
* @return The resulting state after the action has been performed
|
||||
* @deprecated Override and use {@link #getToolModifiedState(BlockState, UseOnContext, ToolAction, boolean)} instead
|
||||
*/
|
||||
@Nullable
|
||||
// TODO 1.19: Remove this and move the default impl to the newer method in 1.19. Has to stay here to preserve behavior of overrides on this method.
|
||||
@Deprecated(forRemoval = true, since = "1.18.2")
|
||||
default BlockState getToolModifiedState(BlockState state, Level level, BlockPos pos, Player player, ItemStack stack, ToolAction toolAction)
|
||||
{
|
||||
if (!stack.canPerformAction(toolAction)) return null;
|
||||
if (ToolActions.AXE_STRIP == toolAction) return AxeItem.getAxeStrippingState(state);
|
||||
else if(ToolActions.AXE_SCRAPE == toolAction) return WeatheringCopper.getPrevious(state).orElse(null);
|
||||
else if(ToolActions.AXE_WAX_OFF == toolAction) return Optional.ofNullable(HoneycombItem.WAX_OFF_BY_BLOCK.get().get(state.getBlock())).map((p_150694_) -> {
|
||||
return p_150694_.withPropertiesOf(state);
|
||||
}).orElse(null);
|
||||
else if (ToolActions.SHOVEL_FLATTEN == toolAction) return ShovelItem.getShovelPathingState(state);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
|
||||
package net.minecraftforge.common.extensions;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
|
||||
import net.minecraft.client.resources.model.BakedModel;
|
||||
import net.minecraft.network.Connection;
|
||||
@@ -26,6 +24,7 @@ import net.minecraftforge.client.model.ModelDataManager;
|
||||
import net.minecraftforge.client.model.data.EmptyModelData;
|
||||
import net.minecraftforge.client.model.data.IModelData;
|
||||
import net.minecraftforge.common.capabilities.ICapabilitySerializable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface IForgeBlockEntity extends ICapabilitySerializable<CompoundTag>
|
||||
{
|
||||
@@ -137,7 +136,7 @@ public interface IForgeBlockEntity extends ICapabilitySerializable<CompoundTag>
|
||||
{
|
||||
// We have to capture any exceptions that may occur here because BUKKIT servers like to send
|
||||
// the tile entity data BEFORE the chunk data, you know, the OPPOSITE of what vanilla does!
|
||||
// So we can not GARENTEE that the world state is the real state for the block...
|
||||
// So we can not GUARANTEE that the world state is the real state for the block...
|
||||
// So, once again in the long line of US having to accommodate BUKKIT breaking things,
|
||||
// here it is, assume that the TE is only 1 cubic block. Problem with this is that it may
|
||||
// cause the TileEntity renderer to error further down the line! But alas, nothing we can do.
|
||||
@@ -169,7 +168,7 @@ public interface IForgeBlockEntity extends ICapabilitySerializable<CompoundTag>
|
||||
* <b>Note that this method may be called on a chunk render thread instead of the main client thread</b>
|
||||
* @return Your model data
|
||||
*/
|
||||
default @Nonnull IModelData getModelData()
|
||||
default @NotNull IModelData getModelData()
|
||||
{
|
||||
return EmptyModelData.INSTANCE;
|
||||
}
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
package net.minecraftforge.common.extensions;
|
||||
|
||||
import java.util.Optional;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.client.Camera;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.Mob;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
@@ -39,6 +39,7 @@ import net.minecraft.world.level.block.SoundType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.common.ToolAction;
|
||||
import net.minecraftforge.common.ToolActions;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface IForgeBlockState
|
||||
{
|
||||
@@ -316,14 +317,15 @@ public interface IForgeBlockState
|
||||
* Gathers how much experience this block drops when broken.
|
||||
*
|
||||
* @param level The level
|
||||
* @param randomSource Random source to use for experience randomness
|
||||
* @param pos Block position
|
||||
* @param fortuneLevel fortune enchantment level of tool being used
|
||||
* @param silkTouchLevel silk touch enchantment level of tool being used
|
||||
* @return Amount of XP from breaking this block.
|
||||
*/
|
||||
default int getExpDrop(LevelReader level, BlockPos pos, int fortuneLevel, int silkTouchLevel)
|
||||
default int getExpDrop(LevelReader level, RandomSource randomSource, BlockPos pos, int fortuneLevel, int silkTouchLevel)
|
||||
{
|
||||
return self().getBlock().getExpDrop(self(), level, pos, fortuneLevel, silkTouchLevel);
|
||||
return self().getBlock().getExpDrop(self(), level, randomSource, pos, fortuneLevel, silkTouchLevel);
|
||||
}
|
||||
|
||||
default BlockState rotate(LevelAccessor level, BlockPos pos, Rotation direction)
|
||||
@@ -622,28 +624,6 @@ public interface IForgeBlockState
|
||||
return eventState != self() ? eventState : self().getBlock().getToolModifiedState(self(), context, toolAction, simulate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the state that this block should transform into when right-clicked by a tool.
|
||||
* For example: Used to determine if {@link ToolActions#AXE_STRIP an axe can strip} or {@link ToolActions#SHOVEL_FLATTEN a shovel can path}.
|
||||
* Returns {@code null} if nothing should happen.
|
||||
*
|
||||
* @param level The level
|
||||
* @param pos The block position in level
|
||||
* @param player The player clicking the block
|
||||
* @param stack The stack being used by the player
|
||||
* @param toolAction The tool type to be considered when performing the action
|
||||
* @return The resulting state after the action has been performed
|
||||
* @deprecated Use {@link #getToolModifiedState(UseOnContext, ToolAction, boolean)} instead
|
||||
*/
|
||||
@Nullable
|
||||
// TODO 1.19: Remove
|
||||
@Deprecated(forRemoval = true, since = "1.18.2")
|
||||
default BlockState getToolModifiedState(Level level, BlockPos pos, Player player, ItemStack stack, ToolAction toolAction)
|
||||
{
|
||||
BlockState eventState = net.minecraftforge.event.ForgeEventFactory.onToolUse(self(), level, pos, player, stack, toolAction);
|
||||
return eventState != self() ? eventState : self().getBlock().getToolModifiedState(self(), level, pos, player, stack, toolAction);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a player or entity handles movement on this block like scaffolding.
|
||||
*
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
package net.minecraftforge.common.extensions;
|
||||
|
||||
import java.util.Collection;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.ai.attributes.AttributeInstance;
|
||||
@@ -25,6 +24,7 @@ import net.minecraftforge.common.ForgeMod;
|
||||
import net.minecraftforge.common.ForgeSpawnEggItem;
|
||||
import net.minecraftforge.common.capabilities.ICapabilitySerializable;
|
||||
import net.minecraftforge.entity.PartEntity;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface IForgeEntity extends ICapabilitySerializable<CompoundTag>
|
||||
{
|
||||
|
||||
@@ -5,22 +5,18 @@
|
||||
|
||||
package net.minecraftforge.common.extensions;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.core.HolderSet;
|
||||
import net.minecraft.world.level.material.Material;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.material.Fluid;
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.Explosion;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraftforge.fluids.FluidAttributes;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface IForgeFluid
|
||||
{
|
||||
|
||||
@@ -11,10 +11,9 @@ import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.registries.ForgeRegistry;
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
import net.minecraftforge.registries.IForgeRegistryEntry;
|
||||
import net.minecraftforge.registries.RegistryManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
@@ -34,7 +33,7 @@ public interface IForgeFriendlyByteBuf
|
||||
* @param entry The entry who's registryName is to be written
|
||||
* @param <T> The type of the entry.
|
||||
*/
|
||||
default <T extends IForgeRegistryEntry<T>> void writeRegistryIdUnsafe(@Nonnull IForgeRegistry<T> registry, @Nonnull T entry)
|
||||
default <T> void writeRegistryIdUnsafe(@NotNull IForgeRegistry<T> registry, @NotNull T entry)
|
||||
{
|
||||
ForgeRegistry<T> forgeRegistry = (ForgeRegistry<T>) registry;
|
||||
int id = forgeRegistry.getID(entry);
|
||||
@@ -47,7 +46,7 @@ public interface IForgeFriendlyByteBuf
|
||||
* @param registry The registry containing the entry represented by this key
|
||||
* @param entryKey The registry-name of an entry in this {@link IForgeRegistry}
|
||||
*/
|
||||
default void writeRegistryIdUnsafe(@Nonnull IForgeRegistry<?> registry, @Nonnull ResourceLocation entryKey)
|
||||
default void writeRegistryIdUnsafe(@NotNull IForgeRegistry<?> registry, @NotNull ResourceLocation entryKey)
|
||||
{
|
||||
ForgeRegistry<?> forgeRegistry = (ForgeRegistry<?>) registry;
|
||||
int id = forgeRegistry.getID(entryKey);
|
||||
@@ -59,7 +58,7 @@ public interface IForgeFriendlyByteBuf
|
||||
* read id, that the registry's default value will be returned.
|
||||
* @param registry The registry containing the entry
|
||||
*/
|
||||
default <T extends IForgeRegistryEntry<T>> T readRegistryIdUnsafe(@Nonnull IForgeRegistry<T> registry)
|
||||
default <T> T readRegistryIdUnsafe(@NotNull IForgeRegistry<T> registry)
|
||||
{
|
||||
ForgeRegistry<T> forgeRegistry = (ForgeRegistry<T>) registry;
|
||||
int id = self().readVarInt();
|
||||
@@ -67,23 +66,24 @@ public interface IForgeFriendlyByteBuf
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes an given registry-entry's integer id to the specified buffer in combination with writing the containing registry's id. In contrast to
|
||||
* {@link #writeRegistryIdUnsafe(IForgeRegistry, IForgeRegistryEntry)} this method checks every single step performed as well as
|
||||
* Writes a given registry-entry's integer id to the specified buffer in combination with writing the containing registry's id. In contrast to
|
||||
* {@link #writeRegistryIdUnsafe(IForgeRegistry, Object)} this method checks every single step performed as well as
|
||||
* writing the registry-id to the buffer, in order to prevent any unexpected behaviour. Therefore this method is to be preferred whenever possible,
|
||||
* over using the unsafe methods.
|
||||
*
|
||||
* @param registry The registry containing the entry
|
||||
* @param entry The entry to write
|
||||
* @param <T> The type of the registry-entry
|
||||
* @throws NullPointerException if the entry was null
|
||||
* @throws IllegalArgumentException if the the registry could not be found or the registry does not contain the specified value
|
||||
* @throws NullPointerException if the registry or entry was null
|
||||
* @throws IllegalArgumentException if the registry does not contain the specified value
|
||||
*/
|
||||
default <T extends IForgeRegistryEntry<T>> void writeRegistryId(@Nonnull T entry)
|
||||
default <T> void writeRegistryId(@NotNull IForgeRegistry<T> registry, @NotNull T entry)
|
||||
{
|
||||
Class<T> regType = Objects.requireNonNull(entry,"Cannot write a null registry entry!").getRegistryType();
|
||||
IForgeRegistry<T> retrievedRegistry = RegistryManager.ACTIVE.getRegistry(regType);
|
||||
Preconditions.checkArgument(retrievedRegistry!=null,"Cannot write registry id for an unknown registry type: %s",regType.getName());
|
||||
ResourceLocation name = retrievedRegistry.getRegistryName();
|
||||
Preconditions.checkArgument(retrievedRegistry.containsValue(entry),"Cannot find %s in %s",entry.getRegistryName()!=null?entry.getRegistryName():entry,name);
|
||||
ForgeRegistry<T> reg = (ForgeRegistry<T>)retrievedRegistry;
|
||||
Objects.requireNonNull(registry, "Cannot write a null registry key!");
|
||||
Objects.requireNonNull(entry,"Cannot write a null registry entry!");
|
||||
ResourceLocation name = registry.getRegistryName();
|
||||
Preconditions.checkArgument(registry.containsValue(entry), "Cannot find %s in %s", registry.getKey(entry) != null ? registry.getKey(entry) : entry, name);
|
||||
ForgeRegistry<T> reg = (ForgeRegistry<T>) registry;
|
||||
self().writeResourceLocation(name); //TODO change to writing a varInt once registries use id's
|
||||
self().writeVarInt(reg.getID(entry));
|
||||
}
|
||||
@@ -94,7 +94,7 @@ public interface IForgeFriendlyByteBuf
|
||||
* @param <T> The type of the registry-entry. Notice that this should match the actual type written to the buffer.
|
||||
* @throws NullPointerException if the registry could not be found.
|
||||
*/
|
||||
default <T extends IForgeRegistryEntry<T>> T readRegistryId()
|
||||
default <T> T readRegistryId()
|
||||
{
|
||||
ResourceLocation location = self().readResourceLocation(); //TODO change to reading a varInt once registries use id's
|
||||
ForgeRegistry<T> registry = RegistryManager.ACTIVE.getRegistry(location);
|
||||
@@ -107,10 +107,10 @@ public interface IForgeFriendlyByteBuf
|
||||
* @throws IllegalArgumentException if the retrieved entries registryType doesn't match the one passed in.
|
||||
* @throws NullPointerException if the registry could not be found.
|
||||
*/
|
||||
default <T extends IForgeRegistryEntry<T>> T readRegistryIdSafe(Class<? super T> registrySuperType)
|
||||
default <T> T readRegistryIdSafe(Class<? super T> registrySuperType)
|
||||
{
|
||||
T value = readRegistryId();
|
||||
if (!value.getRegistryType().equals(registrySuperType))
|
||||
if (!registrySuperType.isAssignableFrom(value.getClass()))
|
||||
throw new IllegalArgumentException("Attempted to read an registryValue of the wrong type from the Buffer!");
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -10,9 +10,6 @@ import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
@@ -36,14 +33,14 @@ import net.minecraft.world.item.context.UseOnContext;
|
||||
import net.minecraft.world.item.crafting.RecipeType;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.common.ToolAction;
|
||||
import net.minecraftforge.common.ToolActions;
|
||||
import net.minecraftforge.registries.IForgeRegistryEntry;
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
// TODO systemic review of all extension functions. lots of unused -C
|
||||
public interface IForgeItem
|
||||
@@ -601,7 +598,7 @@ public interface IForgeItem
|
||||
*
|
||||
* @param itemStack the ItemStack to check
|
||||
* @return the Mod ID for the ItemStack, or null when there is no specially
|
||||
* associated mod and {@link IForgeRegistryEntry#getRegistryName()} would return null.
|
||||
* associated mod and {@link IForgeRegistry#getKey(Object)} would return null.
|
||||
*/
|
||||
@Nullable
|
||||
default String getCreatorModId(ItemStack itemStack)
|
||||
@@ -757,17 +754,17 @@ public interface IForgeItem
|
||||
{
|
||||
return self().canBeDepleted();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a bounding box ({@link AABB}) of a sweep attack.
|
||||
*
|
||||
*
|
||||
* @param stack the stack held by the player.
|
||||
* @param player the performing the attack the attack.
|
||||
* @param target the entity targeted by the attack.
|
||||
* @return the bounding box.
|
||||
*/
|
||||
@Nonnull
|
||||
default AABB getSweepHitBox(@Nonnull ItemStack stack, @Nonnull Player player, @Nonnull Entity target)
|
||||
@NotNull
|
||||
default AABB getSweepHitBox(@NotNull ItemStack stack, @NotNull Player player, @NotNull Entity target)
|
||||
{
|
||||
return target.getBoundingBox().inflate(1.0D, 0.25D, 1.0D);
|
||||
}
|
||||
@@ -778,7 +775,7 @@ public interface IForgeItem
|
||||
* @param stack the stack
|
||||
* @return the default hide flags
|
||||
*/
|
||||
default int getDefaultTooltipHideFlags(@Nonnull ItemStack stack)
|
||||
default int getDefaultTooltipHideFlags(@NotNull ItemStack stack)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -5,9 +5,6 @@
|
||||
|
||||
package net.minecraftforge.common.extensions;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.monster.EnderMan;
|
||||
@@ -35,6 +32,8 @@ import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.common.ToolAction;
|
||||
import net.minecraftforge.common.ToolActions;
|
||||
import net.minecraftforge.common.capabilities.ICapabilitySerializable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/*
|
||||
* Extension added to ItemStack that bounces to ItemSack sensitive Item methods. Typically this is just for convince.
|
||||
@@ -483,16 +482,16 @@ public interface IForgeItemStack extends ICapabilitySerializable<CompoundTag>
|
||||
{
|
||||
return self().getItem().canWalkOnPowderedSnow(self(), wearer);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a bounding box ({@link AABB}) of a sweep attack.
|
||||
*
|
||||
*
|
||||
* @param player the performing the attack the attack.
|
||||
* @param target the entity targeted by the attack.
|
||||
* @return the bounding box.
|
||||
*/
|
||||
@Nonnull
|
||||
default AABB getSweepHitBox(@Nonnull Player player, @Nonnull Entity target)
|
||||
@NotNull
|
||||
default AABB getSweepHitBox(@NotNull Player player, @NotNull Entity target)
|
||||
{
|
||||
return self().getItem().getSweepHitBox(self(), player, target);
|
||||
}
|
||||
|
||||
@@ -11,13 +11,14 @@ import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.Tag;
|
||||
import net.minecraft.tags.TagBuilder;
|
||||
import net.minecraft.tags.TagEntry;
|
||||
|
||||
public interface IForgeRawTagBuilder
|
||||
{
|
||||
default Tag.Builder getRawBuilder()
|
||||
default TagBuilder getRawBuilder()
|
||||
{
|
||||
return (Tag.Builder)this;
|
||||
return (TagBuilder)this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -25,10 +26,10 @@ public interface IForgeRawTagBuilder
|
||||
*/
|
||||
default void serializeTagAdditions(final JsonObject tagJson)
|
||||
{
|
||||
Tag.Builder rawBuilder = this.getRawBuilder();
|
||||
Stream<Tag.BuilderEntry> removeEntries = rawBuilder.getRemoveEntries();
|
||||
TagBuilder rawBuilder = this.getRawBuilder();
|
||||
Stream<TagEntry> removeEntries = rawBuilder.getRemoveEntries();
|
||||
JsonArray removeEntriesAsJsonArray = new JsonArray();
|
||||
removeEntries.forEach(proxy ->proxy.entry().serializeTo(removeEntriesAsJsonArray));
|
||||
//removeEntries.forEach(proxy ->proxy.serializeTo(removeEntriesAsJsonArray)); // TODO: Figure out what the replacement for this is. -C
|
||||
if (removeEntriesAsJsonArray.size() > 0)
|
||||
{
|
||||
tagJson.add("remove", removeEntriesAsJsonArray);
|
||||
@@ -42,9 +43,9 @@ public interface IForgeRawTagBuilder
|
||||
* @param source The source of the caller for logging purposes (generally a modid)
|
||||
* @return The builder for chaining purposes
|
||||
*/
|
||||
default Tag.Builder remove(final Tag.Entry tagEntry, final String source)
|
||||
default TagBuilder remove(final TagEntry tagEntry, final String source)
|
||||
{
|
||||
return this.getRawBuilder().remove(new Tag.BuilderEntry(tagEntry,source));
|
||||
return this.getRawBuilder().remove(tagEntry);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,9 +54,9 @@ public interface IForgeRawTagBuilder
|
||||
* @param source The source of the caller for logging purposes (generally a modid)
|
||||
* @return The builder for chaining purposes
|
||||
*/
|
||||
default Tag.Builder removeElement(final ResourceLocation elementID, final String source)
|
||||
default TagBuilder removeElement(final ResourceLocation elementID, final String source)
|
||||
{
|
||||
return this.remove(new Tag.ElementEntry(elementID), source);
|
||||
return this.remove(TagEntry.element(elementID), source);
|
||||
}
|
||||
|
||||
|
||||
@@ -65,8 +66,8 @@ public interface IForgeRawTagBuilder
|
||||
* @param source The source of the caller for logging purposes (generally a modid)
|
||||
* @return The builder for chaining purposes
|
||||
*/
|
||||
default Tag.Builder removeTag(final ResourceLocation tagID, final String source)
|
||||
default TagBuilder removeTag(final ResourceLocation tagID, final String source)
|
||||
{
|
||||
return this.remove(new Tag.TagEntry(tagID), source);
|
||||
return this.remove(TagEntry.tag(tagID), source);
|
||||
}
|
||||
}
|
||||
@@ -6,8 +6,6 @@
|
||||
package net.minecraftforge.common.extensions;
|
||||
|
||||
import net.minecraft.data.tags.TagsProvider;
|
||||
import net.minecraft.tags.Tag;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.TagKey;
|
||||
|
||||
|
||||
@@ -16,8 +16,8 @@ import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
|
||||
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
|
||||
import net.minecraft.world.level.storage.loot.predicates.LootItemConditionType;
|
||||
import net.minecraftforge.common.ToolAction;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@@ -33,12 +33,12 @@ public class CanToolPerformAction implements LootItemCondition {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@NotNull
|
||||
public LootItemConditionType getType() {
|
||||
return LOOT_CONDITION_TYPE;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@NotNull
|
||||
public Set<LootContextParam<?>> getReferencedContextParams() {
|
||||
return ImmutableSet.of(LootContextParams.TOOL);
|
||||
}
|
||||
@@ -53,12 +53,12 @@ public class CanToolPerformAction implements LootItemCondition {
|
||||
}
|
||||
|
||||
public static class Serializer implements net.minecraft.world.level.storage.loot.Serializer<CanToolPerformAction> {
|
||||
public void serialize(JsonObject json, CanToolPerformAction itemCondition, @Nonnull JsonSerializationContext context) {
|
||||
public void serialize(JsonObject json, CanToolPerformAction itemCondition, @NotNull JsonSerializationContext context) {
|
||||
json.addProperty("action", itemCondition.action.name());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public CanToolPerformAction deserialize(JsonObject json, @Nonnull JsonDeserializationContext context) {
|
||||
@NotNull
|
||||
public CanToolPerformAction deserialize(JsonObject json, @NotNull JsonDeserializationContext context) {
|
||||
return new CanToolPerformAction(ToolAction.get(json.get("action").getAsString()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,8 +10,6 @@ import com.google.gson.JsonObject;
|
||||
import net.minecraft.advancements.critereon.SerializationContext;
|
||||
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.registries.GameData;
|
||||
import net.minecraftforge.registries.IForgeRegistryEntry;
|
||||
|
||||
/**
|
||||
* Abstract base deserializer for LootModifiers. Takes care of Forge registry things.<br/>
|
||||
@@ -19,28 +17,7 @@ import net.minecraftforge.registries.IForgeRegistryEntry;
|
||||
* <code>read</code> method to deserialize from json.
|
||||
* @param <T> the Type to deserialize
|
||||
*/
|
||||
public abstract class GlobalLootModifierSerializer<T extends IGlobalLootModifier> implements IForgeRegistryEntry<GlobalLootModifierSerializer<?>> {
|
||||
private ResourceLocation registryName = null;
|
||||
|
||||
public final GlobalLootModifierSerializer<T> setRegistryName(String name) {
|
||||
if (getRegistryName() != null)
|
||||
throw new IllegalStateException("Attempted to set registry name with existing registry name! New: " + name + " Old: " + getRegistryName());
|
||||
|
||||
this.registryName = GameData.checkPrefix(name, true);
|
||||
return this;
|
||||
}
|
||||
|
||||
//Helpers
|
||||
@Override
|
||||
public final GlobalLootModifierSerializer<T> setRegistryName(ResourceLocation name){ return setRegistryName(name.toString()); }
|
||||
|
||||
public final GlobalLootModifierSerializer<T> setRegistryName(String modID, String name){ return setRegistryName(modID + ":" + name); }
|
||||
|
||||
@Override
|
||||
public final ResourceLocation getRegistryName() {
|
||||
return registryName;
|
||||
}
|
||||
|
||||
public abstract class GlobalLootModifierSerializer<T extends IGlobalLootModifier> {
|
||||
/**
|
||||
* Most mods will likely not need more than<br/>
|
||||
* <code>return new MyModifier(conditionsIn)</code><br/>
|
||||
@@ -68,18 +45,4 @@ public abstract class GlobalLootModifierSerializer<T extends IGlobalLootModifier
|
||||
json.add("conditions", SerializationContext.INSTANCE.serializeConditions(conditions));
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used by Forge's registry system.
|
||||
*/
|
||||
@Override
|
||||
public final Class<GlobalLootModifierSerializer<?>> getRegistryType() {
|
||||
return castClass(GlobalLootModifierSerializer.class);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked") // Need this wrapper, because generics
|
||||
private static <G> Class<G> castClass(Class<?> cls)
|
||||
{
|
||||
return (Class<G>)cls;
|
||||
}
|
||||
}
|
||||
@@ -5,12 +5,10 @@
|
||||
|
||||
package net.minecraftforge.common.loot;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.storage.loot.LootContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Implementation that defines what a global loot modifier must implement in order to be functional.
|
||||
@@ -25,6 +23,6 @@ public interface IGlobalLootModifier {
|
||||
* @param context the LootContext, identical to what is passed to loot tables
|
||||
* @return modified loot drops
|
||||
*/
|
||||
@Nonnull
|
||||
List<ItemStack> apply(List<ItemStack> generatedLoot, LootContext context);
|
||||
@NotNull
|
||||
ObjectArrayList<ItemStack> apply(ObjectArrayList<ItemStack> generatedLoot, LootContext context);
|
||||
}
|
||||
@@ -5,15 +5,14 @@
|
||||
|
||||
package net.minecraftforge.common.loot;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.storage.loot.LootContext;
|
||||
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
|
||||
import net.minecraft.world.level.storage.loot.predicates.LootItemConditions;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A base implementation of a Global Loot Modifier for modders to extend.
|
||||
@@ -23,7 +22,7 @@ import net.minecraft.world.level.storage.loot.predicates.LootItemConditions;
|
||||
public abstract class LootModifier implements IGlobalLootModifier {
|
||||
protected final LootItemCondition[] conditions;
|
||||
private final Predicate<LootContext> combinedConditions;
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a LootModifier.
|
||||
* @param conditionsIn the ILootConditions that need to be matched before the loot is modified.
|
||||
@@ -32,13 +31,13 @@ public abstract class LootModifier implements IGlobalLootModifier {
|
||||
this.conditions = conditionsIn;
|
||||
this.combinedConditions = LootItemConditions.andConditions(conditionsIn);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public final List<ItemStack> apply(List<ItemStack> generatedLoot, LootContext context) {
|
||||
public final ObjectArrayList<ItemStack> apply(ObjectArrayList<ItemStack> generatedLoot, LootContext context) {
|
||||
return this.combinedConditions.test(context) ? this.doApply(generatedLoot, context) : generatedLoot;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Applies the modifier to the generated loot (all loot conditions have already been checked
|
||||
* and have returned true).
|
||||
@@ -46,6 +45,6 @@ public abstract class LootModifier implements IGlobalLootModifier {
|
||||
* @param context the LootContext, identical to what is passed to loot tables
|
||||
* @return modified loot drops
|
||||
*/
|
||||
@Nonnull
|
||||
protected abstract List<ItemStack> doApply(List<ItemStack> generatedLoot, LootContext context);
|
||||
@NotNull
|
||||
protected abstract ObjectArrayList<ItemStack> doApply(ObjectArrayList<ItemStack> generatedLoot, LootContext context);
|
||||
}
|
||||
@@ -68,32 +68,26 @@ public class LootModifierManager extends SimpleJsonResourceReloadListener {
|
||||
//new way
|
||||
ArrayList<ResourceLocation> finalLocations = new ArrayList<ResourceLocation>();
|
||||
ResourceLocation resourcelocation = new ResourceLocation("forge","loot_modifiers/global_loot_modifiers.json");
|
||||
try {
|
||||
//read in all data files from forge:loot_modifiers/global_loot_modifiers in order to do layering
|
||||
for(Resource iresource : resourceManagerIn.getResources(resourcelocation)) {
|
||||
try ( InputStream inputstream = iresource.getInputStream();
|
||||
Reader reader = new BufferedReader(new InputStreamReader(inputstream, StandardCharsets.UTF_8));
|
||||
) {
|
||||
JsonObject jsonobject = GsonHelper.fromJson(GSON_INSTANCE, reader, JsonObject.class);
|
||||
boolean replace = jsonobject.get("replace").getAsBoolean();
|
||||
if(replace) finalLocations.clear();
|
||||
JsonArray entryList = jsonobject.get("entries").getAsJsonArray();
|
||||
for(JsonElement entry : entryList) {
|
||||
String loc = entry.getAsString();
|
||||
ResourceLocation res = new ResourceLocation(loc);
|
||||
if(finalLocations.contains(res)) finalLocations.remove(res);
|
||||
finalLocations.add(res);
|
||||
}
|
||||
}
|
||||
|
||||
catch (RuntimeException | IOException ioexception) {
|
||||
LOGGER.error("Couldn't read global loot modifier list {} in data pack {}", resourcelocation, iresource.getSourceName(), ioexception);
|
||||
} finally {
|
||||
IOUtils.closeQuietly((Closeable)iresource);
|
||||
//read in all data files from forge:loot_modifiers/global_loot_modifiers in order to do layering
|
||||
for(Resource iresource : resourceManagerIn.getResourceStack(resourcelocation)) {
|
||||
try ( InputStream inputstream = iresource.open();
|
||||
Reader reader = new BufferedReader(new InputStreamReader(inputstream, StandardCharsets.UTF_8));
|
||||
) {
|
||||
JsonObject jsonobject = GsonHelper.fromJson(GSON_INSTANCE, reader, JsonObject.class);
|
||||
boolean replace = jsonobject.get("replace").getAsBoolean();
|
||||
if(replace) finalLocations.clear();
|
||||
JsonArray entryList = jsonobject.get("entries").getAsJsonArray();
|
||||
for(JsonElement entry : entryList) {
|
||||
String loc = entry.getAsString();
|
||||
ResourceLocation res = new ResourceLocation(loc);
|
||||
if(finalLocations.contains(res)) finalLocations.remove(res);
|
||||
finalLocations.add(res);
|
||||
}
|
||||
}
|
||||
} catch (IOException ioexception1) {
|
||||
LOGGER.error("Couldn't read global loot modifier list from {}", resourcelocation, ioexception1);
|
||||
|
||||
catch (RuntimeException | IOException ioexception) {
|
||||
LOGGER.error("Couldn't read global loot modifier list {} in data pack {}", resourcelocation, iresource.sourcePackId(), ioexception);
|
||||
}
|
||||
}
|
||||
//use layered config to fetch modifier data files (modifiers missing from config are disabled)
|
||||
finalLocations.forEach(location -> {
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.modloading;
|
||||
|
||||
public class ForgeModStateProvider {
|
||||
//
|
||||
// statusConsumer.ifPresent(c->c.accept("Creating registries"));
|
||||
// dispatchAndHandleError(ModLoadingStage.CREATE_REGISTRIES, syncExecutor, parallelExecutor, periodicTask);
|
||||
// ObjectHolderRegistry.findObjectHolders();
|
||||
// CapabilityManager.INSTANCE.injectCapabilities(modList.getAllScanData());
|
||||
// statusConsumer.ifPresent(c->c.accept("Adding custom tag types"));
|
||||
// GameData.setCustomTagTypesFromRegistries();
|
||||
// statusConsumer.ifPresent(c->c.accept("Populating registries"));
|
||||
// dispatchAndHandleError(ModLoadingStage.LOAD_REGISTRIES, syncExecutor, parallelExecutor, periodicTask);
|
||||
}
|
||||
@@ -7,15 +7,14 @@ package net.minecraftforge.common.ticket;
|
||||
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class AABBTicket extends SimpleTicket<Vec3>
|
||||
{
|
||||
@Nonnull
|
||||
@NotNull
|
||||
public final AABB axisAlignedBB;
|
||||
|
||||
public AABBTicket(@Nonnull AABB axisAlignedBB)
|
||||
public AABBTicket(@NotNull AABB axisAlignedBB)
|
||||
{
|
||||
this.axisAlignedBB = axisAlignedBB;
|
||||
}
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
package net.minecraftforge.common.ticket;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
@@ -28,7 +28,7 @@ public abstract class SimpleTicket<T>
|
||||
* Should <b>not</b> be called if you just want to register a ticket to a system like the {@link net.minecraftforge.common.FarmlandWaterManager}
|
||||
*/
|
||||
@SafeVarargs
|
||||
public final void setManager(@Nonnull ITicketManager<T> masterManager, @Nonnull ITicketManager<T>... dummyManagers)
|
||||
public final void setManager(@NotNull ITicketManager<T> masterManager, @NotNull ITicketManager<T>... dummyManagers)
|
||||
{
|
||||
Preconditions.checkState(this.masterManager == null, "Ticket is already registered to a managing system");
|
||||
this.masterManager = masterManager;
|
||||
|
||||
@@ -18,8 +18,7 @@ import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.server.ServerLifecycleHooks;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Represents a captured snapshot of a block which will not change
|
||||
|
||||
@@ -67,25 +67,23 @@ import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.server.ServerLifecycleHooks;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
//Preliminary, simple Fake Player class
|
||||
public class FakePlayer extends ServerPlayer
|
||||
{
|
||||
public FakePlayer(ServerLevel level, GameProfile name)
|
||||
{
|
||||
super(level.getServer(), level, name);
|
||||
super(level.getServer(), level, name, null);
|
||||
this.connection = new FakePlayerNetHandler(level.getServer(), this);
|
||||
}
|
||||
|
||||
@Override public Vec3 position(){ return new Vec3(0, 0, 0); }
|
||||
@Override public BlockPos blockPosition(){ return BlockPos.ZERO; }
|
||||
@Override public void displayClientMessage(Component chatComponent, boolean actionBar){}
|
||||
@Override public void sendMessage(Component component, UUID senderUUID) {}
|
||||
@Override public void awardStat(Stat par1StatBase, int par2){}
|
||||
//@Override public void openGui(Object mod, int modGuiId, World world, int x, int y, int z){}
|
||||
@Override public boolean isInvulnerableTo(DamageSource source){ return true; }
|
||||
|
||||
@@ -10,8 +10,8 @@ import net.minecraft.world.level.block.SoundType;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
@@ -51,35 +51,35 @@ public class ForgeSoundType extends SoundType
|
||||
this.fallSound = fallSoundIn;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@NotNull
|
||||
@Override
|
||||
public SoundEvent getBreakSound()
|
||||
{
|
||||
return breakSound.get();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@NotNull
|
||||
@Override
|
||||
public SoundEvent getStepSound()
|
||||
{
|
||||
return stepSound.get();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@NotNull
|
||||
@Override
|
||||
public SoundEvent getPlaceSound()
|
||||
{
|
||||
return placeSound.get();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@NotNull
|
||||
@Override
|
||||
public SoundEvent getHitSound()
|
||||
{
|
||||
return hitSound.get();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@NotNull
|
||||
@Override
|
||||
public SoundEvent getFallSound()
|
||||
{
|
||||
|
||||
@@ -7,8 +7,6 @@ package net.minecraftforge.common.util;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.portal.PortalInfo;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
@@ -16,6 +14,7 @@ import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraft.world.level.portal.PortalForcer;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Interface for handling the placement of entities during dimension change.
|
||||
@@ -52,16 +51,16 @@ public interface ITeleporter
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the PortalInfo. defaultPortalInfo references the
|
||||
* vanilla code and should not be used for your purposes.
|
||||
* Override this method to handle your own logic.
|
||||
* Gets the PortalInfo. defaultPortalInfo references the
|
||||
* vanilla code and should not be used for your purposes.
|
||||
* Override this method to handle your own logic.
|
||||
* <p>
|
||||
* Return {@code null} to prevent teleporting.
|
||||
*
|
||||
*
|
||||
* @param entity The entity teleporting before the teleport
|
||||
* @param destWorld The world the entity is teleporting to
|
||||
* @param defaultPortalInfo A reference to the vanilla method for getting portal info. You should implement your own logic instead of using this
|
||||
*
|
||||
*
|
||||
* @return The location, rotation, and motion of the entity in the destWorld after the teleport
|
||||
*/
|
||||
@Nullable
|
||||
@@ -69,7 +68,7 @@ public interface ITeleporter
|
||||
{
|
||||
return this.isVanilla() ? defaultPortalInfo.apply(destWorld) : new PortalInfo(entity.position(), Vec3.ZERO, entity.getYRot(), entity.getXRot());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Is this teleporter the vanilla instance.
|
||||
*/
|
||||
|
||||
@@ -26,8 +26,7 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
|
||||
import net.minecraft.nbt.TagParser;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class JsonUtils
|
||||
{
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
|
||||
package net.minecraftforge.common.util;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
@@ -19,7 +19,7 @@ public interface Lazy<T> extends Supplier<T>
|
||||
* Constructs a lazy-initialized object
|
||||
* @param supplier The supplier for the value, to be called the first time the value is needed.
|
||||
*/
|
||||
static <T> Lazy<T> of(@Nonnull Supplier<T> supplier)
|
||||
static <T> Lazy<T> of(@NotNull Supplier<T> supplier)
|
||||
{
|
||||
return new Lazy.Fast<>(supplier);
|
||||
}
|
||||
@@ -28,7 +28,7 @@ public interface Lazy<T> extends Supplier<T>
|
||||
* Constructs a thread-safe lazy-initialized object
|
||||
* @param supplier The supplier for the value, to be called the first time the value is needed.
|
||||
*/
|
||||
static <T> Lazy<T> concurrentOf(@Nonnull Supplier<T> supplier)
|
||||
static <T> Lazy<T> concurrentOf(@NotNull Supplier<T> supplier)
|
||||
{
|
||||
return new Lazy.Concurrent<>(supplier);
|
||||
}
|
||||
|
||||
@@ -10,8 +10,6 @@ import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import net.minecraft.MethodsReturnNonnullByDefault;
|
||||
@@ -21,6 +19,8 @@ import org.apache.commons.lang3.mutable.MutableObject;
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* This object encapsulates a lazy value, with typical transformation operations
|
||||
@@ -35,7 +35,7 @@ import org.apache.logging.log4j.Logger;
|
||||
* must never be null.
|
||||
* <p>
|
||||
* The empty instance can be retrieved with {@link #empty()}.
|
||||
*
|
||||
*
|
||||
* @param <T> The type of the optional value.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
@@ -51,13 +51,13 @@ public class LazyOptional<T>
|
||||
private Set<NonNullConsumer<LazyOptional<T>>> listeners = new HashSet<>();
|
||||
private boolean isValid = true;
|
||||
|
||||
private static final @Nonnull LazyOptional<Void> EMPTY = new LazyOptional<>(null);
|
||||
private static final @NotNull LazyOptional<Void> EMPTY = new LazyOptional<>(null);
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
/**
|
||||
* Construct a new {@link LazyOptional} that wraps the given
|
||||
* {@link NonNullSupplier}.
|
||||
*
|
||||
*
|
||||
* @param instanceSupplier The {@link NonNullSupplier} to wrap. Cannot return
|
||||
* null, but can be null itself. If null, this method
|
||||
* returns {@link #empty()}.
|
||||
@@ -79,7 +79,7 @@ public class LazyOptional<T>
|
||||
* This method hides an unchecked cast to the inferred type. Only use this if
|
||||
* you are sure the type should match. For capabilities, generally
|
||||
* {@link Capability#orEmpty(Capability, LazyOptional)} should be used.
|
||||
*
|
||||
*
|
||||
* @return This {@link LazyOptional}, cast to the inferred generic type
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -126,7 +126,7 @@ public class LazyOptional<T>
|
||||
|
||||
/**
|
||||
* Check if this {@link LazyOptional} is non-empty.
|
||||
*
|
||||
*
|
||||
* @return {@code true} if this {@link LazyOptional} is non-empty, i.e. holds a
|
||||
* non-null supplier
|
||||
*/
|
||||
@@ -202,7 +202,7 @@ public class LazyOptional<T>
|
||||
* <em>It is important to note that this method is <strong>not</strong> lazy, as
|
||||
* it must resolve the value of the supplier to validate it with the
|
||||
* predicate.</em>
|
||||
*
|
||||
*
|
||||
* @param predicate A {@link NonNullPredicate} to apply to the result of the
|
||||
* contained supplier, if non-empty
|
||||
* @return An {@link Optional} containing the result of the contained
|
||||
|
||||
@@ -5,16 +5,16 @@
|
||||
|
||||
package net.minecraftforge.common.util;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Equivalent to {@link Consumer}, except with nonnull contract.
|
||||
*
|
||||
*
|
||||
* @see Consumer
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface NonNullConsumer<T>
|
||||
{
|
||||
void accept(@Nonnull T t);
|
||||
void accept(@NotNull T t);
|
||||
}
|
||||
@@ -5,17 +5,17 @@
|
||||
|
||||
package net.minecraftforge.common.util;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Equivalent to {@link Function}, except with nonnull contract.
|
||||
*
|
||||
*
|
||||
* @see Function
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface NonNullFunction<T, R>
|
||||
{
|
||||
@Nonnull
|
||||
R apply(@Nonnull T t);
|
||||
@NotNull
|
||||
R apply(@NotNull T t);
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
package net.minecraftforge.common.util;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
@@ -19,7 +19,7 @@ public interface NonNullLazy<T> extends NonNullSupplier<T>
|
||||
* Constructs a lazy-initialized object
|
||||
* @param supplier The supplier for the value, to be called the first time the value is needed.
|
||||
*/
|
||||
static <T> NonNullLazy<T> of(@Nonnull NonNullSupplier<T> supplier)
|
||||
static <T> NonNullLazy<T> of(@NotNull NonNullSupplier<T> supplier)
|
||||
{
|
||||
Lazy<T> lazy = Lazy.of(supplier::get);
|
||||
return () -> Objects.requireNonNull(lazy.get());
|
||||
@@ -29,7 +29,7 @@ public interface NonNullLazy<T> extends NonNullSupplier<T>
|
||||
* Constructs a thread-safe lazy-initialized object
|
||||
* @param supplier The supplier for the value, to be called the first time the value is needed.
|
||||
*/
|
||||
static <T> NonNullLazy<T> concurrentOf(@Nonnull NonNullSupplier<T> supplier)
|
||||
static <T> NonNullLazy<T> concurrentOf(@NotNull NonNullSupplier<T> supplier)
|
||||
{
|
||||
Lazy<T> lazy = Lazy.concurrentOf(supplier::get);
|
||||
return () -> Objects.requireNonNull(lazy.get());
|
||||
|
||||
@@ -5,16 +5,16 @@
|
||||
|
||||
package net.minecraftforge.common.util;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* Equivalent to {@link Predicate}, except with nonnull contract.
|
||||
*
|
||||
*
|
||||
* @see Predicate
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface NonNullPredicate<T>
|
||||
{
|
||||
boolean test(@Nonnull T t);
|
||||
boolean test(@NotNull T t);
|
||||
}
|
||||
@@ -5,16 +5,16 @@
|
||||
|
||||
package net.minecraftforge.common.util;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Equivalent to {@link Supplier}, except with nonnull contract.
|
||||
*
|
||||
*
|
||||
* @see Supplier
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface NonNullSupplier<T>
|
||||
{
|
||||
@Nonnull T get();
|
||||
@NotNull T get();
|
||||
}
|
||||
@@ -7,8 +7,8 @@ package net.minecraftforge.common.util;
|
||||
|
||||
import com.google.common.collect.Streams;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -93,7 +93,7 @@ public class TextTable
|
||||
}
|
||||
}
|
||||
|
||||
public void add(@Nonnull Object... values)
|
||||
public void add(@NotNull Object... values)
|
||||
{
|
||||
if (values.length != columns.size())
|
||||
{
|
||||
|
||||
@@ -5,11 +5,9 @@
|
||||
|
||||
package net.minecraftforge.common.util;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.level.saveddata.SavedData;
|
||||
import net.minecraftforge.common.capabilities.CapabilityProvider;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class WorldCapabilityData extends SavedData
|
||||
{
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.world;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.HolderSet;
|
||||
import net.minecraft.core.RegistryCodecs;
|
||||
import net.minecraft.resources.RegistryFileCodec;
|
||||
import net.minecraft.resources.RegistryOps;
|
||||
import net.minecraft.util.ExtraCodecs;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraftforge.common.world.ModifiableBiomeInfo.BiomeInfo;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* JSON-serializable biome modifier.
|
||||
* Requires a {@link Codec} to deserialize biome modifiers from biome modifier jsons.
|
||||
* <p>
|
||||
* Biome modifier jsons have the following json format:
|
||||
* <pre>
|
||||
* {
|
||||
* "type": "yourmod:yourserializer", // Indicates a registered biome modifier serializer
|
||||
* // Additional fields can be specified here according to the codec
|
||||
* }
|
||||
* </pre>
|
||||
* <p>
|
||||
* Datapacks can also disable a biome modifier by overriding the json and using {@code "type": "forge:none"}.</p>
|
||||
*/
|
||||
public interface BiomeModifier
|
||||
{
|
||||
/**
|
||||
* Codec for (de)serializing biome modifiers inline.
|
||||
* Mods can use this for data generation.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
Codec<BiomeModifier> DIRECT_CODEC = ExtraCodecs.lazyInitializedCodec(() -> ForgeRegistries.BIOME_MODIFIER_SERIALIZERS.get().getCodec())
|
||||
.dispatch(BiomeModifier::codec, Function.identity());
|
||||
|
||||
/**
|
||||
* Codec for referring to biome modifiers by id in other datapack registry files.
|
||||
* Can only be used with {@link RegistryOps}.
|
||||
*/
|
||||
Codec<Holder<BiomeModifier>> REFERENCE_CODEC = RegistryFileCodec.create(ForgeRegistries.Keys.BIOME_MODIFIERS, DIRECT_CODEC);
|
||||
|
||||
/**
|
||||
* Codec for referring to biome modifiers by id, list of id, or tags.
|
||||
* Can only be used with {@link RegistryOps}.
|
||||
*/
|
||||
Codec<HolderSet<BiomeModifier>> LIST_CODEC = RegistryCodecs.homogeneousList(ForgeRegistries.Keys.BIOME_MODIFIERS, DIRECT_CODEC);
|
||||
|
||||
/**
|
||||
* Modifies the information via the provided biome builder.
|
||||
* Allows mob spawns and world-gen features to be added or removed,
|
||||
* and climate and client effects to be modified.
|
||||
*
|
||||
* @param biome the named biome being modified (with original data readable).
|
||||
* @param phase biome modification phase. Biome modifiers apply in each phase in order of the enum constants.
|
||||
* @param builder mutable biome info builder. Apply changes to this.
|
||||
*/
|
||||
void modify(Holder<Biome> biome, Phase phase, BiomeInfo.Builder builder);
|
||||
|
||||
/**
|
||||
* @return the codec which serializes and deserializes this biome modifier
|
||||
*/
|
||||
Codec<? extends BiomeModifier> codec();
|
||||
|
||||
enum Phase
|
||||
{
|
||||
/**
|
||||
* Catch-all for anything that needs to run before standard phases.
|
||||
*/
|
||||
BEFORE_EVERYTHING,
|
||||
/**
|
||||
* Additional features, mob spawns, etc.
|
||||
*/
|
||||
ADD,
|
||||
/**
|
||||
* Removal of features, mob spawns, etc.
|
||||
*/
|
||||
REMOVE,
|
||||
/**
|
||||
* Alteration of values such as climate or colors.
|
||||
*/
|
||||
MODIFY,
|
||||
/**
|
||||
* Catch-all for anything that needs to run after standard phases.
|
||||
*/
|
||||
AFTER_EVERYTHING
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.world;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import net.minecraft.sounds.Music;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.world.level.biome.AmbientAdditionsSettings;
|
||||
import net.minecraft.world.level.biome.AmbientMoodSettings;
|
||||
import net.minecraft.world.level.biome.AmbientParticleSettings;
|
||||
import net.minecraft.world.level.biome.BiomeSpecialEffects;
|
||||
|
||||
/**
|
||||
* Extension of the vanilla builder but also provides read access and a copy-from-existing-data helper.
|
||||
* Also, the base builder crashes if certain values aren't specified on build, so this enforces the setting of those.
|
||||
*/
|
||||
public class BiomeSpecialEffectsBuilder extends BiomeSpecialEffects.Builder
|
||||
{
|
||||
public static BiomeSpecialEffectsBuilder copyOf(BiomeSpecialEffects baseEffects)
|
||||
{
|
||||
BiomeSpecialEffectsBuilder builder = BiomeSpecialEffectsBuilder.create(baseEffects.getFogColor(), baseEffects.getWaterColor(), baseEffects.getWaterFogColor(), baseEffects.getSkyColor());
|
||||
builder.grassColorModifier = baseEffects.getGrassColorModifier();
|
||||
baseEffects.getFoliageColorOverride().ifPresent(builder::foliageColorOverride);
|
||||
baseEffects.getGrassColorOverride().ifPresent(builder::grassColorOverride);
|
||||
baseEffects.getAmbientParticleSettings().ifPresent(builder::ambientParticle);
|
||||
baseEffects.getAmbientLoopSoundEvent().ifPresent(builder::ambientLoopSound);
|
||||
baseEffects.getAmbientMoodSettings().ifPresent(builder::ambientMoodSound);
|
||||
baseEffects.getAmbientAdditionsSettings().ifPresent(builder::ambientAdditionsSound);
|
||||
baseEffects.getBackgroundMusic().ifPresent(builder::backgroundMusic);
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static BiomeSpecialEffectsBuilder create(int fogColor, int waterColor, int waterFogColor, int skyColor)
|
||||
{
|
||||
return new BiomeSpecialEffectsBuilder(fogColor, waterColor, waterFogColor, skyColor);
|
||||
}
|
||||
|
||||
protected BiomeSpecialEffectsBuilder(int fogColor, int waterColor, int waterFogColor, int skyColor)
|
||||
{
|
||||
super();
|
||||
this.fogColor(fogColor);
|
||||
this.waterColor(waterColor);
|
||||
this.waterFogColor(waterFogColor);
|
||||
this.skyColor(skyColor);
|
||||
}
|
||||
|
||||
public int getFogColor()
|
||||
{
|
||||
return this.fogColor.getAsInt();
|
||||
}
|
||||
|
||||
public int waterColor()
|
||||
{
|
||||
return this.waterColor.getAsInt();
|
||||
}
|
||||
|
||||
public int getWaterFogColor()
|
||||
{
|
||||
return this.waterFogColor.getAsInt();
|
||||
}
|
||||
|
||||
public int getSkyColor()
|
||||
{
|
||||
return this.skyColor.getAsInt();
|
||||
}
|
||||
|
||||
public BiomeSpecialEffects.GrassColorModifier getGrassColorModifier()
|
||||
{
|
||||
return this.grassColorModifier;
|
||||
}
|
||||
|
||||
public Optional<Integer> getFoliageColorOverride()
|
||||
{
|
||||
return this.foliageColorOverride;
|
||||
}
|
||||
|
||||
public Optional<Integer> getGrassColorOverride()
|
||||
{
|
||||
return this.grassColorOverride;
|
||||
}
|
||||
|
||||
public Optional<AmbientParticleSettings> getAmbientParticle()
|
||||
{
|
||||
return this.ambientParticle;
|
||||
}
|
||||
|
||||
public Optional<SoundEvent> getAmbientLoopSound()
|
||||
{
|
||||
return this.ambientLoopSoundEvent;
|
||||
}
|
||||
|
||||
public Optional<AmbientMoodSettings> getAmbientMoodSound()
|
||||
{
|
||||
return this.ambientMoodSettings;
|
||||
}
|
||||
|
||||
public Optional<AmbientAdditionsSettings> getAmbientAdditionsSound()
|
||||
{
|
||||
return this.ambientAdditionsSettings;
|
||||
}
|
||||
|
||||
public Optional<Music> getBackgroundMusic()
|
||||
{
|
||||
return this.backgroundMusic;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.world;
|
||||
|
||||
import net.minecraft.world.level.biome.Biome.ClimateSettings;
|
||||
import net.minecraft.world.level.biome.Biome.Precipitation;
|
||||
import net.minecraft.world.level.biome.Biome.TemperatureModifier;
|
||||
|
||||
/**
|
||||
* Builder for {@link ClimateSettings}.
|
||||
*/
|
||||
public class ClimateSettingsBuilder
|
||||
{
|
||||
private Precipitation precipitation;
|
||||
private float temperature;
|
||||
private TemperatureModifier temperatureModifier;
|
||||
private float downfall;
|
||||
|
||||
/**
|
||||
* @param settings Existing ClimateSettings.
|
||||
* @return A new builder with a copy of that ClimateSettings's values.
|
||||
*/
|
||||
public static ClimateSettingsBuilder copyOf(ClimateSettings settings)
|
||||
{
|
||||
return create(settings.precipitation(), settings.temperature(), settings.temperatureModifier(), settings.downfall());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param precipitation Synced to clients, determines weather effects
|
||||
* @param temperature Synced to clients, affects foliage color, freezing, and weather effects.
|
||||
* Vanilla values are in the range [-0.5, 2.0]
|
||||
* @param temperatureModifier Synced to clients, applies a positional modifier to temperature.
|
||||
* Frozen Oceans use this to have occasional warm patches.
|
||||
* @param downfall Synced to clients, affects foliage color.
|
||||
* Biomes with downfall > 0.85 count as humid, inhibiting fire spread.
|
||||
* @return a new builder with the given values
|
||||
*/
|
||||
public static ClimateSettingsBuilder create(Precipitation precipitation, float temperature, TemperatureModifier temperatureModifier, float downfall)
|
||||
{
|
||||
return new ClimateSettingsBuilder(precipitation, temperature, temperatureModifier, downfall);
|
||||
}
|
||||
|
||||
private ClimateSettingsBuilder(Precipitation precipitation, float temperature, TemperatureModifier temperatureModifier, float downfall)
|
||||
{
|
||||
this.precipitation = precipitation;
|
||||
this.temperature = temperature;
|
||||
this.temperatureModifier = temperatureModifier;
|
||||
this.downfall = downfall;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A new ClimateSettings with the finalized values.
|
||||
*/
|
||||
public ClimateSettings build()
|
||||
{
|
||||
return new ClimateSettings(this.precipitation, this.temperature, this.temperatureModifier, this.downfall);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Synced to clients, determines weather effects.
|
||||
*/
|
||||
public Precipitation getPrecipitation()
|
||||
{
|
||||
return precipitation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param precipitation Synced to clients, determines weather effects.
|
||||
*/
|
||||
public void setPrecipitation(Precipitation precipitation)
|
||||
{
|
||||
this.precipitation = precipitation;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return Synced to clients, affects foliage color, freezing, and weather effects}
|
||||
* Vanilla values are in the range [-0.5, 2.0].
|
||||
*/
|
||||
public float getTemperature()
|
||||
{
|
||||
return temperature;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param temperature Synced to clients, affects foliage color, freezing, and weather effects.
|
||||
* Vanilla values are in the range [-0.5, 2.0].
|
||||
*/
|
||||
public void setTemperature(float temperature)
|
||||
{
|
||||
this.temperature = temperature;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return temperatureModifier Synced to clients, applies a positional modifier to temperature.}
|
||||
* Frozen Oceans use this to have occasional warm patches.
|
||||
*/
|
||||
public TemperatureModifier getTemperatureModifier()
|
||||
{
|
||||
return temperatureModifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param temperatureModifier Synced to clients, applies a positional modifier to temperature.
|
||||
* Frozen Oceans use this to have occasional warm patches.
|
||||
*/
|
||||
public void setTemperatureModifier(TemperatureModifier temperatureModifier)
|
||||
{
|
||||
this.temperatureModifier = temperatureModifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return Synced to clients, affects foliage color.}
|
||||
* Biomes with downfall > 0.85 count as humid, inhibiting fire spread.
|
||||
*/
|
||||
public float getDownfall()
|
||||
{
|
||||
return downfall;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param downfall Synced to clients, affects foliage color.
|
||||
* Biomes with downfall > 0.85 count as humid, inhibiting fire spread.
|
||||
*/
|
||||
public void setDownfall(float downfall)
|
||||
{
|
||||
this.downfall = downfall;
|
||||
}
|
||||
}
|
||||
@@ -11,19 +11,16 @@ import net.minecraft.Util;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.world.level.dimension.DimensionType;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.level.levelgen.NoiseGeneratorSettings;
|
||||
import net.minecraft.world.level.dimension.LevelStem;
|
||||
import net.minecraft.world.level.levelgen.WorldGenSettings;
|
||||
import net.minecraftforge.common.ForgeConfig;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.ForgeRegistryEntry;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class ForgeWorldPreset extends ForgeRegistryEntry<ForgeWorldPreset>
|
||||
public class ForgeWorldPreset
|
||||
{
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
@@ -57,12 +54,12 @@ public class ForgeWorldPreset extends ForgeRegistryEntry<ForgeWorldPreset>
|
||||
|
||||
public String getTranslationKey()
|
||||
{
|
||||
return Util.makeDescriptionId("generator", getRegistryName());
|
||||
return Util.makeDescriptionId("generator", ForgeRegistries.WORLD_TYPES.get().getKey(this));
|
||||
}
|
||||
|
||||
public Component getDisplayName()
|
||||
{
|
||||
return new TranslatableComponent(getTranslationKey());
|
||||
return Component.translatable(getTranslationKey());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -86,9 +83,10 @@ public class ForgeWorldPreset extends ForgeRegistryEntry<ForgeWorldPreset>
|
||||
|
||||
default WorldGenSettings createSettings(RegistryAccess dynamicRegistries, long seed, boolean generateStructures, boolean bonusChest, String generatorSettings) {
|
||||
Registry<DimensionType> dimensionTypeRegistry = dynamicRegistries.registryOrThrow(Registry.DIMENSION_TYPE_REGISTRY);
|
||||
Registry<LevelStem> levelStemRegistry = dynamicRegistries.registryOrThrow(Registry.LEVEL_STEM_REGISTRY);
|
||||
return new WorldGenSettings(seed, generateStructures, bonusChest,
|
||||
WorldGenSettings.withOverworld(dimensionTypeRegistry,
|
||||
DimensionType.defaultDimensions(dynamicRegistries, seed),
|
||||
levelStemRegistry,
|
||||
createChunkGenerator(dynamicRegistries, seed, generatorSettings)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,11 +9,10 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.world.entity.MobCategory;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.level.biome.MobSpawnSettings;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class MobSpawnSettingsBuilder extends MobSpawnSettings.Builder
|
||||
{
|
||||
|
||||
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.world;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.Biome.ClimateSettings;
|
||||
import net.minecraft.world.level.biome.BiomeGenerationSettings;
|
||||
import net.minecraft.world.level.biome.BiomeSpecialEffects;
|
||||
import net.minecraft.world.level.biome.MobSpawnSettings;
|
||||
|
||||
/**
|
||||
* Holds lazy-evaluable modified biome info.
|
||||
* Memoizers are not used because it's important to return null
|
||||
* without evaluating the biome info if it's accessed outside of a server context.
|
||||
*/
|
||||
public class ModifiableBiomeInfo
|
||||
{
|
||||
@NotNull
|
||||
private final BiomeInfo originalBiomeInfo;
|
||||
@Nullable
|
||||
private BiomeInfo modifiedBiomeInfo = null;
|
||||
|
||||
/**
|
||||
* @param originalBiomeInfo BiomeInfo representing the original state of a biome when the biome was constructed.
|
||||
*/
|
||||
public ModifiableBiomeInfo(@NotNull final BiomeInfo originalBiomeInfo)
|
||||
{
|
||||
this.originalBiomeInfo = originalBiomeInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return The modified biome info if modified biome info has been generated, otherwise gets original biome info}
|
||||
*/
|
||||
@NotNull
|
||||
public BiomeInfo get()
|
||||
{
|
||||
return this.modifiedBiomeInfo == null
|
||||
? originalBiomeInfo
|
||||
: modifiedBiomeInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return The original biome info that the associated biome was created with}
|
||||
*/
|
||||
@NotNull
|
||||
public BiomeInfo getOriginalBiomeInfo()
|
||||
{
|
||||
return this.originalBiomeInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return Modified biome info; null if it hasn't been set yet}
|
||||
*/
|
||||
@Nullable
|
||||
public BiomeInfo getModifiedBiomeInfo()
|
||||
{
|
||||
return this.modifiedBiomeInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal forge method; the game will crash if mods invoke this.
|
||||
* Creates and caches the modified biome info.
|
||||
* @param biome named biome with original data.
|
||||
* @param biomeModifiers biome modifiers to apply.
|
||||
*
|
||||
* @throws IllegalStateException if invoked more than once.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public void applyBiomeModifiers(final Holder<Biome> biome, final List<BiomeModifier> biomeModifiers)
|
||||
{
|
||||
if (this.modifiedBiomeInfo != null)
|
||||
throw new IllegalStateException(String.format(Locale.ENGLISH, "Biome %s already modified", biome));
|
||||
|
||||
BiomeInfo original = this.getOriginalBiomeInfo();
|
||||
final BiomeInfo.Builder builder = BiomeInfo.Builder.copyOf(original);
|
||||
for (BiomeModifier.Phase phase : BiomeModifier.Phase.values())
|
||||
{
|
||||
for (BiomeModifier modifier : biomeModifiers)
|
||||
{
|
||||
modifier.modify(biome, phase, builder);
|
||||
}
|
||||
}
|
||||
this.modifiedBiomeInfo = builder.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Record containing raw biome data.
|
||||
* @param climateSettings Weather and temperature settings.
|
||||
* @param effects Client-relevant effects for rendering and sound.
|
||||
* @param generationSettings Worldgen features and carvers.
|
||||
* @param mobSpawnSettings Mob spawn settings.
|
||||
*/
|
||||
public record BiomeInfo(ClimateSettings climateSettings, BiomeSpecialEffects effects, BiomeGenerationSettings generationSettings, MobSpawnSettings mobSpawnSettings)
|
||||
{
|
||||
public static class Builder
|
||||
{
|
||||
private ClimateSettingsBuilder climateSettings;
|
||||
private BiomeSpecialEffects.Builder effects;
|
||||
private BiomeGenerationSettingsBuilder generationSettings;
|
||||
private MobSpawnSettingsBuilder mobSpawnSettings;
|
||||
|
||||
/**
|
||||
* @param biome A biome that has not had its modified biome data generated yet
|
||||
* @return A ModifiedBiomeInfo.Builder with a copy of the biome's data
|
||||
*/
|
||||
public static Builder copyOf(final BiomeInfo original)
|
||||
{
|
||||
final ClimateSettingsBuilder climateBuilder = ClimateSettingsBuilder.copyOf(original.climateSettings());
|
||||
final BiomeSpecialEffects.Builder effectsBuilder = BiomeSpecialEffectsBuilder.copyOf(original.effects());
|
||||
final BiomeGenerationSettingsBuilder generationBuilder = new BiomeGenerationSettingsBuilder(original.generationSettings());
|
||||
final MobSpawnSettingsBuilder mobSpawnBuilder = new MobSpawnSettingsBuilder(original.mobSpawnSettings());
|
||||
|
||||
return new Builder(
|
||||
climateBuilder,
|
||||
effectsBuilder,
|
||||
generationBuilder,
|
||||
mobSpawnBuilder
|
||||
);
|
||||
}
|
||||
|
||||
private Builder(final ClimateSettingsBuilder climateSettings, final BiomeSpecialEffects.Builder effects, final BiomeGenerationSettingsBuilder generationSettings, final MobSpawnSettingsBuilder mobSpawnSettings)
|
||||
{
|
||||
this.climateSettings = climateSettings;
|
||||
this.effects = effects;
|
||||
this.generationSettings = generationSettings;
|
||||
this.mobSpawnSettings = mobSpawnSettings;
|
||||
}
|
||||
|
||||
public BiomeInfo build()
|
||||
{
|
||||
return new BiomeInfo(this.climateSettings.build(), this.effects.build(), this.generationSettings.build(), this.mobSpawnSettings.build());
|
||||
}
|
||||
|
||||
public ClimateSettingsBuilder getClimateSettings()
|
||||
{
|
||||
return climateSettings;
|
||||
}
|
||||
|
||||
public BiomeSpecialEffects.Builder getEffects()
|
||||
{
|
||||
return effects;
|
||||
}
|
||||
|
||||
public BiomeGenerationSettingsBuilder getGenerationSettings()
|
||||
{
|
||||
return generationSettings;
|
||||
}
|
||||
|
||||
public MobSpawnSettingsBuilder getMobSpawnSettings()
|
||||
{
|
||||
return mobSpawnSettings;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.world;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraftforge.common.ForgeMod;
|
||||
import net.minecraftforge.common.world.ModifiableBiomeInfo.BiomeInfo.Builder;
|
||||
|
||||
public class NoneBiomeModifier implements BiomeModifier
|
||||
{
|
||||
public static final NoneBiomeModifier INSTANCE = new NoneBiomeModifier();
|
||||
|
||||
@Override
|
||||
public void modify(Holder<Biome> biome, Phase phase, Builder builder)
|
||||
{
|
||||
// NOOP - intended for datapack makers who want to disable a biome modifier
|
||||
}
|
||||
|
||||
@Override
|
||||
public Codec<? extends BiomeModifier> codec()
|
||||
{
|
||||
return ForgeMod.NONE_BIOME_MODIFIER_TYPE.get();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user