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

View File

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