Updated more TileEntities. Nearly done
This commit is contained in:
parent
38d693a6b3
commit
29216ee9c2
11 changed files with 1309 additions and 1217 deletions
|
@ -4,11 +4,15 @@ import java.io.ByteArrayOutputStream;
|
|||
import java.io.DataOutputStream;
|
||||
import java.util.List;
|
||||
|
||||
import jdk.nashorn.internal.runtime.regexp.joni.constants.Arguments;
|
||||
import li.cil.oc.api.machine.Arguments;
|
||||
import li.cil.oc.api.machine.Callback;
|
||||
import li.cil.oc.api.machine.Context;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
|
@ -18,6 +22,9 @@ import cr0s.warpdrive.WarpDrive;
|
|||
import cr0s.warpdrive.WarpDriveConfig;
|
||||
import cr0s.warpdrive.data.CloakedArea;
|
||||
import cr0s.warpdrive.data.Vector3;
|
||||
import dan200.computercraft.api.ComputerCraftAPI;
|
||||
import dan200.computercraft.api.lua.ILuaContext;
|
||||
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||
|
||||
public class TileEntityCloakingDeviceCore extends WarpEnergyTE {
|
||||
private final int MAX_ENERGY_VALUE = 500000000; // 500kk EU
|
||||
|
@ -146,7 +153,7 @@ public class TileEntityCloakingDeviceCore extends WarpEnergyTE {
|
|||
public void searchCoilInDirectionAndSetState(byte dx, byte dy, byte dz, boolean enabled) {
|
||||
int coilCount = 0;
|
||||
for (int i = 0; i < WarpDriveConfig.CD_MAX_CLOAKING_FIELD_SIDE; i++) {
|
||||
if (worldObj.getBlockId(xCoord + i * dx, yCoord + i * dy, zCoord + i * dz) == WarpDriveConfig.cloakCoilID) {
|
||||
if (worldObj.getBlock(xCoord + i * dx, yCoord + i * dy, zCoord + i * dz).isAssociatedBlock(WarpDrive.cloakCoilBlock)) {
|
||||
coilCount++;
|
||||
if (coilCount > 2) {
|
||||
return;
|
||||
|
@ -168,7 +175,7 @@ public class TileEntityCloakingDeviceCore extends WarpEnergyTE {
|
|||
}
|
||||
|
||||
for (int i = START_LENGTH + 1; i < WarpDriveConfig.CD_MAX_CLOAKING_FIELD_SIDE; i++) {
|
||||
if (worldObj.getBlockId(xCoord + i * dx, yCoord + i * dy, zCoord + i * dz) == WarpDriveConfig.cloakCoilID) {
|
||||
if (worldObj.getBlock(xCoord + i * dx, yCoord + i * dy, zCoord + i * dz).isAssociatedBlock(WarpDrive.cloakCoilBlock)) {
|
||||
sendLaserPacket(new Vector3(this).add(0.5), new Vector3(xCoord + i * dx, yCoord + i * dy, zCoord + i * dz).add(0.5), r, g, b, 110, 0, 100);
|
||||
}
|
||||
}
|
||||
|
@ -256,7 +263,7 @@ public class TileEntityCloakingDeviceCore extends WarpEnergyTE {
|
|||
for (y = minY; y <= maxY; y++) {
|
||||
for (x = minX; x <= maxX; x++) {
|
||||
for(z = minZ; z <= maxZ; z++) {
|
||||
if (worldObj.getBlockId(x, y, z) != 0) {
|
||||
if (!worldObj.getBlock(x, y, z) .isAssociatedBlock(Blocks.air)) {
|
||||
volume++;
|
||||
}
|
||||
}
|
||||
|
@ -297,7 +304,9 @@ public class TileEntityCloakingDeviceCore extends WarpEnergyTE {
|
|||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
Packet250CustomPayload packet = new Packet250CustomPayload();
|
||||
//TODO: Needs to be re-done according to http://www.minecraftforge.net/forum/index.php/topic,20135.0.html
|
||||
/*
|
||||
PacketCustomPayload packet = new Packet250CustomPayload();
|
||||
packet.channel = "WarpDriveBeam";
|
||||
packet.data = bos.toByteArray();
|
||||
packet.length = bos.size();
|
||||
|
@ -309,6 +318,7 @@ public class TileEntityCloakingDeviceCore extends WarpEnergyTE {
|
|||
((EntityPlayerMP)e).playerNetServerHandler.sendPacketToPlayer(packet);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -330,7 +340,7 @@ public class TileEntityCloakingDeviceCore extends WarpEnergyTE {
|
|||
|
||||
public int searchCoilInDirection(byte dx, byte dy, byte dz) {
|
||||
for (int i = 3; i < WarpDriveConfig.CD_MAX_CLOAKING_FIELD_SIDE; i++) {
|
||||
if (worldObj.getBlockId(xCoord + i * dx, yCoord + i * dy, zCoord + i * dz) == WarpDriveConfig.cloakCoilID) {
|
||||
if (worldObj.getBlock(xCoord + i * dx, yCoord + i * dy, zCoord + i * dz).isAssociatedBlock(WarpDrive.cloakCoilBlock)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
@ -347,7 +357,7 @@ public class TileEntityCloakingDeviceCore extends WarpEnergyTE {
|
|||
byte[] dz = { 0, 0, 0, 0, -1, 1 };
|
||||
|
||||
for (int i = 0; i < 6; i++) {
|
||||
if (worldObj.getBlockId(xCoord + START_LENGTH * dx[i], yCoord + START_LENGTH * dy[i], zCoord + START_LENGTH * dz[i]) != WarpDriveConfig.cloakCoilID) {
|
||||
if (worldObj.getBlock(xCoord + START_LENGTH * dx[i], yCoord + START_LENGTH * dy[i], zCoord + START_LENGTH * dz[i]).isAssociatedBlock(WarpDrive.cloakCoilBlock)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -441,7 +451,7 @@ public class TileEntityCloakingDeviceCore extends WarpEnergyTE {
|
|||
|
||||
@Override
|
||||
@Optional.Method(modid = "ComputerCraft")
|
||||
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception {
|
||||
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) {
|
||||
String methodName = methodsArray[method];
|
||||
if (methodName.equals("tier")) {
|
||||
if (arguments.length == 1) {
|
||||
|
@ -473,14 +483,21 @@ public class TileEntityCloakingDeviceCore extends WarpEnergyTE {
|
|||
public int getMaxEnergyStored() {
|
||||
return MAX_ENERGY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxSafeInput() {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInputEnergy(ForgeDirection from) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSinkTier() {
|
||||
// TODO Auto-generated method stub
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSourceTier() {
|
||||
// TODO Auto-generated method stub
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package cr0s.warpdrive.machines;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import jdk.nashorn.internal.runtime.regexp.joni.constants.Arguments;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.entity.Entity;
|
||||
|
|
|
@ -2,8 +2,12 @@ package cr0s.warpdrive.machines;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import jdk.nashorn.internal.runtime.regexp.joni.constants.Arguments;
|
||||
import li.cil.oc.api.machine.Arguments;
|
||||
import li.cil.oc.api.machine.Callback;
|
||||
import li.cil.oc.api.machine.Context;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
@ -13,155 +17,186 @@ import cr0s.warpdrive.PacketHandler;
|
|||
import cr0s.warpdrive.WarpDrive;
|
||||
import cr0s.warpdrive.WarpDriveConfig;
|
||||
import cr0s.warpdrive.data.Vector3;
|
||||
import dan200.computercraft.api.lua.ILuaContext;
|
||||
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||
|
||||
public class TileEntityLift extends WarpEnergyTE {
|
||||
private static final int MODE_REDSTONE = -1;
|
||||
private static final int MODE_INACTIVE = 0;
|
||||
private static final int MODE_UP = 1;
|
||||
private static final int MODE_DOWN = 2;
|
||||
|
||||
private int firstUncoveredY;
|
||||
private int mode = MODE_INACTIVE;
|
||||
private boolean isEnabled = false;
|
||||
private boolean computerEnabled = true;
|
||||
private int computerMode = MODE_REDSTONE;
|
||||
|
||||
private int tickCount = 0;
|
||||
|
||||
public TileEntityLift() {
|
||||
super();
|
||||
peripheralName = "warpdriveLaserLift";
|
||||
methodsArray = new String[] {
|
||||
"getEnergyLevel",
|
||||
"mode",
|
||||
"active",
|
||||
"help"
|
||||
};
|
||||
private static final int MODE_REDSTONE = -1;
|
||||
private static final int MODE_INACTIVE = 0;
|
||||
private static final int MODE_UP = 1;
|
||||
private static final int MODE_DOWN = 2;
|
||||
|
||||
private int firstUncoveredY;
|
||||
private int mode = MODE_INACTIVE;
|
||||
private boolean isEnabled = false;
|
||||
private boolean computerEnabled = true;
|
||||
private int computerMode = MODE_REDSTONE;
|
||||
|
||||
private int tickCount = 0;
|
||||
|
||||
public TileEntityLift() {
|
||||
super();
|
||||
peripheralName = "warpdriveLaserLift";
|
||||
methodsArray = new String[] { "getEnergyLevel", "mode", "active",
|
||||
"help" };
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
if (FMLCommonHandler.instance().getEffectiveSide().isClient()) {
|
||||
return;
|
||||
}
|
||||
super.updateEntity();
|
||||
|
||||
tickCount++;
|
||||
if (tickCount >= WarpDriveConfig.LL_TICK_RATE) {
|
||||
tickCount = 0;
|
||||
|
||||
// Switching mode
|
||||
if (computerMode == MODE_DOWN || (computerMode == MODE_REDSTONE && worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord))) {
|
||||
mode = MODE_DOWN;
|
||||
} else {
|
||||
mode = MODE_UP;
|
||||
}
|
||||
|
||||
isEnabled = computerEnabled && isPassableBlock(yCoord + 1) && isPassableBlock(yCoord + 2) && isPassableBlock(yCoord - 1) && isPassableBlock(yCoord - 2);
|
||||
|
||||
if (getEnergyStored() < WarpDriveConfig.LL_LIFT_ENERGY || !isEnabled) {
|
||||
mode = MODE_INACTIVE;
|
||||
if (getBlockMetadata() != 0) {
|
||||
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 0, 2); // disabled
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (getBlockMetadata() != mode) {
|
||||
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, mode, 2); // current mode
|
||||
}
|
||||
|
||||
// Launch a beam: search non-air blocks under lift
|
||||
for (int ny = yCoord - 2; ny > 0; ny--) {
|
||||
if (!isPassableBlock(ny)) {
|
||||
firstUncoveredY = ny + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (yCoord - firstUncoveredY >= 2) {
|
||||
if (mode == MODE_UP) {
|
||||
PacketHandler.sendBeamPacket(worldObj, new Vector3(xCoord + 0.5D, firstUncoveredY, zCoord + 0.5D), new Vector3(xCoord + 0.5D, yCoord, zCoord + 0.5D), 0f, 1f, 0f, 40, 0, 100);
|
||||
} else if (mode == MODE_DOWN) {
|
||||
PacketHandler.sendBeamPacket(worldObj, new Vector3(xCoord + 0.5D, yCoord, zCoord + 0.5D), new Vector3(xCoord + 0.5D, firstUncoveredY, zCoord + 0.5D), 0f, 0f, 1f, 40, 0, 100);
|
||||
}
|
||||
|
||||
liftEntity();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isPassableBlock(int yPosition) {
|
||||
int blockId = worldObj.getBlockId(xCoord, yPosition, zCoord);
|
||||
// 63 & 68 are signs
|
||||
return blockId == 0 || blockId == 63 || blockId == 68 || WarpDriveConfig.isAirBlock(worldObj, blockId, xCoord, yPosition, zCoord);
|
||||
}
|
||||
if (tickCount >= WarpDriveConfig.LL_TICK_RATE) {
|
||||
tickCount = 0;
|
||||
|
||||
private void liftEntity() {
|
||||
final double CUBE_RADIUS = 0.4;
|
||||
double xmax, zmax;
|
||||
double xmin, zmin;
|
||||
|
||||
xmin = xCoord + 0.5 - CUBE_RADIUS;
|
||||
xmax = xCoord + 0.5 + CUBE_RADIUS;
|
||||
zmin = zCoord + 0.5 - CUBE_RADIUS;
|
||||
zmax = zCoord + 0.5 + CUBE_RADIUS;
|
||||
|
||||
// Lift up
|
||||
if (mode == MODE_UP) {
|
||||
AxisAlignedBB aabb = AxisAlignedBB.getBoundingBox(xmin, firstUncoveredY, zmin, xmax, yCoord, zmax);
|
||||
List list = worldObj.getEntitiesWithinAABBExcludingEntity(null, aabb);
|
||||
if (list != null) {
|
||||
for (Object o : list) {
|
||||
if (o != null && o instanceof EntityLivingBase && consumeEnergy(WarpDriveConfig.LL_LIFT_ENERGY, true)) {
|
||||
((EntityLivingBase)o).setPositionAndUpdate(xCoord + 0.5D, yCoord + 1.0D, zCoord + 0.5D);
|
||||
PacketHandler.sendBeamPacket(worldObj, new Vector3(xCoord + 0.5D, firstUncoveredY, zCoord + 0.5D), new Vector3(xCoord + 0.5D, yCoord, zCoord + 0.5D), 1F, 1F, 0F, 40, 0, 100);
|
||||
worldObj.playSoundEffect(xCoord + 0.5D, yCoord, zCoord + 0.5D, "warpdrive:hilaser", 4F, 1F);
|
||||
consumeEnergy(WarpDriveConfig.LL_LIFT_ENERGY, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (mode == MODE_DOWN) {
|
||||
AxisAlignedBB aabb = AxisAlignedBB.getBoundingBox(xmin, Math.min(firstUncoveredY + 4.0D, yCoord), zmin, xmax, yCoord + 2.0D, zmax);
|
||||
List list = worldObj.getEntitiesWithinAABBExcludingEntity(null, aabb);
|
||||
if (list != null) {
|
||||
for (Object o : list) {
|
||||
if (o != null && o instanceof EntityLivingBase && consumeEnergy(WarpDriveConfig.LL_LIFT_ENERGY, true)) {
|
||||
((EntityLivingBase)o).setPositionAndUpdate(xCoord + 0.5D, firstUncoveredY, zCoord + 0.5D);
|
||||
PacketHandler.sendBeamPacket(worldObj, new Vector3(xCoord + 0.5D, yCoord, zCoord + 0.5D), new Vector3(xCoord + 0.5D, firstUncoveredY, zCoord + 0.5D), 1F, 1F, 0F, 40, 0, 100);
|
||||
worldObj.playSoundEffect(xCoord + 0.5D, yCoord, zCoord + 0.5D, "warpdrive:hilaser", 4F, 1F);
|
||||
// Switching mode
|
||||
if (computerMode == MODE_DOWN
|
||||
|| (computerMode == MODE_REDSTONE && worldObj
|
||||
.isBlockIndirectlyGettingPowered(xCoord, yCoord,
|
||||
zCoord))) {
|
||||
mode = MODE_DOWN;
|
||||
} else {
|
||||
mode = MODE_UP;
|
||||
}
|
||||
|
||||
isEnabled = computerEnabled && isPassableBlock(yCoord + 1)
|
||||
&& isPassableBlock(yCoord + 2)
|
||||
&& isPassableBlock(yCoord - 1)
|
||||
&& isPassableBlock(yCoord - 2);
|
||||
|
||||
if (getEnergyStored() < WarpDriveConfig.LL_LIFT_ENERGY
|
||||
|| !isEnabled) {
|
||||
mode = MODE_INACTIVE;
|
||||
if (getBlockMetadata() != 0) {
|
||||
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord,
|
||||
0, 2); // disabled
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (getBlockMetadata() != mode) {
|
||||
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord,
|
||||
mode, 2); // current mode
|
||||
}
|
||||
|
||||
// Launch a beam: search non-air blocks under lift
|
||||
for (int ny = yCoord - 2; ny > 0; ny--) {
|
||||
if (!isPassableBlock(ny)) {
|
||||
firstUncoveredY = ny + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (yCoord - firstUncoveredY >= 2) {
|
||||
if (mode == MODE_UP) {
|
||||
PacketHandler.sendBeamPacket(worldObj, new Vector3(
|
||||
xCoord + 0.5D, firstUncoveredY, zCoord + 0.5D),
|
||||
new Vector3(xCoord + 0.5D, yCoord, zCoord + 0.5D),
|
||||
0f, 1f, 0f, 40, 0, 100);
|
||||
} else if (mode == MODE_DOWN) {
|
||||
PacketHandler.sendBeamPacket(worldObj, new Vector3(
|
||||
xCoord + 0.5D, yCoord, zCoord + 0.5D), new Vector3(
|
||||
xCoord + 0.5D, firstUncoveredY, zCoord + 0.5D), 0f,
|
||||
0f, 1f, 40, 0, 100);
|
||||
}
|
||||
|
||||
liftEntity();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isPassableBlock(int yPosition) {
|
||||
Block block = worldObj.getBlock(xCoord, yPosition, zCoord);
|
||||
//TODO: Make configurable or less specific
|
||||
return block.isAssociatedBlock(Blocks.air)
|
||||
|| block.isAssociatedBlock(Blocks.wall_sign)
|
||||
|| block.isAssociatedBlock(Blocks.standing_sign)
|
||||
|| worldObj.isAirBlock(xCoord, yPosition, zCoord);
|
||||
}
|
||||
|
||||
private void liftEntity() {
|
||||
final double CUBE_RADIUS = 0.4;
|
||||
double xmax, zmax;
|
||||
double xmin, zmin;
|
||||
|
||||
xmin = xCoord + 0.5 - CUBE_RADIUS;
|
||||
xmax = xCoord + 0.5 + CUBE_RADIUS;
|
||||
zmin = zCoord + 0.5 - CUBE_RADIUS;
|
||||
zmax = zCoord + 0.5 + CUBE_RADIUS;
|
||||
|
||||
// Lift up
|
||||
if (mode == MODE_UP) {
|
||||
AxisAlignedBB aabb = AxisAlignedBB.getBoundingBox(xmin,
|
||||
firstUncoveredY, zmin, xmax, yCoord, zmax);
|
||||
List list = worldObj.getEntitiesWithinAABBExcludingEntity(null,
|
||||
aabb);
|
||||
if (list != null) {
|
||||
for (Object o : list) {
|
||||
if (o != null
|
||||
&& o instanceof EntityLivingBase
|
||||
&& consumeEnergy(WarpDriveConfig.LL_LIFT_ENERGY,
|
||||
true)) {
|
||||
((EntityLivingBase) o).setPositionAndUpdate(
|
||||
xCoord + 0.5D, yCoord + 1.0D, zCoord + 0.5D);
|
||||
PacketHandler.sendBeamPacket(worldObj, new Vector3(
|
||||
xCoord + 0.5D, firstUncoveredY, zCoord + 0.5D),
|
||||
new Vector3(xCoord + 0.5D, yCoord,
|
||||
zCoord + 0.5D), 1F, 1F, 0F, 40, 0, 100);
|
||||
worldObj.playSoundEffect(xCoord + 0.5D, yCoord,
|
||||
zCoord + 0.5D, "warpdrive:hilaser", 4F, 1F);
|
||||
consumeEnergy(WarpDriveConfig.LL_LIFT_ENERGY, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (mode == MODE_DOWN) {
|
||||
AxisAlignedBB aabb = AxisAlignedBB.getBoundingBox(xmin,
|
||||
Math.min(firstUncoveredY + 4.0D, yCoord), zmin, xmax,
|
||||
yCoord + 2.0D, zmax);
|
||||
List list = worldObj.getEntitiesWithinAABBExcludingEntity(null,
|
||||
aabb);
|
||||
if (list != null) {
|
||||
for (Object o : list) {
|
||||
if (o != null
|
||||
&& o instanceof EntityLivingBase
|
||||
&& consumeEnergy(WarpDriveConfig.LL_LIFT_ENERGY,
|
||||
true)) {
|
||||
((EntityLivingBase) o).setPositionAndUpdate(
|
||||
xCoord + 0.5D, firstUncoveredY, zCoord + 0.5D);
|
||||
PacketHandler.sendBeamPacket(worldObj, new Vector3(
|
||||
xCoord + 0.5D, yCoord, zCoord + 0.5D),
|
||||
new Vector3(xCoord + 0.5D, firstUncoveredY,
|
||||
zCoord + 0.5D), 1F, 1F, 0F, 40, 0, 100);
|
||||
worldObj.playSoundEffect(xCoord + 0.5D, yCoord,
|
||||
zCoord + 0.5D, "warpdrive:hilaser", 4F, 1F);
|
||||
consumeEnergy(WarpDriveConfig.LL_LIFT_ENERGY, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tag) {
|
||||
super.readFromNBT(tag);
|
||||
}
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tag) {
|
||||
super.readFromNBT(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound tag) {
|
||||
super.writeToNBT(tag);
|
||||
}
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound tag) {
|
||||
super.writeToNBT(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored() {
|
||||
return WarpDriveConfig.LL_MAX_ENERGY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInputEnergy(ForgeDirection from) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// IEnergySink methods implementation
|
||||
@Override
|
||||
public int getMaxSafeInput() {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
@Override
|
||||
public int getMaxEnergyStored() {
|
||||
return WarpDriveConfig.LL_MAX_ENERGY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInputEnergy(ForgeDirection from) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// OpenComputer callback methods
|
||||
@Callback
|
||||
|
@ -169,7 +204,7 @@ public class TileEntityLift extends WarpEnergyTE {
|
|||
private Object[] mode(Context context, Arguments arguments) {
|
||||
return mode(argumentsOCtoCC(arguments));
|
||||
}
|
||||
|
||||
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
private Object[] active(Context context, Arguments arguments) {
|
||||
|
@ -178,62 +213,75 @@ public class TileEntityLift extends WarpEnergyTE {
|
|||
}
|
||||
return new Object[] { computerEnabled ? false : isEnabled };
|
||||
}
|
||||
|
||||
|
||||
private Object[] mode(Object[] arguments) {
|
||||
if (arguments.length == 1) {
|
||||
if (arguments[0].toString().equals("up")) {
|
||||
computerMode = MODE_UP;
|
||||
} else if(arguments[0].toString().equals("down")) {
|
||||
} else if (arguments[0].toString().equals("down")) {
|
||||
computerMode = MODE_DOWN;
|
||||
} else {
|
||||
computerMode = MODE_REDSTONE;
|
||||
}
|
||||
}
|
||||
switch (computerMode) {
|
||||
case -1:
|
||||
return new Object[] { "redstone" };
|
||||
case 1:
|
||||
return new Object[] { "up" };
|
||||
case 2:
|
||||
return new Object[] { "down" };
|
||||
case -1:
|
||||
return new Object[] { "redstone" };
|
||||
case 1:
|
||||
return new Object[] { "up" };
|
||||
case 2:
|
||||
return new Object[] { "down" };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String helpStr(Object[] args) {
|
||||
if (args.length == 1) {
|
||||
String methodName = args[0].toString().toLowerCase();
|
||||
if (methodName.equals("getEnergyLevel")) {
|
||||
return WarpDrive.defEnergyStr;
|
||||
} else if (methodName.equals("mode")) {
|
||||
return "mode(\"up\" or \"down\" or \"redstone\"): sets the mode\nmode(): returns the current mode";
|
||||
} else if (methodName.equals("active")) {
|
||||
return "active(boolean): sets whether the laser is active\nactive(): returns whether the laser is active";
|
||||
}
|
||||
}
|
||||
return WarpDrive.defHelpStr;
|
||||
}
|
||||
public String helpStr(Object[] args) {
|
||||
if (args.length == 1) {
|
||||
String methodName = args[0].toString().toLowerCase();
|
||||
if (methodName.equals("getEnergyLevel")) {
|
||||
return WarpDrive.defEnergyStr;
|
||||
} else if (methodName.equals("mode")) {
|
||||
return "mode(\"up\" or \"down\" or \"redstone\"): sets the mode\nmode(): returns the current mode";
|
||||
} else if (methodName.equals("active")) {
|
||||
return "active(boolean): sets whether the laser is active\nactive(): returns whether the laser is active";
|
||||
}
|
||||
}
|
||||
return WarpDrive.defHelpStr;
|
||||
}
|
||||
|
||||
// ComputerCraft IPeripheral methods implementation
|
||||
@Override
|
||||
// ComputerCraft IPeripheral methods implementation
|
||||
@Override
|
||||
@Optional.Method(modid = "ComputerCraft")
|
||||
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception {
|
||||
String methodName = methodsArray[method];
|
||||
if (methodName.equals("getEnergyLevel")) {
|
||||
return getEnergyLevel();
|
||||
|
||||
public Object[] callMethod(IComputerAccess computer, ILuaContext context,
|
||||
int method, Object[] arguments) {
|
||||
String methodName = methodsArray[method];
|
||||
if (methodName.equals("getEnergyLevel")) {
|
||||
return getEnergyLevel();
|
||||
|
||||
} else if (methodName.equals("mode")) {
|
||||
return mode(arguments);
|
||||
|
||||
|
||||
} else if (methodName.equals("active")) {
|
||||
if (arguments.length == 1) {
|
||||
computerEnabled = toBool(arguments);
|
||||
}
|
||||
return new Object[] { computerEnabled ? false : isEnabled };
|
||||
|
||||
} else if (methodName.equals("help")) {
|
||||
return new Object[] { helpStr(arguments) };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return new Object[] { computerEnabled ? false : isEnabled };
|
||||
|
||||
} else if (methodName.equals("help")) {
|
||||
return new Object[] { helpStr(arguments) };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSinkTier() {
|
||||
// TODO Arbitrarily chosen value
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSourceTier() {
|
||||
// TODO Arbitrarily chosen value
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package cr0s.warpdrive.machines;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import jdk.nashorn.internal.runtime.regexp.joni.constants.Arguments;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
package cr0s.warpdrive.machines;
|
||||
|
||||
import jdk.nashorn.internal.runtime.regexp.joni.constants.Arguments;
|
||||
import li.cil.oc.api.machine.Arguments;
|
||||
import li.cil.oc.api.machine.Callback;
|
||||
import li.cil.oc.api.machine.Context;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.Optional;
|
||||
import cr0s.warpdrive.PacketHandler;
|
||||
import cr0s.warpdrive.WarpDrive;
|
||||
import dan200.computercraft.api.lua.ILuaContext;
|
||||
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||
|
||||
public class TileEntityMonitor extends WarpInterfacedTE {
|
||||
private int frequency = -1;
|
||||
|
@ -71,7 +75,7 @@ public class TileEntityMonitor extends WarpInterfacedTE {
|
|||
// ComputerCraft IPeripheral methods implementation
|
||||
@Override
|
||||
@Optional.Method(modid = "ComputerCraft")
|
||||
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception {
|
||||
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) {
|
||||
String methodName = methodsArray[method];
|
||||
if (methodName.equals("freq")) {
|
||||
if (arguments.length == 1) {
|
||||
|
|
|
@ -42,13 +42,20 @@ public class TileEntityParticleBooster extends WarpEnergyTE {
|
|||
return WarpDriveConfig.PB_MAX_ENERGY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxSafeInput() {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInputEnergy(ForgeDirection from) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSinkTier() {
|
||||
// TODO Auto-generated method stub
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSourceTier() {
|
||||
// TODO Auto-generated method stub
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,16 +2,22 @@ package cr0s.warpdrive.machines;
|
|||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import jdk.nashorn.internal.runtime.regexp.joni.constants.Arguments;
|
||||
import li.cil.oc.api.machine.Arguments;
|
||||
import li.cil.oc.api.machine.Callback;
|
||||
import li.cil.oc.api.machine.Context;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.Optional;
|
||||
import cr0s.warpdrive.WarpDrive;
|
||||
import cr0s.warpdrive.WarpDriveConfig;
|
||||
import cr0s.warpdrive.machines.TileEntityReactor.ReactorMode;
|
||||
import dan200.computercraft.api.ComputerCraftAPI;
|
||||
import dan200.computercraft.api.lua.ILuaContext;
|
||||
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||
|
||||
/**
|
||||
* Protocol block tile entity
|
||||
|
@ -162,19 +168,19 @@ public class TileEntityProtocol extends WarpInterfacedTE {
|
|||
|
||||
public void attachPlayer(EntityPlayer entityPlayer) {
|
||||
for (int i = 0; i < players.size(); i++) {
|
||||
String nick = players.get(i);
|
||||
String name = players.get(i);
|
||||
|
||||
if (entityPlayer.username.equals(nick)) {
|
||||
entityPlayer.addChatMessage(getBlockType().getLocalizedName() + " Detached.");
|
||||
if (entityPlayer.getDisplayName().equals(name)) {
|
||||
entityPlayer.addChatMessage(new ChatComponentText(getBlockType().getLocalizedName() + " Detached."));
|
||||
players.remove(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
entityPlayer.attackEntityFrom(DamageSource.generic, 1);
|
||||
players.add(entityPlayer.username);
|
||||
players.add(entityPlayer.getDisplayName());
|
||||
updatePlayersString();
|
||||
entityPlayer.addChatMessage(getBlockType().getLocalizedName() + " Successfully attached.");
|
||||
entityPlayer.addChatMessage(new ChatComponentText(getBlockType().getLocalizedName() + " Successfully attached."));
|
||||
}
|
||||
|
||||
public void updatePlayersString() {
|
||||
|
@ -735,7 +741,7 @@ public class TileEntityProtocol extends WarpInterfacedTE {
|
|||
|
||||
@Override
|
||||
@Optional.Method(modid = "ComputerCraft")
|
||||
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception {
|
||||
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) {
|
||||
String methodName = methodsArray[method];
|
||||
|
||||
if (methodName.equals("dim_positive")) {// dim_positive (front, right, up)
|
||||
|
|
|
@ -2,13 +2,18 @@ package cr0s.warpdrive.machines;
|
|||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import jdk.nashorn.internal.runtime.regexp.joni.constants.Arguments;
|
||||
import li.cil.oc.api.machine.Arguments;
|
||||
import li.cil.oc.api.machine.Callback;
|
||||
import li.cil.oc.api.machine.Context;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.Optional;
|
||||
import cr0s.warpdrive.WarpDrive;
|
||||
import cr0s.warpdrive.WarpDriveConfig;
|
||||
import dan200.computercraft.api.ComputerCraftAPI;
|
||||
import dan200.computercraft.api.lua.ILuaContext;
|
||||
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||
|
||||
public class TileEntityRadar extends WarpEnergyTE {
|
||||
private ArrayList<TileEntityReactor> results;
|
||||
|
@ -130,7 +135,7 @@ public class TileEntityRadar extends WarpEnergyTE {
|
|||
TileEntityReactor res = results.get(index);
|
||||
if (res != null)
|
||||
{
|
||||
int yAddition = (res.worldObj.provider.dimensionId == WarpDriveConfig.G_SPACE_DIMENSION_ID) ? 256 : (res.worldObj.provider.dimensionId == WarpDriveConfig.G_HYPERSPACE_DIMENSION_ID) ? 512 : 0;
|
||||
int yAddition = (res.getWorldObj().provider.dimensionId == WarpDriveConfig.G_SPACE_DIMENSION_ID) ? 256 : (res.getWorldObj().provider.dimensionId == WarpDriveConfig.G_HYPERSPACE_DIMENSION_ID) ? 512 : 0;
|
||||
return new Object[] { res.coreFrequency, res.xCoord, res.yCoord + yAddition, res.zCoord };
|
||||
}
|
||||
}
|
||||
|
@ -165,7 +170,7 @@ public class TileEntityRadar extends WarpEnergyTE {
|
|||
|
||||
@Override
|
||||
@Optional.Method(modid = "ComputerCraft")
|
||||
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception {
|
||||
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) {
|
||||
String methodName = methodsArray[method];
|
||||
if (methodName.equals("scanRadius")) {// scanRadius (radius)
|
||||
return scanRadius(arguments);
|
||||
|
@ -194,14 +199,20 @@ public class TileEntityRadar extends WarpEnergyTE {
|
|||
return WarpDriveConfig.WR_MAX_ENERGY_VALUE;
|
||||
}
|
||||
|
||||
// IEnergySink methods implementation
|
||||
@Override
|
||||
public int getMaxSafeInput() {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInputEnergy(ForgeDirection from) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSinkTier() {
|
||||
// TODO Arbitrarily chosen value
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSourceTier() {
|
||||
// TODO Arbitrarily chosen value
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -6,7 +6,7 @@ import java.io.File;
|
|||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
import jdk.nashorn.internal.runtime.regexp.joni.constants.Arguments;
|
||||
import li.cil.oc.api.machine.Arguments;
|
||||
import li.cil.oc.api.machine.Callback;
|
||||
import li.cil.oc.api.machine.Context;
|
||||
import net.minecraft.block.Block;
|
||||
|
@ -267,16 +267,16 @@ public class TileEntityShipScanner extends WarpEnergyTE {
|
|||
|
||||
// Do not scan air, bedrock and specified forbidden blocks (like ore or Warp-Cores)
|
||||
if (worldObj.isAirBlock(core.minX + x, core.minY + y, core.minZ + z) || block.isAssociatedBlock(Blocks.bedrock) || WarpDriveConfig.scannerIgnoreBlocks.contains(block)) {
|
||||
block = 0;
|
||||
block = Blocks.air;
|
||||
}
|
||||
|
||||
localBlocks[x + (y * length + z) * width] = (byte) block;
|
||||
localBlocks[x + (y * length + z) * width] = (byte) block.getUnlocalizedName();
|
||||
localMetadata[x + (y * length + z) * width] = (byte) worldObj.getBlockMetadata(core.minX + x, core.minY + y, core.minZ + z);
|
||||
if ((extraBlocks[x + (y * length + z) * width] = (byte) (block >> 8)) > 0) {
|
||||
extra = true;
|
||||
}
|
||||
|
||||
if (block != 0) {
|
||||
if (!block.isAssociatedBlock(Blocks.air)) {
|
||||
TileEntity te = worldObj.getTileEntity(core.minX + x, core.minY + y, core.minZ + z);
|
||||
if (te != null) {
|
||||
try {
|
||||
|
@ -625,7 +625,7 @@ public class TileEntityShipScanner extends WarpEnergyTE {
|
|||
// ComputerCraft IPeripheral methods implementation
|
||||
@Override
|
||||
@Optional.Method(modid = "ComputerCraft")
|
||||
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception {
|
||||
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) {
|
||||
String methodName = methodsArray[method];
|
||||
if (methodName.equals("scan")) {
|
||||
return scan(arguments);
|
||||
|
@ -651,14 +651,20 @@ public class TileEntityShipScanner extends WarpEnergyTE {
|
|||
public int getMaxEnergyStored() {
|
||||
return WarpDriveConfig.SS_MAX_ENERGY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxSafeInput() {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInputEnergy(ForgeDirection from) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSinkTier() {
|
||||
// TODO Arbitrarily chosen value
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSourceTier() {
|
||||
// TODO Arbitrarily chosen value
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import ic2.api.energy.tile.IEnergySource;
|
|||
|
||||
import java.util.HashMap;
|
||||
|
||||
import jdk.nashorn.internal.runtime.regexp.joni.constants.Arguments;
|
||||
import li.cil.oc.api.machine.Arguments;
|
||||
import li.cil.oc.api.machine.Callback;
|
||||
import li.cil.oc.api.machine.Context;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
|
Loading…
Reference in a new issue