Skip to content

Commit

Permalink
feat: expose fluid rendering api
Browse files Browse the repository at this point in the history
standardize tooltips
redstone activation -> redstone mode (shorter)
improve localization of numbers
  • Loading branch information
marcus8448 committed Jan 13, 2024
1 parent b609d6f commit 81ae4cb
Show file tree
Hide file tree
Showing 20 changed files with 194 additions and 212 deletions.
14 changes: 8 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ val fabric = project.property("fabric.version").toString()
plugins {
java
`maven-publish`
id("fabric-loom") version("1.4-SNAPSHOT")
id("fabric-loom") version("1.5-SNAPSHOT")
id("org.cadixdev.licenser") version("0.6.1")
id("org.ajoberstar.grgit") version("5.2.1")
}
Expand Down Expand Up @@ -108,13 +108,13 @@ loom {
getByName("client") {
name("Minecraft Client")
source(sourceSets.getByName("testmod"))
vmArgs("-ea", "-Dfabric-api.gametest", "-Dfabric-api.gametest.report-file=${project.layout.buildDirectory}/junit.xml")
property("fabric-api.gametest")
}
register("gametest") {
name("GameTest Server")
server()
source(sourceSets.getByName("testmod"))
vmArgs("-ea", "-Dfabric-api.gametest", "-Dfabric-api.gametest.report-file=${project.layout.buildDirectory}/junit.xml")
property("fabric-api.gametest")
}
}
}
Expand All @@ -134,11 +134,13 @@ repositories {

dependencies {
minecraft("com.mojang:minecraft:$minecraft")
mappings(loom.layered {
officialMojangMappings()
if (!parchment.isEmpty()) {
mappings(if (parchment.isNotEmpty()) {
loom.layered {
officialMojangMappings()
parchment("org.parchmentmc.data:parchment-$minecraft:$parchment@zip")
}
} else {
loom.officialMojangMappings()
})
modImplementation("net.fabricmc:fabric-loader:$loader")
testImplementation("net.fabricmc:fabric-loader-junit:$loader")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import com.mojang.authlib.GameProfile;
import dev.galacticraft.machinelib.api.block.entity.MachineBlockEntity;
import dev.galacticraft.machinelib.api.machine.configuration.AccessLevel;
import dev.galacticraft.machinelib.api.machine.configuration.RedstoneActivation;
import dev.galacticraft.machinelib.api.machine.configuration.RedstoneMode;
import dev.galacticraft.machinelib.api.machine.configuration.SecuritySettings;
import dev.galacticraft.machinelib.api.storage.MachineItemStorage;
import dev.galacticraft.machinelib.api.storage.slot.ItemResourceSlot;
Expand Down Expand Up @@ -231,8 +231,8 @@ public void appendHoverText(ItemStack stack, BlockGetter view, List<Component> t
}
}

if (nbt.contains(Constant.Nbt.REDSTONE_ACTIVATION, Tag.TAG_BYTE)) {
tooltip.add(Component.translatable(Constant.TranslationKey.REDSTONE_ACTIVATION, RedstoneActivation.readTag((ByteTag) Objects.requireNonNull(nbt.get(Constant.Nbt.REDSTONE_ACTIVATION))).getName()).setStyle(Constant.Text.DARK_RED_STYLE));
if (nbt.contains(Constant.Nbt.REDSTONE_MODE, Tag.TAG_BYTE)) {
tooltip.add(Component.translatable(Constant.TranslationKey.REDSTONE_MODE, RedstoneMode.readTag((ByteTag) Objects.requireNonNull(nbt.get(Constant.Nbt.REDSTONE_MODE))).getName()).setStyle(Constant.Text.DARK_RED_STYLE));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import dev.galacticraft.machinelib.api.machine.MachineType;
import dev.galacticraft.machinelib.api.machine.configuration.MachineConfiguration;
import dev.galacticraft.machinelib.api.machine.configuration.MachineIOConfig;
import dev.galacticraft.machinelib.api.machine.configuration.RedstoneActivation;
import dev.galacticraft.machinelib.api.machine.configuration.RedstoneMode;
import dev.galacticraft.machinelib.api.machine.configuration.SecuritySettings;
import dev.galacticraft.machinelib.api.menu.MachineMenu;
import dev.galacticraft.machinelib.api.misc.AdjacentBlockApiCache;
Expand Down Expand Up @@ -106,7 +106,7 @@ public abstract class MachineBlockEntity extends BlockEntity implements Extended

/**
* The configuration for this machine.
* This is used to store the {@link #getRedstoneActivation() redstone activation}, {@link #getIOConfig() I/O configuration},
* This is used to store the {@link #getRedstoneMode() redstone mode}, {@link #getIOConfig() I/O configuration},
* and {@link #getSecurity() security} settings for this machine.
*
* @see MachineConfiguration
Expand Down Expand Up @@ -284,14 +284,14 @@ public long getEnergyItemExtractionRate() {
}

/**
* Sets the redstone activation mode of this machine.
* Sets the redstone mode mode of this machine.
*
* @param redstone the redstone activation mode to use.
* @see #getRedstoneActivation()
* @param redstone the redstone mode mode to use.
* @see #getRedstoneMode()
*/
@Contract(mutates = "this")
public void setRedstone(@NotNull RedstoneActivation redstone) {
this.configuration.setRedstoneActivation(redstone);
public void setRedstone(@NotNull RedstoneMode redstone) {
this.configuration.setRedstoneMode(redstone);
}

/**
Expand Down Expand Up @@ -344,12 +344,12 @@ public void setRedstone(@NotNull RedstoneActivation redstone) {
* Dictates how this machine should react to redstone.
*
* @return how the machine reacts when it interacts with redstone.
* @see RedstoneActivation
* @see #setRedstone(RedstoneActivation)
* @see RedstoneMode
* @see #setRedstone(RedstoneMode)
*/
@Contract(pure = true)
public final @NotNull RedstoneActivation getRedstoneActivation() {
return this.configuration.getRedstoneActivation();
public final @NotNull RedstoneMode getRedstoneMode() {
return this.configuration.getRedstoneMode();
}

/**
Expand Down Expand Up @@ -396,11 +396,11 @@ public boolean areDropsDisabled() {
* Returns whether the current machine is enabled.
*
* @return whether the current machine is enabled.
* @see RedstoneActivation
* @see #getRedstoneActivation()
* @see RedstoneMode
* @see #getRedstoneMode()
*/
public boolean isDisabled() {
return !this.getRedstoneActivation().isActive(this.state.isPowered());
return !this.getRedstoneMode().isActive(this.state.isPowered());
}

/**
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ static Config create() {

long bucketBreakpoint();

long megaGjBreakpoint();

void copyFrom(Config config);

@ApiStatus.Internal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

package dev.galacticraft.machinelib.api.machine;

import dev.galacticraft.machinelib.api.machine.configuration.RedstoneActivation;
import dev.galacticraft.machinelib.api.machine.configuration.RedstoneMode;
import dev.galacticraft.machinelib.api.menu.sync.MenuSynchronizable;
import dev.galacticraft.machinelib.api.misc.Deserializable;
import dev.galacticraft.machinelib.impl.machine.MachineStateImpl;
Expand Down Expand Up @@ -57,7 +57,7 @@ public interface MachineState extends MenuSynchronizable, Deserializable<Compoun
*
* @return the current status of the machine.
*/
@NotNull Component getStatusText(@NotNull RedstoneActivation activation);
@NotNull Component getStatusText(@NotNull RedstoneMode activation);

/**
* Sets the status of the machine.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,18 @@ public interface MachineConfiguration extends Deserializable<CompoundTag>, MenuS
@NotNull SecuritySettings getSecurity();

/**
* Returns the redstone activation of the machine.
* Returns the redstone mode of the machine.
*
* @return The redstone activation of the machine.
* @return The redstone mode of the machine.
*/
@Contract(pure = true)
@NotNull RedstoneActivation getRedstoneActivation();
@NotNull RedstoneMode getRedstoneMode();

/**
* Sets the redstone activation of the machine.
* Sets the redstone mode of the machine.
*
* @param redstone The redstone activation of the machine.
* @param redstone The redstone mode of the machine.
*/
@Contract(mutates = "this")
void setRedstoneActivation(@NotNull RedstoneActivation redstone);
void setRedstoneMode(@NotNull RedstoneMode redstone);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
/**
* Dictates how a machine behaves when it interacts with redstone.
*/
public enum RedstoneActivation implements StringRepresentable {
public enum RedstoneMode implements StringRepresentable {
/**
* Ignores redstone entirely (always running).
*/
Expand All @@ -49,20 +49,20 @@ public enum RedstoneActivation implements StringRepresentable {
*/
HIGH(Component.translatable(Constant.TranslationKey.HIGH_REDSTONE).setStyle(Constant.Text.RED_STYLE));

public static final RedstoneActivation[] VALUES = RedstoneActivation.values();
public static final RedstoneMode[] VALUES = RedstoneMode.values();

/**
* The text of the redstone activation state.
* The text of the redstone mode state.
*/
private final @NotNull Component name;

/**
* Constructs a redstone activation type with the given text.
* Constructs a redstone mode type with the given text.
*
* @param name the name of the interaction.
*/
@Contract(pure = true)
RedstoneActivation(@NotNull Component name) {
RedstoneMode(@NotNull Component name) {
this.name = name;
}

Expand All @@ -75,30 +75,30 @@ public boolean isActive(boolean powered) {
}

/**
* Deserializes an activation state from NBT.
* Deserializes an redstone mode from NBT.
*
* @param tag the NBT.
* @return the activation state.
* @return the redstone mode.
* @see #createTag()
*/
public static @NotNull RedstoneActivation readTag(@NotNull ByteTag tag) {
public static @NotNull RedstoneMode readTag(@NotNull ByteTag tag) {
return VALUES[tag.getAsByte()];
}

/**
* Deserializes an activation state from a packet.
* Deserializes an redstone mode from a packet.
* @param buf the buffer to read from
* @return the activation state
* @return the redstone mode
* @see #writePacket(FriendlyByteBuf)
*/
public static @NotNull RedstoneActivation readPacket(@NotNull FriendlyByteBuf buf) {
public static @NotNull RedstoneMode readPacket(@NotNull FriendlyByteBuf buf) {
return VALUES[buf.readByte()];
}

/**
* Returns the name of the redstone activation state.
* Returns the name of the redstone mode state.
*
* @return The text of the redstone activation state.
* @return The text of the redstone mode state.
*/
@Contract(pure = true)
public @NotNull Component getName() {
Expand All @@ -117,7 +117,7 @@ public boolean isActive(boolean powered) {

/**
* Serializes this state as a NBT.
* @return this activation state as a tag.
* @return this redstone mode as a tag.
* @see #readTag(ByteTag)
*/
public @NotNull ByteTag createTag() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,30 @@ private StorageHelper() {
throw new UnsupportedOperationException("Utility class cannot be instantiated");
}

public static <Resource, Variant extends TransferVariant<Resource>, S extends Storage<Variant>> long calculateCapacity(Variant variant, @NotNull S storage, @Nullable TransactionContext context) {
if (variant.isBlank()) return 0;

long capacity = 0;
for (StorageView<Variant> view : storage) {
if (variant.equals(view.getResource())) {
capacity += view.getCapacity();
}
}
return capacity;
}

public static <Resource, Variant extends TransferVariant<Resource>, S extends Storage<Variant>> long calculateAmount(Variant variant, @NotNull S storage, @Nullable TransactionContext context) {
if (variant.isBlank()) return 0;

long amount = 0;
for (StorageView<Variant> view : storage) {
if (variant.equals(view.getResource())) {
amount += view.getAmount();
}
}
return amount;
}

public static <Resource, Variant extends TransferVariant<Resource>, S extends Storage<Variant>> long move(Variant variant, @Nullable StorageAccess<Resource> from, @Nullable S to, long maxAmount, @Nullable TransactionContext context) {
if (from == null || to == null || variant.isBlank() || maxAmount == 0) return 0;
StoragePreconditions.notNegative(maxAmount);
Expand Down Expand Up @@ -193,4 +217,6 @@ public static <Resource, Variant extends TransferVariant<Resource>, S extends St
}
return changed;
}

public record StorageContents(long amount, long capacity) {}
}
Loading

0 comments on commit 81ae4cb

Please sign in to comment.