Search in sources :

Example 1 with IRedstoneLinkable

use of com.simibubi.create.content.logistics.IRedstoneLinkable in project Create_Aeronautics by Eriksonnaren.

the class RedstoneLinkNetworkMixin method updateNetworkOf.

@Inject(method = "updateNetworkOf", remap = false, at = @At("HEAD"))
public void updateNetworkOf(IWorld world, IRedstoneLinkable inRealWorldActor, CallbackInfo ci) {
    // airship dimension trickery
    ServerWorld airshipDimension = AirshipDimensionManager.INSTANCE.getWorld();
    if (world != airshipDimension) {
        // iterate over all airships in the world
        for (AirshipContraptionEntity airship : AirshipManager.INSTANCE.AllAirships.values()) {
            // plotpos
            BlockPos plotPos = airship.getPlotPos();
            // get network
            Set<IRedstoneLinkable> airshipNetwork = Create.REDSTONE_LINK_NETWORK_HANDLER.getNetworkOf(airshipDimension, inRealWorldActor);
            Set<IRedstoneLinkable> realWorldNetwork = Create.REDSTONE_LINK_NETWORK_HANDLER.getNetworkOf(world, inRealWorldActor);
            int power = 0;
            for (Iterator<IRedstoneLinkable> iterator = airshipNetwork.iterator(); iterator.hasNext(); ) {
                IRedstoneLinkable inAirshipDimensionActor = iterator.next();
                if (!inAirshipDimensionActor.isAlive()) {
                    iterator.remove();
                    continue;
                }
                if (!withinRange(inRealWorldActor, airship, plotPos, inAirshipDimensionActor)) {
                    iterator.remove();
                    continue;
                }
                if (power < 15)
                    power = Math.max(inAirshipDimensionActor.getTransmittedStrength(), power);
                for (Iterator<IRedstoneLinkable> iterator1 = realWorldNetwork.iterator(); iterator1.hasNext(); ) {
                    IRedstoneLinkable inRealWorldActor2 = iterator1.next();
                    if (!inRealWorldActor2.isAlive()) {
                        iterator1.remove();
                        continue;
                    }
                    if (!withinRange(inRealWorldActor2, airship, plotPos, inAirshipDimensionActor)) {
                        iterator1.remove();
                        continue;
                    }
                    if (power < 15)
                        power = Math.max(inRealWorldActor2.getTransmittedStrength(), power);
                }
            }
            if (inRealWorldActor instanceof LinkBehaviour) {
                LinkBehaviour linkBehaviour = (LinkBehaviour) inRealWorldActor;
                // fix one-to-one loading order problem
                if (linkBehaviour.isListening()) {
                    linkBehaviour.newPosition = true;
                    linkBehaviour.setReceivedStrength(power);
                }
            }
            for (IRedstoneLinkable other : airshipNetwork) {
                if (other != inRealWorldActor && other.isListening() && withinRange(inRealWorldActor, airship, plotPos, other))
                    other.setReceivedStrength(power);
            }
        }
    }
}
Also used : ServerWorld(net.minecraft.world.server.ServerWorld) LinkBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.linked.LinkBehaviour) AirshipContraptionEntity(com.eriksonn.createaeronautics.contraptions.AirshipContraptionEntity) BlockPos(net.minecraft.util.math.BlockPos) IRedstoneLinkable(com.simibubi.create.content.logistics.IRedstoneLinkable) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

AirshipContraptionEntity (com.eriksonn.createaeronautics.contraptions.AirshipContraptionEntity)1 IRedstoneLinkable (com.simibubi.create.content.logistics.IRedstoneLinkable)1 LinkBehaviour (com.simibubi.create.foundation.tileEntity.behaviour.linked.LinkBehaviour)1 BlockPos (net.minecraft.util.math.BlockPos)1 ServerWorld (net.minecraft.world.server.ServerWorld)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1