Skip to content

Commit

Permalink
Add EnvRestriction And InternalOf Annotations
Browse files Browse the repository at this point in the history
Change AdvancedItemSettings
  • Loading branch information
FirstMegaGame4 committed Dec 5, 2023
1 parent 194ecd1 commit 295a095
Show file tree
Hide file tree
Showing 20 changed files with 121 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.mmodding.mmodding_lib.ducks;

import com.mmodding.mmodding_lib.library.blocks.settings.AdvancedBlockSettings;
import com.mmodding.mmodding_lib.library.utils.InternalOf;
import org.quiltmc.qsl.base.api.util.TriState;

@InternalOf(targets = AdvancedBlockSettings.class)
public interface AbstractBlockSettingsDuckInterface {

TriState mmodding_lib$getTranslucent();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.mmodding.mmodding_lib.ducks;

import com.mmodding.mmodding_lib.library.blockentities.BlockEntityTypeBlockSupportCallback;
import com.mmodding.mmodding_lib.library.utils.InternalOf;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType;
import org.quiltmc.qsl.base.api.event.Event;

@InternalOf(targets = BlockEntityTypeBlockSupportCallback.class)
public interface BlockEntityTypeDuckInterface {

Event<BlockEntityTypeBlockSupportCallback> mmodding_lib$supportBlocksCallback();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.mmodding.mmodding_lib.ducks;

import com.mmodding.mmodding_lib.library.utils.InternalOf;
import com.mmodding.mmodding_lib.library.worldgen.veins.CustomVeinType;
import net.minecraft.util.Holder;
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;

@InternalOf(targets = CustomVeinType.class)
public interface ChunkNoiseSamplerDuckInterface {

Holder<ChunkGeneratorSettings> mmodding_lib$getSettingsHolder();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.mmodding.mmodding_lib.ducks;

import com.mmodding.mmodding_lib.library.stellar.client.StellarObject;
import com.mmodding.mmodding_lib.library.utils.InternalOf;
import com.mmodding.mmodding_lib.states.readable.ReadableStellarStatuses;

@InternalOf(targets = StellarObject.class)
public interface ClientWorldDuckInterface {

ReadableStellarStatuses mmodding_lib$getStellarStatusesAccess();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import com.mmodding.mmodding_lib.library.portals.squared.CustomSquaredPortal;
import com.mmodding.mmodding_lib.library.portals.squared.CustomSquaredPortalBlock;
import com.mmodding.mmodding_lib.library.utils.InternalOf;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

@InternalOf(targets = CustomSquaredPortalBlock.class)
public interface EntityDuckInterface {

boolean mmodding_lib$isInCustomPortal();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.mmodding.mmodding_lib.ducks;

import com.mmodding.mmodding_lib.library.blocks.interactions.data.FallingBlockInteractionData;
import com.mmodding.mmodding_lib.library.utils.InternalOf;
import net.minecraft.block.BlockState;

@InternalOf(targets = FallingBlockInteractionData.class)
public interface FallingBlockEntityDuckInterface {

BlockState mmodding_lib$getInitialBlockState();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.mmodding.mmodding_lib.ducks;

import com.mmodding.mmodding_lib.library.blocks.CustomFluidBlock;
import com.mmodding.mmodding_lib.library.utils.InternalOf;
import net.minecraft.fluid.FluidState;

import java.util.function.IntFunction;

@InternalOf(targets = CustomFluidBlock.class)
public interface FlowableFluidDuckInterface {

void mmodding_lib$putCustomStates(FluidState stillState, IntFunction<FluidState> flowingStates);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.mmodding.mmodding_lib.ducks;

import com.mmodding.mmodding_lib.library.utils.InternalOf;
import com.mmodding.mmodding_lib.states.persistant.DifferedSeeds;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtList;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.World;

@InternalOf(targets = DifferedSeeds.class)
public interface GeneratorOptionsDuckInterface {

void mmodding_lib$fillDimensionSeedAddendsNbt(NbtList list);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.mmodding.mmodding_lib.ducks;

import com.mmodding.mmodding_lib.library.entities.projectiles.StuckArrowDisplay;
import com.mmodding.mmodding_lib.library.utils.InternalOf;
import net.minecraft.util.Identifier;

import java.util.List;

@InternalOf(targets = StuckArrowDisplay.class)
public interface LivingEntityDuckInterface {

List<Identifier> mmodding_lib$getStuckArrowTypes();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.mmodding.mmodding_lib.ducks;

import com.mmodding.mmodding_lib.library.portals.squared.CustomSquaredPortalBlock;
import com.mmodding.mmodding_lib.library.utils.InternalOf;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.WorldAccess;

@InternalOf(targets = CustomSquaredPortalBlock.class)
public interface NetherPortalBlockDuckInterface {

BlockState mmodding_lib$getAbstractStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mmodding.mmodding_lib.ducks;

import com.mmodding.mmodding_lib.library.portals.squared.CustomSquaredPortal;
import com.mmodding.mmodding_lib.library.utils.InternalOf;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.BlockLocating;
Expand All @@ -9,6 +10,7 @@

import java.util.Optional;

@InternalOf(targets = CustomSquaredPortal.class)
public interface PortalForcerDuckInterface {

void mmodding_lib$setUseCustomPortalElements(boolean useCustomPortalElements);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.mmodding.mmodding_lib.ducks;

import com.mmodding.mmodding_lib.library.entities.CustomEntityType;
import com.mmodding.mmodding_lib.library.utils.InternalOf;
import net.minecraft.entity.Entity;

@InternalOf(targets = CustomEntityType.class)
public interface QuiltEntityTypeBuilderDuckInterface<T extends Entity> {

CustomEntityType<T> mmodding_lib$buildCustom();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.mmodding.mmodding_lib.ducks;

import com.mmodding.mmodding_lib.library.portals.squared.CustomSquaredPortal;
import com.mmodding.mmodding_lib.library.utils.InternalOf;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockLocating;
import net.minecraft.world.border.WorldBorder;

import java.util.Optional;

@InternalOf(targets = CustomSquaredPortal.class)
public interface ServerPlayerDuckInterface {

Optional<BlockLocating.Rectangle> mmodding_lib$getCustomPortalRect(ServerWorld destWorld, BlockPos destPos, WorldBorder worldBorder);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.mmodding.mmodding_lib.ducks;

import com.mmodding.mmodding_lib.library.utils.InternalOf;
import com.mmodding.mmodding_lib.states.persistant.StellarStatuses;
import net.minecraft.nbt.NbtCompound;

@InternalOf(targets = StellarStatuses.class)
public interface ServerWorldDuckInterface {

StellarStatuses mmodding_lib$createStellarStatuses();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
import com.mmodding.mmodding_lib.MModdingLib;
import com.mmodding.mmodding_lib.client.MModdingScreen;
import com.mmodding.mmodding_lib.library.config.client.screen.ConfigScreen;
import com.mmodding.mmodding_lib.library.utils.InternalOf;
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
import com.terraformersmc.modmenu.api.ModMenuApi;

import java.util.HashMap;
import java.util.Map;

@InternalOf(targets = ConfigScreen.class)
public class ModMenuApiImpl implements ModMenuApi {

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.mmodding.mmodding_lib.library.glint;

import com.mmodding.mmodding_lib.library.utils.EnvRestriction;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier;

@EnvRestriction(side = EnvRestriction.Side.SERVER_COMMON)
public interface GlintPackView {

static GlintPackView of(ItemStack stack) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@
import net.minecraft.item.FoodComponent;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.Rarity;
import org.quiltmc.qsl.item.setting.api.*;

import java.util.Collections;
import java.util.List;
import java.util.function.Function;

public class AdvancedItemSettings extends QuiltItemSettings {

public static final CustomItemSetting<List<Formatting>> NAME_FORMATTINGS = CustomItemSetting.create(Collections::emptyList);
public static final CustomItemSetting<Text[]> DESCRIPTION_LINES = CustomItemSetting.create(() -> null);
public static final CustomItemSetting<Boolean> GLINT = CustomItemSetting.create(Boolean.FALSE);
public static final CustomItemSetting<Function<ItemStack, Boolean>> GLINT = CustomItemSetting.create((stack) -> false);
public static final CustomItemSetting<GlintPackView> GLINT_PACK = CustomItemSetting.create(() -> null);
public static final CustomItemSetting<Boolean> EATABLE = CustomItemSetting.create(Boolean.FALSE);
public static final CustomItemSetting<Boolean> DRINKABLE = CustomItemSetting.create(Boolean.FALSE);
Expand All @@ -37,8 +39,12 @@ public AdvancedItemSettings descriptionLines(Text... descriptionLines) {
return this.customSetting(DESCRIPTION_LINES, descriptionLines);
}

public AdvancedItemSettings glint() {
return this.customSetting(GLINT, true);
public AdvancedItemSettings glint(boolean glint) {
return this.glint(stack -> glint);
}

public AdvancedItemSettings glint(Function<ItemStack, Boolean> glint) {
return this.customSetting(GLINT, glint);
}

public AdvancedItemSettings glintPack(GlintPackView view) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.mmodding.mmodding_lib.library.utils;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Applies an environment restriction to the element used.
* If the side is not the same as the current one it will crash.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.TYPE_USE, ElementType.FIELD, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.PACKAGE})
public @interface EnvRestriction {

Side side() default Side.COMMON;

enum Side {

/**
* Means that the annotated member should be only used by the client thread.
*/
CLIENT_THREAD,

/**
* Means that the annotated member should be only used on the client side.
*/
CLIENT_COMMON,

/**
* Means that the annotated member can be used an all sides. This is the default value.
*/
COMMON,

/**
* Means that the annotated member should be only used on the server side. (Integrated or Dedicated, we don't really care).
*/
SERVER_COMMON,

/**
* Means that the annotated member should be only used by the server thread.
*/
SERVER_THREAD,

/**
* Means that the annotated member should be only used by an integrated server thread.
*/
INTEGRATED_SERVER_THREAD,

/**
* Means that the annotated member should be only used by a dedicated server thread.
*/
DEDICATED_SERVER_THREAD
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.mmodding.mmodding_lib.library.utils;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* This annotation represents a class, a method or a field which is
*/
@Retention(RetentionPolicy.CLASS)
@Target({ElementType.TYPE, ElementType.TYPE_USE, ElementType.FIELD, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.PACKAGE})
public @interface InternalOf {

Class<?>[] targets();
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public abstract class ItemMixin implements ItemGlintPack, Self<Item> {

@Inject(method = "hasGlint", at = @At("TAIL"), cancellable = true)
private void hasGlint(ItemStack stack, CallbackInfoReturnable<Boolean> cir) {
if (AdvancedItemSettings.GLINT.get(this.getObject())) {
if (AdvancedItemSettings.GLINT.get(this.getObject()).apply(stack)) {
cir.setReturnValue(true);
}
}
Expand Down

0 comments on commit 295a095

Please sign in to comment.