-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/1.20.2' into 1.20.4
- Loading branch information
Showing
15 changed files
with
429 additions
and
17 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
...on/src/main/java/dev/architectury/registry/client/gui/ClientTooltipComponentRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* This file is part of architectury. | ||
* Copyright (C) 2020, 2021, 2022 architectury | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
package dev.architectury.registry.client.gui; | ||
|
||
import dev.architectury.injectables.annotations.ExpectPlatform; | ||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent; | ||
import net.minecraft.world.inventory.tooltip.TooltipComponent; | ||
|
||
import java.util.function.Function; | ||
|
||
/** | ||
* Registry for {@link ClientTooltipComponent} factories | ||
*/ | ||
@Environment(EnvType.CLIENT) | ||
public final class ClientTooltipComponentRegistry { | ||
private ClientTooltipComponentRegistry() { | ||
} | ||
|
||
/** | ||
* Allows users to register custom {@link ClientTooltipComponent} | ||
* factories for their {@link TooltipComponent} types. | ||
* | ||
* @param clazz class of {@link T} | ||
* @param factory factory to create instances of {@link ClientTooltipComponent} from {@link T} | ||
* @param <T> the type of {@link TooltipComponent} factory | ||
*/ | ||
@ExpectPlatform | ||
public static <T extends TooltipComponent> void register(Class<T> clazz, Function<? super T, ? extends ClientTooltipComponent> factory) { | ||
throw new AssertionError(); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
common/src/main/java/dev/architectury/registry/level/entity/SpawnPlacementsRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* This file is part of architectury. | ||
* Copyright (C) 2020, 2021, 2022 architectury | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
package dev.architectury.registry.level.entity; | ||
|
||
import dev.architectury.injectables.annotations.ExpectPlatform; | ||
import net.minecraft.world.entity.EntityType; | ||
import net.minecraft.world.entity.Mob; | ||
import net.minecraft.world.entity.SpawnPlacements; | ||
import net.minecraft.world.level.levelgen.Heightmap; | ||
|
||
import java.util.function.Supplier; | ||
|
||
public final class SpawnPlacementsRegistry { | ||
/** | ||
* Registers the spawn placement of an entity. | ||
* | ||
* @param type the type of entity | ||
* @param spawnPlacement the type of spawn placement | ||
* @param heightmapType the type of heightmap | ||
* @param spawnPredicate the spawn predicate | ||
* @see net.minecraft.world.entity.SpawnPlacements | ||
*/ | ||
@ExpectPlatform | ||
public static <T extends Mob> void register(Supplier<? extends EntityType<T>> type, SpawnPlacements.Type spawnPlacement, Heightmap.Types heightmapType, SpawnPlacements.SpawnPredicate<T> spawnPredicate) { | ||
throw new AssertionError(); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
.../src/main/java/dev/architectury/registry/registries/options/DefaultIdRegistrarOption.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* This file is part of architectury. | ||
* Copyright (C) 2020, 2021, 2022 architectury | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
package dev.architectury.registry.registries.options; | ||
|
||
import net.minecraft.resources.ResourceLocation; | ||
|
||
public record DefaultIdRegistrarOption(ResourceLocation defaultId) implements RegistrarOption { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
.../java/dev/architectury/registry/client/gui/fabric/ClientTooltipComponentRegistryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* This file is part of architectury. | ||
* Copyright (C) 2020, 2021, 2022 architectury | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
package dev.architectury.registry.client.gui.fabric; | ||
|
||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.fabricmc.fabric.api.client.rendering.v1.TooltipComponentCallback; | ||
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent; | ||
import net.minecraft.world.inventory.tooltip.TooltipComponent; | ||
import org.jetbrains.annotations.ApiStatus; | ||
|
||
import java.util.function.Function; | ||
|
||
@Environment(EnvType.CLIENT) | ||
@ApiStatus.Internal | ||
public class ClientTooltipComponentRegistryImpl { | ||
public static <T extends TooltipComponent> void register(Class<T> clazz, Function<? super T, ? extends ClientTooltipComponent> factory) { | ||
TooltipComponentCallback.EVENT.register((tooltipComponent) -> { | ||
if (clazz.isInstance(tooltipComponent)) { | ||
return factory.apply(clazz.cast(tooltipComponent)); | ||
} | ||
return null; | ||
}); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
.../main/java/dev/architectury/registry/level/entity/fabric/SpawnPlacementsRegistryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* This file is part of architectury. | ||
* Copyright (C) 2020, 2021, 2022 architectury | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
package dev.architectury.registry.level.entity.fabric; | ||
|
||
import net.minecraft.world.entity.EntityType; | ||
import net.minecraft.world.entity.Mob; | ||
import net.minecraft.world.entity.SpawnPlacements; | ||
import net.minecraft.world.level.levelgen.Heightmap; | ||
|
||
import java.util.function.Supplier; | ||
|
||
public class SpawnPlacementsRegistryImpl { | ||
public static <T extends Mob> void register(Supplier<? extends EntityType<T>> type, SpawnPlacements.Type spawnPlacement, Heightmap.Types heightmapType, SpawnPlacements.SpawnPredicate<T> spawnPredicate) { | ||
SpawnPlacements.register(type.get(), spawnPlacement, heightmapType, spawnPredicate); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...n/java/dev/architectury/registry/client/gui/forge/ClientTooltipComponentRegistryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* This file is part of architectury. | ||
* Copyright (C) 2020, 2021, 2022 architectury | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
package dev.architectury.registry.client.gui.forge; | ||
|
||
import dev.architectury.platform.hooks.EventBusesHooks; | ||
import dev.architectury.utils.ArchitecturyConstants; | ||
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent; | ||
import net.minecraft.world.inventory.tooltip.TooltipComponent; | ||
import net.minecraftforge.api.distmarker.Dist; | ||
import net.minecraftforge.api.distmarker.OnlyIn; | ||
import net.minecraftforge.client.event.RegisterClientTooltipComponentFactoriesEvent; | ||
import net.minecraftforge.eventbus.api.EventPriority; | ||
import org.jetbrains.annotations.ApiStatus; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.function.Function; | ||
|
||
@OnlyIn(Dist.CLIENT) | ||
@ApiStatus.Internal | ||
public class ClientTooltipComponentRegistryImpl { | ||
@Nullable | ||
private static List<Entry<?>> entries = new ArrayList<>(); | ||
|
||
static { | ||
EventBusesHooks.whenAvailable(ArchitecturyConstants.MOD_ID, bus -> { | ||
bus.<RegisterClientTooltipComponentFactoriesEvent>addListener(EventPriority.HIGH, event -> { | ||
if (entries != null) { | ||
for (Entry<?> entry : entries) { | ||
Entry<TooltipComponent> casted = (Entry<TooltipComponent>) entry; | ||
event.register(casted.clazz(), casted.factory()); | ||
} | ||
|
||
entries = null; | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
public static <T extends TooltipComponent> void register(Class<T> clazz, Function<? super T, ? extends ClientTooltipComponent> factory) { | ||
if (entries == null) { | ||
throw new IllegalStateException("Cannot register ClientTooltipComponent factory when factories are already aggregated!"); | ||
} | ||
entries.add(new Entry<>(clazz, factory)); | ||
} | ||
|
||
public record Entry<T extends TooltipComponent>( | ||
Class<T> clazz, Function<? super T, ? extends ClientTooltipComponent> factory | ||
) { | ||
} | ||
} |
Oops, something went wrong.