Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions src/main/resources/plugin.yml → plugin.yml
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: BasicCircuits
main: org.redstonechips.basiccircuits.BasicCircuits
version: 0.97
api-version: 1.15
author: eisental
description: Basic circuit library for RedstoneChips integrated circuits plugin.
website: eisental.github.com/RedstoneChips
Expand Down
9 changes: 8 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,17 @@
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.15.2-R0.1-SNAPSHOT</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.redstonechips</groupId>
<artifactId>RedstoneChips</artifactId>
<version>1.0-SNAPSHOT</version>
<version>1.1-SNAPSHOT</version>
</dependency>
</dependencies>
<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public Class[] getCircuitClasses() {
multiplexer.class, multiplier.class, or.class, pisoregister.class, print.class, random.class, receiver.class,
shiftregister.class, transmitter.class, xor.class, decoder.class, encoder.class, pixel.class, pulse.class, not.class,
synth.class, srnor.class, terminal.class, router.class, ringcounter.class, iptransmitter.class, ipreceiver.class,
comparator.class, delay.class, repeater.class, nand.class, nor.class, xnor.class, segdriver.class, dregister.class,
comparator.class, delay.class, repeater.class, nand.class, nor.class, xnor.class, segdriver.class, dregister.class,
sram.class, bintobcd.class, display.class, burst.class, ramwatch.class };
}

Expand Down
57 changes: 29 additions & 28 deletions src/main/java/org/redstonechips/basiccircuits/SignWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.ArrayList;
import java.util.List;

import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
Expand All @@ -24,48 +25,48 @@ public enum DisplayMode {
}

public static final int LineWidth = 15;

private final Type type;
private final DisplayMode display;

private final StringBuffer textBuffer = new StringBuffer();

private String[] lines = new String[] { "", "", "", "" };
private int scrollPos = 0;
private final List<Location> signList;

public SignWriter(DisplayMode displayMode, Type type, List<Location> signList) {
this.type = type;
this.display = displayMode;
this.signList = signList;
}

public DisplayMode getDisplayMode() {
return display;
}

