cn.nukkit.entity.data.ByteEntityData Java Examples

The following examples show how to use cn.nukkit.entity.data.ByteEntityData. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EntityMinecartAbstract.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Set the minecart display block!
 *
 * @param block The block that will changed. Set {@code null} for BlockAir
 * @return {@code true} if the block is normal block
 */
public boolean setDisplayBlock(Block block) {
    if (block != null) {
        if (block.isNormalBlock()) {
            blockInside = block;
            int display = blockInside.getId()
                    | blockInside.getDamage() << 16;
            setDataProperty(new ByteEntityData(DATA_MINECART_HAS_DISPLAY, 1));
            setDataProperty(new IntEntityData(DATA_MINECART_DISPLAY_BLOCK, display));
            setDisplayBlockOffset(6);
        }
    } else {
        // Set block to air (default).
        blockInside = null;
        setDataProperty(new ByteEntityData(DATA_MINECART_HAS_DISPLAY, 0));
        setDataProperty(new IntEntityData(DATA_MINECART_DISPLAY_BLOCK, 0));
        setDisplayBlockOffset(0);
    }
    return true;
}
 
Example #2
Source File: EntityTameable.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void initEntity() {
    super.initEntity();
    if (getDataProperty(DATA_TAMED_FLAG) == null) {
        setDataProperty(new ByteEntityData(DATA_TAMED_FLAG, (byte) 0));
    }

    if (getDataProperty(DATA_OWNER_NAME) == null) {
        setDataProperty(new StringEntityData(DATA_OWNER_NAME, ""));
    }

    String ownerName = "";

    if (namedTag != null) {
        if (namedTag.contains("Owner")) {
            ownerName = namedTag.getString("Owner");
        }

        if (ownerName.length() > 0) {
            this.setOwnerName(ownerName);
            this.setTamed(true);
        }

        this.setSitting(namedTag.getBoolean("Sitting"));
    }
}
 
Example #3
Source File: EntityTameable.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void initEntity() {
    super.initEntity();
    if (getDataProperty(DATA_TAMED_FLAG) == null) {
        setDataProperty(new ByteEntityData(DATA_TAMED_FLAG, (byte) 0));
    }

    if (getDataProperty(DATA_OWNER_NAME) == null) {
        setDataProperty(new StringEntityData(DATA_OWNER_NAME, ""));
    }

    String ownerName = "";

    if (namedTag != null) {
        if (namedTag.contains("Owner")) {
            ownerName = namedTag.getString("Owner");
        }

        if (ownerName.length() > 0) {
            this.setOwnerName(ownerName);
            this.setTamed(true);
        }

        this.setSitting(namedTag.getBoolean("Sitting"));
    }
}
 
Example #4
Source File: EntityMinecartAbstract.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Set the minecart display block!
 *
 * @param block The block that will changed. Set {@code null} for BlockAir
 * @return {@code true} if the block is normal block
 */
@API(usage = Usage.MAINTAINED, definition = Definition.UNIVERSAL)
public boolean setDisplayBlock(Block block) {
    if (block != null) {
        if (block.isNormalBlock()) {
            blockInside = block;
            int display = blockInside.getId()
                    | blockInside.getDamage() << 16;
            setDataProperty(new ByteEntityData(DATA_MINECART_HAS_DISPLAY, 1));
            setDataProperty(new IntEntityData(DATA_MINECART_DISPLAY_BLOCK, display));
            setDisplayBlockOffset(6);
        }
    } else {
        // Set block to air (default).
        blockInside = null;
        setDataProperty(new ByteEntityData(DATA_MINECART_HAS_DISPLAY, 0));
        setDataProperty(new IntEntityData(DATA_MINECART_DISPLAY_BLOCK, 0));
        setDisplayBlockOffset(0);
    }
    return true;
}
 
Example #5
Source File: EntityTameable.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void initEntity() {
    super.initEntity();
    if (getDataProperty(DATA_TAMED_FLAG) == null) {
        setDataProperty(new ByteEntityData(DATA_TAMED_FLAG, (byte) 0));
    }

    if (getDataProperty(DATA_OWNER_NAME) == null) {
        setDataProperty(new StringEntityData(DATA_OWNER_NAME, ""));
    }

    String ownerName = "";

    if (namedTag != null) {
        if (namedTag.contains("Owner")) {
            ownerName = namedTag.getString("Owner");
        }

        if (ownerName.length() > 0) {
            this.setOwnerName(ownerName);
            this.setTamed(true);
        }

        this.setSitting(namedTag.getBoolean("Sitting"));
    }
}
 
Example #6
Source File: EntityFirework.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public EntityFirework(FullChunk chunk, CompoundTag nbt) {
    super(chunk, nbt);

    this.fireworkAge = 0;
    Random rand = new Random();
    this.lifetime = 30 + rand.nextInt(6) + rand.nextInt(7);

    this.motionX = rand.nextGaussian() * 0.001D;
    this.motionZ = rand.nextGaussian() * 0.001D;
    this.motionY = 0.05D;

    if (nbt.contains("FireworkItem")) {
        firework = NBTIO.getItemHelper(nbt.getCompound("FireworkItem"));
    } else {
        firework = new ItemFirework();
    }

    this.setDataProperty(new NBTEntityData(Entity.DATA_DISPLAY_ITEM, firework.getNamedTag()));
    this.setDataProperty(new IntEntityData(Entity.DATA_DISPLAY_OFFSET, 1));
    this.setDataProperty(new ByteEntityData(Entity.DATA_HAS_DISPLAY, 1));
}
 
Example #7
Source File: EntityBoat.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
    public boolean mountEntity(Entity entity) {
        boolean player = this.passengers.size() >= 1 && this.passengers.get(0) instanceof Player;
        byte mode = SetEntityLinkPacket.TYPE_PASSENGER;

        if (!player && (entity instanceof Player || this.passengers.size() == 0)) {
            mode = SetEntityLinkPacket.TYPE_RIDE;
        }

        boolean r = super.mountEntity(entity, mode);

        if (entity.riding != null) {
            updatePassengers(true);

            entity.setDataProperty(new ByteEntityData(DATA_RIDER_ROTATION_LOCKED, 1));
            entity.setDataProperty(new FloatEntityData(DATA_RIDER_MAX_ROTATION, 90));

            entity.setDataProperty(new FloatEntityData(DATA_RIDER_MIN_ROTATION, this.passengers.indexOf(entity) == 1 ? -90 : 0));

            //            if(entity instanceof Player && mode == SetEntityLinkPacket.TYPE_RIDE){ //TODO: controlling?
//                entity.setDataProperty(new ByteEntityData(DATA_FLAG_WASD_CONTROLLED))
//            }
        }

        return r;
    }
 
Example #8
Source File: EntityCreeper.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public void setPowered(boolean powered) {
    CreeperPowerEvent ev = new CreeperPowerEvent(this, powered ? CreeperPowerEvent.PowerCause.SET_ON : CreeperPowerEvent.PowerCause.SET_OFF);
    this.getServer().getPluginManager().callEvent(ev);

    if (!ev.isCancelled()) {
        this.setDataProperty(new ByteEntityData(DATA_POWERED, powered ? 1 : 0));
        this.namedTag.putBoolean("powered", powered);
    }
}
 
Example #9
Source File: EntityTameable.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void setSitting(boolean flag) {
    int var = getDataPropertyByte(DATA_TAMED_FLAG); // ?

    if (flag) {
        setDataProperty(new ByteEntityData(DATA_TAMED_FLAG, (byte) (var | 1)));
    } else {
        setDataProperty(new ByteEntityData(DATA_TAMED_FLAG, (byte) (var & -2)));
    }
}
 
Example #10
Source File: EntityTameable.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void setTamed(boolean flag) {
    int var = getDataPropertyByte(DATA_TAMED_FLAG); // ?

    if (flag) {
        setDataProperty(new ByteEntityData(DATA_TAMED_FLAG, (byte) (var | 4)));
    } else {
        setDataProperty(new ByteEntityData(DATA_TAMED_FLAG, (byte) (var & -5)));
    }
}
 
Example #11
Source File: EntityCreeper.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void setPowered(boolean powered) {
    CreeperPowerEvent ev = new CreeperPowerEvent(this, powered ? CreeperPowerEvent.PowerCause.SET_ON : CreeperPowerEvent.PowerCause.SET_OFF);
    this.getServer().getPluginManager().callEvent(ev);

    if (!ev.isCancelled()) {
        this.setDataProperty(new ByteEntityData(DATA_POWERED, powered ? 1 : 0));
        this.namedTag.putBoolean("powered", powered);
    }
}
 
Example #12
Source File: EntityCreeper.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void setPowered(EntityLightningStrike bolt) {
    CreeperPowerEvent ev = new CreeperPowerEvent(this, bolt, CreeperPowerEvent.PowerCause.LIGHTNING);
    this.getServer().getPluginManager().callEvent(ev);

    if (!ev.isCancelled()) {
        this.setDataProperty(new ByteEntityData(DATA_POWERED, 1));
        this.namedTag.putBoolean("powered", true);
    }
}
 
