Inventories! (Part 1)

This commit is contained in:
LOOHP
2022-12-09 02:40:16 +00:00
parent ca186938f4
commit 949d2f34d7
48 changed files with 10960 additions and 6652 deletions
@@ -27,6 +27,7 @@ import net.querz.nbt.tag.Tag;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
public class BlockState {
@@ -79,33 +80,15 @@ public class BlockState {
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((tag == null) ? 0 : tag.hashCode());
return result;
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
BlockState that = (BlockState) o;
return Objects.equals(tag, that.tag);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
BlockState other = (BlockState) obj;
if (tag == null) {
if (other.tag != null) {
return false;
}
} else if (!tag.equals(other.tag)) {
return false;
}
return true;
public int hashCode() {
return Objects.hash(tag);
}
}
+17 -33
View File
@@ -41,6 +41,7 @@ import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
@@ -91,7 +92,7 @@ public class World {
chunk.cleanupPalettesAndBlockStates();
chunk.setHeightMaps(HEIGHT_MAP.clone());
chunk.setBiomes(new int[256]);
chunk.setTileEntities(new ListTag<CompoundTag>(CompoundTag.class));
chunk.setTileEntities(new ListTag<>(CompoundTag.class));
}
}
@@ -124,6 +125,10 @@ public class World {
CompoundTag block = SchematicConversionUtils.toBlockTag(blockdata);
chunk.setBlockStateAt(x, y, z, block, false);
}
public BlockState getBlock(BlockPosition blockPosition) {
return getBlock(blockPosition.getX(), blockPosition.getY(), blockPosition.getZ());
}
public BlockState getBlock(int x, int y, int z) {
Chunk chunk = this.chunks[(x >> 4)][(z >> 4)];
@@ -139,6 +144,10 @@ public class World {
}
return new BlockState(tag);
}
public void setBlock(BlockPosition blockPosition, BlockState state) {
setBlock(blockPosition.getX(), blockPosition.getY(), blockPosition.getZ(), state);
}
public void setBlock(int x, int y, int z, BlockState state) {
Chunk chunk = this.chunks[(x >> 4)][(z >> 4)];
@@ -300,40 +309,15 @@ public class World {
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + Arrays.deepHashCode(chunks);
result = prime * result + ((environment == null) ? 0 : environment.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
World world = (World) o;
return Objects.equals(name, world.name);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
World other = (World) obj;
if (!Arrays.deepEquals(chunks, other.chunks)) {
return false;
}
if (environment != other.environment) {
return false;
}
if (name == null) {
if (other.name != null) {
return false;
}
} else if (!name.equals(other.name)) {
return false;
}
return true;
public int hashCode() {
return Objects.hash(name);
}
}