public String[] getLines() { return lines; }
public void setLines(String[] lines) {

public void setLines(String[] lines) {
this.lines = lines;
}

public String getText() {
return textBuffer.toString();
}

public void setText(String text) {
textBuffer.setLength(0);
textBuffer.append(text.toString());

if (display==DisplayMode.scroll)
prepScrollLines();
else prepWrapLines();
updateSigns();
}

List<Location> getSigns() { return signList; }

public void write(String text) {
if (display==DisplayMode.add) {
add(text);
Expand All @@ -79,22 +80,22 @@ public void write(String text) {
add(text);
prepScrollLines();
}

updateSigns();
}

public void write(boolean[] bits, int start, int length) {
write(convertBits(bits, start, length));
}

public void clear() {
textBuffer.setLength(0);
scrollPos = 0;
lines[0] = "";
lines[1] = "";
lines[2] = "";
lines[3] = "";
updateSigns();
updateSigns();
}

public void scroll(int amount) {
Expand All @@ -105,9 +106,9 @@ public void scroll(int amount) {

prepScrollLines();

updateSigns();
updateSigns();
}

private void add(String text) {
if (type==Type.ascii || textBuffer.length()==0) {
textBuffer.append(text);
Expand All @@ -123,9 +124,9 @@ private void updateSigns() {
s.setLine(2, lines[2]);
s.setLine(3, lines[3]);
s.update();
}
}
}

private void prepScrollLines() {
String window;

Expand All @@ -142,7 +143,7 @@ private void prepScrollLines() {
lines[2] = "";
lines[3] = "";
}

private void prepWrapLines() {
if (textBuffer.length()>LineWidth*3) {
String line4 = textBuffer.substring(LineWidth*3);
Expand All @@ -160,7 +161,7 @@ private void prepWrapLines() {
} else if (textBuffer.length()>LineWidth) {
lines[0] = textBuffer.substring(0,LineWidth);
lines[1] = textBuffer.substring(LineWidth);
lines[2] = "";
lines[2] = "";
lines[3] = "";
} else {
lines[0] = textBuffer.toString();
Expand All @@ -169,7 +170,7 @@ private void prepWrapLines() {
lines[3] = "";
}
}

private String convertBits(boolean[] bits, int start, int length) {
String text = null;

Expand All @@ -191,7 +192,7 @@ private String convertBits(boolean[] bits, int start, int length) {

return text;
}

public static SignWriter getSignWriter(DisplayMode mode, Type type, Location... aroundBlocks) {
List<Location> signs = new ArrayList<>();

Expand All @@ -209,10 +210,10 @@ public static SignWriter getSignWriter(DisplayMode mode, Type type, Location...
if (checkBlock(i, east)) { signs.add(east); }
if (checkBlock(i, up)) { signs.add(up); }
}
return new SignWriter(mode, type, signs);

return new SignWriter(mode, type, signs);
}

private static boolean checkBlock(Block i, Location s) {
// TODO: Check whether this method loads the chunk or not.
Block sign = s.getBlock();
Expand All @@ -223,5 +224,5 @@ private static boolean checkBlock(Block i, Location s) {

} else return false;
}

}
16 changes: 8 additions & 8 deletions src/main/java/org/redstonechips/basiccircuits/adder.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected void bitSetChanged(int bitSetIdx, boolean[] set) {
if (constant != 0) {
output = BooleanArrays.add(output, constant, outputlen);
}

// write result
this.writeBits(output);
}
Expand All @@ -53,13 +53,13 @@ public Circuit init(String[] args) {
}

if ((inputlen % wordlength)==0) {
int inBitSetCount = inputlen / wordlength;
inputBitSets = new boolean[inBitSetCount][wordlength];
int inBitSetCount = inputlen / wordlength;
inputBitSets = new boolean[inBitSetCount][wordlength];
} else return error("Invalid number of inputs (" + inputlen + "). Number of inputs must be a multiple of the word length.");

if (args[args.length-1].equalsIgnoreCase("subtract"))
subtract = true;

if ((args.length>1 && !subtract) || (args.length>2)) {
try {
constant = Integer.decode(args[1]);
Expand All @@ -68,14 +68,14 @@ public Circuit init(String[] args) {
return error("Bad constant argument: " + args[1] + " expecting a number.");
}
}

int maxResult = ((int)Math.pow(2, wordlength)-1) * inputBitSets.length + constant;
int expectedOutputs = (int)Math.ceil(Math.log(maxResult)/Math.log(2));

if (outputlen<expectedOutputs)
if (outputlen<expectedOutputs)
info(ChatColor.LIGHT_PURPLE + "Warning: Output might overflow. Circuit should have " + expectedOutputs + " output bits.");
info("Activating adder with " + inputBitSets.length + " input set(s) of " + wordlength +

info("Activating adder with " + inputBitSets.length + " input set(s) of " + wordlength +
" bits each. The chip is running in " + (subtract?"subtract":"add") + " mode" + (constant!=0? ", with a constant value of " + constant:"") + ".");
return this;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/redstonechips/basiccircuits/and.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ protected void bitSetChanged(int bitSetIdx, boolean[] set) {
for (int i=1; i<this.inputBitSets.length; i++) {
BooleanArrays.and(buf, buf, inputBitSets[i]);
}

this.writeBits(buf);
}
}
7 changes: 2 additions & 5 deletions src/main/java/org/redstonechips/basiccircuits/bintobcd.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,16 @@ public class bintobcd extends Circuit {
@Override
public void input(boolean state, int inIdx) {
String value;

value = Long.toString(BooleanArrays.toUnsignedInt(inputs, 0, inputlen));

for (int i=0; i<digits; i++) {
String d;
int digit;

if (i<value.length()) {
d = Character.toString(value.charAt(value.length()-i-1));
digit = Integer.decode(d);
} else
} else {
digit = 0;

}
this.writeInt(digit, i*4, 4);
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/org/redstonechips/basiccircuits/burst.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

package org.redstonechips.basiccircuits;

import org.redstonechips.parsing.UnitParser;
import org.redstonechips.circuit.Circuit;
import org.redstonechips.parsing.UnitParser;
import org.redstonechips.util.BooleanArrays;

/**
Expand Down Expand Up @@ -65,7 +65,7 @@ public Circuit init(String[] args) {
} catch (NumberFormatException ne) {
return error("Bad pulse count argument: " + args[0]);
}

try {
frequency = Math.round(UnitParser.parse(args[1]));
} catch (IllegalArgumentException e) {
Expand All @@ -78,7 +78,7 @@ public Circuit init(String[] args) {
if (inputlen==0) return error("Expecting at least 1 input pin.");

if (activator!=null) clearOutputs();

burstTask = new BurstTask();
return this;
}
Expand All @@ -87,7 +87,7 @@ public Circuit init(String[] args) {
public boolean isStateless() {
return false;
}

private void startBurst() {
if (bursting) return;

Expand All @@ -101,7 +101,7 @@ private void startBurst() {
bursting = false;
}
}

private void stopBurst() {
if (!bursting) return;

Expand All @@ -110,18 +110,18 @@ private void stopBurst() {
rc.getServer().getScheduler().cancelTask(taskId);
bursting = false;
}

@Override
public void disable() {
stopBurst();
}

@Override
public void shutdown() {
stopBurst();
}
private class BurstTask implements Runnable {

private class BurstTask implements Runnable {
@Override
public void run() {
if (!bursting) return;
Expand Down
Loading