file_name
stringlengths
6
86
file_path
stringlengths
45
249
content
stringlengths
47
6.26M
file_size
int64
47
6.26M
language
stringclasses
1 value
extension
stringclasses
1 value
repo_name
stringclasses
767 values
repo_stars
int64
8
14.4k
repo_forks
int64
0
1.17k
repo_open_issues
int64
0
788
repo_created_at
stringclasses
767 values
repo_pushed_at
stringclasses
767 values
Vector3fEntityData.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/data/Vector3fEntityData.java
package cn.nukkit.entity.data; import cn.nukkit.entity.Entity; import cn.nukkit.math.Vector3f; /** * author: MagicDroidX * Nukkit Project */ public class Vector3fEntityData extends EntityData<Vector3f> { public float x; public float y; public float z; public Vector3fEntityData(int id, float x, float y, float z) { super(id); this.x = x; this.y = y; this.z = z; } public Vector3fEntityData(int id, Vector3f pos) { this(id, pos.x, pos.y, pos.z); } @Override public Vector3f getData() { return new Vector3f(x, y, z); } @Override public void setData(Vector3f data) { if (data != null) { this.x = data.x; this.y = data.y; this.z = data.z; } } @Override public int getType() { return Entity.DATA_TYPE_VECTOR3F; } }
892
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
SlotEntityData.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/data/SlotEntityData.java
package cn.nukkit.entity.data; import cn.nukkit.entity.Entity; import cn.nukkit.item.Item; /** * author: MagicDroidX * Nukkit Project */ public class SlotEntityData extends EntityData<Item> { public int blockId; public int meta; public int count; public SlotEntityData(int id, int blockId, int meta, int count) { super(id); this.blockId = blockId; this.meta = meta; this.count = count; } public SlotEntityData(int id, Item item) { this(id, item.getId(), (byte) (item.hasMeta() ? item.getDamage() : 0), item.getCount()); } @Override public Item getData() { return Item.get(blockId, meta, count); } @Override public void setData(Item data) { this.blockId = data.getId(); this.meta = (data.hasMeta() ? data.getDamage() : 0); this.count = data.getCount(); } @Override public int getType() { return Entity.DATA_TYPE_SLOT; } }
975
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
IntPositionEntityData.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/data/IntPositionEntityData.java
package cn.nukkit.entity.data; import cn.nukkit.entity.Entity; import cn.nukkit.math.BlockVector3; import cn.nukkit.math.Vector3; /** * author: MagicDroidX * Nukkit Project */ public class IntPositionEntityData extends EntityData<BlockVector3> { public int x; public int y; public int z; public IntPositionEntityData(int id, int x, int y, int z) { super(id); this.x = x; this.y = y; this.z = z; } public IntPositionEntityData(int id, Vector3 pos) { this(id, (int) pos.x, (int) pos.y, (int) pos.z); } @Override public BlockVector3 getData() { return new BlockVector3(x, y, z); } @Override public void setData(BlockVector3 data) { if (data != null) { this.x = data.x; this.y = data.y; this.z = data.z; } } @Override public int getType() { return Entity.DATA_TYPE_POS; } }
952
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
LongEntityData.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/data/LongEntityData.java
package cn.nukkit.entity.data; import cn.nukkit.entity.Entity; /** * author: MagicDroidX * Nukkit Project */ public class LongEntityData extends EntityData<Long> { public long data; public LongEntityData(int id, long data) { super(id); this.data = data; } public Long getData() { return data; } public void setData(Long data) { this.data = data; } @Override public int getType() { return Entity.DATA_TYPE_LONG; } }
504
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
ShortEntityData.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/data/ShortEntityData.java
package cn.nukkit.entity.data; import cn.nukkit.entity.Entity; /** * author: MagicDroidX * Nukkit Project */ public class ShortEntityData extends EntityData<Integer> { public int data; public ShortEntityData(int id, int data) { super(id); this.data = data; } public Integer getData() { return data; } public void setData(Integer data) { if (data == null) { this.data = 0; } else { this.data = data; } } @Override public int getType() { return Entity.DATA_TYPE_SHORT; } }
600
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
FloatEntityData.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/data/FloatEntityData.java
package cn.nukkit.entity.data; import cn.nukkit.entity.Entity; /** * author: MagicDroidX * Nukkit Project */ public class FloatEntityData extends EntityData<Float> { public float data; public FloatEntityData(int id, float data) { super(id); this.data = data; } public Float getData() { return data; } public void setData(Float data) { if (data == null) { this.data = 0; } else { this.data = data; } } @Override public int getType() { return Entity.DATA_TYPE_FLOAT; } }
599
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
StringEntityData.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/data/StringEntityData.java
package cn.nukkit.entity.data; import cn.nukkit.entity.Entity; /** * author: MagicDroidX * Nukkit Project */ public class StringEntityData extends EntityData<String> { public String data; public StringEntityData(int id, String data) { super(id); this.data = data; } public String getData() { return data; } public void setData(String data) { this.data = data; } @Override public int getType() { return Entity.DATA_TYPE_STRING; } @Override public String toString() { return data; } }
593
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
Skin.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/data/Skin.java
package cn.nukkit.entity.data; import javax.imageio.ImageIO; import javax.imageio.stream.ImageInputStream; import java.awt.*; import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.util.Base64; /** * author: MagicDroidX * Nukkit Project */ public class Skin { public static final int SINGLE_SKIN_SIZE = 64 * 32 * 4; public static final int DOUBLE_SKIN_SIZE = 64 * 64 * 4; public static final String MODEL_STEVE = "Standard_Steve"; public static final String MODEL_ALEX = "Standard_Alex"; private byte[] data = new byte[SINGLE_SKIN_SIZE]; private String model; private Cape cape = new Cape(new byte[0]); //default no cape public Skin(byte[] data) { this(data, MODEL_STEVE); } public Skin(InputStream inputStream) { this(inputStream, MODEL_STEVE); } public Skin(ImageInputStream inputStream) { this(inputStream, MODEL_STEVE); } public Skin(File file) { this(file, MODEL_STEVE); } public Skin(URL url) { this(url, MODEL_STEVE); } public Skin(BufferedImage image) { this(image, MODEL_STEVE); } public Skin(byte[] data, String model) { this.setData(data); this.setModel(model); } public Skin(InputStream inputStream, String model) { BufferedImage image; try { image = ImageIO.read(inputStream); } catch (IOException e) { throw new RuntimeException(e); } this.parseBufferedImage(image); this.setModel(model); } public Skin(ImageInputStream inputStream, String model) { BufferedImage image; try { image = ImageIO.read(inputStream); } catch (IOException e) { throw new RuntimeException(e); } this.parseBufferedImage(image); this.setModel(model); } public Skin(File file, String model) { BufferedImage image; try { image = ImageIO.read(file); } catch (IOException e) { throw new RuntimeException(e); } this.parseBufferedImage(image); this.setModel(model); } public Skin(URL url, String model) { BufferedImage image; try { image = ImageIO.read(url); } catch (IOException e) { throw new RuntimeException(e); } this.parseBufferedImage(image); this.setModel(model); } public Skin(BufferedImage image, String model) { this.parseBufferedImage(image); this.setModel(model); } public Skin(String base64) { this(Base64.getDecoder().decode(base64)); } public Skin(String base64, String model) { this(Base64.getDecoder().decode(base64), model); } public void parseBufferedImage(BufferedImage image) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); for (int y = 0; y < image.getHeight(); y++) { for (int x = 0; x < image.getWidth(); x++) { Color color = new Color(image.getRGB(x, y), true); outputStream.write(color.getRed()); outputStream.write(color.getGreen()); outputStream.write(color.getBlue()); outputStream.write(color.getAlpha()); } } image.flush(); this.setData(outputStream.toByteArray()); } public byte[] getData() { return data; } public String getModel() { return model; } public void setData(byte[] data) { if (data.length != SINGLE_SKIN_SIZE && data.length != DOUBLE_SKIN_SIZE) { throw new IllegalArgumentException("Invalid skin"); } this.data = data; } public void setModel(String model) { if (model == null || model.trim().isEmpty()) { model = MODEL_STEVE; } this.model = model; } public Cape getCape() { return cape; } public void setCape(Cape cape) { this.cape = cape; } public boolean isValid() { return this.data.length == SINGLE_SKIN_SIZE || this.data.length == DOUBLE_SKIN_SIZE; } public class Cape { public byte[] data; public Cape(byte[] data) { this.setData(data); } public Cape(InputStream inputStream) { BufferedImage image; try { image = ImageIO.read(inputStream); } catch (IOException e) { throw new RuntimeException(e); } this.parseBufferedImage(image); } public Cape(ImageInputStream inputStream) { BufferedImage image; try { image = ImageIO.read(inputStream); } catch (IOException e) { throw new RuntimeException(e); } this.parseBufferedImage(image); } public Cape(File file, String model) { BufferedImage image; try { image = ImageIO.read(file); } catch (IOException e) { throw new RuntimeException(e); } this.parseBufferedImage(image); } public Cape(URL url) { BufferedImage image; try { image = ImageIO.read(url); } catch (IOException e) { throw new RuntimeException(e); } this.parseBufferedImage(image); } public Cape(BufferedImage image) { this.parseBufferedImage(image); } public Cape(String base64) { this(Base64.getDecoder().decode(base64)); } public void setData(byte[] data) { this.data = data; } public byte[] getData() { return data; } public void parseBufferedImage(BufferedImage image) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); for (int y = 0; y < image.getHeight(); y++) { for (int x = 0; x < image.getWidth(); x++) { Color color = new Color(image.getRGB(x, y), true); outputStream.write(color.getRed()); outputStream.write(color.getGreen()); outputStream.write(color.getBlue()); outputStream.write(color.getAlpha()); } } image.flush(); this.setData(outputStream.toByteArray()); } } }
6,673
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
IntEntityData.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/data/IntEntityData.java
package cn.nukkit.entity.data; import cn.nukkit.entity.Entity; /** * author: MagicDroidX * Nukkit Project */ public class IntEntityData extends EntityData<Integer> { public int data; public IntEntityData(int id, int data) { super(id); this.data = data; } public Integer getData() { return data; } public void setData(Integer data) { if (data == null) { this.data = 0; } else { this.data = data; } } @Override public int getType() { return Entity.DATA_TYPE_INT; } }
594
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
ByteEntityData.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/data/ByteEntityData.java
package cn.nukkit.entity.data; import cn.nukkit.entity.Entity; /** * author: MagicDroidX * Nukkit Project */ public class ByteEntityData extends EntityData<Integer> { public int data; public ByteEntityData(int id, int data) { super(id); this.data = data; } public Integer getData() { return data; } public void setData(Integer data) { if (data == null) { this.data = 0; } else { this.data = data; } } @Override public int getType() { return Entity.DATA_TYPE_BYTE; } }
597
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityMetadata.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/data/EntityMetadata.java
package cn.nukkit.entity.data; import cn.nukkit.block.BlockAir; import cn.nukkit.item.Item; import cn.nukkit.item.ItemBlock; import cn.nukkit.math.Vector3; import java.util.HashMap; import java.util.Map; /** * author: MagicDroidX * Nukkit Project */ public class EntityMetadata { private final Map<Integer, EntityData> map = new HashMap<>(); public EntityData get(int id) { return this.getOrDefault(id, null); } public EntityData getOrDefault(int id, EntityData defaultValue) { try { return this.map.getOrDefault(id, defaultValue).setId(id); } catch (Exception e) { if (defaultValue != null) { return defaultValue.setId(id); } return null; } } public boolean exists(int id) { return this.map.containsKey(id); } public EntityMetadata put(EntityData data) { this.map.put(data.getId(), data); return this; } public int getByte(int id) { return (int) this.getOrDefault(id, new ByteEntityData(id, 0)).getData() & 0xff; } public int getShort(int id) { return (int) this.getOrDefault(id, new ShortEntityData(id, 0)).getData(); } public int getInt(int id) { return (int) this.getOrDefault(id, new IntEntityData(id, 0)).getData(); } public long getLong(int id) { return (Long) this.getOrDefault(id, new LongEntityData(id, 0)).getData(); } public float getFloat(int id) { return (float) this.getOrDefault(id, new FloatEntityData(id, 0)).getData(); } public boolean getBoolean(int id) { return this.getByte(id) == 1; } public Item getSlot(int id) { return (Item) this.getOrDefault(id, new SlotEntityData(id, new ItemBlock(new BlockAir()))).getData(); } public String getString(int id) { return (String) this.getOrDefault(id, new StringEntityData(id, "")).getData(); } public Vector3 getPosition(int id) { return (Vector3) this.getOrDefault(id, new IntPositionEntityData(id, new Vector3())).getData(); } public EntityMetadata putByte(int id, int value) { return this.put(new ByteEntityData(id, value)); } public EntityMetadata putShort(int id, int value) { return this.put(new ShortEntityData(id, value)); } public EntityMetadata putInt(int id, int value) { return this.put(new IntEntityData(id, value)); } public EntityMetadata putLong(int id, long value) { return this.put(new LongEntityData(id, value)); } public EntityMetadata putFloat(int id, float value) { return this.put(new FloatEntityData(id, value)); } public EntityMetadata putBoolean(int id, boolean value) { return this.putByte(id, value ? 1 : 0); } public EntityMetadata putSlot(int id, int blockId, int meta, int count) { return this.put(new SlotEntityData(id, blockId, (byte) meta, count)); } public EntityMetadata putSlot(int id, Item value) { return this.put(new SlotEntityData(id, value)); } public EntityMetadata putString(int id, String value) { return this.put(new StringEntityData(id, value)); } public Map<Integer, EntityData> getMap() { return new HashMap<>(map); } }
3,322
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityWeather.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/weather/EntityWeather.java
package cn.nukkit.entity.weather; /** * Created by boybook on 2016/2/27. */ public interface EntityWeather { }
114
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityLightningStrike.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/weather/EntityLightningStrike.java
package cn.nukkit.entity.weather; /** * Created by funcraft on 2016/2/27. */ public interface EntityLightningStrike extends EntityWeather { boolean isEffect(); void setEffect(boolean e); }
203
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityLightning.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/weather/EntityLightning.java
package cn.nukkit.entity.weather; import cn.nukkit.Player; import cn.nukkit.block.Block; import cn.nukkit.block.BlockFire; import cn.nukkit.entity.Entity; import cn.nukkit.event.block.BlockIgniteEvent; import cn.nukkit.event.entity.EntityDamageEvent; import cn.nukkit.level.GameRule; import cn.nukkit.level.format.FullChunk; import cn.nukkit.math.AxisAlignedBB; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; import cn.nukkit.network.protocol.LevelSoundEventPacket; import java.util.concurrent.ThreadLocalRandom; /** * Created by boybook on 2016/2/27. */ public class EntityLightning extends Entity implements EntityLightningStrike { public static final int NETWORK_ID = 93; protected boolean isEffect = true; public int state; public int liveTime; @Override public int getNetworkId() { return NETWORK_ID; } public EntityLightning(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override protected void initEntity() { super.initEntity(); this.setHealth(4); this.setMaxHealth(4); this.state = 2; this.liveTime = ThreadLocalRandom.current().nextInt(3) + 1; if (isEffect && this.level.gameRules.getBoolean(GameRule.DO_FIRE_TICK) && (this.server.getDifficulty() >= 2)) { Block block = this.getLevelBlock(); if (block.getId() == 0 || block.getId() == Block.TALL_GRASS) { BlockFire fire = new BlockFire(); fire.x = block.x; fire.y = block.y; fire.z = block.z; fire.level = level; this.getLevel().setBlock(fire, fire, true); if (fire.isBlockTopFacingSurfaceSolid(fire.down()) || fire.canNeighborBurn()) { BlockIgniteEvent e = new BlockIgniteEvent(block, null, this, BlockIgniteEvent.BlockIgniteCause.LIGHTNING); getServer().getPluginManager().callEvent(e); if (!e.isCancelled()) { level.setBlock(fire, fire, true); level.scheduleUpdate(fire, fire.tickRate() + ThreadLocalRandom.current().nextInt(10)); } } } } } public boolean isEffect() { return this.isEffect; } public void setEffect(boolean e) { this.isEffect = e; } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.type = EntityLightning.NETWORK_ID; pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = 0; pk.speedY = 0; pk.speedZ = 0; pk.yaw = (float) this.yaw; pk.pitch = (float) this.pitch; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } @Override public boolean attack(EntityDamageEvent source) { //false? source.setDamage(0); return super.attack(source); } @Override public boolean onUpdate(int currentTick) { if (this.closed) { return false; } int tickDiff = currentTick - this.lastUpdate; if (tickDiff <= 0 && !this.justCreated) { return true; } this.lastUpdate = currentTick; this.entityBaseTick(tickDiff); if (this.state == 2) { this.level.addLevelSoundEvent(this, LevelSoundEventPacket.SOUND_THUNDER, 93, -1); this.level.addLevelSoundEvent(this, LevelSoundEventPacket.SOUND_EXPLODE, 93, -1); } this.state--; if (this.state < 0) { if (this.liveTime == 0) { this.close(); return false; } else if (this.state < -ThreadLocalRandom.current().nextInt(10)) { this.liveTime--; this.state = 1; if (this.isEffect && this.level.gameRules.getBoolean(GameRule.DO_FIRE_TICK)) { Block block = this.getLevelBlock(); if (block.getId() == Block.AIR || block.getId() == Block.TALL_GRASS) { BlockIgniteEvent e = new BlockIgniteEvent(block, null, this, BlockIgniteEvent.BlockIgniteCause.LIGHTNING); getServer().getPluginManager().callEvent(e); if (!e.isCancelled()) { Block fire = new BlockFire(); this.level.setBlock(block, fire); this.getLevel().scheduleUpdate(fire, fire.tickRate()); } } } } } if (this.state >= 0) { if (this.isEffect) { AxisAlignedBB bb = getBoundingBox().grow(3, 3, 3); bb.setMaxX(bb.getMaxX() + 6); for (Entity entity : this.level.getCollidingEntities(bb, this)) { entity.onStruckByLightning(this); } } } return true; } }
5,220
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityGuardian.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/mob/EntityGuardian.java
package cn.nukkit.entity.mob; import cn.nukkit.Player; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; /** * @author PikyCZ */ public class EntityGuardian extends EntityMob { public static final int NETWORK_ID = 49; @Override public int getNetworkId() { return NETWORK_ID; } public EntityGuardian(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override public void initEntity() { super.initEntity(); this.setMaxHealth(30); } @Override public String getName() { return "Guardian"; } @Override public float getWidth() { return 0.85f; } @Override public float getHeight() { return 0.85f; } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } }
1,384
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityZombie.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/mob/EntityZombie.java
package cn.nukkit.entity.mob; import cn.nukkit.Player; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; /** * Created by Dr. Nick Doran on 4/23/2017. */ public class EntityZombie extends EntityMob { public static final int NETWORK_ID = 32; @Override public int getNetworkId() { return NETWORK_ID; } public EntityZombie(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override protected void initEntity() { super.initEntity(); this.setMaxHealth(20); } @Override public float getWidth() { return 0.6f; } @Override public float getHeight() { return 1.95f; } @Override public String getName() { return "Zombie"; } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } }
1,405
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityMob.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/mob/EntityMob.java
package cn.nukkit.entity.mob; import cn.nukkit.entity.EntityCreature; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; /** * author: MagicDroidX * Nukkit Project */ public abstract class EntityMob extends EntityCreature { public EntityMob(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } }
350
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityMagmaCube.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/mob/EntityMagmaCube.java
package cn.nukkit.entity.mob; import cn.nukkit.Player; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; /** * @author PikyCZ */ public class EntityMagmaCube extends EntityMob { public static final int NETWORK_ID = 42; @Override public int getNetworkId() { return NETWORK_ID; } public EntityMagmaCube(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override protected void initEntity() { super.initEntity(); this.setMaxHealth(16); } @Override public float getWidth() { return 2.04f; } @Override public float getHeight() { return 2.04f; } @Override public String getName() { return "Magma Cube"; } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } }
1,391
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityWither.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/mob/EntityWither.java
package cn.nukkit.entity.mob; import cn.nukkit.Player; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; /** * @author PikyCZ */ public class EntityWither extends EntityMob { public static final int NETWORK_ID = 52; @Override public int getNetworkId() { return NETWORK_ID; } public EntityWither(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override public float getWidth() { return 0.9f; } @Override public float getHeight() { return 3.5f; } @Override protected void initEntity() { super.initEntity(); this.setMaxHealth(300); } @Override public String getName() { return "Wither"; } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } }
1,442
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityCaveSpider.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/mob/EntityCaveSpider.java
package cn.nukkit.entity.mob; import cn.nukkit.Player; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; /** * @author PikyCZ */ public class EntityCaveSpider extends EntityMob { public static final int NETWORK_ID = 40; @Override public int getNetworkId() { return NETWORK_ID; } public EntityCaveSpider(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override protected void initEntity() { super.initEntity(); this.setMaxHealth(12); } @Override public float getWidth() { return 0.7f; } @Override public float getHeight() { return 0.5f; } @Override public String getName() { return "CaveSpider"; } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } }
1,453
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityEndermite.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/mob/EntityEndermite.java
package cn.nukkit.entity.mob; import cn.nukkit.Player; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; /** * @author Box. */ public class EntityEndermite extends EntityMob { public static final int NETWORK_ID = 55; @Override public int getNetworkId() { return NETWORK_ID; } public EntityEndermite(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override protected void initEntity() { super.initEntity(); this.setMaxHealth(8); } @Override public float getWidth() { return 0.4f; } @Override public float getHeight() { return 0.3f; } @Override public String getName() { return "Endermite"; } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } }
1,447
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityZombiePigman.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/mob/EntityZombiePigman.java
package cn.nukkit.entity.mob; import cn.nukkit.Player; import cn.nukkit.item.ItemSwordGold; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; import cn.nukkit.network.protocol.MobEquipmentPacket; /** * @author PikyCZ */ public class EntityZombiePigman extends EntityMob { public static final int NETWORK_ID = 36; @Override public int getNetworkId() { return NETWORK_ID; } public EntityZombiePigman(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override protected void initEntity() { super.initEntity(); this.setMaxHealth(20); } @Override public float getWidth() { return 0.6f; } @Override public float getHeight() { return 1.95f; } @Override public String getName() { return "ZombiePigman"; } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); MobEquipmentPacket pk1 = new MobEquipmentPacket(); pk1.eid = this.getId(); pk1.item = new ItemSwordGold(); pk1.hotbarSlot = 10; player.dataPacket(pk1); super.spawnTo(player); } }
1,682
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityWitch.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/mob/EntityWitch.java
package cn.nukkit.entity.mob; import cn.nukkit.Player; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; /** * @author PikyCZ */ public class EntityWitch extends EntityMob { public static final int NETWORK_ID = 45; @Override public int getNetworkId() { return NETWORK_ID; } public EntityWitch(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override protected void initEntity() { super.initEntity(); this.setMaxHealth(26); } @Override public float getWidth() { return 0.6f; } @Override public float getHeight() { return 1.95f; } @Override public String getName() { return "Witch"; } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } }
1,377
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityEnderDragon.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/mob/EntityEnderDragon.java
package cn.nukkit.entity.mob; import cn.nukkit.Player; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; /** * @author PikyCZ */ public class EntityEnderDragon extends EntityMob { public static final int NETWORK_ID = 53; @Override public int getNetworkId() { return NETWORK_ID; } public EntityEnderDragon(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override public float getWidth() { return 13f; } @Override public float getHeight() { return 4f; } @Override public void initEntity() { super.initEntity(); this.setMaxHealth(200); } @Override public String getName() { return "EnderDragon"; } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } }
1,451
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityVex.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/mob/EntityVex.java
package cn.nukkit.entity.mob; import cn.nukkit.Player; import cn.nukkit.item.ItemSwordIron; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; import cn.nukkit.network.protocol.MobEquipmentPacket; /** * @author PikyCZ */ public class EntityVex extends EntityMob { public static final int NETWORK_ID = 105; public EntityVex(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override public int getNetworkId() { return NETWORK_ID; } @Override protected void initEntity() { super.initEntity(); this.setMaxHealth(14); } @Override public float getWidth() { return 0.4f; } @Override public float getHeight() { return 0.8f; } @Override public String getName() { return "Vex"; } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); MobEquipmentPacket pk1 = new MobEquipmentPacket(); pk1.eid = this.getId(); pk1.item = new ItemSwordIron(); pk1.hotbarSlot = 10; player.dataPacket(pk1); super.spawnTo(player); } }
1,727
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityEnderman.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/mob/EntityEnderman.java
package cn.nukkit.entity.mob; import cn.nukkit.Player; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; /** * @author PikyCZ */ public class EntityEnderman extends EntityMob { public static final int NETWORK_ID = 38; @Override public int getNetworkId() { return NETWORK_ID; } public EntityEnderman(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override protected void initEntity() { super.initEntity(); this.setMaxHealth(40); } @Override public float getWidth() { return 0.6f; } @Override public float getHeight() { return 2.9f; } @Override public String getName() { return "Enderman"; } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } }
1,385
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityBlaze.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/mob/EntityBlaze.java
package cn.nukkit.entity.mob; import cn.nukkit.Player; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; /** * @author PikyCZ */ public class EntityBlaze extends EntityMob { public static final int NETWORK_ID = 43; @Override public int getNetworkId() { return NETWORK_ID; } public EntityBlaze(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override protected void initEntity() { super.initEntity(); this.setMaxHealth(20); } @Override public float getWidth() { return 0.6f; } @Override public float getHeight() { return 1.8f; } @Override public String getName() { return "Blaze"; } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } }
1,438
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityShulker.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/mob/EntityShulker.java
package cn.nukkit.entity.mob; import cn.nukkit.Player; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; /** * @author PikyCZ */ public class EntityShulker extends EntityMob { public static final int NETWORK_ID = 54; @Override public int getNetworkId() { return NETWORK_ID; } public EntityShulker(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override protected void initEntity() { super.initEntity(); this.setMaxHealth(30); } @Override public float getWidth() { return 1f; } @Override public float getHeight() { return 1f; } @Override public String getName() { return "Shulker"; } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } }
1,378
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityGhast.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/mob/EntityGhast.java
package cn.nukkit.entity.mob; import cn.nukkit.Player; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; /** * @author PikyCZ */ public class EntityGhast extends EntityMob { public static final int NETWORK_ID = 41; @Override public int getNetworkId() { return NETWORK_ID; } public EntityGhast(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override protected void initEntity() { super.initEntity(); this.setMaxHealth(10); } @Override public float getWidth() { return 4; } @Override public float getHeight() { return 4; } @Override public String getName() { return "Ghast"; } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } }
1,370
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityHusk.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/mob/EntityHusk.java
package cn.nukkit.entity.mob; import cn.nukkit.Player; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; /** * @author PikyCZ */ public class EntityHusk extends EntityMob { public static final int NETWORK_ID = 47; @Override public int getNetworkId() { return NETWORK_ID; } public EntityHusk(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override protected void initEntity() { super.initEntity(); this.setMaxHealth(20); } @Override public float getWidth() { return 0.6f; } @Override public float getHeight() { return 1.95f; } @Override public String getName() { return "Husk"; } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } }
1,374
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityStray.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/mob/EntityStray.java
package cn.nukkit.entity.mob; import cn.nukkit.Player; import cn.nukkit.item.Item; import cn.nukkit.item.ItemBow; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; import cn.nukkit.network.protocol.MobEquipmentPacket; /** * @author PikyCZ */ public class EntityStray extends EntityMob { public static final int NETWORK_ID = 46; @Override public int getNetworkId() { return NETWORK_ID; } public EntityStray(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override protected void initEntity() { super.initEntity(); this.setMaxHealth(20); } @Override public float getWidth() { return 0.6f; } @Override public float getHeight() { return 1.99f; } @Override public String getName() { return "Stray"; } @Override public Item[] getDrops() { return new Item[]{Item.get(Item.BONE, Item.ARROW)}; } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); MobEquipmentPacket pk1 = new MobEquipmentPacket(); pk1.eid = this.getId(); pk1.item = new ItemBow(); pk1.hotbarSlot = 10; player.dataPacket(pk1); super.spawnTo(player); } }
1,789
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityVindicator.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/mob/EntityVindicator.java
package cn.nukkit.entity.mob; import cn.nukkit.Player; import cn.nukkit.item.Item; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; /** * @author PikyCZ */ public class EntityVindicator extends EntityMob { public static final int NETWORK_ID = 57; public EntityVindicator(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override public int getNetworkId() { return NETWORK_ID; } @Override protected void initEntity() { super.initEntity(); this.setMaxHealth(24); } @Override public float getWidth() { return 0.6f; } @Override public float getHeight() { return 1.95f; } @Override public String getName() { return "Vindicator"; } @Override public Item[] getDrops() { return new Item[]{Item.get(Item.IRON_AXE)}; } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } }
1,594
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityEvoker.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/mob/EntityEvoker.java
package cn.nukkit.entity.mob; import cn.nukkit.Player; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; /** * @author PikyCZ */ public class EntityEvoker extends EntityMob { public static final int NETWORK_ID = 104; public EntityEvoker(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override public int getNetworkId() { return NETWORK_ID; } @Override protected void initEntity() { super.initEntity(); this.setMaxHealth(24); } @Override public float getWidth() { return 0.6f; } @Override public float getHeight() { return 1.95f; } @Override public String getName() { return "Evoker"; } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } }
1,445
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityCreeper.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/mob/EntityCreeper.java
package cn.nukkit.entity.mob; import cn.nukkit.Player; import cn.nukkit.entity.Entity; import cn.nukkit.entity.data.ByteEntityData; import cn.nukkit.entity.weather.EntityLightningStrike; import cn.nukkit.event.entity.CreeperPowerEvent; import cn.nukkit.event.entity.EntityDamageByEntityEvent; import cn.nukkit.item.Item; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; import java.util.concurrent.ThreadLocalRandom; /** * @author Box. */ public class EntityCreeper extends EntityMob { public static final int NETWORK_ID = 33; public static final int DATA_SWELL_DIRECTION = 16; public static final int DATA_SWELL = 17; public static final int DATA_SWELL_OLD = 18; public static final int DATA_POWERED = 19; @Override public int getNetworkId() { return NETWORK_ID; } @Override public float getWidth() { return 0.6f; } @Override public float getHeight() { return 1.7f; } public EntityCreeper(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } public boolean isPowered() { return getDataPropertyBoolean(DATA_POWERED); } 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); } } 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); } } public void onStruckByLightning(Entity entity) { this.setPowered(true); } @Override protected void initEntity() { super.initEntity(); if (this.namedTag.getBoolean("powered") || this.namedTag.getBoolean("IsPowered")) { this.dataProperties.putBoolean(DATA_POWERED, true); } this.setMaxHealth(20); } @Override public String getName() { return "Creeper"; } @Override public Item[] getDrops() { if (this.lastDamageCause instanceof EntityDamageByEntityEvent) { return new Item[]{Item.get(Item.GUNPOWDER, ThreadLocalRandom.current().nextInt(2) + 1)}; } return new Item[0]; } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } }
3,349
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntitySkeleton.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/mob/EntitySkeleton.java
package cn.nukkit.entity.mob; import cn.nukkit.Player; import cn.nukkit.item.Item; import cn.nukkit.item.ItemBow; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; import cn.nukkit.network.protocol.MobEquipmentPacket; /** * @author PikyCZ */ public class EntitySkeleton extends EntityMob { public static final int NETWORK_ID = 34; @Override public int getNetworkId() { return NETWORK_ID; } public EntitySkeleton(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override protected void initEntity() { super.initEntity(); this.setMaxHealth(20); } @Override public float getWidth() { return 0.6f; } @Override public float getHeight() { return 1.99f; } @Override public String getName() { return "Skeleton"; } @Override public Item[] getDrops() { return new Item[]{Item.get(Item.BONE, Item.ARROW)}; } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); MobEquipmentPacket pk1 = new MobEquipmentPacket(); pk1.eid = this.getId(); pk1.item = new ItemBow(); pk1.hotbarSlot = 10; player.dataPacket(pk1); super.spawnTo(player); } }
1,799
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntitySlime.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/mob/EntitySlime.java
package cn.nukkit.entity.mob; import cn.nukkit.Player; import cn.nukkit.item.Item; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; /** * @author PikyCZ */ public class EntitySlime extends EntityMob { public static final int NETWORK_ID = 37; @Override public int getNetworkId() { return NETWORK_ID; } public EntitySlime(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override protected void initEntity() { super.initEntity(); this.setMaxHealth(16); } @Override public float getWidth() { return 2.04f; } @Override public float getHeight() { return 2.04f; } @Override public String getName() { return "Slime"; } @Override public Item[] getDrops() { return new Item[]{Item.get(Item.SLIMEBALL)}; } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } }
1,511
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntitySilverfish.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/mob/EntitySilverfish.java
package cn.nukkit.entity.mob; import cn.nukkit.Player; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; /** * @author PikyCZ */ public class EntitySilverfish extends EntityMob { public static final int NETWORK_ID = 39; @Override public int getNetworkId() { return NETWORK_ID; } public EntitySilverfish(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override public String getName() { return "Silverfish"; } @Override public float getWidth() { return 0.4f; } @Override public float getHeight() { return 0.3f; } @Override public void initEntity() { super.initEntity(); this.setMaxHealth(8); } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } }
1,387
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntitySpider.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/mob/EntitySpider.java
package cn.nukkit.entity.mob; import cn.nukkit.Player; import cn.nukkit.item.Item; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; /** * @author PikyCZ */ public class EntitySpider extends EntityMob { public static final int NETWORK_ID = 35; @Override public int getNetworkId() { return NETWORK_ID; } public EntitySpider(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override protected void initEntity() { super.initEntity(); this.setMaxHealth(16); } @Override public float getWidth() { return 1.4f; } @Override public float getHeight() { return 0.9f; } @Override public String getName() { return "Spider"; } @Override public Item[] getDrops() { return new Item[]{Item.get(Item.STRING, Item.SPIDER_EYE)}; } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } }
1,526
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityWitherSkeleton.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/mob/EntityWitherSkeleton.java
package cn.nukkit.entity.mob; import cn.nukkit.Player; import cn.nukkit.item.ItemSwordStone; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; import cn.nukkit.network.protocol.MobEquipmentPacket; /** * @author PikyCZ */ public class EntityWitherSkeleton extends EntityMob { public static final int NETWORK_ID = 48; @Override public int getNetworkId() { return NETWORK_ID; } public EntityWitherSkeleton(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override protected void initEntity() { super.initEntity(); } @Override public float getWidth() { return 0.7f; } @Override public float getHeight() { return 2.4f; } @Override public String getName() { return "WitherSkeleton"; } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); MobEquipmentPacket pk1 = new MobEquipmentPacket(); pk1.eid = this.getId(); pk1.item = new ItemSwordStone(); pk1.hotbarSlot = 10; player.dataPacket(pk1); super.spawnTo(player); } }
1,658
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityZombieVillager.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/mob/EntityZombieVillager.java
package cn.nukkit.entity.mob; import cn.nukkit.Player; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; /** * @author PikyCZ */ public class EntityZombieVillager extends EntityMob { public static final int NETWORK_ID = 44; @Override public int getNetworkId() { return NETWORK_ID; } public EntityZombieVillager(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override protected void initEntity() { super.initEntity(); this.setMaxHealth(20); } @Override public float getWidth() { return 0.6f; } @Override public float getHeight() { return 1.95f; } @Override public String getName() { return "ZombieVillager"; } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } }
1,404
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityElderGuardian.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/mob/EntityElderGuardian.java
package cn.nukkit.entity.mob; import cn.nukkit.Player; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; /** * @author PikyCZ */ public class EntityElderGuardian extends EntityMob { public static final int NETWORK_ID = 50; @Override public int getNetworkId() { return NETWORK_ID; } public EntityElderGuardian(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override protected void initEntity() { super.initEntity(); this.setMaxHealth(80); } @Override public float getWidth() { return 1.9975f; } @Override public float getHeight() { return 1.9975f; } @Override public String getName() { return "ElderGuardian"; } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } }
1,468
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityProjectile.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/projectile/EntityProjectile.java
package cn.nukkit.entity.projectile; import cn.nukkit.entity.Entity; import cn.nukkit.entity.EntityLiving; import cn.nukkit.entity.data.LongEntityData; import cn.nukkit.event.entity.*; import cn.nukkit.event.entity.EntityDamageEvent.DamageCause; import cn.nukkit.level.MovingObjectPosition; import cn.nukkit.level.format.FullChunk; import cn.nukkit.math.AxisAlignedBB; import cn.nukkit.math.NukkitMath; import cn.nukkit.math.Vector3; import cn.nukkit.nbt.tag.CompoundTag; /** * author: MagicDroidX * Nukkit Project */ public abstract class EntityProjectile extends Entity { public static final int DATA_SHOOTER_ID = 17; public Entity shootingEntity = null; protected double getDamage() { return namedTag.contains("damage") ? namedTag.getDouble("damage") : getBaseDamage(); } protected double getBaseDamage() { return 0; } public boolean hadCollision = false; protected double damage = 0; public EntityProjectile(FullChunk chunk, CompoundTag nbt) { this(chunk, nbt, null); } public EntityProjectile(FullChunk chunk, CompoundTag nbt, Entity shootingEntity) { super(chunk, nbt); this.shootingEntity = shootingEntity; if (shootingEntity != null) { this.setDataProperty(new LongEntityData(DATA_SHOOTER_ID, shootingEntity.getId())); } } public int getResultDamage() { return NukkitMath.ceilDouble(Math.sqrt(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ) * getDamage()); } public boolean attack(EntityDamageEvent source) { return source.getCause() == DamageCause.VOID && super.attack(source); } public void onCollideWithEntity(Entity entity) { this.server.getPluginManager().callEvent(new ProjectileHitEvent(this)); float damage = this.getResultDamage(); EntityDamageEvent ev; if (this.shootingEntity == null) { ev = new EntityDamageByEntityEvent(this, entity, DamageCause.PROJECTILE, damage); } else { ev = new EntityDamageByChildEntityEvent(this.shootingEntity, this, entity, DamageCause.PROJECTILE, damage); } entity.attack(ev); this.hadCollision = true; if (this.fireTicks > 0) { EntityCombustByEntityEvent event = new EntityCombustByEntityEvent(this, entity, 5); this.server.getPluginManager().callEvent(ev); if (!event.isCancelled()) { entity.setOnFire(event.getDuration()); } } this.close(); } @Override protected void initEntity() { super.initEntity(); this.setMaxHealth(1); this.setHealth(1); if (this.namedTag.contains("Age")) { this.age = this.namedTag.getShort("Age"); } } @Override public boolean canCollideWith(Entity entity) { return entity instanceof EntityLiving && !this.onGround; } @Override public void saveNBT() { super.saveNBT(); this.namedTag.putShort("Age", this.age); } @Override public boolean onUpdate(int currentTick) { if (this.closed) { return false; } int tickDiff = currentTick - this.lastUpdate; if (tickDiff <= 0 && !this.justCreated) { return true; } this.lastUpdate = currentTick; boolean hasUpdate = this.entityBaseTick(tickDiff); if (this.isAlive()) { MovingObjectPosition movingObjectPosition = null; if (!this.isCollided) { this.motionY -= this.getGravity(); } Vector3 moveVector = new Vector3(this.x + this.motionX, this.y + this.motionY, this.z + this.motionZ); Entity[] list = this.getLevel().getCollidingEntities(this.boundingBox.addCoord(this.motionX, this.motionY, this.motionZ).expand(1, 1, 1), this); double nearDistance = Integer.MAX_VALUE; Entity nearEntity = null; for (Entity entity : list) { if (/*!entity.canCollideWith(this) or */ (entity == this.shootingEntity && this.ticksLived < 5) ) { continue; } AxisAlignedBB axisalignedbb = entity.boundingBox.grow(0.3, 0.3, 0.3); MovingObjectPosition ob = axisalignedbb.calculateIntercept(this, moveVector); if (ob == null) { continue; } double distance = this.distanceSquared(ob.hitVector); if (distance < nearDistance) { nearDistance = distance; nearEntity = entity; } } if (nearEntity != null) { movingObjectPosition = MovingObjectPosition.fromEntity(nearEntity); } if (movingObjectPosition != null) { if (movingObjectPosition.entityHit != null) { onCollideWithEntity(movingObjectPosition.entityHit); return true; } } this.move(this.motionX, this.motionY, this.motionZ); if (this.isCollided && !this.hadCollision) { //collide with block this.hadCollision = true; this.motionX = 0; this.motionY = 0; this.motionZ = 0; this.server.getPluginManager().callEvent(new ProjectileHitEvent(this, MovingObjectPosition.fromBlock(this.getFloorX(), this.getFloorY(), this.getFloorZ(), -1, this))); return false; } else if (!this.isCollided && this.hadCollision) { this.hadCollision = false; } if (!this.hadCollision || Math.abs(this.motionX) > 0.00001 || Math.abs(this.motionY) > 0.00001 || Math.abs(this.motionZ) > 0.00001) { double f = Math.sqrt((this.motionX * this.motionX) + (this.motionZ * this.motionZ)); this.yaw = Math.atan2(this.motionX, this.motionZ) * 180 / Math.PI; this.pitch = Math.atan2(this.motionY, f) * 180 / Math.PI; hasUpdate = true; } this.updateMovement(); } return hasUpdate; } }
6,323
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntitySnowball.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/projectile/EntitySnowball.java
package cn.nukkit.entity.projectile; import cn.nukkit.Player; import cn.nukkit.entity.Entity; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; /** * author: MagicDroidX * Nukkit Project */ public class EntitySnowball extends EntityProjectile { public static final int NETWORK_ID = 81; @Override public int getNetworkId() { return NETWORK_ID; } @Override public float getWidth() { return 0.25f; } @Override public float getLength() { return 0.25f; } @Override public float getHeight() { return 0.25f; } @Override protected float getGravity() { return 0.03f; } @Override protected float getDrag() { return 0.01f; } public EntitySnowball(FullChunk chunk, CompoundTag nbt) { this(chunk, nbt, null); } public EntitySnowball(FullChunk chunk, CompoundTag nbt, Entity shootingEntity) { super(chunk, nbt, shootingEntity); } @Override public boolean onUpdate(int currentTick) { if (this.closed) { return false; } this.timing.startTiming(); boolean hasUpdate = super.onUpdate(currentTick); if (this.age > 1200 || this.isCollided) { this.kill(); hasUpdate = true; } this.timing.stopTiming(); return hasUpdate; } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = EntitySnowball.NETWORK_ID; pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } }
2,039
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityArrow.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/projectile/EntityArrow.java
package cn.nukkit.entity.projectile; import cn.nukkit.Player; import cn.nukkit.entity.Entity; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; import java.util.concurrent.ThreadLocalRandom; /** * author: MagicDroidX * Nukkit Project */ public class EntityArrow extends EntityProjectile { public static final int NETWORK_ID = 80; public static final int DATA_SOURCE_ID = 17; @Override public int getNetworkId() { return NETWORK_ID; } @Override public float getWidth() { return 0.5f; } @Override public float getLength() { return 0.5f; } @Override public float getHeight() { return 0.5f; } @Override public float getGravity() { return 0.05f; } @Override public float getDrag() { return 0.01f; } protected float gravity = 0.05f; protected float drag = 0.01f; public EntityArrow(FullChunk chunk, CompoundTag nbt) { this(chunk, nbt, null); } public EntityArrow(FullChunk chunk, CompoundTag nbt, Entity shootingEntity) { this(chunk, nbt, shootingEntity, false); } public EntityArrow(FullChunk chunk, CompoundTag nbt, Entity shootingEntity, boolean critical) { super(chunk, nbt, shootingEntity); this.setCritical(critical); } @Override protected void initEntity() { super.initEntity(); this.damage = namedTag.contains("damage") ? namedTag.getDouble("damage") : 2; } public void setCritical() { this.setCritical(true); } public void setCritical(boolean value) { this.setDataFlag(DATA_FLAGS, DATA_FLAG_CRITICAL, value); } public boolean isCritical() { return this.getDataFlag(DATA_FLAGS, DATA_FLAG_CRITICAL); } @Override public int getResultDamage() { int base = super.getResultDamage(); if (this.isCritical()) { base += ThreadLocalRandom.current().nextInt(base / 2 + 2); } return base; } @Override protected double getBaseDamage() { return 2; } @Override public boolean onUpdate(int currentTick) { if (this.closed) { return false; } this.timing.startTiming(); boolean hasUpdate = super.onUpdate(currentTick); if (this.onGround || this.hadCollision) { this.setCritical(false); } if (this.age > 1200) { this.close(); hasUpdate = true; } this.timing.stopTiming(); return hasUpdate; } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = EntityArrow.NETWORK_ID; pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.yaw = (float) this.yaw; pk.pitch = (float) this.pitch; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } }
3,312
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityEnderPearl.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/projectile/EntityEnderPearl.java
package cn.nukkit.entity.projectile; import cn.nukkit.Player; import cn.nukkit.entity.Entity; import cn.nukkit.event.player.PlayerTeleportEvent.TeleportCause; import cn.nukkit.level.Sound; import cn.nukkit.level.format.FullChunk; import cn.nukkit.math.NukkitMath; import cn.nukkit.math.Vector3; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; public class EntityEnderPearl extends EntityProjectile { public static final int NETWORK_ID = 87; @Override public int getNetworkId() { return NETWORK_ID; } @Override public float getWidth() { return 0.25f; } @Override public float getLength() { return 0.25f; } @Override public float getHeight() { return 0.25f; } @Override protected float getGravity() { return 0.03f; } @Override protected float getDrag() { return 0.01f; } public EntityEnderPearl(FullChunk chunk, CompoundTag nbt) { this(chunk, nbt, null); } public EntityEnderPearl(FullChunk chunk, CompoundTag nbt, Entity shootingEntity) { super(chunk, nbt, shootingEntity); } @Override public boolean onUpdate(int currentTick) { if (this.closed) { return false; } this.timing.startTiming(); boolean hasUpdate = super.onUpdate(currentTick); if (this.isCollided && this.shootingEntity instanceof Player) { this.shootingEntity.teleport(new Vector3(NukkitMath.floorDouble(this.x) + 0.5, this.y, NukkitMath.floorDouble(this.z) + 0.5), TeleportCause.ENDER_PEARL); if ((((Player) this.shootingEntity).getGamemode() & 0x01) == 0) this.shootingEntity.attack(5); this.level.addSound(this, Sound.MOB_ENDERMEN_PORTAL); } if (this.age > 1200 || this.isCollided) { this.kill(); hasUpdate = true; } this.timing.stopTiming(); return hasUpdate; } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = NETWORK_ID; pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } }
2,563
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityEgg.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/projectile/EntityEgg.java
package cn.nukkit.entity.projectile; import cn.nukkit.Player; import cn.nukkit.entity.Entity; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; /** * author: MagicDroidX * Nukkit Project */ public class EntityEgg extends EntityProjectile { public static final int NETWORK_ID = 82; @Override public int getNetworkId() { return NETWORK_ID; } @Override public float getWidth() { return 0.25f; } @Override public float getLength() { return 0.25f; } @Override public float getHeight() { return 0.25f; } @Override protected float getGravity() { return 0.03f; } @Override protected float getDrag() { return 0.01f; } public EntityEgg(FullChunk chunk, CompoundTag nbt) { this(chunk, nbt, null); } public EntityEgg(FullChunk chunk, CompoundTag nbt, Entity shootingEntity) { super(chunk, nbt, shootingEntity); } @Override public boolean onUpdate(int currentTick) { if (this.closed) { return false; } boolean hasUpdate = super.onUpdate(currentTick); if (this.age > 1200 || this.isCollided) { this.kill(); hasUpdate = true; } return hasUpdate; } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = EntityEgg.NETWORK_ID; pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } }
1,948
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityPainting.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/item/EntityPainting.java
package cn.nukkit.entity.item; import cn.nukkit.Player; import cn.nukkit.entity.Entity; import cn.nukkit.entity.EntityHanging; import cn.nukkit.event.entity.EntityDamageByEntityEvent; import cn.nukkit.event.entity.EntityDamageEvent; import cn.nukkit.item.ItemPainting; import cn.nukkit.level.GameRule; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddPaintingPacket; /** * author: MagicDroidX * Nukkit Project */ public class EntityPainting extends EntityHanging { public static final int NETWORK_ID = 83; public final static Motive[] motives = new Motive[]{ new Motive("Kebab", 1, 1), new Motive("Aztec", 1, 1), new Motive("Alban", 1, 1), new Motive("Aztec2", 1, 1), new Motive("Bomb", 1, 1), new Motive("Plant", 1, 1), new Motive("Wasteland", 1, 1), new Motive("Wanderer", 1, 2), new Motive("Graham", 1, 2), new Motive("Pool", 2, 1), new Motive("Courbet", 2, 1), new Motive("Sunset", 2, 1), new Motive("Sea", 2, 1), new Motive("Creebet", 2, 1), new Motive("Match", 2, 2), new Motive("Bust", 2, 2), new Motive("Stage", 2, 2), new Motive("Void", 2, 2), new Motive("SkullAndRoses", 2, 2), //new Motive("Wither", 2, 2), new Motive("Fighters", 4, 2), new Motive("Skeleton", 4, 3), new Motive("DonkeyKong", 4, 3), new Motive("Pointer", 4, 4), new Motive("Pigscene", 4, 4), new Motive("Flaming Skull", 4, 4) }; private Motive motive; public EntityPainting(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } public static Motive getMotive(String name) { for (Motive motive : motives) { if (motive.title.equals(name)) { return motive; } } return motives[0]; } @Override public int getNetworkId() { return NETWORK_ID; } @Override protected void initEntity() { super.initEntity(); this.motive = getMotive(this.namedTag.getString("Motive")); } @Override public void spawnTo(Player player) { AddPaintingPacket pk = new AddPaintingPacket(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (int) this.x; pk.y = (int) this.y; pk.z = (int) this.z; pk.direction = this.getDirection().getHorizontalIndex(); pk.title = this.namedTag.getString("Motive"); player.dataPacket(pk); super.spawnTo(player); } @Override public boolean attack(EntityDamageEvent source) { if (super.attack(source)) { if (source instanceof EntityDamageByEntityEvent) { Entity damager = ((EntityDamageByEntityEvent) source).getDamager(); if (damager instanceof Player && ((Player) damager).isSurvival() && this.level.getGameRules().getBoolean(GameRule.DO_ENTITY_DROPS)) { this.level.dropItem(this, new ItemPainting()); } } this.close(); return true; } else { return false; } } @Override public void saveNBT() { super.saveNBT(); this.namedTag.putString("Motive", this.motive.title); } public static class Motive { public final String title; public final int width; public final int height; protected Motive(String title, int width, int height) { this.title = title; this.width = width; this.height = height; } } }
3,818
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityBoat.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/item/EntityBoat.java
package cn.nukkit.entity.item; import cn.nukkit.Player; import cn.nukkit.entity.Entity; import cn.nukkit.event.entity.EntityDamageByEntityEvent; import cn.nukkit.event.entity.EntityDamageEvent; import cn.nukkit.event.vehicle.VehicleDamageEvent; import cn.nukkit.event.vehicle.VehicleDestroyEvent; import cn.nukkit.event.vehicle.VehicleMoveEvent; import cn.nukkit.event.vehicle.VehicleUpdateEvent; import cn.nukkit.item.Item; import cn.nukkit.item.ItemBoat; import cn.nukkit.level.GameRule; import cn.nukkit.level.Location; import cn.nukkit.level.format.FullChunk; import cn.nukkit.level.particle.SmokeParticle; import cn.nukkit.math.Vector3; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; /** * Created by yescallop on 2016/2/13. */ public class EntityBoat extends EntityVehicle { public static final int NETWORK_ID = 90; public static final int DATA_WOOD_ID = 20; public EntityBoat(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override protected void initEntity() { super.initEntity(); this.dataProperties.putByte(DATA_WOOD_ID, this.namedTag.getByte("woodID")); this.setHealth(4); this.setMaxHealth(4); } @Override public float getHeight() { return 0.7f; } @Override public float getWidth() { return 1.6f; } @Override protected float getDrag() { return 0.1f; } @Override protected float getGravity() { return 0.1f; } @Override public float getBaseOffset() { return 0.35F; } @Override public int getNetworkId() { return NETWORK_ID; } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.type = EntityBoat.NETWORK_ID; pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = 0; pk.speedY = 0; pk.speedZ = 0; pk.yaw = (float) this.yaw; pk.pitch = (float) this.pitch; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } @Override public boolean attack(EntityDamageEvent source) { if (invulnerable) { return false; } else { // Event start VehicleDamageEvent event = new VehicleDamageEvent(this, source.getEntity(), source.getFinalDamage()); getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { return false; } // Event stop performHurtAnimation((int) event.getDamage()); boolean instantKill = false; if (source instanceof EntityDamageByEntityEvent) { Entity damager = ((EntityDamageByEntityEvent) source).getDamager(); instantKill = damager instanceof Player && ((Player) damager).isCreative(); } if (instantKill || getDamage() > 40) { // Event start VehicleDestroyEvent event2 = new VehicleDestroyEvent(this, source.getEntity()); getServer().getPluginManager().callEvent(event2); if (event2.isCancelled()) { return false; } // Event stop if (linkedEntity != null) { mountEntity(linkedEntity); } if (instantKill && (!hasCustomName())) { kill(); } else { if (level.getGameRules().getBoolean(GameRule.DO_ENTITY_DROPS)) { this.level.dropItem(this, new ItemBoat()); } close(); } } } return true; } @Override public void close() { super.close(); if (this.linkedEntity instanceof Player) { this.linkedEntity.riding = null; } SmokeParticle particle = new SmokeParticle(this); this.level.addParticle(particle); } @Override public boolean onUpdate(int currentTick) { if (this.closed) { return false; } int tickDiff = currentTick - this.lastUpdate; if (tickDiff <= 0 && !this.justCreated) { return true; } this.lastUpdate = currentTick; boolean hasUpdate = this.entityBaseTick(tickDiff); if (this.isAlive()) { super.onUpdate(currentTick); this.motionY = (this.level.getBlock(new Vector3(this.x, this.y, this.z)).getBoundingBox() != null || this.isInsideOfWater()) ? getGravity() : -0.08; if (this.checkObstruction(this.x, this.y, this.z)) { hasUpdate = true; } this.move(this.motionX, this.motionY, this.motionZ); double friction = 1 - this.getDrag(); if (this.onGround && (Math.abs(this.motionX) > 0.00001 || Math.abs(this.motionZ) > 0.00001)) { friction *= this.getLevel().getBlock(this.temporalVector.setComponents((int) Math.floor(this.x), (int) Math.floor(this.y - 1), (int) Math.floor(this.z) - 1)).getFrictionFactor(); } this.motionX *= friction; this.motionY *= 1 - this.getDrag(); this.motionZ *= friction; if (this.onGround) { this.motionY *= -0.5; } Location from = new Location(lastX, lastY, lastZ, lastYaw, lastPitch, level); Location to = new Location(this.x, this.y, this.z, this.yaw, this.pitch, level); this.getServer().getPluginManager().callEvent(new VehicleUpdateEvent(this)); if (!from.equals(to)) { this.getServer().getPluginManager().callEvent(new VehicleMoveEvent(this, from, to)); } this.updateMovement(); } return hasUpdate || !this.onGround || Math.abs(this.motionX) > 0.00001 || Math.abs(this.motionY) > 0.00001 || Math.abs(this.motionZ) > 0.00001; } @Override public boolean onInteract(Player player, Item item) { if (this.linkedEntity != null) { return false; } super.mountEntity(player); return true; } }
6,427
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityMinecartAbstract.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/item/EntityMinecartAbstract.java
package cn.nukkit.entity.item; import cn.nukkit.Player; import cn.nukkit.api.API; import cn.nukkit.api.API.Definition; import cn.nukkit.api.API.Usage; import cn.nukkit.block.Block; import cn.nukkit.block.BlockRail; import cn.nukkit.block.BlockRailActivator; import cn.nukkit.block.BlockRailPowered; import cn.nukkit.entity.Entity; import cn.nukkit.entity.EntityHuman; import cn.nukkit.entity.EntityLiving; import cn.nukkit.entity.data.ByteEntityData; import cn.nukkit.entity.data.IntEntityData; import cn.nukkit.event.entity.EntityDamageByEntityEvent; import cn.nukkit.event.entity.EntityDamageEvent; import cn.nukkit.event.vehicle.VehicleMoveEvent; import cn.nukkit.event.vehicle.VehicleUpdateEvent; import cn.nukkit.item.Item; import cn.nukkit.item.ItemMinecart; import cn.nukkit.level.GameRule; import cn.nukkit.level.Location; import cn.nukkit.level.format.FullChunk; import cn.nukkit.level.particle.SmokeParticle; import cn.nukkit.math.MathHelper; import cn.nukkit.math.NukkitMath; import cn.nukkit.math.Vector3; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; import cn.nukkit.utils.MinecartType; import cn.nukkit.utils.Rail; import cn.nukkit.utils.Rail.Orientation; import java.util.Objects; /** * Created by: larryTheCoder on 2017/6/26. * <p> * Nukkit Project, * Minecart and Riding Project, * Package cn.nukkit.entity.item in project Nukkit. */ public abstract class EntityMinecartAbstract extends EntityVehicle { private String entityName; private static final int[][][] matrix = new int[][][]{ {{0, 0, -1}, {0, 0, 1}}, {{-1, 0, 0}, {1, 0, 0}}, {{-1, -1, 0}, {1, 0, 0}}, {{-1, 0, 0}, {1, -1, 0}}, {{0, 0, -1}, {0, -1, 1}}, {{0, -1, -1}, {0, 0, 1}}, {{0, 0, 1}, {1, 0, 0}}, {{0, 0, 1}, {-1, 0, 0}}, {{0, 0, -1}, {-1, 0, 0}}, {{0, 0, -1}, {1, 0, 0}} }; private double currentSpeed = 0; private Block blockInside; // Plugins modifiers private boolean slowWhenEmpty = true; private double derailedX = 0.5; private double derailedY = 0.5; private double derailedZ = 0.5; private double flyingX = 0.95; private double flyingY = 0.95; private double flyingZ = 0.95; private double maxSpeed = 0.4D; private final boolean devs = false; // Avoid maintained features into production public abstract MinecartType getType(); public EntityMinecartAbstract(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override public float getHeight() { return 0.7F; } @Override public float getWidth() { return 0.98F; } @Override protected float getDrag() { return 0.1F; } public void setName(String name) { entityName = name; } @Override public String getName() { return entityName; } @Override public float getBaseOffset() { return 0.35F; } @Override public boolean hasCustomName() { return entityName != null; } @Override public boolean canDoInteraction() { return linkedEntity == null && this.getDisplayBlock() == null; } @Override public float getMountedYOffset() { return 0.45F; // Real minecart offset } @Override public void initEntity() { super.initEntity(); prepareDataProperty(); } @Override public boolean onUpdate(int currentTick) { if (this.closed) { return false; } if (!this.isAlive()) { ++this.deadTicks; if (this.deadTicks >= 10) { this.despawnFromAll(); this.close(); } return this.deadTicks < 10; } int tickDiff = currentTick - this.lastUpdate; if (tickDiff <= 0) { return false; } this.lastUpdate = currentTick; if (isAlive()) { super.onUpdate(currentTick); // Entity variables lastX = x; lastY = y; lastZ = z; motionY -= 0.03999999910593033D; int dx = MathHelper.floor(x); int dy = MathHelper.floor(y); int dz = MathHelper.floor(z); // Some hack to check rails if (Rail.isRailBlock(level.getBlockIdAt(dx, dy - 1, dz))) { --dy; } Block block = level.getBlock(new Vector3(dx, dy, dz)); // Ensure that the block is a rail if (Rail.isRailBlock(block)) { processMovement(dx, dy, dz, (BlockRail) block); if (block instanceof BlockRailActivator) { // Activate the minecart/TNT activate(dx, dy, dz, (block.getDamage() & 0x8) != 0); } } else { setFalling(); } checkBlockCollision(); // Minecart head pitch = 0; double diffX = this.lastX - this.x; double diffZ = this.lastZ - this.z; double yawToChange = yaw; if (diffX * diffX + diffZ * diffZ > 0.001D) { yawToChange = (Math.atan2(diffZ, diffX) * 180 / 3.141592653589793D); } // Reverse yaw if yaw is below 0 if (yawToChange < 0) { // -90-(-90)-(-90) = 90 yawToChange -= yawToChange - yawToChange; } setRotation(yawToChange, pitch); Location from = new Location(lastX, lastY, lastZ, lastYaw, lastPitch, level); Location to = new Location(this.x, this.y, this.z, this.yaw, this.pitch, level); this.getServer().getPluginManager().callEvent(new VehicleUpdateEvent(this)); if (!from.equals(to)) { this.getServer().getPluginManager().callEvent(new VehicleMoveEvent(this, from, to)); } // Collisions for (Entity entity : level.getNearbyEntities(boundingBox.grow(0.2D, 0, 0.2D), this)) { if (entity != linkedEntity && entity instanceof EntityMinecartAbstract) { entity.applyEntityCollision(this); } } // Easier if ((linkedEntity != null) && (!linkedEntity.isAlive())) { if (linkedEntity.riding == this) { linkedEntity.riding = null; } linkedEntity = null; } // No need to onGround or Motion diff! This always have an update return true; } return false; } @Override public boolean attack(EntityDamageEvent source) { if (invulnerable) { return false; } else { Entity damager = ((EntityDamageByEntityEvent) source).getDamager(); boolean instantKill = damager instanceof Player && ((Player) damager).isCreative(); if (!instantKill) performHurtAnimation((int) source.getFinalDamage()); if (instantKill || getDamage() > 40) { if (linkedEntity != null) { mountEntity(linkedEntity); } if (instantKill && (!hasCustomName())) { kill(); } else { if (level.getGameRules().getBoolean(GameRule.DO_ENTITY_DROPS)) { dropItem(); } close(); } } } return true; } public void dropItem() { level.dropItem(this, new ItemMinecart()); } @Override public void close() { super.close(); if (linkedEntity instanceof Player) { linkedEntity.riding = null; linkedEntity = null; } SmokeParticle particle = new SmokeParticle(this); level.addParticle(particle); } @Override public boolean onInteract(Player p, Item item) { if (linkedEntity != null) { return false; } if (blockInside == null) { mountEntity(p); // Simple } return true; } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.entityUniqueId = getId(); pk.entityRuntimeId = getId(); pk.type = getNetworkId(); pk.x = (float) x; pk.y = (float) y; pk.z = (float) z; pk.speedX = 0; pk.speedY = 0; pk.speedZ = 0; pk.yaw = 0; pk.pitch = 0; pk.metadata = dataProperties; player.dataPacket(pk); super.spawnTo(player); } @Override public void applyEntityCollision(Entity entity) { if (entity != riding) { if (entity instanceof EntityLiving && !(entity instanceof EntityHuman) && motionX * motionX + motionZ * motionZ > 0.01D && linkedEntity == null && entity.riding == null && blockInside == null) { if (riding == null && devs) { mountEntity(entity);// TODO: rewrite (weird riding) } } double motiveX = entity.x - x; double motiveZ = entity.z - z; double square = motiveX * motiveX + motiveZ * motiveZ; if (square >= 9.999999747378752E-5D) { square = Math.sqrt(square); motiveX /= square; motiveZ /= square; double next = 1 / square; if (next > 1) { next = 1; } motiveX *= next; motiveZ *= next; motiveX *= 0.10000000149011612D; motiveZ *= 0.10000000149011612D; motiveX *= 1 + entityCollisionReduction; motiveZ *= 1 + entityCollisionReduction; motiveX *= 0.5D; motiveZ *= 0.5D; if (entity instanceof EntityMinecartAbstract) { EntityMinecartAbstract mine = (EntityMinecartAbstract) entity; double desinityX = mine.x - x; double desinityZ = mine.z - z; Vector3 vector = new Vector3(desinityX, 0, desinityZ).normalize(); Vector3 vec = new Vector3((double) MathHelper.cos((float) yaw * 0.017453292F), 0, (double) MathHelper.sin((float) yaw * 0.017453292F)).normalize(); double desinityXZ = Math.abs(vector.dot(vec)); if (desinityXZ < 0.800000011920929D) { return; } double motX = mine.motionX + motionX; double motZ = mine.motionZ + motionZ; if (mine.getType().getId() == 2 && getType().getId() != 2) { motionX *= 0.20000000298023224D; motionZ *= 0.20000000298023224D; motionX += mine.motionX - motiveX; motionZ += mine.motionZ - motiveZ; mine.motionX *= 0.949999988079071D; mine.motionZ *= 0.949999988079071D; } else if (mine.getType().getId() != 2 && getType().getId() == 2) { mine.motionX *= 0.20000000298023224D; mine.motionZ *= 0.20000000298023224D; motionX += mine.motionX + motiveX; motionZ += mine.motionZ + motiveZ; motionX *= 0.949999988079071D; motionZ *= 0.949999988079071D; } else { motX /= 2; motZ /= 2; motionX *= 0.20000000298023224D; motionZ *= 0.20000000298023224D; motionX += motX - motiveX; motionZ += motZ - motiveZ; mine.motionX *= 0.20000000298023224D; mine.motionZ *= 0.20000000298023224D; mine.motionX += motX + motiveX; mine.motionZ += motZ + motiveZ; } } else { motionX -= motiveX; motionZ -= motiveZ; } } } } @Override public void saveNBT() { super.saveNBT(); saveEntityData(); } public double getMaxSpeed() { return maxSpeed; } protected void activate(int x, int y, int z, boolean flag) { } private boolean hasUpdated = false; private void setFalling() { motionX = NukkitMath.clamp(motionX, -getMaxSpeed(), getMaxSpeed()); motionZ = NukkitMath.clamp(motionZ, -getMaxSpeed(), getMaxSpeed()); if (linkedEntity != null && !hasUpdated) { updateRiderPosition(getMountedYOffset() + 0.35F); hasUpdated = true; } else { hasUpdated = false; } if (onGround) { motionX *= derailedX; motionY *= derailedY; motionZ *= derailedZ; } move(motionX, motionY, motionZ); if (!onGround) { motionX *= flyingX; motionY *= flyingY; motionZ *= flyingZ; } } private void processMovement(int dx, int dy, int dz, BlockRail block) { fallDistance = 0.0F; Vector3 vector = getNextRail(x, y, z); y = (double) dy; boolean isPowered = false; boolean isSlowed = false; if (block instanceof BlockRailPowered) { isPowered = block.isActive(); isSlowed = !block.isActive(); } switch (Orientation.byMetadata(block.getRealMeta())) { case ASCENDING_NORTH: motionX -= 0.0078125D; y += 1; break; case ASCENDING_SOUTH: motionX += 0.0078125D; y += 1; break; case ASCENDING_EAST: motionZ += 0.0078125D; y += 1; break; case ASCENDING_WEST: motionZ -= 0.0078125D; y += 1; break; } int[][] facing = matrix[block.getRealMeta()]; double facing1 = (double) (facing[1][0] - facing[0][0]); double facing2 = (double) (facing[1][2] - facing[0][2]); double speedOnTurns = Math.sqrt(facing1 * facing1 + facing2 * facing2); double realFacing = motionX * facing1 + motionZ * facing2; if (realFacing < 0) { facing1 = -facing1; facing2 = -facing2; } double squareOfFame = Math.sqrt(motionX * motionX + motionZ * motionZ); if (squareOfFame > 2) { squareOfFame = 2; } motionX = squareOfFame * facing1 / speedOnTurns; motionZ = squareOfFame * facing2 / speedOnTurns; double expectedSpeed; double playerYawNeg; // PlayerYawNegative double playerYawPos; // PlayerYawPositive double motion; if (linkedEntity != null && linkedEntity instanceof EntityLiving) { expectedSpeed = currentSpeed; if (expectedSpeed > 0) { // This is a trajectory (Angle of elevation) playerYawNeg = -Math.sin(linkedEntity.yaw * 3.1415927F / 180.0F); playerYawPos = Math.cos(linkedEntity.yaw * 3.1415927F / 180.0F); motion = motionX * motionX + motionZ * motionZ; if (motion < 0.01D) { motionX += playerYawNeg * 0.1D; motionZ += playerYawPos * 0.1D; isSlowed = false; } } } //http://minecraft.gamepedia.com/Powered_Rail#Rail if (isSlowed) { expectedSpeed = Math.sqrt(motionX * motionX + motionZ * motionZ); if (expectedSpeed < 0.03D) { motionX *= 0; motionY *= 0; motionZ *= 0; } else { motionX *= 0.5D; motionY *= 0; motionZ *= 0.5D; } } playerYawNeg = (double) dx + 0.5D + (double) facing[0][0] * 0.5D; playerYawPos = (double) dz + 0.5D + (double) facing[0][2] * 0.5D; motion = (double) dx + 0.5D + (double) facing[1][0] * 0.5D; double wallOfFame = (double) dz + 0.5D + (double) facing[1][2] * 0.5D; facing1 = motion - playerYawNeg; facing2 = wallOfFame - playerYawPos; double motX; double motZ; if (facing1 == 0) { x = (double) dx + 0.5D; expectedSpeed = z - (double) dz; } else if (facing2 == 0) { z = (double) dz + 0.5D; expectedSpeed = x - (double) dx; } else { motX = x - playerYawNeg; motZ = z - playerYawPos; expectedSpeed = (motX * facing1 + motZ * facing2) * 2; } x = playerYawNeg + facing1 * expectedSpeed; z = playerYawPos + facing2 * expectedSpeed; setPosition(new Vector3(x, y, z)); // Hehe, my minstake :3 motX = motionX; motZ = motionZ; if (linkedEntity != null) { motX *= 0.75D; motZ *= 0.75D; } motX = NukkitMath.clamp(motX, -getMaxSpeed(), getMaxSpeed()); motZ = NukkitMath.clamp(motZ, -getMaxSpeed(), getMaxSpeed()); move(motX, 0, motZ); if (facing[0][1] != 0 && MathHelper.floor(x) - dx == facing[0][0] && MathHelper.floor(z) - dz == facing[0][2]) { setPosition(new Vector3(x, y + (double) facing[0][1], z)); } else if (facing[1][1] != 0 && MathHelper.floor(x) - dx == facing[1][0] && MathHelper.floor(z) - dz == facing[1][2]) { setPosition(new Vector3(x, y + (double) facing[1][1], z)); } applyDrag(); Vector3 vector1 = getNextRail(x, y, z); if (vector1 != null && vector != null) { double d14 = (vector.y - vector1.y) * 0.05D; squareOfFame = Math.sqrt(motionX * motionX + motionZ * motionZ); if (squareOfFame > 0) { motionX = motionX / squareOfFame * (squareOfFame + d14); motionZ = motionZ / squareOfFame * (squareOfFame + d14); } setPosition(new Vector3(x, vector1.y, z)); } int floorX = MathHelper.floor(x); int floorZ = MathHelper.floor(z); if (floorX != dx || floorZ != dz) { squareOfFame = Math.sqrt(motionX * motionX + motionZ * motionZ); motionX = squareOfFame * (double) (floorX - dx); motionZ = squareOfFame * (double) (floorZ - dz); } if (isPowered) { double newMovie = Math.sqrt(motionX * motionX + motionZ * motionZ); if (newMovie > 0.01D) { double nextMovie = 0.06D; motionX += motionX / newMovie * nextMovie; motionZ += motionZ / newMovie * nextMovie; } else if (block.getOrientation() == Orientation.STRAIGHT_NORTH_SOUTH) { if (level.getBlock(new Vector3(dx - 1, dy, dz)).isNormalBlock()) { motionX = 0.02D; } else if (level.getBlock(new Vector3(dx + 1, dy, dz)).isNormalBlock()) { motionX = -0.02D; } } else if (block.getOrientation() == Orientation.STRAIGHT_EAST_WEST) { if (level.getBlock(new Vector3(dx, dy, dz - 1)).isNormalBlock()) { motionZ = 0.02D; } else if (level.getBlock(new Vector3(dx, dy, dz + 1)).isNormalBlock()) { motionZ = -0.02D; } } } } private void applyDrag() { if (linkedEntity != null || !slowWhenEmpty) { motionX *= 0.996999979019165D; motionY *= 0.0D; motionZ *= 0.996999979019165D; } else { motionX *= 0.9599999785423279D; motionY *= 0.0D; motionZ *= 0.9599999785423279D; } } private Vector3 getNextRail(double dx, double dy, double dz) { int checkX = MathHelper.floor(dx); int checkY = MathHelper.floor(dy); int checkZ = MathHelper.floor(dz); if (Rail.isRailBlock(level.getBlockIdAt(checkX, checkY - 1, checkZ))) { --checkY; } Block block = level.getBlock(new Vector3(checkX, checkY, checkZ)); if (Rail.isRailBlock(block)) { int[][] facing = matrix[((BlockRail) block).getRealMeta()]; double rail; // Genisys mistake (Doesn't check surrounding more exactly) double nextOne = (double) checkX + 0.5D + (double) facing[0][0] * 0.5D; double nextTwo = (double) checkY + 0.5D + (double) facing[0][1] * 0.5D; double nextThree = (double) checkZ + 0.5D + (double) facing[0][2] * 0.5D; double nextFour = (double) checkX + 0.5D + (double) facing[1][0] * 0.5D; double nextFive = (double) checkY + 0.5D + (double) facing[1][1] * 0.5D; double nextSix = (double) checkZ + 0.5D + (double) facing[1][2] * 0.5D; double nextSeven = nextFour - nextOne; double nextEight = (nextFive - nextTwo) * 2; double nextMax = nextSix - nextThree; if (nextSeven == 0) { rail = dz - (double) checkZ; } else if (nextMax == 0) { rail = dx - (double) checkX; } else { double whatOne = dx - nextOne; double whatTwo = dz - nextThree; rail = (whatOne * nextSeven + whatTwo * nextMax) * 2; } dx = nextOne + nextSeven * rail; dy = nextTwo + nextEight * rail; dz = nextThree + nextMax * rail; if (nextEight < 0) { ++dy; } if (nextEight > 0) { dy += 0.5D; } return new Vector3(dx, dy, dz); } else { return null; } } /** * Used to multiply the minecart current speed * * @param speed The speed of the minecart that will be calculated */ public void setCurrentSpeed(double speed) { currentSpeed = speed; } private void prepareDataProperty() { setRollingAmplitude(0); setRollingDirection(1); setDamage(0); if (namedTag.contains("CustomDisplayTile")) { if (namedTag.getBoolean("CustomDisplayTile")) { int display = namedTag.getInt("DisplayTile"); int offSet = namedTag.getInt("DisplayOffset"); setDataProperty(new ByteEntityData(DATA_MINECART_HAS_DISPLAY, 1)); setDataProperty(new IntEntityData(DATA_MINECART_DISPLAY_BLOCK, display)); setDataProperty(new IntEntityData(DATA_MINECART_DISPLAY_OFFSET, offSet)); } } else { int display = blockInside == null ? 0 : blockInside.getId() | blockInside.getDamage() << 16; if (display == 0) { setDataProperty(new ByteEntityData(DATA_MINECART_HAS_DISPLAY, 0)); return; } setDataProperty(new ByteEntityData(DATA_MINECART_HAS_DISPLAY, 1)); setDataProperty(new IntEntityData(DATA_MINECART_DISPLAY_BLOCK, display)); setDataProperty(new IntEntityData(DATA_MINECART_DISPLAY_OFFSET, 6)); } } private void saveEntityData() { boolean hasDisplay = super.getDataPropertyByte(DATA_MINECART_HAS_DISPLAY) == 1 || blockInside != null; int display; int offSet; namedTag.putBoolean("CustomDisplayTile", hasDisplay); if (hasDisplay) { display = blockInside.getId() | blockInside.getDamage() << 16; offSet = getDataPropertyInt(DATA_MINECART_DISPLAY_OFFSET); namedTag.putInt("DisplayTile", display); namedTag.putInt("DisplayOffset", offSet); } } /** * 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; } /** * Get the minecart display block * * @return Block of minecart display block */ @API(usage = Usage.STABLE, definition = Definition.UNIVERSAL) public Block getDisplayBlock() { return blockInside; } /** * 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)); } /** * Get the block display offset * * @return integer */ @API(usage = Usage.EXPERIMENTAL, definition = Definition.UNIVERSAL) public int getDisplayBlockOffset() { return super.getDataPropertyInt(DATA_MINECART_DISPLAY_OFFSET); } /** * Is the minecart can be slowed when empty? * * @return boolean */ @API(usage = Usage.EXPERIMENTAL, definition = Definition.UNIVERSAL) public boolean isSlowWhenEmpty() { return slowWhenEmpty; } /** * Set the minecart slowdown flag * * @param slow The slowdown flag */ @API(usage = Usage.EXPERIMENTAL, definition = Definition.UNIVERSAL) public void setSlowWhenEmpty(boolean slow) { slowWhenEmpty = slow; } public Vector3 getFlyingVelocityMod() { return new Vector3(flyingX, flyingY, flyingZ); } public void setFlyingVelocityMod(Vector3 flying) { Objects.requireNonNull(flying, "Flying velocity modifiers cannot be null"); flyingX = flying.getX(); flyingY = flying.getY(); flyingZ = flying.getZ(); } public Vector3 getDerailedVelocityMod() { return new Vector3(derailedX, derailedY, derailedZ); } public void setDerailedVelocityMod(Vector3 derailed) { Objects.requireNonNull(derailed, "Derailed velocity modifiers cannot be null"); derailedX = derailed.getX(); derailedY = derailed.getY(); derailedZ = derailed.getZ(); } public void setMaximumSpeed(double speed) { maxSpeed = speed; } }
27,632
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityXPOrb.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/item/EntityXPOrb.java
package cn.nukkit.entity.item; import cn.nukkit.Player; import cn.nukkit.entity.Entity; import cn.nukkit.entity.data.EntityMetadata; import cn.nukkit.event.entity.EntityDamageEvent; import cn.nukkit.event.entity.EntityDamageEvent.DamageCause; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; /** * Created on 2015/12/26 by xtypr. * Package cn.nukkit.entity in project Nukkit . */ public class EntityXPOrb extends Entity { public static final int NETWORK_ID = 69; @Override public int getNetworkId() { return NETWORK_ID; } @Override public float getWidth() { return 0.25f; } @Override public float getLength() { return 0.25f; } @Override public float getHeight() { return 0.25f; } @Override protected float getGravity() { return 0.04f; } @Override protected float getDrag() { return 0.02f; } @Override public boolean canCollide() { return false; } public EntityXPOrb(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } private int age; private int pickupDelay; private int exp; public Player closestPlayer = null; @Override protected void initEntity() { super.initEntity(); setMaxHealth(5); setHealth(5); if (namedTag.contains("Age")) { this.age = namedTag.getInt("Age"); } if (namedTag.contains("PickupDelay")) { this.pickupDelay = namedTag.getInt("PickupDelay"); } //call event item spawn event } @Override public boolean attack(EntityDamageEvent source) { return (source.getCause() == DamageCause.VOID || source.getCause() == DamageCause.FIRE_TICK || source.getCause() == DamageCause.ENTITY_EXPLOSION || source.getCause() == DamageCause.BLOCK_EXPLOSION) && super.attack(source); } @Override public boolean onUpdate(int currentTick) { if (this.closed) { return false; } int tickDiff = currentTick - this.lastUpdate; if (tickDiff <= 0 && !this.justCreated) { return true; } this.lastUpdate = currentTick; boolean hasUpdate = entityBaseTick(tickDiff); if (this.isAlive()) { if (this.pickupDelay > 0 && this.pickupDelay < 32767) { //Infinite delay this.pickupDelay -= tickDiff; if (this.pickupDelay < 0) { this.pickupDelay = 0; } } else { for (Entity entity : this.level.getCollidingEntities(this.boundingBox, this)) { if (entity instanceof Player) { if (((Player) entity).pickupEntity(this, false)) { return true; } } } } this.motionY -= this.getGravity(); if (this.checkObstruction(this.x, this.y, this.z)) { hasUpdate = true; } if (this.closestPlayer == null || this.closestPlayer.distanceSquared(this) > 64.0D) { for (Player p : level.getPlayers().values()) { if (!p.isSpectator() && p.distance(this) <= 8) { this.closestPlayer = p; break; } } } if (this.closestPlayer != null && this.closestPlayer.isSpectator()) { this.closestPlayer = null; } if (this.closestPlayer != null) { double dX = (this.closestPlayer.x - this.x) / 8.0D; double dY = (this.closestPlayer.y + (double) this.closestPlayer.getEyeHeight() / 2.0D - this.y) / 8.0D; double dZ = (this.closestPlayer.z - this.z) / 8.0D; double d = Math.sqrt(dX * dX + dY * dY + dZ * dZ); double diff = 1.0D - d; if (diff > 0.0D) { diff = diff * diff; this.motionX += dX / d * diff * 0.1D; this.motionY += dY / d * diff * 0.1D; this.motionZ += dZ / d * diff * 0.1D; } } this.move(this.motionX, this.motionY, this.motionZ); double friction = 1d - this.getDrag(); if (this.onGround && (Math.abs(this.motionX) > 0.00001 || Math.abs(this.motionZ) > 0.00001)) { friction = this.getLevel().getBlock(this.temporalVector.setComponents((int) Math.floor(this.x), (int) Math.floor(this.y - 1), (int) Math.floor(this.z) - 1)).getFrictionFactor() * friction; } this.motionX *= friction; this.motionY *= 1 - this.getDrag(); this.motionZ *= friction; if (this.onGround) { this.motionY *= -0.5; } this.updateMovement(); if (this.age > 6000) { this.kill(); hasUpdate = true; } } return hasUpdate || !this.onGround || Math.abs(this.motionX) > 0.00001 || Math.abs(this.motionY) > 0.00001 || Math.abs(this.motionZ) > 0.00001; } @Override public void saveNBT() { super.saveNBT(); this.namedTag.putShort("Health", (int) getHealth()); this.namedTag.putShort("Age", age); this.namedTag.putShort("PickupDelay", pickupDelay); } public int getExp() { return exp; } public void setExp(int exp) { this.exp = exp; } @Override public boolean canCollideWith(Entity entity) { return false; } public int getPickupDelay() { return pickupDelay; } public void setPickupDelay(int pickupDelay) { this.pickupDelay = pickupDelay; } @Override public void spawnTo(Player player) { AddEntityPacket packet = new AddEntityPacket(); packet.type = getNetworkId(); packet.entityUniqueId = this.getId(); packet.entityRuntimeId = getId(); packet.x = (float) this.x; packet.y = (float) this.y; packet.z = (float) this.z; packet.speedX = (float) this.motionX; packet.speedY = (float) this.motionY; packet.speedZ = (float) this.motionZ; packet.metadata = new EntityMetadata(); player.dataPacket(packet); //this.sendData(player); super.spawnTo(player); } }
6,626
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityPrimedTNT.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/item/EntityPrimedTNT.java
package cn.nukkit.entity.item; import cn.nukkit.Player; import cn.nukkit.entity.Entity; import cn.nukkit.entity.EntityExplosive; import cn.nukkit.entity.data.IntEntityData; import cn.nukkit.event.entity.EntityDamageEvent; import cn.nukkit.event.entity.EntityDamageEvent.DamageCause; import cn.nukkit.event.entity.EntityExplosionPrimeEvent; import cn.nukkit.level.Explosion; import cn.nukkit.level.GameRule; import cn.nukkit.level.Sound; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; /** * @author MagicDroidX */ public class EntityPrimedTNT extends Entity implements EntityExplosive { public static final int NETWORK_ID = 65; @Override public float getWidth() { return 0.98f; } @Override public float getLength() { return 0.98f; } @Override public float getHeight() { return 0.98f; } @Override protected float getGravity() { return 0.04f; } @Override protected float getDrag() { return 0.02f; } @Override protected float getBaseOffset() { return 0.49f; } @Override public boolean canCollide() { return false; } protected int fuse; public EntityPrimedTNT(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override public int getNetworkId() { return NETWORK_ID; } @Override public boolean attack(EntityDamageEvent source) { return source.getCause() == DamageCause.VOID && super.attack(source); } 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); } public boolean canCollideWith(Entity entity) { return false; } public void saveNBT() { super.saveNBT(); namedTag.putByte("Fuse", fuse); } 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; } public void explode() { EntityExplosionPrimeEvent event = new EntityExplosionPrimeEvent(this, 4); server.getPluginManager().callEvent(event); if (event.isCancelled()) { return; } Explosion explosion = new Explosion(this, event.getForce(), this); if (event.isBlockBreaking()) { explosion.explodeA(); } explosion.explodeB(); } public void spawnTo(Player player) { AddEntityPacket packet = new AddEntityPacket(); packet.type = EntityPrimedTNT.NETWORK_ID; packet.entityUniqueId = this.getId(); packet.entityRuntimeId = getId(); packet.x = (float) x; packet.y = (float) y; packet.z = (float) z; packet.speedX = (float) motionX; packet.speedY = (float) motionY; packet.speedZ = (float) motionZ; packet.metadata = dataProperties; player.dataPacket(packet); super.spawnTo(player); } }
4,475
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityMinecartHopper.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/item/EntityMinecartHopper.java
package cn.nukkit.entity.item; import cn.nukkit.block.BlockHopper; import cn.nukkit.item.ItemMinecartHopper; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.utils.MinecartType; public class EntityMinecartHopper extends EntityMinecartAbstract { public static final int NETWORK_ID = 96; public EntityMinecartHopper(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); super.setDisplayBlock(new BlockHopper()); } // TODO: 2016/12/18 inventory @Override public MinecartType getType() { return MinecartType.valueOf(5); } @Override public int getNetworkId() { return NETWORK_ID; } @Override public void dropItem() { level.dropItem(this, new ItemMinecartHopper()); } }
812
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityMinecartTNT.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/item/EntityMinecartTNT.java
package cn.nukkit.entity.item; import cn.nukkit.block.BlockTNT; import cn.nukkit.entity.EntityExplosive; import cn.nukkit.event.entity.EntityExplosionPrimeEvent; import cn.nukkit.item.ItemMinecartTNT; import cn.nukkit.level.Explosion; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.utils.MinecartType; import java.util.Random; /** * Author: Adam Matthew [larryTheCoder] * <p> * Nukkit Project. */ public class EntityMinecartTNT extends EntityMinecartAbstract implements EntityExplosive { public static final int NETWORK_ID = 97; //wtf? private int fuse; private boolean activated; public EntityMinecartTNT(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); super.setDisplayBlock(new BlockTNT()); } @Override public void initEntity() { super.initEntity(); this.fuse = namedTag.getInt("TNTFuse"); this.setDataFlag(DATA_FLAGS, DATA_FLAG_CHARGED, false); } @Override public void activate(int i, int j, int k, boolean flag) { // TODO: Find out why minecart doesnt have a right TNT fuse length // Could be implemented in the future! } @Override public void explode() { explode(0); } public void explode(double square) { double root = Math.sqrt(square); if (root > 5.0D) { root = 5.0D; } EntityExplosionPrimeEvent event = new EntityExplosionPrimeEvent(this, (4.0D + new Random().nextDouble() * 1.5D * root)); server.getPluginManager().callEvent(event); if (event.isCancelled()) { return; } Explosion explosion = new Explosion(this, event.getForce(), this); if (event.isBlockBreaking()) { explosion.explodeA(); } explosion.explodeB(); kill(); } @Override public void dropItem() { level.dropItem(this, new ItemMinecartTNT()); } @Override public MinecartType getType() { return MinecartType.valueOf(3); } @Override public int getNetworkId() { return EntityMinecartTNT.NETWORK_ID; } @Override public void saveNBT() { super.saveNBT(); super.namedTag.putInt("TNTFuse", this.fuse); } }
2,294
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityVehicle.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/item/EntityVehicle.java
package cn.nukkit.entity.item; import cn.nukkit.Player; import cn.nukkit.Server; import cn.nukkit.entity.Entity; import cn.nukkit.entity.EntityInteractable; import cn.nukkit.entity.EntityRideable; import cn.nukkit.entity.data.IntEntityData; import cn.nukkit.event.entity.EntityVehicleEnterEvent; import cn.nukkit.event.entity.EntityVehicleExitEvent; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.SetEntityLinkPacket; import java.util.Objects; /** * author: MagicDroidX * Nukkit Project */ public abstract class EntityVehicle extends Entity implements EntityRideable, EntityInteractable { public EntityVehicle(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } public int getRollingAmplitude() { return this.getDataPropertyInt(DATA_HURT_TIME); } public void setRollingAmplitude(int time) { this.setDataProperty(new IntEntityData(DATA_HURT_TIME, time)); } public int getRollingDirection() { return this.getDataPropertyInt(DATA_HURT_DIRECTION); } public void setRollingDirection(int direction) { this.setDataProperty(new IntEntityData(DATA_HURT_DIRECTION, direction)); } public int getDamage() { return this.getDataPropertyInt(DATA_HEALTH); // false data name (should be DATA_DAMAGE_TAKEN) } public void setDamage(int damage) { this.setDataProperty(new IntEntityData(DATA_HEALTH, damage)); } @Override public String getInteractButtonText() { return "Mount"; } @Override public boolean canDoInteraction() { return linkedEntity == null; } /** * Mount or Dismounts an Entity from a vehicle * * @param entity The target Entity * @return {@code true} if the mounting successful */ @Override public boolean mountEntity(Entity entity) { Objects.requireNonNull(entity, "The target of the mounting entity can't be null"); this.PitchDelta = 0.0D; this.YawDelta = 0.0D; if (entity.riding != null) { EntityVehicleExitEvent ev = new EntityVehicleExitEvent(entity, this); server.getPluginManager().callEvent(ev); if (ev.isCancelled()) { return false; } SetEntityLinkPacket pk; pk = new SetEntityLinkPacket(); pk.rider = getId(); //Weird Weird Weird pk.riding = entity.getId(); pk.type = 3; Server.broadcastPacket(this.hasSpawned.values(), pk); if (entity instanceof Player) { pk = new SetEntityLinkPacket(); pk.rider = getId(); pk.riding = entity.getId(); pk.type = 3; ((Player) entity).dataPacket(pk); } entity.riding = null; linkedEntity = null; entity.setDataFlag(DATA_FLAGS, DATA_FLAG_RIDING, false); return true; } EntityVehicleEnterEvent ev = new EntityVehicleEnterEvent(entity, this); server.getPluginManager().callEvent(ev); if (ev.isCancelled()) { return false; } SetEntityLinkPacket pk; pk = new SetEntityLinkPacket(); pk.rider = this.getId(); pk.riding = entity.getId(); pk.type = 2; Server.broadcastPacket(this.hasSpawned.values(), pk); if (entity instanceof Player) { pk = new SetEntityLinkPacket(); pk.rider = this.getId(); pk.riding = 0; pk.type = 2; ((Player) entity).dataPacket(pk); } entity.riding = this; linkedEntity = entity; entity.setDataFlag(DATA_FLAGS, DATA_FLAG_RIDING, true); updateRiderPosition(getMountedYOffset()); return true; } @Override public boolean onUpdate(int currentTick) { // The rolling amplitude if (getRollingAmplitude() > 0) { setRollingAmplitude(getRollingAmplitude() - 1); } // The damage token if (getDamage() > 0) { setDamage(getDamage() - 1); } // A killer task if (y < -16) { kill(); } // Movement code updateMovement(); return true; } protected boolean rollingDirection = true; protected boolean performHurtAnimation(int damage) { if (damage >= this.getHealth()) { return false; } // Vehicle does not respond hurt animation on packets // It only respond on vehicle data flags. Such as these setRollingAmplitude(10); setRollingDirection(rollingDirection ? 1 : -1); rollingDirection = !rollingDirection; setDamage(getDamage() + damage); return true; } }
4,856
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityMinecartChest.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/item/EntityMinecartChest.java
package cn.nukkit.entity.item; import cn.nukkit.block.BlockChest; import cn.nukkit.item.ItemMinecartChest; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.utils.MinecartType; /** * Created by Snake1999 on 2016/1/30. * Package cn.nukkit.entity.item in project Nukkit. */ public class EntityMinecartChest extends EntityMinecartAbstract { public static final int NETWORK_ID = 98; public EntityMinecartChest(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); super.setDisplayBlock(new BlockChest()); } // TODO: 2016/1/30 inventory @Override public MinecartType getType() { return MinecartType.valueOf(1); } @Override public int getNetworkId() { return NETWORK_ID; } @Override public void dropItem() { level.dropItem(this, new ItemMinecartChest()); } }
905
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityExpBottle.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/item/EntityExpBottle.java
package cn.nukkit.entity.item; import cn.nukkit.Player; import cn.nukkit.entity.Entity; import cn.nukkit.entity.projectile.EntityProjectile; import cn.nukkit.level.format.FullChunk; import cn.nukkit.level.particle.EnchantParticle; import cn.nukkit.level.particle.Particle; import cn.nukkit.level.particle.SpellParticle; import cn.nukkit.math.NukkitRandom; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; /** * @author xtypr */ public class EntityExpBottle extends EntityProjectile { public static final int NETWORK_ID = 68; @Override public int getNetworkId() { return NETWORK_ID; } @Override public float getWidth() { return 0.25f; } @Override public float getLength() { return 0.25f; } @Override public float getHeight() { return 0.25f; } @Override protected float getGravity() { return 0.1f; } @Override protected float getDrag() { return 0.01f; } public EntityExpBottle(FullChunk chunk, CompoundTag nbt) { this(chunk, nbt, null); } public EntityExpBottle(FullChunk chunk, CompoundTag nbt, Entity shootingEntity) { super(chunk, nbt, shootingEntity); } @Override public boolean onUpdate(int currentTick) { if (this.closed) { return false; } this.timing.startTiming(); int tickDiff = currentTick - this.lastUpdate; boolean hasUpdate = super.onUpdate(currentTick); if (this.age > 1200) { this.kill(); hasUpdate = true; } if (this.isCollided) { this.kill(); Particle particle1 = new EnchantParticle(this); this.getLevel().addParticle(particle1); Particle particle2 = new SpellParticle(this, 0x00385dc6); this.getLevel().addParticle(particle2); hasUpdate = true; NukkitRandom random = new NukkitRandom(); int add = 1; for (int ii = 1; ii <= random.nextRange(3, 11); ii += add) { getLevel().dropExpOrb(this, add); add = random.nextRange(1, 3); } } this.timing.stopTiming(); return hasUpdate; } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = EntityExpBottle.NETWORK_ID; pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } }
2,869
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityItem.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/item/EntityItem.java
package cn.nukkit.entity.item; import cn.nukkit.Player; import cn.nukkit.entity.Entity; import cn.nukkit.event.entity.EntityDamageEvent; import cn.nukkit.event.entity.EntityDamageEvent.DamageCause; import cn.nukkit.event.entity.ItemDespawnEvent; import cn.nukkit.event.entity.ItemSpawnEvent; import cn.nukkit.item.Item; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.NBTIO; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddItemEntityPacket; /** * @author MagicDroidX */ public class EntityItem extends Entity { public static final int NETWORK_ID = 64; public static final int DATA_SOURCE_ID = 17; public EntityItem(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override public int getNetworkId() { return NETWORK_ID; } protected String owner; protected String thrower; protected Item item; protected int pickupDelay; @Override public float getWidth() { return 0.25f; } @Override public float getLength() { return 0.25f; } @Override public float getHeight() { return 0.25f; } @Override public float getGravity() { return 0.04f; } @Override public float getDrag() { return 0.02f; } @Override protected float getBaseOffset() { return 0.125f; } @Override public boolean canCollide() { return false; } @Override protected void initEntity() { super.initEntity(); this.setMaxHealth(5); this.setHealth(this.namedTag.getShort("Health")); if (this.namedTag.contains("Age")) { this.age = this.namedTag.getShort("Age"); } if (this.namedTag.contains("PickupDelay")) { this.pickupDelay = this.namedTag.getShort("PickupDelay"); } if (this.namedTag.contains("Owner")) { this.owner = this.namedTag.getString("Owner"); } if (this.namedTag.contains("Thrower")) { this.thrower = this.namedTag.getString("Thrower"); } if (!this.namedTag.contains("Item")) { this.close(); return; } this.item = NBTIO.getItemHelper(this.namedTag.getCompound("Item")); this.setDataFlag(DATA_FLAGS, DATA_FLAG_IMMOBILE, true); this.server.getPluginManager().callEvent(new ItemSpawnEvent(this)); } @Override public boolean attack(EntityDamageEvent source) { return (source.getCause() == DamageCause.VOID || source.getCause() == DamageCause.FIRE_TICK || source.getCause() == DamageCause.ENTITY_EXPLOSION || source.getCause() == DamageCause.BLOCK_EXPLOSION) && super.attack(source); } @Override public boolean onUpdate(int currentTick) { if (this.closed) { return false; } int tickDiff = currentTick - this.lastUpdate; if (tickDiff <= 0 && !this.justCreated) { return true; } this.lastUpdate = currentTick; this.timing.startTiming(); boolean hasUpdate = this.entityBaseTick(tickDiff); if (this.isAlive()) { if (this.pickupDelay > 0 && this.pickupDelay < 32767) { this.pickupDelay -= tickDiff; if (this.pickupDelay < 0) { this.pickupDelay = 0; } } else { for (Entity entity : this.level.getNearbyEntities(this.boundingBox.grow(1, 0.5, 1), this)) { if (entity instanceof Player) { if (((Player) entity).pickupEntity(this, true)) { return true; } } } } this.motionY -= this.getGravity(); if (this.checkObstruction(this.x, this.y, this.z)) { hasUpdate = true; } this.move(this.motionX, this.motionY, this.motionZ); double friction = 1 - this.getDrag(); if (this.onGround && (Math.abs(this.motionX) > 0.00001 || Math.abs(this.motionZ) > 0.00001)) { friction *= this.getLevel().getBlock(this.temporalVector.setComponents((int) Math.floor(this.x), (int) Math.floor(this.y - 1), (int) Math.floor(this.z) - 1)).getFrictionFactor(); } this.motionX *= friction; this.motionY *= 1 - this.getDrag(); this.motionZ *= friction; if (this.onGround) { this.motionY *= -0.5; } this.updateMovement(); if (this.age > 6000) { ItemDespawnEvent ev = new ItemDespawnEvent(this); this.server.getPluginManager().callEvent(ev); if (ev.isCancelled()) { this.age = 0; } else { this.kill(); hasUpdate = true; } } } this.timing.stopTiming(); return hasUpdate || !this.onGround || Math.abs(this.motionX) > 0.00001 || Math.abs(this.motionY) > 0.00001 || Math.abs(this.motionZ) > 0.00001; } @Override public void saveNBT() { super.saveNBT(); if (this.item != null) { // Yes, a item can be null... I don't know what causes this, but it can happen. this.namedTag.putCompound("Item", NBTIO.putItemHelper(this.item, -1)); this.namedTag.putShort("Health", (int) this.getHealth()); this.namedTag.putShort("Age", this.age); this.namedTag.putShort("PickupDelay", this.pickupDelay); if (this.owner != null) { this.namedTag.putString("Owner", this.owner); } if (this.thrower != null) { this.namedTag.putString("Thrower", this.thrower); } } } @Override public String getName() { return this.hasCustomName() ? this.getNameTag() : (this.item.hasCustomName() ? this.item.getCustomName() : this.item.getName()); } public Item getItem() { return item; } @Override public boolean canCollideWith(Entity entity) { return false; } public int getPickupDelay() { return pickupDelay; } public void setPickupDelay(int pickupDelay) { this.pickupDelay = pickupDelay; } public String getOwner() { return owner; } public void setOwner(String owner) { this.owner = owner; } public String getThrower() { return thrower; } public void setThrower(String thrower) { this.thrower = thrower; } @Override public void spawnTo(Player player) { AddItemEntityPacket pk = new AddItemEntityPacket(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; pk.item = this.getItem(); player.dataPacket(pk); super.spawnTo(player); } @Override public boolean doesTriggerPressurePlate() { return true; } }
7,410
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityFallingBlock.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/item/EntityFallingBlock.java
package cn.nukkit.entity.item; import cn.nukkit.Player; import cn.nukkit.block.Block; import cn.nukkit.entity.Entity; import cn.nukkit.entity.data.IntEntityData; import cn.nukkit.event.entity.EntityBlockChangeEvent; import cn.nukkit.event.entity.EntityDamageEvent; import cn.nukkit.event.entity.EntityDamageEvent.DamageCause; import cn.nukkit.item.Item; import cn.nukkit.level.GameRule; import cn.nukkit.level.Sound; import cn.nukkit.level.format.FullChunk; import cn.nukkit.math.Vector3; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; /** * @author MagicDroidX */ public class EntityFallingBlock extends Entity { public static final int NETWORK_ID = 66; @Override public float getWidth() { return 0.98f; } @Override public float getLength() { return 0.98f; } @Override public float getHeight() { return 0.98f; } @Override protected float getGravity() { return 0.04f; } @Override protected float getDrag() { return 0.02f; } @Override protected float getBaseOffset() { return 0.49f; } @Override public boolean canCollide() { return false; } protected int blockId; protected int damage; public EntityFallingBlock(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @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)); } public boolean canCollideWith(Entity entity) { return false; } @Override public boolean attack(EntityDamageEvent source) { return source.getCause() == DamageCause.VOID && super.attack(source); } @Override public boolean onUpdate(int currentTick) { if (closed) { return false; } this.timing.startTiming(); int tickDiff = currentTick - lastUpdate; if (tickDiff <= 0 && !justCreated) { return true; } lastUpdate = currentTick; boolean hasUpdate = entityBaseTick(tickDiff); if (isAlive()) { motionY -= getGravity(); move(motionX, motionY, motionZ); float friction = 1 - getDrag(); motionX *= friction; motionY *= 1 - getDrag(); motionZ *= friction; Vector3 pos = (new Vector3(x - 0.5, y, z - 0.5)).round(); if (onGround) { kill(); Block block = level.getBlock(pos); if (block.getId() > 0 && block.isTransparent() && !block.canBeReplaced()) { if (this.level.getGameRules().getBoolean(GameRule.DO_ENTITY_DROPS)) { getLevel().dropItem(this, Item.get(this.getBlock(), this.getDamage(), 1)); } } else { EntityBlockChangeEvent event = new EntityBlockChangeEvent(this, block, Block.get(getBlock(), getDamage())); server.getPluginManager().callEvent(event); if (!event.isCancelled()) { getLevel().setBlock(pos, event.getTo(), true); if (event.getTo().getId() == Item.ANVIL) { getLevel().addSound(pos, Sound.RANDOM_ANVIL_LAND); } } } hasUpdate = true; } updateMovement(); } this.timing.stopTiming(); return hasUpdate || !onGround || Math.abs(motionX) > 0.00001 || Math.abs(motionY) > 0.00001 || Math.abs(motionZ) > 0.00001; } public int getBlock() { return blockId; } public int getDamage() { return damage; } @Override public int getNetworkId() { return NETWORK_ID; } @Override public void saveNBT() { namedTag.putInt("TileID", blockId); namedTag.putByte("Data", damage); } @Override public void spawnTo(Player player) { AddEntityPacket packet = new AddEntityPacket(); packet.type = EntityFallingBlock.NETWORK_ID; packet.entityUniqueId = this.getId(); packet.entityRuntimeId = getId(); packet.x = (float) x; packet.y = (float) y; packet.z = (float) z; packet.speedX = (float) motionX; packet.speedY = (float) motionY; packet.speedZ = (float) motionZ; packet.yaw = (float) yaw; packet.pitch = (float) pitch; packet.metadata = dataProperties; player.dataPacket(packet); super.spawnTo(player); } }
5,224
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityMinecartEmpty.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/item/EntityMinecartEmpty.java
package cn.nukkit.entity.item; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.utils.MinecartType; /** * Created by Snake1999 on 2016/1/30. * Package cn.nukkit.entity.item in project Nukkit. */ public class EntityMinecartEmpty extends EntityMinecartAbstract { public static final int NETWORK_ID = 84; @Override public int getNetworkId() { return NETWORK_ID; } public EntityMinecartEmpty(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override public MinecartType getType() { return MinecartType.valueOf(0); } @Override protected void activate(int x, int y, int z, boolean flag) { if (flag) { if (this.riding != null) { mountEntity(riding); } // looks like MCPE and MCPC not same XD // removed rolling feature from here because of MCPE logic? } } }
969
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityPotion.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/item/EntityPotion.java
package cn.nukkit.entity.item; import cn.nukkit.Player; import cn.nukkit.entity.Entity; import cn.nukkit.entity.projectile.EntityProjectile; import cn.nukkit.event.potion.PotionCollideEvent; import cn.nukkit.level.format.FullChunk; import cn.nukkit.level.particle.InstantSpellParticle; import cn.nukkit.level.particle.Particle; import cn.nukkit.level.particle.SpellParticle; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; import cn.nukkit.potion.Effect; import cn.nukkit.potion.Potion; /** * @author xtypr */ public class EntityPotion extends EntityProjectile { public static final int NETWORK_ID = 86; public static final int DATA_POTION_ID = 37; public int potionId; public EntityPotion(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } public EntityPotion(FullChunk chunk, CompoundTag nbt, Entity shootingEntity) { super(chunk, nbt, shootingEntity); } @Override protected void initEntity() { super.initEntity(); potionId = this.namedTag.getShort("PotionId"); this.dataProperties.putShort(DATA_POTION_ID, this.potionId); /*Effect effect = Potion.getEffect(potionId, true); TODO: potion color if(effect != null) { int count = 0; int[] c = effect.getColor(); count += effect.getAmplifier() + 1; int r = ((c[0] * (effect.getAmplifier() + 1)) / count) & 0xff; int g = ((c[1] * (effect.getAmplifier() + 1)) / count) & 0xff; int b = ((c[2] * (effect.getAmplifier() + 1)) / count) & 0xff; this.setDataProperty(new IntEntityData(Entity.DATA_UNKNOWN, (r << 16) + (g << 8) + b)); }*/ } @Override public int getNetworkId() { return NETWORK_ID; } @Override public float getWidth() { return 0.25f; } @Override public float getLength() { return 0.25f; } @Override public float getHeight() { return 0.25f; } @Override protected float getGravity() { return 0.1f; } @Override protected float getDrag() { return 0.01f; } @Override public boolean onUpdate(int currentTick) { if (this.closed) { return false; } this.timing.startTiming(); int tickDiff = currentTick - this.lastUpdate; boolean hasUpdate = super.onUpdate(currentTick); if (this.age > 1200) { this.kill(); hasUpdate = true; } if (this.isCollided) { this.kill(); Potion potion = Potion.getPotion(this.potionId); PotionCollideEvent event = new PotionCollideEvent(potion, this); this.server.getPluginManager().callEvent(event); if (event.isCancelled()) { return false; } potion = event.getPotion(); if (potion == null) { return false; } potion.setSplash(true); Particle particle; int r; int g; int b; Effect effect = Potion.getEffect(potion.getId(), true); if (effect == null) { r = 40; g = 40; b = 255; } else { int[] colors = effect.getColor(); r = colors[0]; g = colors[1]; b = colors[2]; } if (Potion.isInstant(potion.getId())) { particle = new InstantSpellParticle(this, r, g, b); } else { particle = new SpellParticle(this, r, g, b); } this.getLevel().addParticle(particle); hasUpdate = true; Entity[] entities = this.getLevel().getNearbyEntities(this.getBoundingBox().grow(8.25, 4.24, 8.25)); for (Entity anEntity : entities) { double distance = anEntity.distanceSquared(this); if (distance < 16) { double d = 1 - Math.sqrt(distance) / 4; potion.applyPotion(anEntity, d); } } } this.timing.stopTiming(); return hasUpdate; } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = EntityPotion.NETWORK_ID; pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } }
4,852
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntitySkeletonHorse.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/passive/EntitySkeletonHorse.java
package cn.nukkit.entity.passive; import cn.nukkit.Player; import cn.nukkit.item.Item; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; /** * @author PikyCZ */ public class EntitySkeletonHorse extends EntityAnimal { public static final int NETWORK_ID = 26; public EntitySkeletonHorse(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override public int getNetworkId() { return NETWORK_ID; } @Override public float getWidth() { return 1.4f; } @Override public float getHeight() { return 1.6f; } @Override public void initEntity() { super.initEntity(); this.setMaxHealth(15); } @Override public Item[] getDrops() { return new Item[]{Item.get(Item.BONE)}; } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } }
1,449
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityRabbit.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/passive/EntityRabbit.java
package cn.nukkit.entity.passive; import cn.nukkit.Player; import cn.nukkit.item.Item; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; /** * Author: BeYkeRYkt Nukkit Project */ public class EntityRabbit extends EntityAnimal { public static final int NETWORK_ID = 18; public EntityRabbit(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override public float getWidth() { if (this.isBaby()) { return 0.2f; } return 0.4f; } @Override public float getHeight() { if (this.isBaby()) { return 0.25f; } return 0.5f; } @Override public String getName() { return "Rabbit"; } @Override public Item[] getDrops() { return new Item[]{Item.get(Item.RAW_RABBIT), Item.get(Item.RABBIT_HIDE), Item.get(Item.RABBIT_FOOT)}; } @Override public int getNetworkId() { return NETWORK_ID; } @Override protected void initEntity() { super.initEntity(); setMaxHealth(10); } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } }
1,718
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityLlama.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/passive/EntityLlama.java
package cn.nukkit.entity.passive; import cn.nukkit.Player; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; /** * @author PikyCZ */ public class EntityLlama extends EntityAnimal { public static final int NETWORK_ID = 29; public EntityLlama(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override public int getNetworkId() { return NETWORK_ID; } @Override public float getWidth() { if (this.isBaby()) { return 0.45f; } return 0.9f; } @Override public float getHeight() { if (this.isBaby()) { return 0.935f; } return 1.87f; } @Override public float getEyeHeight() { if (this.isBaby()) { return 0.65f; } return 1.2f; } @Override public void initEntity() { super.initEntity(); this.setMaxHealth(15); } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } }
1,651
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityAnimal.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/passive/EntityAnimal.java
package cn.nukkit.entity.passive; import cn.nukkit.Player; import cn.nukkit.entity.Entity; import cn.nukkit.entity.EntityAgeable; import cn.nukkit.entity.EntityCreature; import cn.nukkit.item.Item; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; /** * author: MagicDroidX * Nukkit Project */ public abstract class EntityAnimal extends EntityCreature implements EntityAgeable { public EntityAnimal(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override public boolean isBaby() { return this.getDataFlag(DATA_FLAGS, Entity.DATA_FLAG_BABY); } public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } public boolean isBreedingItem(Item item) { return item.getId() == Item.WHEAT; //default } }
1,334
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityZombieHorse.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/passive/EntityZombieHorse.java
package cn.nukkit.entity.passive; import cn.nukkit.Player; import cn.nukkit.item.Item; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; /** * @author PikyCZ */ public class EntityZombieHorse extends EntityAnimal { public static final int NETWORK_ID = 27; public EntityZombieHorse(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override public int getNetworkId() { return NETWORK_ID; } @Override public float getWidth() { return 1.4f; } @Override public float getHeight() { return 1.6f; } @Override public void initEntity() { super.initEntity(); this.setMaxHealth(15); } @Override public Item[] getDrops() { return new Item[]{Item.get(Item.ROTTEN_FLESH, 1, 1)}; } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } }
1,459
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityBat.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/passive/EntityBat.java
package cn.nukkit.entity.passive; import cn.nukkit.Player; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; /** * @author PikyCZ */ public class EntityBat extends EntityAnimal { public static final int NETWORK_ID = 19; public EntityBat(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override public int getNetworkId() { return NETWORK_ID; } @Override public float getWidth() { return 0.5f; } @Override public float getHeight() { return 0.9f; } @Override public void initEntity() { super.initEntity(); this.setMaxHealth(6); } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } }
1,301
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntitySquid.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/passive/EntitySquid.java
package cn.nukkit.entity.passive; import cn.nukkit.Player; import cn.nukkit.item.Item; import cn.nukkit.item.ItemDye; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; import cn.nukkit.utils.DyeColor; /** * @author PikyCZ */ public class EntitySquid extends EntityWaterAnimal { public static final int NETWORK_ID = 17; public EntitySquid(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override public int getNetworkId() { return NETWORK_ID; } @Override public float getWidth() { return 0.8f; } @Override public float getHeight() { return 0.8f; } @Override public void initEntity() { super.initEntity(); this.setMaxHealth(10); } @Override public Item[] getDrops() { return new Item[]{new ItemDye(DyeColor.BLACK.getDyeData())}; } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } }
1,590
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityMule.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/passive/EntityMule.java
package cn.nukkit.entity.passive; import cn.nukkit.Player; import cn.nukkit.item.Item; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; /** * @author PikyCZ */ public class EntityMule extends EntityAnimal { public static final int NETWORK_ID = 25; public EntityMule(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override public Item[] getDrops() { return new Item[]{Item.get(Item.LEATHER)}; } @Override public int getNetworkId() { return NETWORK_ID; } @Override public float getWidth() { if (this.isBaby()) { return 0.6982f; } return 1.3965f; } @Override public float getHeight() { if (this.isBaby()) { return 0.8f; } return 1.6f; } @Override public void initEntity() { super.initEntity(); this.setMaxHealth(15); } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } }
1,568
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityNPC.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/passive/EntityNPC.java
package cn.nukkit.entity.passive; /** * Created by Pub4Game on 21.06.2016. */ public interface EntityNPC { }
113
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityChicken.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/passive/EntityChicken.java
package cn.nukkit.entity.passive; import cn.nukkit.Player; import cn.nukkit.item.Item; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; /** * Author: BeYkeRYkt Nukkit Project */ public class EntityChicken extends EntityAnimal { public static final int NETWORK_ID = 10; public EntityChicken(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override public float getWidth() { if (this.isBaby()) { return 0.2f; } return 0.4f; } @Override public float getHeight() { if (this.isBaby()) { return 0.35f; } return 0.7f; } @Override public String getName() { return "Chicken"; } @Override public Item[] getDrops() { return new Item[]{Item.get(Item.RAW_CHICKEN), Item.get(Item.FEATHER)}; } @Override public int getNetworkId() { return NETWORK_ID; } @Override protected void initEntity() { super.initEntity(); setMaxHealth(4); } @Override public boolean isBreedingItem(Item item) { int id = item.getId(); return id == Item.WHEAT_SEEDS || id == Item.MELON_SEEDS || id == Item.PUMPKIN_SEEDS || id == Item.BEETROOT_SEEDS; } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } }
1,911
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityMooshroom.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/passive/EntityMooshroom.java
package cn.nukkit.entity.passive; import cn.nukkit.Player; import cn.nukkit.item.Item; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; /** * Author: BeYkeRYkt Nukkit Project */ public class EntityMooshroom extends EntityAnimal { public static final int NETWORK_ID = 16; public EntityMooshroom(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override public float getWidth() { if (isBaby()) { return 0.45f; } return 0.9f; } @Override public float getHeight() { if (isBaby()) { return 0.7f; } return 1.4f; } @Override public String getName() { return "Mooshroom"; } @Override public Item[] getDrops() { return new Item[]{Item.get(Item.LEATHER), Item.get(Item.RAW_BEEF)}; } @Override public int getNetworkId() { return NETWORK_ID; } @Override protected void initEntity() { super.initEntity(); setMaxHealth(10); } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } }
1,683
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityCow.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/passive/EntityCow.java
package cn.nukkit.entity.passive; import cn.nukkit.Player; import cn.nukkit.item.Item; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; /** * Author: BeYkeRYkt Nukkit Project */ public class EntityCow extends EntityAnimal { public static final int NETWORK_ID = 11; public EntityCow(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override public float getWidth() { if (this.isBaby()) { return 0.45f; } return 0.9f; } @Override public float getHeight() { if (this.isBaby()) { return 0.7f; } return 1.4f; } @Override public String getName() { return "Cow"; } @Override public Item[] getDrops() { return new Item[]{Item.get(Item.LEATHER), Item.get(Item.RAW_BEEF)}; } @Override public int getNetworkId() { return NETWORK_ID; } @Override protected void initEntity() { super.initEntity(); this.setMaxHealth(10); } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } }
1,680
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityPolarBear.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/passive/EntityPolarBear.java
package cn.nukkit.entity.passive; import cn.nukkit.Player; import cn.nukkit.item.Item; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; /** * @author PikyCZ */ public class EntityPolarBear extends EntityAnimal { public static final int NETWORK_ID = 28; public EntityPolarBear(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override public int getNetworkId() { return NETWORK_ID; } @Override public float getWidth() { if (this.isBaby()) { return 0.65f; } return 1.3f; } @Override public float getHeight() { if (this.isBaby()) { return 0.7f; } return 1.4f; } @Override public void initEntity() { super.initEntity(); this.setMaxHealth(30); } @Override public Item[] getDrops() { return new Item[]{Item.get(Item.RAW_FISH), Item.get(Item.RAW_SALMON)}; } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } }
1,601
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityVillager.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/passive/EntityVillager.java
package cn.nukkit.entity.passive; import cn.nukkit.Player; import cn.nukkit.entity.Entity; import cn.nukkit.entity.EntityAgeable; import cn.nukkit.entity.EntityCreature; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; /** * Created by Pub4Game on 21.06.2016. */ public class EntityVillager extends EntityCreature implements EntityNPC, EntityAgeable { public static final int PROFESSION_FARMER = 0; public static final int PROFESSION_LIBRARIAN = 1; public static final int PROFESSION_PRIEST = 2; public static final int PROFESSION_BLACKSMITH = 3; public static final int PROFESSION_BUTCHER = 4; public static final int PROFESSION_GENERIC = 5; public static final int NETWORK_ID = 15; public EntityVillager(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override public float getWidth() { if (this.isBaby()) { return 0.3f; } return 0.6f; } @Override public float getHeight() { if (this.isBaby()) { return 0.975f; } return 1.95f; } @Override public String getName() { return "Villager"; } @Override public int getNetworkId() { return NETWORK_ID; } @Override public void initEntity() { super.initEntity(); if (!this.namedTag.contains("Profession")) { this.setProfession(PROFESSION_GENERIC); } } public int getProfession() { return this.namedTag.getInt("Profession"); } public void setProfession(int profession) { this.namedTag.putInt("Profession", profession); } @Override public boolean isBaby() { return this.getDataFlag(DATA_FLAGS, Entity.DATA_FLAG_BABY); } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } }
2,408
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityParrot.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/passive/EntityParrot.java
package cn.nukkit.entity.passive; import cn.nukkit.Player; import cn.nukkit.item.Item; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; /** * @author PikyCZ */ public class EntityParrot extends EntityAnimal { public static final int NETWORK_ID = 105; public EntityParrot(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override public int getNetworkId() { return NETWORK_ID; } public String getName() { return "Bat"; } @Override public float getWidth() { return 0.5f; } @Override public float getHeight() { return 0.9f; } @Override public void initEntity() { super.initEntity(); this.setMaxHealth(6); } @Override public Item[] getDrops() { return new Item[]{Item.get(Item.FEATHER)}; } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } }
1,566
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityWaterAnimal.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/passive/EntityWaterAnimal.java
package cn.nukkit.entity.passive; import cn.nukkit.entity.Entity; import cn.nukkit.entity.EntityAgeable; import cn.nukkit.entity.EntityCreature; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; /** * author: MagicDroidX * Nukkit Project */ public abstract class EntityWaterAnimal extends EntityCreature implements EntityAgeable { public EntityWaterAnimal(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override public boolean isBaby() { return this.getDataFlag(DATA_FLAGS, Entity.DATA_FLAG_BABY); } }
584
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntitySheep.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/passive/EntitySheep.java
package cn.nukkit.entity.passive; import cn.nukkit.Player; import cn.nukkit.entity.data.ByteEntityData; import cn.nukkit.event.entity.EntityDamageByEntityEvent; import cn.nukkit.item.Item; import cn.nukkit.item.ItemDye; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; import cn.nukkit.utils.DyeColor; import java.util.concurrent.ThreadLocalRandom; /** * Author: BeYkeRYkt Nukkit Project */ public class EntitySheep extends EntityAnimal { public static final int NETWORK_ID = 13; public boolean sheared = false; public int color = 0; public EntitySheep(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override public float getWidth() { if (this.isBaby()) { return 0.45f; } return 0.9f; } @Override public float getHeight() { if (isBaby()) { return 0.65f; } return 1.3f; } @Override public String getName() { return "Sheep"; } @Override public int getNetworkId() { return NETWORK_ID; } @Override public void initEntity() { this.setMaxHealth(8); if (!this.namedTag.contains("Color")) { this.setColor(randomColor()); } else { this.setColor(this.namedTag.getByte("Color")); } if (!this.namedTag.contains("Sheared")) { this.namedTag.putByte("Sheared", 0); } else { this.sheared = this.namedTag.getBoolean("Sheared"); } this.setDataFlag(DATA_FLAGS, DATA_FLAG_SHEARED, this.sheared); } @Override public void saveNBT() { super.saveNBT(); this.namedTag.putByte("Color", this.color); this.namedTag.putBoolean("Sheared", this.sheared); } @Override public boolean onInteract(Player player, Item item) { if (item.getId() == Item.DYE) { this.setColor(((ItemDye) item).getDyeColor().getWoolData()); return true; } return item.getId() == Item.SHEARS && shear(); } public boolean shear() { if (sheared) { return false; } this.sheared = true; this.setDataFlag(DATA_FLAGS, DATA_FLAG_SHEARED, true); this.level.dropItem(this, Item.get(Item.WOOL, getColor(), ThreadLocalRandom.current().nextInt(2) + 1)); return true; } @Override public Item[] getDrops() { if (this.lastDamageCause instanceof EntityDamageByEntityEvent) { return new Item[]{Item.get(Item.WOOL, getColor(), 1)}; } return new Item[0]; } public void setColor(int color) { this.color = color; this.setDataProperty(new ByteEntityData(DATA_COLOUR, color)); this.namedTag.putByte("Color", this.color); } public int getColor() { return namedTag.getByte("Color"); } private int randomColor() { ThreadLocalRandom random = ThreadLocalRandom.current(); double rand = random.nextDouble(1, 100); if (rand <= 0.164) { return DyeColor.PINK.getWoolData(); } if (rand <= 15) { return random.nextBoolean() ? DyeColor.BLACK.getWoolData() : random.nextBoolean() ? DyeColor.GRAY.getWoolData() : DyeColor.LIGHT_GRAY.getWoolData(); } return DyeColor.WHITE.getWoolData(); } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } }
4,015
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityPig.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/passive/EntityPig.java
package cn.nukkit.entity.passive; import cn.nukkit.Player; import cn.nukkit.item.Item; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; /** * Author: BeYkeRYkt Nukkit Project */ public class EntityPig extends EntityAnimal { public static final int NETWORK_ID = 12; public EntityPig(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override public float getWidth() { if (this.isBaby()) { return 0.45f; } return 0.9f; } @Override public float getHeight() { if (this.isBaby()) { return 0.45f; } return 0.9f; } @Override public void initEntity() { super.initEntity(); this.setMaxHealth(10); } @Override public String getName() { return "Pig"; } @Override public Item[] getDrops() { return new Item[]{Item.get(Item.RAW_PORKCHOP)}; } @Override public int getNetworkId() { return NETWORK_ID; } @Override public boolean isBreedingItem(Item item) { int id = item.getId(); return id == Item.CARROT || id == Item.POTATO || id == Item.BEETROOT; } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } }
1,836
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityDonkey.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/passive/EntityDonkey.java
package cn.nukkit.entity.passive; import cn.nukkit.Player; import cn.nukkit.item.Item; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; /** * @author PikyCZ */ public class EntityDonkey extends EntityAnimal { public static final int NETWORK_ID = 24; public EntityDonkey(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override public int getNetworkId() { return NETWORK_ID; } @Override public float getWidth() { if (this.isBaby()) { return 0.6982f; } return 1.3965f; } @Override public float getHeight() { if (this.isBaby()) { return 0.8f; } return 1.6f; } @Override public void initEntity() { super.initEntity(); this.setMaxHealth(15); } @Override public Item[] getDrops() { return new Item[]{Item.get(Item.LEATHER)}; } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } }
1,572
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityTameable.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/passive/EntityTameable.java
package cn.nukkit.entity.passive; import cn.nukkit.Player; import cn.nukkit.entity.EntityOwnable; import cn.nukkit.entity.data.ByteEntityData; import cn.nukkit.entity.data.StringEntityData; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; /** * Author: BeYkeRYkt * Nukkit Project */ public abstract class EntityTameable extends EntityAnimal implements EntityOwnable { public static final int DATA_TAMED_FLAG = 16; public static final int DATA_OWNER_NAME = 17; public EntityTameable(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @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")); } } @Override public void saveNBT() { super.saveNBT(); if (this.getOwnerName() == null) { namedTag.putString("Owner", ""); } else { namedTag.putString("Owner", getOwnerName()); } namedTag.putBoolean("Sitting", isSitting()); } @Override public String getOwnerName() { return getDataPropertyString(DATA_OWNER_NAME); } @Override public void setOwnerName(String playerName) { setDataProperty(new StringEntityData(DATA_OWNER_NAME, playerName)); } @Override public Player getOwner() { return getServer().getPlayer(getOwnerName()); } @Override public String getName() { return getNameTag(); } public boolean isTamed() { return (getDataPropertyByte(DATA_TAMED_FLAG) & 4) != 0; } 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))); } } public boolean isSitting() { return (getDataPropertyByte(DATA_TAMED_FLAG) & 1) != 0; } 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))); } } }
2,965
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityOcelot.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/passive/EntityOcelot.java
package cn.nukkit.entity.passive; import cn.nukkit.Player; import cn.nukkit.item.Item; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; /** * Author: BeYkeRYkt Nukkit Project */ public class EntityOcelot extends EntityAnimal { public static final int NETWORK_ID = 22; public EntityOcelot(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override public float getWidth() { if (this.isBaby()) { return 0.3f; } return 0.6f; } @Override public float getHeight() { if (this.isBaby()) { return 0.35f; } return 0.7f; } @Override public String getName() { return "Ocelot"; } @Override public int getNetworkId() { return NETWORK_ID; } @Override public void initEntity() { super.initEntity(); setMaxHealth(10); } @Override public boolean isBreedingItem(Item item) { return item.getId() == Item.RAW_FISH; } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } }
1,667
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityHorse.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/passive/EntityHorse.java
package cn.nukkit.entity.passive; import cn.nukkit.Player; import cn.nukkit.item.Item; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; /** * @author PikyCZ */ public class EntityHorse extends EntityAnimal { public static final int NETWORK_ID = 23; public EntityHorse(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override public int getNetworkId() { return NETWORK_ID; } @Override public float getWidth() { if (this.isBaby()) { return 0.6982f; } return 1.3965f; } @Override public float getHeight() { if (this.isBaby()) { return 0.8f; } return 1.6f; } @Override public void initEntity() { super.initEntity(); this.setMaxHealth(15); } @Override public Item[] getDrops() { return new Item[]{Item.get(Item.LEATHER)}; } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } }
1,570
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityWolf.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/entity/passive/EntityWolf.java
package cn.nukkit.entity.passive; import cn.nukkit.Player; import cn.nukkit.item.Item; import cn.nukkit.level.format.FullChunk; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.AddEntityPacket; /** * Author: BeYkeRYkt Nukkit Project */ public class EntityWolf extends EntityAnimal { public static final int NETWORK_ID = 14; public EntityWolf(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @Override public float getWidth() { return 0.6f; } @Override public float getHeight() { return 0.85f; } @Override public String getName() { return "Wolf"; } @Override public int getNetworkId() { return NETWORK_ID; } @Override public void initEntity() { super.initEntity(); this.setMaxHealth(8); } @Override public boolean isBreedingItem(Item item) { return false; //only certain food } @Override public void spawnTo(Player player) { AddEntityPacket pk = new AddEntityPacket(); pk.type = this.getNetworkId(); pk.entityUniqueId = this.getId(); pk.entityRuntimeId = this.getId(); pk.x = (float) this.x; pk.y = (float) this.y; pk.z = (float) this.z; pk.speedX = (float) this.motionX; pk.speedY = (float) this.motionY; pk.speedZ = (float) this.motionZ; pk.metadata = this.dataProperties; player.dataPacket(pk); super.spawnTo(player); } }
1,533
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
Metadatable.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/metadata/Metadatable.java
package cn.nukkit.metadata; import cn.nukkit.plugin.Plugin; import java.util.List; /** * author: MagicDroidX * Nukkit Project */ public interface Metadatable { void setMetadata(String metadataKey, MetadataValue newMetadataValue) throws Exception; List<MetadataValue> getMetadata(String metadataKey) throws Exception; boolean hasMetadata(String metadataKey) throws Exception; void removeMetadata(String metadataKey, Plugin owningPlugin) throws Exception; }
482
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
LevelMetadataStore.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/metadata/LevelMetadataStore.java
package cn.nukkit.metadata; import cn.nukkit.level.Level; /** * author: MagicDroidX * Nukkit Project */ public class LevelMetadataStore extends MetadataStore { @Override protected String disambiguate(Metadatable level, String metadataKey) { if (!(level instanceof Level)) { throw new IllegalArgumentException("Argument must be a Level instance"); } return (((Level) level).getName() + ":" + metadataKey).toLowerCase(); } }
477
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
MetadataStore.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/metadata/MetadataStore.java
package cn.nukkit.metadata; import cn.nukkit.plugin.Plugin; import cn.nukkit.utils.PluginException; import cn.nukkit.utils.ServerException; import java.util.*; /** * author: MagicDroidX * Nukkit Project */ public abstract class MetadataStore { private final Map<String, Map<Plugin, MetadataValue>> metadataMap = new HashMap<>(); public void setMetadata(Object subject, String metadataKey, MetadataValue newMetadataValue) { if (newMetadataValue == null) { throw new ServerException("Value cannot be null"); } Plugin owningPlugin = newMetadataValue.getOwningPlugin(); if (owningPlugin == null) { throw new PluginException("Plugin cannot be null"); } String key = this.disambiguate((Metadatable) subject, metadataKey); Map<Plugin, MetadataValue> entry = this.metadataMap.computeIfAbsent(key, k -> new WeakHashMap<>(1)); entry.put(owningPlugin, newMetadataValue); } public List<MetadataValue> getMetadata(Object subject, String metadataKey) { String key = this.disambiguate((Metadatable) subject, metadataKey); if (this.metadataMap.containsKey(key)) { Collection values = ((Map) this.metadataMap.get(key)).values(); return Collections.unmodifiableList(new ArrayList<>(values)); } return Collections.emptyList(); } public boolean hasMetadata(Object subject, String metadataKey) { return this.metadataMap.containsKey(this.disambiguate((Metadatable) subject, metadataKey)); } public void removeMetadata(Object subject, String metadataKey, Plugin owningPlugin) { if (owningPlugin == null) { throw new PluginException("Plugin cannot be null"); } String key = this.disambiguate((Metadatable) subject, metadataKey); Map entry = this.metadataMap.get(key); if (entry == null) { return; } entry.remove(owningPlugin); if (entry.isEmpty()) { this.metadataMap.remove(key); } } public void invalidateAll(Plugin owningPlugin) { if (owningPlugin == null) { throw new PluginException("Plugin cannot be null"); } for (Map value : this.metadataMap.values()) { if (value.containsKey(owningPlugin)) { ((MetadataValue) value.get(owningPlugin)).invalidate(); } } } protected abstract String disambiguate(Metadatable subject, String metadataKey); }
2,526
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
BlockMetadataStore.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/metadata/BlockMetadataStore.java
package cn.nukkit.metadata; import cn.nukkit.block.Block; import cn.nukkit.level.Level; import cn.nukkit.plugin.Plugin; import java.util.List; /** * author: MagicDroidX * Nukkit Project */ public class BlockMetadataStore extends MetadataStore { private final Level owningLevel; public BlockMetadataStore(Level owningLevel) { this.owningLevel = owningLevel; } @Override protected String disambiguate(Metadatable block, String metadataKey) { if (!(block instanceof Block)) { throw new IllegalArgumentException("Argument must be a Block instance"); } return ((Block) block).x + ":" + ((Block) block).y + ":" + ((Block) block).z + ":" + metadataKey; } @Override public List<MetadataValue> getMetadata(Object block, String metadataKey) { if (!(block instanceof Block)) { throw new IllegalArgumentException("Object must be a Block"); } if (((Block) block).getLevel() == this.owningLevel) { return super.getMetadata(block, metadataKey); } else { throw new IllegalStateException("Block does not belong to world " + this.owningLevel.getName()); } } @Override public boolean hasMetadata(Object block, String metadataKey) { if (!(block instanceof Block)) { throw new IllegalArgumentException("Object must be a Block"); } if (((Block) block).getLevel() == this.owningLevel) { return super.hasMetadata(block, metadataKey); } else { throw new IllegalStateException("Block does not belong to world " + this.owningLevel.getName()); } } @Override public void removeMetadata(Object block, String metadataKey, Plugin owningPlugin) { if (!(block instanceof Block)) { throw new IllegalArgumentException("Object must be a Block"); } if (((Block) block).getLevel() == this.owningLevel) { super.removeMetadata(block, metadataKey, owningPlugin); } else { throw new IllegalStateException("Block does not belong to world " + this.owningLevel.getName()); } } @Override public void setMetadata(Object block, String metadataKey, MetadataValue newMetadataValue) { if (!(block instanceof Block)) { throw new IllegalArgumentException("Object must be a Block"); } if (((Block) block).getLevel() == this.owningLevel) { super.setMetadata(block, metadataKey, newMetadataValue); } else { throw new IllegalStateException("Block does not belong to world " + this.owningLevel.getName()); } } }
2,685
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
PlayerMetadataStore.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/metadata/PlayerMetadataStore.java
package cn.nukkit.metadata; import cn.nukkit.IPlayer; /** * author: MagicDroidX * Nukkit Project */ public class PlayerMetadataStore extends MetadataStore { @Override protected String disambiguate(Metadatable player, String metadataKey) { if (!(player instanceof IPlayer)) { throw new IllegalArgumentException("Argument must be an IPlayer instance"); } return (((IPlayer) player).getName() + ":" + metadataKey).toLowerCase(); } }
484
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
EntityMetadataStore.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/metadata/EntityMetadataStore.java
package cn.nukkit.metadata; import cn.nukkit.entity.Entity; /** * author: MagicDroidX * Nukkit Project */ public class EntityMetadataStore extends MetadataStore { @Override protected String disambiguate(Metadatable entity, String metadataKey) { if (!(entity instanceof Entity)) { throw new IllegalArgumentException("Argument must be an Entity instance"); } return ((Entity) entity).getId() + ":" + metadataKey; } }
469
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
MetadataValue.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/metadata/MetadataValue.java
package cn.nukkit.metadata; import cn.nukkit.plugin.Plugin; import java.lang.ref.WeakReference; /** * author: MagicDroidX * Nukkit Project */ public abstract class MetadataValue { protected final WeakReference<Plugin> owningPlugin; protected MetadataValue(Plugin owningPlugin) { this.owningPlugin = new WeakReference<>(owningPlugin); } public Plugin getOwningPlugin() { return this.owningPlugin.get(); } public abstract Object value(); public abstract void invalidate(); }
529
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
API.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/api/API.java
package cn.nukkit.api; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import static cn.nukkit.api.API.Definition.UNIVERSAL; import static cn.nukkit.api.API.Usage.BLEEDING; /** * Describes an API element. * * @author Lin Mulan, Nukkit Project * @see Usage * @see Definition */ @Retention(RetentionPolicy.SOURCE) @Target({ElementType.CONSTRUCTOR, ElementType.METHOD, ElementType.ANNOTATION_TYPE, ElementType.TYPE}) @API(usage = BLEEDING, definition = UNIVERSAL) @SuppressWarnings("unused") public @interface API { /** * Indicates the level of stability of an API element. * The stability also describes when to use this API element. * * @return The stability * @see Usage */ Usage usage(); /** * Indicates definition or the platforms this API element supports. * * @return The definition * @see Definition */ Definition definition(); /** * Enum constant for API usage. Indicates when to use this API element. * * @see #DEPRECATED * @see #INCUBATING * @see #BLEEDING * @see #EXPERIMENTAL * @see #MAINTAINED * @see #STABLE */ enum Usage { /** * Should no longer be used, might disappear in the next minor release. */ DEPRECATED, /** * Intended for features in drafts. Should only be used for tests. * <p> * <p>Might contains notable new features, but will be moved to a new package before remarking to {@link #BLEEDING}. * Could be unsafe, might be removed without prior notice. Warnings will be send if used. */ INCUBATING, /** * Intended for features in early development. Should only be used for tests. * <p> * <p>Might be unwrapped, unsafe or have unchecked parameters. * Further contribution was demanded to enhance, strengthen or simplify before remarking to {@link #EXPERIMENTAL}. * Might be removed or modified without prior notice. */ BLEEDING, /** * Intended for new, experimental features where we are looking for feedback. * At least stable for development. * <p> * <p>Use with caution, might be remarked to {@link #MAINTAINED} or {@link #STABLE} in the future, * but also might be removed without prior notice. */ EXPERIMENTAL, /** * Intended for features that was tested, documented and at least stable for production use. * <p> * <p>These features will not be modified in a backwards-incompatible way for at least next minor release * of the current major version. Will be remarked to {@link #DEPRECATED} first if scheduled for removal. */ MAINTAINED, /** * Intended for features that was tested, documented and is preferred in production use. * <p> * <p>Will not be changed in a backwards-incompatible way in the current version. */ STABLE } /** * Enum constant for API definition. Indicates which client platform this API element supports. * * @see #INTERNAL * @see #PLATFORM_NATIVE * @see #UNIVERSAL */ enum Definition { /** * Intended for features should only be used by Nukkit itself. * Should not be used in production. */ INTERNAL, /** * Intended for features only available on one or several client platforms. * <p> * <p>By using {@code PLATFORM_NATIVE} features, program will lose some cross-platform features provided. * Might not available in some client platforms. Read the documents carefully before using this API element. */ PLATFORM_NATIVE, /** * Intended for features implemented in all client platforms. * <p> * <p>Preferred to use for production use, but sometimes be lack of platform-native features. */ UNIVERSAL } }
4,159
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
Potion.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/potion/Potion.java
package cn.nukkit.potion; import cn.nukkit.Player; import cn.nukkit.entity.Entity; import cn.nukkit.entity.EntityLiving; import cn.nukkit.event.entity.EntityDamageEvent; import cn.nukkit.event.entity.EntityDamageEvent.DamageCause; import cn.nukkit.event.entity.EntityRegainHealthEvent; import cn.nukkit.event.potion.PotionApplyEvent; import cn.nukkit.utils.ServerException; /** * author: MagicDroidX * Nukkit Project */ public class Potion implements Cloneable { public static final int NO_EFFECTS = 0; public static final int WATER = 0; public static final int MUNDANE = 1; public static final int MUNDANE_II = 2; public static final int THICK = 3; public static final int AWKWARD = 4; public static final int NIGHT_VISION = 5; public static final int NIGHT_VISION_LONG = 6; public static final int INVISIBLE = 7; public static final int INVISIBLE_LONG = 8; public static final int LEAPING = 9; public static final int LEAPING_LONG = 10; public static final int LEAPING_II = 11; public static final int FIRE_RESISTANCE = 12; public static final int FIRE_RESISTANCE_LONG = 13; public static final int SPEED = 14; public static final int SPEED_LONG = 15; public static final int SPEED_II = 16; public static final int SLOWNESS = 17; public static final int SLOWNESS_LONG = 18; public static final int WATER_BREATHING = 19; public static final int WATER_BREATHING_LONG = 20; public static final int INSTANT_HEALTH = 21; public static final int INSTANT_HEALTH_II = 22; public static final int HARMING = 23; public static final int HARMING_II = 24; public static final int POISON = 25; public static final int POISON_LONG = 26; public static final int POISON_II = 27; public static final int REGENERATION = 28; public static final int REGENERATION_LONG = 29; public static final int REGENERATION_II = 30; public static final int STRENGTH = 31; public static final int STRENGTH_LONG = 32; public static final int STRENGTH_II = 33; public static final int WEAKNESS = 34; public static final int WEAKNESS_LONG = 35; protected static Potion[] potions; public static void init() { potions = new Potion[256]; potions[Potion.WATER] = new Potion(Potion.WATER); potions[Potion.MUNDANE] = new Potion(Potion.MUNDANE); potions[Potion.MUNDANE_II] = new Potion(Potion.MUNDANE_II, 2); potions[Potion.THICK] = new Potion(Potion.THICK); potions[Potion.AWKWARD] = new Potion(Potion.AWKWARD); potions[Potion.NIGHT_VISION] = new Potion(Potion.NIGHT_VISION); potions[Potion.NIGHT_VISION_LONG] = new Potion(Potion.NIGHT_VISION_LONG); potions[Potion.INVISIBLE] = new Potion(Potion.INVISIBLE); potions[Potion.INVISIBLE_LONG] = new Potion(Potion.INVISIBLE_LONG); potions[Potion.LEAPING] = new Potion(Potion.LEAPING); potions[Potion.LEAPING_LONG] = new Potion(Potion.LEAPING_LONG); potions[Potion.LEAPING_II] = new Potion(Potion.LEAPING_II, 2); potions[Potion.FIRE_RESISTANCE] = new Potion(Potion.FIRE_RESISTANCE); potions[Potion.FIRE_RESISTANCE_LONG] = new Potion(Potion.FIRE_RESISTANCE_LONG); potions[Potion.SPEED] = new Potion(Potion.SPEED); potions[Potion.SPEED_LONG] = new Potion(Potion.SPEED_LONG); potions[Potion.SPEED_II] = new Potion(Potion.SPEED_II, 2); potions[Potion.SLOWNESS] = new Potion(Potion.SLOWNESS); potions[Potion.SLOWNESS_LONG] = new Potion(Potion.SLOWNESS_LONG); potions[Potion.WATER_BREATHING] = new Potion(Potion.WATER_BREATHING); potions[Potion.WATER_BREATHING_LONG] = new Potion(Potion.WATER_BREATHING_LONG); potions[Potion.INSTANT_HEALTH] = new Potion(Potion.INSTANT_HEALTH); potions[Potion.INSTANT_HEALTH_II] = new Potion(Potion.INSTANT_HEALTH_II, 2); potions[Potion.HARMING] = new Potion(Potion.HARMING); potions[Potion.HARMING_II] = new Potion(Potion.HARMING_II, 2); potions[Potion.POISON] = new Potion(Potion.POISON); potions[Potion.POISON_LONG] = new Potion(Potion.POISON_LONG); potions[Potion.POISON_II] = new Potion(Potion.POISON_II, 2); potions[Potion.REGENERATION] = new Potion(Potion.REGENERATION); potions[Potion.REGENERATION_LONG] = new Potion(Potion.REGENERATION_LONG); potions[Potion.REGENERATION_II] = new Potion(Potion.REGENERATION_II, 2); potions[Potion.STRENGTH] = new Potion(Potion.STRENGTH); potions[Potion.STRENGTH_LONG] = new Potion(Potion.STRENGTH_LONG); potions[Potion.STRENGTH_II] = new Potion(Potion.STRENGTH_II, 2); potions[Potion.WEAKNESS] = new Potion(Potion.WEAKNESS); potions[Potion.WEAKNESS_LONG] = new Potion(Potion.WEAKNESS_LONG); } public static Potion getPotion(int id) { if (id >= 0 && id < potions.length && potions[id] != null) { return potions[id].clone(); } else { throw new ServerException("Effect id: " + id + " not found"); } } public static Potion getPotionByName(String name) { try { byte id = Potion.class.getField(name.toUpperCase()).getByte(null); return getPotion(id); } catch (Exception e) { throw new RuntimeException(e); } } protected final int id; protected final int level; protected boolean splash = false; public Potion(int id) { this(id, 1); } public Potion(int id, int level) { this(id, level, false); } public Potion(int id, int level, boolean splash) { this.id = id; this.level = level; this.splash = splash; } public Effect getEffect() { return getEffect(this.getId(), this.isSplash()); } public int getId() { return id; } public int getLevel() { return level; } public boolean isSplash() { return splash; } public Potion setSplash(boolean splash) { this.splash = splash; return this; } public void applyPotion(Entity entity) { applyPotion(entity, 0.5); } public void applyPotion(Entity entity, double health) { if (!(entity instanceof EntityLiving)) { return; } Effect applyEffect = getEffect(this.getId(), this.isSplash()); if (applyEffect == null) { return; } if (entity instanceof Player) { if (!((Player) entity).isSurvival() && applyEffect.isBad()) { return; } } PotionApplyEvent event = new PotionApplyEvent(this, applyEffect, entity); entity.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { return; } applyEffect = event.getApplyEffect(); switch (this.getId()) { case INSTANT_HEALTH: case INSTANT_HEALTH_II: entity.heal(new EntityRegainHealthEvent(entity, (float) (health * (double) (4 << (applyEffect.getAmplifier() + 1))), EntityRegainHealthEvent.CAUSE_EATING)); break; case HARMING: case HARMING_II: entity.attack(new EntityDamageEvent(entity, DamageCause.MAGIC, (float) (health * (double) (6 << (applyEffect.getAmplifier() + 1))))); break; default: int duration = (int) ((isSplash() ? health : 1) * (double) applyEffect.getDuration() + 0.5); applyEffect.setDuration(duration); entity.addEffect(applyEffect); } } @Override public Potion clone() { try { return (Potion) super.clone(); } catch (CloneNotSupportedException e) { return null; } } public static Effect getEffect(int potionType, boolean isSplash) { Effect effect; switch (potionType) { case NO_EFFECTS: case MUNDANE: case MUNDANE_II: case THICK: case AWKWARD: return null; case NIGHT_VISION: case NIGHT_VISION_LONG: effect = Effect.getEffect(Effect.NIGHT_VISION); break; case INVISIBLE: case INVISIBLE_LONG: effect = Effect.getEffect(Effect.INVISIBILITY); break; case LEAPING: case LEAPING_LONG: case LEAPING_II: effect = Effect.getEffect(Effect.JUMP); break; case FIRE_RESISTANCE: case FIRE_RESISTANCE_LONG: effect = Effect.getEffect(Effect.FIRE_RESISTANCE); break; case SPEED: case SPEED_LONG: case SPEED_II: effect = Effect.getEffect(Effect.SPEED); break; case SLOWNESS: case SLOWNESS_LONG: effect = Effect.getEffect(Effect.SLOWNESS); break; case WATER_BREATHING: case WATER_BREATHING_LONG: effect = Effect.getEffect(Effect.WATER_BREATHING); break; case INSTANT_HEALTH: case INSTANT_HEALTH_II: return Effect.getEffect(Effect.HEALING); case HARMING: case HARMING_II: return Effect.getEffect(Effect.HARMING); case POISON: case POISON_LONG: case POISON_II: effect = Effect.getEffect(Effect.POISON); break; case REGENERATION: case REGENERATION_LONG: case REGENERATION_II: effect = Effect.getEffect(Effect.REGENERATION); break; case STRENGTH: case STRENGTH_LONG: case STRENGTH_II: effect = Effect.getEffect(Effect.STRENGTH); break; case WEAKNESS: case WEAKNESS_LONG: effect = Effect.getEffect(Effect.WEAKNESS); break; default: return null; } if (getLevel(potionType) > 1) { effect.setAmplifier(1); } if (!isInstant(potionType)) { effect.setDuration(20 * getApplySeconds(potionType, isSplash)); } return effect; } public static int getLevel(int potionType) { switch (potionType) { case MUNDANE_II: case LEAPING_II: case SPEED_II: case INSTANT_HEALTH_II: case HARMING_II: case POISON_II: case REGENERATION_II: case STRENGTH_II: return 2; default: return 1; } } public static boolean isInstant(int potionType) { switch (potionType) { case INSTANT_HEALTH: case INSTANT_HEALTH_II: case HARMING: case HARMING_II: return true; default: return false; } } public static int getApplySeconds(int potionType, boolean isSplash) { if (isSplash) { switch (potionType) { case NO_EFFECTS: return 0; case MUNDANE: return 0; case MUNDANE_II: return 0; case THICK: return 0; case AWKWARD: return 0; case NIGHT_VISION: return 135; case NIGHT_VISION_LONG: return 360; case INVISIBLE: return 135; case INVISIBLE_LONG: return 360; case LEAPING: return 135; case LEAPING_LONG: return 360; case LEAPING_II: return 67; case FIRE_RESISTANCE: return 135; case FIRE_RESISTANCE_LONG: return 360; case SPEED: return 135; case SPEED_LONG: return 360; case SPEED_II: return 67; case SLOWNESS: return 67; case SLOWNESS_LONG: return 180; case WATER_BREATHING: return 135; case WATER_BREATHING_LONG: return 360; case INSTANT_HEALTH: return 0; case INSTANT_HEALTH_II: return 0; case HARMING: return 0; case HARMING_II: return 0; case POISON: return 33; case POISON_LONG: return 90; case POISON_II: return 16; case REGENERATION: return 33; case REGENERATION_LONG: return 90; case REGENERATION_II: return 16; case STRENGTH: return 135; case STRENGTH_LONG: return 360; case STRENGTH_II: return 67; case WEAKNESS: return 67; case WEAKNESS_LONG: return 180; default: return 0; } } else { switch (potionType) { case NO_EFFECTS: return 0; case MUNDANE: return 0; case MUNDANE_II: return 0; case THICK: return 0; case AWKWARD: return 0; case NIGHT_VISION: return 180; case NIGHT_VISION_LONG: return 480; case INVISIBLE: return 180; case INVISIBLE_LONG: return 480; case LEAPING: return 180; case LEAPING_LONG: return 480; case LEAPING_II: return 90; case FIRE_RESISTANCE: return 180; case FIRE_RESISTANCE_LONG: return 480; case SPEED: return 180; case SPEED_LONG: return 480; case SPEED_II: return 480; case SLOWNESS: return 90; case SLOWNESS_LONG: return 240; case WATER_BREATHING: return 180; case WATER_BREATHING_LONG: return 480; case INSTANT_HEALTH: return 0; case INSTANT_HEALTH_II: return 0; case HARMING: return 0; case HARMING_II: return 0; case POISON: return 45; case POISON_LONG: return 120; case POISON_II: return 22; case REGENERATION: return 45; case REGENERATION_LONG: return 120; case REGENERATION_II: return 22; case STRENGTH: return 180; case STRENGTH_LONG: return 480; case STRENGTH_II: return 90; case WEAKNESS: return 90; case WEAKNESS_LONG: return 240; default: return 0; } } } }
16,220
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
Effect.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/potion/Effect.java
package cn.nukkit.potion; import cn.nukkit.Player; import cn.nukkit.entity.Entity; import cn.nukkit.event.entity.EntityDamageEvent; import cn.nukkit.event.entity.EntityDamageEvent.DamageCause; import cn.nukkit.event.entity.EntityRegainHealthEvent; import cn.nukkit.network.protocol.MobEffectPacket; import cn.nukkit.utils.ServerException; /** * author: MagicDroidX * Nukkit Project */ public class Effect implements Cloneable { public static final int SPEED = 1; public static final int SLOWNESS = 2; public static final int HASTE = 3; public static final int SWIFTNESS = 3; public static final int FATIGUE = 4; public static final int MINING_FATIGUE = 4; public static final int STRENGTH = 5; public static final int HEALING = 6; public static final int HARMING = 7; public static final int JUMP = 8; public static final int NAUSEA = 9; public static final int CONFUSION = 9; public static final int REGENERATION = 10; public static final int DAMAGE_RESISTANCE = 11; public static final int FIRE_RESISTANCE = 12; public static final int WATER_BREATHING = 13; public static final int INVISIBILITY = 14; public static final int BLINDNESS = 15; public static final int NIGHT_VISION = 16; public static final int HUNGER = 17; public static final int WEAKNESS = 18; public static final int POISON = 19; public static final int WITHER = 20; public static final int HEALTH_BOOST = 21; public static final int ABSORPTION = 22; public static final int SATURATION = 23; protected static Effect[] effects; public static void init() { effects = new Effect[256]; effects[Effect.SPEED] = new Effect(Effect.SPEED, "%potion.moveSpeed", 124, 175, 198); effects[Effect.SLOWNESS] = new Effect(Effect.SLOWNESS, "%potion.moveSlowdown", 90, 108, 129, true); effects[Effect.SWIFTNESS] = new Effect(Effect.SWIFTNESS, "%potion.digSpeed", 217, 192, 67); effects[Effect.FATIGUE] = new Effect(Effect.FATIGUE, "%potion.digSlowDown", 74, 66, 23, true); effects[Effect.STRENGTH] = new Effect(Effect.STRENGTH, "%potion.damageBoost", 147, 36, 35); effects[Effect.HEALING] = new InstantEffect(Effect.HEALING, "%potion.heal", 248, 36, 35); effects[Effect.HARMING] = new InstantEffect(Effect.HARMING, "%potion.harm", 67, 10, 9, true); effects[Effect.JUMP] = new Effect(Effect.JUMP, "%potion.jump", 34, 255, 76); effects[Effect.NAUSEA] = new Effect(Effect.NAUSEA, "%potion.confusion", 85, 29, 74, true); effects[Effect.REGENERATION] = new Effect(Effect.REGENERATION, "%potion.regeneration", 205, 92, 171); effects[Effect.DAMAGE_RESISTANCE] = new Effect(Effect.DAMAGE_RESISTANCE, "%potion.resistance", 153, 69, 58); effects[Effect.FIRE_RESISTANCE] = new Effect(Effect.FIRE_RESISTANCE, "%potion.fireResistance", 228, 154, 58); effects[Effect.WATER_BREATHING] = new Effect(Effect.WATER_BREATHING, "%potion.waterBreathing", 46, 82, 153); effects[Effect.INVISIBILITY] = new Effect(Effect.INVISIBILITY, "%potion.invisibility", 127, 131, 146); effects[Effect.BLINDNESS] = new Effect(Effect.BLINDNESS, "%potion.blindness", 191, 192, 192); effects[Effect.NIGHT_VISION] = new Effect(Effect.NIGHT_VISION, "%potion.nightVision", 0, 0, 139); effects[Effect.HUNGER] = new Effect(Effect.HUNGER, "%potion.hunger", 46, 139, 87); effects[Effect.WEAKNESS] = new Effect(Effect.WEAKNESS, "%potion.weakness", 72, 77, 72, true); effects[Effect.POISON] = new Effect(Effect.POISON, "%potion.poison", 78, 147, 49, true); effects[Effect.WITHER] = new Effect(Effect.WITHER, "%potion.wither", 53, 42, 39, true); effects[Effect.HEALTH_BOOST] = new Effect(Effect.HEALTH_BOOST, "%potion.healthBoost", 248, 125, 35); effects[Effect.ABSORPTION] = new Effect(Effect.ABSORPTION, "%potion.absorption", 36, 107, 251); effects[Effect.SATURATION] = new Effect(Effect.SATURATION, "%potion.saturation", 255, 0, 255); } public static Effect getEffect(int id) { if (id >= 0 && id < effects.length && effects[id] != null) { return effects[id].clone(); } else { throw new ServerException("Effect id: " + id + " not found"); } } public static Effect getEffectByName(String name) { name = name.trim().replace(' ', '_').replace("minecraft:", ""); try { int id = Effect.class.getField(name.toUpperCase()).getInt(null); return getEffect(id); } catch (Exception e) { throw new RuntimeException(e); } } protected final int id; protected final String name; protected int duration; protected int amplifier = 0; protected int color; protected boolean show = true; protected boolean ambient = false; protected final boolean bad; public Effect(int id, String name, int r, int g, int b) { this(id, name, r, g, b, false); } public Effect(int id, String name, int r, int g, int b, boolean isBad) { this.id = id; this.name = name; this.bad = isBad; this.setColor(r, g, b); } public String getName() { return name; } public int getId() { return id; } public Effect setDuration(int ticks) { this.duration = ticks; return this; } public int getDuration() { return duration; } public boolean isVisible() { return show; } public Effect setVisible(boolean visible) { this.show = visible; return this; } public int getAmplifier() { return amplifier; } public Effect setAmplifier(int amplifier) { this.amplifier = amplifier; return this; } public boolean isAmbient() { return ambient; } public Effect setAmbient(boolean ambient) { this.ambient = ambient; return this; } public boolean isBad() { return bad; } public boolean canTick() { int interval; switch (this.id) { case Effect.POISON: //POISON if ((interval = (25 >> this.amplifier)) > 0) { return (this.duration % interval) == 0; } return true; case Effect.WITHER: //WITHER if ((interval = (50 >> this.amplifier)) > 0) { return (this.duration % interval) == 0; } return true; case Effect.REGENERATION: //REGENERATION if ((interval = (40 >> this.amplifier)) > 0) { return (this.duration % interval) == 0; } return true; case Effect.SPEED: case Effect.SLOWNESS: return (this.duration % 20) == 0; } return false; } public void applyEffect(Entity entity) { switch (this.id) { case Effect.POISON: //POISON if (entity.getHealth() > 1) { entity.attack(new EntityDamageEvent(entity, DamageCause.MAGIC, 1)); } break; case Effect.WITHER: //WITHER entity.attack(new EntityDamageEvent(entity, DamageCause.MAGIC, 1)); break; case Effect.REGENERATION: //REGENERATION if (entity.getHealth() < entity.getMaxHealth()) { entity.heal(new EntityRegainHealthEvent(entity, 1, EntityRegainHealthEvent.CAUSE_MAGIC)); } break; case Effect.SPEED: if (entity instanceof Player) { ((Player) entity).setMovementSpeed((float) (((this.amplifier + 1) * 0.2 + 1) * 0.1)); } break; case Effect.SLOWNESS: if (entity instanceof Player) { ((Player) entity).setMovementSpeed((float) (((this.amplifier + 1) * -0.15 + 1) * 0.1)); } break; } } public int[] getColor() { return new int[]{this.color >> 16, (this.color >> 8) & 0xff, this.color & 0xff}; } public void setColor(int r, int g, int b) { this.color = ((r & 0xff) << 16) + ((g & 0xff) << 8) + (b & 0xff); } public void add(Entity entity) { this.add(entity, false); } public void add(Entity entity, boolean modify) { if (entity instanceof Player) { MobEffectPacket pk = new MobEffectPacket(); pk.eid = entity.getId(); pk.effectId = this.getId(); pk.amplifier = this.getAmplifier(); pk.particles = this.isVisible(); pk.duration = this.getDuration(); if (modify) { pk.eventId = MobEffectPacket.EVENT_MODIFY; } else { pk.eventId = MobEffectPacket.EVENT_ADD; } ((Player) entity).dataPacket(pk); if (this.id == Effect.SPEED) { ((Player) entity).setMovementSpeed((float) (((this.amplifier + 1) * 0.2 + 1) * 0.1)); } if (this.id == Effect.SLOWNESS) { ((Player) entity).setMovementSpeed((float) (((this.amplifier + 1) * -0.15 + 1) * 0.1)); } } if (this.id == Effect.INVISIBILITY) { entity.setDataFlag(Entity.DATA_FLAGS, Entity.DATA_FLAG_INVISIBLE, true); entity.setNameTagVisible(false); } if (this.id == Effect.ABSORPTION) { int add = (this.amplifier + 1) * 4; if (add > entity.getAbsorption()) entity.setAbsorption(add); } } public void remove(Entity entity) { if (entity instanceof Player) { MobEffectPacket pk = new MobEffectPacket(); pk.eid = entity.getId(); pk.effectId = this.getId(); pk.eventId = MobEffectPacket.EVENT_REMOVE; ((Player) entity).dataPacket(pk); if (this.id == Effect.SPEED || this.id == Effect.SLOWNESS) { ((Player) entity).setMovementSpeed(0.1f); } } if (this.id == Effect.INVISIBILITY) { entity.setDataFlag(Entity.DATA_FLAGS, Entity.DATA_FLAG_INVISIBLE, false); entity.setNameTagVisible(true); } if (this.id == Effect.ABSORPTION) { entity.setAbsorption(0); } } @Override public Effect clone() { try { return (Effect) super.clone(); } catch (CloneNotSupportedException e) { return null; } } }
10,707
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
InstantEffect.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/potion/InstantEffect.java
package cn.nukkit.potion; /** * author: MagicDroidX * Nukkit Project */ public class InstantEffect extends Effect { public InstantEffect(int id, String name, int r, int g, int b) { super(id, name, r, g, b); } public InstantEffect(int id, String name, int r, int g, int b, boolean isBad) { super(id, name, r, g, b, isBad); } }
363
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
RakNet.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/raknet/RakNet.java
package cn.nukkit.raknet; /** * author: MagicDroidX * Nukkit Project * UDP network library that follows the RakNet protocol for Nukkit Project * This is not affiliated with Jenkins Software LLC nor RakNet. */ public abstract class RakNet { public static final String VERSION = "1.1.0"; public static final byte PROTOCOL = 6; public static final byte[] MAGIC = new byte[]{ (byte) 0x00, (byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0xfe, (byte) 0xfe, (byte) 0xfe, (byte) 0xfe, (byte) 0xfd, (byte) 0xfd, (byte) 0xfd, (byte) 0xfd, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 }; public static final byte PRIORITY_NORMAL = 0; public static final byte PRIORITY_IMMEDIATE = 1; public static final byte FLAG_NEED_ACK = 0b00001000; /* * ENCAPSULATED payload: * byte (identifier length) * byte[] (identifier) * byte (flags, last 3 bits, priority) * payload (binary internal EncapsulatedPacket) */ public static final byte PACKET_ENCAPSULATED = 0x01; /* * OPEN_SESSION payload: * byte (identifier length) * byte[] (identifier) * byte (address length) * byte[] (address) * short (port) * long (clientID) */ public static final byte PACKET_OPEN_SESSION = 0x02; /* * CLOSE_SESSION payload: * byte (identifier length) * byte[] (identifier) * string (reason) */ public static final byte PACKET_CLOSE_SESSION = 0x03; /* * INVALID_SESSION payload: * byte (identifier length) * byte[] (identifier) */ public static final byte PACKET_INVALID_SESSION = 0x04; /* SEND_QUEUE payload: * byte (identifier length) * byte[] (identifier) */ public static final byte PACKET_SEND_QUEUE = 0x05; /* * ACK_NOTIFICATION payload: * byte (identifier length) * byte[] (identifier) * int (identifierACK) */ public static final byte PACKET_ACK_NOTIFICATION = 0x06; /* * SET_OPTION payload: * byte (option name length) * byte[] (option name) * byte[] (option value) */ public static final byte PACKET_SET_OPTION = 0x07; /* * RAW payload: * byte (address length) * byte[] (address from/to) * short (port) * byte[] (payload) */ public static final byte PACKET_RAW = 0x08; /* * BLOCK_ADDRESS payload: * byte (address length) * byte[] (address) * int (timeout) */ public static final byte PACKET_BLOCK_ADDRESS = 0x09; /* * UNBLOCK_ADDRESS payload: * byte (adress length) * byte[] (address) */ public static final byte PACKET_UNBLOCK_ADDRESS = 0x10; /* * No payload * * Sends the disconnect message, removes sessions correctly, closes sockets. */ public static final byte PACKET_SHUTDOWN = 0x7e; /* * No payload * * Leaves everything as-is and halts, other Threads can be in a post-crash condition. */ public static final byte PACKET_EMERGENCY_SHUTDOWN = 0x7f; }
3,114
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
RakNetServer.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/raknet/server/RakNetServer.java
package cn.nukkit.raknet.server; import cn.nukkit.Server; import cn.nukkit.utils.ThreadedLogger; import java.util.concurrent.ConcurrentLinkedQueue; /** * author: MagicDroidX * Nukkit Project */ public class RakNetServer extends Thread { protected final int port; protected String interfaz; protected ThreadedLogger logger; protected ConcurrentLinkedQueue<byte[]> externalQueue; protected ConcurrentLinkedQueue<byte[]> internalQueue; protected boolean shutdown; public RakNetServer(ThreadedLogger logger, int port) { this(logger, port, "0.0.0.0"); } public RakNetServer(ThreadedLogger logger, int port, String interfaz) { this.port = port; if (port < 1 || port > 65536) { throw new IllegalArgumentException("Invalid port range"); } this.interfaz = interfaz; this.logger = logger; this.externalQueue = new ConcurrentLinkedQueue<>(); this.internalQueue = new ConcurrentLinkedQueue<>(); this.start(); } public boolean isShutdown() { return shutdown; } public void shutdown() { this.shutdown = true; } public int getPort() { return port; } public String getInterface() { return interfaz; } public ThreadedLogger getLogger() { return logger; } public ConcurrentLinkedQueue<byte[]> getExternalQueue() { return externalQueue; } public ConcurrentLinkedQueue<byte[]> getInternalQueue() { return internalQueue; } public void pushMainToThreadPacket(byte[] data) { this.internalQueue.add(data); } public byte[] readMainToThreadPacket() { return this.internalQueue.poll(); } public void pushThreadToMainPacket(byte[] data) { this.externalQueue.add(data); } public byte[] readThreadToMainPacket() { return this.externalQueue.poll(); } private class ShutdownHandler extends Thread { public void run() { if (!shutdown) { logger.emergency("RakNet crashed!"); } } } @Override public void run() { this.setName("RakNet Thread #" + Thread.currentThread().getId()); Runtime.getRuntime().addShutdownHook(new ShutdownHandler()); UDPServerSocket socket = new UDPServerSocket(this.getLogger(), port, this.interfaz); try { new SessionManager(this, socket); } catch (Exception e) { Server.getInstance().getLogger().logException(e); } } }
2,585
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
ServerInstance.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/raknet/server/ServerInstance.java
package cn.nukkit.raknet.server; import cn.nukkit.raknet.protocol.EncapsulatedPacket; /** * author: MagicDroidX * Nukkit Project */ public interface ServerInstance { void openSession(String identifier, String address, int port, long clientID); void closeSession(String identifier, String reason); void handleEncapsulated(String identifier, EncapsulatedPacket packet, int flags); void handleRaw(String address, int port, byte[] payload); void notifyACK(String identifier, int identifierACK); void handleOption(String option, String value); }
576
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
UDPServerSocket.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/raknet/server/UDPServerSocket.java
package cn.nukkit.raknet.server; import cn.nukkit.utils.ThreadedLogger; import io.netty.bootstrap.Bootstrap; import io.netty.buffer.PooledByteBufAllocator; import io.netty.buffer.Unpooled; import io.netty.channel.Channel; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.ChannelOption; import io.netty.channel.epoll.Epoll; import io.netty.channel.epoll.EpollDatagramChannel; import io.netty.channel.epoll.EpollEventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.DatagramPacket; import io.netty.channel.socket.nio.NioDatagramChannel; import java.io.IOException; import java.net.InetSocketAddress; import java.util.concurrent.ConcurrentLinkedQueue; /** * author: MagicDroidX * Nukkit Project */ public class UDPServerSocket extends ChannelInboundHandlerAdapter { protected final ThreadedLogger logger; protected Bootstrap bootstrap; protected Channel channel; protected ConcurrentLinkedQueue<DatagramPacket> packets = new ConcurrentLinkedQueue<>(); public UDPServerSocket(ThreadedLogger logger) { this(logger, 19132, "0.0.0.0"); } public UDPServerSocket(ThreadedLogger logger, int port) { this(logger, port, "0.0.0.0"); } public UDPServerSocket(ThreadedLogger logger, int port, String interfaz) { this.logger = logger; try { if (Epoll.isAvailable()) { bootstrap = new Bootstrap() .channel(EpollDatagramChannel.class) .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .handler(this) .group(new EpollEventLoopGroup()); this.logger.info("Epoll is available. EpollEventLoop will be used."); } else { bootstrap = new Bootstrap() .group(new NioEventLoopGroup()) .channel(NioDatagramChannel.class) .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .handler(this); this.logger.info("Epoll is unavailable. Reverting to NioEventLoop."); } channel = bootstrap.bind(interfaz, port).sync().channel(); } catch (Exception e) { this.logger.critical("**** FAILED TO BIND TO " + interfaz + ":" + port + "!"); this.logger.critical("Perhaps a server is already running on that port?"); System.exit(1); } } public void close() { bootstrap.config().group().shutdownGracefully(); if (channel != null) { channel.close().syncUninterruptibly(); } } public void clearPacketQueue() { this.packets.clear(); } public DatagramPacket readPacket() throws IOException { return this.packets.poll(); } public int writePacket(byte[] data, String dest, int port) throws IOException { return this.writePacket(data, new InetSocketAddress(dest, port)); } public int writePacket(byte[] data, InetSocketAddress dest) throws IOException { channel.writeAndFlush(new DatagramPacket(Unpooled.wrappedBuffer(data), dest)); return data.length; } @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { this.packets.add((DatagramPacket) msg); } @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { this.logger.warning(cause.getMessage(), cause); } }
3,614
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
SessionManager.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/raknet/server/SessionManager.java
package cn.nukkit.raknet.server; import cn.nukkit.raknet.RakNet; import cn.nukkit.raknet.protocol.EncapsulatedPacket; import cn.nukkit.raknet.protocol.Packet; import cn.nukkit.raknet.protocol.packet.*; import cn.nukkit.utils.Binary; import cn.nukkit.utils.ThreadedLogger; import io.netty.buffer.ByteBuf; import io.netty.channel.socket.DatagramPacket; import java.io.IOException; import java.net.InetSocketAddress; import java.nio.charset.StandardCharsets; import java.util.*; /** * author: MagicDroidX * Nukkit Project */ public class SessionManager { protected final Packet.PacketFactory[] packetPool = new Packet.PacketFactory[256]; protected final RakNetServer server; protected final UDPServerSocket socket; protected int receiveBytes = 0; protected int sendBytes = 0; protected final Map<String, Session> sessions = new HashMap<>(); protected String name = ""; protected int packetLimit = 1000; protected boolean shutdown = false; protected long ticks = 0; protected long lastMeasure; protected final Map<String, Long> block = new HashMap<>(); protected final Map<String, Integer> ipSec = new HashMap<>(); public boolean portChecking = true; public final long serverId; protected String currentSource = ""; public SessionManager(RakNetServer server, UDPServerSocket socket) throws Exception { this.server = server; this.socket = socket; this.registerPackets(); this.serverId = new Random().nextLong(); this.run(); } public int getPort() { return this.server.port; } public ThreadedLogger getLogger() { return this.server.getLogger(); } public void run() throws Exception { this.tickProcessor(); } private void tickProcessor() throws Exception { this.lastMeasure = System.currentTimeMillis(); while (!this.shutdown) { long start = System.currentTimeMillis(); int max = 5000; while (max > 0) { try { if (!this.receivePacket()) { break; } --max; } catch (Exception e) { if (!currentSource.isEmpty()) { this.blockAddress(currentSource); } // else ignore } } while (this.receiveStream()) ; long time = System.currentTimeMillis() - start; if (time < 50) { try { Thread.sleep(50 - time); } catch (InterruptedException e) { //ignore } } this.tick(); } } private void tick() throws Exception { long time = System.currentTimeMillis(); for (Session session : new ArrayList<>(this.sessions.values())) { session.update(time); } for (String address : this.ipSec.keySet()) { int count = this.ipSec.get(address); if (count >= this.packetLimit) { this.blockAddress(address); } } this.ipSec.clear(); if ((this.ticks & 0b1111) == 0) { double diff = Math.max(5d, (double) time - this.lastMeasure); this.streamOption("bandwidth", this.sendBytes / diff + ";" + this.receiveBytes / diff); this.lastMeasure = time; this.sendBytes = 0; this.receiveBytes = 0; if (!this.block.isEmpty()) { long now = System.currentTimeMillis(); for (String address : new ArrayList<>(this.block.keySet())) { long timeout = this.block.get(address); if (timeout <= now) { this.block.remove(address); this.getLogger().notice("Unblocked " + address); } else { break; } } } } ++this.ticks; } private boolean receivePacket() throws Exception { DatagramPacket datagramPacket = this.socket.readPacket(); if (datagramPacket != null) { // Check this early try { String source = datagramPacket.sender().getHostString(); currentSource = source; //in order to block address if (this.block.containsKey(source)) { return true; } if (this.ipSec.containsKey(source)) { this.ipSec.put(source, this.ipSec.get(source) + 1); } else { this.ipSec.put(source, 1); } ByteBuf byteBuf = datagramPacket.content(); if (byteBuf.readableBytes() == 0) { // Exit early to process another packet return true; } byte[] buffer = new byte[byteBuf.readableBytes()]; byteBuf.readBytes(buffer); int len = buffer.length; int port = datagramPacket.sender().getPort(); this.receiveBytes += len; byte pid = buffer[0]; if (pid == UNCONNECTED_PONG.ID) { return false; } Packet packet = this.getPacketFromPool(pid); if (packet != null) { packet.buffer = buffer; this.getSession(source, port).handlePacket(packet); return true; } else if (pid == UNCONNECTED_PING.ID) { packet = new UNCONNECTED_PING(); packet.buffer = buffer; packet.decode(); UNCONNECTED_PONG pk = new UNCONNECTED_PONG(); pk.serverID = this.getID(); pk.pingID = ((UNCONNECTED_PING) packet).pingID; pk.serverName = this.getName(); this.sendPacket(pk, source, port); } else if (buffer.length != 0) { this.streamRAW(source, port, buffer); return true; } else { return false; } } finally { datagramPacket.release(); } } return false; } public void sendPacket(Packet packet, String dest, int port) throws IOException { packet.encode(); this.sendBytes += this.socket.writePacket(packet.buffer, dest, port); } public void sendPacket(Packet packet, InetSocketAddress dest) throws IOException { packet.encode(); this.sendBytes += this.socket.writePacket(packet.buffer, dest); } public void streamEncapsulated(Session session, EncapsulatedPacket packet) { this.streamEncapsulated(session, packet, RakNet.PRIORITY_NORMAL); } public void streamEncapsulated(Session session, EncapsulatedPacket packet, int flags) { String id = session.getAddress() + ":" + session.getPort(); byte[] buffer = Binary.appendBytes( RakNet.PACKET_ENCAPSULATED, new byte[]{(byte) (id.length() & 0xff)}, id.getBytes(StandardCharsets.UTF_8), new byte[]{(byte) (flags & 0xff)}, packet.toBinary(true) ); this.server.pushThreadToMainPacket(buffer); } public void streamRAW(String address, int port, byte[] payload) { byte[] buffer = Binary.appendBytes( RakNet.PACKET_RAW, new byte[]{(byte) (address.length() & 0xff)}, address.getBytes(StandardCharsets.UTF_8), Binary.writeShort(port), payload ); this.server.pushThreadToMainPacket(buffer); } protected void streamClose(String identifier, String reason) { byte[] buffer = Binary.appendBytes( RakNet.PACKET_CLOSE_SESSION, new byte[]{(byte) (identifier.length() & 0xff)}, identifier.getBytes(StandardCharsets.UTF_8), new byte[]{(byte) (reason.length() & 0xff)}, reason.getBytes(StandardCharsets.UTF_8) ); this.server.pushThreadToMainPacket(buffer); } protected void streamInvalid(String identifier) { byte[] buffer = Binary.appendBytes( RakNet.PACKET_INVALID_SESSION, new byte[]{(byte) (identifier.length() & 0xff)}, identifier.getBytes(StandardCharsets.UTF_8) ); this.server.pushThreadToMainPacket(buffer); } protected void streamOpen(Session session) { String identifier = session.getAddress() + ":" + session.getPort(); byte[] buffer = Binary.appendBytes( RakNet.PACKET_OPEN_SESSION, new byte[]{(byte) (identifier.length() & 0xff)}, identifier.getBytes(StandardCharsets.UTF_8), new byte[]{(byte) (session.getAddress().length() & 0xff)}, session.getAddress().getBytes(StandardCharsets.UTF_8), Binary.writeShort(session.getPort()), Binary.writeLong(session.getID()) ); this.server.pushThreadToMainPacket(buffer); } protected void streamACK(String identifier, int identifierACK) { byte[] buffer = Binary.appendBytes( RakNet.PACKET_ACK_NOTIFICATION, new byte[]{(byte) (identifier.length() & 0xff)}, identifier.getBytes(StandardCharsets.UTF_8), Binary.writeInt(identifierACK) ); this.server.pushThreadToMainPacket(buffer); } protected void streamOption(String name, String value) { byte[] buffer = Binary.appendBytes( RakNet.PACKET_SET_OPTION, new byte[]{(byte) (name.length() & 0xff)}, name.getBytes(StandardCharsets.UTF_8), value.getBytes(StandardCharsets.UTF_8) ); this.server.pushThreadToMainPacket(buffer); } private void checkSessions() { int size = this.sessions.size(); if (size > 4096) { List<String> keyToRemove = new ArrayList<>(); for (String i : this.sessions.keySet()) { Session s = this.sessions.get(i); if (s.isTemporal()) { keyToRemove.add(i); size--; if (size <= 4096) { break; } } } for (String i : keyToRemove) { this.sessions.remove(i); } } } public boolean receiveStream() throws Exception { byte[] packet = this.server.readMainToThreadPacket(); if (packet != null && packet.length > 0) { byte id = packet[0]; int offset = 1; switch (id) { case RakNet.PACKET_ENCAPSULATED: int len = packet[offset++]; String identifier = new String(Binary.subBytes(packet, offset, len), StandardCharsets.UTF_8); offset += len; if (this.sessions.containsKey(identifier)) { byte flags = packet[offset++]; byte[] buffer = Binary.subBytes(packet, offset); this.sessions.get(identifier).addEncapsulatedToQueue(EncapsulatedPacket.fromBinary(buffer, true), flags); } else { this.streamInvalid(identifier); } break; case RakNet.PACKET_RAW: len = packet[offset++]; String address = new String(Binary.subBytes(packet, offset, len), StandardCharsets.UTF_8); offset += len; int port = Binary.readShort(Binary.subBytes(packet, offset, 2)); offset += 2; byte[] payload = Binary.subBytes(packet, offset); this.socket.writePacket(payload, address, port); break; case RakNet.PACKET_CLOSE_SESSION: len = packet[offset++]; identifier = new String(Binary.subBytes(packet, offset, len), StandardCharsets.UTF_8); if (this.sessions.containsKey(identifier)) { this.removeSession(this.sessions.get(identifier)); } else { this.streamInvalid(identifier); } break; case RakNet.PACKET_INVALID_SESSION: len = packet[offset++]; identifier = new String(Binary.subBytes(packet, offset, len), StandardCharsets.UTF_8); if (this.sessions.containsKey(identifier)) { this.removeSession(this.sessions.get(identifier)); } break; case RakNet.PACKET_SET_OPTION: len = packet[offset++]; String name = new String(Binary.subBytes(packet, offset, len), StandardCharsets.UTF_8); offset += len; String value = new String(Binary.subBytes(packet, offset), StandardCharsets.UTF_8); switch (name) { case "name": this.name = value; break; case "portChecking": this.portChecking = Boolean.valueOf(value); break; case "packetLimit": this.packetLimit = Integer.valueOf(value); break; } break; case RakNet.PACKET_BLOCK_ADDRESS: len = packet[offset++]; address = new String(Binary.subBytes(packet, offset, len), StandardCharsets.UTF_8); offset += len; int timeout = Binary.readInt(Binary.subBytes(packet, offset, 4)); this.blockAddress(address, timeout); break; case RakNet.PACKET_UNBLOCK_ADDRESS: len = packet[offset++]; address = new String(Binary.subBytes(packet, offset, len), StandardCharsets.UTF_8); this.unblockAddress(address); break; case RakNet.PACKET_SHUTDOWN: for (Session session : new ArrayList<>(this.sessions.values())) { this.removeSession(session); } this.socket.close(); this.shutdown = true; break; case RakNet.PACKET_EMERGENCY_SHUTDOWN: this.shutdown = true; default: return false; } return true; } return false; } public void blockAddress(String address) { this.blockAddress(address, 300); } public void blockAddress(String address, int timeout) { long finalTime = System.currentTimeMillis() + timeout * 1000; if (!this.block.containsKey(address) || timeout == -1) { if (timeout == -1) { finalTime = Long.MAX_VALUE; } else { this.getLogger().notice("Blocked " + address + " for " + timeout + " seconds"); } this.block.put(address, finalTime); } else if (this.block.get(address) < finalTime) { this.block.put(address, finalTime); } } public void unblockAddress(String address) { this.block.remove(address); } public Session getSession(String ip, int port) { String id = ip + ":" + port; if (!this.sessions.containsKey(id)) { this.checkSessions(); Session session = new Session(this, ip, port); this.sessions.put(id, session); return session; } return this.sessions.get(id); } public void removeSession(Session session) throws Exception { this.removeSession(session, "unknown"); } public void removeSession(Session session, String reason) throws Exception { String id = session.getAddress() + ":" + session.getPort(); if (this.sessions.containsKey(id)) { this.sessions.get(id).close(); this.sessions.remove(id); this.streamClose(id, reason); } } public void openSession(Session session) { this.streamOpen(session); } public void notifyACK(Session session, int identifierACK) { this.streamACK(session.getAddress() + ":" + session.getPort(), identifierACK); } public String getName() { return name; } public long getID() { return this.serverId; } private void registerPacket(byte id, Packet.PacketFactory factory) { this.packetPool[id & 0xFF] = factory; } public Packet getPacketFromPool(byte id) { return this.packetPool[id & 0xFF].create(); } private void registerPackets() { // fill with dummy returning null Arrays.fill(this.packetPool, (Packet.PacketFactory) () -> null); //this.registerPacket(UNCONNECTED_PING.ID, UNCONNECTED_PING.class); this.registerPacket(UNCONNECTED_PING_OPEN_CONNECTIONS.ID, new UNCONNECTED_PING_OPEN_CONNECTIONS.Factory()); this.registerPacket(OPEN_CONNECTION_REQUEST_1.ID, new OPEN_CONNECTION_REQUEST_1.Factory()); this.registerPacket(OPEN_CONNECTION_REPLY_1.ID, new OPEN_CONNECTION_REPLY_1.Factory()); this.registerPacket(OPEN_CONNECTION_REQUEST_2.ID, new OPEN_CONNECTION_REQUEST_2.Factory()); this.registerPacket(OPEN_CONNECTION_REPLY_2.ID, new OPEN_CONNECTION_REPLY_2.Factory()); this.registerPacket(UNCONNECTED_PONG.ID, new UNCONNECTED_PONG.Factory()); this.registerPacket(ADVERTISE_SYSTEM.ID, new ADVERTISE_SYSTEM.Factory()); this.registerPacket(DATA_PACKET_0.ID, new DATA_PACKET_0.Factory()); this.registerPacket(DATA_PACKET_1.ID, new DATA_PACKET_1.Factory()); this.registerPacket(DATA_PACKET_2.ID, new DATA_PACKET_2.Factory()); this.registerPacket(DATA_PACKET_3.ID, new DATA_PACKET_3.Factory()); this.registerPacket(DATA_PACKET_4.ID, new DATA_PACKET_4.Factory()); this.registerPacket(DATA_PACKET_5.ID, new DATA_PACKET_5.Factory()); this.registerPacket(DATA_PACKET_6.ID, new DATA_PACKET_6.Factory()); this.registerPacket(DATA_PACKET_7.ID, new DATA_PACKET_7.Factory()); this.registerPacket(DATA_PACKET_8.ID, new DATA_PACKET_8.Factory()); this.registerPacket(DATA_PACKET_9.ID, new DATA_PACKET_9.Factory()); this.registerPacket(DATA_PACKET_A.ID, new DATA_PACKET_A.Factory()); this.registerPacket(DATA_PACKET_B.ID, new DATA_PACKET_B.Factory()); this.registerPacket(DATA_PACKET_C.ID, new DATA_PACKET_C.Factory()); this.registerPacket(DATA_PACKET_D.ID, new DATA_PACKET_D.Factory()); this.registerPacket(DATA_PACKET_E.ID, new DATA_PACKET_E.Factory()); this.registerPacket(DATA_PACKET_F.ID, new DATA_PACKET_F.Factory()); this.registerPacket(NACK.ID, new NACK.Factory()); this.registerPacket(ACK.ID, new ACK.Factory()); } }
19,639
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z
ServerHandler.java
/FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/raknet/server/ServerHandler.java
package cn.nukkit.raknet.server; import cn.nukkit.raknet.RakNet; import cn.nukkit.raknet.protocol.EncapsulatedPacket; import cn.nukkit.utils.Binary; import java.nio.charset.StandardCharsets; /** * author: MagicDroidX * Nukkit Project */ public class ServerHandler { protected final RakNetServer server; protected final ServerInstance instance; public ServerHandler(RakNetServer server, ServerInstance instance) { this.server = server; this.instance = instance; } public void sendEncapsulated(String identifier, EncapsulatedPacket packet) { this.sendEncapsulated(identifier, packet, RakNet.PRIORITY_NORMAL); } public void sendEncapsulated(String identifier, EncapsulatedPacket packet, int flags) { byte[] buffer = Binary.appendBytes( RakNet.PACKET_ENCAPSULATED, new byte[]{(byte) (identifier.length() & 0xff)}, identifier.getBytes(StandardCharsets.UTF_8), new byte[]{(byte) (flags & 0xff)}, packet.toBinary(true) ); this.server.pushMainToThreadPacket(buffer); } public void sendRaw(String address, int port, byte[] payload) { byte[] buffer = Binary.appendBytes( RakNet.PACKET_RAW, new byte[]{(byte) (address.length() & 0xff)}, address.getBytes(StandardCharsets.UTF_8), Binary.writeShort(port), payload ); this.server.pushMainToThreadPacket(buffer); } public void closeSession(String identifier, String reason) { byte[] buffer = Binary.appendBytes( RakNet.PACKET_CLOSE_SESSION, new byte[]{(byte) (identifier.length() & 0xff)}, identifier.getBytes(StandardCharsets.UTF_8), new byte[]{(byte) (reason.length() & 0xff)}, reason.getBytes(StandardCharsets.UTF_8) ); this.server.pushMainToThreadPacket(buffer); } public void sendOption(String name, String value) { byte[] buffer = Binary.appendBytes( RakNet.PACKET_SET_OPTION, new byte[]{(byte) (name.length() & 0xff)}, name.getBytes(StandardCharsets.UTF_8), value.getBytes(StandardCharsets.UTF_8) ); this.server.pushMainToThreadPacket(buffer); } public void blockAddress(String address, int timeout) { byte[] buffer = Binary.appendBytes( RakNet.PACKET_BLOCK_ADDRESS, new byte[]{(byte) (address.length() & 0xff)}, address.getBytes(StandardCharsets.UTF_8), Binary.writeInt(timeout) ); this.server.pushMainToThreadPacket(buffer); } public void unblockAddress(String address) { byte[] buffer = Binary.appendBytes( RakNet.PACKET_UNBLOCK_ADDRESS, new byte[]{(byte) (address.length() & 0xff)}, address.getBytes(StandardCharsets.UTF_8) ); this.server.pushMainToThreadPacket(buffer); } public void shutdown() { this.server.pushMainToThreadPacket(new byte[]{RakNet.PACKET_SHUTDOWN}); this.server.shutdown(); synchronized (this) { try { this.wait(20); } catch (InterruptedException e) { //ignore } } try { this.server.join(); } catch (InterruptedException e) { //ignore } } public void emergencyShutdown() { this.server.shutdown(); this.server.pushMainToThreadPacket(new byte[]{RakNet.PACKET_EMERGENCY_SHUTDOWN}); } protected void invalidSession(String identifier) { byte[] buffer = Binary.appendBytes( RakNet.PACKET_INVALID_SESSION, new byte[]{(byte) (identifier.length() & 0xff)}, identifier.getBytes(StandardCharsets.UTF_8) ); this.server.pushMainToThreadPacket(buffer); } public boolean handlePacket() { byte[] packet = this.server.readThreadToMainPacket(); if (packet != null && packet.length > 0) { byte id = packet[0]; int offset = 1; if (id == RakNet.PACKET_ENCAPSULATED) { int len = packet[offset++]; String identifier = new String(Binary.subBytes(packet, offset, len), StandardCharsets.UTF_8); offset += len; int flags = packet[offset++]; byte[] buffer = Binary.subBytes(packet, offset); this.instance.handleEncapsulated(identifier, EncapsulatedPacket.fromBinary(buffer, true), flags); } else if (id == RakNet.PACKET_RAW) { int len = packet[offset++]; String address = new String(Binary.subBytes(packet, offset, len), StandardCharsets.UTF_8); offset += len; int port = Binary.readShort(Binary.subBytes(packet, offset, 2)) & 0xffff; offset += 2; byte[] payload = Binary.subBytes(packet, offset); this.instance.handleRaw(address, port, payload); } else if (id == RakNet.PACKET_SET_OPTION) { int len = packet[offset++]; String name = new String(Binary.subBytes(packet, offset, len), StandardCharsets.UTF_8); offset += len; String value = new String(Binary.subBytes(packet, offset), StandardCharsets.UTF_8); this.instance.handleOption(name, value); } else if (id == RakNet.PACKET_OPEN_SESSION) { int len = packet[offset++]; String identifier = new String(Binary.subBytes(packet, offset, len), StandardCharsets.UTF_8); offset += len; len = packet[offset++]; String address = new String(Binary.subBytes(packet, offset, len), StandardCharsets.UTF_8); offset += len; int port = Binary.readShort(Binary.subBytes(packet, offset, 2)) & 0xffff; offset += 2; long clientID = Binary.readLong(Binary.subBytes(packet, offset, 8)); this.instance.openSession(identifier, address, port, clientID); } else if (id == RakNet.PACKET_CLOSE_SESSION) { int len = packet[offset++]; String identifier = new String(Binary.subBytes(packet, offset, len), StandardCharsets.UTF_8); offset += len; len = packet[offset++]; String reason = new String(Binary.subBytes(packet, offset, len), StandardCharsets.UTF_8); this.instance.closeSession(identifier, reason); } else if (id == RakNet.PACKET_INVALID_SESSION) { int len = packet[offset++]; String identifier = new String(Binary.subBytes(packet, offset, len), StandardCharsets.UTF_8); this.instance.closeSession(identifier, "Invalid session"); } else if (id == RakNet.PACKET_ACK_NOTIFICATION) { int len = packet[offset++]; String identifier = new String(Binary.subBytes(packet, offset, len), StandardCharsets.UTF_8); offset += len; int identifierACK = Binary.readInt(Binary.subBytes(packet, offset, 4)); this.instance.notifyACK(identifier, identifierACK); } return true; } return false; } }
7,527
Java
.java
Nukkit/Nukkit
821
272
171
2015-05-23T09:51:41Z
2024-03-21T12:28:05Z