diff --git a/build.gradle b/build.gradle index e53d31b..ab59013 100644 --- a/build.gradle +++ b/build.gradle @@ -132,6 +132,16 @@ repositories { includeGroup "dev.latvian.mods" } } + + maven { + // K4Unl's Maven (AE2) + url = "https://modmaven.dev" + content { + includeGroup 'appeng' + } + } + + // AE2Things repo is in settings.gradle } dependencies { @@ -157,6 +167,12 @@ dependencies { // Gson implementation 'com.google.code.gson:gson:2.10.1' + // AE2 + compileOnly "appeng:appliedenergistics2-forge:${appeng_version}" + + // AE2 Things + compileOnly "dev.technici4n:AE2-Things:${ae2things_version}" + // Mixin annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' } diff --git a/gradle.properties b/gradle.properties index 86c98b2..8841c4b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,4 +11,6 @@ quark_id = 4812006 quarkOddities_id = 3575623 kubejs_version = 1902.6.2-build.45 rhino_version = 1902.2.3-build.284 -architectury_version = 6.5.85 \ No newline at end of file +architectury_version = 6.5.85 +appeng_version = 12.9.8 +ae2things_version=1.1.1 \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 3703f36..1a4763e 100644 --- a/settings.gradle +++ b/settings.gradle @@ -3,4 +3,10 @@ pluginManagement { gradlePluginPortal() maven { url = 'https://maven.minecraftforge.net/' } } +} + +sourceControl { + gitRepository(URI.create("https://github.com/Technici4n/AE2Things-Forge.git")) { + producesModule("dev.technici4n:AE2-Things") + } } \ No newline at end of file diff --git a/src/main/java/com/kikis/ptdyeplus/appeng/CellUtil.java b/src/main/java/com/kikis/ptdyeplus/appeng/CellUtil.java new file mode 100644 index 0000000..5aaa37f --- /dev/null +++ b/src/main/java/com/kikis/ptdyeplus/appeng/CellUtil.java @@ -0,0 +1,25 @@ +package com.kikis.ptdyeplus.appeng; + +import appeng.api.client.StorageCellModels; +import appeng.api.stacks.AEKeyType; +import com.google.common.base.Preconditions; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.Item; +import net.minecraftforge.registries.ForgeRegistries; + +public final class CellUtil { + public static void registerCell(Item.Properties itemProperties, ResourceLocation itemLocation, ResourceLocation textureLocation, AEKeyType keyType, int bytes, int bytesPerType, int types, double drain) { + Preconditions.checkArgument(types > 0 && types < 64, "Type count must be between 1 and 63"); + Preconditions.checkArgument(bytes > 7 && bytes % 8 == 0, "Bytes must be a positive non-zero multiple of 8"); + var cell = new SimpleStorageCell(itemProperties, drain, bytes, types, bytesPerType, keyType); + ForgeRegistries.ITEMS.register(itemLocation, cell); + StorageCellModels.registerModel(cell, textureLocation); + } + + public static void registerDisk(Item.Properties itemProperties, ResourceLocation itemLocation, ResourceLocation textureLocation, AEKeyType keyType, int bytes, double drain) { + Preconditions.checkArgument(bytes > 7 && bytes % 8 == 0, "Bytes must be a positive non-zero multiple of 8"); + var cell = new SimpleDiskCell(itemProperties, drain, bytes, keyType); + ForgeRegistries.ITEMS.register(itemLocation, cell); + StorageCellModels.registerModel(cell, textureLocation); + } +} diff --git a/src/main/java/com/kikis/ptdyeplus/appeng/ICommonCellItem.java b/src/main/java/com/kikis/ptdyeplus/appeng/ICommonCellItem.java new file mode 100644 index 0000000..d8b75ab --- /dev/null +++ b/src/main/java/com/kikis/ptdyeplus/appeng/ICommonCellItem.java @@ -0,0 +1,14 @@ +package com.kikis.ptdyeplus.appeng; + +import appeng.api.stacks.AEKeyType; +import appeng.api.storage.cells.ICellWorkbenchItem; +import net.minecraft.world.item.ItemStack; + +// Shared non-default definitions between IDiskCellItem and IBasicCellItem +public interface ICommonCellItem extends ICellWorkbenchItem { + AEKeyType _getKeyType(); + + int _getBytes(ItemStack is); + + double _getIdleDrain(); +} \ No newline at end of file diff --git a/src/main/java/com/kikis/ptdyeplus/appeng/SimpleCellItem.java b/src/main/java/com/kikis/ptdyeplus/appeng/SimpleCellItem.java new file mode 100644 index 0000000..2974d16 --- /dev/null +++ b/src/main/java/com/kikis/ptdyeplus/appeng/SimpleCellItem.java @@ -0,0 +1,48 @@ +package com.kikis.ptdyeplus.appeng; + +import appeng.api.config.FuzzyMode; +import appeng.api.stacks.AEKeyType; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; + +public class SimpleCellItem extends Item implements ICommonCellItem { + protected final double powerCost; + protected final int capacity; + private final AEKeyType keyType; + + @Override + public AEKeyType _getKeyType() { return keyType; } + + @Override + public int _getBytes(ItemStack itemStack) { return this.capacity; } + + @Override + public double _getIdleDrain() { return powerCost; } + + @Override + public FuzzyMode getFuzzyMode(ItemStack itemStack) { + // clone of: https://github.com/AppliedEnergistics/Applied-Energistics-2/blob/137cb538538b7ef9c66261931f662182ddf937b4/src/main/java/appeng/items/storage/BasicStorageCell.java#L133 + final String fz = itemStack.getOrCreateTag().getString("FuzzyMode"); + if (fz.isEmpty()) { + return FuzzyMode.IGNORE_ALL; + } + try { + return FuzzyMode.valueOf(fz); + } catch (Throwable t) { + return FuzzyMode.IGNORE_ALL; + } + } + + @Override + public void setFuzzyMode(ItemStack itemStack, FuzzyMode fuzzyMode) { + // clone of: https://github.com/AppliedEnergistics/Applied-Energistics-2/blob/137cb538538b7ef9c66261931f662182ddf937b4/src/main/java/appeng/items/storage/BasicStorageCell.java#L145 + itemStack.getOrCreateTag().putString("FuzzyMode", fuzzyMode.name()); + } + + public SimpleCellItem(Properties properties, double drain, int bytes, AEKeyType keyType) { + super(properties); + this.powerCost = drain; + this.capacity = bytes; + this.keyType = keyType; + } +} \ No newline at end of file diff --git a/src/main/java/com/kikis/ptdyeplus/appeng/SimpleDiskCell.java b/src/main/java/com/kikis/ptdyeplus/appeng/SimpleDiskCell.java new file mode 100644 index 0000000..6bfb765 --- /dev/null +++ b/src/main/java/com/kikis/ptdyeplus/appeng/SimpleDiskCell.java @@ -0,0 +1,29 @@ +package com.kikis.ptdyeplus.appeng; + +import appeng.api.stacks.AEKeyType; +import appeng.items.contents.CellConfig; +import appeng.util.ConfigInventory; +import io.github.projectet.ae2things.storage.IDISKCellItem; +import net.minecraft.world.item.ItemStack; + + +public class SimpleDiskCell extends SimpleCellItem implements IDISKCellItem { + @Override + public AEKeyType getKeyType() { return _getKeyType(); } + + @Override + public int getBytes(ItemStack is) { return _getBytes(is); } + + @Override + public double getIdleDrain() { return _getIdleDrain(); } + + @Override + public ConfigInventory getConfigInventory(ItemStack is) { + // clone of: https://github.com/Technici4n/AE2Things-Forge/blob/57d1ee0338e970cdd72387037aa44d1f9b0c7c6c/src/main/java/io/github/projectet/ae2things/item/DISKDrive.java#L72C12-L72C12 + return CellConfig.create(getKeyType().filter(), is); + } + + public SimpleDiskCell(Properties properties, double drain, int bytes, AEKeyType keyType) { + super(properties, drain, bytes, keyType); + } +} diff --git a/src/main/java/com/kikis/ptdyeplus/appeng/SimpleStorageCell.java b/src/main/java/com/kikis/ptdyeplus/appeng/SimpleStorageCell.java new file mode 100644 index 0000000..409afed --- /dev/null +++ b/src/main/java/com/kikis/ptdyeplus/appeng/SimpleStorageCell.java @@ -0,0 +1,31 @@ +package com.kikis.ptdyeplus.appeng; + +import appeng.api.stacks.AEKeyType; +import appeng.api.storage.cells.IBasicCellItem; +import net.minecraft.world.item.ItemStack; + +public class SimpleStorageCell extends SimpleCellItem implements IBasicCellItem { + protected final int types; + protected final int bytesPerType; + + @Override + public AEKeyType getKeyType() { return _getKeyType(); } + + @Override + public int getBytes(ItemStack is) { return _getBytes(is); } + + @Override + public int getBytesPerType(ItemStack is) { return bytesPerType; } + + @Override + public int getTotalTypes(ItemStack cellItem) { return types; } + + @Override + public double getIdleDrain() { return _getIdleDrain(); } + + public SimpleStorageCell(Properties properties, double drain, int bytes, int types, int bytesPerType, AEKeyType keyType) { + super(properties, drain, bytes, keyType); + this.types = types; + this.bytesPerType = bytesPerType; + } +} \ No newline at end of file diff --git a/src/main/java/com/kikis/ptdyeplus/kubejs/BaseBindings.java b/src/main/java/com/kikis/ptdyeplus/kubejs/BaseBindings.java deleted file mode 100644 index 711a960..0000000 --- a/src/main/java/com/kikis/ptdyeplus/kubejs/BaseBindings.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.kikis.ptdyeplus.kubejs; - -public interface BaseBindings { - Utils utils = new Utils(); -} \ No newline at end of file diff --git a/src/main/java/com/kikis/ptdyeplus/kubejs/PtdyeJS.java b/src/main/java/com/kikis/ptdyeplus/kubejs/PtdyeJS.java index a553353..6d2da4b 100644 --- a/src/main/java/com/kikis/ptdyeplus/kubejs/PtdyeJS.java +++ b/src/main/java/com/kikis/ptdyeplus/kubejs/PtdyeJS.java @@ -20,11 +20,11 @@ public void initStartup() { @Override public void registerEvents() { - GROUP.register(); + PtdyeEvents.GROUP.register(); } @Override public void registerBindings(BindingsEvent event) { - event.add("Ptdye", BaseBindings.class); + event.add("Ptdye", PtdyeBindings.class); } } \ No newline at end of file diff --git a/src/main/java/com/kikis/ptdyeplus/kubejs/bindings/AppengBindings.java b/src/main/java/com/kikis/ptdyeplus/kubejs/bindings/AppengBindings.java new file mode 100644 index 0000000..2665203 --- /dev/null +++ b/src/main/java/com/kikis/ptdyeplus/kubejs/bindings/AppengBindings.java @@ -0,0 +1,6 @@ +package com.kikis.ptdyeplus.kubejs.bindings; + +@SuppressWarnings("unused") +public final class AppengBindings { + public final CellUtilJS cells = new CellUtilJS(); +} diff --git a/src/main/java/com/kikis/ptdyeplus/kubejs/bindings/CellUtilJS.java b/src/main/java/com/kikis/ptdyeplus/kubejs/bindings/CellUtilJS.java new file mode 100644 index 0000000..75327d8 --- /dev/null +++ b/src/main/java/com/kikis/ptdyeplus/kubejs/bindings/CellUtilJS.java @@ -0,0 +1,41 @@ +package com.kikis.ptdyeplus.kubejs.bindings; + + +import appeng.api.client.StorageCellModels; +import appeng.api.stacks.AEKeyType; +import appeng.api.stacks.AEKeyTypes; +import com.kikis.ptdyeplus.appeng.CellUtil; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.Item; + +import javax.annotation.Nullable; + +@SuppressWarnings("unused") +public final class CellUtilJS { + + public void registerItemCell(ResourceLocation id, Item.Properties properties, @Nullable ResourceLocation cellTexture, int typeCount, int byteCount, int bytesPerType, double powerDrain) { + CellUtil.registerCell(properties, id, textureOrDefault(cellTexture), AEKeyType.items(), byteCount, bytesPerType, typeCount, powerDrain); + } + + public void registerFluidCell(ResourceLocation id, Item.Properties properties, @Nullable ResourceLocation cellTexture, int typeCount, int byteCount, int bytesPerType, double powerDrain) { + CellUtil.registerCell(properties, id, textureOrDefault(cellTexture), AEKeyType.fluids(), byteCount, bytesPerType, typeCount, powerDrain); + } + + public void registerCell(ResourceLocation id, Item.Properties properties, @Nullable ResourceLocation cellTexture, ResourceLocation keyType, int typeCount, int byteCount, int bytesPerType, double powerDrain) { + CellUtil.registerCell(properties, id, textureOrDefault(cellTexture), AEKeyTypes.get(keyType), byteCount, bytesPerType, typeCount, powerDrain); + } + + public void registerItemDisk(ResourceLocation id, Item.Properties properties, @Nullable ResourceLocation cellTexture, int byteCount, int powerDrain) { + CellUtil.registerDisk(properties, id, textureOrDefault(cellTexture), AEKeyType.items(), byteCount, powerDrain); + } + + public void registerFluidDisk(ResourceLocation id, Item.Properties properties, @Nullable ResourceLocation cellTexture, int byteCount, int powerDrain) { + CellUtil.registerDisk(properties, id, textureOrDefault(cellTexture), AEKeyType.fluids(), byteCount, powerDrain); + } + + public void registerDisk(ResourceLocation id, Item.Properties properties, @Nullable ResourceLocation cellTexture, ResourceLocation keyType, int byteCount, int powerDrain) { + CellUtil.registerDisk(properties, id, textureOrDefault(cellTexture), AEKeyTypes.get(keyType), byteCount, powerDrain); + } + + private ResourceLocation textureOrDefault(@Nullable ResourceLocation cellTexture) { return cellTexture != null ? cellTexture : StorageCellModels.getDefaultModel(); } +} diff --git a/src/main/java/com/kikis/ptdyeplus/kubejs/bindings/KeyUtilJS.java b/src/main/java/com/kikis/ptdyeplus/kubejs/bindings/KeyUtilJS.java new file mode 100644 index 0000000..ba72d89 --- /dev/null +++ b/src/main/java/com/kikis/ptdyeplus/kubejs/bindings/KeyUtilJS.java @@ -0,0 +1,43 @@ +package com.kikis.ptdyeplus.kubejs.bindings; + +import com.mojang.blaze3d.platform.InputConstants; +import net.minecraft.client.KeyMapping; +import net.minecraft.client.Minecraft; +import net.minecraft.locale.Language; + +import java.util.Arrays; +import java.util.Map; +import java.util.stream.Collectors; + +public final class KeyUtilJS { + + /** + * Get key by key code + * @param keyCode example: "key.forward" + * @return the key or "key-not-found" + */ + public String getKey(String keyCode) throws java.lang.IllegalStateException { + return getKeyMappings().getOrDefault(keyCode, "key-not-found"); + } + + private static Map getKeyMappings() { + return Arrays.stream(Minecraft.getInstance().options.keyMappings).collect(Collectors.toMap(KeyMapping::getName, km -> getKeyRepresentation(km.getKey()))); + } + + /** + * More or less copied from {@link InputConstants.Type#displayTextSupplier} for {@link InputConstants.Type#KEYSYM} + */ + @SuppressWarnings("JavadocReference") + private static String getKeyRepresentation(InputConstants.Key key) { + var lang = Language.getInstance(); + var name = key.getName(); + if (lang.has(name)) return (lang.getOrDefault(name)); + // This will work *most* of the time, but really is just a bandaid fix. + var split = name.split("\\."); + return split[split.length - 1]; + // The following code doesn't work since GLFW must be called from the render thread. + + // var glfwKeyName = GLFW.glfwGetKeyName(key.getValue(), -1); + // return glfwKeyName == null ? Language.getInstance().getOrDefault(key.getName()) : glfwKeyName; + } +} diff --git a/src/main/java/com/kikis/ptdyeplus/kubejs/bindings/PtdyeBindings.java b/src/main/java/com/kikis/ptdyeplus/kubejs/bindings/PtdyeBindings.java new file mode 100644 index 0000000..acbd47a --- /dev/null +++ b/src/main/java/com/kikis/ptdyeplus/kubejs/bindings/PtdyeBindings.java @@ -0,0 +1,7 @@ +package com.kikis.ptdyeplus.kubejs.bindings; + +@SuppressWarnings("unused") +public final class PtdyeBindings { + public static final KeyUtilJS keybinds = new KeyUtilJS(); + public static final AppengBindings appeng = new AppengBindings(); +} \ No newline at end of file diff --git a/src/main/java/com/kikis/ptdyeplus/kubejs/events/PtdyeEvents.java b/src/main/java/com/kikis/ptdyeplus/kubejs/events/PtdyeEvents.java new file mode 100644 index 0000000..3f29256 --- /dev/null +++ b/src/main/java/com/kikis/ptdyeplus/kubejs/events/PtdyeEvents.java @@ -0,0 +1,9 @@ +package com.kikis.ptdyeplus.kubejs.events; + +import dev.latvian.mods.kubejs.event.EventGroup; +import dev.latvian.mods.kubejs.event.EventHandler; + +public final class PtdyeEvents { + public static EventGroup GROUP = EventGroup.of("PtdyeEvents"); + public static EventHandler SETTINGS = GROUP.server("settings", () -> CustomEvent.class); +}