Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a lot of missing documentation #199

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions buildSrc/src/main/java/cm/tasks/CreateBuildInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import org.gradle.api.tasks.OutputDirectory;
import org.gradle.api.tasks.TaskAction;

/**
* Creates the build info.
*/
public abstract class CreateBuildInfo extends DefaultTask {
@Inject
public CreateBuildInfo() {
Expand Down
3 changes: 3 additions & 0 deletions buildSrc/src/main/java/cm/tasks/CreateRegions.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
import org.gradle.api.tasks.OutputDirectory;
import org.gradle.api.tasks.TaskAction;

/**
* Creates the regions.
*/
public abstract class CreateRegions extends DefaultTask {

@Inject
Expand Down
3 changes: 3 additions & 0 deletions buildSrc/src/main/java/cm/tasks/ModifyJarName.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import org.gradle.api.Project;
import org.gradle.jvm.tasks.Jar;

/**
* Modifies the jar name to include the branch.
*/
public class ModifyJarName implements Plugin<Project> {
@Override
public void apply(Project target) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import net.fabricmc.fabric.api.datagen.v1.provider.FabricLanguageProvider;
import net.minecraft.registry.RegistryWrapper;

/**
* Language provider to generate language files.
*/
public abstract class CookiesLanguageProvider extends FabricLanguageProvider implements TranslationKeys {
protected CookiesLanguageProvider(FabricDataOutput dataOutput, CompletableFuture<RegistryWrapper.WrapperLookup> registryLookup) {
super(dataOutput, registryLookup);
Expand All @@ -21,6 +24,9 @@ protected abstract void generateLocals(
RegistryWrapper.WrapperLookup registryLookup,
CookiesTranslationBuilder translationBuilder);

/**
* Expanded translation builder to allow for easy config value addition.
*/
public interface CookiesTranslationBuilder extends FabricLanguageProvider.TranslationBuilder {

default void addConfig(String key, String name, String tooltip) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint;
import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;

/**
* Datagen entrypoint for the mod.
*/
public class CookiesModDataGen implements DataGeneratorEntrypoint {
@Override
public void onInitializeDataGenerator(FabricDataGenerator generator) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;

/**
* Language provider for english.
*/
public class EnglishLanguageProvider extends CookiesLanguageProvider {
public EnglishLanguageProvider(
FabricDataOutput fabricDataOutput, CompletableFuture<RegistryWrapper.WrapperLookup> registryLookupFuture) {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/codes/cookies/mod/CookiesMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ private void registerKeyBindings() {
});
}

/**
* Opens the hud edit screen.
*/
public static void openHudScreen() {
openScreen(new HudEditScreen());
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/codes/cookies/mod/api/ApiManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
@Slf4j
public class ApiManager {

/**
* User agent to use for the mod.
*/
public static String USER_AGENT;
static CloseableHttpClient CLIENT;
private static boolean isAuthenticated;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

import java.awt.*;

/**
* Config for the mine shaft corpse highlight.
*/
public class ShaftConfig extends Foldable {

public BooleanOption enable = new BooleanOption(TranslationKeys.CONFIG_MINING_SHAFT_ENABLE, true);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package codes.cookies.mod.config.categories.mining.powder;

/**
* Time to wait till the powder tracker pauses.
*/
public enum PauseTime {

TEN_SEC(10), THIRTY_SEC(30), ONE_MIN(60), TWO_MIN(120), FIVE_MIN(300), TEN_MIN(600);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import codes.cookies.mod.config.system.options.EnumCycleOption;
import codes.cookies.mod.features.mining.PowderHud;

/**
* Config for the powder hud element.
*/
public class PowderTrackerHudFoldable extends Foldable {

public static PowderTrackerHudFoldable getConfig() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package codes.cookies.mod.config.categories.mining.powder;

/**
* The way the powder hud tracks mineshafts in.
*/
public enum ShaftTrackingType {

ENTER, FIND
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package codes.cookies.mod.config.categories.mining.powder;

/**
* Time to wait after last powder gain till removal and reset of the powder tracker.
*/
public enum TimeoutTime {

ONE_MIN(1), TWO_MINE(2), FIVE_MIN(5), TEN_MIN(10), TWENTY_MIN(20);
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/codes/cookies/mod/config/data/CodecData.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import com.mojang.serialization.Codec;
import org.slf4j.Logger;

/**
* Misc data that has a codec representation.
* @param <T>
*/
public class CodecData<T> implements CodecJsonSerializable<T> {
public CodecData(T defaultValue, Codec<T> codec) {
this.value = defaultValue;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/codes/cookies/mod/config/data/HudData.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

import net.minecraft.util.Identifier;

/**
* Parent element that contains all hud data.
*/
public class HudData implements CodecJsonSerializable<Map<Identifier, HudPosition>> {

private static final Codec<Map<Identifier, HudPosition>> CODEC = Codec.unboundedMap(Identifier.CODEC, HudPosition.CODEC);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@

import net.minecraft.util.Uuids;

/**
* Data that is stored in the config for the squeaky mousemat overlay.
* @param useProfileData A list of uuids where the profile data is used.
* @param data The squeaky mousemat data.
*/
public record SqueakyMousematOption(List<UUID> useProfileData, SqueakyMousematData data) {

public static final Codec<SqueakyMousematOption> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/codes/cookies/mod/config/system/HudSetting.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Used to attach an option to a hud element.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@Repeatable(HudSetting.HudSettings.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,18 @@ public <T, O extends Option<T, O>> ProcessedOption<T, O> processOption(Option<T,
return processedOption;
}

/**
* Adds a hud setting with the processed option.
*/
public <T, O extends Option<T, O>> void addHudSetting(Class<? extends HudElement> value, ProcessedOption<T, O> processedOption) {
final List<Option<?, ?>> orDefault = hudSettings.getOrDefault(value, new ArrayList<>());
hudSettings.putIfAbsent(value, orDefault);
orDefault.add(processedOption.getOption());
}

/**
* Gets all hud settings attached to the element.
*/
public List<Option<?, ?>> getHudSettings(HudElement hudElement) {
return hudSettings.getOrDefault(hudElement.getClass(), Collections.emptyList());
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/codes/cookies/mod/data/Migration.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public interface Migration<T> {
Type getType();

/**
* Whether this migration may fail without causing a data reset.
* @return Whether this migration may fail without causing a data reset.
*/
default boolean mayFail() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;

/**
* Data for the squeaky mousemat overlay.
*/
public record SqueakyMousematData(SqueakyMousematEntry wheat, SqueakyMousematEntry carrot, SqueakyMousematEntry potato,
SqueakyMousematEntry netherWart, SqueakyMousematEntry pumpkin,
SqueakyMousematEntry melon, SqueakyMousematEntry cocoaBeans,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import lombok.Setter;
import lombok.ToString;

/**
* Entry for the squeaky mousemat overlay.
*/
@AllArgsConstructor
@Getter
@Setter
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/codes/cookies/mod/data/mining/PowderData.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import com.mojang.serialization.Codec;
import org.slf4j.Logger;

/**
* The data that is saved about the players powder.
*/
public class PowderData implements CodecJsonSerializable<Map<PowderType, Integer>> {

public static final Codec<Map<PowderType, Integer>> CODEC = Codec.unboundedMap(PowderType.CODEC, Codec.INT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public ItemCompound(int amount, ItemStack itemStack, Set<Item<?>> items) {
this.handleAny(items.iterator().next());
}

/**
* Adds an item of unknown type.
* @param item The item to handle.
*/
public void handleAny(Item<?> item) {
if (this.type == CompoundType.MULTIPLE) {
return;
Expand Down Expand Up @@ -98,6 +102,10 @@ private void handleStorage(Item<?> item) {
this.data = Unit.INSTANCE;
}

/**
* Adds an item to the compound.
* @param item The item to add.
*/
public void add(Item<?> item) {
if (item.source() == ItemSources.CRAFTABLE) {
return;
Expand All @@ -123,6 +131,10 @@ public Set<Item<?>> items() {
return this.items;
}

/**
* Get all items used by craft helper or in total if craft helper is irrelevant.
* @return The items.
*/
public Set<Item<?>> getUsedItems() {
if (this.type == CompoundType.CRAFTABLE && this.data instanceof CraftableItemSource.Data craftData) {
return craftData.amounts()
Expand Down Expand Up @@ -167,6 +179,9 @@ public String toString() {
this.items + ']';
}

/**
* The type of the compound.
*/
public enum CompoundType {
CHEST_POS,
CHEST,
Expand Down Expand Up @@ -214,6 +229,4 @@ public static CompoundType of(ItemSources source, Object data) {
};
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,9 @@ public interface ItemSource<T> {
*/
ItemSources getType();

/**
* Removes the item from the item source.
* @param item The item to remove.
*/
void remove(Item<?> item);
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void remove(Item<?> item) {

ProfileStorage.getCurrentProfile()
.map(ProfileData::getForgeTracker)
.map(FunctionUtils.function(ForgeTracker::remove))
.map(FunctionUtils.function(ForgeTracker::removeItem))
.orElseGet(FunctionUtils::noOp)
.accept(data.slot());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import com.google.gson.JsonObject;
import codes.cookies.mod.data.Migration;

/**
* Moves the current craft helper item to the new version.
*/
public class ProfileDataMigration_0002 implements Migration<JsonObject> {
@Override
public int getNumber() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import java.util.List;
import java.util.Optional;

import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import codes.cookies.mod.events.ChestSaveEvent;
import codes.cookies.mod.utils.json.CodecJsonSerializable;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import lombok.Getter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -27,24 +27,34 @@ public class IslandChestStorage implements CodecJsonSerializable<List<IslandChes
private static final Logger LOGGER = LoggerFactory.getLogger(IslandChestStorage.class);
private final List<ChestItem> items = new ArrayList<>();

/**
* Saves a stack for the chest in the provided slot.
*/
public void save(BlockPos blockPos, BlockPos secondChest, ItemStack stack, int slot) {
Optional.ofNullable(ChestItem.create(blockPos, secondChest, stack, slot))
.ifPresent(items::add);
}

/**
* @return All items that are present within the block.
*/
private List<ChestItem> getItems(BlockPos pos) {
return this.items.stream().filter(chestItem -> pos.equals(chestItem.blockPos))
.toList();
}

public void removeBlockSlot(BlockPos blockPos, int slot) {
this.items.removeIf(item -> blockPos.equals(item.blockPos) && item.slot == slot);
}

/**
* @param chestItem The item to remove.
*/
public void remove(ChestItem chestItem) {
this.items.remove(chestItem);
}

/**
* Removes all items related to the chest position.
*
* @param blockPos The position to remove.
*/
public void removeBlock(BlockPos blockPos) {
if (blockPos == null) {
return;
Expand Down Expand Up @@ -88,6 +98,9 @@ public Logger getLogger() {
return LOGGER;
}

/**
* Sends a chest save event for the provided blocks
*/
public void sendEvent(BlockPos blockPos, BlockPos second) {
if (blockPos != null && second != null) {
final ArrayList<ChestItem> bothItems = new ArrayList<>();
Expand All @@ -97,7 +110,7 @@ public void sendEvent(BlockPos blockPos, BlockPos second) {
return;
}
if (blockPos != null) {
ChestSaveEvent.EVENT.invoker().onSave(blockPos, second,this.getItems(blockPos));
ChestSaveEvent.EVENT.invoker().onSave(blockPos, second, this.getItems(blockPos));
}
}

Expand Down
Loading
Loading