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.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
|
||||
os.system (command)
|
||||
|
|
|
@ -16,6 +16,7 @@ import java.io.IOException;
|
|||
import joptsimple.ArgumentAcceptingOptionSpec;
|
||||
import joptsimple.OptionParser;
|
||||
import joptsimple.OptionSet;
|
||||
import joptsimple.OptionSpecBuilder;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
|
@ -55,6 +56,8 @@ public class BuildCraftTests extends BuildCraftMod {
|
|||
private String testFile = "";
|
||||
private Sequence testSequence;
|
||||
|
||||
private boolean quitAfterRun = false;
|
||||
|
||||
@Mod.EventHandler
|
||||
public void preInit(FMLPreInitializationEvent evt) {
|
||||
blockTestPathfinding = new BlockTestPathfinding();
|
||||
|
@ -80,13 +83,15 @@ public class BuildCraftTests extends BuildCraftMod {
|
|||
optionparser.allowsUnrecognizedOptions();
|
||||
|
||||
ArgumentAcceptingOptionSpec<String> testOption = optionparser.accepts("test").withRequiredArg();
|
||||
OptionSpecBuilder quitOption = optionparser.accepts("quit");
|
||||
|
||||
OptionSet optionset = optionparser.parse(commandLine.split(" "));
|
||||
testFile = optionset.valueOf(testOption);
|
||||
System.out.println("LOADING TEST: " + testFile);
|
||||
quitAfterRun = optionset.has(quitOption);
|
||||
|
||||
if (testFile != null && !"".equals(testFile)) {
|
||||
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()) {
|
||||
testSequence.iterate();
|
||||
} else {
|
||||
MinecraftServer.getServer().stopServer();
|
||||
System.exit(0);
|
||||
if (quitAfterRun) {
|
||||
MinecraftServer.getServer().stopServer();
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ import net.minecraft.world.World;
|
|||
|
||||
import buildcraft.BuildCraftBuilders;
|
||||
import buildcraft.core.DefaultProps;
|
||||
import buildcraft.core.utils.StringUtils;
|
||||
import buildcraft.tests.testcase.SequenceActionCheckBlockMeta;
|
||||
import buildcraft.tests.testcase.TileTestCase;
|
||||
|
||||
|
@ -83,8 +82,6 @@ public class GuiTester extends GuiContainer {
|
|||
textField.setMaxStringLength(BuildCraftBuilders.MAX_BLUEPRINTS_NAME_SIZE);
|
||||
textField.setText("");
|
||||
textField.setFocused(true);
|
||||
|
||||
updateButtons();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -94,8 +91,6 @@ public class GuiTester extends GuiContainer {
|
|||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button) {
|
||||
updateButtons();
|
||||
|
||||
if (button == checkBlockAndMeta) {
|
||||
TileTestCase.currentTestCase.registerAction(new SequenceActionCheckBlockMeta(world, x, y, z));
|
||||
mc.thePlayer.closeScreen();
|
||||
|
@ -104,22 +99,8 @@ public class GuiTester extends GuiContainer {
|
|||
}
|
||||
}
|
||||
|
||||
private void updateButtons () {
|
||||
}
|
||||
|
||||
@Override
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,6 @@ import net.minecraft.util.ResourceLocation;
|
|||
import buildcraft.BuildCraftBuilders;
|
||||
import buildcraft.core.DefaultProps;
|
||||
import buildcraft.core.network.RPCHandler;
|
||||
import buildcraft.core.utils.StringUtils;
|
||||
|
||||
public class GuiTestCase extends GuiContainer {
|
||||
|
||||
|
@ -35,6 +34,8 @@ public class GuiTestCase extends GuiContainer {
|
|||
private GuiTextField textField;
|
||||
private TileTestCase testCase;
|
||||
|
||||
private GuiButton compress;
|
||||
|
||||
public GuiTestCase(EntityPlayer player, int x, int y, int z) {
|
||||
super(new ContainerTestCase(player, x, y, z));
|
||||
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.setMaxStringLength(BuildCraftBuilders.MAX_BLUEPRINTS_NAME_SIZE);
|
||||
textField.setText("");
|
||||
textField.setText(testCase.testName);
|
||||
textField.setFocused(true);
|
||||
|
||||
updateButtons();
|
||||
compress = new GuiButton(0, x + 5, y + 50, 120, 20, "");
|
||||
compress.displayString = "Compress";
|
||||
buttonList.add(compress);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -67,25 +70,14 @@ public class GuiTestCase extends GuiContainer {
|
|||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button) {
|
||||
updateButtons();
|
||||
}
|
||||
|
||||
private void updateButtons () {
|
||||
if (button == compress) {
|
||||
RPCHandler.rpcServer(testCase, "compress");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
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); }
|
||||
*/
|
||||
|
||||
fontRendererObj.drawString(testCase.information, 10, 30, 0x404040);
|
||||
textField.drawTextBox();
|
||||
}
|
||||
|
||||
|
|
|
@ -11,9 +11,14 @@ package buildcraft.tests.testcase;
|
|||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import buildcraft.api.core.NetworkData;
|
||||
|
||||
public class SequenceAction {
|
||||
|
||||
@NetworkData
|
||||
public long date;
|
||||
|
||||
@NetworkData
|
||||
public World world;
|
||||
|
||||
public void execute() {
|
||||
|
|
|
@ -12,10 +12,17 @@ import net.minecraft.block.Block;
|
|||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import buildcraft.api.core.NetworkData;
|
||||
|
||||
public class SequenceActionCheckBlockMeta extends SequenceAction {
|
||||
|
||||
@NetworkData
|
||||
String blockName;
|
||||
|
||||
@NetworkData
|
||||
int meta;
|
||||
|
||||
@NetworkData
|
||||
int x, y, z;
|
||||
|
||||
public SequenceActionCheckBlockMeta() {
|
||||
|
@ -39,11 +46,15 @@ public class SequenceActionCheckBlockMeta extends SequenceAction {
|
|||
int worldMeta = world.getBlockMetadata(x, y, z);
|
||||
|
||||
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) {
|
||||
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 {
|
||||
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.WorldServer;
|
||||
|
||||
import buildcraft.api.core.NetworkData;
|
||||
import buildcraft.core.proxy.CoreProxy;
|
||||
|
||||
public class SequenceActionUseItem extends SequenceAction {
|
||||
|
||||
@NetworkData
|
||||
ItemStack stack;
|
||||
int x, y, z;
|
||||
|
||||
@NetworkData
|
||||
int x, y, z, face;
|
||||
|
||||
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;
|
||||
x = ix;
|
||||
y = iy;
|
||||
z = iz;
|
||||
face = iface;
|
||||
world = iWorld;
|
||||
date = world.getTotalWorldTime();
|
||||
}
|
||||
|
@ -36,7 +41,8 @@ public class SequenceActionUseItem extends SequenceAction {
|
|||
@Override
|
||||
public void execute() {
|
||||
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
|
||||
|
@ -46,6 +52,7 @@ public class SequenceActionUseItem extends SequenceAction {
|
|||
nbt.setInteger("x", x);
|
||||
nbt.setInteger("y", y);
|
||||
nbt.setInteger("z", z);
|
||||
nbt.setInteger("face", face);
|
||||
|
||||
NBTTagCompound stackNBT = new NBTTagCompound();
|
||||
stack.writeToNBT(stackNBT);
|
||||
|
@ -59,6 +66,7 @@ public class SequenceActionUseItem extends SequenceAction {
|
|||
x = nbt.getInteger("x");
|
||||
y = nbt.getInteger("y");
|
||||
z = nbt.getInteger("z");
|
||||
face = nbt.getInteger("face");
|
||||
stack = ItemStack.loadItemStackFromNBT(nbt.getCompoundTag("stack"));
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ import net.minecraftforge.common.MinecraftForge;
|
|||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
|
||||
import buildcraft.core.network.RPC;
|
||||
import buildcraft.core.network.RPCHandler;
|
||||
import buildcraft.core.network.RPCSide;
|
||||
import buildcraft.tests.ItemTester;
|
||||
|
||||
|
@ -40,6 +41,7 @@ public class TileTestCase extends TileEntity {
|
|||
|
||||
Sequence sequence;
|
||||
String testName = "test";
|
||||
String information = "";
|
||||
|
||||
public TileTestCase() {
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
|
@ -54,23 +56,57 @@ public class TileTestCase extends TileEntity {
|
|||
|
||||
@SubscribeEvent
|
||||
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) {
|
||||
sequence = new Sequence(evt.entity.worldObj);
|
||||
sequence = new Sequence(worldObj);
|
||||
}
|
||||
|
||||
if (evt.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) {
|
||||
ItemStack usedItem = evt.entityPlayer.inventory.getCurrentItem();
|
||||
|
||||
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) {
|
||||
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
|
||||
|
@ -108,5 +144,11 @@ public class TileTestCase extends TileEntity {
|
|||
@RPC(RPCSide.SERVER)
|
||||
private void setName(String 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 New Issue