Skip to content

Commit 12bb806

Browse files
committed
aekey
1 parent 5e5c740 commit 12bb806

35 files changed

Lines changed: 4593 additions & 95 deletions

CHANGELOG.md

Lines changed: 0 additions & 6 deletions
This file was deleted.

LICENSE

Lines changed: 840 additions & 21 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,30 @@
1-
## TemplateDevEnv
2-
_For Kotlin see [TemplateDevEnvKt](https://github.com/CleanroomMC/TemplateDevEnvKt)_
1+
## AEKey Legacy
2+
1.20.1 Applied Energistics 2's AEKey API port, adapted as much as possible to the 1.12.2 environment (e.g., metadata, OreDictionary)
33

4-
Template workspace for modding Minecraft 1.12.2. Licensed under MIT, it is made for public use.
4+
### License
55

6-
This template runs on **Java 25**, **Gradle 9.2.1** + **[RetroFuturaGradle](https://github.com/GTNewHorizons/RetroFuturaGradle) 2.0.2** + **Forge 14.23.5.2847**.
6+
#### Applied Energistics 2 API
7+
**(c) 2013 - 2020 AlgorithmX2 et al**
8+
**[![License](https://img.shields.io/badge/License-MIT-red.svg?style=flat-square)](http://opensource.org/licenses/MIT)**
79

8-
With **coremod and mixin support** that is easy to configure.
10+
**Directory:**
11+
- `aekeylegacy.api`
912

10-
### Instructions:
13+
---
1114

12-
1. Click `use this template` at the top.
13-
2. Clone the repository that you have created with this template to your local machine.
14-
3. Make sure IDEA is using Java 25 for Gradle before you sync the project. Verify this by going to IDEA's `Settings > Build, Execution, Deployment > Build Tools > Gradle > Gradle JVM`.
15-
4. Open the project folder in IDEA. When prompted, click "Load Gradle Project" as it detects the `build.gradle`, if you weren't prompted, right-click the project's `build.gradle` in IDEA, select `Link Gradle Project`, after completion, hit `Refresh All` in the gradle tab on the right.
16-
5. Run gradle tasks such as `runClient` and `runServer` in the IDEA gradle tab, or use the auto-imported run configurations like `1. Run Client`.
15+
#### Applied Energistics 2
16+
**(c) 2013 - 2020 AlgorithmX2 et al**
17+
**[![License](https://img.shields.io/badge/License-LGPLv3-blue.svg?style=flat-square)](https://raw.githubusercontent.com/AppliedEnergistics/Applied-Energistics-2/rv2/LICENSE)**
1718

18-
### Notes:
19-
- Dependencies script in [gradle/scripts/dependencies.gradle](gradle/scripts/dependencies.gradle), explanations are commented in the file.
20-
- Publishing script in [gradle/scripts/publishing.gradle](gradle/scripts/publishing.gradle).
21-
- When writing Mixins on IntelliJ, it is advisable to use latest [MinecraftDev Fork for RetroFuturaGradle](https://github.com/eigenraven/MinecraftDev/releases).
19+
**Directories:**
20+
- `aekeylegacy.client`
21+
- `aekeylegacy.init`
22+
- `aekeylegacy.items`
23+
- `aekeylegacy.util`
24+
25+
---
26+
27+
### Credit
28+
29+
**ForgeDevEnv**
30+
**[![License](https://img.shields.io/badge/License-MIT-red.svg?style=flat-square)](https://github.com/CleanroomMC/ForgeDevEnv/blob/master/LICENSE)**

build.gradle

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* It is advised that you do not edit anything in the build.gradle; unless you are sure of what you are doing
33
*/
44
import com.gtnewhorizons.retrofuturagradle.mcp.InjectTagsTask
5-
import org.jetbrains.changelog.Changelog
65
import org.jetbrains.gradle.ext.Gradle
76

87
plugins {
@@ -110,6 +109,7 @@ repositories {
110109
}
111110

112111
dependencies {
112+
compileOnlyApi 'org.jetbrains:annotations:24.1.0'
113113
if (propertyBool('use_modern_java_syntax')) {
114114
annotationProcessor 'com.github.bsideup.jabel:jabel-javac-plugin:1.0.0'
115115
// Workaround for https://github.com/bsideup/jabel/issues/174
@@ -271,19 +271,6 @@ test {
271271
}
272272
}
273273

274-
String parserChangelog() {
275-
if (!file('CHANGELOG.md').exists()) {
276-
throw new GradleException('publish_with_changelog is true, but CHANGELOG.md does not exist in the workspace!')
277-
}
278-
String parsedChangelog = changelog.renderItem(
279-
changelog.get(propertyString('mod_version')).withHeader(false).withEmptySections(false),
280-
Changelog.OutputType.MARKDOWN)
281-
if (parsedChangelog.isEmpty()) {
282-
throw new GradleException('publish_with_changelog is true, but the changelog for the latest version is empty!')
283-
}
284-
return parsedChangelog
285-
}
286-
287274
tasks.register('generateMixinJson') {
288275
group 'cleanroom helpers'
289276
def missingConfig = propertyStringList('mixin_configs').findAll(config -> !file("src/main/resources/mixins.${config}.json").exists())

gradle.properties

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ org.gradle.jvmargs = -Xmx3G
33

44
# Source Options
55
# Use Modern Java(9+) Syntax (Courtesy of Jabel)
6-
use_modern_java_syntax = false
6+
use_modern_java_syntax = true
77

88
# Compilation Options
99
generate_sources_jar = true
@@ -16,9 +16,9 @@ show_testing_output = false
1616
# Mod Information
1717
# HIGHLY RECOMMEND complying with SemVer for mod_version: https://semver.org/
1818
mod_version = 1.0.0
19-
root_package = com.example
20-
mod_id = modid
21-
mod_name = Mod Name
19+
root_package = aekeylegacy
20+
mod_id = aekeylegacy
21+
mod_name = AEKey Legacy
2222

2323
# Mod Metadata (Optional)
2424
mod_description =
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package aekeylegacy;
2+
3+
import java.util.Objects;
4+
5+
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
6+
import net.minecraft.item.Item;
7+
import net.minecraftforge.client.event.ModelRegistryEvent;
8+
import net.minecraftforge.client.model.ModelLoader;
9+
import net.minecraftforge.event.RegistryEvent;
10+
import net.minecraftforge.fml.common.Mod;
11+
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
12+
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
13+
import net.minecraftforge.fml.relauncher.Side;
14+
import net.minecraftforge.fml.relauncher.SideOnly;
15+
16+
import aekeylegacy.aekeylegacy.Tags;
17+
import aekeylegacy.init.InitKeyTypes;
18+
import aekeylegacy.items.WrappedGenericStack;
19+
20+
@Mod(modid = Tags.MOD_ID, name = Tags.MOD_NAME, version = Tags.VERSION)
21+
public class AEKeyLegacy {
22+
23+
@Mod.EventHandler
24+
public void preInit(FMLPreInitializationEvent event) {
25+
InitKeyTypes.init();
26+
}
27+
28+
@Mod.EventBusSubscriber(modid = Tags.MOD_ID)
29+
public static class RegistrationHandler {
30+
@SubscribeEvent
31+
public static void registerItems(RegistryEvent.Register<Item> event) {
32+
var item = new WrappedGenericStack()
33+
.setRegistryName(Tags.MOD_ID, "wrapped_generic_stack")
34+
.setTranslationKey(Tags.MOD_ID + ".wrapped_generic_stack");
35+
event.getRegistry().register(item);
36+
}
37+
38+
@SideOnly(Side.CLIENT)
39+
@SubscribeEvent
40+
public static void registerModels(ModelRegistryEvent event) {
41+
var item = aekeylegacy.items.WrappedGenericStack.getItem();
42+
ModelLoader.setCustomModelResourceLocation(item, 0,
43+
new ModelResourceLocation(Objects.requireNonNull(item.getRegistryName()), "inventory"));
44+
}
45+
}
46+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package aekeylegacy;
2+
3+
import org.apache.logging.log4j.Logger;
4+
import org.apache.logging.log4j.LogManager;
5+
6+
import aekeylegacy.aekeylegacy.Tags;
7+
8+
public class AELog {
9+
public static final Logger LOGGER = LogManager.getLogger(Tags.MOD_NAME);
10+
11+
public static void warn(String message, Object... params) {
12+
LOGGER.warn(message, params);
13+
}
14+
15+
public static void error(String message, Object... params) {
16+
LOGGER.error(message, params);
17+
}
18+
19+
public static void debug(String message, Object... params) {
20+
LOGGER.debug(message, params);
21+
}
22+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package aekeylegacy;
2+
3+
import java.lang.invoke.MethodHandle;
4+
import java.lang.invoke.MethodHandles;
5+
import java.util.List;
6+
import java.util.Map;
7+
import java.util.stream.Stream;
8+
import javax.annotation.Nonnull;
9+
10+
import net.minecraft.item.Item;
11+
import net.minecraftforge.oredict.OreDictionary;
12+
13+
public class OreDictUtil {
14+
private static final MethodHandle STACK_TO_ID_HANDLE;
15+
private static final MethodHandle ID_TO_NAME_HANDLE;
16+
static {
17+
try {
18+
var stackToIdField = OreDictionary.class.getDeclaredField("stackToId");
19+
stackToIdField.setAccessible(true);
20+
STACK_TO_ID_HANDLE = MethodHandles.lookup().unreflectGetter(stackToIdField);
21+
var idToNameField = OreDictionary.class.getDeclaredField("idToName");
22+
idToNameField.setAccessible(true);
23+
ID_TO_NAME_HANDLE = MethodHandles.lookup().unreflectGetter(idToNameField);
24+
} catch (Exception exception) {
25+
throw new RuntimeException("Failed to access OreDictionary private fields", exception);
26+
}
27+
}
28+
29+
@SuppressWarnings("unchecked")
30+
private static Map<Integer, List<Integer>> getStackToId() {
31+
try {
32+
return (Map<Integer, List<Integer>>) STACK_TO_ID_HANDLE.invokeExact();
33+
} catch (Throwable e) {
34+
throw new RuntimeException("Failed to get stackToId", e);
35+
}
36+
}
37+
38+
@SuppressWarnings("unchecked")
39+
private static List<String> getIdToName() {
40+
try {
41+
return (List<String>) ID_TO_NAME_HANDLE.invokeExact();
42+
} catch (Throwable e) {
43+
throw new RuntimeException("Failed to get idToName", e);
44+
}
45+
}
46+
47+
private OreDictUtil() {
48+
}
49+
50+
public static Stream<String> getOreNames() {
51+
return getIdToName().stream();
52+
}
53+
54+
public static boolean hasTag(@Nonnull Item item, int metadata, @Nonnull String tag) {
55+
int itemId = Item.REGISTRY.getIDForObject(item);
56+
int effectiveMeta = item.getHasSubtypes() ? metadata : 0;
57+
var idToName = getIdToName();
58+
int tagId = -1;
59+
60+
for (int i = 0; i < idToName.size(); i++) {
61+
if (tag.equals(idToName.get(i))) {
62+
tagId = i;
63+
break;
64+
}
65+
}
66+
67+
if (tagId == -1) {
68+
return false;
69+
}
70+
71+
var stackToId = getStackToId();
72+
var wildcardIds = stackToId.get(itemId);
73+
if (wildcardIds != null && wildcardIds.contains(tagId)) {
74+
return true;
75+
}
76+
77+
int exactKey = itemId | ((effectiveMeta + 1) << 16);
78+
var exactIds = stackToId.get(exactKey);
79+
80+
return exactIds != null && exactIds.contains(tagId);
81+
}
82+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
Some packages have a different license, please see the corresponding LICENSE files
3+
in those packages.
4+
5+
----
6+
7+
The MIT License (MIT)
8+
9+
Copyright (c) 2023 Team Applied Energistics
10+
11+
Permission is hereby granted, free of charge, to any person obtaining a copy of
12+
this software and associated documentation files (the "Software"), to deal in
13+
the Software without restriction, including without limitation the rights to
14+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
15+
the Software, and to permit persons to whom the Software is furnished to do so,
16+
subject to the following conditions:
17+
18+
The above copyright notice and this permission notice shall be included in all
19+
copies or substantial portions of the Software.
20+
21+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
23+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
24+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
25+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
26+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2013 AlgorithmX2
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
7+
* this software and associated documentation files (the "Software"), to deal in
8+
* the Software without restriction, including without limitation the rights to
9+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10+
* the Software, and to permit persons to whom the Software is furnished to do so,
11+
* subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
*/
23+
24+
package aekeylegacy.api.config;
25+
26+
public enum FuzzyMode {
27+
/**
28+
* Matches any item from undamaged to including 0% durability, but not negative durability (where item damage
29+
* exceeds maxdamage).
30+
*/
31+
IGNORE_ALL(-1),
32+
/**
33+
* Matches items that have less than 100% durability (that is, at least 1 damage point) if a damaged item is used as
34+
* the filter, or undamaged items otherwise.
35+
*/
36+
PERCENT_99(0),
37+
/**
38+
* If an item with less than 75% durability is used as the filter, items with less than 75% durability are matched.
39+
* Otherwise items with 75% durability or more are matched.
40+
*/
41+
PERCENT_75(25),
42+
/**
43+
* If an item with less than 50% durability is used as the filter, items with less than 50% durability are matched.
44+
* Otherwise items with 50% durability or more are matched.
45+
*/
46+
PERCENT_50(50),
47+
/**
48+
* If an item with less than 25% durability is used as the filter, items with less than 50% durability are matched.
49+
* Otherwise items with 25% durability or more are matched.
50+
*/
51+
PERCENT_25(75);
52+
53+
public final float breakPoint;
54+
/**
55+
* Note this is percentage "damaged". It's the inverse of percentage durability.
56+
*/
57+
public final float percentage;
58+
59+
FuzzyMode(float p) {
60+
this.percentage = p;
61+
this.breakPoint = p / 100.0f;
62+
}
63+
64+
public int calculateBreakPoint(int maxDamage) {
65+
return (int) (this.percentage * maxDamage / 100.0f);
66+
}
67+
68+
}

0 commit comments

Comments
 (0)