added check to avoid duplicate components when a block next to the adapter already has an environment interface in addition to a peripheral interface

This commit is contained in:
Florian Nücke 2014-02-10 03:10:30 +01:00
parent 0b3c9ddecd
commit b442981fbf
3 changed files with 13 additions and 4 deletions

View File

@ -17,9 +17,9 @@ public final class Registry {
}
public static void add(final IMod mod) {
final boolean alwaysEnabled = mod.getModId() == null || mod.getModId().isEmpty();
final boolean alwaysEnabled = mod.getModId() == null || mod.getModId().isEmpty() || "Minecraft".equals(mod.getModId());
if ((alwaysEnabled || Loader.isModLoaded(mod.getModId())) && handlers.add(mod)) {
OpenComponents.Log.info(String.format("Initializing handler for '%s'.", mod.getModId()));
OpenComponents.Log.info(String.format("Initializing drivers for '%s'.", mod.getModId()));
try {
mod.initialize();
} catch (Throwable e) {

View File

@ -1,6 +1,7 @@
package li.cil.occ.mods.computercraft;
import dan200.computer.api.IPeripheral;
import li.cil.oc.api.network.Environment;
import li.cil.oc.api.network.ManagedEnvironment;
import li.cil.oc.api.prefab.DriverTileEntity;
import li.cil.oc.api.prefab.ManagedPeripheral;
@ -32,7 +33,15 @@ public final class DriverPeripheral extends DriverTileEntity {
@Override
public boolean worksWith(final World world, final int x, final int y, final int z) {
final TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
return tileEntity != null && !blacklist.contains(tileEntity.getClass()) && super.worksWith(world, x, y, z);
return tileEntity != null
// This ensures we don't get duplicate components, in case the
// tile entity is natively compatible with OpenComputers.
&& !Environment.class.isAssignableFrom(tileEntity.getClass())
// The black list is used to avoid peripherals that are known
// to be incompatible with OpenComputers when used directly.
&& !blacklist.contains(tileEntity.getClass())
// Actual check if it's a peripheral.
&& super.worksWith(world, x, y, z);
}
@Override

View File

@ -9,7 +9,7 @@ import java.util.Map;
public final class ModVanilla implements IMod {
@Override
public String getModId() {
return null;
return "Minecraft";
}
@Override