Created
January 29, 2014 13:28
-
-
Save copygirl/8687945 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package stanhebben.minetweaker.mods.te; | |
import static stanhebben.minetweaker.api.value.TweakerValue.notNull; | |
import net.minecraft.item.ItemStack; | |
import net.minecraft.nbt.NBTTagCompound; | |
import net.minecraftforge.fluids.FluidStack; | |
import stanhebben.minetweaker.api.Tweaker; | |
import stanhebben.minetweaker.api.value.TweakerValue; | |
import stanhebben.minetweaker.mods.te.actions.ThermalExpansionAction; | |
public class ThermalExpansionUtil { | |
private ThermalExpansionUtil() {} | |
public static Integer getInt(TweakerValue[] arguments, int index, String name) { | |
return arguments.length >= index ? null : | |
notNull(arguments[index], name + " cannot be null") | |
.toInt(name + " must be an int").get(); | |
} | |
public static Boolean getBool(TweakerValue[] arguments, int index, String name) { | |
return arguments.length >= index ? null : | |
notNull(arguments[index], name + " cannot be null") | |
.toBool(name + " must be a bool").get(); | |
} | |
public static ItemStack getItemStack(TweakerValue[] arguments, int index, String name) { | |
return arguments.length >= index ? null : | |
notNull(arguments[index], name + " cannot be null") | |
.toItemStack(name + " must be an item stack").get(); | |
} | |
public static FluidStack getFluidStack(TweakerValue[] arguments, int index, String name) { | |
return arguments.length >= index ? null : | |
notNull(arguments[index], name + " cannot be null") | |
.toFluidStack(name + " must be a fluid stack").get(); | |
} | |
public static void applyAction(String key, String description, Object... values) { | |
NBTTagCompound nbt = new NBTTagCompound(); | |
for (int i = 0; i < values.length; i += 2) { | |
String name = (String)values[i]; | |
Object value = values[i + 1]; | |
if (value instanceof Integer) { | |
nbt.setInteger(name, (Integer)value); | |
} else if (value instanceof Boolean) { | |
nbt.setBoolean(name, (Boolean)value); | |
} else if (value instanceof ItemStack) { | |
nbt.setCompoundTag(name, ((ItemStack)value).writeToNBT(new NBTTagCompound())); | |
} else if (value instanceof FluidStack) { | |
nbt.setCompoundTag(name, ((FluidStack)value).writeToNBT(new NBTTagCompound())); | |
} | |
} | |
Tweaker.apply(new ThermalExpansionAction(key, nbt, description)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment