Compare commits

...

2 Commits

Author SHA1 Message Date
Sebastian Hartte 2216c33f12 Be less defensive about copying item stacks in simulated extractions (but still catch obviously broken implementations).
Also fix looping over the same slot while simulating, and try to heuristically guess the maximum extraction from the slot given what getStackInSlot returned.
2020-10-10 20:13:36 +02:00
Sebastian Hartte e76ca86602 Added a mechanism to add mods downloaded from curseforge to a dev-environment by simply dropping them into an extra-mods-<mc-version> folder. 2020-10-09 22:47:21 +02:00
3 changed files with 41 additions and 8 deletions
+17 -2
View File
@@ -20,7 +20,6 @@ buildscript {
repositories {
maven { url = 'https://files.minecraftforge.net/maven' }
maven { url = 'https://repo.spongepowered.org/maven' }
jcenter()
mavenCentral()
}
dependencies {
@@ -40,9 +39,15 @@ apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'org.spongepowered.mixin'
apply plugin: "eclipse"
// All jar files from this folder will be added automatically as runtime mod dependencies
def extraModsDir = "extra-mods-${minecraft_version}"
repositories {
flatDir {
name "extra-mods"
dir file(extraModsDir)
}
mavenLocal()
jcenter()
mavenCentral()
maven { // modmaven, maven proxy
name 'modmaven'
@@ -61,6 +66,16 @@ dependencies {
runtimeOnly fg.deobf("mezz.jei:jei-${jei_minecraft_version}:${jei_version}")
runtimeOnly fg.deobf("mcjty.theoneprobe:TheOneProbe-${minecraft_release}:${minecraft_release}-${top_version}")
// Locally sourced extra mods for runtime (i.e. testing)
for (extraModJar in fileTree(dir: extraModsDir, include: '*.jar')) {
def basename = extraModJar.name.substring(0, extraModJar.name.length() - ".jar".length())
def versionSep = basename.lastIndexOf('-')
assert versionSep != -1
def artifactId = basename.substring(0, versionSep)
def version = basename.substring(versionSep + 1)
runtimeOnly fg.deobf("extra-mods:$artifactId:$version")
}
// unit test dependencies
testCompile "junit:junit:4.13"
+1 -1
View File
@@ -11,7 +11,7 @@ artifact_basename=appliedenergistics2
minecraft_release=1.16
minecraft_version=1.16.3
mcp_mappings=20200916-1.16.2
forge_version=34.0.8
forge_version=34.1.15
#########################################################
# Provided APIs #
@@ -122,6 +122,15 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
do {
extracted = this.itemHandler.extractItem(i, remainingCurrentSlot, simulate);
if (!extracted.isEmpty()) {
// In order to guard against broken IItemHandler implementations, we'll
// try to guess if the returned stack (especially in simulate mode) is
// the same that was returned by getStackInSlot. This is obviously not a
// precise science, but it would catch the previous Forge bug:
// https://github.com/MinecraftForge/MinecraftForge/pull/6580
if (extracted == stackInInventorySlot) {
extracted = extracted.copy();
}
if (extracted.getCount() > remainingCurrentSlot) {
// Something broke. It should never return more than we requested...
// We're going to silently eat the remainder
@@ -131,19 +140,28 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
extracted.setCount(remainingCurrentSlot);
}
// Heuristic for simulation: looping in case of simulations is pointless, since
// the
// state of the underlying inventory does not change after a simulated
// extraction
// To still support inventories that report stacks that are larger than
// maxStackSize,
// we use this heuristic
if (simulate && extracted.getCount() == extracted.getMaxStackSize()
&& remainingCurrentSlot > extracted.getMaxStackSize()) {
extracted.setCount(remainingCurrentSlot);
}
// We're just gonna use the first stack we get our hands on as the template for
// the rest.
// In case some stupid itemhandler (aka forge) returns an internal state we have
// to do a second
// expensive copy again.
if (gathered.isEmpty()) {
gathered = extracted.copy();
gathered = extracted;
} else {
gathered.grow(extracted.getCount());
}
remainingCurrentSlot -= extracted.getCount();
}
} while (!extracted.isEmpty() && remainingCurrentSlot > 0);
} while (!simulate && !extracted.isEmpty() && remainingCurrentSlot > 0);
remainingSize -= stackSizeCurrentSlot - remainingCurrentSlot;