Search in sources :

Example 1 with LinkBehaviour

use of com.simibubi.create.foundation.tileEntity.behaviour.linked.LinkBehaviour in project Create by Creators-of-Create.

the class RedstoneLinkNetworkHandler method updateNetworkOf.

public void updateNetworkOf(LevelAccessor world, IRedstoneLinkable actor) {
    Set<IRedstoneLinkable> network = getNetworkOf(world, actor);
    int power = 0;
    for (Iterator<IRedstoneLinkable> iterator = network.iterator(); iterator.hasNext(); ) {
        IRedstoneLinkable other = iterator.next();
        if (!other.isAlive()) {
            iterator.remove();
            continue;
        }
        if (!world.isAreaLoaded(other.getLocation(), 0)) {
            iterator.remove();
            continue;
        }
        if (!withinRange(actor, other))
            continue;
        if (power < 15)
            power = Math.max(other.getTransmittedStrength(), power);
    }
    if (actor instanceof LinkBehaviour) {
        LinkBehaviour linkBehaviour = (LinkBehaviour) actor;
        // fix one-to-one loading order problem
        if (linkBehaviour.isListening()) {
            linkBehaviour.newPosition = true;
            linkBehaviour.setReceivedStrength(power);
        }
    }
    for (IRedstoneLinkable other : network) {
        if (other != actor && other.isListening() && withinRange(actor, other))
            other.setReceivedStrength(power);
    }
}
Also used : LinkBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.linked.LinkBehaviour)

Example 2 with LinkBehaviour

use of com.simibubi.create.foundation.tileEntity.behaviour.linked.LinkBehaviour in project Create by Creators-of-Create.

the class LinkedControllerBindPacket method handleItem.

@Override
protected void handleItem(ServerPlayer player, ItemStack heldItem) {
    if (player.isSpectator())
        return;
    ItemStackHandler frequencyItems = LinkedControllerItem.getFrequencyItems(heldItem);
    LinkBehaviour linkBehaviour = TileEntityBehaviour.get(player.level, linkLocation, LinkBehaviour.TYPE);
    if (linkBehaviour == null)
        return;
    Pair<Frequency, Frequency> pair = linkBehaviour.getNetworkKey();
    frequencyItems.setStackInSlot(button * 2, pair.getKey().getStack().copy());
    frequencyItems.setStackInSlot(button * 2 + 1, pair.getValue().getStack().copy());
    heldItem.getTag().put("Items", frequencyItems.serializeNBT());
}
Also used : LinkBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.linked.LinkBehaviour) ItemStackHandler(net.minecraftforge.items.ItemStackHandler) Frequency(com.simibubi.create.content.logistics.RedstoneLinkNetworkHandler.Frequency)

Example 3 with LinkBehaviour

use of com.simibubi.create.foundation.tileEntity.behaviour.linked.LinkBehaviour 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)

Example 4 with LinkBehaviour

use of com.simibubi.create.foundation.tileEntity.behaviour.linked.LinkBehaviour in project Create by Creators-of-Create.

the class LinkedControllerClientHandler method tick.

