Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,18 @@
dependencies {
api('com.github.GTNewHorizons:OpenModsLib:0.10.14:dev')

compileOnly('openperipheral:OpenPeripheralCore-API:3.4.1')
compileOnly("com.github.GTNewHorizons:Backhand:1.8.10:dev") { transitive = false }
compileOnly('curse.maven:computercraft-67504:2269339')
compileOnly('com.github.GTNewHorizons:Mobs-Info:0.5.17-GTNH:dev')
compileOnly("com.github.GTNewHorizons:Backhand:1.8.10:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:Baubles-Expanded:2.2.21-GTNH:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:AdventureBackpack2:1.4.21-GTNH:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:Minecraft-Backpack-Mod:2.6.13-GTNH:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:TinkersConstruct:1.14.91-GTNH:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:Galacticraft:3.4.29-GTNH:dev") { transitive = false }
compileOnly('openperipheral:OpenPeripheralCore-API:3.4.1')

devOnlyNonPublishable('com.github.GTNewHorizons:NotEnoughItems:2.8.102-GTNH:dev')
devOnlyNonPublishable("com.github.GTNewHorizons:Baubles-Expanded:2.2.21-GTNH:dev") { transitive = false }
devOnlyNonPublishable("com.github.GTNewHorizons:AdventureBackpack2:1.4.21-GTNH:dev") { transitive = false }
devOnlyNonPublishable("com.github.GTNewHorizons:Minecraft-Backpack-Mod:2.6.13-GTNH:dev") { transitive = false }
devOnlyNonPublishable("com.github.GTNewHorizons:TinkersConstruct:1.14.91-GTNH:dev") { transitive = true }
devOnlyNonPublishable("com.github.GTNewHorizons:waila:1.19.30:dev") { transitive = true }
devOnlyNonPublishable("com.github.GTNewHorizons:HoloInventory:2.5.13-GTNH:dev") { transitive = true }
devOnlyNonPublishable("com.github.GTNewHorizons:Baubles-Expanded:2.2.21-GTNH:dev") { transitive = false }
devOnlyNonPublishable("com.github.GTNewHorizons:CosmeticArmorReworked:1.0.6-GTNH:dev") { transitive = false }
devOnlyNonPublishable("com.github.GTNewHorizons:Galacticraft:3.4.29-GTNH:dev") { transitive = false }
devOnlyNonPublishable("com.github.GTNewHorizons:HoloInventory:2.5.13-GTNH:dev") { transitive = false }
devOnlyNonPublishable("com.github.GTNewHorizons:Minecraft-Backpack-Mod:2.6.13-GTNH:dev") { transitive = false }
devOnlyNonPublishable('com.github.GTNewHorizons:NotEnoughItems:2.8.102-GTNH:dev')
devOnlyNonPublishable("com.github.GTNewHorizons:TinkersConstruct:1.14.91-GTNH:dev")
devOnlyNonPublishable("com.github.GTNewHorizons:waila:1.19.30:dev")
}
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ developmentEnvironmentUserName = Developer
# - jabel: Jabel syntax-only support, compiles to J8 bytecode
# - jvmDowngrader: Full modern Java via JVM Downgrader (syntax + stdlib APIs)
# - modern: Native modern Java bytecode, no downgrading
enableModernJavaSyntax = jabel
enableModernJavaSyntax = jvmDowngrader

# If set, ignores the above setting and compiles with the given toolchain. This may cause unexpected issues,
# and should *not* be used in most situations. -1 disables this.
Expand All @@ -65,7 +65,7 @@ enableModernJavaSyntax = jabel
# - external: Another dependency provides stubs (no constraint, no warning)
# - (empty): Warning reminding you to configure stubs
# Note: 'shade' option requires you to verify license compliance, see: https://github.com/unimined/JvmDowngrader/blob/main/LICENSE.md
# jvmDowngraderStubsProvider =
jvmDowngraderStubsProvider = gtnhlib

