Skip to content

Commit

Permalink
Fixed head texture load issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul19988 committed Jan 16, 2021
1 parent 82d4a8a commit 6a4ab71
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ public byte[] serialize() {
outStream.writeInt(tileEntitiesData.length);
outStream.write(compressedTileEntitiesData);

// System.out.println("HEADS: ");
// System.out.println("TILES: " + tileEntitiesList.toString());

// Entities
List<CompoundTag> entitiesList = sortedChunks.stream().flatMap(chunk -> chunk.getEntities().stream()).collect(Collectors.toList());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ static NBTBase convertTag(Tag tag) {
NBTTagCompound compound = new NBTTagCompound();

((CompoundTag) tag).getValue().forEach((key, value) -> compound.set(key, convertTag(value)));

return compound;
case TAG_INT_ARRAY:
return new NBTTagIntArray(((IntArrayTag) tag).getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import com.grinderwolf.swm.api.world.properties.SlimePropertyMap;
import com.grinderwolf.swm.nms.CraftSlimeChunk;
import com.grinderwolf.swm.nms.CraftSlimeWorld;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import lombok.Getter;
import lombok.Setter;
import net.minecraft.server.v1_16_R3.*;
Expand All @@ -25,6 +27,7 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.Consumer;
import java.util.logging.Level;

public class CustomWorldServer extends WorldServer {

Expand Down Expand Up @@ -106,11 +109,11 @@ public void save(IProgressUpdate progressUpdate, boolean forceSave, boolean flag
private void save() {
synchronized (saveLock) { // Don't want to save the SlimeWorld from multiple threads simultaneously
try {
// LOGGER.info("Saving world " + slimeWorld.getName() + "...");
Bukkit.getLogger().log(Level.INFO, "Saving world " + slimeWorld.getName() + "...");
long start = System.currentTimeMillis();
byte[] serializedWorld = slimeWorld.serialize();
slimeWorld.getLoader().saveWorld(slimeWorld.getName(), serializedWorld, false);
// LOGGER.info("World " + slimeWorld.getName() + " saved in " + (System.currentTimeMillis() - start) + "ms.");
Bukkit.getLogger().log(Level.INFO, "World " + slimeWorld.getName() + " saved in " + (System.currentTimeMillis() - start) + "ms.");
} catch (IOException ex) {
ex.printStackTrace();
}
Expand Down Expand Up @@ -229,10 +232,28 @@ private Chunk createChunk(SlimeChunk chunk) {

// Sometimes null tile entities are saved
if (type.isPresent()) {
IBlockData blockData = nmsChunk.getType(new BlockPosition(tag.getIntValue("x").get(), tag.getIntValue("y").get(), tag.getIntValue("z").get()));
BlockPosition blockPosition = new BlockPosition(tag.getIntValue("x").get(), tag.getIntValue("y").get(), tag.getIntValue("z").get());
IBlockData blockData = nmsChunk.getType(blockPosition);
TileEntity entity = TileEntity.create(blockData, (NBTTagCompound) Converter.convertTag(tag));

if (entity != null) {
if(type.get().toLowerCase().contains("skull") || type.get().toLowerCase().contains("head")) {
NBTTagCompound nbtTagCompound = (NBTTagCompound) Converter.convertTag(tag);
if(tag.getAsCompoundTag("SkullOwner").isPresent()) {
if(tag.getAsCompoundTag("SkullOwner").get().getAsCompoundTag("Properties").isPresent()) {
TileEntitySkull entitySkull = (TileEntitySkull) entity;
String texture = nbtTagCompound.getCompound("SkullOwner").getCompound("Properties").get("textures").toString().split(":")[1].replace("\"", "");
texture = texture.replace("}", "");
texture = texture.replace("]", "");

GameProfile gameProfile = new GameProfile(UUID.randomUUID(), UUID.randomUUID().toString());
Property property = new Property("textures", texture);
gameProfile.getProperties().put("textures", property);
entitySkull.setGameProfile(gameProfile);

entitySkull.update();
}
}
}
nmsChunk.a(entity);
loadedEntities++;
}
Expand Down

0 comments on commit 6a4ab71

Please sign in to comment.