diff --git a/src/main/java/cr0s/warpdrive/block/movement/BlockTransporter.java b/src/main/java/cr0s/warpdrive/block/movement/BlockTransporter.java index b00b9882..81686537 100644 --- a/src/main/java/cr0s/warpdrive/block/movement/BlockTransporter.java +++ b/src/main/java/cr0s/warpdrive/block/movement/BlockTransporter.java @@ -1,8 +1,12 @@ package cr0s.warpdrive.block.movement; +import cpw.mods.fml.common.FMLCommonHandler; +import cr0s.warpdrive.WarpDrive; import cr0s.warpdrive.block.BlockAbstractContainer; +import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IIcon; import net.minecraft.world.World; @@ -14,6 +18,7 @@ public class BlockTransporter extends BlockAbstractContainer { public BlockTransporter() { super(Material.rock); setBlockName("warpdrive.movement.Transporter"); + setStepSound(Block.soundTypeMetal); } @Override @@ -38,4 +43,25 @@ public class BlockTransporter extends BlockAbstractContainer { return iconBuffer[2]; } + + + /** + * Called upon block activation (right click on the block.) + */ + @Override + public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) { + if (FMLCommonHandler.instance().getEffectiveSide().isClient()) { + return false; + } + + if (par5EntityPlayer.getHeldItem() == null) { + TileEntity te = par1World.getTileEntity(par2, par3, par4); + if (te != null && te instanceof TileEntityTransporter) { + WarpDrive.addChatMessage(par5EntityPlayer, ((TileEntityTransporter)te).getStatus()); + return true; + } + } + + return false; + } } \ No newline at end of file diff --git a/src/main/java/cr0s/warpdrive/block/movement/TileEntityLift.java b/src/main/java/cr0s/warpdrive/block/movement/TileEntityLift.java index d62b2a03..50786911 100644 --- a/src/main/java/cr0s/warpdrive/block/movement/TileEntityLift.java +++ b/src/main/java/cr0s/warpdrive/block/movement/TileEntityLift.java @@ -194,7 +194,11 @@ public class TileEntityLift extends TileEntityAbstractEnergy { @Callback @Optional.Method(modid = "OpenComputers") public Object[] mode(Context context, Arguments arguments) { - return mode(argumentsOCtoCC(arguments)); + return mode( + new Object[] { + arguments.checkString(0) + } + ); } @Callback @@ -216,12 +220,13 @@ public class TileEntityLift extends TileEntityAbstractEnergy { computerMode = MODE_REDSTONE; } } + switch (computerMode) { - case -1: + case MODE_REDSTONE: return new Object[] { "redstone" }; - case 1: + case MODE_UP: return new Object[] { "up" }; - case 2: + case MODE_DOWN: return new Object[] { "down" }; default: break; diff --git a/src/main/java/cr0s/warpdrive/block/movement/TileEntityTransporter.java b/src/main/java/cr0s/warpdrive/block/movement/TileEntityTransporter.java index 00a25469..4a659960 100644 --- a/src/main/java/cr0s/warpdrive/block/movement/TileEntityTransporter.java +++ b/src/main/java/cr0s/warpdrive/block/movement/TileEntityTransporter.java @@ -4,6 +4,9 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import li.cil.oc.api.machine.Arguments; +import li.cil.oc.api.machine.Callback; +import li.cil.oc.api.machine.Context; import cpw.mods.fml.common.Optional; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; @@ -73,8 +76,101 @@ public class TileEntityTransporter extends TileEntityAbstractEnergy implements I } } + @Override + public String getStatus() { + return getBlockType().getLocalizedName() + + String.format("Energy level is %.0f/%.0f EU.", + convertInternalToEU(getEnergyStored()), + convertInternalToEU(getMaxEnergyStored()) + ) + + String.format("\nSource: %.0f %.0f %.0f", + sourceVec.x, + sourceVec.y, + sourceVec.z + ) + + String.format("\nDestination: %.0f %.0f %.0f", + destVec.x, + destVec.y, + destVec.z + ); + } + + + + + // OpenComputer callback methods - // FIXME: implement OpenComputers... + // ------------------------------------------------------------------------------------------ + @Callback + @Optional.Method(modid = "OpenComputers") + public Object[] source(Context context, Arguments arguments) { + return setVec3(true, argumentsOCtoCC(arguments)); + } + + @Callback + @Optional.Method(modid = "OpenComputers") + public Object[] dest(Context context, Arguments arguments) { + return setVec3(false, argumentsOCtoCC(arguments)); + } + + @Callback + @Optional.Method(modid = "OpenComputers") + public Object[] lock(Context context, Arguments arguments) { + return new Object[] { + lock(sourceVec, destVec) + }; + } + + @Callback + @Optional.Method(modid = "OpenComputers") + public Object[] release(Context context, Arguments arguments) { + unlock(); + return new Object[] { + null + }; + } + + @Callback + @Optional.Method(modid = "OpenComputers") + public Object[] lockStrength(Context context, Arguments arguments) { + return new Object[] { + getLockStrength() + }; + } + + @Callback + @Optional.Method(modid = "OpenComputers") + public Object[] energize(Context context, Arguments arguments) { + return new Object[] { + energize() + }; + } + + @Callback + @Optional.Method(modid = "OpenComputers") + public Object[] powerBoost(Context context, Arguments arguments) { + return new Object[] { + powerBoost(argumentsOCtoCC(arguments)) + }; + } + + @Callback + @Optional.Method(modid = "OpenComputers") + public Object[] getEnergyRequired(Context context, Arguments arguments) { + return new Object[] { + getEnergyRequired() + }; + } + + @Callback + @Optional.Method(modid = "OpenComputers") + public Object[] help(Context context, Arguments arguments) { + return new Object[] { + helpStr(argumentsOCtoCC(arguments)) + }; + } + + // ComputerCraft IPeripheral methods implementation private static String helpStr(Object[] function) { @@ -102,8 +198,8 @@ public class TileEntityTransporter extends TileEntityAbstractEnergy implements I return "energize(): attempts to teleport all entities at source to dest. Returns the number of entities transported (-1 indicates a problem)."; } else if (methodName.equals("powerboost")) { return "powerBoost(boostAmount): sets the level of power to use (1 being default), returns the level of power\npowerBoost(): returns the level of power"; - } else if (methodName.equals("energycost")) { - return "energyCost(): returns the amount of energy it will take for a single entity to transport with the current settings"; + } else if (methodName.equals("getEnergyRequired")) { + return "getEnergyRequired(): returns the amount of energy it will take for a single entity to transport with the current settings"; } } return null; @@ -170,14 +266,7 @@ public class TileEntityTransporter extends TileEntityAbstractEnergy implements I return new Object[] { energize() }; } else if (methodName.equals("powerBoost")) { - try { - if (arguments.length >= 1) { - powerBoost = clamp(1, WarpDriveConfig.TRANSPORTER_MAX_BOOST_MUL, toDouble(arguments[0])); - } - } catch (NumberFormatException e) { - powerBoost = 1; - } - return new Object[] { powerBoost }; + return new Object[] { powerBoost(arguments) }; } else if (methodName.equals("getEnergyRequired")) { return new Object[] { getEnergyRequired() }; @@ -195,6 +284,19 @@ public class TileEntityTransporter extends TileEntityAbstractEnergy implements I } return null; } + + private double powerBoost(Object[] arguments) { + try { + if (arguments.length >= 1) { + powerBoost = clamp(1, WarpDriveConfig.TRANSPORTER_MAX_BOOST_MUL, toDouble(arguments[0])); + } + } catch (NumberFormatException e) { + powerBoost = 1; + } + + return powerBoost; + } + private int energize() { if (isLocked) {