Skip to content

Instantly share code, notes, and snippets.

@kindlich
Created April 20, 2018 20:45
Show Gist options
  • Select an option

  • Save kindlich/6741c971c795bf47a17b958ffc85f65d to your computer and use it in GitHub Desktop.

Select an option

Save kindlich/6741c971c795bf47a17b958ffc85f65d to your computer and use it in GitHub Desktop.
import crafttweaker.data.IData;
import crafttweaker.item.IIngredient;
var backpack = <improvedbackpacks:backpack>;
var ironBackpacksIngredient as IIngredient =
<ironbackpacks:backpack>.withTag({packInfo: {upgrade: [], type: "ironbackpacks:basic", spec: "NONE"}}) |
<ironbackpacks:backpack>.withTag({packInfo: {upgrade: [], type: "ironbackpacks:iron", spec: "STORAGE"}}) |
<ironbackpacks:backpack>.withTag({packInfo: {upgrade: [], type: "ironbackpacks:gold", spec: "STORAGE"}}) |
<ironbackpacks:backpack>.withTag({packInfo: {upgrade: [], type: "ironbackpacks:diamond", spec: "STORAGE"}});
for ironBackpacksBackpack in ironBackpacksIngredient.items {
var type as string = ironBackpacksBackpack.tag.packInfo.type.asString();
type = type.replace("ironbackpacks:", "");
recipes.addShapeless(
"ct-improvedbackpacks-backpack-transfer-" ~ type,
ironBackpacksBackpack,
[
backpack.marked("bag"),
ironBackpacksIngredient.marked("ironbackpack")
],
//Recipe Function
function(out, ins, cInfo) {
val backPack = ins.bag;
val ironBackPack = ins.ironbackpack;
if(isNull(backPack) | isNull(ironBackPack) | isNull(backPack.tag.Items))
return null;
//Slots = 18 + Tier * 9
val backPackTag = backPack.tag;
var ironTag = ironBackPack.tag;
val slots as int = isNull(backPackTag.Tier) ? 18 : (18 + backPackTag.Tier.asInt() * 9);
print("IRON: " ~ ironTag.asString());
print("BACK: " ~ backPackTag.asString());
var newTag as IData = null;
if(!(ironTag has "packInv")) {
var tag as IData = [{id: "minecraft:air", Count: 1 as byte, Damage: 0 as short}];
for i in 1 .. slots {
tag += [{id: "minecraft:air", Count: 1 as byte, Damage: 0 as short}];
}
ironTag = ironTag.update({packInv : tag});
}
if(ironTag has "packInv" & ironTag.packInv.asList().length >= slots)
for i in 0 .. slots {
print(i);
val tT = ironTag.packInv[i];
val tTag = tT.id;
if(!isNull(tTag) & "minecraft:air" == tTag.asString() & backPackTag has "Items"){
print("to function");
val item as IData = getItemForSlot(backPackTag.Items.asList(), i as IData);
if(isNull(item)){
print("itemNull");
if(isNull(newTag))
newTag = [ironTag.packInv[i]];
else
newTag += [ironTag.packInv[i]];
} else{
print("itemNonNull");
val tagToAdd as IData = {
id : (isNull(item.id) ? "minecraft:air" as IData : item.id),
Count : (isNull(item.Count) ? 1 as IData : item.Count),
Damage: (isNull(item.Damage) ? 0 as IData : item.Damage)
//NBT?
};
if(isNull(newTag))
newTag = [tagToAdd];
else
newTag += [tagToAdd];
}
} else {
print("stuff");
val tagToAdd as IData = ironTag.packInv[i];
if(isNull(newTag))
newTag = [tagToAdd];
else
newTag += [tagToAdd];
}
}
print(newTag.asString());
return ironBackPack.updateTag({packInv : newTag});
},
//recipeAction (null)
null
);
}
function getItemForSlot(items as [IData], slotNr as IData) as IData {
for item in items {
if(item has "Slot" & slotNr == item.Slot)
return item;
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment