mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-06-25 09:04:27 +00:00
Rewrote block parsing, and further switch to BlockState
This commit is contained in:
@ -25,7 +25,7 @@ import com.sk89q.jnbt.NBTUtils;
|
||||
import com.sk89q.jnbt.ShortTag;
|
||||
import com.sk89q.jnbt.StringTag;
|
||||
import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.blocks.metadata.MobType;
|
||||
import com.sk89q.worldedit.blocks.type.BlockState;
|
||||
import com.sk89q.worldedit.world.storage.InvalidFormatException;
|
||||
|
||||
import java.util.HashMap;
|
||||
@ -49,41 +49,23 @@ public class MobSpawnerBlock extends BaseBlock implements TileEntityBlock {
|
||||
private short maxNearbyEntities;
|
||||
private short requiredPlayerRange;
|
||||
|
||||
/**
|
||||
* Construct the mob spawner block with a pig as the mob type.
|
||||
*/
|
||||
public MobSpawnerBlock() {
|
||||
super(BlockID.MOB_SPAWNER);
|
||||
this.mobType = MobType.PIG.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the mob spawner block with a given mob type.
|
||||
*
|
||||
* @param mobType mob type
|
||||
*/
|
||||
public MobSpawnerBlock(String mobType) {
|
||||
super(BlockID.MOB_SPAWNER);
|
||||
this.mobType = mobType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the mob spawner block with a specified data value.
|
||||
*
|
||||
* @param data data value
|
||||
* @param blockState The block state
|
||||
*/
|
||||
public MobSpawnerBlock(int data) {
|
||||
super(BlockID.MOB_SPAWNER, data);
|
||||
public MobSpawnerBlock(BlockState blockState) {
|
||||
super(blockState);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the mob spawner block.
|
||||
*
|
||||
* @param data data value
|
||||
* @param blockState The block state
|
||||
* @param mobType mob type
|
||||
*/
|
||||
public MobSpawnerBlock(int data, String mobType) {
|
||||
super(BlockID.MOB_SPAWNER, data);
|
||||
public MobSpawnerBlock(BlockState blockState, String mobType) {
|
||||
super(blockState);
|
||||
this.mobType = mobType;
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@ package com.sk89q.worldedit.blocks;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.jnbt.StringTag;
|
||||
import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.blocks.type.BlockState;
|
||||
import com.sk89q.worldedit.util.gson.GsonUtil;
|
||||
|
||||
import java.util.HashMap;
|
||||
@ -36,26 +37,14 @@ public class SignBlock extends BaseBlock implements TileEntityBlock {
|
||||
|
||||
private static String EMPTY = "{\"text\":\"\"}";
|
||||
|
||||
/**
|
||||
* Construct the sign without text.
|
||||
*
|
||||
* @param type type ID
|
||||
* @param data data value (orientation)
|
||||
*/
|
||||
public SignBlock(int type, int data) {
|
||||
super(type, data);
|
||||
this.text = new String[] { EMPTY, EMPTY, EMPTY, EMPTY };
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the sign with text.
|
||||
*
|
||||
* @param type type ID
|
||||
* @param data data value (orientation)
|
||||
* @param blockState The block state
|
||||
* @param text lines of text
|
||||
*/
|
||||
public SignBlock(int type, int data, String[] text) {
|
||||
super(type, data);
|
||||
public SignBlock(BlockState blockState, String[] text) {
|
||||
super(blockState);
|
||||
if (text == null) {
|
||||
this.text = new String[] { EMPTY, EMPTY, EMPTY, EMPTY };
|
||||
return;
|
||||
|
@ -19,10 +19,10 @@
|
||||
|
||||
package com.sk89q.worldedit.blocks;
|
||||
|
||||
import com.sk89q.jnbt.ByteTag;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.jnbt.StringTag;
|
||||
import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.blocks.type.BlockState;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -33,60 +33,25 @@ import java.util.Map;
|
||||
public class SkullBlock extends BaseBlock implements TileEntityBlock {
|
||||
|
||||
private String owner = ""; // notchian
|
||||
private byte skullType; // stored here for block, in damage value for item
|
||||
private byte rot; // only matters if block data == 0x1 (on floor)
|
||||
|
||||
/**
|
||||
* Construct the skull block with a default type of skelton.
|
||||
* @param data data value to set, controls placement
|
||||
* @param state BlockState to set
|
||||
*/
|
||||
public SkullBlock(int data) {
|
||||
this(data, (byte) 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the skull block with a given type.
|
||||
* 0 - skeleton
|
||||
* 1 - wither skelly
|
||||
* 2 - zombie
|
||||
* 3 - human
|
||||
* 4 - creeper
|
||||
* @param data data value to set, controls placement
|
||||
* @param type type of skull
|
||||
*/
|
||||
public SkullBlock(int data, byte type) {
|
||||
this(data, type, (byte) 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the skull block with a given type and rotation.
|
||||
* @param data data value to set, controls placement
|
||||
* @param type type of skull
|
||||
* @param rot rotation (if on floor)
|
||||
*/
|
||||
public SkullBlock(int data, byte type, byte rot) {
|
||||
super(BlockID.HEAD, data);
|
||||
if (type < (byte) 0 || type > (byte) 4) {
|
||||
this.skullType = (byte) 0;
|
||||
} else {
|
||||
this.skullType = type;
|
||||
}
|
||||
this.rot = rot;
|
||||
public SkullBlock(BlockState state) {
|
||||
super(state);
|
||||
this.owner = "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the skull block with a given rotation and owner.
|
||||
* The type is assumed to be player unless owner is null or empty.
|
||||
* @param data data value to set, controls placement
|
||||
* @param rot rotation of skull
|
||||
* @param blockState BlockState to set
|
||||
* @param owner name of player
|
||||
*/
|
||||
public SkullBlock(int data, byte rot, String owner) {
|
||||
super(BlockID.HEAD, data);
|
||||
this.rot = rot;
|
||||
public SkullBlock(BlockState blockState, String owner) {
|
||||
super(blockState);
|
||||
this.setOwner(owner);
|
||||
if (owner == null || owner.isEmpty()) this.skullType = (byte) 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -100,7 +65,6 @@ public class SkullBlock extends BaseBlock implements TileEntityBlock {
|
||||
if (owner.length() > 16 || owner.isEmpty()) this.owner = "";
|
||||
else this.owner = owner;
|
||||
}
|
||||
if (!this.owner.isEmpty()) this.skullType = (byte) 3;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -111,38 +75,6 @@ public class SkullBlock extends BaseBlock implements TileEntityBlock {
|
||||
return owner;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the type of skull.
|
||||
* @return the skullType
|
||||
*/
|
||||
public byte getSkullType() {
|
||||
return skullType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the type of skull;
|
||||
* @param skullType the skullType to set
|
||||
*/
|
||||
public void setSkullType(byte skullType) {
|
||||
this.skullType = skullType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get rotation of skull. This only means anything if the block data is 1.
|
||||
* @return the rotation
|
||||
*/
|
||||
public byte getRot() {
|
||||
return rot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the rotation of skull.
|
||||
* @param rot the rotation to set
|
||||
*/
|
||||
public void setRot(byte rot) {
|
||||
this.rot = rot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNbtData() {
|
||||
return true;
|
||||
@ -155,11 +87,9 @@ public class SkullBlock extends BaseBlock implements TileEntityBlock {
|
||||
|
||||
@Override
|
||||
public CompoundTag getNbtData() {
|
||||
Map<String, Tag> values = new HashMap<String, Tag>();
|
||||
values.put("SkullType", new ByteTag(skullType));
|
||||
Map<String, Tag> values = new HashMap<>();
|
||||
if (owner == null) owner = "";
|
||||
values.put("ExtraType", new StringTag( owner));
|
||||
values.put("Rot", new ByteTag(rot));
|
||||
values.put("ExtraType", new StringTag(owner));
|
||||
return new CompoundTag(values);
|
||||
}
|
||||
|
||||
@ -178,17 +108,9 @@ public class SkullBlock extends BaseBlock implements TileEntityBlock {
|
||||
throw new RuntimeException("'Skull' tile entity expected");
|
||||
}
|
||||
|
||||
t = values.get("SkullType");
|
||||
if (t instanceof ByteTag) {
|
||||
skullType = ((ByteTag) t).getValue();
|
||||
}
|
||||
t = values.get("ExtraType");
|
||||
if (t != null && t instanceof StringTag) {
|
||||
if (t instanceof StringTag) {
|
||||
owner = ((StringTag) t).getValue();
|
||||
}
|
||||
t = values.get("Rot");
|
||||
if (t instanceof ByteTag) {
|
||||
rot = ((ByteTag) t).getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user