1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-01-10 01:10:30 +00:00

Fix incorrect Lua list indexes in NBT tags (#1678)

This commit is contained in:
lonevox 2024-01-11 08:16:15 +13:00 committed by GitHub
parent 133b51b092
commit 89294f4a22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 19 deletions

View File

@ -20,28 +20,24 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.Vec2;
import net.minecraft.world.phys.Vec3;
import java.util.HashMap;
import java.util.Map;
import java.util.ArrayList;
import java.util.List;
public class CommandComputerBlockEntity extends ComputerBlockEntity {
public class CommandReceiver implements CommandSource {
private final Map<Integer, String> output = new HashMap<>();
private final List<String> output = new ArrayList<>();
public void clearOutput() {
output.clear();
}
public Map<Integer, String> getOutput() {
return output;
}
public Map<Integer, String> copyOutput() {
return new HashMap<>(output);
public List<String> copyOutput() {
return new ArrayList<>(output);
}
@Override
public void sendSystemMessage(Component textComponent) {
output.put(output.size() + 1, textComponent.getString());
output.add(textComponent.getString());
}
@Override

View File

@ -19,9 +19,7 @@ import java.io.IOException;
import java.io.OutputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
public final class NBTUtil {
private static final Logger LOG = LoggerFactory.getLogger(NBTUtil.class);
@ -149,20 +147,20 @@ public final class NBTUtil {
}
case Tag.TAG_LIST: {
var list = (ListTag) tag;
Map<Integer, Object> map = new HashMap<>(list.size());
for (var i = 0; i < list.size(); i++) map.put(i, toLua(list.get(i)));
List<Object> map = new ArrayList<>(list.size());
for (var value : list) map.add(toLua(value));
return map;
}
case Tag.TAG_BYTE_ARRAY: {
var array = ((ByteArrayTag) tag).getAsByteArray();
Map<Integer, Byte> map = new HashMap<>(array.length);
for (var i = 0; i < array.length; i++) map.put(i + 1, array[i]);
List<Byte> map = new ArrayList<>(array.length);
for (var b : array) map.add(b);
return map;
}
case Tag.TAG_INT_ARRAY: {
var array = ((IntArrayTag) tag).getAsIntArray();
Map<Integer, Integer> map = new HashMap<>(array.length);
for (var i = 0; i < array.length; i++) map.put(i + 1, array[i]);
List<Integer> map = new ArrayList<>(array.length);
for (var j : array) map.add(j);
return map;
}