public static void tick() {
    LinkedControllerItemRenderer.tick();
    if (MODE == Mode.IDLE)
        return;
    if (packetCooldown > 0)
        packetCooldown--;
    Minecraft mc = Minecraft.getInstance();
    LocalPlayer player = mc.player;
    ItemStack heldItem = player.getMainHandItem();
    if (player.isSpectator()) {
        MODE = Mode.IDLE;
        onReset();
        return;
    }
    if (!inLectern() && !AllItems.LINKED_CONTROLLER.isIn(heldItem)) {
        heldItem = player.getOffhandItem();
        if (!AllItems.LINKED_CONTROLLER.isIn(heldItem)) {
            MODE = Mode.IDLE;
            onReset();
            return;
        }
    }
    if (inLectern() && AllBlocks.LECTERN_CONTROLLER.get().getTileEntityOptional(mc.level, lecternPos).map(te -> !te.isUsedBy(mc.player)).orElse(true)) {
        deactivateInLectern();
        return;
    }
    if (mc.screen != null) {
        MODE = Mode.IDLE;
        onReset();
        return;
    }
    if (InputConstants.isKeyDown(mc.getWindow().getWindow(), GLFW.GLFW_KEY_ESCAPE)) {
        MODE = Mode.IDLE;
        onReset();
        return;
    }
    Vector<KeyMapping> controls = getControls();
    Collection<Integer> pressedKeys = new HashSet<>();
    for (int i = 0; i < controls.size(); i++) {
        if (isActuallyPressed(controls.get(i)))
            pressedKeys.add(i);
    }
    Collection<Integer> newKeys = new HashSet<>(pressedKeys);
    Collection<Integer> releasedKeys = currentlyPressed;
    newKeys.removeAll(releasedKeys);
    releasedKeys.removeAll(pressedKeys);
    if (MODE == Mode.ACTIVE) {
        // Released Keys
        if (!releasedKeys.isEmpty()) {
            AllPackets.channel.sendToServer(new LinkedControllerInputPacket(releasedKeys, false, lecternPos));
            AllSoundEvents.CONTROLLER_CLICK.playAt(player.level, player.blockPosition(), 1f, .5f, true);
        }
        // Newly Pressed Keys
        if (!newKeys.isEmpty()) {
            AllPackets.channel.sendToServer(new LinkedControllerInputPacket(newKeys, true, lecternPos));
            packetCooldown = PACKET_RATE;
            AllSoundEvents.CONTROLLER_CLICK.playAt(player.level, player.blockPosition(), 1f, .75f, true);
        }
        // Keepalive Pressed Keys
        if (packetCooldown == 0) {
            if (!pressedKeys.isEmpty()) {
                AllPackets.channel.sendToServer(new LinkedControllerInputPacket(pressedKeys, true, lecternPos));
                packetCooldown = PACKET_RATE;
            }
        }
    }
    if (MODE == Mode.BIND) {
        VoxelShape shape = mc.level.getBlockState(selectedLocation).getShape(mc.level, selectedLocation);
        if (!shape.isEmpty())
            CreateClient.OUTLINER.showAABB("controller", shape.bounds().move(selectedLocation)).colored(0xB73C2D).lineWidth(1 / 16f);
        for (Integer integer : newKeys) {
            LinkBehaviour linkBehaviour = TileEntityBehaviour.get(mc.level, selectedLocation, LinkBehaviour.TYPE);
            if (linkBehaviour != null) {
                AllPackets.channel.sendToServer(new LinkedControllerBindPacket(integer, selectedLocation));
                Lang.sendStatus(mc.player, "linked_controller.key_bound", controls.get(integer).getTranslatedKeyMessage().getString());
            }
            MODE = Mode.IDLE;
            break;
        }
    }
    currentlyPressed = pressedKeys;
    controls.forEach(kb -> kb.setDown(false));
}
Also used : LocalPlayer(net.minecraft.client.player.LocalPlayer) Minecraft(net.minecraft.client.Minecraft) LinkBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.linked.LinkBehaviour) VoxelShape(net.minecraft.world.phys.shapes.VoxelShape) KeyMapping(net.minecraft.client.KeyMapping) ItemStack(net.minecraft.world.item.ItemStack) HashSet(java.util.HashSet)

Example 5 with LinkBehaviour

use of com.simibubi.create.foundation.tileEntity.behaviour.linked.LinkBehaviour in project Create by Creators-of-Create.

the class RedstoneLinkTileEntity method tick.

@Override
public void tick() {
    super.tick();
    if (isTransmitterBlock() != transmitter) {
        transmitter = isTransmitterBlock();
        LinkBehaviour prevlink = link;
        removeBehaviour(LinkBehaviour.TYPE);
        createLink();
        link.copyItemsFrom(prevlink);
        attachBehaviourLate(link);
    }
    if (transmitter)
        return;
    if (level.isClientSide)
        return;
    BlockState blockState = getBlockState();
    if (!AllBlocks.REDSTONE_LINK.has(blockState))
        return;
    if ((getReceivedSignal() > 0) != blockState.getValue(RedstoneLinkBlock.POWERED)) {
        receivedSignalChanged = true;
        level.setBlockAndUpdate(worldPosition, blockState.cycle(RedstoneLinkBlock.POWERED));
    }
    if (receivedSignalChanged) {
        Direction attachedFace = blockState.getValue(RedstoneLinkBlock.FACING).getOpposite();
        BlockPos attachedPos = worldPosition.relative(attachedFace);
        level.blockUpdated(worldPosition, level.getBlockState(worldPosition).getBlock());
        level.blockUpdated(attachedPos, level.getBlockState(attachedPos).getBlock());
        receivedSignalChanged = false;
    }
}
Also used : LinkBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.linked.LinkBehaviour) BlockState(net.minecraft.world.level.block.state.BlockState) BlockPos(net.minecraft.core.BlockPos) Direction(net.minecraft.core.Direction)

Aggregations

LinkBehaviour (com.simibubi.create.foundation.tileEntity.behaviour.linked.LinkBehaviour)5 AirshipContraptionEntity (com.eriksonn.createaeronautics.contraptions.AirshipContraptionEntity)1 IRedstoneLinkable (com.simibubi.create.content.logistics.IRedstoneLinkable)1 Frequency (com.simibubi.create.content.logistics.RedstoneLinkNetworkHandler.Frequency)1 HashSet (java.util.HashSet)1 KeyMapping (net.minecraft.client.KeyMapping)1 Minecraft (net.minecraft.client.Minecraft)1 LocalPlayer (net.minecraft.client.player.LocalPlayer)1 BlockPos (net.minecraft.core.BlockPos)1 Direction (net.minecraft.core.Direction)1 BlockPos (net.minecraft.util.math.BlockPos)1 ItemStack (net.minecraft.world.item.ItemStack)1 BlockState (net.minecraft.world.level.block.state.BlockState)1 VoxelShape (net.minecraft.world.phys.shapes.VoxelShape)1 ServerWorld (net.minecraft.world.server.ServerWorld)1 ItemStackHandler (net.minecraftforge.items.ItemStackHandler)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1