Skip to content

Commit

Permalink
make CrTItemHandler#getStackInSlot return immutable stack
Browse files Browse the repository at this point in the history
  • Loading branch information
friendlyhj committed Apr 24, 2021
1 parent 59394b5 commit a21ba5e
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 8 deletions.
13 changes: 10 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
buildscript {
repositories {
jcenter()
maven { url = "https://files.minecraftforge.net/maven" }
maven { url = "https://maven.minecraftforge.net" }
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT'
Expand All @@ -11,7 +11,7 @@ apply plugin: 'net.minecraftforge.gradle.forge'
//Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.


version = "1.6.7"
version = "1.6.8"
group = "youyihj.zenutils" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "zenutils"

Expand All @@ -20,6 +20,13 @@ compileJava {
sourceCompatibility = targetCompatibility = '1.8'
}

// change default maven url of FG2 to the new one.
repositories.each {
if (it instanceof MavenArtifactRepository && it.url.toString() == "https://files.minecraftforge.net/maven") {
it.url = "https://maven.minecraftforge.net/"
}
}

minecraft {
version = "1.12.2-14.23.5.2847"
runDir = "run"
Expand Down Expand Up @@ -55,7 +62,7 @@ dependencies {
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
// http://www.gradle.org/docs/current/userguide/dependency_management.html

deobfCompile "CraftTweaker2:CraftTweaker2-MC1120-Main:1.12-4.1.20.616"
deobfCompile "CraftTweaker2:CraftTweaker2-MC1120-Main:1.12-4.1.20.640"
deobfCompile "com.teamacronymcoders.base:base:1.12.2-3.13.0-SNAPSHOT.+"
deobfCompile "com.teamacronymcoders:ContentTweaker:1.12.2-4.9.1"
deobfCompile "cofh:RedstoneFlux:1.12-2.1.0.+:universal"
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
3 changes: 2 additions & 1 deletion src/main/java/youyihj/zenutils/ZenUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@
* @author youyihj
*/
@Mod(modid = ZenUtils.MODID, name = ZenUtils.NAME, version = ZenUtils.VERSION, dependencies = ZenUtils.DEPENDENCIES)
@Mod.EventBusSubscriber
public class ZenUtils {
public static final String MODID = "zenutils";
public static final String NAME = "ZenUtils";
public static final String VERSION = "1.6.7";
public static final String VERSION = "1.6.8";
public static final String DEPENDENCIES = "required-after:crafttweaker;after:contenttweaker;required-after:redstoneflux;after:ftbquests";

@Mod.EventHandler
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/youyihj/zenutils/item/CrTItemHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import crafttweaker.annotations.ZenRegister;
import crafttweaker.api.item.IItemStack;
import crafttweaker.api.minecraft.CraftTweakerMC;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
import stanhebben.zenscript.annotations.IterableSimple;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenGetter;
import stanhebben.zenscript.annotations.ZenMethod;
import youyihj.zenutils.util.object.TotallyImmutableItemStack;

import javax.annotation.Nonnull;
import java.util.Iterator;
Expand Down Expand Up @@ -59,7 +61,8 @@ public IItemStack next() {

@ZenMethod
public IItemStack getStackInSlot(int slot) {
return CraftTweakerMC.getIItemStack(itemHandler.getStackInSlot(slot));
ItemStack stack = itemHandler.getStackInSlot(slot);
return stack.isEmpty() ? new TotallyImmutableItemStack(stack) : null;
}

@ZenMethod
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/youyihj/zenutils/util/InternalUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public static void checkDataMap(IData data) {

public static void checkCrTVersion() {
try {
Class.forName("crafttweaker.util.SuppressErrorFlag");
Class.forName("crafttweaker.api.item.IMutableItemStack");
} catch (ClassNotFoundException e) {
throw new RuntimeException("crafttweaker version must be 4.1.20.608 or above!");
throw new RuntimeException("crafttweaker version must be 4.1.20.632 or above!");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package youyihj.zenutils.util.object;

import crafttweaker.api.item.IMutableItemStack;
import crafttweaker.mc1120.item.MCItemStack;
import net.minecraft.item.ItemStack;

public class TotallyImmutableItemStack extends MCItemStack {
public TotallyImmutableItemStack(ItemStack itemStack) {
super(itemStack);
}

@Override
public IMutableItemStack mutable() {
throw new UnsupportedOperationException("The ItemStack is totally immutable. You can't make it mutable");
}
}

0 comments on commit a21ba5e

Please sign in to comment.