mirror of
https://github.com/GTNewHorizons/CraftTweaker.git
synced 2026-11-21 20:42:16 +00:00
Tons of changes:
- Added interface to game, client and server - Added transformations - Made ingredient conditions more practical to use, no longer requires imports - Started implementation of event handling - Moved commands and logic to the common API code - Added common interface to MineTweaker recipes - Added string methods - Moved the logger from static value to static getter - Fixed crashes on dedicated servers - Fixed bracket resolution for <id:meta> values in 1.6.4 - Fixed scripts not being sent to multiplayer clients in 1.6.4
This commit is contained in:
1 parent
7f6235f30d
commit
115593efa5
131 files changed
+3215
-1930
No files matched your search
+6
-6
@@ -4,9 +4,9 @@
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.world;
|
||||
package minetweaker.api.client;
|
||||
|
||||
import java.util.List;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
|
||||
@@ -14,8 +14,8 @@ import stanhebben.zenscript.annotations.ZenGetter;
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.world.IGame")
|
||||
public interface IGame {
|
||||
@ZenGetter("dimensions")
|
||||
public List<IDimension> getDimensions();
|
||||
@ZenClass("minetweaker.api.IClient")
|
||||
public interface IClient {
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer();
|
||||
}
|
||||
@@ -203,6 +203,10 @@ public class DataMap implements IData {
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
if (data instanceof DataString) {
|
||||
return this.data.containsKey(data.asString());
|
||||
}
|
||||
|
||||
Map<String, IData> dataMap = data.asMap();
|
||||
for (Map.Entry<String, IData> dataEntry : dataMap.entrySet()) {
|
||||
if (!this.data.containsKey(dataEntry.getKey())) {
|
||||
|
||||
+24
-1
@@ -12,7 +12,30 @@ import minetweaker.util.EventList;
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class AbstractEventManager implements IEventManager {
|
||||
public class MTEventManager implements IEventManager {
|
||||
public void clear() {
|
||||
elPlayerCrafted.clear();
|
||||
elPlayerSmelted.clear();
|
||||
elPlayerChangedDimension.clear();
|
||||
elPlayerLoggedIn.clear();
|
||||
elPlayerLoggedOut.clear();
|
||||
elPlayerRespawn.clear();
|
||||
elPlayerAttackEntity.clear();
|
||||
elPlayerBonemeal.clear();
|
||||
elPlayerInteractEntity.clear();
|
||||
elPlayerPickup.clear();
|
||||
elPlayerPickupItem.clear();
|
||||
elPlayerFillBucket.clear();
|
||||
elPlayerDeathDrops.clear();
|
||||
elPlayerInteract.clear();
|
||||
elPlayerOpenContainer.clear();
|
||||
elPlayerPickupXp.clear();
|
||||
elPlayerSleepInBed.clear();
|
||||
elPlayerUseHoe.clear();
|
||||
elPlayerUseItemStart.clear();
|
||||
elPlayerUseItemTick.clear();
|
||||
}
|
||||
|
||||
// ##########################
|
||||
// ### PlayerCraftedEvent ###
|
||||
// ##########################
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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.game;
|
||||
|
||||
import java.util.List;
|
||||
import minetweaker.api.item.IItemDefinition;
|
||||
import minetweaker.api.liquid.ILiquidDefinition;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.game.IGame")
|
||||
public interface IGame {
|
||||
@ZenGetter("items")
|
||||
public List<IItemDefinition> getItems();
|
||||
|
||||
@ZenGetter("liquids")
|
||||
public List<ILiquidDefinition> getLiquids();
|
||||
}
|
||||
@@ -115,6 +115,9 @@ public interface IIngredient {
|
||||
@ZenMethod
|
||||
public IItemStack applyTransform(IItemStack item);
|
||||
|
||||
@ZenGetter("hasTransformations")
|
||||
public boolean hasTransformers();
|
||||
|
||||
/**
|
||||
* Gets the internal item backing this ingredient.
|
||||
*
|
||||
|
||||
@@ -6,7 +6,11 @@
|
||||
|
||||
package minetweaker.api.item;
|
||||
|
||||
import stanhebben.zenscript.annotations.Optional;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
import stanhebben.zenscript.annotations.ZenSetter;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -14,5 +18,12 @@ import stanhebben.zenscript.annotations.ZenClass;
|
||||
*/
|
||||
@ZenClass("minetweaker.item.IItemDefinition")
|
||||
public interface IItemDefinition {
|
||||
@ZenGetter("id")
|
||||
public String getId();
|
||||
|
||||
@ZenGetter("name")
|
||||
public String getName();
|
||||
|
||||
@ZenMethod
|
||||
public IItemStack makeStack(@Optional int meta);
|
||||
}
|
||||
@@ -70,6 +70,11 @@ public class IngredientAny implements IIngredient {
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTransformers() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternal() {
|
||||
return INTERNAL_ANY;
|
||||
|
||||
@@ -89,6 +89,11 @@ public class IngredientAnyAdvanced implements IIngredient {
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTransformers() {
|
||||
return transformers.length > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternal() {
|
||||
return IngredientAny.INTERNAL_ANY;
|
||||
|
||||
+28
-23
@@ -7,8 +7,7 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import minetweaker.api.data.IData;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenExpansion;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
@@ -18,104 +17,110 @@ import stanhebben.zenscript.annotations.ZenMethod;
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.item.Condition")
|
||||
public class Condition {
|
||||
@ZenExpansion("minetweaker.item.IIngredient")
|
||||
public class IngredientCondition {
|
||||
/**
|
||||
* Requires the item to be damaged. A damage value of 1 is enough.
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @return damaged condition
|
||||
*/
|
||||
@ZenGetter
|
||||
public static IItemCondition damaged() {
|
||||
return new IItemCondition() {
|
||||
@ZenMethod
|
||||
public static IIngredient onlyDamaged(IIngredient ingredient) {
|
||||
return ingredient.only(new IItemCondition() {
|
||||
@Override
|
||||
public boolean matches(IItemStack stack) {
|
||||
return stack.getDamage() > 0;
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Requires the item to be damaged with at least a specified amount.
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @param minDamage minimum damage
|
||||
* @return damage condition
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IItemCondition damageAtLeast(final int minDamage) {
|
||||
return new IItemCondition() {
|
||||
public static IIngredient onlyDamageAtLeast(IIngredient ingredient, final int minDamage) {
|
||||
return ingredient.only(new IItemCondition() {
|
||||
@Override
|
||||
public boolean matches(IItemStack stack) {
|
||||
return stack.getDamage() >= minDamage;
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Requires the item to be damaged with at most a specified amount. An
|
||||
* undamaged item is accepted.
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @param maxDamage maximum damage
|
||||
* @return damage condition
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IItemCondition damageAtMost(final int maxDamage) {
|
||||
return new IItemCondition() {
|
||||
public static IIngredient onlyDamageAtMost(IIngredient ingredient, final int maxDamage) {
|
||||
return ingredient.only(new IItemCondition() {
|
||||
@Override
|
||||
public boolean matches(IItemStack stack) {
|
||||
return stack.getDamage() <= maxDamage;
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Requires the item damage value to be between two values.
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @param minDamage minimum damage
|
||||
* @param maxDamage maximum damage
|
||||
* @return damage condition
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IItemCondition damageBetween(final int minDamage, final int maxDamage) {
|
||||
return new IItemCondition() {
|
||||
public static IIngredient onlyDamageBetween(IIngredient ingredient, final int minDamage, final int maxDamage) {
|
||||
return ingredient.only(new IItemCondition() {
|
||||
@Override
|
||||
public boolean matches(IItemStack stack) {
|
||||
return stack.getDamage() >= minDamage && stack.getDamage() <= maxDamage;
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Requires the item to contain at least the given tags. It is OK for the
|
||||
* item to contain more data, as remaining data is ignored.
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @param data required data
|
||||
* @return data condition
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IItemCondition data(final IData data) {
|
||||
return new IItemCondition() {
|
||||
public static IIngredient onlyWithTag(IIngredient ingredient, final IData data) {
|
||||
return ingredient.only(new IItemCondition() {
|
||||
@Override
|
||||
public boolean matches(IItemStack stack) {
|
||||
return stack.getTag() != null && stack.getTag().contains(data);
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Requires the input stack to contain at least the given number of items.
|
||||
* Used in combination with stack consuming recipes.
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @param amount required stack size
|
||||
* @return stack size condition
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IItemCondition stack(final int amount) {
|
||||
return new IItemCondition() {
|
||||
public static IIngredient onlyStack(IIngredient ingredient, final int amount) {
|
||||
return ingredient.only(new IItemCondition() {
|
||||
@Override
|
||||
public boolean matches(IItemStack stack) {
|
||||
return stack.getAmount() >= amount;
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -67,7 +67,7 @@ public class IngredientItem implements IIngredient {
|
||||
|
||||
@Override
|
||||
public boolean matches(IItemStack item) {
|
||||
if (!item.matches(item)) return false;
|
||||
if (!this.item.matches(item)) return false;
|
||||
|
||||
for (IItemCondition condition : conditions) {
|
||||
if (!condition.matches(item)) return false;
|
||||
@@ -95,6 +95,11 @@ public class IngredientItem implements IIngredient {
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTransformers() {
|
||||
return transformers.length > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternal() {
|
||||
return item.getInternal();
|
||||
|
||||
@@ -75,4 +75,9 @@ public class IngredientStack implements IIngredient {
|
||||
public Object getInternal() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTransformers() {
|
||||
return ingredient.hasTransformers();
|
||||
}
|
||||
}
|
||||
+26
-23
@@ -6,49 +6,51 @@
|
||||
|
||||
package minetweaker.api.item;
|
||||
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenExpansion;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.item.Transform")
|
||||
public class Transform {
|
||||
@ZenExpansion("minetweaker.item.IIngredient")
|
||||
public class IngredientTransform {
|
||||
/**
|
||||
* Makes the item reusable. Prevents consumption of the item upon crafting.
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @return reuse transformer
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IItemTransformer reuse() {
|
||||
return new IItemTransformer() {
|
||||
public static IIngredient reuse(IIngredient ingredient) {
|
||||
return ingredient.transform(new IItemTransformer() {
|
||||
@Override
|
||||
public IItemStack transform(IItemStack item) {
|
||||
return item.withAmount(item.getAmount() + 1);
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Damages the item. Also makes the item reusable. Will damage the item
|
||||
* for 1 point upon crafting and consume it when broken.
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @return damage transformer
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IItemTransformer damage() {
|
||||
return new IItemTransformer() {
|
||||
public static IIngredient transformDamage(IIngredient ingredient) {
|
||||
return ingredient.transform(new IItemTransformer() {
|
||||
@Override
|
||||
public IItemStack transform(IItemStack item) {
|
||||
int newDamage = item.getDamage() + 1;
|
||||
if (newDamage >= item.getMaxDamage()) {
|
||||
return item.withAmount(item.getAmount() - 1).withDamage(0);
|
||||
return item.withAmount(item.getAmount()).withDamage(0);
|
||||
} else {
|
||||
return item.withDamage(newDamage);
|
||||
return item.withAmount(item.getAmount() + 1).withDamage(newDamage);
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,12 +59,13 @@ public class Transform {
|
||||
* set the proper condition such that an almost-broken item becomes
|
||||
* invalid for crafting.
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @param damage damage to be applied
|
||||
* @return damage transformer
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IItemTransformer damage(final int damage) {
|
||||
return new IItemTransformer() {
|
||||
public static IIngredient transformDamage(IIngredient ingredient, final int damage) {
|
||||
return ingredient.transform(new IItemTransformer() {
|
||||
@Override
|
||||
public IItemStack transform(IItemStack item) {
|
||||
int newDamage = item.getDamage() + damage;
|
||||
@@ -72,26 +75,25 @@ public class Transform {
|
||||
return item.withDamage(newDamage);
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Causes the item to be replaced upon crafting. Can be used, for instance,
|
||||
* to return empty bottles or buckets.
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @param withItem replacement item
|
||||
* @return replacement transformer
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IItemTransformer replaceWith(IItemStack withItem) {
|
||||
final IItemStack result = withItem.withAmount(withItem.getAmount() + 1);
|
||||
|
||||
return new IItemTransformer() {
|
||||
public static IIngredient transformReplace(IIngredient ingredient, final IItemStack withItem) {
|
||||
return ingredient.transform(new IItemTransformer() {
|
||||
@Override
|
||||
public IItemStack transform(IItemStack item) {
|
||||
return result;
|
||||
return withItem.withAmount(withItem.getAmount() + 1);
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,16 +101,17 @@ public class Transform {
|
||||
* a minimum stack size too, as otherwise smaller stacks would still be
|
||||
* accepted for input.
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @param amount consumption amount
|
||||
* @return consuming transformer
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IItemTransformer consume(final int amount) {
|
||||
return new IItemTransformer() {
|
||||
public static IIngredient transformConsume(IIngredient ingredient, final int amount) {
|
||||
return ingredient.transform(new IItemTransformer() {
|
||||
@Override
|
||||
public IItemStack transform(IItemStack item) {
|
||||
return item.withAmount(Math.max(item.getAmount() - amount, 0) + 1);
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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.logger;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.io.Writer;
|
||||
import minetweaker.runtime.ILogger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class FileLogger implements ILogger {
|
||||
private final Writer writer;
|
||||
|
||||
public FileLogger(File output) {
|
||||
try {
|
||||
writer = new OutputStreamWriter(new FileOutputStream(output), "utf-8");
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
throw new RuntimeException("What the heck?");
|
||||
} catch (FileNotFoundException ex) {
|
||||
throw new RuntimeException("File not found");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logCommand(String message) {
|
||||
try {
|
||||
writer.write("COMMAND: " + message + "\n");
|
||||
writer.flush();
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logInfo(String message) {
|
||||
try {
|
||||
writer.write("INFO: " + message + "\n");
|
||||
writer.flush();
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logWarning(String message) {
|
||||
try {
|
||||
writer.write("WARNING: " + message + "\n");
|
||||
writer.flush();
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logError(String message) {
|
||||
try {
|
||||
writer.write("ERROR: " + message + "\n");
|
||||
writer.flush();
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* 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.logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import minetweaker.MineTweakerImplementationAPI;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.runtime.ILogger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MTLogger implements ILogger {
|
||||
private final List<ILogger> loggers = new ArrayList<ILogger>();
|
||||
private final List<IPlayer> players = new ArrayList<IPlayer>();
|
||||
private final List<String> unprocessed = new ArrayList<String>();
|
||||
|
||||
public void addLogger(ILogger logger) {
|
||||
loggers.add(logger);
|
||||
}
|
||||
|
||||
public void removeLogger(ILogger logger) {
|
||||
loggers.remove(logger);
|
||||
}
|
||||
|
||||
public void addPlayer(IPlayer player) {
|
||||
players.add(player);
|
||||
|
||||
if (!unprocessed.isEmpty()) {
|
||||
for (String message : unprocessed) {
|
||||
player.sendChat(MineTweakerImplementationAPI.platform.getMessage(message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void removePlayer(IPlayer player) {
|
||||
players.remove(player);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
unprocessed.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logCommand(String message) {
|
||||
for (ILogger logger : loggers) {
|
||||
logger.logCommand(message);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logInfo(String message) {
|
||||
for (ILogger logger : loggers) {
|
||||
logger.logInfo(message);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logWarning(String message) {
|
||||
for (ILogger logger : loggers) {
|
||||
logger.logWarning(message);
|
||||
}
|
||||
|
||||
String message2 = "WARNING: " + message;
|
||||
|
||||
if (players.isEmpty()) {
|
||||
unprocessed.add(message2);
|
||||
} else {
|
||||
for (IPlayer player : players) {
|
||||
player.sendChat(MineTweakerImplementationAPI.platform.getMessage(message2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logError(String message) {
|
||||
for (ILogger logger : loggers) {
|
||||
logger.logError(message);
|
||||
}
|
||||
|
||||
String message2 = "ERROR: " + message;
|
||||
|
||||
if (players.isEmpty()) {
|
||||
unprocessed.add(message2);
|
||||
} else {
|
||||
for (IPlayer player : players) {
|
||||
player.sendChat(MineTweakerImplementationAPI.platform.getMessage(message2));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,9 @@
|
||||
|
||||
package minetweaker.api.oredict;
|
||||
|
||||
import java.util.List;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenMemberGetter;
|
||||
|
||||
/**
|
||||
@@ -17,4 +19,7 @@ import stanhebben.zenscript.annotations.ZenMemberGetter;
|
||||
public interface IOreDict {
|
||||
@ZenMemberGetter
|
||||
public IOreDictEntry get(String name);
|
||||
|
||||
@ZenGetter("entries")
|
||||
public List<IOreDictEntry> getEntries();
|
||||
}
|
||||
@@ -18,6 +18,9 @@ import stanhebben.zenscript.annotations.ZenMethod;
|
||||
*/
|
||||
@ZenClass("minetweaker.oredict.IOreDictEntry")
|
||||
public interface IOreDictEntry extends IIngredient {
|
||||
@ZenGetter("name")
|
||||
public String getName();
|
||||
|
||||
@ZenGetter("empty")
|
||||
public boolean isEmpty();
|
||||
|
||||
|
||||
@@ -95,6 +95,11 @@ public class IngredientOreDict implements IIngredient {
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTransformers() {
|
||||
return transformers.length > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternal() {
|
||||
return entry.getInternal();
|
||||
|
||||
@@ -6,8 +6,10 @@
|
||||
|
||||
package minetweaker.api.player;
|
||||
|
||||
import java.util.List;
|
||||
import minetweaker.api.chat.IChatMessage;
|
||||
import minetweaker.api.data.IData;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
@@ -18,6 +20,9 @@ import stanhebben.zenscript.annotations.ZenMethod;
|
||||
*/
|
||||
@ZenClass("minetweaker.player.IPlayer")
|
||||
public interface IPlayer {
|
||||
@ZenGetter("id")
|
||||
public String getId();
|
||||
|
||||
@ZenGetter("name")
|
||||
public String getName();
|
||||
|
||||
@@ -29,4 +34,21 @@ public interface IPlayer {
|
||||
|
||||
@ZenMethod
|
||||
public void sendChat(IChatMessage message);
|
||||
|
||||
@ZenGetter("hotbarSize")
|
||||
public int getHotbarSize();
|
||||
|
||||
@ZenMethod
|
||||
public IItemStack getHotbarStack(int i);
|
||||
|
||||
@ZenGetter("inventorySize")
|
||||
public int getInventorySize();
|
||||
|
||||
@ZenMethod
|
||||
public IItemStack getInventoryStack(int i);
|
||||
|
||||
@ZenGetter("currentItem")
|
||||
public IItemStack getCurrentItem();
|
||||
|
||||
public void openBrowser(String url);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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.recipes;
|
||||
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.api.world.IDimension;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class CraftingInfo implements ICraftingInfo {
|
||||
private final ICraftingInventory inventory;
|
||||
private final IDimension dimension;
|
||||
|
||||
public CraftingInfo(ICraftingInventory inventory, IDimension dimension) {
|
||||
this.inventory = inventory;
|
||||
this.dimension = dimension;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICraftingInventory getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPlayer getPlayer() {
|
||||
return inventory.getPlayer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IDimension getDimension() {
|
||||
return dimension;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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.recipes;
|
||||
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.api.world.IDimension;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.recipes.ICraftingInfo")
|
||||
public interface ICraftingInfo {
|
||||
@ZenGetter("inventory")
|
||||
public ICraftingInventory getInventory();
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer();
|
||||
|
||||
@ZenGetter("dimension")
|
||||
public IDimension getDimension();
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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.recipes;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.recipes.ICraftingRecipe")
|
||||
public interface ICraftingRecipe {
|
||||
public boolean matches(ICraftingInventory inventory);
|
||||
|
||||
public IItemStack getCraftingResult(ICraftingInventory inventory);
|
||||
|
||||
public boolean hasTransformers();
|
||||
|
||||
public void applyTransformers(ICraftingInventory inventory);
|
||||
}
|
||||
@@ -16,5 +16,5 @@ import stanhebben.zenscript.annotations.ZenClass;
|
||||
*/
|
||||
@ZenClass("minetweaker.recipes.IRecipeFunction")
|
||||
public interface IRecipeFunction {
|
||||
public IItemStack process(IItemStack output, Map<String, IItemStack> inputs, ICraftingInventory inventory);
|
||||
public IItemStack process(IItemStack output, Map<String, IItemStack> inputs, ICraftingInfo craftingInfo);
|
||||
}
|
||||
@@ -15,7 +15,7 @@ import minetweaker.api.item.IItemStack;
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class ShapedRecipe {
|
||||
public class ShapedRecipe implements ICraftingRecipe {
|
||||
private final int width;
|
||||
private final int height;
|
||||
private final byte[] posx;
|
||||
@@ -93,6 +93,7 @@ public class ShapedRecipe {
|
||||
return output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(ICraftingInventory inventory) {
|
||||
if (inventory.getStackCount() != ingredients.length) {
|
||||
return false;
|
||||
@@ -129,6 +130,7 @@ public class ShapedRecipe {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack getCraftingResult(ICraftingInventory inventory) {
|
||||
IItemStack[] stacks = new IItemStack[ingredients.length];
|
||||
|
||||
@@ -165,6 +167,54 @@ public class ShapedRecipe {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTransformers() {
|
||||
for (IIngredient ingredient : ingredients) {
|
||||
if (ingredient.hasTransformers()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyTransformers(ICraftingInventory inventory) {
|
||||
IItemStack[] stacks = new IItemStack[ingredients.length];
|
||||
|
||||
for (int i = 0; i <= inventory.getWidth() - width; i++) {
|
||||
out: for (int j = 0; j <= inventory.getHeight() - height; j++) {
|
||||
for (int k = 0; k < ingredients.length; k++) {
|
||||
IItemStack item = inventory.getStack(posx[k] + i, posy[k] + j);
|
||||
if (item == null) continue out;
|
||||
|
||||
if (!ingredients[k].matches(item)) continue out;
|
||||
stacks[k] = item;
|
||||
}
|
||||
|
||||
doRecipeTransformers(inventory, stacks, i, j, false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (mirrored) {
|
||||
for (int i = 0; i <= inventory.getWidth() - width; i++) {
|
||||
out: for (int j = 0; j <= inventory.getHeight() - height; j++) {
|
||||
for (int k = 0; k < ingredients.length; k++) {
|
||||
IItemStack item = inventory.getStack(inventory.getWidth() - (posx[k] + i) - 1, posy[k] + j);
|
||||
if (item == null) continue out;
|
||||
|
||||
if (!ingredients[k].matches(item)) continue out;
|
||||
stacks[k] = item;
|
||||
}
|
||||
|
||||
doRecipeTransformers(inventory, stacks, i, j, true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private IItemStack doRecipe(
|
||||
ICraftingInventory inventory,
|
||||
IItemStack[] stacks,
|
||||
@@ -181,7 +231,8 @@ public class ShapedRecipe {
|
||||
}
|
||||
}
|
||||
|
||||
output = function.process(output, tagged, inventory);
|
||||
// TODO: supply dimension
|
||||
output = function.process(output, tagged, new CraftingInfo(inventory, null));
|
||||
System.out.println("Ouput: " + output);
|
||||
}
|
||||
|
||||
@@ -189,6 +240,31 @@ public class ShapedRecipe {
|
||||
return null;
|
||||
}
|
||||
|
||||
/*for (int i = 0; i < ingredients.length; i++) {
|
||||
IItemStack transformed = ingredients[i].applyTransform(stacks[i]);
|
||||
if (transformed != stacks[i]) {
|
||||
if (mirrored) {
|
||||
inventory.setStack(
|
||||
inventory.getWidth() - (offx + posx[i]) - 1,
|
||||
offy + posy[i],
|
||||
transformed);
|
||||
} else {
|
||||
inventory.setStack(
|
||||
offx + posx[i],
|
||||
offy + posy[i],
|
||||
transformed);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
private void doRecipeTransformers(
|
||||
ICraftingInventory inventory,
|
||||
IItemStack[] stacks,
|
||||
int offx, int offy,
|
||||
boolean mirrored) {
|
||||
for (int i = 0; i < ingredients.length; i++) {
|
||||
IItemStack transformed = ingredients[i].applyTransform(stacks[i]);
|
||||
if (transformed != stacks[i]) {
|
||||
@@ -205,7 +281,5 @@ public class ShapedRecipe {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ import minetweaker.api.item.IItemStack;
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class ShapelessRecipe {
|
||||
public class ShapelessRecipe implements ICraftingRecipe {
|
||||
private final IItemStack output;
|
||||
private final IRecipeFunction function;
|
||||
private final IIngredient[] ingredients;
|
||||
@@ -38,10 +38,12 @@ public class ShapelessRecipe {
|
||||
return output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(ICraftingInventory inventory) {
|
||||
return matchShapeless(ingredients, inventory) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack getCraftingResult(ICraftingInventory inventory) {
|
||||
RecipeMatching matching = matchShapeless(ingredients, inventory);
|
||||
|
||||
@@ -54,13 +56,20 @@ public class ShapelessRecipe {
|
||||
}
|
||||
}
|
||||
|
||||
actualOutput = function.process(actualOutput, map, inventory);
|
||||
actualOutput = function.process(actualOutput, map, new CraftingInfo(inventory, null));
|
||||
}
|
||||
|
||||
if (actualOutput == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return actualOutput;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyTransformers(ICraftingInventory inventory) {
|
||||
RecipeMatching matching = matchShapeless(ingredients, inventory);
|
||||
|
||||
for (int i = 0; i < ingredients.length; i++) {
|
||||
IIngredient ingredient = ingredients[i];
|
||||
IItemStack transformed = ingredient.applyTransform(matching.inputs[i]);
|
||||
@@ -68,8 +77,6 @@ public class ShapelessRecipe {
|
||||
inventory.setStack(matching.indices[i], transformed);
|
||||
}
|
||||
}
|
||||
|
||||
return actualOutput;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -116,6 +123,17 @@ public class ShapelessRecipe {
|
||||
return new RecipeMatching(matched, indices);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTransformers() {
|
||||
for (IIngredient ingredient : ingredients) {
|
||||
if (ingredient.hasTransformers()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static class RecipeMatching {
|
||||
public final IItemStack[] inputs;
|
||||
public final int[] indices;
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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.server;
|
||||
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.server.CommandValidators")
|
||||
public class CommandValidators {
|
||||
public static final ICommandValidator ISOP = new ICommandValidator() {
|
||||
@Override
|
||||
public boolean canExecute(IPlayer player) {
|
||||
return MineTweakerAPI.server.isOp(player);
|
||||
}
|
||||
};
|
||||
|
||||
@ZenGetter
|
||||
public static ICommandValidator isOp() {
|
||||
return ISOP;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* 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.server;
|
||||
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.server.ICommandFunction")
|
||||
public interface ICommandFunction {
|
||||
public void execute(String[] arguments, IPlayer player);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* 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.server;
|
||||
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.server.ICommandTabCompletion")
|
||||
public interface ICommandTabCompletion {
|
||||
public String[] getTabCompletionOptions(String[] command, IPlayer player);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* 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.server;
|
||||
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.server.ICommandValidator")
|
||||
public interface ICommandValidator {
|
||||
public boolean canExecute(IPlayer player);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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.server;
|
||||
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.Optional;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.server.IServer")
|
||||
public interface IServer {
|
||||
@ZenMethod
|
||||
public void addCommand(
|
||||
String name,
|
||||
String usage,
|
||||
String[] aliases,
|
||||
ICommandFunction function,
|
||||
@Optional ICommandValidator validator,
|
||||
@Optional ICommandTabCompletion completion);
|
||||
|
||||
@ZenMethod
|
||||
public void removeCommand(String name);
|
||||
|
||||
@ZenMethod
|
||||
public void addMineTweakerCommand(String name, String[] usage, ICommandFunction function);
|
||||
|
||||
@ZenMethod
|
||||
public boolean isOp(IPlayer player);
|
||||
}
|
||||
Reference in new issue
Block a user