mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-04 20:16:41 +00:00
Don't touch the Direction tag, as possibly only Facing changed.
This commit is contained in:
committed by
Matthew Miller
parent
efc4ebe309
commit
56ef786415
@ -2,24 +2,40 @@ package com.sk89q.worldedit.extent.clipboard.io.legacycompat;
|
||||
|
||||
import com.sk89q.jnbt.ByteTag;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.jnbt.CompoundTagBuilder;
|
||||
import com.sk89q.worldedit.internal.helper.MCDirections;
|
||||
import com.sk89q.worldedit.util.Direction;
|
||||
import com.sk89q.worldedit.world.entity.EntityType;
|
||||
|
||||
public class Pre13HangingCompatibilityHandler implements EntityNBTCompatibilityHandler {
|
||||
|
||||
@Override
|
||||
public boolean isAffectedEntity(EntityType type, CompoundTag entityTag) {
|
||||
return entityTag.getValue().get("Facing") instanceof ByteTag;
|
||||
public boolean isAffectedEntity(EntityType type, CompoundTag tag) {
|
||||
boolean hasLegacyDirection = tag.containsKey("Dir");
|
||||
boolean hasFacing = tag.containsKey("Facing");
|
||||
return hasLegacyDirection || hasFacing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag updateNBT(EntityType type, CompoundTag entityTag) {
|
||||
int newFacing = MCDirections.toHanging(
|
||||
MCDirections.fromPre13Hanging(entityTag.getByte("Facing"))
|
||||
);
|
||||
return entityTag.createBuilder()
|
||||
.putByte("Facing", (byte) newFacing)
|
||||
.build();
|
||||
public CompoundTag updateNBT(EntityType type, CompoundTag tag) {
|
||||
boolean hasLegacyDirection = tag.containsKey("Dir");
|
||||
boolean hasFacing = tag.containsKey("Facing");
|
||||
int d;
|
||||
if (hasLegacyDirection) {
|
||||
d = MCDirections.fromLegacyHanging((byte) tag.asInt("Dir"));
|
||||
} else {
|
||||
d = tag.asInt("Facing");
|
||||
}
|
||||
|
||||
Direction newDirection = MCDirections.fromPre13Hanging(d);
|
||||
|
||||
byte hangingByte = (byte) MCDirections.toHanging(newDirection);
|
||||
|
||||
CompoundTagBuilder builder = tag.createBuilder();
|
||||
builder.putByte("Direction", hangingByte);
|
||||
builder.putByte("Facing", hangingByte);
|
||||
builder.putByte("Dir", MCDirections.toLegacyHanging(MCDirections.toHanging(newDirection)));
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user