use of mcmultipart.multipart.IMultipartContainer in project Charset by CharsetMC.
the class RedstoneUtils method canConnectFace.
public static boolean canConnectFace(IBlockAccess world, BlockPos pos, IBlockState state, EnumFacing side, EnumFacing face) {
Block block = state.getBlock();
if ((block instanceof BlockRedstoneDiode || block instanceof BlockRedstoneWire || block instanceof BlockDaylightDetector || block instanceof BlockBasePressurePlate) && face != EnumFacing.DOWN) {
return false;
}
if (block instanceof BlockLever && face != state.getValue(BlockLever.FACING).getFacing().getOpposite()) {
return false;
}
if (block instanceof BlockButton && face != state.getValue(BlockButton.FACING).getOpposite()) {
return false;
}
IMultipartContainer container = MultipartHelper.getPartContainer(world, pos);
if (container != null) {
return MultipartRedstoneHelper.canConnectRedstone(container, side, face);
} else {
return block.canConnectRedstone(world, pos, side);
}
}
use of mcmultipart.multipart.IMultipartContainer in project Charset by CharsetMC.
the class PacketPart method readData.
@Override
public void readData(ByteBuf buf) {
int dim = buf.readInt();
int x = buf.readInt();
int y = buf.readUnsignedShort();
int z = buf.readInt();
long l1 = buf.readLong();
long l2 = buf.readLong();
UUID id = new UUID(l1, l2);
World w = ModCharsetLib.proxy.getLocalWorld(dim);
if (w != null) {
IMultipartContainer container = MultipartHelper.getPartContainer(w, new BlockPos(x, y, z));
if (container != null) {
part = container.getPartFromID(id);
}
}
}
use of mcmultipart.multipart.IMultipartContainer in project Charset by CharsetMC.
the class PartGate method updateInputs.
private boolean updateInputs() {
byte[] oldOutput = new byte[4];
boolean changed = false;
for (int i = 0; i <= 3; i++) {
Connection conn = getType(side);
if (conn.isOutput() && conn.isRedstone()) {
oldOutput[i] = getOutputOutside(side);
}
}
for (int i = 0; i <= 3; i++) {
EnumFacing side = EnumFacing.getFront(i + 2);
Connection conn = getType(side);
if (conn.isInput() && conn.isRedstone()) {
byte oi = inputs[i];
inputs[i] = 0;
EnumFacing real = gateToReal(side);
World w = getWorld();
BlockPos p = getPos().offset(real);
IMultipartContainer container = MultipartHelper.getPartContainer(w, p);
if (container != null) {
inputs[i] = (byte) MultipartRedstoneHelper.getWeakSignal(container, real.getOpposite(), this.side);
} else {
TileEntity tile = w.getTileEntity(p);
if (tile != null && tile.hasCapability(Capabilities.REDSTONE_EMITTER, real.getOpposite())) {
inputs[i] = (byte) tile.getCapability(Capabilities.REDSTONE_EMITTER, real.getOpposite()).getRedstoneSignal();
} else {
IBlockState s = w.getBlockState(p);
if (RedstoneUtils.canConnectFace(w, p, s, real, this.side)) {
if (s.getBlock() instanceof BlockRedstoneWire) {
inputs[i] = s.getValue(BlockRedstoneWire.POWER).byteValue();
} else {
inputs[i] = (byte) s.getBlock().getWeakPower(w, p, s, real);
}
}
}
}
if (conn.isDigital()) {
inputs[i] = inputs[i] != 0 ? (byte) 15 : 0;
}
if (inputs[i] != oi) {
changed = true;
}
}
}
if (!changed) {
for (int i = 0; i <= 3; i++) {
Connection conn = getType(side);
if (conn.isOutput() && conn.isRedstone()) {
if (getOutputOutside(side) != oldOutput[i]) {
changed = true;
break;
}
}
}
}
return changed;
}
use of mcmultipart.multipart.IMultipartContainer in project Charset by CharsetMC.
the class MultipartUtils method getInterface.
public static <T> T getInterface(Class<T> clazz, World world, BlockPos pos, EnumFacing side) {
IMultipartContainer container = MultipartHelper.getPartContainer(world, pos);
if (container == null) {
TileEntity tile = world.getTileEntity(pos);
return tile != null && clazz.isAssignableFrom(tile.getClass()) ? (T) tile : null;
} else {
if (side == null) {
return getInterfaceCenter(clazz, container);
}
EnumFacing[] var2 = EnumFacing.VALUES;
int var3 = var2.length;
for (int var4 = 0; var4 < var3; ++var4) {
EnumFacing face = var2[var4];
if (face != side && face != side.getOpposite()) {
T tmp = getInterface(clazz, container, side, face);
if (tmp != null) {
return tmp;
}
}
}
return null;
}
}
Aggregations