Skip to content

Commit e25e28d

Browse files
committed
Cleanup
1 parent 14140c1 commit e25e28d

19 files changed

Lines changed: 145 additions & 135 deletions

src/client/java/com/hanprogramer/androids/client/screen/android/AndroidInventoryHandledScreen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
8080

8181
@Override
8282
public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) {
83-
if(tabs.get(activeTab).mouseDragged(mouseX, mouseY, button, deltaX, deltaY))
83+
if (tabs.get(activeTab).mouseDragged(mouseX, mouseY, button, deltaX, deltaY))
8484
return true;
8585
return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY);
8686
}

src/client/java/com/hanprogramer/androids/client/screen/android/LogsTab.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
import org.jetbrains.annotations.Nullable;
1616
import org.lwjgl.glfw.GLFW;
1717

18-
import java.awt.*;
19-
import java.awt.datatransfer.Clipboard;
20-
import java.awt.datatransfer.StringSelection;
2118
import java.util.List;
2219

2320
public class LogsTab extends BaseScreenTab<AndroidInventoryHandledScreen> {
@@ -72,7 +69,7 @@ public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmou
7269

7370
@Override
7471
public boolean mouseClicked(double mouseX, double mouseY, int button) {
75-
if(text.getBorder(NavigationDirection.DOWN).contains((int) mouseX, (int) mouseY))
72+
if (text.getBorder(NavigationDirection.DOWN).contains((int) mouseX, (int) mouseY))
7673
return text.mouseClicked(mouseX, mouseY, button);
7774
return false;
7875
}

src/client/java/com/hanprogramer/androids/client/screen/android/SettingsTab.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import com.hanprogramer.androids.client.screen.base.BaseScreenTab;
44
import com.hanprogramer.androids.client.screen.widgets.ColoredButtonWidget;
5-
import com.hanprogramer.androids.entities.android.util.BlockArea;
65
import com.hanprogramer.androids.entities.android.scripting.AndroidProperty;
6+
import com.hanprogramer.androids.entities.android.util.BlockArea;
77
import com.hanprogramer.androids.network.AndroidC2SSetBlockAreaBeginPayload;
88
import com.hanprogramer.androids.network.AndroidC2SSetBlockPosBeginPayload;
99
import com.hanprogramer.androids.network.AndroidC2SSetPropertyPayload;
@@ -84,8 +84,8 @@ public void drawBackground(DrawContext context, float delta, int mouseX, int mou
8484
public class SettingsEntry extends ElementListWidget.Entry<SettingsEntry> {
8585
private final Text title;
8686
private final ButtonWidget button;
87-
private Object value;
8887
private final AndroidProperty property;
88+
private Object value;
8989

9090
public SettingsEntry(AndroidProperty property) {
9191
this.property = property;
@@ -114,9 +114,9 @@ public SettingsEntry(AndroidProperty property) {
114114
ClientPlayNetworking.send(new AndroidC2SSetBlockPosBeginPayload(SettingsTab.this.parent.entity.getId(), property.id));
115115
parent.close();
116116
}).build();
117-
} else if(Objects.equals(property.type, AndroidProperty.TYPE_BLOCKAREA)) {
117+
} else if (Objects.equals(property.type, AndroidProperty.TYPE_BLOCKAREA)) {
118118
var val = (BlockArea) value;
119-
if(val == null) val = new BlockArea(BlockPos.ORIGIN, BlockPos.ORIGIN);
119+
if (val == null) val = new BlockArea(BlockPos.ORIGIN, BlockPos.ORIGIN);
120120

121121
button = ButtonWidget.builder(Text.of(String.format("[%s,%s,%s] - [%s,%s,%s]", val.getX1(), val.getY1(), val.getZ1(), val.getX2(), val.getY2(), val.getZ2())), button1 -> {
122122
ClientPlayNetworking.send(new AndroidC2SSetBlockAreaBeginPayload(SettingsTab.this.parent.entity.getId(), property.id));
@@ -126,15 +126,15 @@ public SettingsEntry(AndroidProperty property) {
126126
button = ButtonWidget.builder(Text.of("Unknown"), button1 -> {
127127
}).build();
128128
}
129-
if(property.unused)
129+
if (property.unused)
130130
button.setTooltip(Tooltip.of(Text.of("Variable is unused by the current script")));
131131
}
132132

133133
@Override
134134
public void render(DrawContext context, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickProgress) {
135135
var textRenderer = SettingsTab.this.parent.getTextRenderer();
136136
context.fill(x, y, x + entryWidth, y + entryHeight, Colors.DARK_GRAY);
137-
context.drawText(textRenderer, title, x + 2, y + (entryHeight - 8) / 2, property.unused? Colors.RED : Colors.WHITE, true);
137+
context.drawText(textRenderer, title, x + 2, y + (entryHeight - 8) / 2, property.unused ? Colors.RED : Colors.WHITE, true);
138138

139139
int btnW = 60, btnH = 20;
140140
int btnX = x + entryWidth - btnW - 4;
@@ -160,6 +160,7 @@ public boolean mouseClicked(double mx, double my, int btn) {
160160
public boolean mouseReleased(double mx, double my, int btn) {
161161
return this.button.mouseReleased(mx, my, btn) || super.mouseReleased(mx, my, btn);
162162
}
163+
163164
@Override
164165
public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) {
165166
return list.mouseDragged(mouseX, mouseY, button, deltaX, deltaY);

src/main/java/com/hanprogramer/androids/ModBlocks.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,17 @@ public class ModBlocks {
2222
public static final Pair<SolarPanelBlock, BlockItem> SOLAR_PANEL = RegistryHelper.registerBlockWithItem("solar_panel", SolarPanelBlock::new);
2323

2424
public static void initialize() {
25-
} public static final BlockEntityType<ComputerBlockEntity> COMPUTER_BLOCK_ENTITY =
26-
Registry.register(Registries.BLOCK_ENTITY_TYPE, Identifier.of(AndroidsCraft.MOD_ID, "computer_block_entity"),
27-
FabricBlockEntityTypeBuilder.create(ComputerBlockEntity::new, COMPUTER_BLOCK.getLeft()).build());
25+
}
2826

2927
public static void initEnergyLookups() {
3028
EnergyStorage.SIDED.registerForBlockEntity(
3129
(be, side) -> be.getEnergyStorage(side),
3230
SOLAR_PANEL_BLOCK_ENTITY
3331
);
34-
}
32+
} public static final BlockEntityType<ComputerBlockEntity> COMPUTER_BLOCK_ENTITY =
33+
Registry.register(Registries.BLOCK_ENTITY_TYPE, Identifier.of(AndroidsCraft.MOD_ID, "computer_block_entity"),
34+
FabricBlockEntityTypeBuilder.create(ComputerBlockEntity::new, COMPUTER_BLOCK.getLeft()).build());
35+
3536

3637

3738

src/main/java/com/hanprogramer/androids/components/AndroidSetBlockAreaComponent.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,18 @@
55

66
public interface AndroidSetBlockAreaComponent extends Component {
77
boolean isFirstPosDefined();
8-
BlockPos getFirstPos();
8+
99
void setFirstPosDefined(BlockPos pos);
10+
11+
BlockPos getFirstPos();
12+
1013
void clear();
14+
1115
int getEntityId();
16+
1217
void setEntityId(int value);
18+
1319
String getPropertyId();
20+
1421
void setPropertyId(String value);
1522
}

src/main/java/com/hanprogramer/androids/components/AndroidSetBlockAreaComponentImpl.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ public boolean isFirstPosDefined() {
1515
return isFirstPosDefined;
1616
}
1717

18-
@Override
19-
public BlockPos getFirstPos() {
20-
return pos1;
21-
}
22-
2318
@Override
2419
public void setFirstPosDefined(BlockPos pos) {
2520
isFirstPosDefined = true;
2621
pos1 = pos;
2722
}
2823

24+
@Override
25+
public BlockPos getFirstPos() {
26+
return pos1;
27+
}
28+
2929
@Override
3030
public void clear() {
3131
pos1 = null;

src/main/java/com/hanprogramer/androids/components/AndroidSetBlockPosComponent.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
public interface AndroidSetBlockPosComponent extends Component {
66
int getEntityId();
7+
78
void setEntityId(int value);
9+
810
String getPropertyId();
11+
912
void setPropertyId(String value);
1013
}

src/main/java/com/hanprogramer/androids/components/AndroidSetBlockPosComponentImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import net.minecraft.storage.ReadView;
44
import net.minecraft.storage.WriteView;
55

6-
public class AndroidSetBlockPosComponentImpl implements AndroidSetBlockPosComponent{
6+
public class AndroidSetBlockPosComponentImpl implements AndroidSetBlockPosComponent {
77
private int entityId = -1;
88
private String propertyId = "";
99

src/main/java/com/hanprogramer/androids/entities/android/AndroidEntity.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package com.hanprogramer.androids.entities.android;
22

33
import com.hanprogramer.androids.entities.android.inventory.TrackedInventory;
4-
import com.hanprogramer.androids.entities.android.util.BlockArea;
4+
import com.hanprogramer.androids.entities.android.scripting.AndroidProperty;
55
import com.hanprogramer.androids.entities.android.scripting.SelfBridge;
6-
import com.hanprogramer.androids.entities.android.util.Sleeper;
76
import com.hanprogramer.androids.entities.android.scripting.WorldBridge;
8-
import com.hanprogramer.androids.entities.android.scripting.AndroidProperty;
97
import com.hanprogramer.androids.entities.android.util.AndroidPropertyList;
8+
import com.hanprogramer.androids.entities.android.util.BlockArea;
9+
import com.hanprogramer.androids.entities.android.util.Sleeper;
1010
import com.hanprogramer.androids.items.BatteryItem;
1111
import com.hanprogramer.androids.items.RemoteItem;
1212
import com.hanprogramer.androids.items.chips.ScriptableChipItem;
@@ -68,6 +68,7 @@ public void encode(ByteBuf byteBuf, AndroidMaterial material) {
6868
public static final TrackedData<AndroidMaterial> material = DataTracker.registerData(AndroidEntity.class, ANDROID_MATERIAL_TRACKED_DATA_HANDLER);
6969
public static final TrackedDataHandler<List<AndroidProperty>> ANDROID_PROPERTIES_TRACKED_DATA_HANDLER = TrackedDataHandler.create(AndroidPropertyList.PROPERTY_LIST_DATA_HANDLER.codec());
7070
public static final TrackedData<List<AndroidProperty>> properties = DataTracker.registerData(AndroidEntity.class, ANDROID_PROPERTIES_TRACKED_DATA_HANDLER);
71+
public static final TrackedData<String> log = DataTracker.registerData(AndroidEntity.class, TrackedDataHandlerRegistry.STRING);
7172
private static final TrackedData<Boolean> isOn = DataTracker.registerData(AndroidEntity.class, TrackedDataHandlerRegistry.BOOLEAN);
7273
private static final TrackedData<Long> totalPower = DataTracker.registerData(AndroidEntity.class, TrackedDataHandlerRegistry.LONG);
7374
private static final TrackedData<Long> totalCapacity = DataTracker.registerData(AndroidEntity.class, TrackedDataHandlerRegistry.LONG);
@@ -78,7 +79,7 @@ public void encode(ByteBuf byteBuf, AndroidMaterial material) {
7879
private final TrackedInventory inventory;
7980
public String scriptUid = "";
8081
private List<AndroidProperty> _properties = new ArrayList<>();
81-
private List<AndroidProperty> _scriptProperties = new ArrayList<>();
82+
private final List<AndroidProperty> _scriptProperties = new ArrayList<>();
8283
// Per-entity JS state
8384
private Context jsCtx;
8485
private Value tickFn, startFn;
@@ -91,7 +92,6 @@ public void encode(ByteBuf byteBuf, AndroidMaterial material) {
9192
private Sleeper sleeper;
9293
private String _log = "";
9394
private boolean hasChip = false;
94-
public static final TrackedData<String> log = DataTracker.registerData(AndroidEntity.class, TrackedDataHandlerRegistry.STRING);
9595

9696

9797
public AndroidEntity(EntityType<? extends PathAwareEntity> entityType, World world) {
@@ -657,14 +657,14 @@ public void applyProperty(AndroidProperty prop) throws Exception {
657657
private void applyRegularProp(String propId, String displayName, String type, Object value) {
658658
boolean found = false;
659659
for (var p : _properties) {
660-
if(Objects.equals(p.id, propId)) {
660+
if (Objects.equals(p.id, propId)) {
661661
found = true;
662662
p.value = value;
663663
break;
664664
}
665665
}
666666
// If not found then add new entry
667-
if(!found)
667+
if (!found)
668668
_properties.add(new AndroidProperty(propId, displayName, type, value));
669669
}
670670

@@ -687,7 +687,7 @@ public void applyProperty(String propId, Object value) throws Exception {
687687
}
688688
}
689689
// If still not found
690-
if(!found)
690+
if (!found)
691691
throw new Exception("Can't apply prop because it was not found: " + propId);
692692
}
693693
updateProperties();

src/main/java/com/hanprogramer/androids/entities/android/AndroidInventoryScreenHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public boolean onButtonClick(PlayerEntity player, int id) {
108108
slots.clear();
109109
} else if (id == SWITCH_BUTTON_OFF) {
110110
entity.setOn(false);
111-
} else if(id == LOGS_CLEAR_BUTTON) {
111+
} else if (id == LOGS_CLEAR_BUTTON) {
112112
entity.clearLog();
113113
}
114114

0 commit comments

Comments
 (0)