Boolean test = RedstoneUtil.testAnyInput(world, underPt);
if (test == null || test) {
if (minecart.getType() == MinecartInterface.Type.STORAGE) {
Vector pt = new Vector(blockX, blockY, blockZ);
NearbyChestBlockBag bag = new NearbyChestBlockBag(pt);
for (int y = -1; y <= 0; y++) {
bag.addSingleSourcePosition(world, pt.add(1, y, 0));
bag.addSingleSourcePosition(world, pt.add(2, y, 0));
bag.addSingleSourcePosition(world, pt.add(-1, y, 0));
bag.addSingleSourcePosition(world, pt.add(-2, y, 0));
bag.addSingleSourcePosition(world, pt.add(0, y, 1));
bag.addSingleSourcePosition(world, pt.add(0, y, 2));
bag.addSingleSourcePosition(world, pt.add(0, y, -1));
bag.addSingleSourcePosition(world, pt.add(0, y, -2));
}
if (bag.getChestBlockCount() > 0) {
if (getControllerSign(world, pt.add(0, -1, 0), "[Deposit]") != null) {
InventoryUtil.moveChestBagToItemArray(
(StorageMinecartInterface) minecart, bag);
} else {
InventoryUtil.moveItemArrayToChestBag(
(StorageMinecartInterface) minecart, bag);
}
}
}
}
return;
} else if (under == minecartEjectBlock) {
Boolean test = RedstoneUtil.testAnyInput(world, underPt);
if (test == null || test) {
PlayerInterface player = minecart.getPlayer();
if (player != null) {
// Let's find a place to put the player
Tuple3<Integer, Integer, Integer> loc =
new Tuple3<Integer, Integer, Integer>(blockX, blockY, blockZ);
Vector signPos = new Vector(blockX, blockY - 2, blockZ);
if (world.getId(signPos) == BlockType.SIGN_POST
&& MinecraftUtil.doesSignSay(world, signPos, 1, "[Eject]")) {
Vector pos = MinecraftUtil.getSignPostOrthogonalBack(world, signPos, 1);
// Acceptable sign direction
if (pos != null) {
pos = pos.setY(blockY);
// Is the spot free?
if (BlockType.canPassThrough(world.getId(pos.add(0, 1, 0)))
&& BlockType.canPassThrough(world.getId(pos))) {
loc = new Tuple3<Integer, Integer, Integer>(
pos.getBlockX(),
pos.getBlockY(),
pos.getBlockZ());
BlockEntity cBlock = world.getBlockEntity(
blockX, blockY - 2, blockZ);
if (cBlock instanceof SignInterface) {
SignInterface sign = (SignInterface) cBlock;
String text = sign.getLine1();
if (text.length() > 0) {
player.sendMessage(Colors.GOLD + "You've arrived at: "
+ text);
}
}
}
}
}
player.setX(loc.a + 0.5);
player.setY(loc.b + 0.1);
player.setX(loc.c + 0.5);
}
}
return;
} else if (under == minecartSortBlock) {
Boolean test = RedstoneUtil.testAnyInput(world, underPt);
if (test == null || test) {
SignInterface sign =
getControllerSign(world, blockX, blockY - 1, blockZ, "[Sort]");
if (sign != null) {
SortDir dir = SortDir.FORWARD;
if (satisfiesCartSort(sign.getLine3(), minecart,
new Vector(blockX, blockY, blockZ))) {
dir = SortDir.LEFT;
} else if (satisfiesCartSort(sign.getLine4(), minecart,
new Vector(blockX, blockY, blockZ))) {
dir = SortDir.RIGHT;
}
int signData = world.getData(
sign.getX(), sign.getY(), sign.getZ());
int newData = 0;
Vector targetTrack = null;
if (signData == 0x8) { // West
if (dir == SortDir.LEFT) {
newData = 9;
} else if (dir == SortDir.RIGHT) {
newData = 8;
} else {
newData = 0;
}
targetTrack = new Vector(blockX, blockY, blockZ + 1);
} else if (signData == 0x0) { // East
if (dir == SortDir.LEFT) {
newData = 7;
} else if (dir == SortDir.RIGHT) {
newData = 6;
} else {
newData = 0;
}
targetTrack = new Vector(blockX, blockY, blockZ - 1);
} else if (signData == 0xC) { // North
if (dir == SortDir.LEFT) {
newData = 6;
} else if (dir == SortDir.RIGHT) {
newData = 9;
} else {
newData = 1;
}
targetTrack = new Vector(blockX - 1, blockY, blockZ);
} else if (signData == 0x4) { // South
if (dir == SortDir.LEFT) {
newData = 8;
} else if (dir == SortDir.RIGHT) {
newData = 7;
} else {
newData = 1;
}
targetTrack = new Vector(blockX + 1, blockY, blockZ);
}
if (targetTrack != null
&& world.getId(targetTrack) == BlockType.MINECART_TRACKS) {
world.setData(targetTrack, newData);
}
}
}
return;
}
}
if (minecartTrackMessages
&& world.getId(underPt.add(0, -1, 0)) == BlockType.SIGN_POST) {
Vector signPos = underPt.add(0, -1, 0);
Boolean test = RedstoneUtil.testAnyInput(world, signPos);
if (test == null || test) {
BlockEntity cblock = world.getBlockEntity(
signPos.getBlockX(), signPos.getBlockY(), signPos.getBlockZ());
if (!(cblock instanceof SignInterface)) {
return;
}
SignInterface sign = (SignInterface) cblock;
String line1 = sign.getLine1();
if (line1.equalsIgnoreCase("[Print]")) {
if (!minecart.hasPlayer()) {
return;
}
PlayerInterface player = minecart.getPlayer();
String name = player.getName();
String msg = sign.getLine2() + sign.getLine3() + sign.getLine4();
long now = System.currentTimeMillis();
if (lastMinecartMsg.containsKey(name)) {
String lastMessage = lastMinecartMsg.get(name);
if (lastMessage.equals(msg)
&& now < lastMinecartMsgTime.get(name) + 3000) {
return;
}
}
lastMinecartMsg.put(name, msg);
lastMinecartMsgTime.put(name, now);
player.sendMessage("> " + msg);
}
}
}
if (minecartDispensers) {
Vector pt = new Vector(blockX, blockY, blockZ);
Vector depositPt = null;
if (world.getId(pt.add(1, 0, 0)) == BlockType.CHEST
&& (world.getId(pt.add(-1, 0, 0)) == BlockType.MINECART_TRACKS
|| world.getId(pt.add(-1, -1, 0)) == BlockType.MINECART_TRACKS
|| world.getId(pt.add(-1, 1, 0)) == BlockType.MINECART_TRACKS)) {
depositPt = pt.add(1, 0, 0);
} else if (world.getId(pt.add(-1, 0, 0)) == BlockType.CHEST
&& (world.getId(pt.add(1, 0, 0)) == BlockType.MINECART_TRACKS
|| world.getId(pt.add(1, -1, 0)) == BlockType.MINECART_TRACKS
|| world.getId(pt.add(1, 1, 0)) == BlockType.MINECART_TRACKS)) {
depositPt = pt.add(-1, 0, 0);
} else if (world.getId(pt.add(0, 0, 1)) == BlockType.CHEST
&& (world.getId(pt.add(0, 0, -1)) == BlockType.MINECART_TRACKS
|| world.getId(pt.add(0, -1, -1)) == BlockType.MINECART_TRACKS
|| world.getId(pt.add(0, 1, -1)) == BlockType.MINECART_TRACKS)) {
depositPt = pt.add(0, 0, 1);
} else if (world.getId(pt.add(0, 0, -1)) == BlockType.CHEST
&& (world.getId(pt.add(0, 0, 1)) == BlockType.MINECART_TRACKS
|| world.getId(pt.add(0, -1, 1)) == BlockType.MINECART_TRACKS
|| world.getId(pt.add(0, 1, 1)) == BlockType.MINECART_TRACKS)) {
depositPt = pt.add(0, 0, -1);
}
if (depositPt != null) {
SignInterface sign =
getControllerSign(world, depositPt.add(0, -1, 0), "[Dispenser]");
String collectType = sign != null ? sign.getLine2() : "";
NearbyChestBlockBag blockBag = new NearbyChestBlockBag(depositPt);
blockBag.addSingleSourcePosition(world, depositPt);
blockBag.addSingleSourcePosition(world, depositPt.add(1, 0, 0));
blockBag.addSingleSourcePosition(world, depositPt.add(-1, 0, 0));
blockBag.addSingleSourcePosition(world, depositPt.add(0, 0, 1));
blockBag.addSingleSourcePosition(world, depositPt.add(0, 0, -1));
MinecartInterface.Type type = minecart.getType();
if (type == MinecartInterface.Type.REGULAR) {
try {
blockBag.storeBlock(ItemType.MINECART);
minecart.remove();
} catch (BlockBagException e) {
}
} else if (type == MinecartInterface.Type.STORAGE) {
try {
InventoryUtil.moveItemArrayToChestBag(
(StorageMinecartInterface) minecart, blockBag);
if (collectType.equalsIgnoreCase("Storage")) {
blockBag.storeBlock(ItemType.STORAGE_MINECART);
} else {
blockBag.storeBlock(ItemType.MINECART);
blockBag.storeBlock(BlockType.CHEST);
}
minecart.remove();
} catch (BlockBagException e) {
// Ran out of space
}
} else if (type == MinecartInterface.Type.POWERED) {
try {
if (collectType.equalsIgnoreCase("Powered")) {
blockBag.storeBlock(ItemType.POWERED_MINECART);
} else {
blockBag.storeBlock(ItemType.MINECART);
blockBag.storeBlock(BlockType.FURNACE);
}
minecart.remove();
} catch (BlockBagException e) {
// Ran out of space
}
}
blockBag.flushChanges();
}
}
}