Skip to content

Commit

Permalink
Merge branch 'refs/heads/dev/1.19.2' into dev/0.8
Browse files Browse the repository at this point in the history
# Conflicts:
#	gradle.properties
#	src/main/java/de/srendi/advancedperipherals/common/commands/APCommands.java
#	src/main/java/de/srendi/advancedperipherals/common/util/CoordUtil.java
#	src/main/java/de/srendi/advancedperipherals/common/util/ServerWorker.java
  • Loading branch information
SirEndii committed Apr 26, 2024
2 parents ab4b47c + 4acaa1c commit ab0d58a
Show file tree
Hide file tree
Showing 8 changed files with 307 additions and 103 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/build-and-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Build and Test

on:
workflow_dispatch:
push:
pull_request_target:
types:
- opened
- synchronize

jobs:
build-and-test:
uses: IntelligenceModding/actions/.github/workflows/build-and-test.yaml@master
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [1.19.2-0.7.35r] - 2024-04-12

### Fixed
- [#559] Fixed the creation of empty nbt tags when inserting items into the ME System - @Thanks to michele-grifa!
- [#577,#570] Fixed that the RS bridge does not show `isCraftable` in `getItem` or `getPattern` - Thanks to @tomprince!
- [#570] Improved performance of ME Bridge's iterating functions by making the functions not quadratic - Thanks to @tomprince!
- [#560] Fixed stacking problems when using `getItems` from the inventory manager
- [#551] Fixed that RS Bridge's `isItemCrafting` is false when the item is not in the system
- [#536] Invalidate the energy detectors in and output energy providers to prevent the energy detector from stopping to transfer energy
- [#575] Added support for more disk cells and portable cells for the ME Bridge - Thanks to @iTrooz

### Added
- [#571] Added `selectionMode` to the output of ME Bridge's `getCraftingCPUs` function - Thanks to @tomprince!
- [#564] Added optional parameter to `getPlayerPos` to specify the amount of decimal places to retrieve the position of - Thanks to @minecraf7771

## [1.19.2-0.7.34r] - 2024-02-13

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ChunkyPeripheral extends BasePeripheral<TurtlePeripheralOwner> {

public static final String PERIPHERAL_TYPE = "chunky";
private static final String UUID_TAG = "uuid";
private @Nullable ChunkPos loadedCentralChunk;
private @Nullable ChunkPos loadedCentralChunk = null;

public ChunkyPeripheral(ITurtleAccess turtle, TurtleSide side) {
super(PERIPHERAL_TYPE, new TurtlePeripheralOwner(turtle, side));
Expand All @@ -45,36 +45,51 @@ public boolean isEnabled() {
}

public void updateChunkState() {
// TODO: should find someway to update after turtle moved or while moving, but not every tick
ServerLevel level = (ServerLevel) getLevel();
ChunkManager manager = ChunkManager.get(level);
ChunkPos currentChunk = getChunkPos();
if (loadedCentralChunk == null || !loadedCentralChunk.equals(currentChunk)) {
setLoadedChunk(currentChunk, manager, level);
} else {
manager.touch(getUUID());
}
setLoadedChunk(currentChunk, manager, level);
manager.touch(getUUID());
}

protected void setLoadedChunk(@Nullable ChunkPos newChunk, ChunkManager manager, ServerLevel level) {
if (loadedCentralChunk != null) {
manager.removeForceChunk(level, getUUID(), loadedCentralChunk);
//Should not be used
//level.setChunkForced(loadedChunk.x, loadedChunk.z, false);
if (loadedCentralChunk.equals(newChunk)) {
return;
}
manager.removeForceChunk(level, getUUID());
// Should not be used
// level.setChunkForced(loadedChunk.x, loadedChunk.z, false);
loadedCentralChunk = null;
}
if (newChunk != null) {
loadedCentralChunk = newChunk;
manager.addForceChunk(level, getUUID(), loadedCentralChunk);
//Should not be used
//level.setChunkForced(newChunk.x, newChunk.z, true);
// Should not be used
// level.setChunkForced(newChunk.x, newChunk.z, true);
}
}

@Override
public void detach(@NotNull IComputerAccess computer) {
super.detach(computer);
public void attach(IComputerAccess computer) {
super.attach(computer);
ServerLevel level = (ServerLevel) owner.getLevel();
ChunkManager manager = ChunkManager.get(Objects.requireNonNull(level));
setLoadedChunk(null, manager, level);
ChunkPos currentChunk = getChunkPos();
setLoadedChunk(currentChunk, manager, level);
}

@Override
public void detach(@NotNull IComputerAccess computer) {
super.detach(computer);
// Should not remove the loaded chunk when detaching,
// because CC:T will detach all peripherals before server stopped.
// So the chunk record will never be saved if we removed the chunk record when detaching.
// The records will be automatically removed by the ChunkManager if they have not been touched a while ago.

// ServerLevel level = (ServerLevel) owner.getLevel();
// ChunkManager manager = ChunkManager.get(Objects.requireNonNull(level));
// setLoadedChunk(null, manager, level);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -250,16 +250,19 @@ public final Map<String, Object> getPlayerPos(IArguments arguments) throws LuaEx

int decimals = Math.min(arguments.optInt(1, 0), 4);

info.put("x", Math.floor(x * Math.pow(10, decimals)) / Math.pow(10, decimals));
info.put("y", Math.floor(y * Math.pow(10, decimals)) / Math.pow(10, decimals));
info.put("z", Math.floor(z * Math.pow(10, decimals)) / Math.pow(10, decimals));
final double unit = Math.pow(10, decimals);
info.put("x", Math.floor(x * unit) / unit);
info.put("y", Math.floor(y * unit) / unit);
info.put("z", Math.floor(z * unit) / unit);
if (APConfig.PERIPHERALS_CONFIG.morePlayerInformation.get()) {
info.put("yaw", existingPlayer.yRotO);
info.put("pitch", existingPlayer.xRotO);
info.put("dimension", existingPlayer.getLevel().dimension().location().toString());
info.put("eyeHeight", existingPlayer.getEyeHeight());
info.put("health", existingPlayer.getHealth());
info.put("maxHeatlh", existingPlayer.getMaxHealth());
// TODO: remove the next line in next major version
info.put("maxHeatlh", existingPlayer.getMaxHealth()); // keep this for backward compatibility
info.put("maxHealth", existingPlayer.getMaxHealth());
info.put("airSupply", existingPlayer.getAirSupply());
info.put("respawnPosition", LuaConverter.posToObject(existingPlayer.getRespawnPosition()));
info.put("respawnDimension", existingPlayer.getRespawnDimension().location().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
import org.jetbrains.annotations.NotNull;

public class TurtleChunkyUpgrade extends PeripheralTurtleUpgrade<ChunkyPeripheral> {
private int updateTick = 0;

public TurtleChunkyUpgrade(ResourceLocation id, ItemStack stack) {
super(id, stack);
}

@Override
public ModelResourceLocation getLeftModel() {
return null; //Null, the turtle uses the chunk controller item model. See BaseTurtle.java
return null; // Null, the turtle uses the chunk controller item model. See BaseTurtle.java
}

@Override
Expand All @@ -34,10 +35,16 @@ protected ChunkyPeripheral buildPeripheral(@NotNull ITurtleAccess turtle, @NotNu

@Override
public void update(@NotNull ITurtleAccess turtle, @NotNull TurtleSide side) {
//Add a chunk to the Chunk Manager every 10 ticks, if it's not already forced.
//The turtle can move, so we need to do that.
// Add a chunk to the Chunk Manager every 10 ticks, if it's not already forced.
// The turtle can move, so we need to do that.
super.update(turtle, side);
if (APConfig.PERIPHERALS_CONFIG.enableChunkyTurtle.get()) {
// TODO: turtle will stop work when crossing chunks if update every 10 ticks
// updateTick++;
// if (updateTick < 10) {
// return;
// }
// updateTick = 0;
IPeripheral peripheral = turtle.getPeripheral(side);
if (peripheral instanceof ChunkyPeripheral chunkyPeripheral) {
chunkyPeripheral.updateChunkState();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
package de.srendi.advancedperipherals.common.commands;

import com.mojang.brigadier.exceptions.CommandSyntaxException;

import dan200.computercraft.core.computer.ComputerSide;
import dan200.computercraft.core.computer.Environment;
import dan200.computercraft.shared.command.UserLevel;
import dan200.computercraft.shared.command.text.ChatHelpers;
import dan200.computercraft.shared.command.text.TableBuilder;
import dan200.computercraft.shared.computer.core.ServerComputer;
import dan200.computercraft.shared.computer.core.ServerContext;

import de.srendi.advancedperipherals.AdvancedPeripherals;
import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.ChunkyPeripheral;
import de.srendi.advancedperipherals.common.util.inventory.ItemUtil;

import net.minecraft.ChatFormatting;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
Expand All @@ -17,12 +28,25 @@

@Mod.EventBusSubscriber(modid = AdvancedPeripherals.MOD_ID)
public class APCommands {
public static final String ROOT_LITERAL = "advancedperipherals";
public static final String FORCELOAD_LITERAL = "forceload";
static final String FORCELOAD_HELP =
"/" + ROOT_LITERAL + " " + FORCELOAD_LITERAL + " help" + " - show this help message\n" +
"/" + ROOT_LITERAL + " " + FORCELOAD_LITERAL + " dump" + " - show all chunky turtles\n";

@SubscribeEvent
public static void register(RegisterCommandsEvent event) {
event.getDispatcher().register(Commands.literal("advancedperipherals")
event.getDispatcher().register(Commands.literal(ROOT_LITERAL)
.then(Commands.literal("getHashItem")
.executes(context -> getHashItem(context.getSource()))));
.executes(context -> getHashItem(context.getSource()))).then(Commands.literal(FORCELOAD_LITERAL)
.executes(context -> forceloadHelp(context.getSource()))
.then(Commands.literal("help")
.executes(context -> forceloadHelp(context.getSource())))
.then(Commands.literal("dump")
.requires(UserLevel.OWNER_OP)
.executes(context -> forceloadDump(context.getSource())))
)
);
}

private static int getHashItem(CommandSourceStack source) throws CommandSyntaxException {
Expand All @@ -44,4 +68,50 @@ private static int getHashItem(CommandSourceStack source) throws CommandSyntaxEx
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal("Copy"))))), true);
return 1;
}

private static int forceloadHelp(CommandSourceStack source) throws CommandSyntaxException {
source.sendSuccess(Component.literal(FORCELOAD_HELP), true);
return 1;
}

private static int forceloadDump(CommandSourceStack source) throws CommandSyntaxException {
TableBuilder table = new TableBuilder("ChunkyTurtles", "Computer", "Position");

ServerComputer[] computers = ServerContext.get(source.getServer()).registry().getComputers().stream().filter((computer) -> {
Environment env = computer.getComputer().getEnvironment();
for (ComputerSide side : ComputerSide.values()) {
if (env.getPeripheral(side) instanceof ChunkyPeripheral) {
return true;
}
}
return false;
}).sorted((a, b) -> a.getID() - b.getID()).toArray(size -> new ServerComputer[size]);

for (ServerComputer computer : computers) {
table.row(
makeComputerDumpCommand(computer),
makeComputerPosCommand(computer)
);
}

table.display(source);
return computers.length;
}


private static Component makeComputerDumpCommand(ServerComputer computer) {
return ChatHelpers.link(
Component.literal("#" + computer.getID()),
"/computercraft dump " + computer.getInstanceID(),
Component.translatable("commands.computercraft.dump.action")
);
}

private static Component makeComputerPosCommand(ServerComputer computer) {
return ChatHelpers.link(
ChatHelpers.position(computer.getPosition()),
"/computercraft tp " + computer.getInstanceID(),
Component.translatable("commands.computercraft.tp.action")
);
}
}
Loading

0 comments on commit ab0d58a

Please sign in to comment.