Merge branch 'master' of github.com:SirSengir/BuildCraft

This commit is contained in:
SirSengir 2012-07-15 22:24:51 +02:00
commit 53cc613c9f
2 changed files with 274 additions and 271 deletions

View file

@ -133,6 +133,9 @@ public class GuiAssemblyTable extends GuiAdvancedInterface {
if (position != -1) { if (position != -1) {
RecipeSlot slot = (RecipeSlot) slots[position]; RecipeSlot slot = (RecipeSlot) slots[position];
if (slot.recipe == null)
return;
SelectionMessage message = new SelectionMessage(); SelectionMessage message = new SelectionMessage();

View file

@ -1,271 +1,271 @@
/** /**
* Copyright (c) SpaceToad, 2011 * Copyright (c) SpaceToad, 2011
* http://www.mod-buildcraft.com * http://www.mod-buildcraft.com
* *
* BuildCraft is distributed under the terms of the Minecraft Mod Public * BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in * License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt * http://www.mod-buildcraft.com/MMPL-1.0.txt
*/ */
package net.minecraft.src.buildcraft.silicon; package net.minecraft.src.buildcraft.silicon;
import java.util.LinkedList; import java.util.LinkedList;
import net.minecraft.src.NBTTagCompound; import net.minecraft.src.NBTTagCompound;
import net.minecraft.src.TileEntity; import net.minecraft.src.TileEntity;
import net.minecraft.src.buildcraft.api.APIProxy; import net.minecraft.src.buildcraft.api.APIProxy;
import net.minecraft.src.buildcraft.api.IPowerReceptor; import net.minecraft.src.buildcraft.api.IPowerReceptor;
import net.minecraft.src.buildcraft.api.Orientations; import net.minecraft.src.buildcraft.api.Orientations;
import net.minecraft.src.buildcraft.api.Position; import net.minecraft.src.buildcraft.api.Position;
import net.minecraft.src.buildcraft.api.PowerFramework; import net.minecraft.src.buildcraft.api.PowerFramework;
import net.minecraft.src.buildcraft.api.PowerProvider; import net.minecraft.src.buildcraft.api.PowerProvider;
import net.minecraft.src.buildcraft.api.SafeTimeTracker; import net.minecraft.src.buildcraft.api.SafeTimeTracker;
import net.minecraft.src.buildcraft.api.TileNetworkData; import net.minecraft.src.buildcraft.api.TileNetworkData;
import net.minecraft.src.buildcraft.core.BlockIndex; import net.minecraft.src.buildcraft.core.BlockIndex;
import net.minecraft.src.buildcraft.core.EntityEnergyLaser; import net.minecraft.src.buildcraft.core.EntityEnergyLaser;
import net.minecraft.src.buildcraft.core.TileBuildCraft; import net.minecraft.src.buildcraft.core.TileBuildCraft;
import net.minecraft.src.buildcraft.factory.TileAssemblyTable; import net.minecraft.src.buildcraft.factory.TileAssemblyTable;
public class TileLaser extends TileBuildCraft implements IPowerReceptor { public class TileLaser extends TileBuildCraft implements IPowerReceptor {
private EntityEnergyLaser laser = null; private EntityEnergyLaser laser = null;
private final SafeTimeTracker laserTickTracker = new SafeTimeTracker(); private final SafeTimeTracker laserTickTracker = new SafeTimeTracker();
private final SafeTimeTracker searchTracker = new SafeTimeTracker(); private final SafeTimeTracker searchTracker = new SafeTimeTracker();
private final SafeTimeTracker networkTracker = new SafeTimeTracker(); private final SafeTimeTracker networkTracker = new SafeTimeTracker();
private TileAssemblyTable assemblyTable; private TileAssemblyTable assemblyTable;
@TileNetworkData @TileNetworkData
public PowerProvider powerProvider; public PowerProvider powerProvider;
private int nextNetworkUpdate = 3; private int nextNetworkUpdate = 3;
private int nextLaserUpdate = 10; private int nextLaserUpdate = 10;
private int nextLaserSearch = 10; private int nextLaserSearch = 10;
public TileLaser() { public TileLaser() {
powerProvider = PowerFramework.currentFramework.createPowerProvider(); powerProvider = PowerFramework.currentFramework.createPowerProvider();
powerProvider.configure(20, 25, 25, 25, 1000); powerProvider.configure(20, 25, 25, 25, 1000);
} }
@Override @Override
public void updateEntity() { public void updateEntity() {
if (powerProvider.energyStored == 0) { if (powerProvider.energyStored == 0) {
removeLaser(); removeLaser();
return; return;
} }
if (!isValidTable()) { if (!isValidTable()) {
if (canFindTable()) { if (canFindTable()) {
findTable(); findTable();
} }
} }
if (!isValidTable()) { if (!isValidTable()) {
removeLaser(); removeLaser();
return; return;
} }
if (laser == null) { if (laser == null) {
createLaser(); createLaser();
} }
if (laser != null && canUpdateLaser()) { if (laser != null && canUpdateLaser()) {
updateLaser(); updateLaser();
} }
float p = powerProvider.useEnergy(0, 4, true); float p = powerProvider.useEnergy(0, 4, true);
assemblyTable.receiveLaserEnergy(p); assemblyTable.receiveLaserEnergy(p);
if (laser != null) { if (laser != null) {
laser.pushPower(p); laser.pushPower(p);
} }
sendNetworkUpdate(); sendNetworkUpdate();
} }
protected boolean canFindTable() { protected boolean canFindTable() {
return searchTracker.markTimeIfDelay(worldObj, nextLaserSearch); return searchTracker.markTimeIfDelay(worldObj, nextLaserSearch);
} }
protected boolean canUpdateLaser() { protected boolean canUpdateLaser() {
return laserTickTracker.markTimeIfDelay(worldObj, nextLaserUpdate); return laserTickTracker.markTimeIfDelay(worldObj, nextLaserUpdate);
} }
protected boolean isValidTable() { protected boolean isValidTable() {
if (assemblyTable == null || assemblyTable.isInvalid() || assemblyTable.currentRecipe == null) { if (assemblyTable == null || assemblyTable.isInvalid() || assemblyTable.currentRecipe == null) {
return false; return false;
} }
return true; return true;
} }
protected void findTable() { protected void findTable() {
int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord); int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
int minX = xCoord - 5; int minX = xCoord - 5;
int minY = yCoord - 5; int minY = yCoord - 5;
int minZ = zCoord - 5; int minZ = zCoord - 5;
int maxX = xCoord + 5; int maxX = xCoord + 5;
int maxY = yCoord + 5; int maxY = yCoord + 5;
int maxZ = zCoord + 5; int maxZ = zCoord + 5;
switch (Orientations.values()[meta]) { switch (Orientations.values()[meta]) {
case XNeg: case XNeg:
maxX = xCoord; maxX = xCoord;
break; break;
case XPos: case XPos:
minX = xCoord; minX = xCoord;
break; break;
case YNeg: case YNeg:
maxY = yCoord; maxY = yCoord;
break; break;
case YPos: case YPos:
minY = yCoord; minY = yCoord;
break; break;
case ZNeg: case ZNeg:
maxZ = zCoord; maxZ = zCoord;
break; break;
case ZPos: case ZPos:
minZ = zCoord; minZ = zCoord;
break; break;
} }
LinkedList<BlockIndex> targets = new LinkedList<BlockIndex>(); LinkedList<BlockIndex> targets = new LinkedList<BlockIndex>();
for (int x = minX; x <= maxX; ++x) { for (int x = minX; x <= maxX; ++x) {
for (int y = minY; y <= maxY; ++y) { for (int y = minY; y <= maxY; ++y) {
for (int z = minZ; z <= maxZ; ++z) { for (int z = minZ; z <= maxZ; ++z) {
TileEntity tile = worldObj.getBlockTileEntity(x, y, z); TileEntity tile = worldObj.getBlockTileEntity(x, y, z);
if (tile instanceof TileAssemblyTable) { if (tile instanceof TileAssemblyTable) {
TileAssemblyTable table = (TileAssemblyTable) tile; TileAssemblyTable table = (TileAssemblyTable) tile;
if (table.currentRecipe != null) { if (table.currentRecipe != null) {
targets.add(new BlockIndex(x, y, z)); targets.add(new BlockIndex(x, y, z));
} }
} }
} }
} }
} }
if (targets.size() == 0) { if (targets.size() == 0) {
return; return;
} }
BlockIndex b = targets.get(worldObj.rand.nextInt(targets.size())); BlockIndex b = targets.get(worldObj.rand.nextInt(targets.size()));
assemblyTable = (TileAssemblyTable) worldObj.getBlockTileEntity(b.i, b.j, b.k); assemblyTable = (TileAssemblyTable) worldObj.getBlockTileEntity(b.i, b.j, b.k);
} }
protected void createLaser() { protected void createLaser() {
if (!APIProxy.isClient(worldObj)) if (APIProxy.isServerSide())
return; return;
laser = new EntityEnergyLaser(worldObj, new Position(xCoord, yCoord, zCoord), new Position(xCoord, yCoord, zCoord)); laser = new EntityEnergyLaser(worldObj, new Position(xCoord, yCoord, zCoord), new Position(xCoord, yCoord, zCoord));
worldObj.spawnEntityInWorld(laser); worldObj.spawnEntityInWorld(laser);
} }
protected void updateLaser() { protected void updateLaser() {
int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord); int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
double px = 0, py = 0, pz = 0; double px = 0, py = 0, pz = 0;
switch (Orientations.values()[meta]) { switch (Orientations.values()[meta]) {
case XNeg: case XNeg:
px = -0.3; px = -0.3;
break; break;
case XPos: case XPos:
px = 0.3; px = 0.3;
break; break;
case YNeg: case YNeg:
py = -0.3; py = -0.3;
break; break;
case YPos: case YPos:
py = 0.3; py = 0.3;
break; break;
case ZNeg: case ZNeg:
pz = -0.3; pz = -0.3;
break; break;
case ZPos: case ZPos:
pz = 0.3; pz = 0.3;
break; break;
} }
Position head = new Position(xCoord + 0.5 + px, yCoord + 0.5 + py, zCoord + 0.5 + pz); Position head = new Position(xCoord + 0.5 + px, yCoord + 0.5 + py, zCoord + 0.5 + pz);
Position tail = new Position( Position tail = new Position(
assemblyTable.xCoord + 0.475 + (worldObj.rand.nextFloat() - 0.5) / 5F, assemblyTable.xCoord + 0.475 + (worldObj.rand.nextFloat() - 0.5) / 5F,
assemblyTable.yCoord + 9F / 16F, assemblyTable.yCoord + 9F / 16F,
assemblyTable.zCoord + 0.475 + (worldObj.rand.nextFloat() - 0.5) / 5F); assemblyTable.zCoord + 0.475 + (worldObj.rand.nextFloat() - 0.5) / 5F);
laser.setPositions(head, tail); laser.setPositions(head, tail);
laser.show(); laser.show();
} }
protected void removeLaser() { protected void removeLaser() {
if (laser != null) { if (laser != null) {
laser.setDead(); laser.setDead();
laser = null; laser = null;
} }
} }
@Override @Override
public void setPowerProvider(PowerProvider provider) { public void setPowerProvider(PowerProvider provider) {
powerProvider = provider; powerProvider = provider;
} }
@Override @Override
public PowerProvider getPowerProvider() { public PowerProvider getPowerProvider() {
return powerProvider; return powerProvider;
} }
@Override @Override
public void doWork() {} public void doWork() {}
@Override @Override
public int powerRequest() { public int powerRequest() {
if (powerProvider.energyStored < 200 || laser != null) { if (powerProvider.energyStored < 200 || laser != null) {
return 25; return 25;
} else { } else {
return 0; return 0;
} }
} }
@Override @Override
public void sendNetworkUpdate() { public void sendNetworkUpdate() {
if (networkTracker.markTimeIfDelay(worldObj, nextNetworkUpdate)) { if (networkTracker.markTimeIfDelay(worldObj, nextNetworkUpdate)) {
super.sendNetworkUpdate(); super.sendNetworkUpdate();
} }
}; };
@Override @Override
public void readFromNBT(NBTTagCompound nbttagcompound) { public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound); super.readFromNBT(nbttagcompound);
PowerFramework.currentFramework.loadPowerProvider(this, nbttagcompound); PowerFramework.currentFramework.loadPowerProvider(this, nbttagcompound);
powerProvider.configure(20, 25, 25, 25, 1000); powerProvider.configure(20, 25, 25, 25, 1000);
} }
@Override @Override
public void writeToNBT(NBTTagCompound nbttagcompound) { public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound); super.writeToNBT(nbttagcompound);
PowerFramework.currentFramework.savePowerProvider(this, nbttagcompound); PowerFramework.currentFramework.savePowerProvider(this, nbttagcompound);
} }
@Override @Override
public void invalidate() { public void invalidate() {
super.invalidate(); super.invalidate();
removeLaser(); removeLaser();
} }
} }