mirror of
https://github.com/architectury/architectury-api.git
synced 2026-04-02 13:37:43 -05:00
Merge remote-tracking branch 'architectury/1.16' into 1.17
Signed-off-by: shedaniel <daniel@shedaniel.me> # Conflicts: # .github/workflows/publish.yml # .github/workflows/snapshot.yml # build.gradle # common/src/main/resources/architectury-common.mixins.json # fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinLevelChunk.java # fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinServerGamePacketListenerImpl.java # fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinServerLevel.java # fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/client/MixinMouseHandler.java # fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/client/MixinScreen.java # forge/gradle.properties # gradle.properties # gradle/wrapper/gradle-wrapper.properties # testmod-fabric/build.gradle # testmod-forge/gradle.properties
This commit is contained in:
@@ -32,23 +32,23 @@ public class PlatformMethods {
|
||||
String lookupType = lookupClass.getName().replace("$", "") + "Impl";
|
||||
|
||||
String platformExpectedClass = lookupType.substring(0, lookupType.lastIndexOf('.')) + "." + ArchitecturyTarget.getCurrentTarget() + "." +
|
||||
lookupType.substring(lookupType.lastIndexOf('.') + 1);
|
||||
lookupType.substring(lookupType.lastIndexOf('.') + 1);
|
||||
Class<?> newClass;
|
||||
try {
|
||||
newClass = Class.forName(platformExpectedClass, false, lookupClass.getClassLoader());
|
||||
} catch (ClassNotFoundException exception) {
|
||||
throw new PlatformExpectedError(lookupClass.getName() + "#" + name + " expected platform implementation in " + platformExpectedClass +
|
||||
"#" + name + ", but the class doesn't exist!", exception);
|
||||
"#" + name + ", but the class doesn't exist!", exception);
|
||||
}
|
||||
MethodHandle platformMethod;
|
||||
try {
|
||||
platformMethod = lookup.findStatic(newClass, name, type);
|
||||
} catch (NoSuchMethodException exception) {
|
||||
throw new PlatformExpectedError(lookupClass.getName() + "#" + name + " expected platform implementation in " + platformExpectedClass +
|
||||
"#" + name + ", but the method doesn't exist!", exception);
|
||||
"#" + name + ", but the method doesn't exist!", exception);
|
||||
} catch (IllegalAccessException exception) {
|
||||
throw new PlatformExpectedError(lookupClass.getName() + "#" + name + " expected platform implementation in " + platformExpectedClass +
|
||||
"#" + name + ", but the method's modifier doesn't match the access requirements!", exception);
|
||||
"#" + name + ", but the method's modifier doesn't match the access requirements!", exception);
|
||||
}
|
||||
return new ConstantCallSite(platformMethod);
|
||||
}
|
||||
|
||||
@@ -37,7 +37,8 @@ import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
public final class EventFactory {
|
||||
private EventFactory() {}
|
||||
private EventFactory() {
|
||||
}
|
||||
|
||||
public static <T> Event<T> of(Function<List<T>, T> function) {
|
||||
return new EventImpl<>(function);
|
||||
|
||||
@@ -29,7 +29,8 @@ import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
public final class EventHandler {
|
||||
private EventHandler() {}
|
||||
private EventHandler() {
|
||||
}
|
||||
|
||||
private static boolean initialized = false;
|
||||
|
||||
|
||||
@@ -63,11 +63,13 @@ public interface LifecycleEvent {
|
||||
void stateChanged(T instance);
|
||||
}
|
||||
|
||||
interface ServerState extends InstanceState<MinecraftServer> {}
|
||||
interface ServerState extends InstanceState<MinecraftServer> {
|
||||
}
|
||||
|
||||
interface WorldState<T extends Level> {
|
||||
void act(T world);
|
||||
}
|
||||
|
||||
interface ServerWorldState extends WorldState<ServerLevel> {}
|
||||
interface ServerWorldState extends WorldState<ServerLevel> {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,11 +35,15 @@ public interface TickEvent<T> {
|
||||
|
||||
void tick(T instance);
|
||||
|
||||
interface Server extends TickEvent<MinecraftServer> {}
|
||||
interface Server extends TickEvent<MinecraftServer> {
|
||||
}
|
||||
|
||||
interface WorldTick<T extends Level> extends TickEvent<T> {}
|
||||
interface WorldTick<T extends Level> extends TickEvent<T> {
|
||||
}
|
||||
|
||||
interface ServerWorld extends WorldTick<ServerLevel> {}
|
||||
interface ServerWorld extends WorldTick<ServerLevel> {
|
||||
}
|
||||
|
||||
interface Player extends TickEvent<net.minecraft.world.entity.player.Player> {}
|
||||
interface Player extends TickEvent<net.minecraft.world.entity.player.Player> {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,11 +32,13 @@ public interface ClientLifecycleEvent {
|
||||
/**
|
||||
* Invoked when client has been initialised, not available in forge.
|
||||
*/
|
||||
@Deprecated Event<ClientState> CLIENT_STARTED = EventFactory.createLoop();
|
||||
@Deprecated
|
||||
Event<ClientState> CLIENT_STARTED = EventFactory.createLoop();
|
||||
/**
|
||||
* Invoked when client is stopping, not available in forge.
|
||||
*/
|
||||
@Deprecated Event<ClientState> CLIENT_STOPPING = EventFactory.createLoop();
|
||||
@Deprecated
|
||||
Event<ClientState> CLIENT_STOPPING = EventFactory.createLoop();
|
||||
/**
|
||||
* Invoked after a world is loaded only on client, equivalent to forge's {@code WorldEvent.Load}.
|
||||
*/
|
||||
@@ -44,8 +46,10 @@ public interface ClientLifecycleEvent {
|
||||
Event<ClientState> CLIENT_SETUP = EventFactory.createLoop();
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
interface ClientState extends LifecycleEvent.InstanceState<Minecraft> {}
|
||||
interface ClientState extends LifecycleEvent.InstanceState<Minecraft> {
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
interface ClientWorldState extends LifecycleEvent.WorldState<ClientLevel> {}
|
||||
interface ClientWorldState extends LifecycleEvent.WorldState<ClientLevel> {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,8 +36,10 @@ public interface ClientTickEvent<T> {
|
||||
void tick(T instance);
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
interface Client extends ClientTickEvent<Minecraft> {}
|
||||
interface Client extends ClientTickEvent<Minecraft> {
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
interface ClientWorld extends ClientTickEvent<ClientLevel> {}
|
||||
interface ClientWorld extends ClientTickEvent<ClientLevel> {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,8 @@ import me.shedaniel.architectury.annotations.ExpectPlatform;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
|
||||
public class BlockEntityHooks {
|
||||
private BlockEntityHooks() {}
|
||||
private BlockEntityHooks() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sync data to the clients.
|
||||
|
||||
@@ -23,7 +23,8 @@ import me.shedaniel.architectury.annotations.ExpectPlatform;
|
||||
import net.minecraft.world.item.DyeColor;
|
||||
|
||||
public class DyeColorHooks {
|
||||
private DyeColorHooks() {}
|
||||
private DyeColorHooks() {
|
||||
}
|
||||
|
||||
@ExpectPlatform
|
||||
public static int getColorValue(DyeColor color) {
|
||||
|
||||
@@ -25,7 +25,8 @@ import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public final class EntityHooks {
|
||||
private EntityHooks() {}
|
||||
private EntityHooks() {
|
||||
}
|
||||
|
||||
@ExpectPlatform
|
||||
public static String getEncodeId(Entity entity) {
|
||||
|
||||
@@ -26,7 +26,8 @@ import net.minecraft.world.phys.Vec3;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public final class ExplosionHooks {
|
||||
private ExplosionHooks() {}
|
||||
private ExplosionHooks() {
|
||||
}
|
||||
|
||||
@ExpectPlatform
|
||||
public static Vec3 getPosition(Explosion explosion) {
|
||||
|
||||
@@ -34,7 +34,8 @@ import net.minecraft.world.level.material.FluidState;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class FluidStackHooks {
|
||||
private FluidStackHooks() {}
|
||||
private FluidStackHooks() {
|
||||
}
|
||||
|
||||
@ExpectPlatform
|
||||
public static Component getName(FluidStack stack) {
|
||||
|
||||
@@ -24,7 +24,8 @@ import me.shedaniel.architectury.utils.IntValue;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
|
||||
public final class ItemEntityHooks {
|
||||
private ItemEntityHooks() {}
|
||||
private ItemEntityHooks() {
|
||||
}
|
||||
|
||||
/**
|
||||
* The lifespan of an {@link ItemEntity}.
|
||||
|
||||
@@ -26,7 +26,8 @@ import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
public final class ItemStackHooks {
|
||||
private ItemStackHooks() {}
|
||||
private ItemStackHooks() {
|
||||
}
|
||||
|
||||
public static ItemStack copyWithCount(ItemStack stack, int count) {
|
||||
ItemStack copy = stack.copy();
|
||||
|
||||
@@ -22,7 +22,8 @@ package me.shedaniel.architectury.hooks;
|
||||
import net.minecraft.world.level.storage.LevelResource;
|
||||
|
||||
public class LevelResourceHooks {
|
||||
private LevelResourceHooks() {}
|
||||
private LevelResourceHooks() {
|
||||
}
|
||||
|
||||
public static LevelResource create(String id) {
|
||||
return new LevelResource(id);
|
||||
|
||||
@@ -24,7 +24,8 @@ import net.minecraft.server.packs.repository.PackRepository;
|
||||
import net.minecraft.server.packs.repository.RepositorySource;
|
||||
|
||||
public class PackRepositoryHooks {
|
||||
private PackRepositoryHooks() {}
|
||||
private PackRepositoryHooks() {
|
||||
}
|
||||
|
||||
@ExpectPlatform
|
||||
public static void addSource(PackRepository repository, RepositorySource source) {
|
||||
|
||||
@@ -23,7 +23,8 @@ import me.shedaniel.architectury.annotations.ExpectPlatform;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
||||
public final class PlayerHooks {
|
||||
private PlayerHooks() {}
|
||||
private PlayerHooks() {
|
||||
}
|
||||
|
||||
@ExpectPlatform
|
||||
public static boolean isFake(Player player) {
|
||||
|
||||
@@ -30,7 +30,8 @@ import java.util.List;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public final class ScreenHooks {
|
||||
private ScreenHooks() {}
|
||||
private ScreenHooks() {
|
||||
}
|
||||
|
||||
@ExpectPlatform
|
||||
public static List<AbstractWidget> getButtons(Screen screen) {
|
||||
|
||||
@@ -31,7 +31,8 @@ import net.minecraft.world.level.material.Fluid;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public final class TagHooks {
|
||||
private TagHooks() {}
|
||||
private TagHooks() {
|
||||
}
|
||||
|
||||
@ExpectPlatform
|
||||
public static <T> Tag.Named<T> getOptional(ResourceLocation id, Supplier<TagCollection<T>> collection) {
|
||||
|
||||
@@ -31,7 +31,6 @@ import net.minecraft.world.level.levelgen.carver.ConfiguredWorldCarver;
|
||||
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
|
||||
import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature;
|
||||
import net.minecraft.world.level.levelgen.surfacebuilders.ConfiguredSurfaceBuilder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
@@ -61,10 +60,10 @@ public final class BiomeHooks {
|
||||
}
|
||||
|
||||
public BiomeWrapped(Biome biome,
|
||||
ClimateProperties climateProperties,
|
||||
EffectsProperties effectsProperties,
|
||||
GenerationProperties generationProperties,
|
||||
SpawnProperties spawnProperties) {
|
||||
ClimateProperties climateProperties,
|
||||
EffectsProperties effectsProperties,
|
||||
GenerationProperties generationProperties,
|
||||
SpawnProperties spawnProperties) {
|
||||
this.biome = biome;
|
||||
this.climateProperties = climateProperties;
|
||||
this.effectsProperties = effectsProperties;
|
||||
@@ -110,8 +109,8 @@ public final class BiomeHooks {
|
||||
|
||||
public static class MutableBiomeWrapped extends BiomeWrapped implements BiomeProperties.Mutable {
|
||||
public MutableBiomeWrapped(Biome biome,
|
||||
GenerationProperties.Mutable generationProperties,
|
||||
SpawnProperties.Mutable spawnProperties) {
|
||||
GenerationProperties.Mutable generationProperties,
|
||||
SpawnProperties.Mutable spawnProperties) {
|
||||
this(biome,
|
||||
new ClimateWrapped(biome.climateSettings),
|
||||
new EffectsWrapped(biome.getSpecialEffects()),
|
||||
@@ -120,10 +119,10 @@ public final class BiomeHooks {
|
||||
}
|
||||
|
||||
public MutableBiomeWrapped(Biome biome,
|
||||
ClimateProperties.Mutable climateProperties,
|
||||
EffectsProperties.Mutable effectsProperties,
|
||||
GenerationProperties.Mutable generationProperties,
|
||||
SpawnProperties.Mutable spawnProperties) {
|
||||
ClimateProperties.Mutable climateProperties,
|
||||
EffectsProperties.Mutable effectsProperties,
|
||||
GenerationProperties.Mutable generationProperties,
|
||||
SpawnProperties.Mutable spawnProperties) {
|
||||
super(biome,
|
||||
climateProperties,
|
||||
effectsProperties,
|
||||
|
||||
@@ -21,7 +21,6 @@ package me.shedaniel.architectury.hooks.biome;
|
||||
|
||||
import net.minecraft.world.level.biome.Biome.Precipitation;
|
||||
import net.minecraft.world.level.biome.Biome.TemperatureModifier;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface ClimateProperties {
|
||||
Precipitation getPrecipitation();
|
||||
|
||||
@@ -32,14 +32,15 @@ import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
|
||||
public final class Platform {
|
||||
private Platform() {}
|
||||
private Platform() {
|
||||
}
|
||||
|
||||
private static int simpleLoaderCache = -1;
|
||||
|
||||
/**
|
||||
* @return the current mod loader, either "fabric" or "forge"
|
||||
* @deprecated does not reflect the true mod loader, "quilt" is never returned,
|
||||
* use {@link ArchitecturyTarget#getCurrentTarget()} instead.
|
||||
* use {@link ArchitecturyTarget#getCurrentTarget()} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
@ApiStatus.ScheduledForRemoval(inVersion = "2.0")
|
||||
|
||||
@@ -32,7 +32,8 @@ import java.util.function.Function;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public final class BlockEntityRenderers {
|
||||
private BlockEntityRenderers() {}
|
||||
private BlockEntityRenderers() {
|
||||
}
|
||||
|
||||
@ExpectPlatform
|
||||
public static <T extends BlockEntity> void registerRenderer(BlockEntityType<T> type, BlockEntityRendererProvider<? super T> provider) {
|
||||
|
||||
@@ -32,7 +32,8 @@ import java.util.function.Supplier;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public final class ColorHandlers {
|
||||
private ColorHandlers() {}
|
||||
private ColorHandlers() {
|
||||
}
|
||||
|
||||
public static void registerItemColors(ItemColor color, ItemLike... items) {
|
||||
Supplier<ItemLike>[] array = new Supplier[items.length];
|
||||
|
||||
@@ -27,7 +27,8 @@ import net.minecraft.world.item.ItemStack;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public final class CreativeTabs {
|
||||
private CreativeTabs() {}
|
||||
private CreativeTabs() {
|
||||
}
|
||||
|
||||
// I am sorry, fabric wants a resource location instead of the translation key for whatever reason
|
||||
@ExpectPlatform
|
||||
|
||||
@@ -23,7 +23,8 @@ import me.shedaniel.architectury.annotations.ExpectPlatform;
|
||||
import net.minecraft.advancements.CriterionTrigger;
|
||||
|
||||
public final class CriteriaTriggersRegistry {
|
||||
private CriteriaTriggersRegistry() {}
|
||||
private CriteriaTriggersRegistry() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes {@link net.minecraft.advancements.CriteriaTriggers#register(CriterionTrigger)}.
|
||||
|
||||
@@ -29,8 +29,9 @@ import java.util.function.BiConsumer;
|
||||
* A utility class for creating game rule types.
|
||||
*/
|
||||
public final class GameRuleFactory {
|
||||
private GameRuleFactory() {}
|
||||
|
||||
private GameRuleFactory() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a boolean rule type.
|
||||
*
|
||||
@@ -41,7 +42,7 @@ public final class GameRuleFactory {
|
||||
public static GameRules.Type<GameRules.BooleanValue> createBooleanRule(boolean defaultValue) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a boolean rule type.
|
||||
*
|
||||
@@ -53,7 +54,7 @@ public final class GameRuleFactory {
|
||||
public static GameRules.Type<GameRules.BooleanValue> createBooleanRule(boolean defaultValue, BiConsumer<MinecraftServer, GameRules.BooleanValue> changedCallback) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates an integer rule type.
|
||||
*
|
||||
@@ -64,7 +65,7 @@ public final class GameRuleFactory {
|
||||
public static GameRules.Type<GameRules.IntegerValue> createIntRule(int defaultValue) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates an integer rule type.
|
||||
*
|
||||
|
||||
@@ -26,15 +26,16 @@ import net.minecraft.world.level.GameRules;
|
||||
* A registry for registering game rules.
|
||||
*/
|
||||
public final class GameRuleRegistry {
|
||||
private GameRuleRegistry() {}
|
||||
|
||||
private GameRuleRegistry() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a game rule.
|
||||
*
|
||||
* @param name the rule's name
|
||||
* @param category the rule category
|
||||
* @param type the type of the rule
|
||||
* @param <T> the type of the rule value
|
||||
* @param <T> the type of the rule value
|
||||
* @return a key for the registered rule
|
||||
*/
|
||||
@ExpectPlatform
|
||||
|
||||
@@ -26,7 +26,8 @@ import net.minecraft.client.KeyMapping;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public final class KeyBindings {
|
||||
private KeyBindings() {}
|
||||
private KeyBindings() {
|
||||
}
|
||||
|
||||
@ExpectPlatform
|
||||
public static void registerKeyBinding(KeyMapping binding) {
|
||||
|
||||
@@ -41,7 +41,8 @@ import java.util.function.Consumer;
|
||||
* A utility class to register {@link MenuType}s and {@link Screen}s for containers
|
||||
*/
|
||||
public final class MenuRegistry {
|
||||
private MenuRegistry() {}
|
||||
private MenuRegistry() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the menu.
|
||||
|
||||
@@ -24,7 +24,8 @@ import net.minecraft.server.packs.PackType;
|
||||
import net.minecraft.server.packs.resources.PreparableReloadListener;
|
||||
|
||||
public final class ReloadListeners {
|
||||
private ReloadListeners() {}
|
||||
private ReloadListeners() {
|
||||
}
|
||||
|
||||
@ExpectPlatform
|
||||
public static void registerReloadListener(PackType type, PreparableReloadListener listener) {
|
||||
|
||||
@@ -28,7 +28,8 @@ import net.minecraft.world.level.material.Fluid;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public final class RenderTypes {
|
||||
private RenderTypes() {}
|
||||
private RenderTypes() {
|
||||
}
|
||||
|
||||
@ExpectPlatform
|
||||
public static void register(RenderType type, Block... blocks) {
|
||||
|
||||
@@ -27,7 +27,8 @@ import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public final class EntityAttributes {
|
||||
private EntityAttributes() {}
|
||||
private EntityAttributes() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers default attributes to entities.
|
||||
|
||||
@@ -32,7 +32,8 @@ import java.util.function.Function;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public final class EntityRenderers {
|
||||
private EntityRenderers() {}
|
||||
private EntityRenderers() {
|
||||
}
|
||||
|
||||
@ExpectPlatform
|
||||
public static <T extends Entity> void register(EntityType<T> type, EntityRendererProvider<T> provider) {
|
||||
|
||||
@@ -24,7 +24,8 @@ import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
|
||||
public final class FuelRegistry {
|
||||
private FuelRegistry() {}
|
||||
private FuelRegistry() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a burn time for items.
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* This file is part of architectury.
|
||||
* Copyright (C) 2020, 2021 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 me.shedaniel.architectury.registry.trade;
|
||||
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.npc.VillagerTrades;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.trading.MerchantOffer;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* This class is the easiest implementation of a trade object.
|
||||
* All trades added by vanilla do have custom classes like {@link VillagerTrades.EmeraldForItems}, but they aren't accessible.
|
||||
* <p>
|
||||
* Instead of widening the access of those classes or recreating them, this class was added to serve a basic trading implementation.
|
||||
* To register a trade, just call
|
||||
* {@link TradeRegistry#registerVillagerTrade(net.minecraft.world.entity.npc.VillagerProfession, int, VillagerTrades.ItemListing...)}
|
||||
* or
|
||||
* {@link TradeRegistry#registerTradeForWanderingTrader(boolean, VillagerTrades.ItemListing...)}.
|
||||
*/
|
||||
public class SimpleTrade implements VillagerTrades.ItemListing {
|
||||
private final ItemStack primaryPrice;
|
||||
private final ItemStack secondaryPrice;
|
||||
private final ItemStack sale;
|
||||
private final int maxTrades;
|
||||
private final int experiencePoints;
|
||||
private final float priceMultiplier;
|
||||
|
||||
/**
|
||||
* Constructor for creating the trade.
|
||||
* You can take a look at all the values the vanilla game uses right here {@link VillagerTrades#TRADES}.
|
||||
*
|
||||
* @param primaryPrice The first price a player has to pay to get the 'sale' stack.
|
||||
* @param secondaryPrice A optional, secondary price to pay as well as the primary one. If not needed just use {@link ItemStack#EMPTY}.
|
||||
* @param sale The ItemStack which a player can purchase in exchange for the two prices.
|
||||
* @param maxTrades The amount of trades one villager or wanderer can do. When the amount is surpassed, the trade can't be purchased anymore.
|
||||
* @param experiencePoints How much experience points does the player get, when trading. Vanilla uses between 2 and 30 for this.
|
||||
* @param priceMultiplier How much should the price rise, after the trade is used. It is added to the stack size of the primary price. Vanilla uses between 0.05 and 0.2.
|
||||
*/
|
||||
public SimpleTrade(ItemStack primaryPrice, ItemStack secondaryPrice, ItemStack sale, int maxTrades, int experiencePoints, float priceMultiplier) {
|
||||
this.primaryPrice = primaryPrice;
|
||||
this.secondaryPrice = secondaryPrice;
|
||||
this.sale = sale;
|
||||
this.maxTrades = maxTrades;
|
||||
this.experiencePoints = experiencePoints;
|
||||
this.priceMultiplier = priceMultiplier;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public MerchantOffer getOffer(Entity entity, Random random) {
|
||||
return new MerchantOffer(this.primaryPrice, this.secondaryPrice, this.sale, this.maxTrades, this.experiencePoints, this.priceMultiplier);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* This file is part of architectury.
|
||||
* Copyright (C) 2020, 2021 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 me.shedaniel.architectury.registry.trade;
|
||||
|
||||
import me.shedaniel.architectury.annotations.ExpectPlatform;
|
||||
import net.minecraft.world.entity.npc.VillagerProfession;
|
||||
import net.minecraft.world.entity.npc.VillagerTrades;
|
||||
|
||||
public class TradeRegistry {
|
||||
private TradeRegistry() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a trade ({@link VillagerTrades.ItemListing}) for a villager by its profession and level.
|
||||
* When the mod loader is Forge, the {@code VillagerTradesEvent} event is used.
|
||||
*
|
||||
* @param profession The Profession the villager needs to have this trade.
|
||||
* @param level The level the villager needs. Vanilla range is 1 to 5, however mods may extend that upper limit further.
|
||||
* @param trades The trades to add to this profession at the specified level.
|
||||
*/
|
||||
public static void registerVillagerTrade(VillagerProfession profession, int level, VillagerTrades.ItemListing... trades) {
|
||||
if (level < 1) {
|
||||
throw new IllegalArgumentException("Villager Trade level has to be at least 1!");
|
||||
}
|
||||
registerVillagerTrade0(profession, level, trades);
|
||||
}
|
||||
|
||||
@ExpectPlatform
|
||||
private static void registerVillagerTrade0(VillagerProfession profession, int level, VillagerTrades.ItemListing... trades) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a trade ({@link VillagerTrades.ItemListing}) to a wandering trader by its rarity.
|
||||
* When the mod loader is Forge, the {@code WandererTradesEvent} event is used.
|
||||
*
|
||||
* @param rare Whether this trade is "rare". Rare trades have a five times lower chance of being used.
|
||||
* @param trades The trades to add to the wandering trader.
|
||||
*/
|
||||
@ExpectPlatform
|
||||
public static void registerTradeForWanderingTrader(boolean rare, VillagerTrades.ItemListing... trades) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -56,5 +56,6 @@ public final class EnvExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
private EnvExecutor() {}
|
||||
private EnvExecutor() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,5 +40,6 @@ public final class NbtType {
|
||||
*/
|
||||
public static final int NUMBER = 99;
|
||||
|
||||
private NbtType() {}
|
||||
private NbtType() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,19 +22,19 @@ package me.shedaniel.architectury.utils;
|
||||
public class PlatformExpectedError extends Error {
|
||||
public PlatformExpectedError() {
|
||||
}
|
||||
|
||||
|
||||
public PlatformExpectedError(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
|
||||
public PlatformExpectedError(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
|
||||
public PlatformExpectedError(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
|
||||
public PlatformExpectedError(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
|
||||
@@ -22,4 +22,5 @@ package me.shedaniel.architectury.utils;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public interface Value<T> extends Supplier<T>, Consumer<T> {}
|
||||
public interface Value<T> extends Supplier<T>, Consumer<T> {
|
||||
}
|
||||
|
||||
@@ -5,7 +5,11 @@
|
||||
"minVersion": "0.7.11",
|
||||
"client": [
|
||||
],
|
||||
"mixins": ["MixinFallingBlockEntity", "FluidTagsAccessor", "MixinLightningBolt"],
|
||||
"mixins": [
|
||||
"MixinFallingBlockEntity",
|
||||
"FluidTagsAccessor",
|
||||
"MixinLightningBolt"
|
||||
],
|
||||
"injectors": {
|
||||
"maxShiftBy": 5,
|
||||
"defaultRequire": 1
|
||||
|
||||
Reference in New Issue
Block a user