- Improved IC2 implementation

- Fixed multiply operator on liquid stacks
This commit is contained in:
Stan Hebben committed 2014-06-29 18:36:29 +02:00
1 parent ea0d369519
commit fd9bf8b080
17 files changed
+843 -7

No files matched your search

@@ -49,6 +49,12 @@ public interface IItemStack extends IIngredient {
@ZenMethod
public IItemStack amount(int amount);
@ZenOperator(OperatorType.MOD)
public WeightedItemStack percent(float p);
@ZenMethod
public WeightedItemStack weight(float p);
@ZenMethod
public IIngredient anyDamage();
@@ -0,0 +1,69 @@
/*
* 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.api.item;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenGetter;
/**
*
* @author Stan
*/
@ZenClass("minetweaker.item.WeightedItemStack")
public final class WeightedItemStack {
private final IItemStack stack;
private final float p;
public WeightedItemStack(IItemStack stack, float p) {
this.stack = stack;
this.p = p;
}
@ZenGetter("stack")
public IItemStack getStack() {
return stack;
}
@ZenGetter("chance")
public float getChance() {
return p;
}
@ZenGetter("percent")
public float getPercent() {
return p * 100;
}
// #############################
// ### Object implementation ###
// #############################
@Override
public int hashCode() {
int hash = 7;
hash = 29 * hash + (this.stack != null ? this.stack.hashCode() : 0);
hash = 29 * hash + Float.floatToIntBits(this.p);
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final WeightedItemStack other = (WeightedItemStack) obj;
if (this.stack != other.stack && (this.stack == null || !this.stack.equals(other.stack))) {
return false;
}
if (Float.floatToIntBits(this.p) != Float.floatToIntBits(other.p)) {
return false;
}
return true;
}
}
@@ -7,9 +7,11 @@
package minetweaker.api.liquid;
import minetweaker.api.data.IData;
import stanhebben.zenscript.annotations.OperatorType;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenGetter;
import stanhebben.zenscript.annotations.ZenMethod;
import stanhebben.zenscript.annotations.ZenOperator;
/**
*
@@ -50,6 +52,7 @@ public interface ILiquidStack {
@ZenMethod
public ILiquidStack withTag(IData data);
@ZenOperator(OperatorType.MUL)
@ZenMethod
public ILiquidStack withAmount(int amount);
@@ -0,0 +1,24 @@
/*
* 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.expand;
import minetweaker.api.item.IItemStack;
import minetweaker.api.item.WeightedItemStack;
import stanhebben.zenscript.annotations.ZenCaster;
import stanhebben.zenscript.annotations.ZenExpansion;
/**
*
* @author Stan
*/
@ZenExpansion("minetweaker.item.IItemStack")
public class ExpandItemStack {
@ZenCaster
public static WeightedItemStack asWeightedItemStack(IItemStack value) {
return new WeightedItemStack(value, 1.0f);
}
}
@@ -14,6 +14,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -36,7 +37,8 @@ import stanhebben.zenscript.parser.ParseException;
*/
public class Tweaker implements IMineTweaker {
private final List<IUndoableAction> actions = new ArrayList<IUndoableAction>();
private final Set<IUndoableAction> wereStuck = new HashSet<IUndoableAction>();
private final Set<IUndoableAction> wereStuck = new LinkedHashSet<IUndoableAction>();
private final Map<Object, IUndoableAction> stuckOverridable = new HashMap<Object, IUndoableAction>();
private IScriptProvider scriptProvider;
private byte[] scriptData;
@@ -44,8 +46,23 @@ public class Tweaker implements IMineTweaker {
@Override
public void apply(IUndoableAction action) {
MineTweakerAPI.logger.logInfo(action.describe());
action.apply();
actions.add(action);
Object overrideKey = action.getOverrideKey();
if (wereStuck.contains(action)) {
wereStuck.remove(action);
if (overrideKey != null) {
stuckOverridable.remove(overrideKey);
}
} else {
if (overrideKey != null && stuckOverridable.containsKey(overrideKey)) {
wereStuck.remove(stuckOverridable.get(overrideKey));
stuckOverridable.remove(overrideKey);
}
action.apply();
actions.add(action);
}
}
@Override
@@ -65,6 +82,11 @@ public class Tweaker implements IMineTweaker {
MineTweakerAPI.logger.logInfo("[Stuck] " + action.describe());
stuck.add(0, action);
wereStuck.add(action);
Object overrideKey = action.getOverrideKey();
if (overrideKey != null) {
stuckOverridable.put(overrideKey, action);
}
}
}
actions.clear();