Skip to content

Commit

Permalink
untested port & some rewrites
Browse files Browse the repository at this point in the history
  • Loading branch information
Uraneptus committed Aug 15, 2024
1 parent 370092e commit cf6f9f5
Show file tree
Hide file tree
Showing 22 changed files with 341 additions and 292 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Thumbs.db

## ForgeGradle
/run
/runs

## eclipse
/.settings
Expand Down
74 changes: 22 additions & 52 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,70 +3,39 @@ plugins {
id 'maven-publish'
id 'pmd'
id 'com.diffplug.spotless' version '5.12.5'
id 'net.minecraftforge.gradle' version '5.1.+'
id 'org.parchmentmc.librarian.forgegradle' version '1.+'
id 'org.spongepowered.mixin' version '0.7.+'
id 'net.neoforged.gradle.userdev' version '7.0.145'
}

ext.configFile = file('build.properties')
ext.config = parseConfig(configFile)

version = "${config.version}-${config.build_number}"
group = "vazkii.${config.mod_id}" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = config.mod_name

java.toolchain.languageVersion = JavaLanguageVersion.of(17)
repositories {
mavenLocal()
}

base {
archivesName = config.mod_name
}

java.toolchain.languageVersion = JavaLanguageVersion.of(21)

compileJava.options.compilerArgs << "-Xlint:all,-classfile,-processing,-deprecation" << "-Werror"

if (System.getenv('BUILD_NUMBER') != null) {
version += "." + System.getenv('BUILD_NUMBER')
}

minecraft {
// The mappings can be changed at any time, and must be in the following format.
// snapshot_YYYYMMDD Snapshot are built nightly.
// stable_# Stables are built at the discretion of the MCP team.
// Use non-default mappings at your own risk. they may not always work.
// Simply re-run your setup task after changing the mappings to update your workspace.

mappings channel: "${config.mapping_channel}", version: "${config.mapping_version}"
// makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.

// Default run configurations.
// These can be tweaked, removed, or duplicated as needed.
runs {
client {
workingDirectory project.file('run')

// Recommended logging data for a userdev environment
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'

// Recommended logging level for the console
property 'forge.logging.console.level', 'debug'

mods {
morphtool {
source sourceSets.main
}
}
}

server {
workingDirectory project.file('run')

// Recommended logging data for a userdev environment
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'

// Recommended logging level for the console
property 'forge.logging.console.level', 'debug'
runs {
configureEach {
systemProperty 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
systemProperty 'forge.logging.console.level', 'debug'
modSource project.sourceSets.main
}

mods {
morphtool {
source sourceSets.main
}
}
}
client {
}
}

Expand All @@ -77,7 +46,9 @@ repositories {
}

dependencies {
minecraft "net.minecraftforge:forge:${config.mc_version}-${config.forge_version}"
implementation "net.neoforged:neoforge:21.1.1"

implementation "curse.maven:applied-energistics-2-223794:5610903"
}

spotless {
Expand All @@ -96,7 +67,6 @@ pmd {
toolVersion '6.22.0'
// no way around this warning unless we upgrade Gradle, apparently
//incrementalAnalysis.set(true)
ruleSets.clear()
ruleSetFiles = files("spotless/pmd-ruleset.xml")
}

Expand All @@ -115,7 +85,7 @@ task incrementBuildNumber {

import java.util.regex.Pattern
task sortArtifacts(type: Copy) {
from jar.destinationDir
from jar.getDestinationDirectory()
into config.dir_output
//Put each jar with a classifier in a subfolder with the classifier as its name
eachFile {
Expand All @@ -142,7 +112,7 @@ def parseConfig(File config) {

jar {
//rename the default output, for some better... sanity with scipts
archiveName = "${baseName}-${version}.${extension}"
//archiveName = "${archiveBaseName}-${archiveVersion}.${archiveExtension}"

manifest {
attributes([
Expand Down
10 changes: 5 additions & 5 deletions build.properties
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#Wed Aug 07 18:14:56 UTC 2024
mapping_channel=parchment
forge_version=47.1.3
neoforge_version=21.1.1
mod_id=morphtool
dir_repo=./
build_number=39
dir_output=../Build Output/Morphtool/
mapping_version=2023.09.03-1.20.1
version=1.7
version=1.8
mod_name=Morph-o-Tool
mc_version=1.20.1
mc_version=1.21.1
neogradle.subsystems.parchment.minecraftVersion=1.21
neogradle.subsystems.parchment.mappingsVersion=2024.07.28
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-all.zip
9 changes: 5 additions & 4 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
pluginManagement {
repositories {
gradlePluginPortal()
jcenter()
mavenCentral()
maven { url = 'https://maven.minecraftforge.net/' }
maven { url = 'https://maven.parchmentmc.org' }
maven { url = "https://repo.spongepowered.org/repository/maven-public/" }
mavenLocal()
maven { url = 'https://maven.neoforged.net/releases' }
}
}

plugins {
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.8.0'
}
74 changes: 30 additions & 44 deletions src/main/java/vazkii/morphtool/AttachementRecipe.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
package vazkii.morphtool;

import net.minecraft.core.NonNullList;
import net.minecraft.core.RegistryAccess;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.inventory.CraftingContainer;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.CraftingBookCategory;
import net.minecraft.world.item.crafting.CustomRecipe;
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.item.crafting.*;
import net.minecraft.world.level.Level;
import net.minecraftforge.registries.ForgeRegistries;
import vazkii.morphtool.data_components.ToolContentComponent;

import java.util.ArrayList;
import java.util.List;

public class AttachementRecipe extends CustomRecipe {

public AttachementRecipe(ResourceLocation idIn, CraftingBookCategory pCategory) {
super(idIn, pCategory);
public AttachementRecipe(CraftingBookCategory pCategory) {
super(pCategory);
}

@Override
public boolean matches(CraftingContainer var1, Level var2) {
public boolean matches(CraftingInput input, Level var2) {
boolean foundTool = false;
boolean foundTarget = false;

for (int i = 0; i < var1.getContainerSize(); i++) {
ItemStack stack = var1.getItem(i);
for (int i = 0; i < input.size(); i++) {
ItemStack stack = input.getItem(i);
if (!stack.isEmpty()) {
if (isTarget(stack)) {
if (foundTarget) {
Expand All @@ -46,12 +45,12 @@ public boolean matches(CraftingContainer var1, Level var2) {
}

@Override
public ItemStack assemble(CraftingContainer var1, RegistryAccess pRegistryAccess) {
public ItemStack assemble(CraftingInput input, HolderLookup.Provider provider) {
ItemStack tool = ItemStack.EMPTY;
ItemStack target = ItemStack.EMPTY;

for (int i = 0; i < var1.getContainerSize(); i++) {
ItemStack stack = var1.getItem(i);
for (int i = 0; i < input.size(); i++) {
ItemStack stack = input.getItem(i);
if (!stack.isEmpty()) {
if (stack.is(Registries.MORPH_TOOL.get())) {
tool = stack;
Expand All @@ -61,27 +60,24 @@ public ItemStack assemble(CraftingContainer var1, RegistryAccess pRegistryAccess
}
}

if (!tool.has(Registries.TOOL_CONTENT)) return ItemStack.EMPTY;
ItemStack copy = tool.copy();
CompoundTag cmp = copy.getTag();
if (cmp == null) {
cmp = new CompoundTag();
copy.setTag(cmp);
}

if (!cmp.contains(MorphingHandler.TAG_MORPH_TOOL_DATA)) {
cmp.put(MorphingHandler.TAG_MORPH_TOOL_DATA, new CompoundTag());
}

CompoundTag morphData = cmp.getCompound(MorphingHandler.TAG_MORPH_TOOL_DATA);
String mod = MorphingHandler.getModFromStack(target);

if (morphData.contains(mod)) {
return ItemStack.EMPTY;
ToolContentComponent contents = copy.get(Registries.TOOL_CONTENT);
List<ItemStack> contentStacks = new ArrayList<>(List.copyOf(copy.get(Registries.TOOL_CONTENT).contents()));

//This assures that only one item of a mod is in the tool
if (!contentStacks.isEmpty()) {
for (ItemStack contentStack : contentStacks) {
if (BuiltInRegistries.ITEM.getKey(contentStack.getItem()).getNamespace().equals(mod)) {
return ItemStack.EMPTY;
}
}
}

CompoundTag modCmp = new CompoundTag();
target.save(modCmp);
morphData.put(mod, modCmp);
contentStacks.add(target);

copy.set(Registries.TOOL_CONTENT, new ToolContentComponent(contentStacks));

return copy;
}
Expand Down Expand Up @@ -109,7 +105,7 @@ public boolean isTarget(ItemStack stack) {
return false;
}

ResourceLocation registryNameRL = ForgeRegistries.ITEMS.getKey(stack.getItem());
ResourceLocation registryNameRL = BuiltInRegistries.ITEM.getKey(stack.getItem());
String registryName = registryNameRL.toString();
if (ConfigHandler.whitelistedItems.get().contains(registryName) || ConfigHandler.whitelistedItems.get().contains(registryName + ":" + stack.getDamageValue())) {
return true;
Expand All @@ -125,16 +121,6 @@ public boolean isTarget(ItemStack stack) {
return false;
}

@Override
public ItemStack getResultItem(RegistryAccess pRegistryAccess) {
return ItemStack.EMPTY;
}

@Override
public NonNullList<ItemStack> getRemainingItems(CraftingContainer inv) {
return NonNullList.withSize(inv.getContainerSize(), ItemStack.EMPTY);
}

@Override
public RecipeSerializer<?> getSerializer() {
return Registries.ATTACHMENT.get();
Expand Down
Loading

0 comments on commit cf6f9f5

Please sign in to comment.