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);
}
}
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());
}
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);
}
}
}
}
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));
}
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;
}
}
Aggregations