This commit is contained in:
Raoul Van den Berge
2016-05-14 16:41:02 +02:00
parent dd7cee8c8b
commit 440b4cc0bc
4 changed files with 74 additions and 68 deletions

View File

@@ -298,6 +298,6 @@ public class RefinedStorageUtils {
} }
public static void reRenderBlock(World world, BlockPos pos) { public static void reRenderBlock(World world, BlockPos pos) {
world.notifyBlockUpdate(pos, world.getBlockState(pos), world.getBlockState(pos), 1 | 2); world.notifyBlockUpdate(pos, world.getBlockState(pos), world.getBlockState(pos), 2 | 4);
} }
} }

View File

@@ -54,7 +54,7 @@ public abstract class BlockMachine extends BlockBase {
super.onNeighborBlockChange(world, pos, state, neighborBlock); super.onNeighborBlockChange(world, pos, state, neighborBlock);
if (!world.isRemote) { if (!world.isRemote) {
((TileMachine) world.getTileEntity(pos)).searchController(); ((TileMachine) world.getTileEntity(pos)).searchController(world);
} }
} }
} }

View File

@@ -102,79 +102,79 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
List<IStorage> newStorages = new ArrayList<IStorage>(); List<IStorage> newStorages = new ArrayList<IStorage>();
List<CraftingPattern> newPatterns = new ArrayList<CraftingPattern>(); List<CraftingPattern> newPatterns = new ArrayList<CraftingPattern>();
if (canRun()) { //if (canRun()) {
newEnergyUsage = 10; newEnergyUsage = 10;
for (TileMachine machine : machines) { for (TileMachine machine : machines) {
machine.updateMachine(); machine.updateMachine();
if (machine instanceof TileWirelessTransmitter) { if (machine instanceof TileWirelessTransmitter) {
newWirelessGridRange += ((TileWirelessTransmitter) machine).getRange(); newWirelessGridRange += ((TileWirelessTransmitter) machine).getRange();
} }
if (machine instanceof IStorageProvider) { if (machine instanceof IStorageProvider) {
((IStorageProvider) machine).provide(newStorages); ((IStorageProvider) machine).provide(newStorages);
} }
if (machine instanceof TileCrafter) { if (machine instanceof TileCrafter) {
TileCrafter crafter = (TileCrafter) machine; TileCrafter crafter = (TileCrafter) machine;
for (int i = 0; i < TileCrafter.PATTERN_SLOTS; ++i) { for (int i = 0; i < TileCrafter.PATTERN_SLOTS; ++i) {
if (crafter.getStackInSlot(i) != null) { if (crafter.getStackInSlot(i) != null) {
ItemStack pattern = crafter.getStackInSlot(i); ItemStack pattern = crafter.getStackInSlot(i);
newPatterns.add(new CraftingPattern( newPatterns.add(new CraftingPattern(
crafter.getPos().getX(), crafter.getPos().getX(),
crafter.getPos().getY(), crafter.getPos().getY(),
crafter.getPos().getZ(), crafter.getPos().getZ(),
ItemPattern.isProcessing(pattern), ItemPattern.isProcessing(pattern),
ItemPattern.getInputs(pattern), ItemPattern.getInputs(pattern),
ItemPattern.getOutputs(pattern))); ItemPattern.getOutputs(pattern)));
}
} }
} }
newEnergyUsage += machine.getEnergyUsage();
} }
Collections.sort(storages, new Comparator<IStorage>() { newEnergyUsage += machine.getEnergyUsage();
@Override
public int compare(IStorage s1, IStorage s2) {
if (s1.getPriority() == s2.getPriority()) {
return 0;
}
return (s1.getPriority() > s2.getPriority()) ? -1 : 1;
}
});
syncItems();
for (ICraftingTask taskToCancel : craftingTasksToCancel) {
taskToCancel.onCancelled(this);
}
craftingTasks.removeAll(craftingTasksToCancel);
craftingTasksToCancel.clear();
craftingTasks.addAll(craftingTasksToAdd);
craftingTasksToAdd.clear();
Iterator<ICraftingTask> craftingTaskIterator = craftingTasks.iterator();
while (craftingTaskIterator.hasNext()) {
ICraftingTask task = craftingTaskIterator.next();
if (ticks % task.getPattern().getCrafter(worldObj).getSpeed() == 0 && task.update(this)) {
task.onDone(this);
craftingTaskIterator.remove();
}
}
} else {
disconnectAll();
} }
Collections.sort(storages, new Comparator<IStorage>() {
@Override
public int compare(IStorage s1, IStorage s2) {
if (s1.getPriority() == s2.getPriority()) {
return 0;
}
return (s1.getPriority() > s2.getPriority()) ? -1 : 1;
}
});
syncItems();
for (ICraftingTask taskToCancel : craftingTasksToCancel) {
taskToCancel.onCancelled(this);
}
craftingTasks.removeAll(craftingTasksToCancel);
craftingTasksToCancel.clear();
craftingTasks.addAll(craftingTasksToAdd);
craftingTasksToAdd.clear();
Iterator<ICraftingTask> craftingTaskIterator = craftingTasks.iterator();
while (craftingTaskIterator.hasNext()) {
ICraftingTask task = craftingTaskIterator.next();
if (ticks % task.getPattern().getCrafter(worldObj).getSpeed() == 0 && task.update(this)) {
task.onDone(this);
craftingTaskIterator.remove();
}
}
/*} else {
disconnectAll();
}*/
wirelessGridRange = newWirelessGridRange; wirelessGridRange = newWirelessGridRange;
energyUsage = newEnergyUsage; energyUsage = newEnergyUsage;
storages = newStorages; storages = newStorages;
@@ -208,7 +208,7 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
break; break;
} }
if (lastEnergy != energy.getEnergyStored()) { if (lastEnergy != energy.getEnergyStored() || ticks == 1) {
worldObj.updateComparatorOutputLevel(pos, RefinedStorageBlocks.CONTROLLER); worldObj.updateComparatorOutputLevel(pos, RefinedStorageBlocks.CONTROLLER);
if (System.currentTimeMillis() - lastEnergyUpdate > 3000L) { if (System.currentTimeMillis() - lastEnergyUpdate > 3000L) {
@@ -216,8 +216,6 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
lastEnergyUpdate = System.currentTimeMillis(); lastEnergyUpdate = System.currentTimeMillis();
} }
} else if (ticks < 10) {
RefinedStorageUtils.sendToAllAround(worldObj, pos, new MessageControllerEnergyUpdate(this));
} }
} }
} }

