Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-12-25 18:40:05 +01:00
Add skull handler.
Dieser Commit ist enthalten in:
Ursprung
526b3366b5
Commit
fcb42f05cf
@ -39,6 +39,7 @@ import com.sk89q.worldedit.extent.clipboard.io.legacycompat.NBTCompatibilityHand
|
|||||||
import com.sk89q.worldedit.extent.clipboard.io.legacycompat.NoteBlockCompatibilityHandler;
|
import com.sk89q.worldedit.extent.clipboard.io.legacycompat.NoteBlockCompatibilityHandler;
|
||||||
import com.sk89q.worldedit.extent.clipboard.io.legacycompat.Pre13HangingCompatibilityHandler;
|
import com.sk89q.worldedit.extent.clipboard.io.legacycompat.Pre13HangingCompatibilityHandler;
|
||||||
import com.sk89q.worldedit.extent.clipboard.io.legacycompat.SignCompatibilityHandler;
|
import com.sk89q.worldedit.extent.clipboard.io.legacycompat.SignCompatibilityHandler;
|
||||||
|
import com.sk89q.worldedit.extent.clipboard.io.legacycompat.SkullBlockCompatibilityHandler;
|
||||||
import com.sk89q.worldedit.math.BlockVector3;
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||||
import com.sk89q.worldedit.regions.Region;
|
import com.sk89q.worldedit.regions.Region;
|
||||||
@ -67,8 +68,9 @@ public class MCEditSchematicReader extends NBTSchematicReader {
|
|||||||
= ImmutableList.of(
|
= ImmutableList.of(
|
||||||
new SignCompatibilityHandler(),
|
new SignCompatibilityHandler(),
|
||||||
new FlowerPotCompatibilityHandler(),
|
new FlowerPotCompatibilityHandler(),
|
||||||
new NoteBlockCompatibilityHandler()
|
new NoteBlockCompatibilityHandler(),
|
||||||
// TODO - skulls, item tags for inventories...? DFUs :>
|
new SkullBlockCompatibilityHandler()
|
||||||
|
// TODO - item tags for inventories...? DFUs :>
|
||||||
);
|
);
|
||||||
private static final ImmutableList<EntityNBTCompatibilityHandler> ENTITY_COMPATIBILITY_HANDLERS
|
private static final ImmutableList<EntityNBTCompatibilityHandler> ENTITY_COMPATIBILITY_HANDLERS
|
||||||
= ImmutableList.of(
|
= ImmutableList.of(
|
||||||
|
@ -29,13 +29,13 @@ public class NoteBlockCompatibilityHandler implements NBTCompatibilityHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <B extends BlockStateHolder<B>> B updateNBT(B block, Map<String, Tag> values) {
|
public <B extends BlockStateHolder<B>> B updateNBT(B block, Map<String, Tag> values) {
|
||||||
// note that instrument was note stored (in state or nbt) previously.
|
// note that instrument was not stored (in state or nbt) previously.
|
||||||
// it will be updated to the block below when it gets set into the world for the first time
|
// it will be updated to the block below when it gets set into the world for the first time
|
||||||
Tag noteTag = values.get("note");
|
Tag noteTag = values.get("note");
|
||||||
if (noteTag instanceof ByteTag) {
|
if (noteTag instanceof ByteTag) {
|
||||||
Byte note = ((ByteTag) noteTag).getValue();
|
Byte note = ((ByteTag) noteTag).getValue();
|
||||||
if (note != null) {
|
if (note != null) {
|
||||||
return (B) block.with(NoteProperty, (int) note);
|
return block.with(NoteProperty, (int) note);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return block;
|
return block;
|
||||||
|
@ -0,0 +1,81 @@
|
|||||||
|
package com.sk89q.worldedit.extent.clipboard.io.legacycompat;
|
||||||
|
|
||||||
|
import com.sk89q.jnbt.ByteTag;
|
||||||
|
import com.sk89q.jnbt.Tag;
|
||||||
|
import com.sk89q.worldedit.registry.state.DirectionalProperty;
|
||||||
|
import com.sk89q.worldedit.registry.state.Property;
|
||||||
|
import com.sk89q.worldedit.world.block.BlockState;
|
||||||
|
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||||
|
import com.sk89q.worldedit.world.block.BlockType;
|
||||||
|
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class SkullBlockCompatibilityHandler implements NBTCompatibilityHandler {
|
||||||
|
|
||||||
|
private static final DirectionalProperty FacingProperty;
|
||||||
|
|
||||||
|
static {
|
||||||
|
DirectionalProperty tempFacing;
|
||||||
|
try {
|
||||||
|
tempFacing = (DirectionalProperty) (Property<?>) BlockTypes.SKELETON_WALL_SKULL.getProperty("facing");
|
||||||
|
} catch (NullPointerException | IllegalArgumentException | ClassCastException e) {
|
||||||
|
tempFacing = null;
|
||||||
|
}
|
||||||
|
FacingProperty = tempFacing;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <B extends BlockStateHolder<B>> boolean isAffectedBlock(B block) {
|
||||||
|
return block.getBlockType() == BlockTypes.SKELETON_SKULL
|
||||||
|
|| block.getBlockType() == BlockTypes.SKELETON_WALL_SKULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <B extends BlockStateHolder<B>> B updateNBT(B block, Map<String, Tag> values) {
|
||||||
|
boolean isWall = block.getBlockType() == BlockTypes.SKELETON_WALL_SKULL;
|
||||||
|
Tag typeTag = values.get("SkullType");
|
||||||
|
if (typeTag instanceof ByteTag) {
|
||||||
|
String skullType = convertSkullType(((ByteTag) typeTag).getValue(), isWall);
|
||||||
|
if (skullType != null) {
|
||||||
|
BlockType type = BlockTypes.get("minecraft:" + skullType);
|
||||||
|
if (type != null) {
|
||||||
|
BlockState state = type.getDefaultState();
|
||||||
|
if (isWall) {
|
||||||
|
Property newProp = type.getProperty("facing");
|
||||||
|
state = state.with(newProp, block.getState(FacingProperty));
|
||||||
|
} else {
|
||||||
|
Tag rotTag = values.get("Rot");
|
||||||
|
if (rotTag instanceof ByteTag) {
|
||||||
|
Property newProp = type.getProperty("rotation");
|
||||||
|
state = state.with(newProp, (int) ((ByteTag) rotTag).getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
values.remove("SkullType");
|
||||||
|
values.remove("Rot");
|
||||||
|
return (B) state;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return block;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String convertSkullType(Byte oldType, boolean isWall) {
|
||||||
|
switch (oldType) {
|
||||||
|
case 0:
|
||||||
|
return isWall ? "skeleton_wall_skull" : "skeleton_skull";
|
||||||
|
case 1:
|
||||||
|
return isWall ? "wither_skeleton_wall_skull" : "wither_skeleton_skull";
|
||||||
|
case 2:
|
||||||
|
return isWall ? "zombie_wall_head" : "zombie_head";
|
||||||
|
case 3:
|
||||||
|
return isWall ? "player_wall_head" : "player_head";
|
||||||
|
case 4:
|
||||||
|
return isWall ? "creeper_wall_head" : "creeper_head";
|
||||||
|
case 5:
|
||||||
|
return isWall ? "dragon_wall_head" : "dragon_head";
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren