use of pl.asie.charset.api.wires.IRedstoneReceiver in project Charset by CharsetMC.
the class Capabilities method init.
public static void init() {
CapabilityManager.INSTANCE.register(IBundledEmitter.class, new DefaultBundledEmitterStorage(), DefaultBundledEmitter.class);
CapabilityManager.INSTANCE.register(IRedstoneEmitter.class, new DefaultRedstoneEmitterStorage(), DefaultRedstoneEmitter.class);
CapabilityManager.INSTANCE.register(IBundledReceiver.class, new Capability.IStorage<IBundledReceiver>() {
@Override
public NBTBase writeNBT(Capability<IBundledReceiver> capability, IBundledReceiver instance, EnumFacing side) {
return null;
}
@Override
public void readNBT(Capability<IBundledReceiver> capability, IBundledReceiver instance, EnumFacing side, NBTBase nbt) {
}
}, DummyRedstoneReceiver.class);
CapabilityManager.INSTANCE.register(IRedstoneReceiver.class, new Capability.IStorage<IRedstoneReceiver>() {
@Override
public NBTBase writeNBT(Capability<IRedstoneReceiver> capability, IRedstoneReceiver instance, EnumFacing side) {
return null;
}
@Override
public void readNBT(Capability<IRedstoneReceiver> capability, IRedstoneReceiver instance, EnumFacing side, NBTBase nbt) {
}
}, DummyRedstoneReceiver.class);
if (Loader.isModLoaded("mcmultipart")) {
initMultiplePants();
}
}
use of pl.asie.charset.api.wires.IRedstoneReceiver in project Charset by CharsetMC.
the class PartWireNormal method propagate.
@Override
public void propagate(int color) {
if (DEBUG) {
System.out.println("--- PROPAGATE " + getPos().toString() + " " + location.name() + " (" + getWorld().getTotalWorldTime() + ") ---");
}
int maxSignal = 0;
int oldSignal = signalLevel;
int[] neighborLevel = new int[7];
boolean[] isWire = new boolean[7];
boolean hasRedstoneWire = false;
PartWireBase.PROPAGATING = true;
if (type == WireKind.NORMAL) {
if (location != WireFace.CENTER) {
EnumFacing facing = location.facing;
BlockPos pos = getPos().offset(facing);
IBlockState state = getWorld().getBlockState(pos);
int power = WireUtils.getRedstoneLevel(getWorld(), pos, state, facing, location, false);
if (power > 0) {
neighborLevel[facing.ordinal()] = Math.min(15, power) << 8 | 0xFF;
}
}
}
if (internalConnections > 0) {
for (WireFace location : WireFace.VALUES) {
if (connectsInternal(location)) {
isWire[location.ordinal()] = true;
neighborLevel[location.ordinal()] = getRedstoneLevel(getContainer(), location);
}
}
}
for (EnumFacing facing : EnumFacing.VALUES) {
int facidx = facing.ordinal();
if (facing == location.facing && type == WireKind.NORMAL) {
BlockPos pos = getPos().offset(facing);
int i = 0;
for (EnumFacing enumfacing : EnumFacing.values()) {
if (enumfacing == facing.getOpposite()) {
continue;
}
IBlockState state = getWorld().getBlockState(pos.offset(enumfacing));
Block block = state.getBlock();
if (!(block instanceof BlockRedstoneWire)) {
int power = WireUtils.getRedstoneLevel(getWorld(), pos.offset(enumfacing), state, enumfacing, location, true);
if (power >= 15) {
i = 15;
break;
}
if (power > i) {
i = power;
}
}
}
if (i > 0) {
neighborLevel[facidx] = (i << 8) | 0xFF;
}
} else if (connectsExternal(facing)) {
BlockPos pos = getPos().offset(facing);
IMultipartContainer container = MultipartHelper.getPartContainer(getWorld(), pos);
if (WireUtils.getWire(container, location) != null) {
isWire[facidx] = true;
neighborLevel[facidx] = getRedstoneLevel(container, location);
} else {
IBlockState state = getWorld().getBlockState(pos);
int power = WireUtils.getRedstoneLevel(getWorld(), pos, state, facing, location, true);
if (state.getBlock() instanceof BlockRedstoneWire) {
isWire[facidx] = true;
hasRedstoneWire = true;
power--;
}
if (power > 0) {
neighborLevel[facidx] = (Math.min(power, 15) << 8) | 0xFF;
}
}
} else if (connectsCorner(facing)) {
IMultipartContainer container = MultipartHelper.getPartContainer(getWorld(), getPos().offset(facing).offset(location.facing));
if (container != null) {
isWire[facidx] = true;
neighborLevel[facidx] = getRedstoneLevel(container, WireFace.get(facing.getOpposite()));
}
}
}
PartWireBase.PROPAGATING = false;
int maxSignalNonWire = 0;
for (int i = 0; i < 7; i++) {
if (neighborLevel[i] > maxSignal) {
maxSignal = neighborLevel[i];
}
if (!isWire[i] && neighborLevel[i] > maxSignalNonWire) {
maxSignalNonWire = neighborLevel[i];
}
}
if (DEBUG) {
System.out.println("ConnectionCache: " + Integer.toBinaryString(internalConnections) + " " + Integer.toBinaryString(externalConnections) + " " + Integer.toBinaryString(cornerConnections));
System.out.println("Levels: " + Arrays.toString(neighborLevel));
}
if (maxSignal > signalLevel) {
signalLevel = maxSignal - 1;
if ((signalLevel & 0xFF) == 0 || (signalLevel & 0xFF) == 0xFF) {
signalLevel = 0;
}
} else {
signalLevel = maxSignalNonWire;
}
if (oldSignal == signalLevel) {
return;
}
if (DEBUG) {
System.out.println("Switch: " + oldSignal + " -> " + signalLevel);
}
if (signalLevel == 0) {
for (WireFace nLoc : WireFace.VALUES) {
if (connectsInternal(nLoc)) {
if (neighborLevel[nLoc.ordinal()] > 0) {
WireUtils.getWire(getContainer(), nLoc).onSignalChanged(type.color());
}
} else if (nLoc != WireFace.CENTER) {
EnumFacing facing = nLoc.facing;
if (connectsExternal(facing)) {
IMultipartContainer container = MultipartHelper.getPartContainer(getWorld(), getPos().offset(facing));
if (container == null || WireUtils.getWire(container, location) == null || neighborLevel[facing.ordinal()] > 0) {
propagateNotify(facing, type.color());
}
} else if (connectsCorner(facing)) {
if (neighborLevel[nLoc.ordinal()] > 0) {
propagateNotifyCorner(location.facing, facing, type.color());
}
} else if (type == WireKind.NORMAL && facing.getOpposite() != location.facing) {
TileEntity nt = getWorld().getTileEntity(getPos().offset(facing));
if (!(nt instanceof IRedstoneReceiver)) {
getWorld().notifyBlockOfStateChange(getPos().offset(facing), MCMultiPartMod.multipart);
}
}
}
}
} else {
for (WireFace nLoc : WireFace.VALUES) {
if (neighborLevel[nLoc.ordinal()] < signalLevel - 1 || neighborLevel[nLoc.ordinal()] > (signalLevel + 1)) {
if (connectsInternal(nLoc)) {
WireUtils.getWire(getContainer(), nLoc).onSignalChanged(type.color());
} else if (nLoc != WireFace.CENTER) {
EnumFacing facing = nLoc.facing;
if (connectsExternal(facing)) {
propagateNotify(facing, type.color());
} else if (connectsCorner(facing)) {
propagateNotifyCorner(location.facing, facing, type.color());
} else if (type == WireKind.NORMAL && facing.getOpposite() != location.facing) {
TileEntity nt = getWorld().getTileEntity(getPos().offset(facing));
if (!(nt instanceof IRedstoneReceiver)) {
getWorld().notifyBlockOfStateChange(getPos().offset(facing), MCMultiPartMod.multipart);
}
}
}
}
}
}
if (type == WireKind.NORMAL) {
if ((oldSignal & 0xF00) != (signalLevel & 0xF00)) {
scheduleRenderUpdate();
if (location != WireFace.CENTER) {
BlockPos uPos = getPos().offset(location.facing);
getWorld().notifyNeighborsOfStateExcept(uPos, MCMultiPartMod.multipart, location.facing.getOpposite());
}
}
} else {
if ((oldSignal & 0xF00) != (signalLevel & 0xF00)) {
if (location != WireFace.CENTER) {
getWorld().notifyBlockOfStateChange(getPos().offset(location.facing), MCMultiPartMod.multipart);
}
}
}
finishPropagation();
}
Aggregations