Files
Mekanism-Community-Edition/src/main/java/mekanism/common/integration/computer/CCPeripheral.java
T
Richard Freimer 80b07bc4b3 Code cleanup (#5468)
* remove direct guava predicates from BlockStateMachine

* cleanup blockstatebasic

* fix a large number of e.printStacktrace calls, narrow ComputerIntegration exception signature

* fix simple todos, remove invalid todos, unify some duplicate rendering code

* use a generic method to get around unchecked warning

* remove some redundant uses of hasCapability

* experimental OptionalCapability class. not in use yet

* nullable checks/annotations & remove duplicate field controlType in factory TE

* Inline various redundant variables

* Remove unused list

* Cleanup BlockStateGenerator

* Replace string constants with pointers to the proper mod id constant

* As 9.7.5 breaks backwards compat API wise for the DynamicNetwork this is as good a time as any to remove this deprecated method

* Use two argument constructor instead of appending a ':' inbetween

* Convert other BlockState type classes to using suppliers for tile entity creation
2019-05-13 11:43:42 -04:00

78 lines
2.5 KiB
Java

package mekanism.common.integration.computer;
import dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.peripheral.IComputerAccess;
import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.api.peripheral.IPeripheralProvider;
import javax.annotation.Nonnull;
import mekanism.common.integration.MekanismHooks;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.Optional;
/**
* Created by aidancbrady on 7/20/15.
*/
@Optional.Interface(iface = "dan200.computercraft.api.peripheral.IPeripheral", modid = MekanismHooks.COMPUTERCRAFT_MOD_ID)
public class CCPeripheral implements IPeripheral {
public IComputerIntegration computerTile;
public CCPeripheral(IComputerIntegration tile) {
computerTile = tile;
}
@Nonnull
@Override
@Optional.Method(modid = MekanismHooks.COMPUTERCRAFT_MOD_ID)
public String getType() {
return computerTile.getName();
}
@Nonnull
@Override
@Optional.Method(modid = MekanismHooks.COMPUTERCRAFT_MOD_ID)
public String[] getMethodNames() {
return computerTile.getMethods();
}
@Override
@Optional.Method(modid = MekanismHooks.COMPUTERCRAFT_MOD_ID)
public Object[] callMethod(@Nonnull IComputerAccess computer, @Nonnull ILuaContext context, int method, @Nonnull Object[] arguments) {
try {
return computerTile.invoke(method, arguments);
} catch (NoSuchMethodException e) {
return new Object[]{"Unknown command."};
}
}
@Override
@Optional.Method(modid = MekanismHooks.COMPUTERCRAFT_MOD_ID)
public void attach(@Nonnull IComputerAccess computer) {
}
@Override
@Optional.Method(modid = MekanismHooks.COMPUTERCRAFT_MOD_ID)
public void detach(@Nonnull IComputerAccess computer) {
}
@Override
@Optional.Method(modid = MekanismHooks.COMPUTERCRAFT_MOD_ID)
public boolean equals(IPeripheral other) {
return this == other;
}
public static class CCPeripheralProvider implements IPeripheralProvider {
@Override
public IPeripheral getPeripheral(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side) {
TileEntity te = world.getTileEntity(pos);
if (te instanceof IComputerIntegration) {
return new CCPeripheral((IComputerIntegration) te);
}
return null;
}
}
}