cn.nukkit.entity.data.IntEntityData Java Examples
The following examples show how to use
cn.nukkit.entity.data.IntEntityData.
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: EntityFallingBlock.java From Nukkit with GNU General Public License v3.0 | 6 votes |
@Override protected void initEntity() { super.initEntity(); if (namedTag != null) { if (namedTag.contains("TileID")) { blockId = namedTag.getInt("TileID"); } else if (namedTag.contains("Tile")) { blockId = namedTag.getInt("Tile"); namedTag.putInt("TileID", blockId); } if (namedTag.contains("Data")) { damage = namedTag.getByte("Data"); } } if (blockId == 0) { close(); return; } setDataProperty(new IntEntityData(DATA_VARIANT, this.getBlock() | this.getDamage() << 8)); }
Example #2
Source File: EntityMinecartAbstract.java From Nukkit with GNU General Public License v3.0 | 6 votes |
/** * 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 #3
Source File: EntityFallingBlock.java From Nukkit with GNU General Public License v3.0 | 6 votes |
@Override protected void initEntity() { super.initEntity(); if (namedTag != null) { if (namedTag.contains("TileID")) { blockId = namedTag.getInt("TileID"); } else if (namedTag.contains("Tile")) { blockId = namedTag.getInt("Tile"); namedTag.putInt("TileID", blockId); } if (namedTag.contains("Data")) { damage = namedTag.getByte("Data"); } } if (blockId == 0) { close(); return; } this.fireProof = true; setDataProperty(new IntEntityData(DATA_VARIANT, GlobalBlockPalette.getOrCreateRuntimeId(this.getBlock(), this.getDamage()))); }
Example #4
Source File: EntityMinecartAbstract.java From Jupiter with GNU General Public License v3.0 | 6 votes |
/** * 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 #5
Source File: EntityFirework.java From Nukkit with GNU General Public License v3.0 | 6 votes |
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 #6
Source File: EntityFallingBlock.java From Jupiter with GNU General Public License v3.0 | 6 votes |
@Override protected void initEntity() { super.initEntity(); if (namedTag != null) { if (namedTag.contains("TileID")) { blockId = namedTag.getInt("TileID"); } else if (namedTag.contains("Tile")) { blockId = namedTag.getInt("Tile"); namedTag.putInt("TileID", blockId); } if (namedTag.contains("Data")) { damage = namedTag.getByte("Data"); } } if (blockId == 0) { close(); return; } setDataProperty(new IntEntityData(DATA_VARIANT, this.getBlock() | this.getDamage() << 8)); }
Example #7
Source File: EntityPrimedTNT.java From Nukkit with GNU General Public License v3.0 | 5 votes |
protected void initEntity() { super.initEntity(); if (namedTag.contains("Fuse")) { fuse = namedTag.getByte("Fuse"); } else { fuse = 80; } this.setDataFlag(DATA_FLAGS, DATA_FLAG_IGNITED, true); this.setDataProperty(new IntEntityData(DATA_FUSE_LENGTH, fuse)); this.getLevel().addLevelSoundEvent(this, LevelSoundEventPacket.SOUND_FIZZ); }
Example #8
Source File: EntityPrimedTNT.java From Nukkit with GNU General Public License v3.0 | 5 votes |
protected void initEntity() { super.initEntity(); if (namedTag.contains("Fuse")) { fuse = namedTag.getByte("Fuse"); } else { fuse = 80; } this.setDataFlag(DATA_FLAGS, DATA_FLAG_IGNITED, true); this.setDataProperty(new IntEntityData(DATA_FUSE_LENGTH, fuse)); this.level.addSound(this, Sound.RANDOM_FIZZ); }
Example #9
Source File: EntityMinecartTNT.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean onUpdate(int currentTick) { this.timing.startTiming(); if (fuse < 80) { int tickDiff = currentTick - lastUpdate; lastUpdate = currentTick; if (fuse % 5 == 0) { setDataProperty(new IntEntityData(DATA_FUSE_LENGTH, fuse)); } fuse -= tickDiff; if (isAlive() && fuse <= 0) { if (this.level.getGameRules().getBoolean(GameRule.TNT_EXPLODES)) { this.explode(ThreadLocalRandom.current().nextInt(5)); } this.close(); return false; } } this.timing.stopTiming(); return super.onUpdate(currentTick); }
Example #10
Source File: EntityMinecartAbstract.java From Nukkit with GNU General Public License v3.0 | 5 votes |
/** * 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 #11
Source File: Entity.java From Jupiter with GNU General Public License v3.0 | 5 votes |
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 #12
Source File: EntityPrimedTNT.java From Jupiter with GNU General Public License v3.0 | 5 votes |
protected void initEntity() { super.initEntity(); if (namedTag.contains("Fuse")) { fuse = namedTag.getByte("Fuse"); } else { fuse = 80; } this.setDataFlag(DATA_FLAGS, DATA_FLAG_IGNITED, true); this.setDataProperty(new IntEntityData(DATA_FUSE_LENGTH, fuse)); }
Example #13
Source File: Binary.java From Jupiter with GNU General Public License v3.0 | 4 votes |
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 #14
Source File: EntityVehicle.java From Jupiter with GNU General Public License v3.0 | 4 votes |
public void setDamage(int damage) { this.setDataProperty(new IntEntityData(DATA_HEALTH, damage)); }
Example #15
Source File: EntityVehicle.java From Jupiter with GNU General Public License v3.0 | 4 votes |
public void setRollingDirection(int direction) { this.setDataProperty(new IntEntityData(DATA_HURT_DIRECTION, direction)); }
Example #16
Source File: EntityVehicle.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public void setDamage(int damage) { this.setDataProperty(new IntEntityData(DATA_HEALTH, damage)); }
Example #17
Source File: EntityVehicle.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public void setRollingAmplitude(int time) { this.setDataProperty(new IntEntityData(DATA_HURT_TIME, time)); }
Example #18
Source File: EntityVehicle.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public void setRollingDirection(int direction) { this.setDataProperty(new IntEntityData(DATA_HURT_DIRECTION, direction)); }
Example #19
Source File: EntityVehicle.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public void setDamage(int damage) { this.setDataProperty(new IntEntityData(DATA_HEALTH, damage)); }
Example #20
Source File: EntityVehicle.java From Jupiter with GNU General Public License v3.0 | 4 votes |
public void setRollingAmplitude(int time) { this.setDataProperty(new IntEntityData(DATA_HURT_TIME, time)); }
Example #21
Source File: EntityVehicle.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public void setRollingDirection(int direction) { this.setDataProperty(new IntEntityData(DATA_HURT_DIRECTION, direction)); }
Example #22
Source File: EntityVehicle.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public void setRollingAmplitude(int time) { this.setDataProperty(new IntEntityData(DATA_HURT_TIME, time)); }
Example #23
Source File: EntityMinecartAbstract.java From Jupiter with GNU General Public License v3.0 | 2 votes |
/** * Set the block offset. * * @param offset The offset */ public void setDisplayBlockOffset(int offset) { setDataProperty(new IntEntityData(DATA_MINECART_DISPLAY_OFFSET, offset)); }
Example #24
Source File: EntityPrimedTNT.java From Nukkit with GNU General Public License v3.0 | 2 votes |
public boolean onUpdate(int currentTick) { if (closed) { return false; } this.timing.startTiming(); int tickDiff = currentTick - lastUpdate; if (tickDiff <= 0 && !justCreated) { return true; } if (fuse % 5 == 0) { this.setDataProperty(new IntEntityData(DATA_FUSE_LENGTH, fuse)); } lastUpdate = currentTick; boolean hasUpdate = entityBaseTick(tickDiff); if (isAlive()) { motionY -= getGravity(); move(motionX, motionY, motionZ); float friction = 1 - getDrag(); motionX *= friction; motionY *= friction; motionZ *= friction; updateMovement(); if (onGround) { motionY *= -0.5; motionX *= 0.7; motionZ *= 0.7; } fuse -= tickDiff; if (fuse <= 0) { if (this.level.getGameRules().getBoolean(GameRule.TNT_EXPLODES)) explode(); kill(); } } this.timing.stopTiming(); return hasUpdate || fuse >= 0 || Math.abs(motionX) > 0.00001 || Math.abs(motionY) > 0.00001 || Math.abs(motionZ) > 0.00001; }
Example #25
Source File: EntityMinecartAbstract.java From Nukkit with GNU General Public License v3.0 | 2 votes |
/** * Set the block offset. * * @param offset The offset */ @API(usage = Usage.EXPERIMENTAL, definition = Definition.PLATFORM_NATIVE) public void setDisplayBlockOffset(int offset) { setDataProperty(new IntEntityData(DATA_MINECART_DISPLAY_OFFSET, offset)); }
Example #26
Source File: EntityPrimedTNT.java From Jupiter with GNU General Public License v3.0 | 2 votes |
public boolean onUpdate(int currentTick) { if (closed) { return false; } this.timing.startTiming(); int tickDiff = currentTick - lastUpdate; if (tickDiff <= 0 && !justCreated) { return true; } if (fuse % 5 == 0) { this.setDataProperty(new IntEntityData(DATA_FUSE_LENGTH, fuse)); } lastUpdate = currentTick; boolean hasUpdate = entityBaseTick(tickDiff); if (isAlive()) { motionY -= getGravity(); move(motionX, motionY, motionZ); float friction = 1 - getDrag(); motionX *= friction; motionY *= friction; motionZ *= friction; updateMovement(); if (onGround) { motionY *= -0.5; motionX *= 0.7; motionZ *= 0.7; } fuse -= tickDiff; if (fuse <= 0) { explode(); kill(); } } this.timing.stopTiming(); return hasUpdate || fuse >= 0 || Math.abs(motionX) > 0.00001 || Math.abs(motionY) > 0.00001 || Math.abs(motionZ) > 0.00001; }
Example #27
Source File: EntityPrimedTNT.java From Nukkit with GNU General Public License v3.0 | 2 votes |
public boolean onUpdate(int currentTick) { if (closed) { return false; } this.timing.startTiming(); int tickDiff = currentTick - lastUpdate; if (tickDiff <= 0 && !justCreated) { return true; } if (fuse % 5 == 0) { this.setDataProperty(new IntEntityData(DATA_FUSE_LENGTH, fuse)); } lastUpdate = currentTick; boolean hasUpdate = entityBaseTick(tickDiff); if (isAlive()) { motionY -= getGravity(); move(motionX, motionY, motionZ); float friction = 1 - getDrag(); motionX *= friction; motionY *= friction; motionZ *= friction; updateMovement(); if (onGround) { motionY *= -0.5; motionX *= 0.7; motionZ *= 0.7; } fuse -= tickDiff; if (fuse <= 0) { if (this.level.getGameRules().getBoolean(GameRule.TNT_EXPLODES)) explode(); kill(); } } this.timing.stopTiming(); return hasUpdate || fuse >= 0 || Math.abs(motionX) > 0.00001 || Math.abs(motionY) > 0.00001 || Math.abs(motionZ) > 0.00001; }
Example #28
Source File: EntityMinecartAbstract.java From Nukkit with GNU General Public License v3.0 | 2 votes |
/** * Set the block offset. * * @param offset The offset */ @API(usage = Usage.EXPERIMENTAL, definition = Definition.PLATFORM_NATIVE) public void setDisplayBlockOffset(int offset) { setDataProperty(new IntEntityData(DATA_DISPLAY_OFFSET, offset)); }