-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
280 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
14
src/main/java/com/kikis/ptdyeplus/appeng/ICommonCellItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
48
src/main/java/com/kikis/ptdyeplus/appeng/SimpleCellItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
29
src/main/java/com/kikis/ptdyeplus/appeng/SimpleDiskCell.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
31
src/main/java/com/kikis/ptdyeplus/appeng/SimpleStorageCell.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/main/java/com/kikis/ptdyeplus/kubejs/bindings/AppengBindings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
41
src/main/java/com/kikis/ptdyeplus/kubejs/bindings/CellUtilJS.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
43
src/main/java/com/kikis/ptdyeplus/kubejs/bindings/KeyUtilJS.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/kikis/ptdyeplus/kubejs/bindings/PtdyeBindings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/kikis/ptdyeplus/kubejs/events/PtdyeEvents.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |