mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 01:37:37 +00:00
Fix 1.13 entity direction code, port old schematics
This commit is contained in:
parent
c325b789b2
commit
efc4ebe309
@ -19,6 +19,7 @@
|
||||
|
||||
package com.sk89q.worldedit.extent.clipboard.io;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.sk89q.jnbt.ByteArrayTag;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.jnbt.IntTag;
|
||||
@ -32,7 +33,9 @@ import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.legacycompat.EntityNBTCompatibilityHandler;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.legacycompat.NBTCompatibilityHandler;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.legacycompat.Pre13HangingCompatibilityHandler;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.legacycompat.SignCompatibilityHandler;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
@ -47,7 +50,6 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -59,12 +61,15 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||
*/
|
||||
public class MCEditSchematicReader extends NBTSchematicReader {
|
||||
|
||||
private static final List<NBTCompatibilityHandler> COMPATIBILITY_HANDLERS = new ArrayList<>();
|
||||
|
||||
static {
|
||||
COMPATIBILITY_HANDLERS.add(new SignCompatibilityHandler());
|
||||
private static final ImmutableList<NBTCompatibilityHandler> COMPATIBILITY_HANDLERS
|
||||
= ImmutableList.of(
|
||||
new SignCompatibilityHandler()
|
||||
// TODO Add a handler for skulls, flower pots, note blocks, etc.
|
||||
}
|
||||
);
|
||||
private static final ImmutableList<EntityNBTCompatibilityHandler> ENTITY_COMPATIBILITY_HANDLERS
|
||||
= ImmutableList.of(
|
||||
new Pre13HangingCompatibilityHandler()
|
||||
);
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(MCEditSchematicReader.class);
|
||||
private final NBTInputStream inputStream;
|
||||
@ -264,6 +269,11 @@ public class MCEditSchematicReader extends NBTSchematicReader {
|
||||
if (!id.isEmpty()) {
|
||||
EntityType entityType = EntityTypes.get(id.toLowerCase());
|
||||
if (entityType != null) {
|
||||
for (EntityNBTCompatibilityHandler compatibilityHandler : ENTITY_COMPATIBILITY_HANDLERS) {
|
||||
if (compatibilityHandler.isAffectedEntity(entityType, compound)) {
|
||||
compound = compatibilityHandler.updateNBT(entityType, compound);
|
||||
}
|
||||
}
|
||||
BaseEntity state = new BaseEntity(entityType, compound);
|
||||
clipboard.createEntity(location, state);
|
||||
} else {
|
||||
|
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.extent.clipboard.io.legacycompat;
|
||||
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.entity.EntityType;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface EntityNBTCompatibilityHandler {
|
||||
boolean isAffectedEntity(EntityType type, CompoundTag entityTag);
|
||||
CompoundTag updateNBT(EntityType type, CompoundTag entityTag);
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package com.sk89q.worldedit.extent.clipboard.io.legacycompat;
|
||||
|
||||
import com.sk89q.jnbt.ByteTag;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.internal.helper.MCDirections;
|
||||
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;
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
}
|
@ -30,6 +30,44 @@ public final class MCDirections {
|
||||
}
|
||||
|
||||
public static Direction fromHanging(int i) {
|
||||
switch (i) {
|
||||
case 0:
|
||||
return Direction.DOWN;
|
||||
case 1:
|
||||
return Direction.UP;
|
||||
case 2:
|
||||
return Direction.NORTH;
|
||||
case 3:
|
||||
return Direction.SOUTH;
|
||||
case 4:
|
||||
return Direction.WEST;
|
||||
case 5:
|
||||
return Direction.EAST;
|
||||
default:
|
||||
return Direction.DOWN;
|
||||
}
|
||||
}
|
||||
|
||||
public static int toHanging(Direction direction) {
|
||||
switch (direction) {
|
||||
case DOWN:
|
||||
return 0;
|
||||
case UP:
|
||||
return 1;
|
||||
case NORTH:
|
||||
return 2;
|
||||
case SOUTH:
|
||||
return 3;
|
||||
case WEST:
|
||||
return 4;
|
||||
case EAST:
|
||||
return 5;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static Direction fromPre13Hanging(int i) {
|
||||
switch (i) {
|
||||
case 0:
|
||||
return Direction.SOUTH;
|
||||
@ -44,7 +82,7 @@ public final class MCDirections {
|
||||
}
|
||||
}
|
||||
|
||||
public static int toHanging(Direction direction) {
|
||||
public static int toPre13Hanging(Direction direction) {
|
||||
switch (direction) {
|
||||
case SOUTH:
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user