progress in implementation of tests, #1486
This commit is contained in:
parent
f0af7f3b06
commit
5a40c529cd
2
test.py
2
test.py
|
@ -22,6 +22,6 @@ shutil.rmtree ("world", True)
|
||||||
shutil.copytree ("../base/world", "world")
|
shutil.copytree ("../base/world", "world")
|
||||||
shutil.copy ("../base/server.properties", "server.properties")
|
shutil.copy ("../base/server.properties", "server.properties")
|
||||||
|
|
||||||
command = "java -Xincgc -Xmx1024M -Xms1024M -classpath \"" + classpath + "\" cpw.mods.fml.relauncher.ServerLaunchWrapper --nogui --world world --test test.seq "
|
command = "java -Xincgc -Xmx1024M -Xms1024M -classpath \"" + classpath + "\" cpw.mods.fml.relauncher.ServerLaunchWrapper --nogui --world world --test test.seq --quit"
|
||||||
print command
|
print command
|
||||||
os.system (command)
|
os.system (command)
|
||||||
|
|
|
@ -16,6 +16,7 @@ import java.io.IOException;
|
||||||
import joptsimple.ArgumentAcceptingOptionSpec;
|
import joptsimple.ArgumentAcceptingOptionSpec;
|
||||||
import joptsimple.OptionParser;
|
import joptsimple.OptionParser;
|
||||||
import joptsimple.OptionSet;
|
import joptsimple.OptionSet;
|
||||||
|
import joptsimple.OptionSpecBuilder;
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
|
@ -55,6 +56,8 @@ public class BuildCraftTests extends BuildCraftMod {
|
||||||
private String testFile = "";
|
private String testFile = "";
|
||||||
private Sequence testSequence;
|
private Sequence testSequence;
|
||||||
|
|
||||||
|
private boolean quitAfterRun = false;
|
||||||
|
|
||||||
@Mod.EventHandler
|
@Mod.EventHandler
|
||||||
public void preInit(FMLPreInitializationEvent evt) {
|
public void preInit(FMLPreInitializationEvent evt) {
|
||||||
blockTestPathfinding = new BlockTestPathfinding();
|
blockTestPathfinding = new BlockTestPathfinding();
|
||||||
|
@ -80,13 +83,15 @@ public class BuildCraftTests extends BuildCraftMod {
|
||||||
optionparser.allowsUnrecognizedOptions();
|
optionparser.allowsUnrecognizedOptions();
|
||||||
|
|
||||||
ArgumentAcceptingOptionSpec<String> testOption = optionparser.accepts("test").withRequiredArg();
|
ArgumentAcceptingOptionSpec<String> testOption = optionparser.accepts("test").withRequiredArg();
|
||||||
|
OptionSpecBuilder quitOption = optionparser.accepts("quit");
|
||||||
|
|
||||||
OptionSet optionset = optionparser.parse(commandLine.split(" "));
|
OptionSet optionset = optionparser.parse(commandLine.split(" "));
|
||||||
testFile = optionset.valueOf(testOption);
|
testFile = optionset.valueOf(testOption);
|
||||||
System.out.println("LOADING TEST: " + testFile);
|
quitAfterRun = optionset.has(quitOption);
|
||||||
|
|
||||||
if (testFile != null && !"".equals(testFile)) {
|
if (testFile != null && !"".equals(testFile)) {
|
||||||
FMLCommonHandler.instance().bus().register(this);
|
FMLCommonHandler.instance().bus().register(this);
|
||||||
|
System.out.println("[TEST 0] [LOAD TEST] \"" + testFile + "\"");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,8 +127,10 @@ public class BuildCraftTests extends BuildCraftMod {
|
||||||
if (!testSequence.done()) {
|
if (!testSequence.done()) {
|
||||||
testSequence.iterate();
|
testSequence.iterate();
|
||||||
} else {
|
} else {
|
||||||
MinecraftServer.getServer().stopServer();
|
if (quitAfterRun) {
|
||||||
System.exit(0);
|
MinecraftServer.getServer().stopServer();
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,6 @@ import net.minecraft.world.World;
|
||||||
|
|
||||||
import buildcraft.BuildCraftBuilders;
|
import buildcraft.BuildCraftBuilders;
|
||||||
import buildcraft.core.DefaultProps;
|
import buildcraft.core.DefaultProps;
|
||||||
import buildcraft.core.utils.StringUtils;
|
|
||||||
import buildcraft.tests.testcase.SequenceActionCheckBlockMeta;
|
import buildcraft.tests.testcase.SequenceActionCheckBlockMeta;
|
||||||
import buildcraft.tests.testcase.TileTestCase;
|
import buildcraft.tests.testcase.TileTestCase;
|
||||||
|
|
||||||
|
@ -83,8 +82,6 @@ public class GuiTester extends GuiContainer {
|
||||||
textField.setMaxStringLength(BuildCraftBuilders.MAX_BLUEPRINTS_NAME_SIZE);
|
textField.setMaxStringLength(BuildCraftBuilders.MAX_BLUEPRINTS_NAME_SIZE);
|
||||||
textField.setText("");
|
textField.setText("");
|
||||||
textField.setFocused(true);
|
textField.setFocused(true);
|
||||||
|
|
||||||
updateButtons();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -94,8 +91,6 @@ public class GuiTester extends GuiContainer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void actionPerformed(GuiButton button) {
|
protected void actionPerformed(GuiButton button) {
|
||||||
updateButtons();
|
|
||||||
|
|
||||||
if (button == checkBlockAndMeta) {
|
if (button == checkBlockAndMeta) {
|
||||||
TileTestCase.currentTestCase.registerAction(new SequenceActionCheckBlockMeta(world, x, y, z));
|
TileTestCase.currentTestCase.registerAction(new SequenceActionCheckBlockMeta(world, x, y, z));
|
||||||
mc.thePlayer.closeScreen();
|
mc.thePlayer.closeScreen();
|
||||||
|
@ -104,22 +99,8 @@ public class GuiTester extends GuiContainer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateButtons () {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void drawGuiContainerForegroundLayer(int par1, int par2) {
|
protected void drawGuiContainerForegroundLayer(int par1, int par2) {
|
||||||
String title = StringUtils.localize("tile.architectBlock.name");
|
|
||||||
// fontRendererObj.drawString(title, getCenteredOffset(title), 6,
|
|
||||||
// 0x404040);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* if (editMode && ((new Date()).getTime() / 100) % 8 >= 4) {
|
|
||||||
* fontRendererObj.drawString(architect.name + "|", 131, 62, 0x404040);
|
|
||||||
* } else { fontRendererObj.drawString(architect.name, 131, 62,
|
|
||||||
* 0x404040); }
|
|
||||||
*/
|
|
||||||
|
|
||||||
textField.drawTextBox();
|
textField.drawTextBox();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,6 @@ import net.minecraft.util.ResourceLocation;
|
||||||
import buildcraft.BuildCraftBuilders;
|
import buildcraft.BuildCraftBuilders;
|
||||||
import buildcraft.core.DefaultProps;
|
import buildcraft.core.DefaultProps;
|
||||||
import buildcraft.core.network.RPCHandler;
|
import buildcraft.core.network.RPCHandler;
|
||||||
import buildcraft.core.utils.StringUtils;
|
|
||||||
|
|
||||||
public class GuiTestCase extends GuiContainer {
|
public class GuiTestCase extends GuiContainer {
|
||||||
|
|
||||||
|
@ -35,6 +34,8 @@ public class GuiTestCase extends GuiContainer {
|
||||||
private GuiTextField textField;
|
private GuiTextField textField;
|
||||||
private TileTestCase testCase;
|
private TileTestCase testCase;
|
||||||
|
|
||||||
|
private GuiButton compress;
|
||||||
|
|
||||||
public GuiTestCase(EntityPlayer player, int x, int y, int z) {
|
public GuiTestCase(EntityPlayer player, int x, int y, int z) {
|
||||||
super(new ContainerTestCase(player, x, y, z));
|
super(new ContainerTestCase(player, x, y, z));
|
||||||
xSize = 256;
|
xSize = 256;
|
||||||
|
@ -54,10 +55,12 @@ public class GuiTestCase extends GuiContainer {
|
||||||
|
|
||||||
textField = new GuiTextField(this.fontRendererObj, TEXT_X, TEXT_Y, TEXT_WIDTH, TEXT_HEIGHT);
|
textField = new GuiTextField(this.fontRendererObj, TEXT_X, TEXT_Y, TEXT_WIDTH, TEXT_HEIGHT);
|
||||||
textField.setMaxStringLength(BuildCraftBuilders.MAX_BLUEPRINTS_NAME_SIZE);
|
textField.setMaxStringLength(BuildCraftBuilders.MAX_BLUEPRINTS_NAME_SIZE);
|
||||||
textField.setText("");
|
textField.setText(testCase.testName);
|
||||||
textField.setFocused(true);
|
textField.setFocused(true);
|
||||||
|
|
||||||
updateButtons();
|
compress = new GuiButton(0, x + 5, y + 50, 120, 20, "");
|
||||||
|
compress.displayString = "Compress";
|
||||||
|
buttonList.add(compress);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -67,25 +70,14 @@ public class GuiTestCase extends GuiContainer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void actionPerformed(GuiButton button) {
|
protected void actionPerformed(GuiButton button) {
|
||||||
updateButtons();
|
if (button == compress) {
|
||||||
}
|
RPCHandler.rpcServer(testCase, "compress");
|
||||||
|
}
|
||||||
private void updateButtons () {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void drawGuiContainerForegroundLayer(int par1, int par2) {
|
protected void drawGuiContainerForegroundLayer(int par1, int par2) {
|
||||||
String title = StringUtils.localize("tile.architectBlock.name");
|
fontRendererObj.drawString(testCase.information, 10, 30, 0x404040);
|
||||||
// fontRendererObj.drawString(title, getCenteredOffset(title), 6,
|
|
||||||
// 0x404040);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* if (editMode && ((new Date()).getTime() / 100) % 8 >= 4) {
|
|
||||||
* fontRendererObj.drawString(architect.name + "|", 131, 62, 0x404040);
|
|
||||||
* } else { fontRendererObj.drawString(architect.name, 131, 62,
|
|
||||||
* 0x404040); }
|
|
||||||
*/
|
|
||||||
|
|
||||||
textField.drawTextBox();
|
textField.drawTextBox();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,9 +11,14 @@ package buildcraft.tests.testcase;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
import buildcraft.api.core.NetworkData;
|
||||||
|
|
||||||
public class SequenceAction {
|
public class SequenceAction {
|
||||||
|
|
||||||
|
@NetworkData
|
||||||
public long date;
|
public long date;
|
||||||
|
|
||||||
|
@NetworkData
|
||||||
public World world;
|
public World world;
|
||||||
|
|
||||||
public void execute() {
|
public void execute() {
|
||||||
|
|
|
@ -12,10 +12,17 @@ import net.minecraft.block.Block;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
import buildcraft.api.core.NetworkData;
|
||||||
|
|
||||||
public class SequenceActionCheckBlockMeta extends SequenceAction {
|
public class SequenceActionCheckBlockMeta extends SequenceAction {
|
||||||
|
|
||||||
|
@NetworkData
|
||||||
String blockName;
|
String blockName;
|
||||||
|
|
||||||
|
@NetworkData
|
||||||
int meta;
|
int meta;
|
||||||
|
|
||||||
|
@NetworkData
|
||||||
int x, y, z;
|
int x, y, z;
|
||||||
|
|
||||||
public SequenceActionCheckBlockMeta() {
|
public SequenceActionCheckBlockMeta() {
|
||||||
|
@ -39,11 +46,15 @@ public class SequenceActionCheckBlockMeta extends SequenceAction {
|
||||||
int worldMeta = world.getBlockMetadata(x, y, z);
|
int worldMeta = world.getBlockMetadata(x, y, z);
|
||||||
|
|
||||||
if (!worldBlockName.equals(blockName)) {
|
if (!worldBlockName.equals(blockName)) {
|
||||||
System.err.println("[TESTCASE ERROR] block " + blockName + " expected, " + worldBlockName + " found.");
|
System.out.println("[TEST " + date + "] [ERROR] " + x + ", " + y + ", " + z + " block " + blockName
|
||||||
|
+ " expected, " + worldBlockName + " found.");
|
||||||
} else if (meta != worldMeta) {
|
} else if (meta != worldMeta) {
|
||||||
System.err.println("[TESTCASE ERROR] meta " + meta + " expected, " + worldMeta + " found.");
|
System.out.println("[TEST " + date + "] [ERROR] " + x + ", " + y + ", " + z + " meta " + meta
|
||||||
|
+ " expected, " + worldMeta + " found.");
|
||||||
} else {
|
} else {
|
||||||
System.out.println("[TESTCASE OK] " + x + ", " + y + ", " + z + " is {" + blockName + ", " + meta + "}");
|
System.out.println("[TEST " + date + "] [OK] " + x + ", " + y + ", " + z + " is {" + blockName + ", "
|
||||||
|
+ meta
|
||||||
|
+ "}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,22 +13,27 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.world.WorldServer;
|
import net.minecraft.world.WorldServer;
|
||||||
|
|
||||||
|
import buildcraft.api.core.NetworkData;
|
||||||
import buildcraft.core.proxy.CoreProxy;
|
import buildcraft.core.proxy.CoreProxy;
|
||||||
|
|
||||||
public class SequenceActionUseItem extends SequenceAction {
|
public class SequenceActionUseItem extends SequenceAction {
|
||||||
|
|
||||||
|
@NetworkData
|
||||||
ItemStack stack;
|
ItemStack stack;
|
||||||
int x, y, z;
|
|
||||||
|
@NetworkData
|
||||||
|
int x, y, z, face;
|
||||||
|
|
||||||
public SequenceActionUseItem() {
|
public SequenceActionUseItem() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public SequenceActionUseItem(World iWorld, ItemStack iStack, int ix, int iy, int iz) {
|
public SequenceActionUseItem(World iWorld, ItemStack iStack, int ix, int iy, int iz, int iface) {
|
||||||
stack = iStack;
|
stack = iStack;
|
||||||
x = ix;
|
x = ix;
|
||||||
y = iy;
|
y = iy;
|
||||||
z = iz;
|
z = iz;
|
||||||
|
face = iface;
|
||||||
world = iWorld;
|
world = iWorld;
|
||||||
date = world.getTotalWorldTime();
|
date = world.getTotalWorldTime();
|
||||||
}
|
}
|
||||||
|
@ -36,7 +41,8 @@ public class SequenceActionUseItem extends SequenceAction {
|
||||||
@Override
|
@Override
|
||||||
public void execute() {
|
public void execute() {
|
||||||
stack.getItem().onItemUse(stack, CoreProxy.proxy.getBuildCraftPlayer((WorldServer) world).get(), world, x, y,
|
stack.getItem().onItemUse(stack, CoreProxy.proxy.getBuildCraftPlayer((WorldServer) world).get(), world, x, y,
|
||||||
z, 1, x, y, z);
|
z, face, x, y, z);
|
||||||
|
System.out.println("[TEST " + date + "] [USE ITEM] " + x + ", " + y + ", " + z + ": " + stack.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -46,6 +52,7 @@ public class SequenceActionUseItem extends SequenceAction {
|
||||||
nbt.setInteger("x", x);
|
nbt.setInteger("x", x);
|
||||||
nbt.setInteger("y", y);
|
nbt.setInteger("y", y);
|
||||||
nbt.setInteger("z", z);
|
nbt.setInteger("z", z);
|
||||||
|
nbt.setInteger("face", face);
|
||||||
|
|
||||||
NBTTagCompound stackNBT = new NBTTagCompound();
|
NBTTagCompound stackNBT = new NBTTagCompound();
|
||||||
stack.writeToNBT(stackNBT);
|
stack.writeToNBT(stackNBT);
|
||||||
|
@ -59,6 +66,7 @@ public class SequenceActionUseItem extends SequenceAction {
|
||||||
x = nbt.getInteger("x");
|
x = nbt.getInteger("x");
|
||||||
y = nbt.getInteger("y");
|
y = nbt.getInteger("y");
|
||||||
z = nbt.getInteger("z");
|
z = nbt.getInteger("z");
|
||||||
|
face = nbt.getInteger("face");
|
||||||
stack = ItemStack.loadItemStackFromNBT(nbt.getCompoundTag("stack"));
|
stack = ItemStack.loadItemStackFromNBT(nbt.getCompoundTag("stack"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ import net.minecraftforge.common.MinecraftForge;
|
||||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||||
|
|
||||||
import buildcraft.core.network.RPC;
|
import buildcraft.core.network.RPC;
|
||||||
|
import buildcraft.core.network.RPCHandler;
|
||||||
import buildcraft.core.network.RPCSide;
|
import buildcraft.core.network.RPCSide;
|
||||||
import buildcraft.tests.ItemTester;
|
import buildcraft.tests.ItemTester;
|
||||||
|
|
||||||
|
@ -40,6 +41,7 @@ public class TileTestCase extends TileEntity {
|
||||||
|
|
||||||
Sequence sequence;
|
Sequence sequence;
|
||||||
String testName = "test";
|
String testName = "test";
|
||||||
|
String information = "";
|
||||||
|
|
||||||
public TileTestCase() {
|
public TileTestCase() {
|
||||||
MinecraftForge.EVENT_BUS.register(this);
|
MinecraftForge.EVENT_BUS.register(this);
|
||||||
|
@ -54,23 +56,57 @@ public class TileTestCase extends TileEntity {
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void itemUsed(PlayerInteractEvent evt) {
|
public void itemUsed(PlayerInteractEvent evt) {
|
||||||
if (!evt.entity.worldObj.isRemote) {
|
// For some reason, this called 4 times with all combinaisons of world.
|
||||||
|
// we're only interested in one call from the server side.
|
||||||
|
if (!worldObj.isRemote && !evt.entity.worldObj.isRemote) {
|
||||||
if (sequence == null) {
|
if (sequence == null) {
|
||||||
sequence = new Sequence(evt.entity.worldObj);
|
sequence = new Sequence(worldObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (evt.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) {
|
if (evt.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) {
|
||||||
ItemStack usedItem = evt.entityPlayer.inventory.getCurrentItem();
|
ItemStack usedItem = evt.entityPlayer.inventory.getCurrentItem();
|
||||||
|
|
||||||
if (usedItem != null && !(usedItem.getItem() instanceof ItemTester)) {
|
if (usedItem != null && !(usedItem.getItem() instanceof ItemTester)) {
|
||||||
registerAction(new SequenceActionUseItem(evt.entity.worldObj, usedItem, evt.x, evt.y, evt.z));
|
registerAction(new SequenceActionUseItem(worldObj, usedItem, evt.x, evt.y, evt.z, evt.face));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RPC(RPCSide.SERVER)
|
||||||
public synchronized void registerAction(SequenceAction action) {
|
public synchronized void registerAction(SequenceAction action) {
|
||||||
sequence.actions.add(action);
|
sequence.actions.add(action);
|
||||||
|
updateInformation();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateInformation() {
|
||||||
|
long time = sequence.actions.getLast().date - sequence.initialDate;
|
||||||
|
information = sequence.actions.size() + " actions in " + time + " cycles, starting " + sequence.initialDate;
|
||||||
|
RPCHandler.rpcBroadcastPlayers(this, "setInformation", information);
|
||||||
|
}
|
||||||
|
|
||||||
|
@RPC(RPCSide.CLIENT)
|
||||||
|
private void setInformation(String info) {
|
||||||
|
information = info;
|
||||||
|
}
|
||||||
|
|
||||||
|
@RPC (RPCSide.SERVER)
|
||||||
|
public synchronized void compress() {
|
||||||
|
long date = -1;
|
||||||
|
|
||||||
|
sequence.initialDate = worldObj.getTotalWorldTime();
|
||||||
|
|
||||||
|
for (SequenceAction action : sequence.actions) {
|
||||||
|
if (date == -1) {
|
||||||
|
date = sequence.initialDate;
|
||||||
|
} else {
|
||||||
|
date = date + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
action.date = date;
|
||||||
|
}
|
||||||
|
|
||||||
|
updateInformation();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -108,5 +144,11 @@ public class TileTestCase extends TileEntity {
|
||||||
@RPC(RPCSide.SERVER)
|
@RPC(RPCSide.SERVER)
|
||||||
private void setName(String name) {
|
private void setName(String name) {
|
||||||
testName = name;
|
testName = name;
|
||||||
|
RPCHandler.rpcBroadcastPlayers(this, "setNameClient", name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@RPC(RPCSide.CLIENT)
|
||||||
|
private void setNameClient(String name) {
|
||||||
|
testName = name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Loading…
Reference in a new issue