Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ComputerCraft integrations to more devices #6849

Open
wants to merge 7 commits into
base: mc1.18/dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add ComputerCraft integration to Creative Motors
- Add CC {get,set}GeneratedSpeed() function get/set motor speed
  • Loading branch information
ElementW committed Sep 5, 2024
commit abffebd30e01ab03994592af3d65fb8f13f7ddd2
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import com.simibubi.create.compat.computercraft.AbstractComputerBehaviour;
import com.simibubi.create.compat.computercraft.events.ComputerEvent;
import com.simibubi.create.compat.computercraft.implementation.peripherals.CreativeMotorPeripheral;
import com.simibubi.create.compat.computercraft.implementation.peripherals.DisplayLinkPeripheral;
import com.simibubi.create.compat.computercraft.implementation.peripherals.NixieTubePeripheral;
import com.simibubi.create.compat.computercraft.implementation.peripherals.SequencedGearshiftPeripheral;
Expand All @@ -17,6 +18,7 @@
import com.simibubi.create.compat.computercraft.implementation.peripherals.TrackObserverPeripheral;
import com.simibubi.create.content.kinetics.gauge.SpeedGaugeBlockEntity;
import com.simibubi.create.content.kinetics.gauge.StressGaugeBlockEntity;
import com.simibubi.create.content.kinetics.motor.CreativeMotorBlockEntity;
import com.simibubi.create.content.kinetics.speedController.SpeedControllerBlockEntity;
import com.simibubi.create.content.kinetics.transmission.sequencer.SequencedGearshiftBlockEntity;
import com.simibubi.create.content.redstone.displayLink.DisplayLinkBlockEntity;
Expand Down Expand Up @@ -49,6 +51,8 @@ public ComputerBehaviour(SmartBlockEntity te) {
public static NonNullSupplier<SyncedPeripheral<?>> getPeripheralFor(SmartBlockEntity be) {
if (be instanceof SpeedControllerBlockEntity scbe)
return () -> new SpeedControllerPeripheral(scbe, scbe.targetSpeed);
if (be instanceof CreativeMotorBlockEntity cmbe)
return () -> new CreativeMotorPeripheral(cmbe, cmbe.generatedSpeed);
if (be instanceof DisplayLinkBlockEntity dlbe)
return () -> new DisplayLinkPeripheral(dlbe);
if (be instanceof NixieTubeBlockEntity ntbe)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.simibubi.create.compat.computercraft.implementation.peripherals;

import org.jetbrains.annotations.NotNull;

import com.simibubi.create.content.kinetics.motor.CreativeMotorBlockEntity;
import com.simibubi.create.foundation.blockEntity.behaviour.scrollValue.ScrollValueBehaviour;

import dan200.computercraft.api.lua.LuaFunction;

public class CreativeMotorPeripheral extends SyncedPeripheral<CreativeMotorBlockEntity> {

private final ScrollValueBehaviour generatedSpeed;

public CreativeMotorPeripheral(CreativeMotorBlockEntity blockEntity, ScrollValueBehaviour generatedSpeed) {
super(blockEntity);
this.generatedSpeed = generatedSpeed;
}

@LuaFunction(mainThread = true)
public final void setGeneratedSpeed(int speed) {
this.generatedSpeed.setValue(speed);
}

@LuaFunction
public final float getGeneratedSpeed() {
return this.generatedSpeed.getValue();
}

@NotNull
@Override
public String getType() {
return "Create_CreativeMotor";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@

import java.util.List;

import org.jetbrains.annotations.NotNull;


import com.jozufozu.flywheel.util.transform.TransformStack;
import com.mojang.blaze3d.vertex.PoseStack;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.compat.computercraft.AbstractComputerBehaviour;
import com.simibubi.create.compat.computercraft.ComputerCraftProxy;
import com.simibubi.create.content.kinetics.base.GeneratingKineticBlockEntity;
import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour;
import com.simibubi.create.foundation.blockEntity.behaviour.ValueBoxTransform;
Expand All @@ -19,13 +24,16 @@
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.LazyOptional;

public class CreativeMotorBlockEntity extends GeneratingKineticBlockEntity {

public static final int DEFAULT_SPEED = 16;
public static final int MAX_SPEED = 256;

protected ScrollValueBehaviour generatedSpeed;
public ScrollValueBehaviour generatedSpeed;
public AbstractComputerBehaviour computerBehaviour;

public CreativeMotorBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
super(type, pos, state);
Expand All @@ -41,6 +49,7 @@ public void addBehaviours(List<BlockEntityBehaviour> behaviours) {
generatedSpeed.value = DEFAULT_SPEED;
generatedSpeed.withCallback(i -> this.updateGeneratedRotation());
behaviours.add(generatedSpeed);
behaviours.add(computerBehaviour = ComputerCraftProxy.behaviour(this));
}

@Override
Expand Down Expand Up @@ -93,4 +102,17 @@ protected boolean isSideActive(BlockState state, Direction direction) {

}

@Override
public <T> @NotNull LazyOptional<T> getCapability(@NotNull Capability<T> cap, Direction side) {
if (computerBehaviour.isPeripheralCap(cap))
return computerBehaviour.getPeripheralCapability();
return super.getCapability(cap, side);
}

@Override
public void invalidateCaps() {
super.invalidateCaps();
computerBehaviour.removePeripheral();
}

}