Skip to content

Commit

Permalink
Implement failsafe catch for headless servers without a Clipboard. Ha…
Browse files Browse the repository at this point in the history
…ve NEI handle the hiding of names the same as adding them, regarding logging anyway. Fix #239 regarding to blockHardness in a reobfuscated environement.
  • Loading branch information
Mary committed Sep 28, 2015
1 parent 28a8e50 commit a82955c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -679,9 +679,12 @@ public static void addMineTweakerCommand(String name, String[] description, ICom
// ##############################

private static void copyToClipboard(String value) {
StringSelection stringSelection = new StringSelection(value);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(stringSelection, null);
try {
StringSelection stringSelection = new StringSelection(value);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(stringSelection, null);
} catch (Throwable e) {
}
}

// ############################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import minetweaker.MineTweakerAPI;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import cpw.mods.fml.relauncher.ReflectionHelper;
import cpw.mods.fml.common.ObfuscationReflectionHelper;

/**
*
Expand All @@ -25,7 +25,7 @@ public class SetBlockHardnessAction implements IUndoableAction {
public SetBlockHardnessAction(ItemStack stack, float hardness) {
this.stack = stack;
this.hardness = hardness;
this.oldHardness = ReflectionHelper.getPrivateValue(Block.class, Block.getBlockFromItem(stack.getItem()), "blockHardness");
this.oldHardness = ObfuscationReflectionHelper.getPrivateValue(Block.class, Block.getBlockFromItem(stack.getItem()), "field_149782_v");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import java.util.Collections;
import java.util.List;

import cpw.mods.fml.relauncher.ReflectionHelper;
import cpw.mods.fml.common.ObfuscationReflectionHelper;
import minetweaker.MineTweakerAPI;
import minetweaker.api.block.IBlock;
import minetweaker.api.data.DataMap;
Expand Down Expand Up @@ -122,7 +122,7 @@ public void setMaxStackSize(int size) {

@Override
public float getBlockHardness() {
return ReflectionHelper.getPrivateValue(Block.class, Block.getBlockFromItem(stack.getItem()), "blockHardness");
return ObfuscationReflectionHelper.getPrivateValue(Block.class, Block.getBlockFromItem(stack.getItem()), "field_149782_v");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ public Object getOverrideKey() {
}

private static class NEIHideItemAction implements IUndoableAction {
private final ItemStack stack;
private final ItemStack item;

public NEIHideItemAction(ItemStack stack) {
this.stack = stack;
public NEIHideItemAction(ItemStack item) {
this.item = item;
}

@Override
public void apply() {
API.hideItem(stack);
API.hideItem(item);
}

@Override
Expand All @@ -119,17 +119,17 @@ public boolean canUndo() {

@Override
public void undo() {
API.addItemListEntry(stack);
API.addItemListEntry(item);
}

@Override
public String describe() {
return "Hiding " + stack.getUnlocalizedName() + " in NEI";
return "Hiding " + item.getDisplayName() + " in NEI";
}

@Override
public String describeUndo() {
return "Displaying " + stack.getUnlocalizedName() + " in NEI";
return "Displaying " + item.getDisplayName() + " in NEI";
}

@Override
Expand Down

0 comments on commit a82955c

Please sign in to comment.