mirror of
https://github.com/GTNewHorizons/CraftTweaker.git
synced 2026-11-21 04:22:19 +00:00
Merge pull request #227 from jaredlll08/master
Closes a bunch of issues (including #160), added block hardness.
This commit is contained in:
commit
e56f88e635
14 files changed
+149
-30
No files matched your search
+3
-1
@@ -32,4 +32,6 @@ run
|
||||
usernamecache.json
|
||||
MineTweaker3-MC1710-Main/eclipse/.metadata/.plugins/org.eclipse.core.resources/.projects/Minecraft/.location
|
||||
*.location
|
||||
MineTweaker3-MC1710-Main/eclipse/.metadata/.plugins/org.eclipse.core.resources/.projects/Minecraft/.location
|
||||
MineTweaker3-MC1710-Main/eclipse/.metadata/.plugins/org.eclipse.core.resources/.projects/Minecraft/.location
|
||||
MineTweaker3-MC164-Main/bin/assets/minetweaker/logo.png
|
||||
MineTweaker3-MC164-Main/bin/mcmod.info
|
||||
@@ -211,20 +211,23 @@ public class MineTweakerImplementationAPI {
|
||||
}
|
||||
} else if (arguments[0].equals("hand") && player != null) {
|
||||
IItemStack item = player.getCurrentItem();
|
||||
if (item != null) {
|
||||
List<ICraftingRecipe> recipes = MineTweakerAPI.recipes.getRecipesFor(item.anyAmount());
|
||||
if (recipes.isEmpty()) {
|
||||
player.sendChat("No crafting recipes found for that item");
|
||||
} else {
|
||||
StringBuilder recipesString = new StringBuilder();
|
||||
|
||||
List<ICraftingRecipe> recipes = MineTweakerAPI.recipes.getRecipesFor(item.anyAmount());
|
||||
if (recipes.isEmpty()) {
|
||||
player.sendChat("No crafting recipes found for that item");
|
||||
} else {
|
||||
StringBuilder recipesString = new StringBuilder();
|
||||
for (ICraftingRecipe recipe : recipes) {
|
||||
MineTweakerAPI.logCommand(recipe.toCommandString());
|
||||
player.sendChat(recipe.toCommandString());
|
||||
recipesString.append(recipe.toCommandString()).append("\n");
|
||||
}
|
||||
|
||||
for (ICraftingRecipe recipe : recipes) {
|
||||
MineTweakerAPI.logCommand(recipe.toCommandString());
|
||||
player.sendChat(recipe.toCommandString());
|
||||
recipesString.append(recipe.toCommandString()).append("\n");
|
||||
copyToClipboard(recipesString.toString());
|
||||
}
|
||||
|
||||
copyToClipboard(recipesString.toString());
|
||||
} else {
|
||||
player.sendChat("No item was found");
|
||||
}
|
||||
} else {
|
||||
if (player != null) {
|
||||
|
||||
@@ -15,4 +15,5 @@ public interface IBlockDefinition {
|
||||
|
||||
@ZenGetter("displayName")
|
||||
public String getDisplayName();
|
||||
|
||||
}
|
||||
@@ -7,6 +7,7 @@
|
||||
package minetweaker.api.block;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import stanhebben.zenscript.annotations.OperatorType;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
|
||||
@@ -80,6 +80,20 @@ public interface IItemStack extends IIngredient {
|
||||
*/
|
||||
@ZenSetter("maxStackSize")
|
||||
public void setMaxStackSize(int size);
|
||||
|
||||
/**
|
||||
* Gets the block hardness
|
||||
*/
|
||||
@ZenGetter("hardness")
|
||||
public float getBlockHardness();
|
||||
|
||||
/**
|
||||
* Sets the block hardness
|
||||
*
|
||||
* @param hardness the new hardness
|
||||
*/
|
||||
@ZenSetter("hardness")
|
||||
public void setBlockHardness(float hardness);
|
||||
|
||||
/**
|
||||
* Gets the item damage. Returns 0 if the item cannot be damaged.
|
||||
|
||||
@@ -21,10 +21,12 @@ import cpw.mods.fml.common.registry.VillagerRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Set;
|
||||
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.MineTweakerImplementationAPI;
|
||||
import minetweaker.api.logger.FileLogger;
|
||||
import minetweaker.mc1710.brackets.ItemBracketHandler;
|
||||
import minetweaker.mc1710.client.MCClient;
|
||||
import minetweaker.mc1710.formatting.MCFormatter;
|
||||
import minetweaker.mc1710.furnace.FuelTweaker;
|
||||
@@ -47,6 +49,7 @@ import minetweaker.runtime.IScriptProvider;
|
||||
import minetweaker.runtime.providers.ScriptProviderCascade;
|
||||
import minetweaker.runtime.providers.ScriptProviderCustom;
|
||||
import minetweaker.runtime.providers.ScriptProviderDirectory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
@@ -152,7 +155,9 @@ public class MineTweakerMod {
|
||||
public void onServerAboutToStart(FMLServerAboutToStartEvent ev) {
|
||||
// starts before loading worlds
|
||||
// perfect place to start MineTweaker!
|
||||
|
||||
for (String itemName : (Set<String>) Item.itemRegistry.getKeys()) {
|
||||
ItemBracketHandler.itemNames.put(itemName.replace(" ", ""), (Item) Item.itemRegistry.getObject(itemName));
|
||||
}
|
||||
if (MineTweakerPlatformUtils.isClient()) {
|
||||
MineTweakerAPI.client = new MCClient();
|
||||
}
|
||||
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mc1710.actions;
|
||||
|
||||
import minetweaker.IUndoableAction;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import cpw.mods.fml.relauncher.ReflectionHelper;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Jared
|
||||
*/
|
||||
public class SetBlockHardnessAction implements IUndoableAction {
|
||||
|
||||
private final ItemStack stack;
|
||||
private final float hardness;
|
||||
private final float oldHardness;
|
||||
|
||||
public SetBlockHardnessAction(ItemStack stack, float hardness) {
|
||||
this.stack = stack;
|
||||
this.hardness = hardness;
|
||||
this.oldHardness = ReflectionHelper.getPrivateValue(Block.class, Block.getBlockFromItem(stack.getItem()), "blockHardness");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
if (isBlock(stack)) {
|
||||
set(stack, hardness);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
if (isBlock(stack))
|
||||
set(stack, oldHardness);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
if (isBlock(stack)) {
|
||||
return "Setting hardness of " + stack.getDisplayName() + " to " + hardness;
|
||||
}
|
||||
return "Unable to set hardness of " + stack.getDisplayName() + " because it is an Item";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
if (isBlock(stack)) {
|
||||
return "Reverting hardness of " + stack.getDisplayName() + " to " + oldHardness;
|
||||
}
|
||||
return "Unable to revert hardness of " + stack.getDisplayName() + " because it is an Item";
|
||||
}
|
||||
|
||||
private static void set(ItemStack stack, float hardness) {
|
||||
if (isBlock(stack)) {
|
||||
Block block = Block.getBlockFromItem(stack.getItem());
|
||||
block.setHardness(hardness);
|
||||
} else {
|
||||
MineTweakerAPI.logError("Item is not a block");
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isBlock(ItemStack stack) {
|
||||
String name = Block.blockRegistry.getNameForObject(Block.getBlockFromItem(stack.getItem()));
|
||||
return !name.equalsIgnoreCase("minecraft:air") && Block.blockRegistry.containsKey(name);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+3
@@ -56,6 +56,9 @@ public class SetTranslationAction implements IUndoableAction {
|
||||
}
|
||||
|
||||
private static void set(String key, String value) {
|
||||
if (value.contains("\\\"")) {
|
||||
value = value.replace("\\\"", "\"");
|
||||
}
|
||||
StringTranslate.inject(new ByteArrayInputStream((key + "=" + value).getBytes(UTF8)));
|
||||
}
|
||||
|
||||
|
||||
+1
-8
@@ -36,14 +36,7 @@ import stanhebben.zenscript.util.ZenPosition;
|
||||
*/
|
||||
@BracketHandler(priority = 100)
|
||||
public class ItemBracketHandler implements IBracketHandler {
|
||||
private static final Map<String, Item> itemNames;
|
||||
|
||||
static {
|
||||
itemNames = new HashMap<String, Item>();
|
||||
for (String itemName : (Set<String>) Item.itemRegistry.getKeys()) {
|
||||
itemNames.put(itemName.replace(" ", ""), (Item) Item.itemRegistry.getObject(itemName));
|
||||
}
|
||||
}
|
||||
public static final Map<String, Item> itemNames = new HashMap<String, Item>();
|
||||
|
||||
public static IItemStack getItem(String name, int meta) {
|
||||
// Item item = (Item) Item.itemRegistry.getObject(name);
|
||||
|
||||
@@ -12,6 +12,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import cpw.mods.fml.relauncher.ReflectionHelper;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.api.block.IBlock;
|
||||
import minetweaker.api.data.DataMap;
|
||||
@@ -27,6 +28,7 @@ import minetweaker.api.item.WeightedItemStack;
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import minetweaker.api.oredict.IOreDictEntry;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.mc1710.actions.SetBlockHardnessAction;
|
||||
import minetweaker.mc1710.actions.SetStackSizeAction;
|
||||
import minetweaker.mc1710.actions.SetTranslationAction;
|
||||
import minetweaker.mc1710.block.MCItemBlock;
|
||||
@@ -111,6 +113,16 @@ public class MCItemStack implements IItemStack {
|
||||
MineTweakerAPI.apply(new SetStackSizeAction((ItemStack) getInternal(), size));
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getBlockHardness() {
|
||||
return ReflectionHelper.getPrivateValue(Block.class, Block.getBlockFromItem(stack.getItem()), "blockHardness");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlockHardness(float hardness) {
|
||||
MineTweakerAPI.apply(new SetBlockHardnessAction(stack, hardness));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDamage() {
|
||||
return stack.getItemDamage();
|
||||
@@ -260,7 +272,7 @@ public class MCItemStack implements IItemStack {
|
||||
@Override
|
||||
public boolean matches(IItemStack item) {
|
||||
ItemStack internal = getItemStack(item);
|
||||
return internal.getItem() == stack.getItem() && (wildcardSize || internal.stackSize >= stack.stackSize) && (stack.getItemDamage() == OreDictionary.WILDCARD_VALUE || stack.getItemDamage() == internal.getItemDamage() || (!stack.getHasSubtypes() && !stack.getItem().isDamageable()));
|
||||
return internal !=null && stack !=null &&internal.getItem() == stack.getItem() && (wildcardSize || internal.stackSize >= stack.stackSize) && (stack.getItemDamage() == OreDictionary.WILDCARD_VALUE || stack.getItemDamage() == internal.getItemDamage() || (!stack.getHasSubtypes() && !stack.getItem().isDamageable()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -293,10 +305,11 @@ public class MCItemStack implements IItemStack {
|
||||
|
||||
@Override
|
||||
public IBlock asBlock() {
|
||||
if (Block.getBlockFromItem(stack.getItem()) == null) {
|
||||
throw new ClassCastException("This item is not a block");
|
||||
} else {
|
||||
String name = Block.blockRegistry.getNameForObject(Block.getBlockFromItem(stack.getItem()));
|
||||
if (Block.blockRegistry.containsKey(name)) {
|
||||
return new MCItemBlock(stack);
|
||||
} else {
|
||||
throw new ClassCastException("This item is not a block");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ public class MCServer extends AbstractServer {
|
||||
return true;
|
||||
|
||||
UserListOps ops = MinecraftServer.getServer().getConfigurationManager().func_152603_m();
|
||||
if (server.isDedicatedServer()) {
|
||||
if (server.isDedicatedServer() && ops != null) {
|
||||
return ops.func_152690_d() || ops.func_152700_a(player.getName()) != null;
|
||||
} else {
|
||||
return true;
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ import stanhebben.zenscript.annotations.ZenMethod;
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("mods.mfr.AutoSpawner")
|
||||
@ZenClass("mods.mfr.SafariNet")
|
||||
@ModOnly("MineFactoryReloaded")
|
||||
public class SafariNet {
|
||||
@ZenMethod
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
ext.mineTweakerVersion = "3.0.9D_alpha"
|
||||
ext.mineTweakerDebug = "false"
|
||||
ext.javaToolsJar = new File("C:/Program Files/Java/jdk1.8.0_05/lib/tools.jar")
|
||||
ext.javaToolsJar = new File("C:/Program Files/Java/jdk1.8.0_45/lib/tools.jar")
|
||||
|
||||
// ######################
|
||||
// ### 1.6.4 settings ###
|
||||
@@ -37,7 +37,7 @@ ext.projects172 = [
|
||||
// ### 1.7.10 settings ###
|
||||
// #######################
|
||||
|
||||
ext.forgeVersion1710 = "1.7.10-10.13.2.1291"
|
||||
ext.forgeVersion1710 = "1.7.10-10.13.4.1448-1.7.10"
|
||||
ext.projects1710 = [
|
||||
'MineTweaker3-MC1710-Main',
|
||||
'MineTweaker3-MC1710-Mod-IC2',
|
||||
|
||||
@@ -34,7 +34,7 @@ The following global tasks are available:
|
||||
|
||||
### Adding mod support
|
||||
|
||||
When starting a new mod support library, it is best to start from an existing one. For instance, copy the NEI support library, and remove the source files inside the src/java/main directory. Then you can work with it like any other support library. Make sure to update gradle.properties to add the projects in there.
|
||||
When starting a new mod support library, it is best to start from an existing one. For instance, copy the NEI support library, and remove the source files inside the src/java/main directory. Then you can work with it like any other support library. Make sure to update configuration.gradle to add the projects in there.
|
||||
|
||||
### Building a release
|
||||
|
||||
|
||||
Reference in new issue
Block a user