mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-18 11:29:15 +00:00
1.21 Update
Co-authored-by: RealMangoRage <[email protected]> Co-authored-by: Daniel Norris <[email protected]> Co-authored-by: Ven <[email protected]>
This commit is contained in:
941 files changed
+3119
-4266
No files matched your search
@@ -18,6 +18,7 @@ import com.google.gson.JsonObject;
|
||||
import com.mojang.logging.LogUtils;
|
||||
import it.unimi.dsi.fastutil.booleans.BooleanConsumer;
|
||||
import java.util.Comparator;
|
||||
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
@@ -30,10 +31,6 @@ import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.util.profiling.ProfilerFiller;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.item.CreativeModeTabs;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.CreativeModeTabSearchRegistry;
|
||||
import net.minecraftforge.fml.loading.FMLEnvironment;
|
||||
import net.minecraftforge.fml.loading.FMLLoader;
|
||||
import net.minecraftforge.fml.loading.toposort.TopologicalSort;
|
||||
import net.minecraftforge.server.ServerLifecycleHooks;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
@@ -50,10 +47,9 @@ import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public final class CreativeModeTabRegistry
|
||||
{
|
||||
public final class CreativeModeTabRegistry {
|
||||
private static final Logger LOGGER = LogUtils.getLogger();
|
||||
private static final ResourceLocation CREATIVE_MODE_TAB_ORDERING_JSON = new ResourceLocation("forge", "creative_mode_tab_ordering.json");
|
||||
private static final ResourceLocation CREATIVE_MODE_TAB_ORDERING_JSON = ResourceLocation.fromNamespaceAndPath("forge", "creative_mode_tab_ordering.json");
|
||||
private static final List<CreativeModeTab> SORTED_TABS = new ArrayList<>();
|
||||
private static final List<CreativeModeTab> SORTED_TABS_VIEW = Collections.unmodifiableList(SORTED_TABS);
|
||||
private static final List<CreativeModeTab> DEFAULT_TABS = new ArrayList<>();
|
||||
@@ -61,8 +57,7 @@ public final class CreativeModeTabRegistry
|
||||
/**
|
||||
* {@return an unmodifiable view of the sorted list of creative mode tabs in ascending order}
|
||||
*/
|
||||
public static List<CreativeModeTab> getSortedCreativeModeTabs()
|
||||
{
|
||||
public static List<CreativeModeTab> getSortedCreativeModeTabs() {
|
||||
return SORTED_TABS_VIEW;
|
||||
}
|
||||
|
||||
@@ -76,8 +71,7 @@ public final class CreativeModeTabRegistry
|
||||
* @param name the name to look up
|
||||
*/
|
||||
@Nullable
|
||||
public static CreativeModeTab getTab(ResourceLocation name)
|
||||
{
|
||||
public static CreativeModeTab getTab(ResourceLocation name) {
|
||||
return BuiltInRegistries.CREATIVE_MODE_TAB.get(name);
|
||||
}
|
||||
|
||||
@@ -87,50 +81,39 @@ public final class CreativeModeTabRegistry
|
||||
* @param tab the tab to look up
|
||||
*/
|
||||
@Nullable
|
||||
public static ResourceLocation getName(CreativeModeTab tab)
|
||||
{
|
||||
public static ResourceLocation getName(CreativeModeTab tab) {
|
||||
return BuiltInRegistries.CREATIVE_MODE_TAB.getKey(tab);
|
||||
}
|
||||
|
||||
private static final Multimap<ResourceLocation, ResourceLocation> edges = HashMultimap.create();
|
||||
|
||||
static PreparableReloadListener getReloadListener()
|
||||
{
|
||||
return new SimplePreparableReloadListener<JsonObject>()
|
||||
{
|
||||
static PreparableReloadListener getReloadListener() {
|
||||
return new SimplePreparableReloadListener<JsonObject>() {
|
||||
final Gson gson = new GsonBuilder().create();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected JsonObject prepare(@NotNull ResourceManager resourceManager, ProfilerFiller profiler)
|
||||
{
|
||||
protected JsonObject prepare(@NotNull ResourceManager resourceManager, ProfilerFiller profiler) {
|
||||
Optional<Resource> res = resourceManager.getResource(CREATIVE_MODE_TAB_ORDERING_JSON);
|
||||
if (res.isEmpty())
|
||||
return new JsonObject();
|
||||
|
||||
try (Reader reader = res.get().openAsReader())
|
||||
{
|
||||
try (Reader reader = res.get().openAsReader()) {
|
||||
return this.gson.fromJson(reader, JsonObject.class);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("Could not read CreativeModeTab sorting file " + CREATIVE_MODE_TAB_ORDERING_JSON, e);
|
||||
return new JsonObject();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void apply(@NotNull JsonObject data, @NotNull ResourceManager resourceManager, ProfilerFiller p)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (data.size() > 0)
|
||||
{
|
||||
protected void apply(@NotNull JsonObject data, @NotNull ResourceManager resourceManager, ProfilerFiller p) {
|
||||
try {
|
||||
if (data.size() > 0) {
|
||||
JsonArray order = GsonHelper.getAsJsonArray(data, "order");
|
||||
List<CreativeModeTab> customOrder = new ArrayList<>();
|
||||
for (JsonElement entry : order)
|
||||
{
|
||||
ResourceLocation id = new ResourceLocation(entry.getAsString());
|
||||
for (JsonElement entry : order) {
|
||||
ResourceLocation id = ResourceLocation.parse(entry.getAsString());
|
||||
CreativeModeTab CreativeModeTab = getTab(id);
|
||||
if (CreativeModeTab == null)
|
||||
throw new IllegalStateException("CreativeModeTab not found with name " + id);
|
||||
@@ -145,9 +128,7 @@ public final class CreativeModeTabRegistry
|
||||
setCreativeModeTabOrder(customOrder);
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Error parsing CreativeModeTab sorting file " + CREATIVE_MODE_TAB_ORDERING_JSON, e);
|
||||
}
|
||||
|
||||
@@ -156,23 +137,21 @@ public final class CreativeModeTabRegistry
|
||||
};
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
private static void recalculateItemCreativeModeTabs()
|
||||
{
|
||||
private static void recalculateItemCreativeModeTabs() {
|
||||
final MutableGraph<CreativeModeTab> graph = GraphBuilder.directed().nodeOrder(ElementOrder.<CreativeModeTab>insertion()).build();
|
||||
|
||||
for (CreativeModeTab tab : BuiltInRegistries.CREATIVE_MODE_TAB)
|
||||
{
|
||||
for (CreativeModeTab tab : BuiltInRegistries.CREATIVE_MODE_TAB) {
|
||||
if (!DEFAULT_TABS.contains(tab))
|
||||
graph.addNode(tab);
|
||||
}
|
||||
edges.forEach((key, value) ->
|
||||
{
|
||||
|
||||
edges.forEach((key, value) -> {
|
||||
final CreativeModeTab keyC = getTab(key);
|
||||
final CreativeModeTab valueC = getTab(value);
|
||||
if (keyC != null && valueC != null)
|
||||
graph.putEdge(keyC, valueC);
|
||||
});
|
||||
|
||||
//Note: We can ignore the null warning as we validate getting tabs by key before adding to the graph
|
||||
// so the graph should only contain tabs that we know have names in the registry
|
||||
List<CreativeModeTab> tierList = TopologicalSort.topologicalSort(graph, Comparator.comparing(tab -> getName(tab)));
|
||||
@@ -180,17 +159,14 @@ public final class CreativeModeTabRegistry
|
||||
setCreativeModeTabOrder(tierList);
|
||||
}
|
||||
|
||||
private static void setCreativeModeTabOrder(List<CreativeModeTab> tierList)
|
||||
{
|
||||
runInServerThreadIfPossible(hasServer ->
|
||||
{
|
||||
private static void setCreativeModeTabOrder(List<CreativeModeTab> tierList) {
|
||||
runInServerThreadIfPossible(hasServer -> {
|
||||
SORTED_TABS.clear();
|
||||
SORTED_TABS.addAll(tierList);
|
||||
});
|
||||
}
|
||||
|
||||
private static void runInServerThreadIfPossible(BooleanConsumer runnable)
|
||||
{
|
||||
private static void runInServerThreadIfPossible(BooleanConsumer runnable) {
|
||||
MinecraftServer server = ServerLifecycleHooks.getCurrentServer();
|
||||
if (server != null)
|
||||
server.execute(() -> runnable.accept(true));
|
||||
@@ -199,8 +175,7 @@ public final class CreativeModeTabRegistry
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static void sortTabs()
|
||||
{
|
||||
public static void sortTabs() {
|
||||
edges.clear();
|
||||
|
||||
DEFAULT_TABS.add(BuiltInRegistries.CREATIVE_MODE_TAB.get(CreativeModeTabs.HOTBAR));
|
||||
@@ -212,16 +187,14 @@ public final class CreativeModeTabRegistry
|
||||
BuiltInRegistries.CREATIVE_MODE_TAB.holders().filter(c -> !DEFAULT_TABS.contains(c.get())).forEach(indexed::add);
|
||||
int vanillaTabs = 10;
|
||||
|
||||
for (int i = 0; i < vanillaTabs; i++) // Vanilla ordering
|
||||
{
|
||||
for (int i = 0; i < vanillaTabs; i++) { // Vanilla ordering
|
||||
final Holder<CreativeModeTab> value = indexed.get(i);
|
||||
final CreativeModeTab tab = value.get();
|
||||
final ResourceLocation name = value.unwrapKey().orElseThrow().location();
|
||||
|
||||
if (!tab.tabsBefore.isEmpty() || !tab.tabsAfter.isEmpty())
|
||||
addTabOrder(tab, name);
|
||||
else
|
||||
{
|
||||
else {
|
||||
// If there is no order specified ensure vanilla ordering by specifying the previous and next indexed tab as edges
|
||||
if (i != 0)
|
||||
edges.put(indexed.get(i - 1).unwrapKey().orElseThrow().location(), name);
|
||||
@@ -231,8 +204,7 @@ public final class CreativeModeTabRegistry
|
||||
}
|
||||
|
||||
ResourceLocation lastVanilla = indexed.get(vanillaTabs - 1).unwrapKey().orElseThrow().location();
|
||||
for (int i = vanillaTabs; i < indexed.size(); i++)
|
||||
{
|
||||
for (int i = vanillaTabs; i < indexed.size(); i++) {
|
||||
final Holder<CreativeModeTab> value = indexed.get(i);
|
||||
final CreativeModeTab tab = value.get();
|
||||
final ResourceLocation name = value.unwrapKey().orElseThrow().location();
|
||||
@@ -244,22 +216,15 @@ public final class CreativeModeTabRegistry
|
||||
}
|
||||
|
||||
recalculateItemCreativeModeTabs();
|
||||
|
||||
if (FMLEnvironment.dist == Dist.CLIENT && !FMLLoader.getLaunchHandler().isData())
|
||||
CreativeModeTabSearchRegistry.createSearchTrees();
|
||||
}
|
||||
|
||||
private static void addTabOrder(CreativeModeTab tab, ResourceLocation name)
|
||||
{
|
||||
for (final ResourceLocation after : tab.tabsAfter)
|
||||
{
|
||||
private static void addTabOrder(CreativeModeTab tab, ResourceLocation name) {
|
||||
for (var after : tab.tabsAfter) {
|
||||
edges.put(name, after);
|
||||
}
|
||||
|
||||
for (final ResourceLocation before : tab.tabsBefore)
|
||||
{
|
||||
for (var before : tab.tabsBefore) {
|
||||
edges.put(before, name);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -52,6 +51,7 @@ import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.core.component.DataComponentMap;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.core.particles.ParticleTypes;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||
@@ -131,7 +131,6 @@ import net.minecraftforge.entity.IEntityAdditionalSpawnData;
|
||||
import net.minecraftforge.event.AnvilUpdateEvent;
|
||||
import net.minecraftforge.event.BuildCreativeModeTabContentsEvent;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
import net.minecraftforge.event.GatherComponentsEvent;
|
||||
import net.minecraftforge.event.GrindstoneEvent;
|
||||
import net.minecraftforge.event.ModMismatchEvent;
|
||||
import net.minecraftforge.event.ServerChatEvent;
|
||||
@@ -143,16 +142,12 @@ import net.minecraftforge.event.entity.living.EnderManAngerEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingAttackEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingBreatheEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingDamageEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingDeathEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingDropsEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingDrownEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingEvent.LivingJumpEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingEvent.LivingTickEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingHurtEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingMakeBrainEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingUseTotemEvent;
|
||||
import net.minecraftforge.event.entity.living.LootingLevelEvent;
|
||||
import net.minecraftforge.event.entity.player.AttackEntityEvent;
|
||||
import net.minecraftforge.event.entity.player.CriticalHitEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
@@ -172,7 +167,6 @@ import net.minecraftforge.network.ForgePayload;
|
||||
import net.minecraftforge.network.NetworkContext;
|
||||
import net.minecraftforge.network.NetworkDirection;
|
||||
import net.minecraftforge.network.NetworkInitialization;
|
||||
import net.minecraftforge.network.NetworkProtocol;
|
||||
import net.minecraftforge.network.NetworkRegistry;
|
||||
import net.minecraftforge.network.packets.SpawnEntity;
|
||||
import net.minecraftforge.resource.ResourcePackLoader;
|
||||
@@ -265,16 +259,12 @@ public final class ForgeHooks {
|
||||
public static int getLootingLevel(Entity target, @Nullable Entity killer, @Nullable DamageSource cause) {
|
||||
int looting = 0;
|
||||
if (killer instanceof LivingEntity living)
|
||||
looting = EnchantmentHelper.getMobLooting(living);
|
||||
if (target instanceof LivingEntity living)
|
||||
looting = getLootingLevel(living, cause, looting);
|
||||
return looting;
|
||||
}
|
||||
looting = EnchantmentHelper.getEnchantmentLevel(living.level().holderLookup(Registries.ENCHANTMENT).getOrThrow(Enchantments.LOOTING), living);
|
||||
|
||||
public static int getLootingLevel(LivingEntity target, @Nullable DamageSource cause, int level) {
|
||||
LootingLevelEvent event = new LootingLevelEvent(target, cause, level);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
return event.getLootingLevel();
|
||||
if (target instanceof LivingEntity living)
|
||||
looting = ForgeEventFactory.fireLootingLevel(living, cause, looting).getLootingLevel();
|
||||
|
||||
return looting;
|
||||
}
|
||||
|
||||
public static double getEntityVisibilityMultiplier(LivingEntity entity, Entity lookingEntity, double originalMultiplier){
|
||||
@@ -406,8 +396,9 @@ public final class ForgeHooks {
|
||||
}
|
||||
|
||||
public static void dropXpForBlock(BlockState state, ServerLevel level, BlockPos pos, ItemStack stack) {
|
||||
int fortuneLevel = stack.getEnchantmentLevel(Enchantments.FORTUNE);
|
||||
int silkTouchLevel = stack.getEnchantmentLevel(Enchantments.SILK_TOUCH);
|
||||
var lookup = level.holderLookup(Registries.ENCHANTMENT);
|
||||
int fortuneLevel = EnchantmentHelper.getItemEnchantmentLevel(lookup.getOrThrow(Enchantments.FORTUNE), stack);
|
||||
int silkTouchLevel = EnchantmentHelper.getItemEnchantmentLevel(lookup.getOrThrow(Enchantments.SILK_TOUCH), stack);
|
||||
int exp = state.getExpDrop(level, level.random, pos, fortuneLevel, silkTouchLevel);
|
||||
if (exp > 0)
|
||||
state.getBlock().popExperience(level, pos, exp);
|
||||
@@ -948,7 +939,7 @@ public final class ForgeHooks {
|
||||
Map<ResourceLocation, ForgeRegistry.Snapshot> snapshot = new HashMap<>();
|
||||
CompoundTag regs = tag.getCompound("Registries");
|
||||
for (String key : regs.getAllKeys())
|
||||
snapshot.put(new ResourceLocation(key), ForgeRegistry.Snapshot.read(regs.getCompound(key)));
|
||||
snapshot.put(ResourceLocation.parse(key), ForgeRegistry.Snapshot.read(regs.getCompound(key)));
|
||||
failedElements = GameData.injectSnapshot(snapshot, true, true);
|
||||
}
|
||||
|
||||
@@ -1013,30 +1004,6 @@ public final class ForgeHooks {
|
||||
return biomeLocation != null && !biomeLocation.getNamespace().equals(ResourceLocation.DEFAULT_NAMESPACE);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* This method is used to prefix the path, where elements of the associated registry are stored, with their namespace, if it is not minecraft
|
||||
* </p>
|
||||
* <p>
|
||||
* This rules conflicts with equal paths out. If for example the mod {@code fancy_cheese} adds a registry named {@code cheeses},
|
||||
* but the mod {@code awesome_cheese} also adds a registry called {@code cheeses},
|
||||
* they are going to have the same path {@code cheeses}, just with different namespaces.
|
||||
* If {@code additional_cheese} wants to add additional cheese to {@code awesome_cheese}, but not {@code fancy_cheese},
|
||||
* it can not differentiate both. Both paths will look like {@code data/additional_cheese/cheeses}.
|
||||
* </p>
|
||||
* <p>
|
||||
* The fix, which is applied here prefixes the path of the registry with the namespace,
|
||||
* so {@code fancy_cheese}'s registry stores its elements in {@code data/<namespace>/fancy_cheese/cheeses}
|
||||
* and {@code awesome_cheese}'s registry stores its elements in {@code data/namespace/awesome_cheese/cheeses}
|
||||
* </p>
|
||||
*
|
||||
* @param registryKey key of the registry
|
||||
* @return path of the registry key. Prefixed with the namespace if it is not "minecraft"
|
||||
*/
|
||||
public static String prefixNamespace(ResourceLocation registryKey) {
|
||||
return registryKey.getNamespace().equals("minecraft") ? registryKey.getPath() : registryKey.getNamespace() + "/" + registryKey.getPath();
|
||||
}
|
||||
|
||||
public static boolean canUseEntitySelectors(SharedSuggestionProvider provider) {
|
||||
if (provider.hasPermission(Commands.LEVEL_GAMEMASTERS))
|
||||
return true;
|
||||
|
||||
@@ -17,10 +17,7 @@ import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.data.PackOutput;
|
||||
import net.minecraft.data.metadata.PackMetadataGenerator;
|
||||
import net.minecraft.network.chat.ChatType;
|
||||
import net.minecraft.network.chat.ChatTypeDecoration;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.Style;
|
||||
import net.minecraft.server.packs.PackType;
|
||||
import net.minecraft.server.packs.metadata.pack.PackMetadataSection;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
@@ -116,7 +113,6 @@ import net.minecraftforge.fml.common.Mod;
|
||||
import org.apache.logging.log4j.Marker;
|
||||
import org.apache.logging.log4j.MarkerManager;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.MapCodec;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -233,10 +229,10 @@ public class ForgeMod {
|
||||
@Override
|
||||
public void initializeClient(Consumer<IClientFluidTypeExtensions> consumer) {
|
||||
consumer.accept(new IClientFluidTypeExtensions() {
|
||||
private static final ResourceLocation UNDERWATER_LOCATION = new ResourceLocation("textures/misc/underwater.png"),
|
||||
WATER_STILL = new ResourceLocation("block/water_still"),
|
||||
WATER_FLOW = new ResourceLocation("block/water_flow"),
|
||||
WATER_OVERLAY = new ResourceLocation("block/water_overlay");
|
||||
private static final ResourceLocation UNDERWATER_LOCATION = ResourceLocation.withDefaultNamespace("textures/misc/underwater.png");
|
||||
private static final ResourceLocation WATER_STILL = ResourceLocation.withDefaultNamespace("block/water_still");
|
||||
private static final ResourceLocation WATER_FLOW = ResourceLocation.withDefaultNamespace("block/water_flow");
|
||||
private static final ResourceLocation WATER_OVERLAY = ResourceLocation.withDefaultNamespace("block/water_overlay");
|
||||
|
||||
@Override
|
||||
public ResourceLocation getStillTexture() {
|
||||
@@ -300,8 +296,8 @@ public class ForgeMod {
|
||||
@Override
|
||||
public void initializeClient(Consumer<IClientFluidTypeExtensions> consumer) {
|
||||
consumer.accept(new IClientFluidTypeExtensions() {
|
||||
private static final ResourceLocation LAVA_STILL = new ResourceLocation("block/lava_still"),
|
||||
LAVA_FLOW = new ResourceLocation("block/lava_flow");
|
||||
private static final ResourceLocation LAVA_STILL = ResourceLocation.withDefaultNamespace("block/lava_still");
|
||||
private static final ResourceLocation LAVA_FLOW = ResourceLocation.withDefaultNamespace("block/lava_flow");
|
||||
|
||||
@Override
|
||||
public ResourceLocation getStillTexture() {
|
||||
@@ -350,11 +346,11 @@ public class ForgeMod {
|
||||
|
||||
|
||||
private static boolean enableMilkFluid = false;
|
||||
public static final RegistryObject<SoundEvent> BUCKET_EMPTY_MILK = RegistryObject.create(new ResourceLocation("item.bucket.empty_milk"), ForgeRegistries.SOUND_EVENTS);
|
||||
public static final RegistryObject<SoundEvent> BUCKET_FILL_MILK = RegistryObject.create(new ResourceLocation("item.bucket.fill_milk"), ForgeRegistries.SOUND_EVENTS);
|
||||
public static final RegistryObject<FluidType> MILK_TYPE = RegistryObject.createOptional(new ResourceLocation("milk"), ForgeRegistries.Keys.FLUID_TYPES.location(), "minecraft");
|
||||
public static final RegistryObject<Fluid> MILK = RegistryObject.create(new ResourceLocation("milk"), ForgeRegistries.FLUIDS);
|
||||
public static final RegistryObject<Fluid> FLOWING_MILK = RegistryObject.create(new ResourceLocation("flowing_milk"), ForgeRegistries.FLUIDS);
|
||||
public static final RegistryObject<SoundEvent> BUCKET_EMPTY_MILK = RegistryObject.create(ResourceLocation.withDefaultNamespace("item.bucket.empty_milk"), ForgeRegistries.SOUND_EVENTS);
|
||||
public static final RegistryObject<SoundEvent> BUCKET_FILL_MILK = RegistryObject.create(ResourceLocation.withDefaultNamespace("item.bucket.fill_milk"), ForgeRegistries.SOUND_EVENTS);
|
||||
public static final RegistryObject<FluidType> MILK_TYPE = RegistryObject.createOptional(ResourceLocation.withDefaultNamespace("milk"), ForgeRegistries.Keys.FLUID_TYPES.location(), "minecraft");
|
||||
public static final RegistryObject<Fluid> MILK = RegistryObject.create(ResourceLocation.withDefaultNamespace("milk"), ForgeRegistries.FLUIDS);
|
||||
public static final RegistryObject<Fluid> FLOWING_MILK = RegistryObject.create(ResourceLocation.withDefaultNamespace("flowing_milk"), ForgeRegistries.FLUIDS);
|
||||
|
||||
/*
|
||||
private static final ChatTypeDecoration SYSTEM_CHAT_TYPE_DECORATION = new ChatTypeDecoration("forge.chatType.system", List.of(ChatTypeDecoration.Parameter.CONTENT), Style.EMPTY);
|
||||
@@ -425,8 +421,8 @@ public class ForgeMod {
|
||||
ForgeRegistries.ITEMS.tags().addOptionalTagDefaults(Tags.Items.ENCHANTING_FUELS, Set.of(ForgeRegistries.ITEMS.getDelegateOrThrow(Items.LAPIS_LAZULI)));
|
||||
|
||||
// TODO: Remove when addAlias becomes proper API, as this should be done in the DR's above.
|
||||
addAlias(ForgeRegistries.ATTRIBUTES, new ResourceLocation("forge", "reach_distance"), new ResourceLocation("forge", "block_reach"));
|
||||
addAlias(ForgeRegistries.ATTRIBUTES, new ResourceLocation("forge", "attack_range"), new ResourceLocation("forge", "entity_reach"));
|
||||
addAlias(ForgeRegistries.ATTRIBUTES, ResourceLocation.fromNamespaceAndPath("forge", "reach_distance"), ResourceLocation.fromNamespaceAndPath("forge", "block_reach"));
|
||||
addAlias(ForgeRegistries.ATTRIBUTES, ResourceLocation.fromNamespaceAndPath("forge", "attack_range"), ResourceLocation.fromNamespaceAndPath("forge", "entity_reach"));
|
||||
}
|
||||
|
||||
public void preInit(FMLCommonSetupEvent evt) {
|
||||
@@ -493,8 +489,8 @@ public class ForgeMod {
|
||||
@Override
|
||||
public void initializeClient(Consumer<IClientFluidTypeExtensions> consumer) {
|
||||
consumer.accept(new IClientFluidTypeExtensions() {
|
||||
private static final ResourceLocation MILK_STILL = new ResourceLocation("forge", "block/milk_still");
|
||||
private static final ResourceLocation MILK_FLOW = new ResourceLocation("forge", "block/milk_flowing");
|
||||
private static final ResourceLocation MILK_STILL = ResourceLocation.fromNamespaceAndPath("forge", "block/milk_still");
|
||||
private static final ResourceLocation MILK_FLOW = ResourceLocation.fromNamespaceAndPath("forge", "block/milk_flowing");
|
||||
|
||||
@Override
|
||||
public ResourceLocation getStillTexture() {
|
||||
@@ -528,7 +524,7 @@ public class ForgeMod {
|
||||
|
||||
Arrays.stream(ItemDisplayContext.values())
|
||||
.filter(Predicate.not(ItemDisplayContext::isModded))
|
||||
.forEach(ctx -> forgeRegistry.register(ctx.getId(), new ResourceLocation("minecraft", ctx.getSerializedName()), ctx));
|
||||
.forEach(ctx -> forgeRegistry.register(ctx.getId(), ResourceLocation.fromNamespaceAndPath("minecraft", ctx.getSerializedName()), ctx));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -177,7 +177,7 @@ public class Tags
|
||||
|
||||
private static TagKey<Block> tag(String name)
|
||||
{
|
||||
return BlockTags.create(new ResourceLocation("forge", name));
|
||||
return BlockTags.create(ResourceLocation.fromNamespaceAndPath("forge", name));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ public class Tags
|
||||
|
||||
private static TagKey<EntityType<?>> tag(String name)
|
||||
{
|
||||
return TagKey.create(Registries.ENTITY_TYPE, new ResourceLocation("forge", name));
|
||||
return TagKey.create(Registries.ENTITY_TYPE, ResourceLocation.fromNamespaceAndPath("forge", name));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -484,7 +484,7 @@ public class Tags
|
||||
|
||||
private static TagKey<Item> tag(String name)
|
||||
{
|
||||
return ItemTags.create(new ResourceLocation("forge", name));
|
||||
return ItemTags.create(ResourceLocation.fromNamespaceAndPath("forge", name));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -503,7 +503,7 @@ public class Tags
|
||||
|
||||
private static TagKey<Fluid> tag(String name)
|
||||
{
|
||||
return FluidTags.create(new ResourceLocation("forge", name));
|
||||
return FluidTags.create(ResourceLocation.fromNamespaceAndPath("forge", name));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -567,7 +567,7 @@ public class Tags
|
||||
|
||||
private static TagKey<Biome> tag(String name)
|
||||
{
|
||||
return TagKey.create(Registries.BIOME, new ResourceLocation("forge", name));
|
||||
return TagKey.create(Registries.BIOME, ResourceLocation.fromNamespaceAndPath("forge", name));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,7 @@ public class ConditionalAdvancement {
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private static final ResourceLocation DOESNT_MATTER = new ResourceLocation("doesnt", "matter");
|
||||
private static final ResourceLocation DOESNT_MATTER = ResourceLocation.fromNamespaceAndPath("doesnt", "matter");
|
||||
|
||||
private List<Adv> advancements = new ArrayList<>();
|
||||
private ICondition condition;
|
||||
|
||||
@@ -31,6 +31,7 @@ import net.minecraft.data.recipes.RecipeBuilder;
|
||||
import net.minecraft.data.recipes.RecipeOutput;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.crafting.CraftingInput;
|
||||
import net.minecraft.world.item.crafting.Recipe;
|
||||
import net.minecraft.world.item.crafting.RecipeSerializer;
|
||||
import net.minecraft.world.item.crafting.RecipeType;
|
||||
@@ -134,7 +135,7 @@ public class ConditionalRecipe {
|
||||
}
|
||||
|
||||
public void save(RecipeOutput out, String namespace, String path) {
|
||||
save(out, new ResourceLocation(namespace, path));
|
||||
save(out, ResourceLocation.fromNamespaceAndPath(namespace, path));
|
||||
}
|
||||
|
||||
public void save(RecipeOutput out, ResourceLocation id) {
|
||||
@@ -168,9 +169,9 @@ public class ConditionalRecipe {
|
||||
private record InnerRecipe(ICondition condition, Recipe<?> recipe) {}
|
||||
private record InnerAdvancement(ICondition condition, AdvancementHolder advancement, JsonObject json) {}
|
||||
|
||||
private static class Wrapper implements Recipe<Container> {
|
||||
@Override public boolean matches(Container inv, Level level) { return false; }
|
||||
@Override public ItemStack assemble(Container inv, HolderLookup.Provider reg) { return null; }
|
||||
private static class Wrapper implements Recipe<CraftingInput> {
|
||||
@Override public boolean matches(CraftingInput inv, Level level) { return false; }
|
||||
@Override public ItemStack assemble(CraftingInput inv, HolderLookup.Provider reg) { return null; }
|
||||
@Override public boolean canCraftInDimensions(int width, int height) { return false; }
|
||||
@Override public ItemStack getResultItem(HolderLookup.Provider reg) { return null; }
|
||||
@Override public RecipeSerializer<?> getSerializer() { return ConditionalRecipe.SERIALZIER; }
|
||||
|
||||
@@ -5,15 +5,15 @@
|
||||
|
||||
package net.minecraftforge.common.crafting;
|
||||
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.item.crafting.Recipe;
|
||||
import net.minecraft.world.item.crafting.RecipeInput;
|
||||
|
||||
/**
|
||||
* Used to mark a recipe that shape matters so that the recipe
|
||||
* book and auto crafting picks the correct shape.
|
||||
* Note: These methods can't be named 'getHeight' or 'getWidth' due to obfusication issues.
|
||||
*/
|
||||
public interface IShapedRecipe<T extends Container> extends Recipe<T> {
|
||||
public interface IShapedRecipe<T extends RecipeInput> extends Recipe<T> {
|
||||
int getRecipeWidth();
|
||||
int getRecipeHeight();
|
||||
}
|
||||
@@ -11,98 +11,15 @@ import it.unimi.dsi.fastutil.chars.Char2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.chars.Char2ObjectOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.chars.CharArraySet;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.world.ContainerHelper;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.entity.player.StackedContents;
|
||||
import net.minecraft.world.inventory.CraftingContainer;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.crafting.CraftingInput;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
|
||||
public class SimpleCraftingContainer implements CraftingContainer {
|
||||
private final int width;
|
||||
private final int height;
|
||||
private final NonNullList<ItemStack> items;
|
||||
|
||||
public class SimpleCraftingContainer {
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public SimpleCraftingContainer(int width, int height) {
|
||||
this(width, height, NonNullList.withSize(width * height, ItemStack.EMPTY));
|
||||
}
|
||||
|
||||
public SimpleCraftingContainer(int width, int height, NonNullList<ItemStack> items) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.items = items;
|
||||
if (items.size() != (width * height))
|
||||
throw new IllegalArgumentException("Invalid item list, must be same size inventory width * height, received " + items.size() + " expected " + (width * height));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getContainerSize() {
|
||||
return this.items.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return this.items.stream().noneMatch(p -> !p.isEmpty());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(int slot) {
|
||||
return slot >= this.items.size() ? ItemStack.EMPTY : this.items.get(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItem(int slot, int count) {
|
||||
return ContainerHelper.removeItem(this.items, slot, count);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItemNoUpdate(int slot) {
|
||||
return ContainerHelper.takeItem(this.items, slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int slot, ItemStack stack) {
|
||||
this.items.set(slot, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChanged() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stillValid(Player player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearContent() {
|
||||
this.items.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fillStackedContents(StackedContents stacked) {
|
||||
this.items.forEach(stacked::accountSimpleStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getItems() {
|
||||
return List.copyOf(this.items);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private final List<String> rows = new ArrayList<>();
|
||||
private final Char2ObjectMap<ItemStack> keys = new Char2ObjectOpenHashMap<>();
|
||||
@@ -135,7 +52,7 @@ public class SimpleCraftingContainer implements CraftingContainer {
|
||||
return this;
|
||||
}
|
||||
|
||||
public SimpleCraftingContainer build() {
|
||||
public CraftingInput build() {
|
||||
var unseen = new CharArraySet(this.keys.keySet());
|
||||
unseen.remove(' ');
|
||||
|
||||
@@ -160,7 +77,7 @@ public class SimpleCraftingContainer implements CraftingContainer {
|
||||
if (!unseen.isEmpty())
|
||||
throw new IllegalStateException("Invalid builder, missing usage of defined keys: " + unseen);
|
||||
|
||||
return new SimpleCraftingContainer(width, height, items);
|
||||
return CraftingInput.of(width, height, items);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,7 @@ public interface ICondition {
|
||||
interface IContext {
|
||||
/* Key used to attach this context option to a DynamicOps instance */
|
||||
@ApiStatus.Internal
|
||||
public static ResourceLocation KEY = new ResourceLocation("forge", "condition_context");
|
||||
public static ResourceLocation KEY = ResourceLocation.fromNamespaceAndPath("forge", "condition_context");
|
||||
|
||||
IContext EMPTY = new IContext() {
|
||||
@Override
|
||||
|
||||
@@ -33,7 +33,7 @@ public interface IConditionBuilder {
|
||||
}
|
||||
|
||||
default ICondition itemExists(String namespace, String path) {
|
||||
return new ItemExistsCondition(new ResourceLocation(namespace, path));
|
||||
return new ItemExistsCondition(ResourceLocation.fromNamespaceAndPath(namespace, path));
|
||||
}
|
||||
|
||||
default ICondition modLoaded(String modid) {
|
||||
|
||||
@@ -6,18 +6,10 @@
|
||||
package net.minecraftforge.common.data;
|
||||
|
||||
import net.minecraft.core.*;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.PackOutput;
|
||||
import net.minecraft.data.registries.RegistriesDatapackGenerator;
|
||||
import net.minecraft.data.registries.RegistryPatchGenerator;
|
||||
import net.minecraft.data.tags.ItemTagsProvider;
|
||||
import net.minecraft.data.tags.TagsProvider;
|
||||
import net.minecraft.data.worldgen.features.OreFeatures;
|
||||
import net.minecraftforge.data.event.GatherDataEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@@ -26,8 +18,7 @@ import java.util.concurrent.CompletableFuture;
|
||||
* referencing existing dynamic registry objects within another dynamic registry
|
||||
* object.
|
||||
*/
|
||||
public class DatapackBuiltinEntriesProvider extends RegistriesDatapackGenerator
|
||||
{
|
||||
public class DatapackBuiltinEntriesProvider extends RegistriesDatapackGenerator {
|
||||
|
||||
private final CompletableFuture<HolderLookup.Provider> fullRegistries;
|
||||
|
||||
@@ -39,8 +30,7 @@ public class DatapackBuiltinEntriesProvider extends RegistriesDatapackGenerator
|
||||
* @param registries a future of patched registries
|
||||
* @param modIds a set of mod ids to generate the dynamic registry objects of
|
||||
*/
|
||||
public DatapackBuiltinEntriesProvider(PackOutput output, CompletableFuture<RegistrySetBuilder.PatchedRegistries> registries, Set<String> modIds)
|
||||
{
|
||||
public DatapackBuiltinEntriesProvider(PackOutput output, CompletableFuture<RegistrySetBuilder.PatchedRegistries> registries, Set<String> modIds) {
|
||||
super(output, registries.thenApply(RegistrySetBuilder.PatchedRegistries::patches), modIds);
|
||||
this.fullRegistries = registries.thenApply(RegistrySetBuilder.PatchedRegistries::full);
|
||||
}
|
||||
@@ -55,8 +45,7 @@ public class DatapackBuiltinEntriesProvider extends RegistriesDatapackGenerator
|
||||
* @param registryBuilder a builder containing the dynamic registry objects added by this provider
|
||||
* @param modIds a set of mod ids to generate the dynamic registry objects of
|
||||
*/
|
||||
public DatapackBuiltinEntriesProvider(PackOutput output, CompletableFuture<HolderLookup.Provider> registries, RegistrySetBuilder registryBuilder, Set<String> modIds)
|
||||
{
|
||||
public DatapackBuiltinEntriesProvider(PackOutput output, CompletableFuture<HolderLookup.Provider> registries, RegistrySetBuilder registryBuilder, Set<String> modIds) {
|
||||
this(output, RegistryPatchGenerator.createLookup(registries, registryBuilder), modIds);
|
||||
}
|
||||
|
||||
@@ -69,8 +58,7 @@ public class DatapackBuiltinEntriesProvider extends RegistriesDatapackGenerator
|
||||
* An example use case is the {@link TagsProvider}.
|
||||
* @return the future of the full registry lookup
|
||||
*/
|
||||
public CompletableFuture<HolderLookup.Provider> getFullRegistries()
|
||||
{
|
||||
public CompletableFuture<HolderLookup.Provider> getFullRegistries() {
|
||||
return this.fullRegistries;
|
||||
}
|
||||
}
|
||||
@@ -150,7 +150,7 @@ public class ExistingFileHelper {
|
||||
}
|
||||
|
||||
private ResourceLocation getLocation(ResourceLocation base, String suffix, String prefix) {
|
||||
return new ResourceLocation(base.getNamespace(), prefix + "/" + base.getPath() + suffix);
|
||||
return base.withPath(p -> prefix + '/' + p + suffix);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -112,7 +112,7 @@ public final class ForgeBlockTagsProvider extends BlockTagsProvider
|
||||
String prefix = group.location().getPath().toUpperCase(Locale.ENGLISH) + '_';
|
||||
for (DyeColor color : DyeColor.values())
|
||||
{
|
||||
ResourceLocation key = new ResourceLocation("minecraft", pattern.replace("{color}", color.getName()));
|
||||
ResourceLocation key = ResourceLocation.fromNamespaceAndPath("minecraft", pattern.replace("{color}", color.getName()));
|
||||
TagKey<Block> tag = getForgeTag(prefix + color.getName());
|
||||
Block block = ForgeRegistries.BLOCKS.getValue(key);
|
||||
if (block == null || block == Blocks.AIR)
|
||||
|
||||
@@ -175,7 +175,7 @@ public final class ForgeItemTagsProvider extends ItemTagsProvider
|
||||
String prefix = group.location().getPath().toUpperCase(Locale.ENGLISH) + '_';
|
||||
for (DyeColor color : DyeColor.values())
|
||||
{
|
||||
ResourceLocation key = new ResourceLocation("minecraft", pattern.replace("{color}", color.getName()));
|
||||
ResourceLocation key = ResourceLocation.fromNamespaceAndPath("minecraft", pattern.replace("{color}", color.getName()));
|
||||
TagKey<Item> tag = getForgeItemTag(prefix + color.getName());
|
||||
Item item = ForgeRegistries.ITEMS.getValue(key);
|
||||
if (item == null || item == Items.AIR)
|
||||
|
||||
@@ -62,12 +62,12 @@ public final class ForgeLootTableProvider extends LootTableProvider {
|
||||
public List<LootTableProvider.SubProviderEntry> getTables() {
|
||||
return super.getTables().stream().map(entry -> {
|
||||
// Provides new sub provider with filtering only changed loot tables and replacing condition item to condition tag
|
||||
return new LootTableProvider.SubProviderEntry(() -> replaceAndFilterChangesOnly(entry.provider().get()), entry.paramSet());
|
||||
return new LootTableProvider.SubProviderEntry(provider -> replaceAndFilterChangesOnly(entry.provider().apply(provider)), entry.paramSet());
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private LootTableSubProvider replaceAndFilterChangesOnly(LootTableSubProvider subProvider) {
|
||||
return (provider, newConsumer) -> subProvider.generate(provider, (resourceLocation, builder) -> {
|
||||
return (newConsumer) -> subProvider.generate((resourceLocation, builder) -> {
|
||||
if (findAndReplaceInLootTableBuilder(builder, Items.SHEARS, ToolActions.SHEARS_DIG)) {
|
||||
newConsumer.accept(resourceLocation, builder);
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ public final class ForgeRecipeProvider extends VanillaRecipeProvider {
|
||||
}
|
||||
|
||||
private void exclude(String name) {
|
||||
excludes.add(new ResourceLocation(name));
|
||||
excludes.add(ResourceLocation.parse(name));
|
||||
}
|
||||
|
||||
private void replace(ItemLike item, TagKey<Item> tag) {
|
||||
|
||||
@@ -21,6 +21,6 @@ public class ForgeSpriteSourceProvider extends SpriteSourceProvider
|
||||
@Override
|
||||
protected void addSources()
|
||||
{
|
||||
atlas(SpriteSourceProvider.BLOCKS_ATLAS).addSource(new SingleFile(new ResourceLocation("forge:white"), Optional.empty()));
|
||||
atlas(SpriteSourceProvider.BLOCKS_ATLAS).addSource(new SingleFile(ResourceLocation.parse("forge:white"), Optional.empty()));
|
||||
}
|
||||
}
|
||||
@@ -56,7 +56,7 @@ public abstract class GlobalLootModifierProvider implements DataProvider {
|
||||
/**
|
||||
* Call {@link #add} here, which will pass in the necessary information to write the jsons.
|
||||
*/
|
||||
protected abstract void start();
|
||||
protected abstract void start(HolderLookup.Provider registries);
|
||||
|
||||
@Override
|
||||
public CompletableFuture<?> run(CachedOutput cache) {
|
||||
@@ -64,7 +64,7 @@ public abstract class GlobalLootModifierProvider implements DataProvider {
|
||||
}
|
||||
|
||||
private CompletableFuture<?> run(CachedOutput cache, HolderLookup.Provider registries) {
|
||||
start();
|
||||
start(registries);
|
||||
|
||||
Path forgePath = this.output.getOutputFolder(PackOutput.Target.DATA_PACK).resolve("forge/loot_modifiers/global_loot_modifiers.json");
|
||||
Path modifierFolderPath = this.output.getOutputFolder(PackOutput.Target.DATA_PACK).resolve(this.modid).resolve("loot_modifiers");
|
||||
@@ -78,7 +78,7 @@ public abstract class GlobalLootModifierProvider implements DataProvider {
|
||||
|
||||
toSerialize.forEach(LamdbaExceptionUtils.rethrowBiConsumer((name, instance) -> {
|
||||
var json = codec.encodeStart(ops, instance).getOrThrow();
|
||||
entries.add(new ResourceLocation(modid, name));
|
||||
entries.add(ResourceLocation.fromNamespaceAndPath(modid, name));
|
||||
Path modifierPath = modifierFolderPath.resolve(name + ".json");
|
||||
futuresBuilder.add(DataProvider.saveStable(cache, json, modifierPath));
|
||||
}));
|
||||
|
||||
@@ -14,6 +14,7 @@ import java.util.function.Supplier;
|
||||
import net.minecraft.data.CachedOutput;
|
||||
import net.minecraft.data.DataProvider;
|
||||
import net.minecraft.data.PackOutput;
|
||||
import net.minecraft.network.chat.contents.TranslatableContents;
|
||||
import net.minecraft.world.effect.MobEffect;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.item.Item;
|
||||
@@ -87,7 +88,10 @@ public abstract class LanguageProvider implements DataProvider {
|
||||
}
|
||||
|
||||
public void add(Enchantment key, String name) {
|
||||
add(key.getDescriptionId(), name);
|
||||
if (!(key.description().getContents() instanceof TranslatableContents description))
|
||||
throw new IllegalArgumentException("Enchantment " + key + " does not have a translatable name");
|
||||
|
||||
add(description.getKey(), name);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -114,7 +114,7 @@ public abstract class SoundDefinitionsProvider implements DataProvider
|
||||
*/
|
||||
protected static SoundDefinition.Sound sound(final String name, final SoundDefinition.SoundType type)
|
||||
{
|
||||
return sound(new ResourceLocation(name), type);
|
||||
return sound(ResourceLocation.parse(name), type);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -125,7 +125,7 @@ public abstract class SoundDefinitionsProvider implements DataProvider
|
||||
*/
|
||||
protected static SoundDefinition.Sound sound(final String name)
|
||||
{
|
||||
return sound(new ResourceLocation(name));
|
||||
return sound(ResourceLocation.parse(name));
|
||||
}
|
||||
|
||||
// Addition methods
|
||||
@@ -186,7 +186,7 @@ public abstract class SoundDefinitionsProvider implements DataProvider
|
||||
*/
|
||||
protected void add(final String soundEvent, final SoundDefinition definition)
|
||||
{
|
||||
this.add(new ResourceLocation(soundEvent), definition);
|
||||
this.add(ResourceLocation.parse(soundEvent), definition);
|
||||
}
|
||||
|
||||
private void addSounds(final String soundEvent, final SoundDefinition definition)
|
||||
|
||||
@@ -27,16 +27,16 @@ import java.util.function.BiConsumer;
|
||||
*/
|
||||
public abstract class SpriteSourceProvider extends JsonCodecProvider<List<SpriteSource>>
|
||||
{
|
||||
protected static final ResourceLocation BLOCKS_ATLAS = new ResourceLocation("blocks");
|
||||
protected static final ResourceLocation BANNER_PATTERNS_ATLAS = new ResourceLocation("banner_patterns");
|
||||
protected static final ResourceLocation BEDS_ATLAS = new ResourceLocation("beds");
|
||||
protected static final ResourceLocation CHESTS_ATLAS = new ResourceLocation("chests");
|
||||
protected static final ResourceLocation SHIELD_PATTERNS_ATLAS = new ResourceLocation("shield_patterns");
|
||||
protected static final ResourceLocation SHULKER_BOXES_ATLAS = new ResourceLocation("shulker_boxes");
|
||||
protected static final ResourceLocation SIGNS_ATLAS = new ResourceLocation("signs");
|
||||
protected static final ResourceLocation MOB_EFFECTS_ATLAS = new ResourceLocation("mob_effects");
|
||||
protected static final ResourceLocation PAINTINGS_ATLAS = new ResourceLocation("paintings");
|
||||
protected static final ResourceLocation PARTICLES_ATLAS = new ResourceLocation("particles");
|
||||
protected static final ResourceLocation BLOCKS_ATLAS = ResourceLocation.withDefaultNamespace("blocks");
|
||||
protected static final ResourceLocation BANNER_PATTERNS_ATLAS = ResourceLocation.withDefaultNamespace("banner_patterns");
|
||||
protected static final ResourceLocation BEDS_ATLAS = ResourceLocation.withDefaultNamespace("beds");
|
||||
protected static final ResourceLocation CHESTS_ATLAS = ResourceLocation.withDefaultNamespace("chests");
|
||||
protected static final ResourceLocation SHIELD_PATTERNS_ATLAS = ResourceLocation.withDefaultNamespace("shield_patterns");
|
||||
protected static final ResourceLocation SHULKER_BOXES_ATLAS = ResourceLocation.withDefaultNamespace("shulker_boxes");
|
||||
protected static final ResourceLocation SIGNS_ATLAS = ResourceLocation.withDefaultNamespace("signs");
|
||||
protected static final ResourceLocation MOB_EFFECTS_ATLAS = ResourceLocation.withDefaultNamespace("mob_effects");
|
||||
protected static final ResourceLocation PAINTINGS_ATLAS = ResourceLocation.withDefaultNamespace("paintings");
|
||||
protected static final ResourceLocation PARTICLES_ATLAS = ResourceLocation.withDefaultNamespace("particles");
|
||||
|
||||
private final Map<ResourceLocation, SourceList> atlases = new HashMap<>();
|
||||
|
||||
|
||||
@@ -476,13 +476,13 @@ public interface IForgeBlock {
|
||||
* @param level The level
|
||||
* @param pos The position of this state
|
||||
* @param beaconPos The position of the beacon
|
||||
* @return A float RGB [0.0, 1.0] array to be averaged with a beacon's existing beam color, or null to do nothing to the beam
|
||||
* @return A ARGB32 color to merge info the beacon's existing beam color, or -1 to do nothing to the beam
|
||||
*/
|
||||
@Nullable
|
||||
default float[] getBeaconColorMultiplier(BlockState state, LevelReader level, BlockPos pos, BlockPos beaconPos) {
|
||||
default int getBeaconColorMultiplier(BlockState state, LevelReader level, BlockPos pos, BlockPos beaconPos) {
|
||||
if (self() instanceof BeaconBeamBlock beam)
|
||||
return beam.getColor().getTextureDiffuseColors();
|
||||
return null;
|
||||
return beam.getColor().getTextureDiffuseColor();
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -397,10 +397,10 @@ public interface IForgeBlockState {
|
||||
* @param level The level
|
||||
* @param pos The position of this state
|
||||
* @param beacon The position of the beacon
|
||||
* @return A float RGB [0.0, 1.0] array to be averaged with a beacon's existing beam color, or null to do nothing to the beam
|
||||
* @return A ARGB32 color to merge info the beacon's existing beam color, or -1 to do nothing to the beam
|
||||
*/
|
||||
@Nullable
|
||||
default float[] getBeaconColorMultiplier(LevelReader level, BlockPos pos, BlockPos beacon) {
|
||||
default int getBeaconColorMultiplier(LevelReader level, BlockPos pos, BlockPos beacon) {
|
||||
return self().getBlock().getBeaconColorMultiplier(self(), level, pos, beacon);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.extensions;
|
||||
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public interface IForgeEnchantment {
|
||||
private Enchantment self() {
|
||||
return (Enchantment)this;
|
||||
}
|
||||
|
||||
/**
|
||||
* ItemStack aware version of {@link Enchantment#getDamageBonus(int, MobType)}
|
||||
* @param level the level of the enchantment
|
||||
* @param mobType the mob type being attacked
|
||||
* @param enchantedItem the item used for the attack
|
||||
* @return the damage bonus
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
default float getDamageBonus(int level, @Nullable EntityType<?> mobType, ItemStack enchantedItem) {
|
||||
return self().getDamageBonus(level, mobType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this enchantment allowed to be enchanted on books via Enchantment Table
|
||||
* @return false to disable the vanilla feature
|
||||
*/
|
||||
default boolean isAllowedOnBooks() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* This applies specifically to applying at the enchanting table. The other method {@link #canEnchant(ItemStack)}
|
||||
* applies for <i>all possible</i> enchantments.
|
||||
*/
|
||||
default boolean canApplyAtEnchantingTable(ItemStack stack) {
|
||||
return stack.canApplyAtEnchantingTable(self());
|
||||
}
|
||||
}
|
||||
@@ -54,7 +54,7 @@ public interface IForgeGameTestHelper {
|
||||
var server = level.getServer();
|
||||
|
||||
var listener = new ServerGamePacketListenerImpl(server, connection, player, cookie);
|
||||
var info = GameProtocols.SERVERBOUND.bind(RegistryFriendlyByteBuf.decorator(server.registryAccess()));
|
||||
var info = GameProtocols.SERVERBOUND_TEMPLATE.bind(RegistryFriendlyByteBuf.decorator(server.registryAccess()));
|
||||
connection.setupInboundProtocol(info, listener);
|
||||
return player;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import net.minecraft.world.item.context.UseOnContext;
|
||||
import net.minecraft.world.item.crafting.RecipeType;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.Level;
|
||||
@@ -106,14 +107,6 @@ public interface IForgeItem {
|
||||
return stack.getItem() instanceof ArmorItem && ((ArmorItem) stack.getItem()).getMaterial() == ArmorMaterials.GOLD;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the amount of durability the mending enchantment
|
||||
* will repair, on average, per point of experience.
|
||||
*/
|
||||
default float getXpRepairRatio(ItemStack stack) {
|
||||
return 2f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called before a block is broken. Return true to prevent default block
|
||||
* harvesting.
|
||||
@@ -255,12 +248,6 @@ public interface IForgeItem {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called to tick armor in the armor slot. Override to do something
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "1.20.1") // Use onInventoryTick
|
||||
default void onArmorTick(ItemStack stack, Level level, Player player){ }
|
||||
|
||||
/**
|
||||
* Called to tick this items in a players inventory, the indexes are the global slot index.
|
||||
*/
|
||||
@@ -272,8 +259,6 @@ public interface IForgeItem {
|
||||
vanillaIndex -= inv.items.size();
|
||||
if (vanillaIndex >= inv.armor.size())
|
||||
vanillaIndex -= inv.armor.size();
|
||||
else
|
||||
onArmorTick(stack, level, player);
|
||||
}
|
||||
stack.inventoryTick(level, player, vanillaIndex, selectedIndex == vanillaIndex);
|
||||
}
|
||||
@@ -288,7 +273,9 @@ public interface IForgeItem {
|
||||
* @return True if the given ItemStack can be inserted in the slot
|
||||
*/
|
||||
default boolean canEquip(ItemStack stack, EquipmentSlot armorType, Entity entity) {
|
||||
return Mob.getEquipmentSlotForItem(stack) == armorType;
|
||||
if (entity instanceof LivingEntity living)
|
||||
return living.getEquipmentSlotForItem(stack) == armorType;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -382,21 +369,7 @@ public interface IForgeItem {
|
||||
* @return true if the enchantment can be applied to this item
|
||||
*/
|
||||
default boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment) {
|
||||
return self().builtInRegistryHolder().is(enchantment.getSupportedItems()) && enchantment.isPrimaryItem(stack);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the level of the enchantment currently present on the stack. By default, returns the enchantment level present in NBT.
|
||||
* Most enchantment implementations rely upon this method.
|
||||
* For consistency, results of this method should be the same as getting the enchantment from {@link #getAllEnchantments(ItemStack)}
|
||||
*
|
||||
* @param stack the item stack being checked
|
||||
* @param enchantment the enchantment being checked for
|
||||
* @return Level of the enchantment, or 0 if not present
|
||||
* @see #getAllEnchantments(ItemStack)
|
||||
*/
|
||||
default int getEnchantmentLevel(ItemStack stack, Enchantment enchantment) {
|
||||
return EnchantmentHelper.getEnchantmentsForCrafting(stack).getLevel(enchantment);
|
||||
return enchantment.isPrimaryItem(stack);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -137,22 +137,6 @@ public interface IForgeItemStack {
|
||||
return self().getItem().canApplyAtEnchantingTable(self(), enchantment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the level of the enchantment currently present on the stack. By default, returns the enchantment level present in NBT.
|
||||
*
|
||||
* Equivalent to calling {@link net.minecraft.world.item.enchantment.EnchantmentHelper#getItemEnchantmentLevel(Enchantment, ItemStack)}
|
||||
* Use in place of {@link net.minecraft.world.item.enchantment.EnchantmentHelper#getTagEnchantmentLevel(Enchantment, ItemStack)} for checking presence of an enchantment in logic implementing the enchantment behavior.
|
||||
* Use {@link net.minecraft.world.item.enchantment.EnchantmentHelper#getTagEnchantmentLevel(Enchantment, ItemStack)} instead when modifying an item's enchantments.
|
||||
*
|
||||
* @param enchantment the enchantment being checked for
|
||||
* @return Level of the enchantment, or 0 if not present
|
||||
* @see #getAllEnchantments()
|
||||
* @see net.minecraft.world.item.enchantment.EnchantmentHelper#getTagEnchantmentLevel(Enchantment, ItemStack)
|
||||
*/
|
||||
default int getEnchantmentLevel(Enchantment enchantment) {
|
||||
return self().getItem().getEnchantmentLevel(self(), enchantment);
|
||||
}
|
||||
|
||||
/**
|
||||
* ItemStack sensitive version of {@link Item#getEnchantmentValue()}.
|
||||
*
|
||||
@@ -231,14 +215,6 @@ public interface IForgeItemStack {
|
||||
return self().getItem().onEntityItemUpdate(self(), entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the amount of durability the mending enchantment
|
||||
* will repair, on average, per point of experience.
|
||||
*/
|
||||
default float getXpRepairRatio() {
|
||||
return self().getItem().getXpRepairRatio(self());
|
||||
}
|
||||
|
||||
/**
|
||||
* Called to tick this items in a players inventory, the indexes are the global slot index.
|
||||
*/
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
|
||||
package net.minecraftforge.common.extensions;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.TagBuilder;
|
||||
import net.minecraft.tags.TagEntry;
|
||||
@@ -16,12 +14,6 @@ public interface IForgeRawTagBuilder {
|
||||
return (TagBuilder) this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Never used, tags use a Codec now, so remove this later.
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "1.20.1")
|
||||
default void serializeTagAdditions(final JsonObject tagJson) {}
|
||||
|
||||
/**
|
||||
* Adds a tag entry to the remove list.
|
||||
* @param tagEntry The tag entry to add to the remove list
|
||||
|
||||
@@ -31,7 +31,7 @@ import java.util.function.Function;
|
||||
public interface IGlobalLootModifier {
|
||||
Codec<IGlobalLootModifier> DIRECT_CODEC = Codec.lazyInitialized(() -> ForgeRegistries.GLOBAL_LOOT_MODIFIER_SERIALIZERS.get().getCodec().dispatch(IGlobalLootModifier::codec, Function.identity()));
|
||||
|
||||
Codec<LootItemCondition[]> LOOT_CONDITIONS_CODEC = LootItemConditions.DIRECT_CODEC.listOf().xmap(list -> list.toArray(LootItemCondition[]::new), List::of);
|
||||
Codec<LootItemCondition[]> LOOT_CONDITIONS_CODEC = LootItemCondition.DIRECT_CODEC.listOf().xmap(list -> list.toArray(LootItemCondition[]::new), List::of);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static <U> JsonElement getJson(Dynamic<?> dynamic) {
|
||||
|
||||
@@ -38,7 +38,7 @@ public class LootModifierManager extends SimpleJsonResourceReloadListener {
|
||||
|
||||
@Override
|
||||
protected Map<ResourceLocation, JsonElement> prepare(ResourceManager resources, ProfilerFiller profilerFiller) {
|
||||
var path = new ResourceLocation("forge", FOLDER + "/global_loot_modifiers.json");
|
||||
var path = ResourceLocation.fromNamespaceAndPath("forge", FOLDER + "/global_loot_modifiers.json");
|
||||
|
||||
List<ResourceLocation> toLoad = new ArrayList<>();
|
||||
//read in all data files from forge:loot_modifiers/global_loot_modifiers in order to do layering
|
||||
@@ -50,7 +50,7 @@ public class LootModifierManager extends SimpleJsonResourceReloadListener {
|
||||
toLoad.clear();
|
||||
|
||||
for(var entry : GsonHelper.getAsJsonArray(json, "entries")) {
|
||||
ResourceLocation loc = new ResourceLocation(entry.getAsString());
|
||||
ResourceLocation loc = ResourceLocation.parse(entry.getAsString());
|
||||
toLoad.remove(loc); //remove and re-add if needed, to update the ordering.
|
||||
toLoad.add(loc);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ public record LootTableIdCondition(ResourceLocation id) implements LootItemCondi
|
||||
|
||||
// TODO Forge Registry at some point?
|
||||
public static final LootItemConditionType TYPE = new LootItemConditionType(CODEC);
|
||||
public static final ResourceLocation UNKNOWN_LOOT_TABLE = new ResourceLocation("forge", "unknown_loot_table");
|
||||
public static final ResourceLocation UNKNOWN_LOOT_TABLE = ResourceLocation.fromNamespaceAndPath("forge", "unknown_loot_table");
|
||||
|
||||
@Override
|
||||
public LootItemConditionType getType() {
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.util;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.portal.PortalInfo;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
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.
|
||||
* <p>
|
||||
* An implementation of this interface can be used to place the entity
|
||||
* in a safe location, or generate a return portal, for instance.
|
||||
* <p>
|
||||
* See the {@link PortalForcer} class, which has
|
||||
* been patched to implement this interface, for a vanilla example.
|
||||
*/
|
||||
public interface ITeleporter
|
||||
{
|
||||
/**
|
||||
* Called to handle placing the entity in the new world.
|
||||
* <p>
|
||||
* The initial position of the entity will be its
|
||||
* position in the origin world, multiplied horizontally
|
||||
* by the computed cross-dimensional movement factor.
|
||||
* <p>
|
||||
* Note that the supplied entity has not yet been spawned
|
||||
* in the destination world at the time.
|
||||
*
|
||||
* @param entity the entity to be placed
|
||||
* @param currentWorld the entity's origin
|
||||
* @param destWorld the entity's destination
|
||||
* @param yaw the suggested yaw value to apply
|
||||
* @param repositionEntity a function to reposition the entity, which returns the new entity in the new dimension. This is the vanilla implementation of the dimension travel logic. If the supplied boolean is true, it is attempted to spawn a new portal.
|
||||
*
|
||||
* @return the entity in the new World. Vanilla creates for most {@link Entity}s a new instance and copy the data. But <b>you are not allowed</b> to create a new instance for {@link Player}s! Move the player and update its state, see {@link ServerPlayer#changeDimension(ServerLevel, ITeleporter)}
|
||||
*/
|
||||
default Entity placeEntity(Entity entity, ServerLevel currentWorld, ServerLevel destWorld, float yaw, Function<Boolean, Entity> repositionEntity)
|
||||
{
|
||||
return repositionEntity.apply(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
default PortalInfo getPortalInfo(Entity entity, ServerLevel destWorld, Function<ServerLevel, PortalInfo> defaultPortalInfo)
|
||||
{
|
||||
return this.isVanilla() ? defaultPortalInfo.apply(destWorld) : new PortalInfo(entity.position(), Vec3.ZERO, entity.getYRot(), entity.getXRot());
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this teleporter the vanilla instance.
|
||||
*/
|
||||
default boolean isVanilla()
|
||||
{
|
||||
return this.getClass() == PortalForcer.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when vanilla wants to play the portal sound after teleporting. Return true to play the vanilla sound.
|
||||
* @param player the player
|
||||
* @param sourceWorld the source world
|
||||
* @param destWorld the target world
|
||||
* @return true to play the vanilla sound
|
||||
*/
|
||||
default boolean playTeleportSound(ServerPlayer player, ServerLevel sourceWorld, ServerLevel destWorld)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user