Skip to content

Commit

Permalink
20230426a
Browse files Browse the repository at this point in the history
  • Loading branch information
mrh0 committed Apr 26, 2023
1 parent 057f898 commit 42a6a55
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 50 deletions.
4 changes: 4 additions & 0 deletions COMPUTERCRAFT.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,8 @@ da.print("Text on first line again")
```
The function `getMaxLines()` will return the max number of lines that can be displayable using the Digital Adapter (will always return 16).

### Other

The function `getDurationDistance(blocks, rpm)` will return the time needed to push a Mechanical Piston, Pulley or Gantry a number of blocks at the given rpm.

The function `getDurationAngle(degrees, rpm)` will return the time needed to rotate a Mechanical Bearing by a number of degrees at the given rpm.
Original file line number Diff line number Diff line change
Expand Up @@ -231,49 +231,9 @@ public void tick() {
updateGeneratedRotation();
}
}

/*if (world.isRemote)
return;
if (currentInstructionDuration < 0)
return;
if (timer < currentInstructionDuration) {
timer++;
return;
}*/

//currentTarget = -1;
//currentInstruct = Instruct.NONE;
//currentInstructionDuration = -1;
//timer = 0;
}

/*@Override
public void onSpeedChanged(float previousSpeed) {
super.onSpeedChanged(previousSpeed);
if (currentInstruct == Instruct.NONE)
return;
float currentSpeed = Math.abs(speed);
if (Math.abs(previousSpeed) == currentSpeed)
return;
float initialProgress = timer / (float) currentInstructionDuration;
if(currentInstruct == Instruct.ANGLE)
currentInstructionDuration = getDurationAngle(currentTarget, initialProgress, generatedSpeed.getValue());
timer = 0;
}*/

/*public float runAngle(int angle, int speed) {
generatedSpeed.setValue(angle < 0 ? -speed : speed);
currentInstructionDuration = getDurationAngle(Math.abs(angle), 0, speed);
//currentTarget = angle;
//timer = 0;
return (float)currentInstructionDuration / 20f;
}*/



public int getDurationAngle(int deg, float initialProgress, float speed) {
public static int getDurationAngle(int deg, float initialProgress, float speed) {
speed = Math.abs(speed);
deg = Math.abs(deg);
if(speed < 0.1f)
Expand All @@ -282,7 +242,7 @@ public int getDurationAngle(int deg, float initialProgress, float speed) {
return (int) ((1 - initialProgress) * deg / degreesPerTick + 1);
}

public int getDurationDistance(int dis, float initialProgress, float speed) {
public static int getDurationDistance(int dis, float initialProgress, float speed) {
speed = Math.abs(speed);
dis = Math.abs(dis);
if(speed < 0.1f)
Expand All @@ -292,7 +252,6 @@ public int getDurationDistance(int dis, float initialProgress, float speed) {
}

public boolean setRPM(int rpm) {
//System.out.println("SETSPEED" + rpm);
rpm = Math.max(Math.min(rpm, RPM_RANGE), -RPM_RANGE);
cc_new_rpm = rpm;
cc_update_rpm = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package com.mrh0.createaddition.compat.computercraft;

import com.mrh0.createaddition.blocks.digital_adapter.DigitalAdapterTileEntity;
import com.mrh0.createaddition.blocks.electric_motor.ElectricMotorTileEntity;
import com.simibubi.create.foundation.config.AllConfigs;
import com.simibubi.create.foundation.config.CServer;
import dan200.computercraft.api.lua.LuaException;
import dan200.computercraft.api.lua.LuaFunction;
import dan200.computercraft.api.peripheral.IPeripheral;
import net.minecraft.core.Direction;
import net.minecraft.network.chat.TextComponent;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Optional;

public class DigitalAdapterPeripheral implements IPeripheral {
private final String type;
private final DigitalAdapterTileEntity tileEntity;
Expand Down Expand Up @@ -50,14 +54,16 @@ public final void clear() {

@LuaFunction(mainThread = true)
public final void print(String text) {
this.tileEntity.setTextLine(this.tileEntity.getLine(), new TextComponent(text.substring(0, 128)));
this.tileEntity.setTextLine(this.tileEntity.getLine(), new TextComponent(text.substring(0, Math.min(text.length(), 128))));
this.tileEntity.incrementLine();
}

//@LuaFunction(mainThread = true)
//public final void write(String text) {
// this.tileEntity.append(this.tileEntity.getLine(), new TextComponent(text));
//}
/*
@LuaFunction(mainThread = true)
public final void write(String text) {
this.tileEntity.append(this.tileEntity.getLine(), new TextComponent(text));
}
*/

@LuaFunction(mainThread = true)
public final int getLine() {
Expand Down Expand Up @@ -162,4 +168,14 @@ public final int getBearingAngle(String direction) {
if(mp == null) return 0;
return (int) mp.getInterpolatedAngle(.5f);
}

@LuaFunction(mainThread = true)
public final float getDurationAngle(int deg, int rpm) throws LuaException {
return ElectricMotorTileEntity.getDurationAngle(deg, 0, rpm) / 20f;
}

@LuaFunction(mainThread = true)
public final float getDurationDistance(int blocks, int rpm) throws LuaException {
return ElectricMotorTileEntity.getDurationDistance(blocks, 0, rpm) / 20f;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public final float rotate(int deg, Optional<Integer> rpm) throws LuaException {
int _rpm = rpm.orElse(getSpeed());
if(rpm.isPresent())
setSpeed(deg < 0 ? -_rpm : _rpm);
return tileEntity.getDurationAngle(deg, 0, _rpm) / 20f;
return ElectricMotorTileEntity.getDurationAngle(deg, 0, _rpm) / 20f;
}
return 0f;
}
Expand All @@ -104,7 +104,7 @@ public final float translate(int blocks, Optional<Integer> rpm) throws LuaExcept
int _rpm = rpm.orElse(getSpeed());
if(rpm.isPresent())
setSpeed(blocks < 0 ? -_rpm : _rpm);
return tileEntity.getDurationDistance(blocks, 0, _rpm) / 20f;
return ElectricMotorTileEntity.getDurationDistance(blocks, 0, _rpm) / 20f;
}
return 0f;
}
Expand Down

0 comments on commit 42a6a55

Please sign in to comment.