use of net.glowstone.block.itemtype.ItemFood in project Glowstone by GlowstoneMC.
the class ItemTable method registerBuiltins.
// //////////////////////////////////////////////////////////////////////////
// Registration
private void registerBuiltins() {
// TODO: Some new materials in 1.13 may be missing, although most are covered as part of
// MaterialUtil sets.
// Blocks:
reg(Material.FLOWER_POT, new BlockFlowerPot());
reg(Material.JUKEBOX, new BlockJukebox());
reg(Material.NOTE_BLOCK, new BlockNote());
reg(Material.SPAWNER, new BlockMobSpawner());
regAll(MaterialTags.INFESTED_BLOCKS, new BlockMonsterEgg());
reg(Material.DRAGON_EGG, new BlockFalling(Material.DRAGON_EGG));
regAll(Tag.SIGNS, BlockSign::new, Sound.BLOCK_WOOD_BREAK);
regAll(Tag.WALL_SIGNS, BlockSign::new, Sound.BLOCK_WOOD_BREAK);
reg(Material.CRAFTING_TABLE, new BlockWorkbench(), Sound.BLOCK_WOOD_BREAK);
reg(Material.ENDER_CHEST, new BlockEnderChest());
reg(Material.CHEST, new BlockChest(), Sound.BLOCK_WOOD_BREAK);
reg(Material.TRAPPED_CHEST, new BlockChest(true), Sound.BLOCK_WOOD_BREAK);
reg(Material.DISPENSER, new BlockDispenser());
reg(Material.DROPPER, new BlockDropper());
reg(Material.BOOKSHELF, new BlockDirectDrops(Material.BOOK, 3), Sound.BLOCK_WOOD_BREAK);
reg(Material.CLAY, new BlockDirectDrops(Material.CLAY_BALL, 4), Sound.BLOCK_GRAVEL_BREAK);
regAll(MaterialTags.STAINED_TERRACOTTA, new BlockDirectDrops(ToolType.PICKAXE));
regAll(MaterialTags.GLAZED_TERRACOTTA, new BlockDirectDrops(ToolType.PICKAXE));
regAll(Tag.WOODEN_DOORS, BlockDoor::new, Sound.BLOCK_WOOD_BREAK);
reg(Material.IRON_DOOR, new BlockDoor(Material.IRON_DOOR));
reg(Material.FARMLAND, new BlockFarmland(), Sound.BLOCK_GRAVEL_BREAK);
reg(Material.GLASS, new BlockDropless());
reg(Material.GLASS_PANE, new BlockDropless());
regAll(MaterialTags.STAINED_GLASS, new BlockDropless());
regAll(MaterialTags.STAINED_GLASS_PANES, new BlockDropless());
reg(Material.GLOWSTONE, new BlockRandomDrops(Material.GLOWSTONE_DUST, 2, 4));
reg(Material.MYCELIUM, new BlockMycel(), Sound.BLOCK_GRAVEL_BREAK);
reg(Material.GRASS, new BlockGrass(), Sound.BLOCK_GRASS_BREAK);
reg(Material.DIRT, new BlockDirt(), Sound.BLOCK_GRAVEL_BREAK);
reg(Material.GRAVEL, new BlockGravel(), Sound.BLOCK_GRAVEL_BREAK);
reg(Material.SAND, new BlockFalling(Material.SAND), Sound.BLOCK_SAND_BREAK);
reg(Material.ANVIL, new BlockAnvil());
reg(Material.ICE, new BlockIce());
reg(Material.PACKED_ICE, new BlockDropless());
reg(Material.SNOW, new BlockSnow(), Sound.BLOCK_SNOW_BREAK);
reg(Material.SNOW_BLOCK, new BlockSnowBlock(), Sound.BLOCK_SNOW_BREAK);
reg(Material.PRISMARINE, new BlockDirectDrops(ToolType.PICKAXE));
reg(Material.RED_SANDSTONE, new BlockDirectDrops(ToolType.PICKAXE));
reg(Material.SANDSTONE, new BlockDirectDrops(ToolType.PICKAXE));
reg(Material.NETHER_BRICK, new BlockDirectDrops(ToolType.PICKAXE));
reg(Material.NETHER_BRICK_FENCE, new BlockFence(Material.NETHER_BRICK_FENCE, ToolType.PICKAXE));
regAll(Tag.WOODEN_FENCES, BlockFence::new);
reg(Material.NETHERRACK, new BlockDirectDrops(ToolType.PICKAXE));
// TODO: Convert
reg(Material.IRON_BARS, new BlockDirectDrops(ToolType.PICKAXE));
reg(Material.BRICK, new BlockDirectDrops(ToolType.PICKAXE));
// TODO: Convert
reg(Material.LEGACY_SMOOTH_BRICK, new BlockDirectDrops(ToolType.PICKAXE));
reg(Material.END_STONE, new BlockDirectDrops(ToolType.PICKAXE));
reg(Material.COBBLESTONE, new BlockDirectDrops(ToolType.PICKAXE));
reg(Material.COBBLESTONE_WALL, new BlockDirectDrops(ToolType.PICKAXE));
reg(Material.MOSSY_COBBLESTONE, new BlockDirectDrops(ToolType.PICKAXE));
reg(Material.STONE, new BlockStone());
reg(Material.OBSIDIAN, new BlockDirectDrops(ToolType.DIAMOND_PICKAXE));
reg(Material.COAL_ORE, new BlockOre(Material.COAL, ToolType.PICKAXE));
reg(Material.COAL_BLOCK, new BlockDirectDrops(ToolType.PICKAXE));
reg(Material.IRON_ORE, new BlockDirectDrops(ToolType.STONE_PICKAXE));
reg(Material.IRON_BLOCK, new BlockDirectDrops(ToolType.STONE_PICKAXE));
reg(Material.GOLD_ORE, new BlockDirectDrops(ToolType.IRON_PICKAXE));
reg(Material.GOLD_BLOCK, new BlockDirectDrops(ToolType.IRON_PICKAXE));
reg(Material.DIAMOND_ORE, new BlockOre(Material.DIAMOND, ToolType.IRON_PICKAXE));
reg(Material.DIAMOND_BLOCK, new BlockDirectDrops(ToolType.IRON_PICKAXE));
reg(Material.EMERALD_ORE, new BlockOre(Material.EMERALD, ToolType.IRON_PICKAXE));
reg(Material.EMERALD_BLOCK, new BlockDirectDrops(ToolType.PICKAXE));
reg(Material.LAPIS_ORE, new BlockOre(Material.LAPIS_LAZULI, ToolType.STONE_PICKAXE, 4, 4, 8));
reg(Material.LAPIS_BLOCK, new BlockDirectDrops(ToolType.STONE_PICKAXE));
reg(Material.NETHER_QUARTZ_ORE, new BlockOre(Material.QUARTZ, ToolType.PICKAXE));
reg(Material.REDSTONE_ORE, new BlockRedstoneOre());
reg(Material.REDSTONE_BLOCK, new BlockDirectDrops(ToolType.PICKAXE));
reg(Material.CARROT, new BlockCarrot(), Sound.BLOCK_GRASS_BREAK);
reg(Material.COCOA, new BlockCocoa(), Sound.BLOCK_WOOD_BREAK);
reg(Material.DEAD_BUSH, new BlockDeadBush(), Sound.BLOCK_GRASS_BREAK);
reg(Material.TALL_GRASS, new BlockTallGrass(), Sound.BLOCK_GRASS_BREAK);
reg(Material.RED_MUSHROOM_BLOCK, new BlockHugeMushroom(true), Sound.BLOCK_WOOD_BREAK);
reg(Material.BROWN_MUSHROOM_BLOCK, new BlockHugeMushroom(false), Sound.BLOCK_WOOD_BREAK);
regAll(Tag.LEAVES, new BlockLeaves(), Sound.BLOCK_GRASS_BREAK);
reg(Material.MELON, new BlockMelon(), Sound.BLOCK_WOOD_BREAK);
reg(Material.MELON_STEM, new BlockStem(Material.MELON_STEM), Sound.BLOCK_GRASS_BREAK);
reg(Material.NETHER_WART, new BlockNetherWart(), Sound.BLOCK_GRASS_BREAK);
reg(Material.POTATO, new BlockPotato(), Sound.BLOCK_GRASS_BREAK);
reg(Material.PUMPKIN_STEM, new BlockStem(Material.PUMPKIN_STEM), Sound.BLOCK_GRASS_BREAK);
reg(Material.WHEAT, new BlockCrops(), Sound.BLOCK_GRASS_BREAK);
reg(Material.CAKE, new BlockDropless(), Sound.BLOCK_WOOL_BREAK);
reg(Material.COBWEB, new BlockWeb());
reg(Material.FIRE, new BlockFire());
reg(Material.END_PORTAL_FRAME, new BlockEnderPortalFrame());
regAll(MaterialTags.WOODEN_GATES, new BlockFenceGate());
regAll(Tag.TRAPDOORS, new BlockWoodenTrapDoor(), Sound.BLOCK_WOOD_BREAK);
reg(Material.IRON_TRAPDOOR, new BlockIronTrapDoor());
reg(Material.FURNACE, new BlockFurnace());
reg(Material.LEVER, new BlockLever());
reg(Material.HOPPER, new BlockHopper());
reg(Material.PISTON, new BlockPiston(false));
reg(Material.STICKY_PISTON, new BlockPiston(true));
regAll(Tag.WOODEN_STAIRS, new BlockStairs(), Sound.BLOCK_WOOD_BREAK);
regAll(Sets.difference(Tag.STAIRS.getValues(), Tag.WOODEN_STAIRS.getValues()), new BlockStairs());
regAll(Tag.WOODEN_SLABS, new BlockSlab(), Sound.BLOCK_WOOD_BREAK);
regAll(Sets.difference(Tag.SLABS.getValues(), Tag.WOODEN_SLABS.getValues()), new BlockSlab());
reg(Material.HAY_BLOCK, new BlockHay());
reg(Material.QUARTZ_BLOCK, new BlockQuartz());
regAll(Tag.LOGS, new BlockLog(), Sound.BLOCK_WOOD_BREAK);
reg(Material.LADDER, new BlockLadder(), Sound.BLOCK_WOOD_BREAK);
reg(Material.VINE, new BlockVine());
reg(Material.STONE_BUTTON, new BlockButton(Material.STONE_BUTTON));
regAll(Tag.WOODEN_BUTTONS, BlockButton::new, Sound.BLOCK_WOOD_BREAK);
regAll(MaterialTags.BEDS, new BlockBed());
regAll(MaterialTags.SKULLS, new BlockSkull());
reg(Material.TORCH, new BlockTorch());
reg(Material.LIGHT_WEIGHTED_PRESSURE_PLATE, new BlockDirectDrops(Material.LIGHT_WEIGHTED_PRESSURE_PLATE, ToolType.PICKAXE));
reg(Material.HEAVY_WEIGHTED_PRESSURE_PLATE, new BlockDirectDrops(Material.HEAVY_WEIGHTED_PRESSURE_PLATE, ToolType.PICKAXE));
reg(Material.STONE_PRESSURE_PLATE, new BlockDirectDrops(Material.STONE_PRESSURE_PLATE, ToolType.PICKAXE));
reg(Material.DAYLIGHT_DETECTOR, new BlockDaylightDetector());
regAll(Tag.FLOWERS, new BlockNeedsAttached());
reg(Material.BROWN_MUSHROOM, new BlockMushroom(Material.BROWN_MUSHROOM));
reg(Material.RED_MUSHROOM, new BlockMushroom(Material.RED_MUSHROOM));
reg(Material.SUGAR_CANE, new BlockSugarCane(), Sound.BLOCK_GRASS_BREAK);
regAll(Tag.SAPLINGS, new BlockSapling());
reg(Material.RAIL, new BlockRails());
reg(Material.ACTIVATOR_RAIL, new BlockRails());
reg(Material.DETECTOR_RAIL, new BlockRails());
reg(Material.POWERED_RAIL, new BlockRails());
regAll(Tag.CARPETS, new BlockCarpet(), Sound.BLOCK_WOOL_BREAK);
reg(Material.ENCHANTING_TABLE, new BlockEnchantmentTable());
reg(Material.BREWING_STAND, new BlockBrewingStand());
reg(Material.CACTUS, new BlockCactus());
reg(Material.WATER, new BlockWater());
reg(Material.LAVA, new BlockLava());
reg(Material.CAULDRON, new BlockCauldron());
reg(Material.SPONGE, new BlockSponge());
reg(Material.TNT, new BlockTnt());
// TODO: Convert
reg(Material.LEGACY_DOUBLE_PLANT, new BlockDoublePlant());
reg(Material.PUMPKIN, new BlockPumpkin());
reg(Material.JACK_O_LANTERN, new BlockPumpkinBase(Material.JACK_O_LANTERN));
reg(Material.SEA_LANTERN, new BlockRandomDrops(Material.PRISMARINE_CRYSTALS, 2, 3));
reg(Material.REDSTONE_LAMP, new BlockLamp());
reg(Material.REDSTONE_WIRE, new BlockRedstone());
reg(Material.REDSTONE_TORCH, new BlockRedstoneTorch());
reg(Material.REPEATER, new BlockRedstoneRepeater());
reg(Material.MAGMA_BLOCK, new BlockMagma());
reg(Material.NETHER_WART_BLOCK, new BlockDirectDrops(Material.NETHER_WART_BLOCK, ToolType.AXE));
reg(Material.RED_NETHER_BRICKS, new BlockDirectDrops(Material.RED_NETHER_BRICKS, ToolType.PICKAXE));
reg(Material.BONE_BLOCK, new BlockDirectDrops(Material.BONE_BLOCK, ToolType.PICKAXE));
reg(Material.OBSERVER, new BlockObserver());
reg(Material.COMPARATOR, new BlockRedstoneComparator());
reg(Material.BEACON, new BlockBeacon());
reg(Material.PURPUR_PILLAR, new BlockPurpurPillar());
reg(Material.PURPUR_BLOCK, new BlockDirectDrops(Material.PURPUR_BLOCK, ToolType.PICKAXE));
reg(Material.END_ROD, new BlockEndRod());
regAll(MaterialTags.CONCRETES, BlockDirectDrops::new);
regAll(MaterialTags.CONCRETE_POWDER, new BlockConcretePowder());
regAll(MaterialTags.GLAZED_TERRACOTTA, BlockDirectDrops::new);
reg(Material.CHORUS_FLOWER, new BlockChorusFlower());
reg(Material.CHORUS_PLANT, new BlockChorusPlant());
reg(Material.GRASS_PATH, new BlockGrassPath(), Sound.BLOCK_GRASS_BREAK);
// Non-block and ItemPlaceAs items:
reg(Material.FLINT_AND_STEEL, new ItemFlintAndSteel());
regAll(Tag.SIGNS, new ItemSign());
reg(Material.REDSTONE, new ItemPlaceAs(Material.REDSTONE_WIRE));
reg(Material.BREWING_STAND, new ItemPlaceAs(Material.BREWING_STAND));
reg(Material.CAULDRON, new ItemPlaceAs(Material.CAULDRON));
reg(Material.FLOWER_POT, new ItemPlaceAs(Material.FLOWER_POT));
regAll(MaterialTags.SKULLS, ItemPlaceAs::new);
reg(Material.BUCKET, new ItemBucket());
reg(Material.WATER_BUCKET, new ItemFilledBucket(Material.WATER));
reg(Material.LAVA_BUCKET, new ItemFilledBucket(Material.LAVA));
reg(Material.WOODEN_HOE, new ItemHoe());
reg(Material.STONE_HOE, new ItemHoe());
reg(Material.IRON_HOE, new ItemHoe());
reg(Material.GOLDEN_HOE, new ItemHoe());
reg(Material.DIAMOND_HOE, new ItemHoe());
reg(Material.WOODEN_SHOVEL, new ItemShovel());
reg(Material.STONE_SHOVEL, new ItemShovel());
reg(Material.IRON_SHOVEL, new ItemShovel());
reg(Material.GOLDEN_SHOVEL, new ItemShovel());
reg(Material.DIAMOND_SHOVEL, new ItemShovel());
regAll(MaterialTags.SPAWN_EGGS, new ItemSpawn());
reg(Material.WHEAT_SEEDS, new ItemSeeds(Material.WHEAT, Material.FARMLAND));
reg(Material.MELON_SEEDS, new ItemSeeds(Material.MELON_STEM, Material.FARMLAND));
reg(Material.PUMPKIN_SEEDS, new ItemSeeds(Material.PUMPKIN_STEM, Material.FARMLAND));
reg(Material.NETHER_WART, new ItemSeeds(Material.NETHER_WART, Material.SOUL_SAND));
reg(Material.CARROT, new ItemFoodSeeds(Material.CARROT, Material.FARMLAND, 3, 3.6f));
reg(Material.POTATO, new ItemFoodSeeds(Material.POTATO, Material.FARMLAND, 1, 0.6f));
reg(Material.INK_SAC, new ItemDye());
regAll(Tag.BANNERS, new ItemBanner());
reg(Material.IRON_DOOR, new ItemPlaceAs(Material.IRON_DOOR));
reg(Material.WRITTEN_BOOK, new ItemWrittenBook());
reg(Material.ITEM_FRAME, new ItemItemFrame());
reg(Material.APPLE, new ItemFood(4, 2.4f));
reg(Material.BAKED_POTATO, new ItemFood(5, 6f));
reg(Material.BREAD, new ItemFood(5, 6f));
reg(Material.COOKED_CHICKEN, new ItemFood(6, 7.2f));
reg(Material.COOKED_COD, new ItemFishCooked());
reg(Material.COOKED_SALMON, new ItemFishCooked());
reg(Material.COOKED_MUTTON, new ItemFood(6, 9.6f));
reg(Material.COOKED_BEEF, new ItemFood(8, 12.8f));
reg(Material.COOKED_RABBIT, new ItemFood(5, 6f));
reg(Material.COOKIE, new ItemFood(2, 0.4f));
reg(Material.GOLDEN_APPLE, new ItemGoldenApple());
reg(Material.GOLDEN_CARROT, new ItemFood(6, 14.4f));
reg(Material.COOKED_PORKCHOP, new ItemFood(8, 12.8f));
reg(Material.MELON, new ItemFood(2, 1.2f));
reg(Material.BEETROOT, new ItemFood(1, 1.2f));
reg(Material.BEETROOT_SOUP, new ItemSoup(6, 7.2f));
reg(Material.MUSHROOM_STEW, new ItemSoup(6, 7.2f));
reg(Material.POISONOUS_POTATO, new ItemPoisonousPotato());
reg(Material.PUMPKIN_PIE, new ItemFood(8, 4.8f));
reg(Material.RABBIT_STEW, new ItemSoup(10, 12f));
reg(Material.BEEF, new ItemFood(3, 1.8f));
reg(Material.CHICKEN, new ItemRawChicken());
reg(Material.COD, new ItemFishRaw());
reg(Material.SALMON, new ItemFishRaw());
reg(Material.MUTTON, new ItemFood(2, 1.2f));
reg(Material.PORKCHOP, new ItemFood(3, 1.8f));
reg(Material.RABBIT, new ItemFood(3, 1.8f));
reg(Material.ROTTEN_FLESH, new ItemRottenFlesh());
reg(Material.SPIDER_EYE, new ItemSpiderEye());
reg(Material.CHORUS_FRUIT, new ItemChorusFruit());
reg(Material.ARMOR_STAND, new ItemArmorStand());
reg(Material.MILK_BUCKET, new ItemMilk());
reg(Material.MINECART, new ItemMinecart(GlowMinecart.MinecartType.RIDEABLE));
reg(Material.COMMAND_BLOCK_MINECART, new ItemMinecart(GlowMinecart.MinecartType.COMMAND));
reg(Material.TNT_MINECART, new ItemMinecart(GlowMinecart.MinecartType.TNT));
reg(Material.HOPPER_MINECART, new ItemMinecart(GlowMinecart.MinecartType.HOPPER));
reg(Material.FURNACE_MINECART, new ItemMinecart(GlowMinecart.MinecartType.FURNACE));
reg(Material.CHEST_MINECART, new ItemMinecart(GlowMinecart.MinecartType.CHEST));
reg(Material.SNOWBALL, new ItemSnowball());
reg(Material.EGG, new ItemEgg());
reg(Material.BOW, new ItemBow());
reg(Material.EXPERIENCE_BOTTLE, new ItemExperienceBottle());
reg(Material.END_CRYSTAL, new ItemEndCrystal());
reg(Material.OAK_BOAT, new ItemBoat(TreeSpecies.GENERIC));
reg(Material.SPRUCE_BOAT, new ItemBoat(TreeSpecies.REDWOOD));
reg(Material.BIRCH_BOAT, new ItemBoat(TreeSpecies.BIRCH));
reg(Material.JUNGLE_BOAT, new ItemBoat(TreeSpecies.JUNGLE));
reg(Material.ACACIA_BOAT, new ItemBoat(TreeSpecies.ACACIA));
reg(Material.DARK_OAK_BOAT, new ItemBoat(TreeSpecies.DARK_OAK));
reg(Material.PAINTING, new ItemPainting());
reg(Material.FIREWORK_ROCKET, new ItemFirework());
reg(Material.ENDER_PEARL, new ItemEnderPearl());
reg(Material.KNOWLEDGE_BOOK, new ItemKnowledgeBook());
reg(Material.FISHING_ROD, new ItemFishingRod());
}
use of net.glowstone.block.itemtype.ItemFood in project Glowstone by GlowstoneMC.
the class GlowPlayer method pulse.
@Override
public void pulse() {
super.pulse();
incrementStatistic(Statistic.TIME_SINCE_DEATH);
if (usageItem != null) {
if (usageItem.equals(getItemInHand())) {
// todo: implement offhand
if (--usageTime == 0) {
ItemType item = ItemTable.instance().getItem(usageItem.getType());
if (item instanceof ItemFood) {
((ItemFood) item).eat(this, usageItem);
}
}
} else {
usageItem = null;
usageTime = 0;
}
}
if (digging != null) {
pulseDigging();
}
if (exhaustion > 4.0f) {
exhaustion -= 4.0f;
if (saturation > 0f) {
saturation = Math.max(saturation - 1f, 0f);
sendHealth();
} else if (world.getDifficulty() != Difficulty.PEACEFUL) {
FoodLevelChangeEvent event = EventFactory.getInstance().callEvent(new FoodLevelChangeEvent(this, Math.max(foodLevel - 1, 0)));
if (!event.isCancelled()) {
foodLevel = event.getFoodLevel();
}
sendHealth();
}
}
if (getHealth() < getMaxHealth() && !isDead()) {
if (foodLevel >= 18 && ticksLived % 80 == 0 || world.getDifficulty() == Difficulty.PEACEFUL) {
EntityUtils.heal(this, 1, EntityRegainHealthEvent.RegainReason.SATIATED);
exhaustion = Math.min(exhaustion + 3.0f, 40.0f);
saturation -= 3;
}
}
// Process food level and starvation based on difficulty.
switch(world.getDifficulty()) {
case PEACEFUL:
{
if (foodLevel < 20 && ticksLived % 20 == 0) {
foodLevel++;
}
break;
}
case EASY:
{
if (foodLevel == 0 && getHealth() > 10 && ticksLived % 80 == 0) {
damage(1, DamageCause.STARVATION);
}
break;
}
case NORMAL:
{
if (foodLevel == 0 && getHealth() > 1 && ticksLived % 80 == 0) {
damage(1, DamageCause.STARVATION);
}
break;
}
case HARD:
{
if (foodLevel == 0 && ticksLived % 80 == 0) {
damage(1, DamageCause.STARVATION);
}
break;
}
default:
{
// Do nothing when there are other game difficulties.
}
}
// process ender pearl cooldown, decrease by 1 every game tick.
if (enderPearlCooldown > 0) {
enderPearlCooldown--;
}
// stream world
streamBlocks();
processBlockChanges();
// add to playtime (despite inaccurate name, this counts ticks rather than minutes)
incrementStatistic(Statistic.PLAY_ONE_MINUTE);
if (isSneaking()) {
incrementStatistic(Statistic.SNEAK_TIME);
}
// update inventory
for (InventoryMonitor.Entry entry : invMonitor.getChanges()) {
sendItemChange(entry.slot, entry.item);
}
// send changed metadata
List<MetadataMap.Entry> changes = metadata.getChanges();
if (!changes.isEmpty()) {
session.send(new EntityMetadataMessage(getEntityId(), changes));
}
// Entity IDs are only unique per world, so we can't spawn or teleport between worlds while
// updating them.
worldLock.writeLock().lock();
try {
// update or remove entities
List<GlowEntity> destroyEntities = new LinkedList<>();
for (Iterator<GlowEntity> it = knownEntities.iterator(); it.hasNext(); ) {
GlowEntity entity = it.next();
if (!isWithinDistance(entity) || entity.isRemoved()) {
destroyEntities.add(entity);
} else {
entity.createUpdateMessage(session).forEach(session::send);
}
}
if (!destroyEntities.isEmpty()) {
List<Integer> destroyIds = new ArrayList<>(destroyEntities.size());
for (GlowEntity entity : destroyEntities) {
knownEntities.remove(entity);
destroyIds.add(entity.getEntityId());
}
session.send(new DestroyEntitiesMessage(destroyIds));
}
// add entities
knownChunks.forEach(key -> world.getChunkAt(key.getX(), key.getZ()).getRawEntities().stream().filter(entity -> this != entity && isWithinDistance(entity) && !entity.isDead() && !knownEntities.contains(entity) && !hiddenEntities.contains(entity.getUniqueId())).forEach((entity) -> Bukkit.getScheduler().runTaskAsynchronously(null, () -> {
worldLock.readLock().lock();
try {
knownEntities.add(entity);
} finally {
worldLock.readLock().unlock();
}
entity.createSpawnMessage().forEach(session::send);
entity.createAfterSpawnMessage(session).forEach(session::send);
})));
} finally {
worldLock.writeLock().unlock();
}
if (passengerChanged) {
session.send(new SetPassengerMessage(getEntityId(), getPassengers().stream().mapToInt(Entity::getEntityId).toArray()));
}
getAttributeManager().sendMessages(session);
GlowFishingHook hook = currentFishingHook.get();
if (hook != null) {
// bobber, or if the player stops holding a fishing rod.
if (getInventory().getItemInMainHand().getType() != Material.FISHING_ROD && getInventory().getItemInOffHand().getType() != Material.FISHING_ROD) {
setCurrentFishingHook(null);
}
if (hook.location.distanceSquared(location) > HOOK_MAX_DISTANCE * HOOK_MAX_DISTANCE) {
setCurrentFishingHook(null);
}
}
}
Aggregations