Skip to content

Commit

Permalink
chore: fill in javadoc for many classes
Browse files Browse the repository at this point in the history
  • Loading branch information
CallMeEchoCodes committed Oct 7, 2024
1 parent 806bd0a commit e283669
Show file tree
Hide file tree
Showing 16 changed files with 130 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,78 @@
import net.minecraft.registry.Registries;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.ApiStatus;

public final class BlockMetatags {
/**
* A metatag that specifies that a block is strippable.
*
* @implNote Note that this metatag does not include blocks made strippable by vanilla or blocks that are registered as strippable using {@link net.fabricmc.fabric.api.registry.StrippableBlockRegistry StrippableBlockRegistry}
*/
public static final Metatag<Block, Block> STRIPPABLE = Metatag.builder(
Registries.BLOCK,
Identifier.of(SpecterGlobals.MODID, "strippable"),
Registries.BLOCK.getCodec(),
PacketCodecs.registryValue(RegistryKeys.BLOCK)
).build();

/**
* A metatag that specifies that a block is flattenable.
*
* @implNote This metatag does not include blocks made flattenable by vanilla or blocks that are registered as flattenable using {@link net.fabricmc.fabric.api.registry.FlattenableBlockRegistry FlattenableBlockRegistry}
*/
public static final Metatag<Block, BlockState> FLATTENABLE = Metatag.builder(
Registries.BLOCK,
Identifier.of(SpecterGlobals.MODID, "flattenable"),
BlockState.CODEC,
PacketCodecs.entryOf(Block.STATE_IDS).cast()
).build();

/**
* A metatag that specifies that a block is waxable.
*
* @implNote This metatag does not include blocks made waxable by vanilla or blocks that are registered as waxable using {@link net.fabricmc.fabric.api.registry.OxidizableBlocksRegistry OxidizableBlocksRegistry}
*/
public static final Metatag<Block, Block> WAXABLE = Metatag.builder(
Registries.BLOCK,
Identifier.of(SpecterGlobals.MODID, "waxable"),
Registries.BLOCK.getCodec(),
PacketCodecs.registryValue(RegistryKeys.BLOCK)
).build();

/**
* A metatag that specifies that a block is oxidizable.
*
* @implNote This metatag does not include blocks made oxidizable by vanilla or blocks that are registered as oxidizable using {@link net.fabricmc.fabric.api.registry.OxidizableBlocksRegistry OxidizableBlocksRegistry}
*/
public static final Metatag<Block, Block> OXIDIZABLE = Metatag.builder(
Registries.BLOCK,
Identifier.of(SpecterGlobals.MODID, "oxidizable"),
Registries.BLOCK.getCodec(),
PacketCodecs.registryValue(RegistryKeys.BLOCK)
).build();

/**
* A metatag that specifies the flammability of a block.
*
* @implNote This metatag does not include blocks made flammable by vanilla or blocks that are registered as flammable using {@link net.fabricmc.fabric.api.registry.FlammableBlockRegistry FlammableBlockRegistry}
*/
public static final Metatag<Block, FlammableBlockData> FLAMMABLE = Metatag.builder(
Registries.BLOCK,
Identifier.of(SpecterGlobals.MODID, "flammable"),
FlammableBlockData.CODEC,
FlammableBlockData.PACKET_CODEC
).build();

private BlockMetatags() {
throw new UnsupportedOperationException("Cannot instantiate utility class");
}

/**
* Hacky workaround to force class loading.
*/
@SuppressWarnings("EmptyMethod")
@ApiStatus.Internal
public static void init() {
// NO-OP
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import net.minecraft.network.codec.PacketCodecs;
import org.jetbrains.annotations.Range;

/**
* The flammability data of a block.
*/
public record FlammableBlockData(@Range(from = 0, to = Integer.MAX_VALUE) int burn,
@Range(from = 0, to = Integer.MAX_VALUE) int spread) {
public static final Codec<FlammableBlockData> CODEC = RecordCodecBuilder.create(instance -> instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@
* Simple {@link net.minecraft.inventory.Inventory} implementation.
*/
public interface ImplementedInventory extends Inventory {
/**
* Gets the item list of this inventory.
* Must always return the same instance.
*
* @return The item list of this inventory.
*/
DefaultedList<ItemStack> getItems();

static ImplementedInventory of(DefaultedList<ItemStack> items) {
return () -> items;
}
Expand All @@ -26,6 +18,14 @@ static ImplementedInventory ofSize(int size) {
return of(DefaultedList.ofSize(size, ItemStack.EMPTY));
}

/**
* Gets the item list of this inventory.
*
* @return The item list of this inventory.
* @implSpec Must always return the same instance.
*/
DefaultedList<ItemStack> getItems();

@Override
default int size() {
return getItems().size();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
import net.minecraft.util.math.BlockPos;
import org.jetbrains.annotations.Nullable;

/**
* A simple {@link BlockEntity} with an inventory that is synchronized with the client.
*/
public class InventoryBlockEntity extends BlockEntity implements ImplementedInventory {
protected final DefaultedList<ItemStack> inventory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,24 @@ public boolean isEmpty() {
return ImplementedInventory.super.isEmpty();
}

public ItemStack getStack(int i) {
public ItemStack getStack(int slot) {
this.generateLoot(null);
return ImplementedInventory.super.getStack(i);
return ImplementedInventory.super.getStack(slot);
}

public ItemStack removeStack(int i, int j) {
public ItemStack removeStack(int slot, int amount) {
this.generateLoot(null);
return ImplementedInventory.super.removeStack(i, j);
return ImplementedInventory.super.removeStack(slot, amount);
}

public ItemStack removeStack(int i) {
public ItemStack removeStack(int slot) {
this.generateLoot(null);
return ImplementedInventory.super.removeStack(i);
return ImplementedInventory.super.removeStack(slot);
}

public void setStack(int i, ItemStack itemStack) {
public void setStack(int slot, ItemStack itemStack) {
this.generateLoot(null);
ImplementedInventory.super.setStack(i, itemStack);
ImplementedInventory.super.setStack(slot, itemStack);
}


Expand All @@ -84,18 +84,14 @@ public DefaultedList<ItemStack> getItems() {
@Override
protected void writeNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup registryLookup) {
super.writeNbt(nbt, registryLookup);
if (!this.writeLootTable(nbt)) {
Inventories.writeNbt(nbt, this.inventory, registryLookup);
}
if (!this.writeLootTable(nbt)) Inventories.writeNbt(nbt, this.inventory, registryLookup);
}

@Override
protected void readNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup registryLookup) {
super.readNbt(nbt, registryLookup);
this.clear();
if (!this.readLootTable(nbt)) {
Inventories.readNbt(nbt, this.inventory, registryLookup);
}
if (!this.readLootTable(nbt)) Inventories.readNbt(nbt, this.inventory, registryLookup);
}

@Override
Expand All @@ -111,9 +107,8 @@ protected void readComponents(BlockEntity.ComponentsAccess components) {
@Override
protected void addComponents(ComponentMap.Builder componentMapBuilder) {
super.addComponents(componentMapBuilder);
if (this.lootTable != null) {
if (this.lootTable != null)
componentMapBuilder.add(DataComponentTypes.CONTAINER_LOOT, new ContainerLootComponent(this.lootTable, this.lootTableSeed));
}
}

@SuppressWarnings("deprecation")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ public void onInitialize() {
ServerLifecycleEvents.END_DATA_PACK_RELOAD.register((server, serverResourceManager, success) -> reloadBiMaps());
ServerLifecycleEvents.SERVER_STARTED.register((server) -> reloadBiMaps());
}

// TODO: Find a better way to do this
// Currently it's very incompatible with anything that modifies waxing.
// Ideally, we would do what the fabric api does, but we can't just reimplement it without breaking anything that uses it.

private void reloadBiMaps() {
UNWAXED_TO_WAXED_BLOCKS.clear();
WAXED_TO_UNWAXED_BLOCKS.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.option.KeyBinding;

/**
* Allows for listening to keybind events instead of having to check for pressed keys in the tick event.
*/
public final class ClientKeybindEvents {
private ClientKeybindEvents() {
throw new UnsupportedOperationException("Cannot instantiate utility class");
}

public static Event<KeybindListener> pressed(KeyBinding keybind) {
return ClientKeybindEventsImpl.pressed(keybind);
}

@FunctionalInterface
public interface KeybindListener {
void onKeybind(MinecraftClient client);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@ public static Event<ClientKeybindEvents.KeybindListener> pressed(KeyBinding keyb
}

public static void tick(MinecraftClient client) {
for (Map.Entry<KeyBinding, Event<ClientKeybindEvents.KeybindListener>> entry : EVENTS.entrySet())
while (entry.getKey().wasPressed()) entry.getValue().invoker().onKeybind(client);
}

public enum KeybindEvent {
PRESSED, RELEASED
EVENTS.forEach((key, value) -> {
while (key.wasPressed()) value.invoker().onKeybind(client);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,18 @@ public enum Easing {
else return 1 - (7.5625 * (t -= 2.625F / 2.75F) * t + 0.984375F);
}); // TODO: Make this customizable and clean up the if mess

final Double2DoubleFunction function;

Easing(Double2DoubleFunction function) {
this.function = function;
}

/**
* Creates a polynomial easing function (e.g. t^2, t^3, t^4, etc.)
* Only use this for powers above 5, otherwise use the predefined easing functions
*
* @param power The power of the polynomial
* @return The polynomial easing function
* @apiNote Only use this for powers above 5, otherwise use the predefined easing functions
* @see #QUAD
* @see #CUBIC
* @see #QUART
Expand Down Expand Up @@ -84,12 +90,6 @@ public static Double2DoubleFunction elastic(double amplitude, double period) {
return t -> a * Math.pow(2, -10 * t) * Math.sin((t - s) * (2 * Math.PI) / period) + 1;
}

final Double2DoubleFunction function;

Easing(Double2DoubleFunction function) {
this.function = function;
}

public double in(double t) {
return function.get(t);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public V get(Class<?> clazz) {
.findFirst()
.map(Pair::getSecond)
.orElse(null);

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,34 @@
import net.minecraft.entity.EntityType;
import net.minecraft.registry.Registries;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.ApiStatus;

import static dev.spiritstudios.specter.api.core.SpecterGlobals.MODID;

public final class EntityMetatags {
/**
* A metatag that specifies the default attributes of an entity type.
*
* @implNote If an entity type already has default attributes, then the contents of this metatag will be appended to the existing attributes.
* @apiNote This metatag does not include default attributes set by vanilla or other mods that use the vanilla attribute system.
*/
public static final Metatag<EntityType<?>, DataDefaultAttributeBuilder> DEFAULT_ATTRIBUTES = Metatag.builder(
Registries.ENTITY_TYPE,
Identifier.of(MODID, "default_attributes"),
DataDefaultAttributeBuilder.CODEC,
DataDefaultAttributeBuilder.PACKET_CODEC
).build();

private EntityMetatags() {
throw new UnsupportedOperationException("Cannot instantiate utility class");
}

/**
* Hacky workaround to force class loading.
*/
@SuppressWarnings("EmptyMethod")
@ApiStatus.Internal
public static void init() {
// NO-OP
}

private EntityMetatags() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Internal implementation classes for Specter.
* Do not use these classes directly.
*/
@ApiStatus.Internal
package dev.spiritstudios.specter.impl.entity;

import org.jetbrains.annotations.ApiStatus;
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.spiritstudios.specter.api.serialization;

import com.mojang.datafixers.util.Pair;
import io.netty.buffer.ByteBuf;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.network.codec.PacketCodecs;
Expand All @@ -17,4 +18,14 @@ public static <T extends Enum<T>> PacketCodec<ByteBuf, T> enumPacketCodec(Class<
return values[id];
}, Enum::ordinal);
}

public static <F, S> PacketCodec<ByteBuf, Pair<F, S>> pair(PacketCodec<ByteBuf, F> first, PacketCodec<ByteBuf, S> second) {
return PacketCodec.tuple(
first,
Pair::getFirst,
second,
Pair::getSecond,
Pair::of
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Internal implementation classes for Specter.
* Do not use these classes directly.
*/
@ApiStatus.Internal
package dev.spiritstudios.specter.impl.serialization.format;

import org.jetbrains.annotations.ApiStatus;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Internal implementation classes for Specter.
* Do not use these classes directly.
*/
@ApiStatus.Internal
package dev.spiritstudios.specter.impl.serialization;

import org.jetbrains.annotations.ApiStatus;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Internal implementation classes for Specter.
* Do not use these classes directly.
*/
@ApiStatus.Internal
package dev.spiritstudios.specter.impl.serialization.text;

import org.jetbrains.annotations.ApiStatus;

0 comments on commit e283669

Please sign in to comment.