Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;

import tconstruct.library.modifier.IModifyable;
import tconstruct.library.tools.AbilityHelper;
import com.darkona.adventurebackpack.util.TinkersUtils;

public class SlotCraftResult extends SlotCrafting {

Expand All @@ -23,9 +22,9 @@ public SlotCraftResult(ContainerBackpack container, EntityPlayer player, IInvent
public void onPickupFromSlot(EntityPlayer player, ItemStack stack) {
eventHandler.syncCraftMatrixWithInventory(true); // pre craft sync
ItemStack tool = eventHandler.craftMatrix.getStackInSlot(4);
if (stack.getItem() instanceof IModifyable && tool != null && tool.getItem() instanceof IModifyable) {
IModifyable modifyable = (IModifyable) stack.getItem();
NBTTagCompound tags = stack.getTagCompound().getCompoundTag(modifyable.getBaseTagName());
if (TinkersUtils.isModifyable(stack) && TinkersUtils.isModifyable(tool)) {
String tagName = TinkersUtils.getBaseTagName(stack);
NBTTagCompound tags = stack.getTagCompound().getCompoundTag(tagName);
int[] toRemoveArray = tags.hasKey("ToRemove") ? tags.getIntArray("ToRemove") : null;
int toRemoveIndex = 0;
IInventory inventory = eventHandler.craftMatrix;
Expand All @@ -52,7 +51,7 @@ public void onPickupFromSlot(EntityPlayer player, ItemStack stack) {
player.posZ,
"tinker:little_saw",
1.0F,
(AbilityHelper.random.nextFloat() - AbilityHelper.random.nextFloat()) * 0.2F + 1.0F);
(player.worldObj.rand.nextFloat() - player.worldObj.rand.nextFloat()) * 0.2F + 1.0F);
} else {
super.onPickupFromSlot(player, stack);
}
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/com/darkona/adventurebackpack/util/TinkersUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,22 @@ public final class TinkersUtils {
private static Class<?> craftingStation;
private static Object craftingStationInstance;

private static final String CLASS_IMODIFYABLE = "tconstruct.library.modifier.IModifyable";
private static Class<?> modifyableClass;
private static java.lang.reflect.Method getBaseTagNameMethod;

private TinkersUtils() {}

static {
if (LoadedMods.TCONSTRUCT) {
createCraftingStationInstance();

try {
modifyableClass = Class.forName(CLASS_IMODIFYABLE);
getBaseTagNameMethod = modifyableClass.getMethod("getBaseTagName");
} catch (Exception e) {
LogHelper.error("Error getting Tinkers IModifyable class or getBaseTagName method: " + e);
}
}
}

Expand Down Expand Up @@ -73,6 +84,25 @@ private static InventoryPlayer getInventoryPlayer() {
return invPlayer;
}

public static boolean isModifyable(ItemStack stack) {
if (!LoadedMods.TCONSTRUCT || stack == null || stack.getItem() == null || modifyableClass == null) return false;
return modifyableClass.isInstance(stack.getItem());
}

public static String getBaseTagName(ItemStack stack) {
if (!LoadedMods.TCONSTRUCT || stack == null
|| stack.getItem() == null
|| modifyableClass == null
|| getBaseTagNameMethod == null)
return "InfiTool";
try {
if (modifyableClass.isInstance(stack.getItem())) {
return (String) getBaseTagNameMethod.invoke(stack.getItem());
}
} catch (Exception e) {}
return "InfiTool";
}

public static boolean isToolOrWeapon(@Nullable ItemStack stack) {
if (stack == null) return false;

Expand Down