Code cleanup & Fixed IC2 reactor monitor

Removed LUA help methods that are in the wiki
Replaced Vector3 with VectorI when applicable
Fixed asynchronous laser beam in Enantiomorphic reactor
Removed redundant code existing in Forge
Fixed default mining laser radius
This commit is contained in:
LemADEC 2015-08-23 22:08:51 +02:00
parent c0d5105bd3
commit c5244398c7
16 changed files with 368 additions and 398 deletions

View file

@ -32,6 +32,7 @@ import cr0s.warpdrive.data.JumpBlock;
import cr0s.warpdrive.data.MovingEntity;
import cr0s.warpdrive.data.Planet;
import cr0s.warpdrive.data.Vector3;
import cr0s.warpdrive.data.VectorI;
import cr0s.warpdrive.world.SpaceTeleporter;
public class EntityJump extends Entity {
@ -347,7 +348,7 @@ public class EntityJump extends Entity {
Planet transitionPlane = WarpDriveConfig.PLANETS[iPlane];
if (worldObj.provider.dimensionId == transitionPlane.dimensionId) {
planeFound = true;
int planeDistance = transitionPlane.isValidToSpace(new Vector3(this));
int planeDistance = transitionPlane.isValidToSpace(new VectorI(this));
if (planeDistance == 0) {
planeValid = true;
moveX = transitionPlane.spaceCenterX - transitionPlane.dimensionCenterX;
@ -386,7 +387,7 @@ public class EntityJump extends Entity {
Planet closestTransitionPlane = null;
for (int iPlane = 0; (!planeFound) && iPlane < WarpDriveConfig.PLANETS.length; iPlane++) {
Planet transitionPlane = WarpDriveConfig.PLANETS[iPlane];
int planeDistance = transitionPlane.isValidFromSpace(new Vector3(this));
int planeDistance = transitionPlane.isValidFromSpace(new VectorI(this));
if (planeDistance == 0) {
planeFound = true;
moveX = transitionPlane.dimensionCenterX - transitionPlane.spaceCenterX;

View file

@ -65,9 +65,9 @@ public abstract class BlockAbstractContainer extends BlockContainer {
@Override
public void onNeighborBlockChange(World w, int x, int y, int z, Block b) {
super.onNeighborBlockChange(w, x, y, z, b);
TileEntity te = w.getTileEntity(x, y, z);
if (te instanceof IBlockUpdateDetector) {
((IBlockUpdateDetector) te).updatedNeighbours();
TileEntity tileEntity = w.getTileEntity(x, y, z);
if (tileEntity instanceof IBlockUpdateDetector) {
((IBlockUpdateDetector) tileEntity).updatedNeighbours();
}
}
}

View file

@ -16,7 +16,7 @@ import cr0s.warpdrive.WarpDrive;
public class BlockLaserMedium extends BlockContainer {
private IIcon[] iconBuffer;
public BlockLaserMedium(int texture, Material material) {
super(material);
setHardness(0.5F);
@ -24,7 +24,7 @@ public class BlockLaserMedium extends BlockContainer {
setCreativeTab(WarpDrive.creativeTabWarpDrive);
setBlockName("warpdrive.machines.LaserMedium");
}
@Override
public void registerBlockIcons(IIconRegister par1IconRegister) {
iconBuffer = new IIcon[16];
@ -41,21 +41,21 @@ public class BlockLaserMedium extends BlockContainer {
iconBuffer[10] = par1IconRegister.registerIcon("warpdrive:laserMediumSide10");
iconBuffer[11] = par1IconRegister.registerIcon("warpdrive:laserMediumTopBottom");
}
@Override
public IIcon getIcon(int side, int metadata) {
if (side == 0 || side == 1) {
return iconBuffer[11];
}
return iconBuffer[metadata];
}
@Override
public TileEntity createNewTileEntity(World var1, int i) {
return new TileEntityLaserMedium();
}
/**
* Returns the quantity of items to drop on block destruction.
*/
@ -63,7 +63,7 @@ public class BlockLaserMedium extends BlockContainer {
public int quantityDropped(Random par1Random) {
return 1;
}
/**
* Returns the ID of the items to drop on destruction.
*/
@ -71,24 +71,24 @@ public class BlockLaserMedium extends BlockContainer {
public Item getItemDropped(int par1, Random par2Random, int par3) {
return Item.getItemFromBlock(this);
}
/**
* 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) {
public boolean onBlockActivated(World par1World, int x, int y, int z, EntityPlayer entityPlayer, 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 TileEntityAbstractEnergy) {
WarpDrive.addChatMessage(par5EntityPlayer, ((TileEntityAbstractEnergy) te).getStatus());
if (entityPlayer.getHeldItem() == null) {
TileEntity tileEntity = par1World.getTileEntity(x, y, z);
if (tileEntity != null && tileEntity instanceof TileEntityAbstractEnergy) {
WarpDrive.addChatMessage(entityPlayer, ((TileEntityAbstractEnergy) tileEntity).getStatus());
return true;
}
}
return false;
}
}

View file

@ -5,17 +5,6 @@ import cr0s.warpdrive.data.Vector3;
public abstract class TileEntityAbstractBase extends TileEntity
{
public static final Vector3[] adjacentSideOffsets = new Vector3[6];
static
{
adjacentSideOffsets[0] = new Vector3( 0, 0, 1);
adjacentSideOffsets[1] = new Vector3( 0, 0,-1);
adjacentSideOffsets[2] = new Vector3( 0, 1, 0);
adjacentSideOffsets[3] = new Vector3( 0,-1, 0);
adjacentSideOffsets[4] = new Vector3( 1, 0, 0);
adjacentSideOffsets[5] = new Vector3(-1, 0, 0);
}
protected static int toInt(double d) {
return (int) Math.round(d);
}

View file

@ -10,12 +10,14 @@ import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.IFluidBlock;
import cr0s.warpdrive.WarpDrive;
import cr0s.warpdrive.block.TileEntityAbstractLaser;
import cr0s.warpdrive.block.TileEntityLaserMedium;
import cr0s.warpdrive.conf.WarpDriveConfig;
import cr0s.warpdrive.data.Vector3;
import cr0s.warpdrive.data.VectorI;
import cr0s.warpdrive.network.PacketHandler;
public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser
@ -25,31 +27,25 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser
private int fortuneLevel = 0;
private TileEntityLaserMedium booster = null;
private Vector3 minerVector;
private Vector3 laserOutput;
abstract boolean canSilkTouch();
abstract int minFortune();
abstract int maxFortune();
abstract double laserBelow();
ForgeDirection laserOutputSide = ForgeDirection.UP;
abstract float getColorR();
abstract float getColorG();
abstract float getColorB();
public TileEntityAbstractMiner()
{
public TileEntityAbstractMiner() {
super();
fixMinerVector();
}
private void fixMinerVector()
{
if(minerVector == null)
minerVector = new Vector3(xCoord,yCoord-laserBelow(),zCoord);
minerVector.x = xCoord;
minerVector.y = yCoord - (laserBelow());
minerVector.z = zCoord;
minerVector.translate(0.5);
@Override
public void validate() {
super.validate();
laserOutput = new Vector3(this).translate(0.5D).translate(laserOutputSide, 0.5D);
}
private List<ItemStack> getItemStackFromBlock(int i, int j, int k, Block block, int blockMeta)
@ -78,9 +74,8 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser
private IInventory findChest() {
TileEntity result = null;
for(int i = 0; i < 6; i++) {
Vector3 sideOffset = adjacentSideOffsets[i];
result = worldObj.getTileEntity(xCoord + sideOffset.intX(), yCoord + sideOffset.intY(), zCoord + sideOffset.intZ());
for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
result = worldObj.getTileEntity(xCoord + side.offsetX, yCoord + side.offsetY, zCoord + side.offsetZ);
if (result != null && !(result instanceof TileEntityAbstractMiner) && (result instanceof IInventory)) {
return (IInventory) result;
}
@ -204,31 +199,30 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser
//MINING FUNCTIONS
protected void laserBlock(Vector3 valuable)
protected void laserBlock(VectorI valuable)
{
fixMinerVector();
float r = getColorR();
float g = getColorG();
float b = getColorB();
PacketHandler.sendBeamPacket(worldObj, minerVector, valuable.clone().translate(0.5D), r, g, b, 2 * WarpDriveConfig.MINING_LASER_MINE_DELAY_TICKS, 0, 50);
PacketHandler.sendBeamPacket(worldObj, laserOutput, valuable.getBlockCenter(), r, g, b, 2 * WarpDriveConfig.MINING_LASER_MINE_DELAY_TICKS, 0, 50);
//worldObj.playSoundEffect(xCoord + 0.5f, yCoord, zCoord + 0.5f, "warpdrive:lowlaser", 4F, 1F);
}
private void mineBlock(Vector3 valuable, Block block, int blockMeta)
private void mineBlock(VectorI valuable, Block block, int blockMeta)
{
laserBlock(valuable);
worldObj.playAuxSFXAtEntity(null, 2001, valuable.intX(), valuable.intY(), valuable.intZ(), (blockMeta << 12));
worldObj.setBlockToAir(valuable.intX(), valuable.intY(), valuable.intZ());
worldObj.playAuxSFXAtEntity(null, 2001, valuable.x, valuable.y, valuable.z, (blockMeta << 12));
worldObj.setBlockToAir(valuable.x, valuable.y, valuable.z);
}
protected boolean harvestBlock(Vector3 valuable)
protected boolean harvestBlock(VectorI valuable)
{
Block block = worldObj.getBlock(valuable.intX(), valuable.intY(), valuable.intZ());
int blockMeta = worldObj.getBlockMetadata(valuable.intX(), valuable.intY(), valuable.intZ());
Block block = worldObj.getBlock(valuable.x, valuable.y, valuable.z);
int blockMeta = worldObj.getBlockMetadata(valuable.x, valuable.y, valuable.z);
if (!block.isAssociatedBlock(Blocks.water) && !block.isAssociatedBlock(Blocks.lava))
{
boolean didPlace = true;
List<ItemStack> stacks = getItemStackFromBlock(valuable.intX(), valuable.intY(), valuable.intZ(), block, blockMeta);
List<ItemStack> stacks = getItemStackFromBlock(valuable.x, valuable.y, valuable.z, block, blockMeta);
if (stacks != null)
{
for (ItemStack stack : stacks)
@ -239,10 +233,11 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser
mineBlock(valuable, block, blockMeta);
return didPlace;
}
else if (block.isAssociatedBlock(Blocks.water))
else if (block.isAssociatedBlock(Blocks.water)) {
// Evaporate water
worldObj.playSoundEffect(valuable.intX() + 0.5D, valuable.intY() + 0.5D, valuable.intZ() + 0.5D, "random.fizz", 0.5F, 2.6F + (worldObj.rand.nextFloat() - worldObj.rand.nextFloat()) * 0.8F);
worldObj.setBlockToAir(valuable.intX(), valuable.intY(), valuable.intZ());
worldObj.playSoundEffect(valuable.x + 0.5D, valuable.y + 0.5D, valuable.z + 0.5D, "random.fizz", 0.5F, 2.6F + (worldObj.rand.nextFloat() - worldObj.rand.nextFloat()) * 0.8F);
}
worldObj.setBlockToAir(valuable.x, valuable.y, valuable.z);
return true;
}
@ -356,11 +351,6 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser
super.readFromNBT(tag);
silkTouch = tag.getBoolean("silkTouch");
fortuneLevel = tag.getInteger("fortuneLevel");
minerVector.x = xCoord;
minerVector.y = yCoord - (laserBelow());
minerVector.z = zCoord;
minerVector = minerVector.translate(0.5);
}
@Override

View file

@ -5,14 +5,15 @@ import java.util.LinkedList;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
import cr0s.warpdrive.WarpDrive;
import cr0s.warpdrive.conf.WarpDriveConfig;
import cr0s.warpdrive.data.Vector3;
import cr0s.warpdrive.data.VectorI;
import dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.peripheral.IComputerAccess;
public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
Boolean active = false;
private boolean active = false;
private int mode = 0;
private boolean doLeaves = false;
@ -30,11 +31,12 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
private int radiusX = radiusDefault;
private int radiusZ = radiusDefault;
LinkedList<Vector3> logs;
LinkedList<VectorI> logs;
private int logIndex = 0;
public TileEntityLaserTreeFarm() {
super();
laserOutputSide = ForgeDirection.UP;
IC2_sinkTier = 2;
IC2_sourceTier = 2;
peripheralName = "warpdriveLaserTreefarm";
@ -72,8 +74,8 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
mode = 0;
return;
}
Vector3 pos = logs.get(logIndex);
Block block = worldObj.getBlock(pos.intX(), pos.intY(), pos.intZ());
VectorI pos = logs.get(logIndex);
Block block = worldObj.getBlock(pos.x, pos.y, pos.z);
if (mode == 1) {
int cost = calculateBlockCost(block);
@ -101,7 +103,7 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
if (consumeEnergyFromBooster(cost, true)) {
if (isRoomForHarvest()) {
if (block.isAssociatedBlock(Block.getBlockFromItem(WarpDriveConfig.IC2_rubberWood.getItem()))) {
int metadata = worldObj.getBlockMetadata(pos.intX(), pos.intY(), pos.intZ());
int metadata = worldObj.getBlockMetadata(pos.x, pos.y, pos.z);
if (metadata >= 2 && metadata <= 5) {
if (WarpDriveConfig.LOGGING_COLLECTION) {
WarpDrive.logger.info("wetspot found");
@ -110,7 +112,7 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
ItemStack resin = WarpDriveConfig.IC2_Resin.copy();
resin.stackSize = (int) Math.round(Math.random() * 4);
dumpToInv(resin);
worldObj.setBlockMetadataWithNotify(pos.intX(), pos.intY(), pos.intZ(), metadata+6, 3);
worldObj.setBlockMetadataWithNotify(pos.x, pos.y, pos.z, metadata + 6, 3);
laserBlock(pos);
totalHarvested++;
delayMul = 4;
@ -155,33 +157,28 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
return WarpDriveConfig.minerLeaves.contains(block);
}
private static void addTree(LinkedList<Vector3> list, Vector3 newTree) {
private static void addTree(LinkedList<VectorI> list, VectorI newTree) {
if (WarpDriveConfig.LOGGING_COLLECTION) {
WarpDrive.logger.info("Adding tree position:" + newTree.x + "," + newTree.y + "," + newTree.z);
}
list.add(newTree);
}
private LinkedList<Vector3> scanTrees() {
int xmax, zmax, x1, x2, z1, z2;
private LinkedList<VectorI> scanTrees() {
int xmax, zmax;
int xmin, zmin;
x1 = xCoord + radiusX;
x2 = xCoord - radiusX;
xmin = Math.min(x1, x2);
xmax = Math.max(x1, x2);
z1 = zCoord + radiusZ;
z2 = zCoord - radiusZ;
zmin = Math.min(z1, z2);
zmax = Math.max(z1, z2);
LinkedList<Vector3> logPositions = new LinkedList<Vector3>();
xmax = xCoord + radiusX;
xmin = xCoord - radiusX;
zmax = zCoord + radiusZ;
zmin = zCoord - radiusZ;
LinkedList<VectorI> logPositions = new LinkedList<VectorI>();
for(int x = xmin; x <= xmax; x++) {
for(int z = zmin; z <= zmax; z++) {
Block block = worldObj.getBlock(x, yCoord, z);
if (isLog(block)) {
Vector3 pos = new Vector3(x, yCoord, z);
VectorI pos = new VectorI(x, yCoord, z);
logPositions.add(pos);
scanNearby(logPositions, x, yCoord, z, 0);
}
@ -190,14 +187,14 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
return logPositions;
}
private void scanNearby(LinkedList<Vector3> current, int x, int y, int z, int d) {
private void scanNearby(LinkedList<VectorI> current, int x, int y, int z, int d) {
int[] deltas = {0, -1, 1};
for(int dx : deltas) {
for(int dy = 1; dy >= 0; dy--) {
for(int dz : deltas) {
Block block = worldObj.getBlock(x + dx, y + dy, z + dz);
if (isLog(block) || (doLeaves && isLeaf(block))) {
Vector3 pos = new Vector3(x + dx, y + dy, z + dz);
VectorI pos = new VectorI(x + dx, y + dy, z + dz);
if (!current.contains(pos)) {
addTree(current, pos);
if (d < 35) {
@ -343,11 +340,6 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
return 0;
}
@Override
protected double laserBelow() {
return -0.5;
}
@Override
protected float getColorR() {
return 0.2f;

View file

@ -23,6 +23,7 @@ import cr0s.warpdrive.block.TileEntityAbstractInterfaced;
import cr0s.warpdrive.block.TileEntityLaserMedium;
import cr0s.warpdrive.conf.WarpDriveConfig;
import cr0s.warpdrive.data.Vector3;
import cr0s.warpdrive.data.VectorI;
import cr0s.warpdrive.network.PacketHandler;
import dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.peripheral.IComputerAccess;
@ -49,7 +50,7 @@ public class TileEntityMiningLaser extends TileEntityAbstractInterfaced {
private boolean enoughPower = false;
private int currentLayer;
private ArrayList<Vector3> valuablesInLayer = new ArrayList<Vector3>();
private ArrayList<VectorI> valuablesInLayer = new ArrayList<VectorI>();
private int valuableIndex = 0;
private int layerOffset = 1;
@ -79,7 +80,7 @@ public class TileEntityMiningLaser extends TileEntityAbstractInterfaced {
boolean isOnEarth = (worldObj.provider.dimensionId == 0);
Vector3 minerVector = new Vector3(xCoord + 0.5D, yCoord, zCoord + 0.5D);
Vector3 laserOutput = new Vector3(xCoord + 0.5D, yCoord, zCoord + 0.5D);
if (currentState == STATE_WARMUP) { // warming up
delayTicksWarmup++;
@ -104,10 +105,10 @@ public class TileEntityMiningLaser extends TileEntityAbstractInterfaced {
}
// show current layer
int age = Math.max(40, 5 * WarpDriveConfig.MINING_LASER_SCAN_DELAY_TICKS);
double xmax = xCoord + WarpDriveConfig.MINING_LASER_MAX_RADIUS + 1.0D;
double xmin = xCoord - WarpDriveConfig.MINING_LASER_MAX_RADIUS + 0.0D;
double zmax = zCoord + WarpDriveConfig.MINING_LASER_MAX_RADIUS + 1.0D;
double zmin = zCoord - WarpDriveConfig.MINING_LASER_MAX_RADIUS + 0.0D;
double xmax = xCoord + WarpDriveConfig.MINING_LASER_RADIUS_BLOCKS + 1.0D;
double xmin = xCoord - WarpDriveConfig.MINING_LASER_RADIUS_BLOCKS + 0.0D;
double zmax = zCoord + WarpDriveConfig.MINING_LASER_RADIUS_BLOCKS + 1.0D;
double zmin = zCoord - WarpDriveConfig.MINING_LASER_RADIUS_BLOCKS + 0.0D;
double y = currentLayer + 1.0D;
PacketHandler.sendBeamPacket(worldObj, new Vector3(xmin, y, zmin), new Vector3(xmax, y, zmin), 0.3F, 0.0F, 1.0F, age, 0, 50);
PacketHandler.sendBeamPacket(worldObj, new Vector3(xmax, y, zmin), new Vector3(xmax, y, zmax), 0.3F, 0.0F, 1.0F, age, 0, 50);
@ -130,17 +131,17 @@ public class TileEntityMiningLaser extends TileEntityAbstractInterfaced {
// scan
scanLayer();
if (valuablesInLayer.size() > 0) {
int r = (int) Math.ceil(WarpDriveConfig.MINING_LASER_MAX_RADIUS / 2.0D);
int r = (int) Math.ceil(WarpDriveConfig.MINING_LASER_RADIUS_BLOCKS / 2.0D);
int offset = (yCoord - currentLayer) % (2 * r);
int age = Math.max(20, Math.round(2.5F * WarpDriveConfig.MINING_LASER_SCAN_DELAY_TICKS));
double y = currentLayer + 1.0D;
PacketHandler.sendBeamPacket(worldObj, minerVector, new Vector3(xCoord - r + offset, y, zCoord + r).translate(0.3D),
PacketHandler.sendBeamPacket(worldObj, laserOutput, new Vector3(xCoord - r + offset, y, zCoord + r).translate(0.3D),
0.0F, 0.0F, 1.0F, age, 0, 50);
PacketHandler.sendBeamPacket(worldObj, minerVector, new Vector3(xCoord + r, y, zCoord + r - offset).translate(0.3D),
PacketHandler.sendBeamPacket(worldObj, laserOutput, new Vector3(xCoord + r, y, zCoord + r - offset).translate(0.3D),
0.0F, 0.0F, 1.0F, age, 0, 50);
PacketHandler.sendBeamPacket(worldObj, minerVector, new Vector3(xCoord + r - offset, y, zCoord - r).translate(0.3D),
PacketHandler.sendBeamPacket(worldObj, laserOutput, new Vector3(xCoord + r - offset, y, zCoord - r).translate(0.3D),
0.0F, 0.0F, 1.0F, age, 0, 50);
PacketHandler.sendBeamPacket(worldObj, minerVector, new Vector3(xCoord - r, y, zCoord - r + offset).translate(0.3D),
PacketHandler.sendBeamPacket(worldObj, laserOutput, new Vector3(xCoord - r, y, zCoord - r + offset).translate(0.3D),
0.0F, 0.0F, 1.0F, age, 0, 50);
worldObj.playSoundEffect(xCoord + 0.5f, yCoord, zCoord + 0.5f, "warpdrive:hilaser", 4F, 1F);
delayTicksMine = 0;
@ -178,19 +179,18 @@ public class TileEntityMiningLaser extends TileEntityAbstractInterfaced {
updateMetadata(BlockMiningLaser.ICON_MININGPOWERED);
}
// System.out.println("[ML] Mining: " + (valuableIndex + 1) +
// "/" + valuablesInLayer.size());
Vector3 valuable = valuablesInLayer.get(valuableIndex);
// System.out.println("[ML] Mining: " + (valuableIndex + 1) + "/" + valuablesInLayer.size());
VectorI valuable = valuablesInLayer.get(valuableIndex);
valuableIndex++;
// Mine valuable ore
Block block = worldObj.getBlock(valuable.intX(), valuable.intY(), valuable.intZ());
Block block = worldObj.getBlock(valuable.x, valuable.y, valuable.z);
// Skip if block is too hard or its empty block (check again in
// case it changed)
if (!canDig(block, valuable.intX(), valuable.intY(), valuable.intZ())) {
if (!canDig(block, valuable.x, valuable.y, valuable.z)) {
delayTicksMine = Math.round(WarpDriveConfig.MINING_LASER_MINE_DELAY_TICKS * 0.8F);
}
int age = Math.max(10, Math.round((4 + worldObj.rand.nextFloat()) * WarpDriveConfig.MINING_LASER_MINE_DELAY_TICKS));
PacketHandler.sendBeamPacket(worldObj, minerVector, new Vector3(valuable.intX(), valuable.intY(), valuable.intZ()).translate(0.5D), 1.0F, 1.0F,
PacketHandler.sendBeamPacket(worldObj, laserOutput, new Vector3(valuable.x, valuable.y, valuable.z).translate(0.5D), 1.0F, 1.0F,
0.0F, age, 0, 50);
worldObj.playSoundEffect(xCoord + 0.5f, yCoord, zCoord + 0.5f, "warpdrive:lowlaser", 4F, 1F);
harvestBlock(valuable);
@ -240,15 +240,15 @@ public class TileEntityMiningLaser extends TileEntityAbstractInterfaced {
return false;
}
private void harvestBlock(Vector3 valuable) {
Block block = worldObj.getBlock(valuable.intX(), valuable.intY(), valuable.intZ());
int blockMeta = worldObj.getBlockMetadata(valuable.intX(), valuable.intY(), valuable.intZ());
private void harvestBlock(VectorI valuable) {
Block block = worldObj.getBlock(valuable.x, valuable.y, valuable.z);
int blockMeta = worldObj.getBlockMetadata(valuable.x, valuable.y, valuable.z);
if (block != null && (block instanceof BlockLiquid)) {
// Evaporate fluid
worldObj.playSoundEffect(valuable.intX() + 0.5D, valuable.intY() + 0.5D, valuable.intZ() + 0.5D, "random.fizz", 0.5F,
worldObj.playSoundEffect(valuable.x + 0.5D, valuable.y + 0.5D, valuable.z + 0.5D, "random.fizz", 0.5F,
2.6F + (worldObj.rand.nextFloat() - worldObj.rand.nextFloat()) * 0.8F);
} else {
List<ItemStack> stacks = getItemStackFromBlock(valuable.intX(), valuable.intY(), valuable.intZ(), block, blockMeta);
List<ItemStack> stacks = getItemStackFromBlock(valuable.x, valuable.y, valuable.z, block, blockMeta);
if (stacks != null) {
boolean overflow = false;
int qtyLeft = 0;
@ -274,9 +274,9 @@ public class TileEntityMiningLaser extends TileEntityAbstractInterfaced {
}
}
// standard harvest block effect
worldObj.playAuxSFXAtEntity(null, 2001, valuable.intX(), valuable.intY(), valuable.intZ(), Block.getIdFromBlock(block) + (blockMeta << 12));
worldObj.playAuxSFXAtEntity(null, 2001, valuable.x, valuable.y, valuable.z, Block.getIdFromBlock(block) + (blockMeta << 12));
}
worldObj.setBlockToAir(valuable.intX(), valuable.intY(), valuable.intZ());
worldObj.setBlockToAir(valuable.x, valuable.y, valuable.z);
}
private IInventory findChest() {
@ -416,10 +416,10 @@ public class TileEntityMiningLaser extends TileEntityAbstractInterfaced {
block = worldObj.getBlock(x, currentLayer, z);
if (canDig(block, x, currentLayer, z)) {
if (isQuarry || WarpDriveConfig.minerOres.contains(block)) {// Quarry collects all blocks or only collect valuables blocks
valuablesInLayer.add(new Vector3(x, currentLayer, z));
valuablesInLayer.add(new VectorI(x, currentLayer, z));
}
}
for (radius = 1; radius <= WarpDriveConfig.MINING_LASER_MAX_RADIUS; radius++) {
for (radius = 1; radius <= WarpDriveConfig.MINING_LASER_RADIUS_BLOCKS; radius++) {
xmax = xCoord + radius;
xmin = xCoord - radius;
zmax = zCoord + radius;
@ -430,7 +430,7 @@ public class TileEntityMiningLaser extends TileEntityAbstractInterfaced {
block = worldObj.getBlock(x, currentLayer, z);
if (canDig(block, x, currentLayer, z)) {
if (isQuarry || WarpDriveConfig.minerOres.contains(block)) {// Quarry collects all blocks or only collect valuables blocks
valuablesInLayer.add(new Vector3(x, currentLayer, z));
valuablesInLayer.add(new VectorI(x, currentLayer, z));
}
}
}
@ -440,7 +440,7 @@ public class TileEntityMiningLaser extends TileEntityAbstractInterfaced {
block = worldObj.getBlock(x, currentLayer, z);
if (canDig(block, x, currentLayer, z)) {
if (isQuarry || WarpDriveConfig.minerOres.contains(block)) {// Quarry collects all blocks or only collect valuables blocks
valuablesInLayer.add(new Vector3(x, currentLayer, z));
valuablesInLayer.add(new VectorI(x, currentLayer, z));
}
}
}
@ -450,7 +450,7 @@ public class TileEntityMiningLaser extends TileEntityAbstractInterfaced {
block = worldObj.getBlock(x, currentLayer, z);
if (canDig(block, x, currentLayer, z)) {
if (isQuarry || WarpDriveConfig.minerOres.contains(block)) {// Quarry collects all blocks or only collect valuables blocks
valuablesInLayer.add(new Vector3(x, currentLayer, z));
valuablesInLayer.add(new VectorI(x, currentLayer, z));
}
}
}
@ -460,7 +460,7 @@ public class TileEntityMiningLaser extends TileEntityAbstractInterfaced {
block = worldObj.getBlock(x, currentLayer, z);
if (canDig(block, x, currentLayer, z)) {
if (isQuarry || WarpDriveConfig.minerOres.contains(block)) {// Quarry collects all blocks or only collect valuables blocks
valuablesInLayer.add(new Vector3(x, currentLayer, z));
valuablesInLayer.add(new VectorI(x, currentLayer, z));
}
}
}
@ -470,7 +470,7 @@ public class TileEntityMiningLaser extends TileEntityAbstractInterfaced {
block = worldObj.getBlock(x, currentLayer, z);
if (canDig(block, x, currentLayer, z)) {
if (isQuarry || WarpDriveConfig.minerOres.contains(block)) {// Quarry collects all blocks or only collect valuables blocks
valuablesInLayer.add(new Vector3(x, currentLayer, z));
valuablesInLayer.add(new VectorI(x, currentLayer, z));
}
}
}

View file

@ -1,9 +1,11 @@
package cr0s.warpdrive.block.energy;
import cpw.mods.fml.common.FMLCommonHandler;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
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.world.World;
import cr0s.warpdrive.WarpDrive;
@ -31,4 +33,24 @@ public class BlockIC2reactorLaserMonitor extends BlockContainer {
public TileEntity createNewTileEntity(World var1, int i) {
return new TileEntityIC2reactorLaserMonitor();
}
/**
* Called upon block activation (right click on the block.)
*/
@Override
public boolean onBlockActivated(World par1World, int x, int y, int z, EntityPlayer entityPlayer, int par6, float par7, float par8, float par9) {
if (FMLCommonHandler.instance().getEffectiveSide().isClient()) {
return false;
}
if (entityPlayer.getHeldItem() == null) {
TileEntity tileEntity = par1World.getTileEntity(x, y, z);
if (tileEntity != null && tileEntity instanceof TileEntityIC2reactorLaserMonitor) {
WarpDrive.addChatMessage(entityPlayer, ((TileEntityIC2reactorLaserMonitor) tileEntity).getStatus());
return true;
}
}
return false;
}
}

View file

@ -269,38 +269,15 @@ public class TileEntityEnanReactorCore extends TileEntityAbstractEnergy implemen
}
return exploding;
}
// Takes the arguments passed by function call and returns an appropriate string
private static String helpStr(Object[] args) {
if (args.length > 0) {
String arg = args[0].toString().toLowerCase();
if (arg.equals("getactive")) {
return "getActive(): returns true if the reactor is active and false otherwise";
} else if (arg.equals("setactive")) {
return "setActive(bool): activates the reactor if passed true and deactivates if passed false";
} else if (arg.equals("energy")) {
return WarpDrive.defEnergyStr;
} else if (arg.equals("instability")) {
return "instability(): returns the 4 instability values (100 is the point when the reactor explodes)";
} else if (arg.equals("release")) {
return "release(bool): sets the reactor to output all energy or disables outputting of energy";
} else if (arg.equals("releaserate")) {
return "releaseRate(int): sets the reactor to try to release exactly int/tick";
} else if (arg.equals("releaseabove")) {
return "releaseAbove(int): releases all energy above stored int";
}
}
return WarpDrive.defHelpStr;
}
@Override
public void updatedNeighbours() {
TileEntity te;
super.updatedNeighbours();
int[] xo = { 0, 0, -2, 2 };
int[] zo = { 2, -2, 0, 0 };
for (int i = 0; i < 4; i++) {
te = worldObj.getTileEntity(xCoord + xo[i], yCoord, zCoord + zo[i]);
if (te instanceof TileEntityEnanReactorLaser) {
@ -308,10 +285,10 @@ public class TileEntityEnanReactorCore extends TileEntityAbstractEnergy implemen
}
}
}
// OpenComputer callback methods
// FIXME: implement OpenComputers...
public Object[] active(Object[] arguments) throws Exception {
if (arguments.length == 1) {
boolean activate = false;
@ -335,7 +312,7 @@ public class TileEntityEnanReactorCore extends TileEntityAbstractEnergy implemen
return new Object[] { active, MODE_STRING[releaseMode], releaseRate };
}
}
private Object[] release(Object[] arguments) throws Exception {
boolean doRelease = false;
if (arguments.length > 0) {
@ -344,14 +321,14 @@ public class TileEntityEnanReactorCore extends TileEntityAbstractEnergy implemen
} catch (Exception e) {
throw new Exception("Function expects an boolean value");
}
releaseMode = doRelease ? MODE_MANUAL_RELEASE : MODE_DONT_RELEASE;
releaseAbove = 0;
releaseRate = 0;
}
return new Object[] { releaseMode != MODE_DONT_RELEASE };
}
private Object[] releaseRate(Object[] arguments) throws Exception {
int rate = -1;
try {
@ -359,7 +336,7 @@ public class TileEntityEnanReactorCore extends TileEntityAbstractEnergy implemen
} catch (Exception e) {
throw new Exception("Function expects an integer value");
}
if (rate <= 0) {
releaseMode = MODE_DONT_RELEASE;
releaseRate = 0;
@ -368,10 +345,10 @@ public class TileEntityEnanReactorCore extends TileEntityAbstractEnergy implemen
releaseRate = rate;
releaseMode = MODE_RELEASE_AT_RATE;
}
return new Object[] { MODE_STRING[releaseMode], releaseRate };
}
private Object[] releaseAbove(Object[] arguments) throws Exception {
int above = -1;
try {
@ -379,7 +356,7 @@ public class TileEntityEnanReactorCore extends TileEntityAbstractEnergy implemen
} catch (Exception e) {
throw new Exception("Function expects an integer value");
}
if (above <= 0) {
releaseMode = 0;
releaseAbove = MODE_DONT_RELEASE;
@ -387,51 +364,48 @@ public class TileEntityEnanReactorCore extends TileEntityAbstractEnergy implemen
releaseMode = MODE_RELEASE_ABOVE;
releaseAbove = above;
}
return new Object[] { MODE_STRING[releaseMode], releaseAbove };
}
// ComputerCraft IPeripheral methods implementation
@Override
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) {
// computer is alive => start updating reactor
hold = false;
String methodName = methodsArray[method];
try {
if (methodName.equals("active")) {
return active(arguments);
} else if (methodName.equals("energy")) {
return new Object[] { containedEnergy, WarpDriveConfig.ENAN_REACTOR_MAX_ENERGY_STORED, releasedLastCycle / WarpDriveConfig.ENAN_REACTOR_UPDATE_INTERVAL_TICKS };
} else if (methodName.equals("instability")) {
Object[] retVal = new Object[4];
for (int i = 0; i < 4; i++) {
retVal[i] = instabilityValues[i];
}
return retVal;
} else if (methodName.equals("release")) {
return release(arguments);
} else if (methodName.equals("releaseRate")) {
return releaseRate(arguments);
} else if (methodName.equals("releaseAbove")) {
return releaseAbove(arguments);
} else if (methodName.equals("help")) {
return new Object[] { helpStr(arguments) };
}
} catch (Exception e) {
return new String[] { e.getMessage() };
}
return null;
}
// POWER INTERFACES
@Override
public int getPotentialEnergyOutput() {
@ -459,7 +433,7 @@ public class TileEntityEnanReactorCore extends TileEntityAbstractEnergy implemen
}
return convertRFtoInternal(result);
}
@Override
public boolean canOutputEnergy(ForgeDirection from) {
if (from.equals(ForgeDirection.UP) || from.equals(ForgeDirection.DOWN)) {

View file

@ -8,6 +8,7 @@ import cr0s.warpdrive.WarpDrive;
import cr0s.warpdrive.api.IBlockUpdateDetector;
import cr0s.warpdrive.block.TileEntityAbstractLaser;
import cr0s.warpdrive.block.TileEntityLaserMedium;
import cr0s.warpdrive.conf.WarpDriveConfig;
import cr0s.warpdrive.data.Vector3;
import cr0s.warpdrive.network.PacketHandler;
import dan200.computercraft.api.lua.ILuaContext;
@ -19,55 +20,54 @@ public class TileEntityEnanReactorLaser extends TileEntityAbstractLaser implemen
ForgeDirection side = ForgeDirection.UNKNOWN;
TileEntityLaserMedium booster;
TileEntityEnanReactorCore reactor;
boolean useLaser = false;
boolean doOnce = false;
private boolean isFirstUpdate = true;
public TileEntityEnanReactorLaser() {
methodsArray = new String[] { "energy", "hasReactor", "side", "sendLaser", "help" };
methodsArray = new String[] { "energy", "hasReactor", "side", "sendLaser" };
peripheralName = "warpdriveEnanReactorLaser";
}
public TileEntityEnanReactorCore scanForReactor() {
reactor = null;
TileEntity te;
TileEntity tileEntity;
// I AM ON THE NORTH SIDE
side = ForgeDirection.UNKNOWN;
te = worldObj.getTileEntity(xCoord, yCoord, zCoord + 2);
if (te instanceof TileEntityEnanReactorCore && worldObj.isAirBlock(xCoord, yCoord, zCoord + 1)) {
tileEntity = worldObj.getTileEntity(xCoord, yCoord, zCoord + 2);
if (tileEntity instanceof TileEntityEnanReactorCore && worldObj.isAirBlock(xCoord, yCoord, zCoord + 1)) {
side = ForgeDirection.NORTH;
reactor = (TileEntityEnanReactorCore) te;
reactor = (TileEntityEnanReactorCore) tileEntity;
}
// I AM ON THE SOUTH SIDE
te = worldObj.getTileEntity(xCoord, yCoord, zCoord - 2);
if (te instanceof TileEntityEnanReactorCore && worldObj.isAirBlock(xCoord, yCoord, zCoord - 1)) {
tileEntity = worldObj.getTileEntity(xCoord, yCoord, zCoord - 2);
if (tileEntity instanceof TileEntityEnanReactorCore && worldObj.isAirBlock(xCoord, yCoord, zCoord - 1)) {
side = ForgeDirection.SOUTH;
reactor = (TileEntityEnanReactorCore) te;
reactor = (TileEntityEnanReactorCore) tileEntity;
}
// I AM ON THE WEST SIDE
te = worldObj.getTileEntity(xCoord + 2, yCoord, zCoord);
if (te instanceof TileEntityEnanReactorCore && worldObj.isAirBlock(xCoord + 1, yCoord, zCoord)) {
tileEntity = worldObj.getTileEntity(xCoord + 2, yCoord, zCoord);
if (tileEntity instanceof TileEntityEnanReactorCore && worldObj.isAirBlock(xCoord + 1, yCoord, zCoord)) {
side = ForgeDirection.WEST;
reactor = (TileEntityEnanReactorCore) te;
reactor = (TileEntityEnanReactorCore) tileEntity;
}
// I AM ON THE EAST SIDE
te = worldObj.getTileEntity(xCoord - 2, yCoord, zCoord);
if (te instanceof TileEntityEnanReactorCore && worldObj.isAirBlock(xCoord - 1, yCoord, zCoord)) {
tileEntity = worldObj.getTileEntity(xCoord - 2, yCoord, zCoord);
if (tileEntity instanceof TileEntityEnanReactorCore && worldObj.isAirBlock(xCoord - 1, yCoord, zCoord)) {
side = ForgeDirection.EAST;
reactor = (TileEntityEnanReactorCore) te;
reactor = (TileEntityEnanReactorCore) tileEntity;
}
setMetadata();
if (reactor != null) {
reactorVec = new Vector3(reactor).translate(0.5);
}
return reactor;
}
private void setMetadata() {
int metadata = 0;
if (side != ForgeDirection.UNKNOWN) {
@ -77,56 +77,52 @@ public class TileEntityEnanReactorLaser extends TileEntityAbstractLaser implemen
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, metadata, 3);
}
}
public TileEntityLaserMedium scanForBooster() {
booster = null;
TileEntity te;
te = worldObj.getTileEntity(xCoord, yCoord + 1, zCoord);
if (te != null && te instanceof TileEntityLaserMedium) {
booster = (TileEntityLaserMedium) te;
TileEntity tileEntity;
tileEntity = worldObj.getTileEntity(xCoord, yCoord + 1, zCoord);
if (tileEntity != null && tileEntity instanceof TileEntityLaserMedium) {
booster = (TileEntityLaserMedium) tileEntity;
}
te = worldObj.getTileEntity(xCoord, yCoord - 1, zCoord);
if (te != null && te instanceof TileEntityLaserMedium) {
booster = (TileEntityLaserMedium) te;
tileEntity = worldObj.getTileEntity(xCoord, yCoord - 1, zCoord);
if (tileEntity != null && tileEntity instanceof TileEntityLaserMedium) {
booster = (TileEntityLaserMedium) tileEntity;
}
return booster;
}
@Override
public void updateEntity() {
super.updateEntity();
if (doOnce == false) {
if (isFirstUpdate) {
isFirstUpdate = false;
scanForReactor();
scanForBooster();
myVec = new Vector3(this).translate(0.5);
doOnce = true;
}
if (useLaser == true) {
PacketHandler.sendBeamPacket(worldObj, myVec, reactorVec, 0.1F, 0.2F, 1.0F, 25, 50, 100);
useLaser = false;
}
}
public void unlink() {
side = ForgeDirection.UNKNOWN;
setMetadata();
}
@Override
public void updatedNeighbours() {
super.updatedNeighbours();
scanForBooster();
scanForReactor();
}
private void laserReactor(int energy) {
if (energy <= 0) {
return;
}
scanForBooster();
scanForReactor();
if (booster == null)
@ -134,39 +130,24 @@ public class TileEntityEnanReactorLaser extends TileEntityAbstractLaser implemen
if (reactor == null)
return;
if (booster.consumeEnergy(energy, false)) {
// WarpDrive.debugPrint("ReactorLaser on " + side.toString()
// +" side sending " + amount);
useLaser = true;
if (WarpDriveConfig.LOGGING_ENERGY && WarpDriveConfig.LOGGING_LUA) {
WarpDrive.logger.info("ReactorLaser on " + side.toString() + " side sending " + energy);
}
reactor.decreaseInstability(side, energy);
PacketHandler.sendBeamPacket(worldObj, myVec, reactorVec, 0.1F, 0.2F, 1.0F, 25, 50, 100);
}
}
@Override
public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt);
}
@Override
public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
}
private static String helpStr(Object[] args) {
if (args.length > 0) {
String arg = args[0].toString().toLowerCase();
if (arg.equals("energy")) {
return WarpDrive.defEnergyStr;
} else if (arg.equals("hasReactor")) {
return "hasReactor(): returns true if the laser can see a reactor and false otherwise";
} else if (arg.equals("sendlaser")) {
return "sendLaser(int): sends a laser of energy int to the reactor";
} else if (arg.equals("side")) {
return "side(): returns 0-3 depending on which side of the reactor its on";
}
}
return WarpDrive.defHelpStr;
}
// ComputerCraft methods
@Override
@Optional.Method(modid = "ComputerCraft")
@ -179,14 +160,15 @@ public class TileEntityEnanReactorLaser extends TileEntityAbstractLaser implemen
} else {
return new Object[] { booster.getEnergyStored(), booster.getMaxEnergyStored() };
}
} else if (methodName.equals("hasReactor")) {
return new Object[] { scanForReactor() != null };
} else if (methodName.equals("sendLaser")) {
if (arguments.length >= 1) {
laserReactor(toInt(arguments[0]));
}
} else if (methodName.equals("help")) {
return new Object[] { helpStr(arguments) };
} else if (methodName.equals("side")) {
return new Object[] { side.ordinal() - 2 };
}

View file

@ -19,63 +19,64 @@ import cr0s.warpdrive.item.ItemIC2reactorLaserFocus;
import cr0s.warpdrive.network.PacketHandler;
public class TileEntityIC2reactorLaserMonitor extends TileEntityAbstractLaser {
private final int workRate = 10;
private int ticks = 0;
private int ticks = WarpDriveConfig.IC2_REACTOR_COOLING_INTERVAL_TICKS;
public TileEntityIC2reactorLaserMonitor() {
super();
IC2_sinkTier = 2;
IC2_sourceTier = 2;
}
private Set<Object> findReactors() {//returns either IReactor or IReactorChamber tile entity
int[] xD = {-2, 2, 0, 0, 0, 0};
int[] yD = { 0, 0,-2, 2, 0, 0};
int[] zD = { 0, 0, 0, 0,-2, 2};
Set<Object> output = new HashSet<Object>();
for(int i = 0; i < xD.length; i++) {
int xO = xCoord + xD[i];
int yO = yCoord + yD[i];
int zO = zCoord + zD[i];
TileEntity te = worldObj.getTileEntity(xO, yO, zO);
if(te == null)
private static int[] deltaX = {-2, 2, 0, 0, 0, 0};
private static int[] deltaY = { 0, 0,-2, 2, 0, 0};
private static int[] deltaZ = { 0, 0, 0, 0,-2, 2};
// returns IReactor tile entities
private Set<IReactor> findReactors() {
Set<IReactor> output = new HashSet<IReactor>();
for(int i = 0; i < deltaX.length; i++) {
TileEntity tileEntity = worldObj.getTileEntity(xCoord + deltaX[i], yCoord + deltaY[i], zCoord + deltaZ[i]);
if (tileEntity == null) {
continue;
if (te instanceof IReactor) {
output.add(te);
} else if(te instanceof IReactorChamber) {
IReactor reactor = ((IReactorChamber)te).getReactor();
if(reactor == null)
}
if (tileEntity instanceof IReactor) {
output.add((IReactor)tileEntity);
} else if (tileEntity instanceof IReactorChamber) {
IReactor reactor = ((IReactorChamber)tileEntity).getReactor();
if (reactor == null) {
continue;
}
// ignore if we're right next to the reactor
ChunkCoordinates coords = reactor.getPosition();
if(Math.abs(coords.posX - xCoord) == 1)
if ( Math.abs(coords.posX - xCoord) == 1
|| Math.abs(coords.posY - yCoord) == 1
|| Math.abs(coords.posZ - zCoord) == 1) {
continue;
if(Math.abs(coords.posY - yCoord) == 1)
continue;
if(Math.abs(coords.posZ - zCoord) == 1)
continue;
output.add(te);
}
output.add(reactor);
}
}
return output;
}
private boolean coolReactor(IReactor react) {
private boolean coolReactor(IReactor reactor) {
boolean didCoolReactor = false;
for(int x = 0; x < 9; x++) {
for(int y = 0; y < 6; y++) {
ItemStack item = react.getItemAt(x, y);
for(int x = 0; x < 9 && !didCoolReactor; x++) {
for(int y = 0; y < 6 && !didCoolReactor; y++) {
ItemStack item = reactor.getItemAt(x, y);
if (item != null) {
if(item.getItem() instanceof ItemIC2reactorLaserFocus) {
int heat = item.getItemDamage();
int heatRemoval = (int) Math.floor(Math.min(getEnergyStored() / WarpDriveConfig.IC2_REACTOR_ENERGY_PER_HEAT, heat));
if (heatRemoval > 0) {
if (item.getItem() instanceof ItemIC2reactorLaserFocus) {
int heatInLaserFocus = item.getItemDamage();
int heatRemovable = (int) Math.floor(Math.min(getEnergyStored() / WarpDriveConfig.IC2_REACTOR_ENERGY_PER_HEAT, heatInLaserFocus));
if (heatRemovable > 0) {
didCoolReactor = true;
consumeEnergy((int) Math.ceil(heatRemoval * WarpDriveConfig.IC2_REACTOR_ENERGY_PER_HEAT), false);
item.setItemDamage(heat - heatRemoval);
consumeEnergy((int) Math.ceil(heatRemovable * WarpDriveConfig.IC2_REACTOR_ENERGY_PER_HEAT), false);
item.setItemDamage(heatInLaserFocus - heatRemovable);
}
}
}
@ -83,60 +84,55 @@ public class TileEntityIC2reactorLaserMonitor extends TileEntityAbstractLaser {
}
return didCoolReactor;
}
@Override
public void updateEntity() {
super.updateEntity();
if (FMLCommonHandler.instance().getEffectiveSide().isClient()) {
return;
}
ticks++;
if (ticks > workRate) {
ticks = 0;
ticks--;
if (ticks <= 0) {
ticks = WarpDriveConfig.IC2_REACTOR_COOLING_INTERVAL_TICKS;
Vector3 myPos = new Vector3(this).translate(0.5);
Set<Object> reactors = findReactors();
if(reactors.size() == 0)
Set<IReactor> reactors = findReactors();
if (reactors.size() == 0) {
return;
for(Object o : reactors)
{
IReactor react = null;
if(o instanceof TileEntity)
{
if(o instanceof IReactor)
react = (IReactor)o;
else if(o instanceof IReactorChamber)
react = ((IReactorChamber)o).getReactor();
if(react != null)
{
if(coolReactor(react))
{
TileEntity te = (TileEntity)o;
PacketHandler.sendBeamPacket(worldObj, myPos, new Vector3(te.xCoord,te.yCoord,te.zCoord).translate(0.5D), 0f, 0.8f, 1f, 20, 0, 20);
}
}
}
for(IReactor reactor : reactors) {
if (coolReactor(reactor)) {
PacketHandler.sendBeamPacket(worldObj, myPos, new Vector3(reactor.getPosition()).translate(0.5D), 0.0f, 0.8f, 1.0f, 20, 0, 20);
}
}
}
}
@Override
public void writeToNBT(NBTTagCompound tag) {
super.writeToNBT(tag);
}
@Override
public void readFromNBT(NBTTagCompound tag) {
super.readFromNBT(tag);
}
@Override
public String getStatus() {
Set<IReactor> reactors = findReactors();
return getBlockType().getLocalizedName()
+ String.format(" energy level is %.0f/%.0f EU.", convertInternalToEU(getEnergyStored()), convertInternalToEU(getMaxEnergyStored()))
+ ((reactors == null || reactors.size() == 0) ? " No reactor found!" : " " + reactors.size() + " reactor(s) connected.");
}
@Override
public int getMaxEnergyStored() {
return WarpDriveConfig.IC2_REACTOR_MAX_ENERGY_STORED;
}
@Override
public boolean canInputEnergy(ForgeDirection from) {
return true;

View file

@ -13,7 +13,6 @@ import net.minecraft.util.AxisAlignedBB;
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.block.TileEntityAbstractEnergy;
import cr0s.warpdrive.conf.WarpDriveConfig;
import cr0s.warpdrive.data.Vector3;
@ -26,15 +25,15 @@ public class TileEntityLift extends TileEntityAbstractEnergy {
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();
IC2_sinkTier = 2;
@ -43,22 +42,21 @@ public class TileEntityLift extends TileEntityAbstractEnergy {
methodsArray = new String[] {
"getEnergyLevel",
"mode",
"active",
"help" };
"active" };
}
@Override
public void updateEntity() {
super.updateEntity();
if (FMLCommonHandler.instance().getEffectiveSide().isClient()) {
return;
}
tickCount++;
if (tickCount >= WarpDriveConfig.LIFT_UPDATE_INTERVAL_TICKS) {
tickCount = 0;
// Switching mode
if ( computerMode == MODE_DOWN
|| (computerMode == MODE_REDSTONE && worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord))) {
@ -66,12 +64,12 @@ public class TileEntityLift extends TileEntityAbstractEnergy {
} else {
mode = MODE_UP;
}
isEnabled = computerEnabled && isPassableBlock(yCoord + 1)
&& isPassableBlock(yCoord + 2)
&& isPassableBlock(yCoord - 1)
&& isPassableBlock(yCoord - 2);
if (getEnergyStored() < WarpDriveConfig.LIFT_ENERGY_PER_ENTITY
|| !isEnabled) {
mode = MODE_INACTIVE;
@ -81,12 +79,12 @@ public class TileEntityLift extends TileEntityAbstractEnergy {
}
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)) {
@ -94,7 +92,7 @@ public class TileEntityLift extends TileEntityAbstractEnergy {
break;
}
}
if (yCoord - firstUncoveredY >= 2) {
if (mode == MODE_UP) {
PacketHandler.sendBeamPacket(worldObj, new Vector3(
@ -107,12 +105,12 @@ public class TileEntityLift extends TileEntityAbstractEnergy {
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
@ -121,17 +119,17 @@ public class TileEntityLift extends TileEntityAbstractEnergy {
|| 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);
@ -170,34 +168,34 @@ public class TileEntityLift extends TileEntityAbstractEnergy {
}
}
}
@Override
public void readFromNBT(NBTTagCompound tag) {
super.readFromNBT(tag);
}
@Override
public void writeToNBT(NBTTagCompound tag) {
super.writeToNBT(tag);
}
@Override
public int getMaxEnergyStored() {
return WarpDriveConfig.LIFT_MAX_ENERGY_STORED;
}
@Override
public boolean canInputEnergy(ForgeDirection from) {
return true;
}
// OpenComputer callback methods
@Callback
@Optional.Method(modid = "OpenComputers")
public Object[] mode(Context context, Arguments arguments) {
return mode(argumentsOCtoCC(arguments));
}
@Callback
@Optional.Method(modid = "OpenComputers")
public Object[] active(Context context, Arguments arguments) {
@ -206,7 +204,7 @@ public class TileEntityLift extends TileEntityAbstractEnergy {
}
return new Object[] { computerEnabled ? false : isEnabled };
}
private Object[] mode(Object[] arguments) {
if (arguments.length == 1) {
if (arguments[0].toString().equals("up")) {
@ -227,41 +225,23 @@ public class TileEntityLift extends TileEntityAbstractEnergy {
}
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;
}
// ComputerCraft IPeripheral methods implementation
@Override
@Optional.Method(modid = "ComputerCraft")
public Object[] callMethod(IComputerAccess computer, ILuaContext context,
int method, Object[] arguments) {
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;
}

View file

@ -33,7 +33,7 @@ public class WarpDriveConfig {
private static File configDirectory;
private static DocumentBuilder xmlDocumentBuilder;
private static final String[] defaultXMLfilenames = { "structures-default.xml" };
/*
* The variables which store whether or not individual mods are loaded
*/
@ -51,7 +51,7 @@ public class WarpDriveConfig {
public static boolean isThermalExpansionLoaded = false;
public static boolean isAdvancedRepulsionSystemsLoaded = false;
public static boolean isMagicalCropsLoaded = false;
// ForgeMultipart (microblocks) support
public static Method forgeMultipart_helper_createTileFromNBT = null;
public static Method forgeMultipart_helper_sendDescPacket = null;
@ -199,7 +199,7 @@ public class WarpDriveConfig {
// - overall consumption in 'ores, space' is ML_EU_PER_LAYER_SPACE + ((ML_MAX_RADIUS * 2 + 1) ^ 2) * ML_EU_PER_BLOCK_SPACE * ML_EU_MUL_ORESONLY / 25 => ~ 28630 EU/layer
// - at radius 5, one layer takes 403 ticks (2 * ML_SCAN_DELAY_TICKS + ML_MINE_DELAY_TICKS * (ML_MAX_RADIUS * 2 + 1) ^ 2)
public static int MINING_LASER_MAX_MEDIUMS_COUNT = 1;
public static int MINING_LASER_MAX_RADIUS = 16;
public static int MINING_LASER_RADIUS_BLOCKS = 5;
public static int MINING_LASER_WARMUP_DELAY_TICKS = 20;
public static int MINING_LASER_SCAN_DELAY_TICKS = 20;
public static int MINING_LASER_MINE_DELAY_TICKS = 3;
@ -234,26 +234,27 @@ public class WarpDriveConfig {
// IC2 Reactor monitor
public static int IC2_REACTOR_MAX_ENERGY_STORED = 1000000;
public static double IC2_REACTOR_ENERGY_PER_HEAT = 2;
public static int IC2_REACTOR_COOLING_INTERVAL_TICKS = 10;
// Transporter
public static int TRANSPORTER_MAX_ENERGY = 1000000;
public static boolean TRANSPORTER_USE_RELATIVE_COORDS = true;
public static double TRANSPORTER_ENERGY_PER_BLOCK = 100.0;
public static double TRANSPORTER_MAX_BOOST_MUL = 4.0;
// Enantiomorphic Power reactor
public static int ENAN_REACTOR_MAX_ENERGY_STORED = 100000000;
public static int ENAN_REACTOR_UPDATE_INTERVAL_TICKS = 5;
public static int ENAN_REACTOR_MAX_LASERS_PER_SECOND = 6;
// Power store
public static int ENERGY_BANK_MAX_ENERGY_STORED = 1000000;
// Laser Lift
public static int LIFT_MAX_ENERGY_STORED = 2400;
public static int LIFT_ENERGY_PER_ENTITY = 800;
public static int LIFT_UPDATE_INTERVAL_TICKS = 10;
// Chunk Loader
public static int CL_MAX_ENERGY = 1000000;
public static int CL_MAX_DISTANCE = 2;
@ -292,22 +293,6 @@ public class WarpDriveConfig {
// read configuration file
loadWarpDriveConfig(new File(configDirectory, WarpDrive.MODID + ".cfg"));
// read XML files
File[] files = configDirectory.listFiles(new FilenameFilter() {
@Override
public boolean accept(File file_notUsed, String name) {
return name.endsWith(".xml");
}
});
if (files.length == 0) {
for(String defaultXMLfilename : defaultXMLfilenames) {
unpackResourceToFolder(defaultXMLfilename, "config", configDirectory);
}
}
FillerManager.loadOres(configDirectory);
StructureManager.loadStructures(configDirectory);
}
public static void loadWarpDriveConfig(File file) {
@ -542,8 +527,8 @@ public class WarpDriveConfig {
// Mining Laser
MINING_LASER_MAX_MEDIUMS_COUNT = clamp(1, 64,
config.get("mining_laser", "max_mediums_count", MINING_LASER_MAX_MEDIUMS_COUNT).getInt());
MINING_LASER_MAX_RADIUS = clamp(1, 64,
config.get("mining_laser", "max_radius", MINING_LASER_MAX_RADIUS).getInt());
MINING_LASER_RADIUS_BLOCKS = clamp(1, 64,
config.get("mining_laser", "radius_blocks", MINING_LASER_RADIUS_BLOCKS).getInt());
MINING_LASER_WARMUP_DELAY_TICKS = clamp(1, 300,
config.get("mining_laser", "warmup_delay_ticks", MINING_LASER_WARMUP_DELAY_TICKS).getInt());
@ -607,6 +592,8 @@ public class WarpDriveConfig {
config.get("ic2_reactor_laser", "max_energy_stored", IC2_REACTOR_MAX_ENERGY_STORED).getInt());
IC2_REACTOR_ENERGY_PER_HEAT = clamp(2.0D, 100000.0D,
config.get("ic2_reactor_laser", "energy_per_heat", IC2_REACTOR_ENERGY_PER_HEAT).getDouble(2));
IC2_REACTOR_COOLING_INTERVAL_TICKS = clamp(0, 1200,
config.get("ic2_reactor_laser", "cooling_interval_ticks", IC2_REACTOR_COOLING_INTERVAL_TICKS).getInt());
// Transporter
TRANSPORTER_MAX_ENERGY = clamp(1, Integer.MAX_VALUE,
@ -756,7 +743,24 @@ public class WarpDriveConfig {
}
public static void postInit() {
// read XML files
File[] files = configDirectory.listFiles(new FilenameFilter() {
@Override
public boolean accept(File file_notUsed, String name) {
return name.endsWith(".xml");
}
});
if (files.length == 0) {
for(String defaultXMLfilename : defaultXMLfilenames) {
unpackResourceToFolder(defaultXMLfilename, "config", configDirectory);
}
}
FillerManager.loadOres(configDirectory);
StructureManager.loadStructures(configDirectory);
LoadOreDict();
FillerManager.finishLoading();
}

View file

@ -45,7 +45,7 @@ public class Planet implements Cloneable {
* @param currentPosition current position in the planet/dimension
* @return distance to transition borders, 0 if take off is possible
*/
public int isValidToSpace(Vector3 currentPosition) {
public int isValidToSpace(VectorI currentPosition) {
if ((Math.abs(currentPosition.x - dimensionCenterX) <= borderSizeX) && (Math.abs(currentPosition.z - dimensionCenterZ) <= borderSizeZ)) {
return 0;
}
@ -60,7 +60,7 @@ public class Planet implements Cloneable {
* @param currentPosition current position in space
* @return distance to transition borders, 0 if entry is possible
*/
public int isValidFromSpace(Vector3 currentPosition) {
public int isValidFromSpace(VectorI currentPosition) {
if ((Math.abs(currentPosition.x - spaceCenterX) <= borderSizeX) && (Math.abs(currentPosition.z - spaceCenterZ) <= borderSizeZ)) {
return 0;
}

View file

@ -212,7 +212,40 @@ public class Vector3 implements Cloneable {
this.z += par1;
return this;
}
// modify current vector by translation of amount block in side direction
public Vector3 translate(final ForgeDirection side, final double amount) {
switch (side) {
case DOWN:
y -= amount;
break;
case UP:
y += amount;
break;
case NORTH:
z -= amount;
break;
case SOUTH:
z += amount;
break;
case WEST:
x -= amount;
break;
case EAST:
x += amount;
}
return this;
}
// modify current vector by translation of 1 block in side direction
public Vector3 translate(final ForgeDirection side) {
x += side.offsetX;
y += side.offsetY;
z += side.offsetZ;
return this;
}
public static Vector3 translate(Vector3 translate, Vector3 par1) {
translate.x += par1.x;
translate.y += par1.y;
@ -226,7 +259,7 @@ public class Vector3 implements Cloneable {
translate.z += par1;
return translate;
}
public Vector3 subtract(Vector3 amount) {
return this.translate(amount.clone().invert());
}

View file

@ -70,6 +70,11 @@ public class VectorI implements Cloneable {
}
public Vector3 getBlockCenter() {
return new Vector3(x + 0.5D, y + 0.5D, z + 0.5D);
}
@Override
public VectorI clone() {
return new VectorI(x, y, z);
@ -178,7 +183,9 @@ public class VectorI implements Cloneable {
// modify current vector by translation of 1 block in side direction
public VectorI translate(final ForgeDirection side) {
translate(side, 1);
x += side.offsetX;
y += side.offsetY;
z += side.offsetZ;
return this;
}