NBT save function changes
This commit is contained in:
parent
d2ade23f36
commit
304609595f
2 changed files with 23 additions and 5 deletions
|
@ -8,7 +8,7 @@
|
||||||
loader_version = 0.10.1+build.209
|
loader_version = 0.10.1+build.209
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version = 0.3.2-alpha
|
mod_version = 0.4.0-alpha
|
||||||
maven_group = ru.betterend
|
maven_group = ru.betterend
|
||||||
archives_base_name = better-end
|
archives_base_name = better-end
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ import java.util.Map;
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.nbt.ListTag;
|
import net.minecraft.nbt.ListTag;
|
||||||
|
@ -112,10 +111,16 @@ public class StructureWorld {
|
||||||
|
|
||||||
public Part(CompoundTag tag) {
|
public Part(CompoundTag tag) {
|
||||||
ListTag map = tag.getList("blocks", 10);
|
ListTag map = tag.getList("blocks", 10);
|
||||||
|
ListTag map2 = tag.getList("states", 10);
|
||||||
|
BlockState[] states = new BlockState[map2.size()];
|
||||||
|
for (int i = 0; i < states.length; i++) {
|
||||||
|
states[i] = NbtHelper.toBlockState((CompoundTag) map2.get(i));
|
||||||
|
}
|
||||||
|
|
||||||
map.forEach((element) -> {
|
map.forEach((element) -> {
|
||||||
CompoundTag block = (CompoundTag) element;
|
CompoundTag block = (CompoundTag) element;
|
||||||
BlockPos pos = NbtHelper.toBlockPos(block.getCompound("pos"));
|
BlockPos pos = NbtHelper.toBlockPos(block.getCompound("pos"));
|
||||||
BlockState state = Block.getStateFromRawId(block.getInt("state"));
|
BlockState state = states[block.getInt("state")];
|
||||||
blocks.put(pos, state);
|
blocks.put(pos, state);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -127,7 +132,6 @@ public class StructureWorld {
|
||||||
|
|
||||||
void placeChunk(Chunk chunk) {
|
void placeChunk(Chunk chunk) {
|
||||||
blocks.forEach((pos, state) -> {
|
blocks.forEach((pos, state) -> {
|
||||||
//if (pos.getY() > 10)
|
|
||||||
chunk.setBlockState(pos, state, false);
|
chunk.setBlockState(pos, state, false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -138,12 +142,26 @@ public class StructureWorld {
|
||||||
tag.putInt("z", z);
|
tag.putInt("z", z);
|
||||||
ListTag map = new ListTag();
|
ListTag map = new ListTag();
|
||||||
tag.put("blocks", map);
|
tag.put("blocks", map);
|
||||||
|
ListTag stateMap = new ListTag();
|
||||||
|
tag.put("states", stateMap);
|
||||||
|
|
||||||
|
int[] id = new int[1];
|
||||||
|
Map<BlockState, Integer> states = Maps.newHashMap();
|
||||||
|
|
||||||
blocks.forEach((pos, state) -> {
|
blocks.forEach((pos, state) -> {
|
||||||
|
int stateID = states.getOrDefault(states, -1);
|
||||||
|
if (stateID < 0) {
|
||||||
|
stateID = id[0] ++;
|
||||||
|
states.put(state, stateID);
|
||||||
|
stateMap.add(NbtHelper.fromBlockState(state));
|
||||||
|
}
|
||||||
|
|
||||||
CompoundTag block = new CompoundTag();
|
CompoundTag block = new CompoundTag();
|
||||||
block.put("pos", NbtHelper.fromBlockPos(pos));
|
block.put("pos", NbtHelper.fromBlockPos(pos));
|
||||||
block.putInt("state", Block.getRawIdFromState(state));
|
block.putInt("state", stateID);
|
||||||
map.add(block);
|
map.add(block);
|
||||||
});
|
});
|
||||||
|
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue