diff --git a/src/base/gcewing/sg/BaseBlock.java b/src/base/gcewing/sg/BaseBlock.java index 495d0b8f..0ca72add 100644 --- a/src/base/gcewing/sg/BaseBlock.java +++ b/src/base/gcewing/sg/BaseBlock.java @@ -150,7 +150,6 @@ protected void addProperty(IProperty property) { int i = numProperties++; properties[i] = property; Object[] values = BaseUtils.arrayOf(property.getAllowedValues()); - //Arrays.sort(values); propertyValues[i] = values; } else @@ -213,15 +212,12 @@ public int getMetaFromState(IBlockState state) { for (int i = numProperties - 1; i >= 0; i--) { Object value = state.getValue(properties[i]); Object[] values = propertyValues[i]; - //int k = Arrays.binarySearch(values, value); int k = values.length - 1; while (k > 0 && !values[k].equals(value)) --k; if (debugState) System.out.printf("BaseBlock.getMetaFromState: property %s value %s --> %s of %s\n", i, value, k, values.length); - //if (k < 0) - // k = 0; meta = meta * values.length + k; } if (debugState) diff --git a/src/base/gcewing/sg/BaseModClient.java b/src/base/gcewing/sg/BaseModClient.java index 9ec193a5..02baa23b 100644 --- a/src/base/gcewing/sg/BaseModClient.java +++ b/src/base/gcewing/sg/BaseModClient.java @@ -337,11 +337,10 @@ GuiScreen getGuiScreen(int id, EntityPlayer player, World world, BlockPos pos, i public interface ICustomRenderer { void renderBlock(IBlockAccess world, BlockPos pos, IBlockState state, IRenderTarget target, EnumWorldBlockLayer layer, Trans3 t); - void renderItemStack(ItemStack stack, IRenderTarget target); + void renderItemStack(ItemStack stack, IRenderTarget target, Trans3 t); } public interface ITexture { - //TextureAtlasSprite getIcon(); ResourceLocation location(); int tintIndex(); double red(); @@ -512,6 +511,11 @@ protected ItemRenderDispatcher getItemRenderDispatcher() { protected static BaseGLRenderTarget glTarget = new BaseGLRenderTarget(); + protected static Trans3 entityTrans = Trans3.blockCenter; + protected static Trans3 equippedTrans = Trans3.blockCenter; + protected static Trans3 firstPersonTrans = Trans3.blockCenterSideTurn(0, 3); + protected static Trans3 inventoryTrans = Trans3.blockCenter; + protected class ItemRenderDispatcher implements IItemRenderer { public boolean handleRenderType(ItemStack item, ItemRenderType type) { @@ -523,21 +527,6 @@ public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRe } public void renderItem(ItemRenderType type, ItemStack stack, Object... data) { -// EntityLiving entity = null; -// RenderBlocks rb = null; - switch (type) { - case ENTITY: - case EQUIPPED: - case EQUIPPED_FIRST_PERSON: -// rb = (RenderBlocks)data[0]; -// entity = (EntityLiving)data[1]; -// break; - case INVENTORY: -// rb = (RenderBlocks)data[0]; - break; - default: - return; - } if (debugRenderItem) System.out.printf("BaseModClient.ItemRenderDispatcher.renderItem: %s %s\n", type, stack); ICustomRenderer renderer = itemRenderers.get(stack.getItem()); if (debugRenderItem) System.out.printf("BaseModClient.ItemRenderDispatcher.renderItem: Custom renderer = %s\n", renderer); @@ -546,8 +535,16 @@ public void renderItem(ItemRenderType type, ItemStack stack, Object... data) { if (debugRenderItem) System.out.printf("BaseModClient.ItemRenderDispatcher.renderItem: Model renderer = %s\n", renderer); } if (renderer != null) { + Trans3 t; + switch (type) { + case ENTITY: t = entityTrans; break; + case EQUIPPED: t = equippedTrans; break; + case EQUIPPED_FIRST_PERSON: t = firstPersonTrans; break; + case INVENTORY: t = inventoryTrans; break; + default: return; + } glTarget.start(false); - renderer.renderItemStack(stack, glTarget); + renderer.renderItemStack(stack, glTarget, t); glTarget.finish(); } } @@ -632,11 +629,11 @@ public void renderBlockUsingModelSpec(IBlockAccess world, BlockPos pos, IBlockSt } // Call this from renderItemStack of an ICustomRenderer to fall back to model spec - public void renderItemStackUsingModelSpec(ItemStack stack, IRenderTarget target) { + public void renderItemStackUsingModelSpec(ItemStack stack, IRenderTarget target, Trans3 t) { ICustomRenderer rend = getModelRendererForItemStack(stack); if (debugRenderItem) System.out.printf("BaseModClient.renderItemStackUsingModelSpec: renderer = %s\n", rend); if (rend != null) - rend.renderItemStack(stack, target); + rend.renderItemStack(stack, target, t); } public IModel getModel(String name) { diff --git a/src/base/gcewing/sg/BaseModelRenderer.java b/src/base/gcewing/sg/BaseModelRenderer.java index 8b6828bb..d29a1f00 100644 --- a/src/base/gcewing/sg/BaseModelRenderer.java +++ b/src/base/gcewing/sg/BaseModelRenderer.java @@ -22,7 +22,7 @@ public class BaseModelRenderer implements ICustomRenderer { protected ITexture[] textures; protected Vector3 origin; - private static Trans3 itemTrans = Trans3.blockCenterSideTurn(0, 0); +// private static Trans3 itemTrans = Trans3.blockCenterSideTurn(0, 0); public BaseModelRenderer(IModel model, ITexture... textures) { this(model, Vector3.zero, textures); @@ -42,14 +42,14 @@ public void renderBlock(IBlockAccess world, BlockPos pos, IBlockState state, IRe model.render(t2, target, textures); } - public void renderItemStack(ItemStack stack, IRenderTarget target) { + public void renderItemStack(ItemStack stack, IRenderTarget target, Trans3 t) { if (debugRenderModel) { System.out.printf("BaseModelRenderer.renderItemStack: %s\n", stack); System.out.printf("BaseModelRenderer.renderItemStack: model = %s\n", model); for (int i = 0; i < textures.length; i++) System.out.printf("BaseModelRenderer.renderItemStack: textures[%s] = %s\n", i, textures[i]); } - model.render(itemTrans.translate(origin), target, textures); + model.render(t.translate(origin), target, textures); } } diff --git a/src/base/gcewing/sg/BaseOrientation.java b/src/base/gcewing/sg/BaseOrientation.java index 4230f197..d38db590 100644 --- a/src/base/gcewing/sg/BaseOrientation.java +++ b/src/base/gcewing/sg/BaseOrientation.java @@ -19,7 +19,8 @@ public class BaseOrientation { - public static boolean debugPlacement = true; + public static boolean debugPlacement = false; + public static boolean debugOrientation = false; public static IOrientationHandler orient4WaysByState = new Orient4WaysByState(); public static IOrientationHandler orient24WaysByTE = new Orient24WaysByTE(); @@ -50,7 +51,7 @@ protected EnumFacing getHorizontalFacing(Entity entity) { public Trans3 localToGlobalTransformation(IBlockAccess world, BlockPos pos, IBlockState state, Vector3 origin) { EnumFacing f = (EnumFacing)state.getValue(FACING); - if (BaseModClient.debugRenderBlock) + if (debugOrientation) System.out.printf("BaseOrientation.Orient4WaysByState.localToGlobalTransformation: for %s: facing = %s\n", state, f); int i; diff --git a/src/base/gcewing/sg/BlockPos.java b/src/base/gcewing/sg/BlockPos.java index 8639b210..2e70658c 100644 --- a/src/base/gcewing/sg/BlockPos.java +++ b/src/base/gcewing/sg/BlockPos.java @@ -36,6 +36,10 @@ public BlockPos offset(EnumFacing dir) { return new BlockPos(x + v.getX(), y + v.getY(), z + v.getZ()); } + public boolean equals(BlockPos other) { + return this.x == other.x && this.y == other.y && this.z == other.z; + } + @Override public String toString() { return String.format("(%s,%s,%s)", x, y, z); diff --git a/src/mod/gcewing/sg/DHDBlock.java b/src/mod/gcewing/sg/DHDBlock.java index 6d3cc223..1cc73cc6 100644 --- a/src/mod/gcewing/sg/DHDBlock.java +++ b/src/mod/gcewing/sg/DHDBlock.java @@ -64,7 +64,7 @@ public boolean isOpaqueCube() { @Override public void onBlockAdded(World world, BlockPos pos, IBlockState state) { if (SGBaseBlock.debugMerge) - System.out.printf("DHDBlock.onBlockAdded: at %d\n", pos); + System.out.printf("DHDBlock.onBlockAdded: at %s\n", pos); checkForLink(world, pos); } @@ -75,7 +75,6 @@ public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, Entity } @Override -// public boolean canHarvestBlock(IBlockAccess world, BlockPos pos, EntityPlayer player) { public boolean canHarvestBlock(IBlockState state, EntityPlayer player) { return true; } diff --git a/src/mod/gcewing/sg/DHDScreen.java b/src/mod/gcewing/sg/DHDScreen.java index 314fa104..8c619a5a 100644 --- a/src/mod/gcewing/sg/DHDScreen.java +++ b/src/mod/gcewing/sg/DHDScreen.java @@ -95,8 +95,8 @@ public void updateScreen() { } @Override - public void mousePressed(int x, int y, int mouseButton) { - System.out.printf("DHDScreen.mousePressed: %d, %d, %d\n", x, y, mouseButton); + protected void mousePressed(int x, int y, int mouseButton) { + //System.out.printf("DHDScreen.mousePressed: %d, %d, %d\n", x, y, mouseButton); if (mouseButton == 0) { int i = findDHDButton(x, y); if (i >= 0) { @@ -140,12 +140,12 @@ int findDHDButton(int mx, int my) { i0 = 27; nb = 11; } int i = i0 + (int)Math.floor(a * nb / 360); - System.out.printf("DHDScreen.findDHDButton: i = %d\n", i); + //System.out.printf("DHDScreen.findDHDButton: i = %d\n", i); return i; } void dhdButtonPressed(int i) { - System.out.printf("DHDScreen.dhdButtonPressed: %d\n", i); + //System.out.printf("DHDScreen.dhdButtonPressed: %d\n", i); buttonSound(); if (i == 0) orangeButtonPressed(false); @@ -181,9 +181,7 @@ else if (key == Keyboard.KEY_RETURN || key == Keyboard.KEY_NUMPADENTER) void orangeButtonPressed(boolean connectOnly) { SGBaseTE te = getStargateTE(); - System.out.printf("DHDScreen.orangeButtonPressed: connectOnly = %s, te = %s\n", connectOnly, te); if (te != null) { - System.out.printf("DHDScreen.orangeButtonPressed: state = %s\n", te.state); if (te.state == SGState.Idle) sendConnectOrDisconnect(te, getEnteredAddress()); else if (!connectOnly) @@ -192,7 +190,6 @@ else if (!connectOnly) } void sendConnectOrDisconnect(SGBaseTE te, String address) { - System.out.printf("DHDScreen.sendConnectOrDisconnect: %s %s\n", te, address); SGChannel.sendConnectOrDisconnectToServer(te, address); closeAfterDelay(10); } diff --git a/src/mod/gcewing/sg/IrisEntity.java b/src/mod/gcewing/sg/IrisEntity.java index c7aef135..db09e50b 100644 --- a/src/mod/gcewing/sg/IrisEntity.java +++ b/src/mod/gcewing/sg/IrisEntity.java @@ -22,6 +22,8 @@ public class IrisEntity extends BaseEntity implements IEntityAdditionalSpawnData { + public static boolean debugIrisEntity = false; + BlockPos blockPos; public IrisEntity(World world) { @@ -48,7 +50,8 @@ public IrisEntity(SGBaseTE te) { } void init(BlockPos pos, AxisAlignedBB box) { - //System.out.printf("IrisEntity.init: %s at %s box %s\n", this, pos, box); + if (debugIrisEntity) + System.out.printf("IrisEntity.init: %s at %s box %s\n", this, pos, box); this.blockPos = pos; setPosition(box.minX, box.minY, box.minZ); setBoundingBox(box); @@ -93,7 +96,8 @@ public boolean canBePushed() { @Override public void readEntityFromNBT(NBTTagCompound nbt) { - //System.out.printf("IrisEntity.readEntityFromNBT\n"); + if (debugIrisEntity) + System.out.printf("IrisEntity.readEntityFromNBT: %s\n", nbt); int blockX = nbt.getInteger("blockX"); int blockY = nbt.getInteger("blockY"); int blockZ = nbt.getInteger("blockZ"); @@ -110,7 +114,6 @@ public void readEntityFromNBT(NBTTagCompound nbt) { @Override public void writeEntityToNBT(NBTTagCompound nbt) { - //System.out.printf("IrisEntity.writeEntityToNBT\n"); nbt.setInteger("blockX", blockPos.getX()); nbt.setInteger("blockY", blockPos.getY()); nbt.setInteger("blockZ", blockPos.getZ()); @@ -121,6 +124,8 @@ public void writeEntityToNBT(NBTTagCompound nbt) { nbt.setDouble("maxX", box.maxX); nbt.setDouble("maxY", box.maxY); nbt.setDouble("maxZ", box.maxZ); + if (debugIrisEntity) + System.out.printf("IrisEntity.writeEntityToNBT: %s\n", nbt); } @Override diff --git a/src/mod/gcewing/sg/SGBaseBlock.java b/src/mod/gcewing/sg/SGBaseBlock.java index 57fc75a1..da83b943 100644 --- a/src/mod/gcewing/sg/SGBaseBlock.java +++ b/src/mod/gcewing/sg/SGBaseBlock.java @@ -108,7 +108,7 @@ public boolean isMerged(IBlockAccess world, BlockPos pos) { @Override public void onBlockAdded(World world, BlockPos pos, IBlockState state) { if (SGBaseBlock.debugMerge) - System.out.printf("SGBaseBlock.onBlockAdded: at %d\n", pos); + System.out.printf("SGBaseBlock.onBlockAdded: at %s\n", pos); checkForMerge(world, pos); } @@ -252,7 +252,7 @@ void unmergeRing(World world, BlockPos pos) { void unmergeRingBlock(World world, BlockPos pos, BlockPos ringPos) { //System.out.printf("SGBaseBlock.unmergeRingBlock at (%d,%d,%d)\n", xr, yr, zr); - Block block = getWorldBlock(world, pos); + Block block = getWorldBlock(world, ringPos); if (debugMerge) System.out.printf("SGBaseBlock.unmergeRingBlock: found %s at %s\n", block, ringPos); if (block instanceof SGRingBlock) { diff --git a/src/mod/gcewing/sg/SGBaseTE.java b/src/mod/gcewing/sg/SGBaseTE.java index 4959f6cc..84543b33 100644 --- a/src/mod/gcewing/sg/SGBaseTE.java +++ b/src/mod/gcewing/sg/SGBaseTE.java @@ -11,7 +11,6 @@ import org.apache.logging.log4j.*; import io.netty.channel.*; -import net.minecraft.client.renderer.texture.ITickable; import net.minecraft.entity.*; import net.minecraft.entity.player.*; import net.minecraft.inventory.*; @@ -41,7 +40,7 @@ import static gcewing.sg.BaseInventoryUtils.*; import static gcewing.sg.Utils.*; -public class SGBaseTE extends BaseTileInventory implements ITickable { +public class SGBaseTE extends BaseTileInventory { static boolean debugState = false; static boolean debugEnergyUse = false; @@ -54,7 +53,7 @@ public class SGBaseTE extends BaseTileInventory implements ITickable { public final static double ringSymbolAngle = 360.0 / numRingSymbols; public final static double irisZPosition = 0.1; public final static double irisThickness = 0.2; //0.1; - public final static DamageSource irisDamageSource = new DamageSource("sgcraft:iris"); //new IrisDamageSource(); + public final static DamageSource irisDamageSource = new DamageSource("sgcraft:iris"); public final static float irisDamageAmount = 1000000; final static int[] diallingTime = {40, 28}; // ticks @@ -95,7 +94,7 @@ public class SGBaseTE extends BaseTileInventory implements ITickable { public static boolean transparency = true; static Random random = new Random(); - static DamageSource transientDamage = new DamageSource("sgcraft:transient"); //new TransientDamageSource(); + static DamageSource transientDamage = new DamageSource("sgcraft:transient"); public boolean isMerged; public SGState state = SGState.Idle; @@ -400,7 +399,7 @@ public void updateEntity() { tick(); } - @Override +// @Override public void tick() { if (worldObj.isRemote) clientUpdate(); @@ -438,7 +437,6 @@ void enterState(SGState newState, int newTimeout) { String oldDesc = sgStateDescription(oldState); String newDesc = sgStateDescription(newState); if (!oldDesc.equals(newDesc)) - //postEvent("sgStargateStateChange", "oldState", oldDesc, "newState", newDesc); postEvent("sgStargateStateChange", newDesc, oldDesc); } @@ -483,7 +481,7 @@ public void unlinkFromController() { public void clearLinkToController() { if (SGBaseBlock.debugMerge) - System.out.printf("SGBaseTE: Unlinking stargate at %d from controller\n", getPos()); + System.out.printf("SGBaseTE: Unlinking stargate at %s from controller\n", getPos()); isLinkedToController = false; markDirty(); } @@ -651,7 +649,6 @@ void startDiallingStargate(String address, SGBaseTE dte, boolean initiator) { isInitiator = initiator; markDirty(); startDiallingNextSymbol(); - //postEvent(initiator ? "sgDialOut" : "sgDialIn", "address", address); postEvent(initiator ? "sgDialOut" : "sgDialIn", address); } @@ -870,9 +867,6 @@ void startDiallingToAngle(double a) { void finishDiallingSymbol() { ++numEngagedChevrons; -// postEvent("sgChevronEngaged", -// "chevron", numEngagedChevrons, -// "symbol", dialledAddress.substring(numEngagedChevrons - 1, numEngagedChevrons)); String symbol = dialledAddress.substring(numEngagedChevrons - 1, numEngagedChevrons); postEvent("sgChevronEngaged", numEngagedChevrons, symbol); if (undialledDigitsRemaining()) @@ -1456,7 +1450,6 @@ void enterIrisState(IrisState newState) { } } if (!oldDesc.equals(newDesc)) - //postEvent("sgIrisStateChange", "oldState", oldDesc, "newState", newDesc); postEvent("sgIrisStateChange", newDesc, oldDesc); } } @@ -1568,23 +1561,17 @@ public boolean hasBaseCornerCamouflage() { public boolean hasBaseCamouflageAt(int i) { return numItemsInSlot(firstCamouflageSlot + i) > 0; } - - static int rdx[] = {1, 0, -1, 0}; - static int rdz[] = {0, -1, 0, 1}; // Find locations of tile entities that could connect to the stargate ring. // TODO: Cache this public Collection adjacentTiles() { Collection result = new ArrayList(); - int r = turn; + Trans3 t = localToGlobalTransformation(); for (int i = -2; i <= 2; i++) { - //System.out.printf("SGBaseTE.adjacentTiles: Looking at (%s,%s,%s)\n", - // xCoord + rdx[r], yCoord - 1, zCoord + rdz[r]); - TileEntity te = getWorldTileEntity(worldObj, getPos().add(i * rdx[r], -1, i * rdz[r])); - if (te != null) { - //System.out.printf("SGBaseTE.adjacentTiles: Found %s\n", te); + BlockPos bp = t.p(i, -1, 0).blockPos(); + TileEntity te = getWorldTileEntity(worldObj, bp); + if (te != null) result.add(new BlockRef(te)); - } } return result; } @@ -1605,22 +1592,22 @@ void rebroadcastNetworkPacket(Object packet) { } } - public void sendMessage(Object[] args) { + public String sendMessage(Object[] args) { SGBaseTE dte = getConnectedStargateTE(); - if (dte != null) + if (dte != null) { dte.postEvent("sgMessageReceived", args); + return null; + } + else + return "Stargate not connected"; } void postEvent(String name, Object... args) { - //System.out.printf("SGBaseTE.postEvent: %s from (%s,%s,%s)\n", name, - // xCoord, yCoord, zCoord); + //System.out.printf("SGBaseTE.postEvent: %s from %s\n", name, getTileEntityPos(this)); for (BlockRef b : adjacentTiles()) { TileEntity te = b.getTileEntity(); - if (te instanceof IComputerInterface) { - //System.out.printf("SGBaseTE.postEvent: to TE at (%s,%s,%s)\n", - // b.xCoord, b.yCoord, b.zCoord); + if (te instanceof IComputerInterface) ((IComputerInterface)te).postEvent(this, name, args); - } } } diff --git a/src/mod/gcewing/sg/SGInterfaceTE.java b/src/mod/gcewing/sg/SGInterfaceTE.java index 1cfd63ee..69100b0a 100644 --- a/src/mod/gcewing/sg/SGInterfaceTE.java +++ b/src/mod/gcewing/sg/SGInterfaceTE.java @@ -165,9 +165,10 @@ public void ciCloseIris() { } public void ciSendMessage(Object[] args) { - SGBaseTE te = getBaseTE(); - if (te != null) - te.sendMessage(args); + SGBaseTE te = requireBaseTE(); + String error = te.sendMessage(args); + if (error != null) + throw new IllegalArgumentException(error); } } diff --git a/src/mod/gcewing/sg/SGRingBlock.java b/src/mod/gcewing/sg/SGRingBlock.java index 5c5f0b29..de58c5b7 100644 --- a/src/mod/gcewing/sg/SGRingBlock.java +++ b/src/mod/gcewing/sg/SGRingBlock.java @@ -154,10 +154,13 @@ public void mergeWith(World world, BlockPos pos, BlockPos basePos) { public void unmergeFrom(World world, BlockPos pos, BlockPos basePos) { SGRingTE te = getTileEntity(world, pos); + if (SGBaseBlock.debugMerge) + System.out.printf("SGRingBlock.unmergeFrom: ring at %s base at %s te.isMerged = %s te.basePos = %s\n", + pos, basePos, te.isMerged, te.basePos); if (te.isMerged && te.basePos.equals(basePos)) { - //System.out.printf("SGRingBlock.unmergeFrom: unmerging\n"); + if (SGBaseBlock.debugMerge) + System.out.printf("SGRingBlock.unmergeFrom: unmerging\n"); te.isMerged = false; - //te.onInventoryChanged(); markWorldBlockForUpdate(world, pos); } } diff --git a/src/mod/gcewing/sg/SGRingBlockRenderer.java b/src/mod/gcewing/sg/SGRingBlockRenderer.java index 71a03dc1..c890448a 100644 --- a/src/mod/gcewing/sg/SGRingBlockRenderer.java +++ b/src/mod/gcewing/sg/SGRingBlockRenderer.java @@ -50,10 +50,10 @@ public void renderBlock(IBlockAccess world, BlockPos pos, IBlockState state, IRe } } - public void renderItemStack(ItemStack stack, IRenderTarget target) { + public void renderItemStack(ItemStack stack, IRenderTarget target, Trans3 t) { if (BaseModClient.debugRenderItem) System.out.printf("SGRingBlockRenderer.renderItemStack: %s\n", stack); - SGCraft.mod.client.renderItemStackUsingModelSpec(stack, target); + SGCraft.mod.client.renderItemStackUsingModelSpec(stack, target, t); } } diff --git a/src/mod/gcewing/sg/cc/CCInterfaceTE.java b/src/mod/gcewing/sg/cc/CCInterfaceTE.java index 4210b8f2..46478a7e 100644 --- a/src/mod/gcewing/sg/cc/CCInterfaceTE.java +++ b/src/mod/gcewing/sg/cc/CCInterfaceTE.java @@ -20,11 +20,8 @@ public class CCInterfaceTE extends SGInterfaceTE implements IComputerInterface { public void postEvent(TileEntity source, String name, Object... args) { //System.out.printf("CCInterfaceTE.postEvent: %s\n", name); - for (IComputerAccess cpu : attachedComputers) { - //System.out.printf("CCInterfaceTE.postEvent: to %s\n", cpu); - //cpu.queueEvent(name, new Object[]{args}); + for (IComputerAccess cpu : attachedComputers) cpu.queueEvent(name, prependArgs(cpu.getAttachmentName(), args)); - } } } diff --git a/src/mod/gcewing/sg/cc/CCPeripheralProvider.java b/src/mod/gcewing/sg/cc/CCPeripheralProvider.java index 61feb0f2..49d2b195 100644 --- a/src/mod/gcewing/sg/cc/CCPeripheralProvider.java +++ b/src/mod/gcewing/sg/cc/CCPeripheralProvider.java @@ -18,20 +18,10 @@ public class CCPeripheralProvider implements IPeripheralProvider { @Override public IPeripheral getPeripheral(World world, int x, int y, int z, int side) { TileEntity te = world.getTileEntity(x, y, z); - //System.out.printf("CCPeripheralProvider.getPeripheral: found %s\n", te); if (te instanceof CCInterfaceTE) return new CCSGPeripheral((CCInterfaceTE)te); else return null; } -// @Override -// public IPeripheral getPeripheral(World world, int x, int y, int z, int side) { -// TileEntity te = world.getTileEntity(x, y, z); -// if (te instanceof IPeripheral) -// return (IPeripheral)te; -// else -// return null; -// } - } diff --git a/src/mod/gcewing/sg/cc/CCSGPeripheral.java b/src/mod/gcewing/sg/cc/CCSGPeripheral.java index 852f4f24..583c2459 100644 --- a/src/mod/gcewing/sg/cc/CCSGPeripheral.java +++ b/src/mod/gcewing/sg/cc/CCSGPeripheral.java @@ -139,6 +139,7 @@ public String[] getMethodNames() { public Object[] callMethod(IComputerAccess cpu, ILuaContext ctx, int method, Object[] args) throws LuaException, InterruptedException { + //System.out.printf("CCSGPeripheral.callMethod: %s\n", method); if (method >= 0 && method < methods.length) return CCMethodQueue.instance.invoke(cpu, ctx, this, methods[method], args); else @@ -169,6 +170,8 @@ public boolean equals(IPeripheral other) { abstract class SGMethod extends CCMethod { + private static Object[] success = {true}; + public SGMethod(String name) { super(name); } @@ -179,11 +182,20 @@ public SGMethod(String name, int nargs) { @Override Object[] call(IComputerAccess cpu, ILuaContext ctx, Object target, Object[] args) { - SGInterfaceTE te = ((CCSGPeripheral)target).getInterfaceTE(); - if (te != null) - return call(te, args); - else - throw new IllegalArgumentException("Stargate interface failed internal diagnostics"); + try { + SGInterfaceTE te = ((CCSGPeripheral)target).getInterfaceTE(); + if (te != null) { + Object[] result = call(te, args); + if (result == null) + result = success; + return result; + } + else + throw new IllegalArgumentException("Stargate interface failed internal diagnostics"); + } + catch (Exception e) { + return new Object[] {null, e.getMessage()}; + } } abstract Object[] call(SGInterfaceTE te, Object[] args); diff --git a/src/mod/gcewing/sg/oc/OCInterfaceTE.java b/src/mod/gcewing/sg/oc/OCInterfaceTE.java index 8f203e11..75d82461 100644 --- a/src/mod/gcewing/sg/oc/OCInterfaceTE.java +++ b/src/mod/gcewing/sg/oc/OCInterfaceTE.java @@ -31,6 +31,7 @@ public class OCInterfaceTE extends SGInterfaceTE implements IComputerInterface, Environment, IInventory { + static boolean debugConnection = false; static boolean debugNetworking = false; final static int numUpgradeSlots = 1; @@ -41,7 +42,7 @@ public OCInterfaceTE() { node = Network.newNode(this, Visibility.Network) .withComponent("stargate", Visibility.Network) .create(); - System.out.printf("OCInterfaceTE: Created node %s\n", node); + //System.out.printf("OCInterfaceTE: Created node %s\n", node); } //@Override @@ -81,74 +82,86 @@ public void rebroadcastNetworkPacket(Object packet) { // -------------------------- Methods -------------------------- + protected static Object[] success = {true}; + + protected static Object[] failure(Exception e) { + return new Object[] {null, e.getMessage()}; + } + @Callback public Object[] stargateState(Context ctx, Arguments args) { - CIStargateState result = ciStargateState(); - return new Object[]{result.state, result.chevrons, result.direction}; + try { + CIStargateState result = ciStargateState(); + return new Object[]{result.state, result.chevrons, result.direction}; + } + catch (Exception e) {return failure(e);} } @Callback public Object[] energyAvailable(Context ctx, Arguments args) { - return new Object[]{ciEnergyAvailable()}; + try {return new Object[]{ciEnergyAvailable()};} + catch (Exception e) {return failure(e);} } @Callback public Object[] energyToDial(Context ctx, Arguments args) { - return new Object[]{ciEnergyToDial(args.checkString(0))}; + try {return new Object[]{ciEnergyToDial(args.checkString(0))};} + catch (Exception e) {return failure(e);} } @Callback public Object[] localAddress(Context ctx, Arguments args) { - return new Object[]{ciLocalAddress()}; + try {return new Object[]{ciLocalAddress()};} + catch (Exception e) {return failure(e);} } @Callback public Object[] remoteAddress(Context ctx, Arguments args) { - return new Object[]{ciRemoteAddress()}; + try {return new Object[]{ciRemoteAddress()};} + catch (Exception e) {return failure(e);} } @Callback public Object[] dial(Context ctx, Arguments args) { - ciDial(args.checkString(0)); - return null; + try {ciDial(args.checkString(0)); return success;} + catch (Exception e) {return failure(e);} } @Callback public Object[] disconnect(Context ctx, Arguments args) { - ciDisconnect(); - return null; + try {ciDisconnect(); return success;} + catch (Exception e) {return failure(e);} } -// @Callback -// public Object[] direction(Context ctx, Arguments args) { -// return new Object[]{ciDirection()}; -// } - @Callback public Object[] irisState(Context ctx, Arguments args) { - return new Object[]{ciIrisState()}; + try {return new Object[]{ciIrisState()};} + catch (Exception e) {return failure(e);} } @Callback public Object[] openIris(Context ctx, Arguments args) { - ciOpenIris(); - return null; + try {ciOpenIris(); return success;} + catch (Exception e) {return failure(e);} } @Callback public Object[] closeIris(Context ctx, Arguments args) { - ciCloseIris(); - return null; + try {ciCloseIris(); return success;} + catch (Exception e) {return failure(e);} } @Callback public Object[] sendMessage(Context ctx, Arguments args) { - int n = args.count(); - Object[] objs = new Object[n]; - for (int i = 0; i < n; i++) - objs[i] = args.checkAny(i); - ciSendMessage(objs); - return null; + try { + int n = args.count(); + Object[] objs = new Object[n]; + for (int i = 0; i < n; i++) + objs[i] = args.checkAny(i); + ciSendMessage(objs); + return success; + } + catch (Exception e) {return failure(e);} } // -------------------------- Environment -------------------------- @@ -205,7 +218,8 @@ public void onConnect(final Node node) { // network our node is in, in which case `node` is the added node. // If our node is added to an existing network, this is called for each // node already in said network. - System.out.printf("OCInterfaceTE.onConnect: %s\n", node); + if (debugConnection) + System.out.printf("OCInterfaceTE.onConnect: %s\n", node); } @Override @@ -217,7 +231,8 @@ public void onDisconnect(final Node node) { // network our node is in, in which case `node` is the removed node. // If a net-split occurs this is called for each node that is no longer // connected to our node. - System.out.printf("OCInterfaceTE.onDisconnect: %s\n", node); + if (debugConnection) + System.out.printf("OCInterfaceTE.onDisconnect: %s\n", node); } @Override