# Enables injecting missing generics into the decompiled source code for a better coding experience.
# Turns most publicly visible List, Map, etc. into proper List<E>, Map<K, V> types.
Expand Down
35 changes: 27 additions & 8 deletions src/main/java/openblocks/common/GraveAutoEquip.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import baubles.api.IBauble;
import de.eydamos.backpack.item.ItemBackpackBase;
import de.eydamos.backpack.saves.PlayerSave;
import lain.mods.cos.CosmeticArmorReworked;
import lain.mods.cos.inventory.InventoryCosArmor;
import micdoodle8.mods.galacticraft.api.item.IItemThermal;
import micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats;
import micdoodle8.mods.galacticraft.core.inventory.InventoryExtended;
Expand All @@ -34,22 +36,23 @@ public class GraveAutoEquip {
public static boolean tryRestoreToOrigin(EntityPlayer player, ItemStack stack, GraveSlotOrigin origin) {
if (stack == null || origin == null) return false;
try {
return switch (origin.inventoryType) {
case GraveSlotOrigin.INV_MAIN -> restoreToMain(player, stack, origin.slot);
case GraveSlotOrigin.INV_ARMOR -> restoreToArmor(player, stack, origin.slot);
case GraveSlotOrigin.INV_TCONSTRUCT -> restoreToTConstruct(player, stack, origin.slot);
case GraveSlotOrigin.INV_BAUBLES -> restoreToBaubles(player, stack, origin.slot);
return switch (origin.inventoryType()) {
case GraveSlotOrigin.INV_MAIN -> restoreToMain(player, stack, origin.slot());
case GraveSlotOrigin.INV_ARMOR -> restoreToArmor(player, stack, origin.slot());
case GraveSlotOrigin.INV_ADVENTURE_BACKPACK -> restoreToAdventureBackpack(player, stack);
case GraveSlotOrigin.INV_BAUBLES -> restoreToBaubles(player, stack, origin.slot());
case GraveSlotOrigin.INV_COSMETIC_ARMOR -> restoreToCosmeticArmor(player, stack, origin.slot());
case GraveSlotOrigin.INV_GALACTICRAFT -> restoreToGalacticraft(player, stack, origin.slot());
case GraveSlotOrigin.INV_MC_BACKPACK -> restoreToMcBackpack(player, stack);
case GraveSlotOrigin.INV_GALACTICRAFT -> restoreToGalacticraft(player, stack, origin.slot);
case GraveSlotOrigin.INV_TCONSTRUCT -> restoreToTConstruct(player, stack, origin.slot());
default -> false;
};
} catch (Exception e) {
Log.warn(
"GraveAutoEquip: error restoring %s to origin %s/%d: %s",
stack.getDisplayName(),
origin.inventoryType,
origin.slot,
origin.inventoryType(),
origin.slot(),
e);
return false;
}
Expand Down Expand Up @@ -104,6 +107,22 @@ static boolean restore(EntityPlayer player, ItemStack stack) {
}
}

private static boolean restoreToCosmeticArmor(EntityPlayer player, ItemStack stack, int slot) {
if (!ModPresence.COSMETIC_ARMOR) return false;
return CosmeticArmorRestoreHelper.restore(player, stack, slot);
}

private static final class CosmeticArmorRestoreHelper {

static boolean restore(EntityPlayer player, ItemStack stack, int slot) {
InventoryCosArmor inv = CosmeticArmorReworked.invMan.getCosArmorInventory(player.getUniqueID());
if (inv.getStackInSlot(slot) != null) return false;
inv.setInventorySlotContents(slot, stack.copy());
inv.markDirty();
return true;
}
}

private static boolean restoreToMcBackpack(EntityPlayer player, ItemStack stack) {
if (!ModPresence.MC_BACKPACK) return false;
return McBackpackRestoreHelper.restore(player, stack);
Expand Down
45 changes: 31 additions & 14 deletions src/main/java/openblocks/common/GraveInventorySnapshot.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

import baubles.api.BaublesApi;
import de.eydamos.backpack.saves.PlayerSave;
import lain.mods.cos.CosmeticArmorReworked;
import lain.mods.cos.inventory.InventoryCosArmor;
import micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats;
import micdoodle8.mods.galacticraft.core.inventory.InventoryExtended;
import openmods.Log;
Expand All @@ -24,18 +26,9 @@

public class GraveInventorySnapshot {

public static final class OriginatedStack {
public record OriginatedStack(GraveSlotOrigin origin, ItemStack stack) {}

public final GraveSlotOrigin origin;
public final ItemStack stack;

public OriginatedStack(GraveSlotOrigin origin, ItemStack stack) {
this.origin = origin;
this.stack = stack;
}
}

private final List<OriginatedStack> entries = new ArrayList<OriginatedStack>();
private final List<OriginatedStack> entries = new ArrayList<>();

public GraveInventorySnapshot(EntityPlayer player) {
captureMain(player);
Expand All @@ -45,6 +38,7 @@ public GraveInventorySnapshot(EntityPlayer player) {
captureAdventureBackpack(player);
captureMcBackpack(player);
captureGalacticraft(player);
captureCosmeticArmor(player);
}

private void captureMain(EntityPlayer player) {
Expand Down Expand Up @@ -182,6 +176,29 @@ static void capture(EntityPlayer player, List<OriginatedStack> out) {
}
}

private void captureCosmeticArmor(EntityPlayer player) {
if (!ModPresence.COSMETIC_ARMOR) return;
try {
CosmeticArmorCaptureHelper.capture(player, entries);
} catch (Exception e) {
Log.warn("GraveInventorySnapshot: failed to capture Cosmetic Armor slots: %s", e);
}
}

private static final class CosmeticArmorCaptureHelper {

static void capture(EntityPlayer player, List<OriginatedStack> out) {
InventoryCosArmor cosArmorInventory = CosmeticArmorReworked.invMan
.getCosArmorInventory(player.getUniqueID());
ItemStack[] inv = cosArmorInventory.getInventory();
for (int i = 0; i < inv.length; i++) {
ItemStack stack = inv[i];
if (stack != null)
out.add(new OriginatedStack(new GraveSlotOrigin(GraveSlotOrigin.INV_COSMETIC_ARMOR, i), stack));
}
}
}

/**
* Builds grave inventory and slot origins from the snapshot. Only items that appear in graveLoot (matched by
* item/damage/NBT) are included.
Expand All @@ -192,21 +209,21 @@ static void capture(EntityPlayer player, List<OriginatedStack> out) {
*/
public IInventory buildLoot(List<EntityItem> graveLoot, Map<Integer, GraveSlotOrigin> originsOut) {
// Build a consumable pool of drops for matching
List<ItemStack> pool = new ArrayList<ItemStack>(graveLoot.size());
List<ItemStack> pool = new ArrayList<>(graveLoot.size());
for (EntityItem ei : graveLoot) {
ItemStack s = ei.getEntityItem();
if (s != null) pool.add(s);
}

List<OriginatedStack> matched = new ArrayList<OriginatedStack>();
List<OriginatedStack> matched = new ArrayList<>();
for (OriginatedStack entry : entries) {
int idx = findAndConsume(pool, entry.stack);
if (idx >= 0) matched.add(entry);
}

// Items in graveLoot that had no snapshot match (e.g. spawned by other mods)
// are added without origin info.
List<ItemStack> unmatched = new ArrayList<ItemStack>(pool);
List<ItemStack> unmatched = new ArrayList<>(pool);

GenericInventory inv = new GenericInventory("tmpplayer", false, matched.size() + unmatched.size());
int graveSlot = 0;
Expand Down
17 changes: 5 additions & 12 deletions src/main/java/openblocks/common/GraveSlotOrigin.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,16 @@

import net.minecraft.nbt.NBTTagCompound;

public class GraveSlotOrigin {
public record GraveSlotOrigin(String inventoryType, int slot) {

public static final String INV_MAIN = "main";
public static final String INV_ARMOR = "armor";
public static final String INV_TCONSTRUCT = "tconstruct";
public static final String INV_BAUBLES = "baubles";
public static final String INV_ADVENTURE_BACKPACK = "adventurebackpack";
public static final String INV_MC_BACKPACK = "mcbackpack";
public static final String INV_BAUBLES = "baubles";
public static final String INV_COSMETIC_ARMOR = "cosmeticarmor";
public static final String INV_GALACTICRAFT = "galacticraft";

public final String inventoryType;
public final int slot;

public GraveSlotOrigin(String inventoryType, int slot) {
this.inventoryType = inventoryType;
this.slot = slot;
}
public static final String INV_MC_BACKPACK = "mcbackpack";
public static final String INV_TCONSTRUCT = "tconstruct";

public NBTTagCompound toNBT() {
NBTTagCompound tag = new NBTTagCompound();
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/openblocks/common/ModPresence.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ public final class ModPresence {

private ModPresence() {}

public static final boolean BAUBLES = Loader.isModLoaded("Baubles");
public static final boolean TCONSTRUCT = Loader.isModLoaded("TConstruct");
public static final boolean ADVENTURE_BACKPACK = Loader.isModLoaded("adventurebackpack");
public static final boolean MC_BACKPACK = Loader.isModLoaded("Backpack");
public static final boolean BAUBLES = Loader.isModLoaded("Baubles");
public static final boolean COSMETIC_ARMOR = Loader.isModLoaded("cosmeticarmorreworked");
public static final boolean GALACTICRAFT = Loader.isModLoaded("GalacticraftCore");
public static final boolean MC_BACKPACK = Loader.isModLoaded("Backpack");
public static final boolean TCONSTRUCT = Loader.isModLoaded("TConstruct");
}