implemented checks and cycle-dependent actions, #1846
This commit is contained in:
parent
3f46097772
commit
f0af7f3b06
|
@ -10,9 +10,13 @@ package buildcraft.tests;
|
|||
|
||||
import net.minecraft.block.BlockContainer;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import buildcraft.core.CreativeTabBuildCraft;
|
||||
|
||||
public class BlockTestPathfinding extends BlockContainer {
|
||||
|
@ -28,4 +32,9 @@ public class BlockTestPathfinding extends BlockContainer {
|
|||
return new TileTestPathfinding();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerBlockIcons(IIconRegister par1IconRegister) {
|
||||
this.blockIcon = par1IconRegister.registerIcon("buildcraft:testcase");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -121,6 +121,9 @@ public class BuildCraftTests extends BuildCraftMod {
|
|||
} else {
|
||||
if (!testSequence.done()) {
|
||||
testSequence.iterate();
|
||||
} else {
|
||||
MinecraftServer.getServer().stopServer();
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,33 +16,42 @@ import net.minecraft.client.gui.GuiTextField;
|
|||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
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;
|
||||
|
||||
public class GuiTester extends GuiContainer {
|
||||
|
||||
private static final int TEXT_X = 90;
|
||||
private static final int TEXT_Y = 62;
|
||||
private static final int TEXT_X = 10;
|
||||
private static final int TEXT_Y = 10;
|
||||
private static final int TEXT_WIDTH = 156;
|
||||
private static final int TEXT_HEIGHT = 12;
|
||||
|
||||
private static final ResourceLocation TEXTURE = new ResourceLocation(
|
||||
"buildcraft", DefaultProps.TEXTURE_PATH_GUI + "/tester.png");
|
||||
|
||||
private GuiButton optionRotate;
|
||||
private GuiButton optionReadMods;
|
||||
private GuiButton optionReadBlocks;
|
||||
private GuiButton optionExcavate;
|
||||
private GuiButton optionExplicit;
|
||||
private GuiButton checkBlockAndMeta;
|
||||
private GuiButton checkTileMethod;
|
||||
private GuiButton checkTestCommand;
|
||||
private GuiButton cancel;
|
||||
|
||||
private GuiTextField textField;
|
||||
|
||||
public GuiTester(EntityPlayer player, int x, int y, int z) {
|
||||
super(new ContainerTester(player, x, y, z));
|
||||
World world;
|
||||
int x, y, z;
|
||||
|
||||
public GuiTester(EntityPlayer player, int ix, int iy, int iz) {
|
||||
super(new ContainerTester(player, ix, iy, iz));
|
||||
x = ix;
|
||||
y = iy;
|
||||
z = iz;
|
||||
xSize = 256;
|
||||
ySize = 166;
|
||||
world = player.worldObj;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -54,17 +63,21 @@ public class GuiTester extends GuiContainer {
|
|||
|
||||
Keyboard.enableRepeatEvents(true);
|
||||
|
||||
optionRotate = new GuiButton(0, x + 5, y + 30, 77, 20, "");
|
||||
buttonList.add(optionRotate);
|
||||
checkBlockAndMeta = new GuiButton(0, x + 5, y + 30, 120, 20, "");
|
||||
checkBlockAndMeta.displayString = "Check Block and Meta";
|
||||
buttonList.add(checkBlockAndMeta);
|
||||
|
||||
optionReadBlocks = new GuiButton(1, x + 5, y + 55, 77, 20, "");
|
||||
buttonList.add(optionReadBlocks);
|
||||
checkTileMethod = new GuiButton(1, x + 5, y + 55, 120, 20, "");
|
||||
checkTileMethod.displayString = "Check Tile Method";
|
||||
buttonList.add(checkTileMethod);
|
||||
|
||||
optionExcavate = new GuiButton(2, x + 5, y + 80, 77, 20, "");
|
||||
buttonList.add(optionExcavate);
|
||||
checkTestCommand = new GuiButton(2, x + 5, y + 80, 120, 20, "");
|
||||
checkTestCommand.displayString = "Check Test Command";
|
||||
buttonList.add(checkTestCommand);
|
||||
|
||||
optionExplicit = new GuiButton(3, x + 5, y + 105, 77, 20, "");
|
||||
buttonList.add(optionExplicit);
|
||||
cancel = new GuiButton(2, x + 5, y + 105, 120, 20, "");
|
||||
cancel.displayString = "Cancel";
|
||||
buttonList.add(cancel);
|
||||
|
||||
textField = new GuiTextField(this.fontRendererObj, TEXT_X, TEXT_Y, TEXT_WIDTH, TEXT_HEIGHT);
|
||||
textField.setMaxStringLength(BuildCraftBuilders.MAX_BLUEPRINTS_NAME_SIZE);
|
||||
|
@ -82,6 +95,13 @@ 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();
|
||||
} else if (button == cancel) {
|
||||
mc.thePlayer.closeScreen();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateButtons () {
|
||||
|
|
|
@ -24,12 +24,16 @@ public class Sequence {
|
|||
public LinkedList<SequenceAction> actions = new LinkedList<SequenceAction>();
|
||||
|
||||
public World world;
|
||||
public long initialDate;
|
||||
|
||||
public Sequence(World iWorld) {
|
||||
world = iWorld;
|
||||
initialDate = iWorld.getTotalWorldTime();
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
nbt.setLong("initialDate", initialDate);
|
||||
|
||||
MappingRegistry registry = new MappingRegistry();
|
||||
|
||||
NBTTagList list = new NBTTagList();
|
||||
|
@ -50,6 +54,8 @@ public class Sequence {
|
|||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
initialDate = nbt.getLong("initialDate");
|
||||
|
||||
MappingRegistry registry = new MappingRegistry();
|
||||
registry.read(nbt.getCompoundTag("registry"));
|
||||
|
||||
|
@ -63,6 +69,9 @@ public class Sequence {
|
|||
SequenceAction action = (SequenceAction) Class.forName(cpt.getString("class")).newInstance();
|
||||
action.world = world;
|
||||
action.readFromNBT(cpt);
|
||||
|
||||
action.date = (action.date - initialDate) + world.getTotalWorldTime();
|
||||
|
||||
actions.add(action);
|
||||
} catch (MappingNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -81,7 +90,12 @@ public class Sequence {
|
|||
}
|
||||
|
||||
public void iterate() {
|
||||
actions.pop().execute();
|
||||
SequenceAction next = actions.getFirst();
|
||||
|
||||
if (world.getTotalWorldTime() >= next.date) {
|
||||
next.execute();
|
||||
actions.removeFirst();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import net.minecraft.world.World;
|
|||
|
||||
public class SequenceAction {
|
||||
|
||||
public long date;
|
||||
public World world;
|
||||
|
||||
public void execute() {
|
||||
|
@ -20,11 +21,11 @@ public class SequenceAction {
|
|||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
|
||||
nbt.setLong("date", date);
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
|
||||
date = nbt.getLong("date");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
71
tests/buildcraft/tests/testcase/SequenceActionCheckBlockMeta.java
Executable file
71
tests/buildcraft/tests/testcase/SequenceActionCheckBlockMeta.java
Executable file
|
@ -0,0 +1,71 @@
|
|||
/**
|
||||
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
|
||||
* http://www.mod-buildcraft.com
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
package buildcraft.tests.testcase;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class SequenceActionCheckBlockMeta extends SequenceAction {
|
||||
|
||||
String blockName;
|
||||
int meta;
|
||||
int x, y, z;
|
||||
|
||||
public SequenceActionCheckBlockMeta() {
|
||||
|
||||
}
|
||||
|
||||
public SequenceActionCheckBlockMeta(World iWorld, int ix, int iy, int iz) {
|
||||
x = ix;
|
||||
y = iy;
|
||||
z = iz;
|
||||
world = iWorld;
|
||||
date = world.getTotalWorldTime();
|
||||
|
||||
blockName = Block.blockRegistry.getNameForObject(world.getBlock(x, y, z));
|
||||
meta = world.getBlockMetadata(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
String worldBlockName = Block.blockRegistry.getNameForObject(world.getBlock(x, y, z));
|
||||
int worldMeta = world.getBlockMetadata(x, y, z);
|
||||
|
||||
if (!worldBlockName.equals(blockName)) {
|
||||
System.err.println("[TESTCASE ERROR] block " + blockName + " expected, " + worldBlockName + " found.");
|
||||
} else if (meta != worldMeta) {
|
||||
System.err.println("[TESTCASE ERROR] meta " + meta + " expected, " + worldMeta + " found.");
|
||||
} else {
|
||||
System.out.println("[TESTCASE OK] " + x + ", " + y + ", " + z + " is {" + blockName + ", " + meta + "}");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
|
||||
nbt.setInteger("x", x);
|
||||
nbt.setInteger("y", y);
|
||||
nbt.setInteger("z", z);
|
||||
nbt.setInteger("meta", meta);
|
||||
nbt.setString("block", blockName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
|
||||
x = nbt.getInteger("x");
|
||||
y = nbt.getInteger("y");
|
||||
z = nbt.getInteger("z");
|
||||
meta = nbt.getInteger("meta");
|
||||
blockName = nbt.getString("block");
|
||||
}
|
||||
}
|
|
@ -30,6 +30,7 @@ public class SequenceActionUseItem extends SequenceAction {
|
|||
y = iy;
|
||||
z = iz;
|
||||
world = iWorld;
|
||||
date = world.getTotalWorldTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -40,6 +41,8 @@ public class SequenceActionUseItem extends SequenceAction {
|
|||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
|
||||
nbt.setInteger("x", x);
|
||||
nbt.setInteger("y", y);
|
||||
nbt.setInteger("z", z);
|
||||
|
@ -51,6 +54,8 @@ public class SequenceActionUseItem extends SequenceAction {
|
|||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
|
||||
x = nbt.getInteger("x");
|
||||
y = nbt.getInteger("y");
|
||||
z = nbt.getInteger("z");
|
||||
|
|
|
@ -31,6 +31,13 @@ import buildcraft.tests.ItemTester;
|
|||
|
||||
public class TileTestCase extends TileEntity {
|
||||
|
||||
/**
|
||||
* This way of handling the current test case means that test cases only
|
||||
* work on single player, as this field needs to be share between both
|
||||
* threads.
|
||||
*/
|
||||
public static TileTestCase currentTestCase;
|
||||
|
||||
Sequence sequence;
|
||||
String testName = "test";
|
||||
|
||||
|
@ -38,6 +45,13 @@ public class TileTestCase extends TileEntity {
|
|||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
if (currentTestCase == null && !worldObj.isRemote) {
|
||||
currentTestCase = this;
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void itemUsed(PlayerInteractEvent evt) {
|
||||
if (!evt.entity.worldObj.isRemote) {
|
||||
|
@ -49,12 +63,16 @@ public class TileTestCase extends TileEntity {
|
|||
ItemStack usedItem = evt.entityPlayer.inventory.getCurrentItem();
|
||||
|
||||
if (usedItem != null && !(usedItem.getItem() instanceof ItemTester)) {
|
||||
sequence.actions.add(new SequenceActionUseItem(evt.entity.worldObj, usedItem, evt.x, evt.y, evt.z));
|
||||
registerAction(new SequenceActionUseItem(evt.entity.worldObj, usedItem, evt.x, evt.y, evt.z));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void registerAction(SequenceAction action) {
|
||||
sequence.actions.add(action);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate() {
|
||||
super.invalidate();
|
||||
|
@ -83,6 +101,8 @@ public class TileTestCase extends TileEntity {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
currentTestCase = null;
|
||||
}
|
||||
|
||||
@RPC(RPCSide.SERVER)
|
||||
|
|
Loading…
Reference in a new issue