View File

@@ -4,6 +4,7 @@ import io.netty.buffer.ByteBuf;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import refinedstorage.RefinedStorageUtils; import refinedstorage.RefinedStorageUtils;
import refinedstorage.block.BlockMachine; import refinedstorage.block.BlockMachine;
import refinedstorage.network.MessageMachineConnectedUpdate; import refinedstorage.network.MessageMachineConnectedUpdate;
@@ -25,7 +26,14 @@ public abstract class TileMachine extends TileBase implements ISynchronizedConta
return controller; return controller;
} }
public void searchController() { // We use a world parameter here and not worldObj because in BlockMachine.onNeighborBlockChange
// this method is called and at that point in time worldObj is not set yet.
public void searchController(World world) {
// @TODO: Give onConnected and onDisconnected a world param
if (worldObj == null) {
worldObj = world;
}
visited.clear(); visited.clear();
TileController newController = ControllerSearcher.search(worldObj, pos, visited); TileController newController = ControllerSearcher.search(worldObj, pos, visited);
@@ -49,7 +57,7 @@ public abstract class TileMachine extends TileBase implements ISynchronizedConta
if (ticks == 1) { if (ticks == 1) {
block = worldObj.getBlockState(pos).getBlock(); block = worldObj.getBlockState(pos).getBlock();
searchController(); searchController(worldObj);
} }
if (connected && !redstoneMode.isEnabled(worldObj, pos)) { if (connected && !redstoneMode.isEnabled(worldObj, pos)) {