Example #13
Source File: EntityTameable.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void setSitting(boolean flag) {
    int var = getDataPropertyByte(DATA_TAMED_FLAG); // ?

    if (flag) {
        setDataProperty(new ByteEntityData(DATA_TAMED_FLAG, (byte) (var | 1)));
    } else {
        setDataProperty(new ByteEntityData(DATA_TAMED_FLAG, (byte) (var & -2)));
    }
}
 
Example #14
Source File: EntityTameable.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void setTamed(boolean flag) {
    int var = getDataPropertyByte(DATA_TAMED_FLAG); // ?

    if (flag) {
        setDataProperty(new ByteEntityData(DATA_TAMED_FLAG, (byte) (var | 4)));
    } else {
        setDataProperty(new ByteEntityData(DATA_TAMED_FLAG, (byte) (var & -5)));
    }
}
 
Example #15
Source File: EntityBoat.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean dismountEntity(Entity entity) {
    boolean r = super.dismountEntity(entity);

    updatePassengers();
    entity.setDataProperty(new ByteEntityData(DATA_RIDER_ROTATION_LOCKED, 0));

    return r;
}
 
Example #16
Source File: EntityMinecartAbstract.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Set the minecart display block
 *
 * @param block The block that will changed. Set {@code null} for BlockAir
 * @param update Do update for the block. (This state changes if you want to show the block)
 * @return {@code true} if the block is normal block
 */
@API(usage = Usage.MAINTAINED, definition = Definition.UNIVERSAL)
public boolean setDisplayBlock(Block block, boolean update) {
    if(!update){
        if (block.isNormalBlock()) {
            blockInside = block;
        } else {
            blockInside = null;
        }
        return true;
    }
    if (block != null) {
        if (block.isNormalBlock()) {
            blockInside = block;
            int display = blockInside.getId()
                    | blockInside.getDamage() << 16;
            setDataProperty(new ByteEntityData(DATA_HAS_DISPLAY, 1));
            setDataProperty(new IntEntityData(DATA_DISPLAY_ITEM, display));
            setDisplayBlockOffset(6);
        }
    } else {
        // Set block to air (default).
        blockInside = null;
        setDataProperty(new ByteEntityData(DATA_HAS_DISPLAY, 0));
        setDataProperty(new IntEntityData(DATA_DISPLAY_ITEM, 0));
        setDisplayBlockOffset(0);
    }
    return true;
}
 
Example #17
Source File: EntityCreeper.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void setPowered(boolean powered) {
    CreeperPowerEvent ev = new CreeperPowerEvent(this, powered ? CreeperPowerEvent.PowerCause.SET_ON : CreeperPowerEvent.PowerCause.SET_OFF);
    this.getServer().getPluginManager().callEvent(ev);

    if (!ev.isCancelled()) {
        this.setDataProperty(new ByteEntityData(DATA_POWERED, powered ? 1 : 0));
        this.namedTag.putBoolean("powered", powered);
    }
}
 
Example #18
Source File: EntityCreeper.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void setPowered(EntityLightningStrike bolt) {
    CreeperPowerEvent ev = new CreeperPowerEvent(this, bolt, CreeperPowerEvent.PowerCause.LIGHTNING);
    this.getServer().getPluginManager().callEvent(ev);

    if (!ev.isCancelled()) {
        this.setDataProperty(new ByteEntityData(DATA_POWERED, 1));
        this.namedTag.putBoolean("powered", true);
    }
}
 
Example #19
Source File: EntityTameable.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public void setSitting(boolean flag) {
    int var = getDataPropertyByte(DATA_TAMED_FLAG); // ?

    if (flag) {
        setDataProperty(new ByteEntityData(DATA_TAMED_FLAG, (byte) (var | 1)));
    } else {
        setDataProperty(new ByteEntityData(DATA_TAMED_FLAG, (byte) (var & -2)));
    }
}
 
Example #20
Source File: EntityTameable.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public void setTamed(boolean flag) {
    int var = getDataPropertyByte(DATA_TAMED_FLAG); // ?

    if (flag) {
        setDataProperty(new ByteEntityData(DATA_TAMED_FLAG, (byte) (var | 4)));
    } else {
        setDataProperty(new ByteEntityData(DATA_TAMED_FLAG, (byte) (var & -5)));
    }
}
 
Example #21
Source File: Entity.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
protected void recalculateEffectColor() {
    int[] color = new int[3];
    int count = 0;
    boolean ambient = true;
    for (Effect effect : this.effects.values()) {
        if (effect.isVisible()) {
            int[] c = effect.getColor();
            color[0] += c[0] * (effect.getAmplifier() + 1);
            color[1] += c[1] * (effect.getAmplifier() + 1);
            color[2] += c[2] * (effect.getAmplifier() + 1);
            count += effect.getAmplifier() + 1;
            if (!effect.isAmbient()) {
                ambient = false;
            }
        }
    }

    if (count > 0) {
        int r = (color[0] / count) & 0xff;
        int g = (color[1] / count) & 0xff;
        int b = (color[2] / count) & 0xff;

        this.setDataProperty(new IntEntityData(Entity.DATA_POTION_COLOR, (r << 16) + (g << 8) + b));
        this.setDataProperty(new ByteEntityData(Entity.DATA_POTION_AMBIENT, ambient ? 1 : 0));
    } else {
        this.setDataProperty(new IntEntityData(Entity.DATA_POTION_COLOR, 0));
        this.setDataProperty(new ByteEntityData(Entity.DATA_POTION_AMBIENT, 0));
    }
}
 
Example #22
Source File: EntityCreeper.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public void setPowered(EntityLightningStrike bolt) {
    CreeperPowerEvent ev = new CreeperPowerEvent(this, bolt, CreeperPowerEvent.PowerCause.LIGHTNING);
    this.getServer().getPluginManager().callEvent(ev);

    if (!ev.isCancelled()) {
        this.setDataProperty(new ByteEntityData(DATA_POWERED, 1));
        this.namedTag.putBoolean("powered", true);
    }
}
 
Example #23
Source File: EntitySheep.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public void setColor(int color) {
    this.color = color;
    this.setDataProperty(new ByteEntityData(DATA_COLOUR, color));
    this.namedTag.putByte("Color", this.color);
}
 
Example #24
Source File: Binary.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public static byte[] writeMetadata(EntityMetadata metadata) {
    BinaryStream stream = new BinaryStream();
    Map<Integer, EntityData> map = metadata.getMap();
    stream.putUnsignedVarInt(map.size());
    for (int id : map.keySet()) {
        EntityData d = map.get(id);
        stream.putUnsignedVarInt(id);
        stream.putUnsignedVarInt(d.getType());
        switch (d.getType()) {
            case Entity.DATA_TYPE_BYTE:
                stream.putByte(((ByteEntityData) d).getData().byteValue());
                break;
            case Entity.DATA_TYPE_SHORT:
                stream.putLShort(((ShortEntityData) d).getData());
                break;
            case Entity.DATA_TYPE_INT:
                stream.putVarInt(((IntEntityData) d).getData());
                break;
            case Entity.DATA_TYPE_FLOAT:
                stream.putLFloat(((FloatEntityData) d).getData());
                break;
            case Entity.DATA_TYPE_STRING:
                String s = ((StringEntityData) d).getData();
                stream.putUnsignedVarInt(s.getBytes(StandardCharsets.UTF_8).length);
                stream.put(s.getBytes(StandardCharsets.UTF_8));
                break;
            case Entity.DATA_TYPE_SLOT:
                SlotEntityData slot = (SlotEntityData) d;
                stream.putLShort(slot.blockId);
                stream.putByte((byte) slot.meta);
                stream.putLShort(slot.count);
                break;
            case Entity.DATA_TYPE_POS:
                IntPositionEntityData pos = (IntPositionEntityData) d;
                stream.putVarInt(pos.x);
                stream.putByte((byte) pos.y);
                stream.putVarInt(pos.z);
                break;
            case Entity.DATA_TYPE_LONG:
                stream.putVarLong(((LongEntityData) d).getData());
                break;
            case Entity.DATA_TYPE_VECTOR3F:
                Vector3fEntityData v3data = (Vector3fEntityData) d;
                stream.putLFloat(v3data.x);
                stream.putLFloat(v3data.y);
                stream.putLFloat(v3data.z);
                break;
        }
    }
    return stream.getBuffer();
}
 
Example #25
Source File: EntitySheep.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public void setColor(int color) {
    this.color = color;
    this.setDataProperty(new ByteEntityData(DATA_COLOUR, color));
}
 
Example #26
Source File: EntitySheep.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public void setColor(int color) {
    this.color = color;
    this.setDataProperty(new ByteEntityData(DATA_COLOUR, color));
    this.namedTag.putByte("Color", this.color);
}