Skip to content

Commit

Permalink
Merge branch 'pr/4'
Browse files Browse the repository at this point in the history
  • Loading branch information
jasperalani committed Jan 26, 2024
2 parents 11bd12b + 9b8dca0 commit 422dad7
Show file tree
Hide file tree
Showing 15 changed files with 280 additions and 8 deletions.
16 changes: 16 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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'
}
Expand Down
4 changes: 3 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
architectury_version = 6.5.85
appeng_version = 12.9.8
ae2things_version=1.1.1
6 changes: 6 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
25 changes: 25 additions & 0 deletions src/main/java/com/kikis/ptdyeplus/appeng/CellUtil.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
14 changes: 14 additions & 0 deletions src/main/java/com/kikis/ptdyeplus/appeng/ICommonCellItem.java
Original file line number Diff line number Diff line change
@@ -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();
}
48 changes: 48 additions & 0 deletions src/main/java/com/kikis/ptdyeplus/appeng/SimpleCellItem.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
29 changes: 29 additions & 0 deletions src/main/java/com/kikis/ptdyeplus/appeng/SimpleDiskCell.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
31 changes: 31 additions & 0 deletions src/main/java/com/kikis/ptdyeplus/appeng/SimpleStorageCell.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
5 changes: 0 additions & 5 deletions src/main/java/com/kikis/ptdyeplus/kubejs/BaseBindings.java

This file was deleted.

4 changes: 2 additions & 2 deletions src/main/java/com/kikis/ptdyeplus/kubejs/PtdyeJS.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.kikis.ptdyeplus.kubejs.bindings;

@SuppressWarnings("unused")
public final class AppengBindings {
public final CellUtilJS cells = new CellUtilJS();
}
41 changes: 41 additions & 0 deletions src/main/java/com/kikis/ptdyeplus/kubejs/bindings/CellUtilJS.java
Original file line number Diff line number Diff line change
@@ -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(); }
}
43 changes: 43 additions & 0 deletions src/main/java/com/kikis/ptdyeplus/kubejs/bindings/KeyUtilJS.java
Original file line number Diff line number Diff line change
@@ -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<String, String> 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;
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit 422dad7

Please sign in to comment.