Compare commits

..

535 Commits

Author SHA1 Message Date
7e1095e28d Reenabled collision against entities on move 2014-11-06 12:57:17 +01:00
f1519e6d13 Improved Level->getTile() to a direct lookup instead of linear search 2014-11-06 12:34:33 +01:00
3b9a9bcd5d Use proper indexes on Living->getLineOfSight() when a max length is set 2014-11-06 12:23:45 +01:00
263bff01c8 Change RuntimeException to InvalidStateException on BlockIterator 2014-11-06 12:16:12 +01:00
987d647b76 Return proper BlockIterator index, throw more exceptions, improved blockQueue performance 2014-11-06 12:12:31 +01:00
9eed0a579c Fixed red sand smelting recipe 2014-11-05 17:41:12 +01:00
064976d32b Fixed ladder recipe 2014-11-05 17:38:23 +01:00
2abb577178 Fixed String -> Wool recipe 2014-11-05 17:36:44 +01:00
127855c220 Fixed Snow block recipe 2014-11-05 17:36:06 +01:00
93c7a3c170 Fixed bonemeal recipe, closes #2260 2014-11-05 17:32:28 +01:00
31903a764a Fixed unloaded chunks residing on memory and getting loaded again causing crash, fixed spawn chunks getting unloaded by players 2014-11-04 17:16:02 +01:00
79bc1d6c85 Fixed server not stopping after a special crash 2014-11-04 17:15:20 +01:00
cc7f12739d Added vertical and horizontal collision detection to Entities 2014-11-04 12:23:42 +01:00
32dae93ef9 Removed unused imports 2014-11-04 12:08:24 +01:00
8fd6582e74 Automatically set Entity / Tile entity save identifiers 2014-11-04 12:04:08 +01:00
a5369b3570 Fixed unloading chunks 2014-11-04 11:18:34 +01:00
abbd33210a Possible fix for #2245 2014-11-04 00:19:50 +01:00
6b6222c09c Allow passing a Player source as last parameter on Inventory->addItem() and Inventory->removeItem() 2014-11-04 00:16:25 +01:00
a8c997d88a ¬¬ 2014-11-03 12:54:46 +01:00
6993718a83 Added EntityDamageByChildEntityEvent 2014-11-03 12:03:37 +01:00
86afecec89 Improved inventory sending, send single slots instead of full inventory as much as possible 2014-11-03 11:48:10 +01:00
29d1fd1fc8 Fixed player viewer list including themselves 2014-11-03 11:29:01 +01:00
af4eb2ab1e Create server.log properly on non-existent directories 2014-11-02 16:15:15 +01:00
f7baf46a54 Fire PlayerInteractEvent on 0xff face 2014-11-02 16:12:51 +01:00
75c0d8324c Fixed some inventory events not firing on players 2014-11-02 13:26:58 +01:00
da4334f06b Revert Armor then Inventory instead of Inventory then Armor on failed transaction 2014-11-01 23:02:59 +01:00
413bd3c0df Use SplFixedArray for improved performance 2014-11-01 22:12:35 +01:00
1a0428654b Updated timings command, give direct link to results 2014-11-01 21:20:44 +01:00
2803a38fd1 Fixed random block updates not firing 2014-11-01 20:26:13 +01:00
95a5ca7889 Added command message to /time add 2014-11-01 20:12:55 +01:00
240f14c425 Fixed #2253 2014-11-01 19:40:15 +01:00
cb9b6ab1d1 Fixed server not using the correct provided path if it did not exist 2014-11-01 19:23:10 +01:00
8a87280566 Added /time start and /time stop 2014-11-01 17:45:11 +01:00
4d97827d44 Improved level switching for players 2014-11-01 17:39:09 +01:00
f8f1e0e9df Despawn entities correctly from clients as they move 2014-11-01 16:47:40 +01:00
bf596ebf05 Fixed Query-related crash 2014-11-01 16:20:40 +01:00
90777014b6 Fixed Stone crash 2014-11-01 16:17:47 +01:00
4a78ffd2dd Fixed FallingSand crash 2014-11-01 16:15:09 +01:00
7c361a52d2 Fixed #2252 2014-11-01 13:52:20 +01:00
13fc0df92c Fixed #2251 2014-11-01 12:40:45 +01:00
d5012f6fcf Fixed server not stopping after a fatal error 2014-11-01 03:07:47 +01:00
4569a73f3d Fixed Entity being set position after being closed 2014-10-31 23:10:29 +01:00
66acb5cdd7 Possible fix for crashing server not stopping 2014-10-31 23:10:12 +01:00
8601405a88 Fixed CPU leak 2014-10-31 21:07:00 +01:00
ae06681b60 Added packet exception handling, updated RakLib 2014-10-31 19:14:59 +01:00
01ffb14e39 Fixed #2204 2014-10-31 17:34:45 +01:00
ce989876af Improved freeing chunks 2014-10-31 16:39:32 +01:00
f8d6ebabf3 Removed some calls 2014-10-31 15:57:07 +01:00
094b600a0c Updated NBT/DataPacket reading 2014-10-31 01:02:31 +01:00
82cfe6ea9c Updated NBT/DataPacket reading 2014-10-31 00:32:50 +01:00
f72d7284b9 Added EncapsulatedPacket reuse on broadcast 2014-10-30 23:20:28 +01:00
8f0527832f Removed extra AxisAlignedBB generation on Door and Trapdoor 2014-10-30 22:15:19 +01:00
f66944368d Update RakLib 2014-10-30 22:06:23 +01:00
7ab3c57b00 Optimized networking code & AxisAlignedBB 2014-10-30 22:06:07 +01:00
673b867ee8 Fixed players not loading chunks when stuck on a unloaded chunk 2014-10-30 20:05:40 +01:00
2424c8a76c Update RakLib, possible fix for notifyACK 2014-10-30 19:44:05 +01:00
92eb5cb0b8 Added LE Triad methods 2014-10-30 17:56:58 +01:00
fd46c71120 Updated RakLib 2014-10-30 17:18:43 +01:00
6a4259bf24 Updated RakLib 2014-10-30 17:04:19 +01:00
9a65279c6a Added ifndef for packets Binary 2014-10-30 16:41:11 +01:00
09a01be709 Added ifndef for NBT Binary 2014-10-30 16:32:57 +01:00
57d1847c50 Updated to receive new optimizations 2014-10-30 16:02:48 +01:00
6e8e2a79dd Fixed Event name being null 2014-10-30 14:52:11 +01:00
d8f9def7f4 Added preprocessor optimizations 2014-10-30 07:58:53 +01:00
8cb9dd9a14 Fixed #2244 2014-10-29 22:58:40 +01:00
c4c374e3fa Added extra chunk sending timings 2014-10-29 21:52:27 +01:00
d57e37896d Improved Region / RakLib 2014-10-29 17:43:21 +01:00
022a978ffb Added InventoryPickupArrowEvent 2014-10-29 16:29:00 +01:00
00b282d40c Improved cache pool cleanup times 2014-10-29 16:13:47 +01:00
8a768cea33 EntityDamageEvent and children now only fire if the attack is possible, moved event trigger to Entity->attack() 2014-10-29 16:02:40 +01:00
289bc56b4b Blocks now save their bounding box, fixed entity block collision check 2014-10-29 15:43:23 +01:00
6f64af3066 Reuse even more objects! 2014-10-29 14:23:51 +01:00
72c09045d5 Fixed Zombie drops crash 2014-10-29 13:21:54 +01:00
5e55c3a8f0 Fixed Chest->unpair() 2014-10-29 13:21:14 +01:00
afaa2cf722 Fixed Double Chest behavior 2014-10-29 12:57:26 +01:00
50cfeaa393 Fixed Stonecutter recipe 2014-10-29 12:36:34 +01:00
dda8b03349 Fixed Bowl recipe 2014-10-29 12:12:54 +01:00
56e848488a Fixed Trapdoor recipe 2014-10-29 12:10:48 +01:00
7e4f862634 Fixed typo in OfflinePlayer 2014-10-29 11:42:29 +01:00
78f8d0280d Removed unused imports 2014-10-29 01:14:09 +01:00
0680b98380 Remove chunks from advanced cache after setting 2014-10-29 01:07:30 +01:00
cbe0fe5e46 Added Entity->onGround setting when entities keep moving without checks 2014-10-29 00:41:13 +01:00
7eed92e8fb Use Player->forceMovement on MovePlayerPacket non-tick revert 2014-10-29 00:31:17 +01:00
f772391866 Fixed InventoryPickupItemEvent 2014-10-28 22:05:54 +01:00
8c4faa8622 Added extra Exceptions 2014-10-28 21:07:12 +01:00
b6f7ee20fc Added Error -> Exception handling 2014-10-28 20:43:36 +01:00
0fce83c671 Fixed #2189 2014-10-28 13:27:30 +01:00
8080643cc9 Fixed plugins crashing the server when teleporting players on an invalid event 2014-10-28 13:18:40 +01:00
5bf2174cad Fixed UseItemPacket being able to be sent before spawning 2014-10-28 13:16:20 +01:00
34ae760def New way to spawn entities/tiles using a global register table, allow overriding default entity/tile classes via classes 2014-10-28 13:09:27 +01:00
a5b85c549a Added Snowballs 2014-10-28 12:13:31 +01:00
b9f1812f61 Disallow further modification of Signs by its creator after load/unload 2014-10-28 11:05:32 +01:00
350cee3d41 Added Event allocation pool, updated SPL with Class::onClassLoaded() 2014-10-28 10:47:40 +01:00
144a871c07 Improved Vector3 and Block handling, less allocation on Positions 2014-10-28 10:03:10 +01:00
69492474e4 Improve #2238, do not crash when an invalid/corrupt RCON stop event happens 2014-10-28 02:09:36 +01:00
4299ebebcc Bump API version to 1.6.1 2014-10-28 00:55:07 +01:00
119b429ab8 RakLib update 2014-10-28 00:43:47 +01:00
8f1eb41ca5 RakLib update 2014-10-28 00:23:55 +01:00
ca92d2a0d3 Bumped API version to 1.7.0 2014-10-27 20:30:58 +01:00
db82f76c11 Improved network packets allocation 2014-10-27 20:30:33 +01:00
3f5b129cf5 Updated RakLib 2014-10-27 19:39:24 +01:00
f6aac8728b Mark chunk to be saved when removing invalid entities/tiles 2014-10-27 18:43:58 +01:00
809fc44813 Bump API version to 1.6.1 2014-10-27 16:07:00 +01:00
64f1ff066d Fixed /setworldspawn changing sender data 2014-10-27 15:57:26 +01:00
a5a3f4801a Fixed entities not getting ticks on movement 2014-10-27 15:53:14 +01:00
23d1532ff9 Merge branch 'master' of github.com:PocketMine/PocketMine-MP 2014-10-27 15:44:44 +01:00
ecbbcc2e8e Drop invalid entities / tile entities on chunk loading 2014-10-27 15:44:36 +01:00
7abf52e615 Implemented Vector3 List and AxisAlignedBB Pool to decrease object allocation 2014-10-27 15:39:20 +01:00
9e01e2ef49 Merge pull request #2235 from nno88551/patch-2
Update BaseInventory.php
2014-10-26 15:52:08 +01:00
df81b365e5 Update BaseInventory.php 2014-10-26 22:21:21 +09:00
db8ac0b9cb Merge pull request #2225 from PEMapModder/falling-sand
Update FallingBlock to new Anvil formats, possible fix for #2189
2014-10-25 17:58:47 +02:00
ee4f416d93 Fix FallingBlock.php 2014-10-25 18:15:47 +08:00
8feea721e3 Merge pull request #2223 from Falkirks/set-armour-fix
Fix various get and set armour in PlayerInventory
2014-10-25 12:13:28 +02:00
8e7077ff4b Update FallingBlock to new Anvil formats, possible fix for #2189
I don't have time to test yet, so I am not sure if it does fix it.
2014-10-25 12:26:57 +08:00
4f4a6e7446 Fixes get and set armour 2014-10-24 17:11:59 -07:00
be948f99cc Fixed #2207 Server crashing if players are closed before logging in 2014-10-24 12:06:55 +02:00
516bb37a50 Removed some direct type checks on Entity/Tile->closed 2014-10-21 19:28:29 +02:00
580ade9092 Possible fix for entities not closing correctly 2014-10-21 19:26:16 +02:00
8f7dfe0b71 Removed extra ; from if, fixes #2205 2014-10-21 18:37:29 +02:00
5310ba3ae6 Fixed crash when doing var_dump() of anything that contains the Server object 2014-10-20 13:06:53 +02:00
ef97efcd96 Added explosion death message 2014-10-20 13:00:03 +02:00
30c3718ea8 Improved Explosion item drop position 2014-10-20 12:58:05 +02:00
e3e97a4205 Improved Player->onGround checking 2014-10-20 12:52:00 +02:00
fec387d2ec Fixed entities not being pushed out of blocks 2014-10-20 12:37:17 +02:00
481e2b08ee Removed debug call 2014-10-20 12:05:40 +02:00
15de0eece7 Improved inventory and window allocation, fixes #2200 2014-10-20 09:48:11 +02:00
2f8267aa1e Improved Level object deallocation 2014-10-19 20:45:03 +02:00
f2b573c32f Fixed Level->getMetadata() and similar, removed extra references 2014-10-19 19:51:36 +02:00
34946faf94 Remove errors from Utils::getRandomBytes() 2014-10-19 13:44:38 +02:00
3b47513439 Return result directly on Server->getOfflinePlayer() 2014-10-19 02:49:58 +02:00
2e6366868d Merge branch 'master' of github.com:PocketMine/PocketMine-MP 2014-10-18 16:53:42 +02:00
245e9b4f18 Fixes inventory changes getting the wrong window, closes #2187 2014-10-18 16:53:06 +02:00
68e73d4e3a Merge pull request #2188 from aodzip/patch-1
Update Skeleton.php
2014-10-18 15:36:02 +02:00
684617d370 Update Skeleton.php
fixed a little wrong
2014-10-18 21:13:35 +08:00
05f71691fc Fixed AxisAlignedBB->setBB() 2014-10-17 09:57:42 +02:00
1c03c3afcf Decreased chunk ordering times 2014-10-17 09:57:18 +02:00
94e9485be9 Improved broadcast packet encoding 2014-10-17 09:36:47 +02:00
9cb27e26ef Fixed #2183 2014-10-16 22:01:32 +02:00
7760559be1 Improved chunk loading and order refresh times 2014-10-16 20:21:06 +02:00
163a37ee23 Optimized Player->orderChunks() and chunk sending ordering algorithm 2014-10-16 14:54:55 +02:00
c73a3e53be Added extra Entity metadata 2014-10-16 12:49:45 +02:00
8637b7f5a3 Fixed Tasks deleting their Timings reports 2014-10-16 12:49:26 +02:00
747fdab389 Fixed Inventory->removeItem() 2014-10-16 12:16:23 +02:00
204915450f Do not wrap text if unknown characters are found. 2014-10-15 18:38:14 +02:00
500a690cd0 Throw CRITICAL error message on unhandled Exception on commands instead of crashing 2014-10-15 18:35:42 +02:00
d473ce13ee Throw CRITICAL error message on unhandled Exception on plugin events instead of crashing 2014-10-15 18:35:30 +02:00
1adf53a81e Fixed error_handler trace generation on higher debug levels 2014-10-15 17:58:03 +02:00
ed942100ec Do not block when killing workers 2014-10-15 17:49:08 +02:00
8abe95309c Fixed RegionLoader not creating default index on first load 2014-10-15 16:59:31 +02:00
5dc5aba42c Match Player pickup area with Minecraft 2014-10-15 14:57:12 +02:00
bda6f03e15 Added BlockUpdateEvent 2014-10-15 13:07:10 +02:00
69d132401e Fixes entities not being saved and tile entities having an incorrect field, closes #1661 2014-10-15 12:15:17 +02:00
e3a9db5d8f Implemented saving modified chunks 2014-10-15 11:42:58 +02:00
b71a4701d9 Fixed player using an invalid spawn chunk 2014-10-15 11:40:41 +02:00
9b85abd75e Micro-optimizations 2014-10-15 10:44:01 +02:00
7b7b91ea0d Fixed Entity updates not firing 2014-10-15 10:13:49 +02:00
18f6bad48d Implemented scheduled and partial entity updates 2014-10-14 22:49:35 +02:00
fbe548c611 RakLib update, PING/PONG handling 2014-10-14 16:13:32 +02:00
4e793199fa Deprecated EntityMoveEvent 2014-10-14 16:11:10 +02:00
43a97c407d New PlayerMoveEvent, improved player movement event firing 2014-10-14 16:10:50 +02:00
07dcbdb9b0 Fixed Level->getNearbyEntities(), fixes item drops not being picked up 2014-10-14 16:03:14 +02:00
60ca24fe0e Updated PluginManager event deprecation message 2014-10-14 14:11:58 +02:00
6e8144d5d9 Improved player movement event firing & corrections 2014-10-14 00:11:17 +02:00
464afb949e Increased Player->forceMovement check radius 2014-10-13 23:44:28 +02:00
823dc933b8 Improved Entity extinguish operations and packet spam 2014-10-13 23:44:11 +02:00
883f93cc8c Improved item drop spawning 2014-10-13 22:45:04 +02:00
b26ee09f76 Removed a bunch of TODO and fixed item drops on block update 2014-10-13 18:54:34 +02:00
1eec333501 Save block bounding boxes, improves block cache 2014-10-13 18:38:00 +02:00
5448a48f67 Fixed Level->getCollidingEntities() 2014-10-13 18:36:13 +02:00
a10ad42a13 Removed Generic block class 2014-10-13 18:12:34 +02:00
da23cf685d Added PlayerBucketEvent and children, improved Bucket usage and Liquid placing 2014-10-13 18:04:40 +02:00
79e4b3e3a9 Removed old Player->timeout property 2014-10-12 17:12:59 +02:00
8472349caf Improved global block cache 2014-10-12 17:02:27 +02:00
96b61fbb92 Made Wheat crops extend Crop class 2014-10-12 16:20:30 +02:00
6246ad19c4 Added global block cache 2014-10-12 16:16:19 +02:00
9b69cc4288 Removed debug code 2014-10-12 15:40:14 +02:00
114153ae97 Added EntityBlockChangeEvent 2014-10-12 13:37:45 +02:00
ebb844fa52 Removed unused code, fixed undefined variables 2014-10-11 22:22:51 +02:00
bf89ea1cf6 Added BlockGrowEvent 2014-10-11 20:19:46 +02:00
4076fb4657 Added BlockSpreadEvent 2014-10-11 19:27:43 +02:00
312f377483 Added LeavesDecayEvent 2014-10-11 19:01:27 +02:00
0af3dfedd5 Improved Living entity ticking 2014-10-11 17:35:13 +02:00
6f1f201c41 Workaround for entities glitching through the floor on the client-side 2014-10-11 17:02:41 +02:00
48f591e5ce Removed workaround on flying check due to physics calculation fix, closes #2169 2014-10-11 16:43:14 +02:00
7f85e37540 Worked on scheduler 2014-10-11 16:36:38 +02:00
341717c89d Increased Player->stepHeight to 0.6, closes #2156 2014-10-11 16:36:17 +02:00
afdf7bc2b9 Added proper TextWrap width 2014-10-11 00:17:31 +02:00
24c76acf30 Submodule update 2014-10-11 00:04:17 +02:00
baf06dc363 Revert "Use Collectable class on AsyncTask, removed task collection workaround on ServerScheduler"
This reverts commit 0dba14074a.
2014-10-11 00:03:46 +02:00
645c00b2f7 Added TextWrapper 2014-10-11 00:01:53 +02:00
0dd46c835c Made ExplosionPrimeEvent accept setting block breaking settings 2014-10-10 22:39:06 +02:00
0dba14074a Use Collectable class on AsyncTask, removed task collection workaround on ServerScheduler 2014-10-10 20:53:28 +02:00
8b585fd9f7 Deprecated Level->getSpawn() in favor of Level->getSpawnLocation() 2014-10-10 11:43:54 +02:00
9ede8177df Fixed Entity->getLineOfSight() 2014-10-10 09:53:58 +02:00
13ec046f0d Removed old OS detection code 2014-10-09 19:37:23 +02:00
5c4e7b6ee0 Added Living->getTargetBlock(), Living->getLineOfSight(), Vector3 side constants, Vector3::getOppositeSide() 2014-10-09 17:57:25 +02:00
6424934df6 Fixed EntityCombustEvent children using a different handlerList 2014-10-09 14:40:52 +02:00
b2ac959083 Added FurnaceSmeltEvent 2014-10-09 12:47:42 +02:00
c67d4dae7b Added FurnaceBurnEvent 2014-10-09 12:36:57 +02:00
22ad75c5a0 Update fuel duration to ticks 2014-10-09 12:21:14 +02:00
b45ef8928c Added Tile->getBlock() method 2014-10-09 12:14:39 +02:00
eccf7b08d2 Added PlayerDeathEvent methods for inventory keeping 2014-10-09 11:06:05 +02:00
94eb9e35e2 Improved liquid performance, update RakLib 2014-10-08 23:24:39 +02:00
79bf1f12f2 API 1.6.0 2014-10-08 17:39:43 +02:00
10b33546ef Added PlayerBedEnterEvent and PlayerBedLeaveEvent 2014-10-08 17:37:11 +02:00
c52dc58d6f Added ProjectileHitEvent 2014-10-08 17:04:35 +02:00
62af784d37 Removed unused imports 2014-10-08 17:00:23 +02:00
aa010b7dea Added ProjectileLaunchEvent 2014-10-08 16:58:17 +02:00
4a3163b4c8 Added ItemSpawnEvent 2014-10-08 16:53:13 +02:00
c750a204e6 Added ItemDespawnEvent 2014-10-08 16:51:10 +02:00
3313981d54 Fixed issues with Entity::heal() method 2014-10-08 16:46:21 +02:00
57f7d57c76 Added ExplosionPrimeEvent 2014-10-08 16:45:55 +02:00
64bf293c69 Improved EntityShootBowEvent 2014-10-08 16:36:43 +02:00
7b09edf048 Improved EntityRegainHealthEvent 2014-10-08 16:28:40 +02:00
4346773e25 Added EntityDamageByBlockEvent (child of EntityDamageEvent) 2014-10-08 16:13:18 +02:00
b0c314526d Added EntityCombustEvent and childs 2014-10-08 15:51:27 +02:00
dd140ce018 Fixed arrow damage not getting overridden by the event result 2014-10-08 15:38:58 +02:00
08aa7808cf Updated RakLib, better player join 2014-10-08 10:45:37 +02:00
582c165479 Implemented Explosion and PrimedTNT, closes #2139 2014-10-07 17:46:01 +02:00
5fb205493a Spawnable->spawnToAll() now uses the actual chunk instead of the entire level to spawn 2014-10-07 12:50:53 +02:00
e346d245e2 Merge pull request #2166 from PocketMine/query-event-implementation
Query event implementation
2014-10-07 11:46:55 +02:00
4fece32ca8 API 1.5.0 2014-10-07 11:02:22 +02:00
0b79d74a2f Implemented QueryRegenerateEvent 2014-10-07 11:02:05 +02:00
b83c6fbfa3 Added Vine blocks, closes #2162 2014-10-07 10:18:02 +02:00
dda9c598f1 Added new Tool type selection constants 2014-10-07 10:16:05 +02:00
8769d2bcd1 Unload entities from chunks, possible fix for #2157, fixes #2165 2014-10-07 09:27:18 +02:00
3b7ece3363 Do not spawn dead entities to players, fixes #2157, possible fix for #2165 2014-10-07 09:24:19 +02:00
b6025e3f2b Removed selectors on Player->sendMessage() 2014-10-06 16:45:11 +02:00
35de331b74 Fixed Level->getCollidingEntities() when called with a null Entity 2014-10-06 13:18:05 +02:00
de11cce154 Improved entity ticking 2014-10-06 13:10:59 +02:00
d53ba52d32 Removed parse errors from AutoReporting 2014-10-06 12:12:54 +02:00
9db2fe40eb Fixed player datta not getting saved, use fall distance on fly calculation 2014-10-06 12:02:36 +02:00
57bb8f14fa Fixed Player movement collision checks 2014-10-06 11:47:28 +02:00
761cd59514 Implemented flying protection 2014-10-06 11:22:59 +02:00
4c2a1c8684 Implement crop growth levels properly, fixes #2002, closes #2160 2014-10-06 09:34:40 +02:00
31bb6d1a68 Changed base block classes to abstract, closes #2159 2014-10-06 09:27:44 +02:00
cd65179aef Fixes #2155 2014-10-06 12:07:48 +10:30
9abd2c63f4 Improved initial chunk loading, do not skip near chunks, fixes world loading getting stuck 2014-10-06 00:45:02 +02:00
376e359577 Moved connected flag up in the Player disconnect process 2014-10-05 22:51:20 +02:00
571e2f8895 Revert "Option to disable hitbox calculation"
This reverts commit fae330d499.
2014-10-05 16:32:49 +02:00
7106ea87e6 Merge branch 'master' of github.com:PocketMine/PocketMine-MP 2014-10-05 16:32:27 +02:00
6b65b68ebc Possible fix for #1661 2014-10-05 16:32:15 +02:00
d4c75ce68a Trim system timezone output 2014-10-05 17:40:17 +10:30
fae330d499 Option to disable hitbox calculation 2014-10-04 20:07:37 -05:00
5e03e157ad Fixed #2153 2014-10-04 23:16:35 +02:00
b0c40dc1ab Fixed Server->unloadLevel() not removing objects from memory 2014-10-04 20:56:27 +02:00
6840589f4e Fix trailing newline 2014-10-04 18:28:42 +02:00
19e4aaa16a Merge pull request #2151 from sekjun9878/master
Timezone for Windows and IP Geolocation TZdata
2014-10-05 01:51:44 +09:30
e0a7944faa Re-use timezone offset parsing 2014-10-05 01:43:33 +09:30
eeda22d0ba Add portable linux timezone detection for incompatible linux distributions. 2014-10-05 01:29:07 +09:30
769f1effb0 Cleaner timezone parsing for Linux and add support for Macs 2014-10-05 01:05:00 +09:30
42c7322273 Reliable timezone detection using systeminfo for Windows and additional IP Geolocation-based detection. Added a warning message for when auto-detection fails. Fixes #2015. 2014-10-05 00:32:01 +09:30
c8cf6b715e Merge pull request #2150 from PEMapModder/patch-2
Fixed PlayerChatEvent::setRecipients() being ignored
2014-10-04 14:49:14 +02:00
41f94f7385 Fixed PlayerChatEvent::setRecipients() being useless 2014-10-04 20:10:12 +08:00
602bdf27a5 Compatibility with pthreads > 2.0.8 2014-10-02 16:58:37 +02:00
539fa232f8 Added individual object timings to Entities / Tile Entities 2014-09-30 16:09:21 +02:00
f8378c09ba Fixed entities getting OnGround default to true 2014-09-30 13:13:31 +02:00
69fb7ae525 Update RakLib, fixes server locking when shutting down 2014-09-30 09:52:50 +02:00
ee8ad6f92a Implement Armor changes as Transactions 2014-09-30 09:37:58 +02:00
f888acbd7c Send PlayerArmorEquipmentPacket instead of ContainerSetContentPacket with id 0x78 2014-09-29 23:43:52 +02:00
215691f1c4 Update RakLib 2014-09-29 23:23:11 +02:00
1252dd65a9 Improved PlayerInventory->setItemInHand() $source call, fixed Tool durability 2014-09-29 17:53:53 +02:00
762c27affe Added armor change $source parameter 2014-09-29 17:50:48 +02:00
706e1099a1 Update raklib 2014-09-29 16:46:19 +02:00
9cd66dc969 Some changes 2014-09-29 16:37:56 +02:00
5b6b789ab3 Improved exponentiation 2014-09-29 13:24:25 +02:00
85ff696ae5 Improved Chunk entity loading 2014-09-29 13:14:14 +02:00
25f8e8318b Fixed Anvil levels duplicating saved entities 2014-09-29 13:09:13 +02:00
61d84c73d0 Implemented Arrow pick up 2014-09-29 13:05:18 +02:00
f5822c6de8 Improved entity movement updates 2014-09-29 12:59:01 +02:00
b0bd927545 Improved entity base ticks 2014-09-29 12:55:10 +02:00
fde61b7d21 Improved single-threaded chunk generation efficiency 2014-09-29 12:48:11 +02:00
886ad8442c Fixed #2055 Extra packet data sent on armor change 2014-09-28 17:31:44 +02:00
7b5869bea8 RakLib submodule update 2014-09-28 16:35:24 +02:00
3063863c65 RakLib update 2014-09-28 16:06:27 +02:00
0dfaa19380 Fixed invalid spawn position setting for plugins 2014-09-28 15:19:09 +02:00
7fea29e874 Updated pthreads version on Travis-CI 2014-09-28 12:50:03 +02:00
2ded2013bf Fixed auto-save configuration, made it global 2014-09-28 10:50:43 +02:00
aa27c28e65 Force new player position on spawn 2014-09-28 01:14:03 +02:00
05a81bebf4 Fixed server crash when Tile Entities / Entities were loaded and requested the same chunk 2014-09-28 00:39:49 +02:00
ce91f2943a Fixed Double Chests 2014-09-28 00:39:11 +02:00
1d8562fb8c Allow setting the player spawnpoint via events before PlayerJoinEvent 2014-09-28 00:14:08 +02:00
1dfb17b932 Fixed #2126 Items drop twice from tile entities 2014-09-27 14:31:41 +02:00
16384c2b20 Improved Player generation queue 2014-09-27 10:31:02 +02:00
48041b2f19 Basic entity motion on water 2014-09-27 00:09:38 +02:00
529bf743db Added torch drop 2014-09-26 23:07:43 +02:00
48bc919a33 Added Liquid flow 2014-09-26 16:56:10 +02:00
474091c013 Improved Level block update scheduling for repeated updates 2014-09-26 16:55:34 +02:00
666e5553c2 Fixed Level->scheduleUpdate() tick calculation 2014-09-26 16:04:51 +02:00
ae6f532b1d Partial Liquid flow 2014-09-26 13:25:52 +02:00
b231eba803 Fixed E_NOTICE error on player movement 2014-09-26 13:23:47 +02:00
82d903733d Fixed #2121 2014-09-26 11:34:06 +02:00
8e2903da86 API version 1.4.1 2014-09-26 11:19:30 +02:00
d720113ac9 Added non-threaded chunk generation, toggleable on pocketmine.yml 2014-09-26 11:18:46 +02:00
5db45222c6 Deprecated Level->getChunkAt() in favor of Level->getChunk() 2014-09-26 10:31:32 +02:00
2975509d0f Improved chunk unload queue, possible fix for #1661 2014-09-25 23:03:56 +02:00
7e49d073fa Improved player movement, check once per tick 2014-09-24 16:58:22 +02:00
ef3674a296 Possible fix for #1661 2014-09-24 16:47:53 +02:00
6cb7e36f8a Improved knockback motion 2014-09-24 16:17:04 +02:00
b88f19bb74 Improved Level::getSafeSpawn() 2014-09-23 20:16:16 +02:00
8c3fcf0798 Send player metadata on respawn 2014-09-23 20:14:01 +02:00
6b312a7826 Fixed players getting Suffocation damage inside transparent blocks 2014-09-23 19:50:44 +02:00
9907e84eee Torches can now be crafted using charcoal 2014-09-23 19:36:30 +02:00
01f299a7f1 Merge branch 'master' of github.com:PocketMine/PocketMine-MP 2014-09-23 15:54:59 +02:00
91f20f6789 Add valid position difference back to Player entities 2014-09-23 15:54:48 +02:00
4c1edc3f7e Re-order RFC section 2014-09-23 20:32:39 +09:30
5fd1e271c5 Merge pull request #2112 from PocketMine/rfc-rfc-and-voting
RFC and Voting
2014-09-22 15:46:03 +02:00
593b0497b0 Fixed #1750 cannot place slabs against blocks 2014-09-22 11:58:15 +02:00
0907aedcef Fixed Entity/Block issues on negative coordinates, closes #2100 2014-09-22 11:48:39 +02:00
0a29e66b62 Fixed #2114 Removed Player collisions with other entities 2014-09-22 11:26:12 +02:00
3cc4afbcd6 Possible fix for #1920 2014-09-22 11:21:54 +02:00
b3ae6eae04 Added RFC ready status, added new label to label list 2014-09-22 09:30:14 +02:00
3b56b536b6 Changed RFC label 2014-09-22 08:46:03 +02:00
9258281546 Fixed missing whitespace 2014-09-21 21:18:37 +02:00
e7897be7cd Merge pull request #2113 from tnpxxsheepdog/rfc-rfc-and-voting
Update CONTRIBUTING.md
2014-09-21 21:08:18 +02:00
5ff01de413 Update CONTRIBUTING.md
Smoothed out wording, fix grammar.
2014-09-21 15:05:08 -04:00
f191ada405 Fixed text typo 2014-09-21 18:33:34 +02:00
addd74d09e Fix typo, added PR: Request for Comments label 2014-09-21 17:51:35 +02:00
4e9d2d0a7f Added 'RFC and Voting' to CONTRIBUTING.md 2014-09-21 17:45:58 +02:00
d04e994d1b Added TPS load to /status 2014-09-21 12:18:51 +02:00
3d870629f2 Fixed ifconfig command typo 2014-09-21 12:18:26 +02:00
8dbe834dc3 Submodule update 2014-09-21 12:18:10 +02:00
36d8100e17 Protect against \0 attacks on name checking 2014-09-20 18:26:17 +02:00
b880bf13f8 Documented tool usage in Level::useBreakOn() 2014-09-20 18:25:53 +02:00
1ac08ce404 Fixed Utils::getUniqueID() on Linux due to /proc/cpuinfo 2014-09-20 12:39:57 +02:00
689b2ea877 Fixed #2104 Can't place blocks where non-solid entities exist 2014-09-20 11:10:46 +02:00
d1f22ee395 Block more player actions when dead, closes #2102 2014-09-19 20:19:27 +02:00
056ed4802f Send project name on usage 2014-09-19 15:08:40 +02:00
bcb65e9a48 Send build number on usage 2014-09-19 15:07:48 +02:00
5404ba77d0 Throw exception when Server::dispatchCommand() is called with an invalid CommandSender 2014-09-19 10:30:35 +02:00
ae54426836 Fixed date_default_timezone_set E_NOTICE 2014-09-19 10:26:44 +02:00
ee7d84dfbd Fixed T_DOUBLE_COLON 2014-09-19 09:48:02 +02:00
3e1ea23036 Fixed CallbackTask name 2014-09-19 09:46:38 +02:00
d312d2a143 Possible fix for #2046, removed embedded class names 2014-09-19 09:44:58 +02:00
8c627bd0af Remove level locks, possible fix for #2046 2014-09-18 11:44:16 +02:00
6fb7170556 Handle force parameter properly on Level::unload() 2014-09-18 11:38:03 +02:00
50f5c6d8ed RakLib patches 2014-09-18 09:22:52 +02:00
f9d5c5bd37 Improved event checking on PlayerInteractEvent 2014-09-16 17:49:44 +02:00
45dbb3f828 Improved block collision check 2014-09-16 12:02:33 +02:00
8a8a95480e Added Cactus damage 2014-09-16 12:02:18 +02:00
34139c7efe Added more death messages 2014-09-16 11:51:43 +02:00
f0e7713dce Added suffocation, drowning damage. Closes #1908 2014-09-16 11:51:31 +02:00
3ba099b309 Cobweb, Ladders and Water won't cause fall damage 2014-09-16 10:52:00 +02:00
c4a0c759dc Show fire to other clients 2014-09-16 10:48:56 +02:00
e9a2f88847 Added Fire, Lava damage 2014-09-16 10:42:29 +02:00
e608acbd1c Improved Player last damage check 2014-09-16 10:42:01 +02:00
42033da08b Fixed #2035 Invalid Fence Gate bounding box 2014-09-16 00:47:04 +02:00
69ab0d433b Removed old trigger_error() 2014-09-16 00:42:36 +02:00
44a30b7fac Added forced position strong check for Player 2014-09-16 00:32:03 +02:00
50b2f55583 Increased movement error range 2014-09-15 23:53:08 +02:00
da084d6908 Fixed door bounding boxes, closes#2075 2014-09-15 23:40:26 +02:00
7d51bc0004 Possible fix for #2077 2014-09-15 22:14:05 +02:00
87dbc18452 Removed position revert message on plugin event cancelled 2014-09-15 20:32:42 +02:00
5b8d4bba11 Fixed issues with placing doors 2014-09-15 20:32:27 +02:00
bb4c54106a Added temporal workaround for pthreads version check 2014-09-15 18:55:15 +02:00
1617b2509e Fixed plugin-related crash 2014-09-15 12:09:30 +02:00
ec293ebd9e Merge pull request #2071 from PocketMine/pthreads-fix
Removed pthreads workarounds, new pthreads version
2014-09-15 10:16:35 +02:00
9f9422f0ed Added Player->forceMovement check on teleport 2014-09-15 01:16:13 +02:00
da715e48e2 Bumped pthreads version 2014-09-13 12:07:04 +02:00
702b2e539c Update RakLib 2014-09-13 12:01:11 +02:00
63fc229c12 Enabled default PHP GC on generator thread 2014-09-12 15:57:02 +02:00
c71689a919 Optimized server sleep times 2014-09-12 15:56:21 +02:00
09428bc8c7 Merge branch 'master' into pthreads-fix 2014-09-12 13:32:53 +02:00
6c7e16d9d4 Added Permission/Permissible calculation timings 2014-09-12 13:08:59 +02:00
315ea2ea3c 64-bit Random optimizations 2014-09-12 12:58:21 +02:00
83eb9f778a Level generators can be set in server.properties 2014-09-12 01:05:32 +02:00
7923c40b33 Removed as Vector3 on Flat generator 2014-09-12 00:12:52 +02:00
d298adabad Merge branch 'master' into pthreads-fix 2014-09-11 22:06:10 +02:00
cfcf515f62 Added type hint to BlockEvent::getBlock() 2014-09-11 21:57:56 +02:00
b5deae7ba0 Added synchronization to GenerationThread::pushMainToThreadPacket() 2014-09-11 19:18:14 +02:00
d991c32435 Fixed Generator Thread as specified on krakjoe/pthreads#349 2014-09-11 19:10:25 +02:00
dbd1f3f96e Use pthreads interface on Chunk Generation THread, remove IPC sockets, improve performance 2014-09-11 18:05:14 +02:00
0bd7ab9def Added .mailmap file, fixes duplicated commiter names 2014-09-11 17:41:07 +02:00
665c275bb7 New improved RakLib version with pthreads changes 2014-09-11 17:18:54 +02:00
7ef2708fca Permission & interface optimization 2014-09-11 16:43:11 +02:00
78b4223795 Added PermissionAttachment::unsetPermissions(), PermissionAttachment::clearPermissions() 2014-09-11 12:43:53 +02:00
0328b4c5f5 Added PermissionAttachment::setPermissions()
This allows bulk permission without recalculating the new permissions until all everything is set. Permission plugins that set a big amount of nodes may want to use this method.
2014-09-11 12:39:01 +02:00
4624dfb472 Fixed Permissible::setPermission() not using the correct order on replacement 2014-09-11 12:17:03 +02:00
fba12c6ddf Fixed EntityMoveEvent not being cancelled correctly on players 2014-09-10 20:06:30 +02:00
60011a5ecf Fixed PermissionAttachment not recalculating its Permissible permissions 2014-09-10 20:05:41 +02:00
f4ae58dda2 Removed pthreads workarounds 2014-09-10 15:11:56 +02:00
8c939feed9 Added Pumpkin & Lit Pumpkin rotation, closes 2014-09-10 12:36:05 +02:00
02ca227085 Normalized Player pitch/yaw 2014-09-10 12:23:23 +02:00
1174b0c45c Added binary reading optimizations, faster 64-bit reading 2014-09-10 12:13:15 +02:00
8940360df4 Possible fix for #2061 2014-09-10 10:43:24 +02:00
bb34e06754 Fix division by zero when the server goes too fast 2014-09-09 19:13:35 +02:00
e06092cb99 Added Server::getTickUsage() 2014-09-09 18:46:20 +02:00
57373b8c5e TPS measurement improvement, moved interface handling to tick 2014-09-09 18:07:27 +02:00
317c6788a6 Updated RakLib path 2014-09-08 10:11:43 +02:00
0a4e0e3228 Fixed Item drop delay 2014-09-08 07:40:19 +02:00
d8c492de4a Merge pull request #2062 from Yosshi999/patch1
Fixed HeldItem were swapped in mining
2014-09-08 07:37:24 +02:00
05d59d587b Merge pull request #2063 from Yosshi999/patch2
Fixed Player's slot[0] disappears on loging in
2014-09-08 07:37:16 +02:00
7d387fe6aa Fixed TravisTest output 2014-09-07 19:54:13 +02:00
4f7a6a06be Fixed TravisTest pipes 2014-09-07 19:47:31 +02:00
344c84cfa6 Added --disable-readline CLI argument 2014-09-07 19:42:36 +02:00
bd721a13a3 Merge branch 'master' of github.com:PocketMine/PocketMine-MP 2014-09-07 19:33:01 +02:00
92b0b4d43c Implemented basic Travis-CI test 2014-09-07 19:32:21 +02:00
d0b0fbf992 Merge pull request #2064 from PEMapModder/patch-2
Fixed wrong cases
2014-09-07 09:02:54 +02:00
ab334e6962 Fixed wrong cases
I know this doesn't matter at all, but it is ugly in IDEs.
2014-09-07 13:21:05 +08:00
1ad6438e60 Fixed Player's slot[0] disappears on loging in 2014-09-07 11:37:54 +09:00
4ecec42c9d Fixed HeldItem were swapped in mining 2014-09-07 11:29:17 +09:00
84e62598ce Implemented attack cooldown 2014-09-06 16:52:52 +02:00
ad7acb93b6 Added cactus neighbour block check 2014-09-05 11:16:24 +02:00
ac4b4b08fd Fixed Level::setBlock() old calls 2014-09-05 11:00:13 +02:00
d3c308c5a8 Fixed possible Player crash on save 2014-09-05 10:50:19 +02:00
98e0583f34 Implemented Falling Sand 2014-09-05 10:50:06 +02:00
020351e20f Fixed #2052 2014-09-05 09:02:45 +02:00
f140fef52d Possible fix for level save issues, related to #1985 #1982 #1758 2014-09-04 12:37:27 +02:00
9980a0780a Fixed Server::getTicksPerSecond() 2014-09-04 12:22:16 +02:00
352497d88c Improves server ticking.
As I was lying in my bed, I came to a solution for the tick problem.
While remembering how most of the time the server is sleeping,
and how the TPS drops once costly operations are ticked,
I reviewed mentally that part of the code, Server::tick().

Then I saw it: I was setting the next execution time
using the time after it was executed as the base, but it should
have been done using the tick start time - that way if something takes
longer, the server will catch up and won't drop the TPS
until the CPU hits its limit.

I got up, got to my computer, and checked that function.
It was exactly as I saw in a near-dream state, so I fixed it
and tested things if they worked right.

Now I'm fully awake and I can't sleep anymore, so I wrote this.
2014-09-04 01:04:09 +02:00
ba08bfaa45 Do not report E_PARSE or E_COMPILE_ERROR crashes 2014-09-03 13:38:24 +02:00
dea4513c34 Possible fix for #2041 2014-09-03 11:55:49 +02:00
0eac084aa7 Added extra documentation to Level::setBlock() 2014-09-03 11:44:30 +02:00
e17ecf5795 Improved Arrow / Item movement 2014-09-03 10:55:14 +02:00
e94ddcabe0 Fixed dropped items going too fast 2014-09-01 23:37:31 +02:00
acf7eb1ce9 Remove scheduled updates from entities 2014-09-01 23:30:35 +02:00
dcfb7a7ac4 Fixed #2037 2014-09-01 17:47:28 +02:00
97c87aa8fa Added __debugInfo() to Server and Level 2014-09-01 17:37:28 +02:00
11f684d803 Improved CallbackTask timings data 2014-09-01 12:44:52 +02:00
ff48eb3d4d Added better Entity/Tile scheduled updates 2014-09-01 11:59:46 +02:00
e047b6a870 Fixed bows not getting damaged 2014-09-01 11:43:48 +02:00
c5626bae34 Do not set Level to null, closes #2032 2014-09-01 11:29:44 +02:00
3eac08f5ba Possible fix for #2027, properly check Player onGround flag 2014-09-01 02:32:16 +02:00
cc2555bb88 Fixed crash when chests are closed with viewers 2014-09-01 02:26:23 +02:00
705e4da789 Tick entities on Level, show correct timing reports 2014-09-01 01:56:13 +02:00
9b7a94b5ee Fixed timings ticks getting reset 2014-09-01 01:50:28 +02:00
bcdb6d8c2e Fixed timings name 2014-09-01 01:28:42 +02:00
eff63a661e Player creative check refactor 2014-08-31 10:49:20 +02:00
5a756d215d Fixed creative players dropping their inventory 2014-08-31 10:45:38 +02:00
422262d585 Fixed infinite Entity recursion on chunk load 2014-08-31 01:06:53 +02:00
b761a97660 Fixed crash due to class name conflict 2014-08-31 01:05:15 +02:00
7579cd763a Added Trapdoor bounding box 2014-08-30 23:57:57 +02:00
6bc5f60011 Added Cobble Wall bounding box 2014-08-30 23:52:06 +02:00
3eb8ca0d13 Added Soul Sand bounding box 2014-08-30 23:47:39 +02:00
a23352be88 Added Ladder bounding box 2014-08-30 23:45:08 +02:00
fa5f00a1ff Added Cake bounding boxe 2014-08-30 23:42:07 +02:00
d3a05adede Added Doors bounding boxes 2014-08-30 23:38:56 +02:00
f9182bd0f8 Added Iron bars bounding box 2014-08-30 23:30:10 +02:00
edad52c6ea Added Glass Pane bounding box 2014-08-30 23:30:01 +02:00
cd5e16f017 Added Fence Gate bounding box 2014-08-30 23:20:59 +02:00
310a7d6c04 Added Fence bounding box 2014-08-30 23:18:37 +02:00
ccea26c978 Added Farmland bounding box 2014-08-30 23:07:55 +02:00
cf542ac73a Added End Portal frame bounding box 2014-08-30 23:06:50 +02:00
3bf39df255 Added cactus bounding box 2014-08-30 23:06:27 +02:00
910e5e6181 Added stairs bounding box 2014-08-30 23:01:33 +02:00
a396b8c220 Fixed #2021 2014-08-30 21:45:32 +02:00
ec1fe6a083 Fixed EntityShootBowEventEvent crash 2014-08-30 19:07:17 +02:00
706c97b9b1 Made shooting bow use its durability 2014-08-30 18:46:09 +02:00
a04516a879 Added EntityShootBowEvent, made bow require an arrow 2014-08-30 18:43:32 +02:00
0f6dfd39b8 Made EntityDamageByEntityEvent call EntityDamageEvent handlers 2014-08-30 18:41:00 +02:00
36ee6d9966 Added arrow and suicide death messages 2014-08-30 18:30:39 +02:00
23793e0fc4 Added check for invalid entity attack 2014-08-30 18:24:24 +02:00
3409d332e7 Added survival check to movements 2014-08-30 17:57:30 +02:00
ca1b67a675 hmm 2014-08-30 17:07:50 +02:00
f5eed4f12b Disable RakLib port checking by default 2014-08-30 16:14:09 +02:00
7a10f91330 Fixed entity partial block moving 2014-08-30 15:31:22 +02:00
6477f4f077 Added Wooden Slab bounding box 2014-08-30 02:14:48 +02:00
3731e74696 Added Slab bounding box 2014-08-30 02:14:24 +02:00
c774e4c203 Added Carpet bounding box 2014-08-30 02:09:15 +02:00
d4907a2688 Added Chest bounding box 2014-08-30 02:07:50 +02:00
793520926b Added Bed bounding box 2014-08-30 02:06:46 +02:00
bf839e821c Added proper arrows and damage 2014-08-30 01:22:46 +02:00
7aeacf2705 Fixed armor crafting recipes 2014-08-29 14:49:41 +02:00
fc62c91c90 Fixed double physics calculation 2014-08-29 13:33:59 +02:00
98dd7f8c15 Use Entity::move() as player movement, protect against noclip cheat 2014-08-29 13:33:25 +02:00
7a1d25617f Fixed physics sneak flag 2014-08-29 13:02:08 +02:00
69b3ef326b Merge pull request #1994 from PocketMine/nbt-array
Added NBT <-> PHP array/type conversion methods
2014-08-29 12:17:10 +02:00
fadff2cc5b Removed debug code 2014-08-28 23:59:18 +02:00
43a0ef433e API version bump 2014-08-28 23:44:19 +02:00
9a1e7ca83c Implemented NBT::getArray() and NBT::setArray() 2014-08-28 23:43:04 +02:00
b9111b6f52 Fixed #1992 2014-08-28 23:19:44 +02:00
be70121f3a Renamed Item\Block to Item\ItemBlock 2014-08-28 22:28:32 +02:00
e2986992c7 Fixed AxisAlignedBB infinite expansion 2014-08-28 21:11:49 +02:00
9fb46d8fe8 Fixed entity physics 2014-08-28 18:26:37 +02:00
eab86f5f90 Replaced array() with [] 2014-08-28 17:04:22 +02:00
2f2afe2336 Fixed #1966 Face Lit Pumkins correctly 2014-08-28 11:00:41 +02:00
f7de1ede3f Made PocketMine loader backwards-compatible 2014-08-27 21:30:36 +02:00
812ae09a06 Merge branch 'php-5.6' 2014-08-27 21:24:52 +02:00
e473cd5e67 Improved unloaded tile entity handling 2014-08-27 18:18:33 +02:00
9e5e4fb362 Fixed possible Level::getBlock() crash 2014-08-27 18:11:23 +02:00
afa98866e0 Fixed Item after-clone behaviour 2014-08-27 18:11:02 +02:00
90fa40de34 Added entity id names 2014-08-27 17:42:38 +02:00
e6234c4c4d Removed cli_set_process_title() check 2014-08-27 12:45:14 +02:00
8f66d03d99 Improved Item::get() 2014-08-27 12:43:54 +02:00
8e9da9c84e Improved safe_var_dump(), Inventory::addItem() Inventory::removeItem() using argument unpacking 2014-08-27 12:29:04 +02:00
759d7e2545 Initial PHP 5.6 features support 2014-08-27 12:21:01 +02:00
f4b92bcdfc Fixed #1980 2014-08-27 11:41:00 +02:00
f7e2d31f0a Check player online status, closes #1983 2014-08-27 11:28:49 +02:00
e0fc3784ad Throw exception when saving an already-closed player, closes #1981 2014-08-26 22:02:43 +02:00
bf5630dc0d Fixed #1926 Teleport to non-generated chunks 2014-08-26 16:45:51 +02:00
472431752b Dropped items and arrows get deleted on Y < 0 2014-08-26 16:19:45 +02:00
c40f9f65a5 Optimize imports 2014-08-26 11:54:24 +02:00
f74af12914 Improved chunk ticking, enabled again. Disable it setting chunk-ticking.per-tick to 0 2014-08-26 11:52:45 +02:00
d169734781 Improved chunk sending 2014-08-26 11:50:51 +02:00
35b86af2af Fixed furnace achievement check 2014-08-26 10:56:33 +02:00
706bc8e8db Fixed undefined index on furnace recipes 2014-08-26 00:05:40 +02:00
b542c5b9bd Added Furnace progress fire 2014-08-26 00:05:18 +02:00
69800c6d79 Fixed #1911 Implemented FurnaceInventory callback 2014-08-26 00:03:16 +02:00
ea9fc3c72e Fixed #1879 Tile entities were not saved on chunk unload 2014-08-26 00:02:20 +02:00
8b90281355 Fixed #1953 Increased item PickupDelay to 2.5 seconds 2014-08-25 23:38:35 +02:00
92cabced97 Ctrl+C handling and kill signals are working again 2014-08-25 23:24:18 +02:00
cb645fa288 Moved spl to PocketMine-SPL 2014-08-25 21:02:33 +02:00
bda597a71e Moved spl to PocketMine-SPL 2014-08-25 20:54:53 +02:00
d6a0e284e3 Workaround BaseChunk::setBlock() recursion issues 2014-08-25 17:08:02 +02:00
1795c8c5e3 Fixed Chests/Furnaces not dropping contents when broken 2014-08-25 16:59:04 +02:00
c3b1b59118 Fixed #1970 Breaking blocks does not remove tile entities 2014-08-25 16:55:52 +02:00
a0df0a8fff Fixed player fall damage 2014-08-25 16:53:20 +02:00
049103ab7a Improved Block selection and construction performance 2014-08-25 16:39:47 +02:00
84c63c48ca Improved NBT IntArray read/write 2014-08-25 16:28:46 +02:00
20e11bd408 Improved player onGround collision check 2014-08-25 15:48:12 +02:00
456760b334 Removed unloaded chunk check 2014-08-25 15:43:48 +02:00
46e502430e Added teleport flag to MovePlayerPacket, improves player movement 2014-08-25 13:01:39 +02:00
87b800ebb9 Fixed #1967 Glowstone dust -> Glowstone recipe 2014-08-25 11:33:47 +02:00
9fdafb87b4 Fixed #1962 Fake client-side player entities 2014-08-24 23:12:12 +02:00
1fcfef20b0 Implemented beds 2014-08-24 20:34:24 +02:00
6109505786 Implemented correct time offsets and speed 2014-08-24 20:34:06 +02:00
764937dda4 Fixed #1961 2014-08-24 18:08:14 +02:00
8bf36315ae Updated RakLib 2014-08-24 17:21:05 +02:00
1ea0531ec7 Added RakLib port checking option 2014-08-24 17:16:37 +02:00
c47e359262 Updated blocks bounding boxes 2014-08-24 16:30:56 +02:00
f0f9bccb4b Fixed #1960 2014-08-24 15:57:13 +02:00
214dcef1ea Improved Air block collision check 2014-08-24 15:55:34 +02:00
4edadd764c Improved Level::getBlock() 2014-08-24 14:30:43 +02:00
01ebe74974 Performance improvements in blocks and Entities 2014-08-24 14:08:17 +02:00
84ce5f1c73 Performance improvements in NBT reading/writing 2014-08-24 13:59:37 +02:00
93a2bd36e0 Require PHP >= 5.5 2014-08-24 13:33:03 +02:00
fdd59e4506 Fixed default memory-limit values 2014-08-23 20:14:41 +02:00
9b86b1d45b Added --enable-profiler parameter to use with @krakjoe profiler 2014-08-23 20:14:04 +02:00
1a38003bc4 Fixed /version 2014-08-22 19:39:24 +02:00
60ea4d0e96 Removed hardcoded Server name from source 2014-08-22 18:31:17 +02:00
6077190a62 Deprecated Server::loadPlugin(Plugin) in favor of Server::enablePlugin(Plugin) 2014-08-22 17:43:29 +02:00
57299b9a29 Fixed #1948 /whitelist list is now working 2014-08-22 13:23:56 +02:00
bb08da701b Fixed header logo in PR #1944 2014-08-22 11:30:15 +02:00
ee593fe5e4 Merge pull request #1944 from PEMapModder/patch-2
Cleaned Mycelium.php and fixed its potential crash
2014-08-22 11:22:10 +02:00
e8b1b0fab6 Cleaned Mycelium.php and fixed its potential crash
Crash report: http://crash.pocketmine.net/view/27500
2014-08-22 11:05:47 +08:00
446 changed files with 11087 additions and 6670 deletions

3
.gitmodules vendored
View File

@ -6,3 +6,6 @@
path = src/raklib
url = https://github.com/PocketMine/RakLib.git
branch = master
[submodule "src/spl"]
path = src/spl
url = https://github.com/PocketMine/PocketMine-SPL.git

5
.mailmap Normal file
View File

@ -0,0 +1,5 @@
Shoghi Cervantes <shoghicp@gmail.com>
Shoghi Cervantes <shoghicp@gmail.com> Shoghi Cervantes <shoghicp@pocketmine.net>
Brandon V <brandon15811@gmail.com>
Michael Yoo <sekjun9878@gmail.com> Michael Yoo <michael@yoo.id.au>
Michael Yoo <sekjun9878@gmail.com> Michael Yoo <sekjun9878@sekjun9878.info>

View File

@ -1,23 +1,21 @@
language: php
php:
- 5.4
- 5.5
- 5.6
branches:
except:
- Core-Rewrite
- master
- 0.9.0
- master
before_script:
- pecl install channel://pecl.php.net/pthreads-2.0.4
- mkdir plugins
- wget -O plugins/DevTools.phar https://github.com/PocketMine/DevTools/releases/download/v1.9.0/DevTools_v1.9.0.phar
- pecl install channel://pecl.php.net/pthreads-2.0.10
- pecl install channel://pecl.php.net/weakref-0.2.4
- echo | pecl install channel://pecl.php.net/yaml-1.1.1
script:
- php src/tests/ServerSuiteTest.php --no-wizard
- php tests/TravisTest.php
notifications:
email: false
webhooks: http://n.tkte.ch/h/214/wsNvmG43-ncxUVRrFPwSM-r0
#webhooks: http://n.tkte.ch/h/214/wsNvmG43-ncxUVRrFPwSM-r0

View File

@ -72,6 +72,19 @@ class ExampleClass{
}
```
### RFC and Voting
* These are big Pull Requests or contributions that change important behavior.
* RFCs will be tagged with the *PR: RFC* label
* A vote will be held once the RFC is ready. All users can vote commenting on the Pull Request
* Comments MUST use "Yes" or "No" on the FIRST sentence to signify the vote, except when they don't want it to be counted.
* If your comment is a voting comment, specify the reason of your vote or it won't be counted.
* After voting has been closed, no further votes will be counted.
* An RFC will be rejected if less than 50% + 1 (simple majority) has voted Yes.
* If the RFC is approved, Team Members have the final word on its implementation or rejection.
* RFCs with complex voting options will specify the vote percentage or other details.
## Bug Tracking for Collaborators
### Labels
@ -91,6 +104,7 @@ Category labels are prefixed by `C:`. Multiple category labels may be applied to
Pull Requests are prefixed by `PR:`. Only one label may be applied for a Pull Request.
- PR: Bug Fix - This label is applied when the Pull Request fixes a bug.
- PR: Contribution - This label is applied when the Pull Request contributes code to PocketMine-MP such as a new feature or an improvement.
- PR: RFC - Request for Comments
#### Status
Status labels show the status of the issue. Multiple status labels may be applied.

View File

@ -30,78 +30,78 @@ abstract class Achievement{
/**
* @var array[]
*/
public static $list = array(
public static $list = [
/*"openInventory" => array(
"name" => "Taking Inventory",
"requires" => [],
),*/
"mineWood" => array(
"mineWood" => [
"name" => "Getting Wood",
"requires" => array( //"openInventory",
),
),
"buildWorkBench" => array(
"requires" => [ //"openInventory",
],
],
"buildWorkBench" => [
"name" => "Benchmarking",
"requires" => array(
"requires" => [
"mineWood",
),
),
"buildPickaxe" => array(
],
],
"buildPickaxe" => [
"name" => "Time to Mine!",
"requires" => array(
"requires" => [
"buildWorkBench",
),
),
"buildFurnace" => array(
],
],
"buildFurnace" => [
"name" => "Hot Topic",
"requires" => array(
"requires" => [
"buildPickaxe",
),
),
"acquireIron" => array(
],
],
"acquireIron" => [
"name" => "Acquire hardware",
"requires" => array(
"requires" => [
"buildFurnace",
),
),
"buildHoe" => array(
],
],
"buildHoe" => [
"name" => "Time to Farm!",
"requires" => array(
"requires" => [
"buildWorkBench",
),
),
"makeBread" => array(
],
],
"makeBread" => [
"name" => "Bake Bread",
"requires" => array(
"requires" => [
"buildHoe",
),
),
"bakeCake" => array(
],
],
"bakeCake" => [
"name" => "The Lie",
"requires" => array(
"requires" => [
"buildHoe",
),
),
"buildBetterPickaxe" => array(
],
],
"buildBetterPickaxe" => [
"name" => "Getting an Upgrade",
"requires" => array(
"requires" => [
"buildPickaxe",
),
),
"buildSword" => array(
],
],
"buildSword" => [
"name" => "Time to Strike!",
"requires" => array(
"requires" => [
"buildWorkBench",
),
),
"diamonds" => array(
],
],
"diamonds" => [
"name" => "DIAMONDS!",
"requires" => array(
"requires" => [
"acquireIron",
),
),
],
],
);
];
public static function broadcast(Player $player, $achievementId){
@ -120,10 +120,10 @@ abstract class Achievement{
public static function add($achievementId, $achievementName, array $requires = []){
if(!isset(Achievement::$list[$achievementId])){
Achievement::$list[$achievementId] = array(
Achievement::$list[$achievementId] = [
"name" => $achievementName,
"requires" => $requires,
);
];
return true;
}

View File

@ -19,12 +19,14 @@
*
*/
interface LoggerAttachment{
namespace pocketmine;
class CompatibleClassLoader extends \BaseClassLoader{
/**
* @param mixed $level
* @param string $message
* @deprecated
*/
public function log($level, $message);
public function add($namespace, $paths){
$this->addPath(array_shift($paths));
}
}

View File

@ -22,6 +22,7 @@
namespace pocketmine;
use pocketmine\network\protocol\Info;
use pocketmine\plugin\PluginBase;
use pocketmine\plugin\PluginLoadOrder;
use pocketmine\utils\Utils;
use pocketmine\utils\VersionString;
@ -43,7 +44,7 @@ class CrashDump{
$this->path = $this->server->getDataPath() . "CrashDump_" . date("D_M_j-H.i.s-T_Y", $this->time) . ".log";
$this->fp = fopen($this->path, "wb");
$this->data["time"] = $this->time;
$this->addLine("PocketMine-MP Crash Dump " . date("D M j H:i:s T Y", $this->time));
$this->addLine($this->server->getName() . " Crash Dump " . date("D M j H:i:s T Y", $this->time));
$this->addLine();
$this->baseCrash();
$this->generalData();
@ -136,8 +137,8 @@ class CrashDump{
$error = $lastExceptionError;
}else{
$error = (array) error_get_last();
$error["trace"] = getTrace(4);
$errorConversion = array(
$error["trace"] = @getTrace(4);
$errorConversion = [
E_ERROR => "E_ERROR",
E_WARNING => "E_WARNING",
E_PARSE => "E_PARSE",
@ -153,7 +154,7 @@ class CrashDump{
E_RECOVERABLE_ERROR => "E_RECOVERABLE_ERROR",
E_DEPRECATED => "E_DEPRECATED",
E_USER_DEPRECATED => "E_USER_DEPRECATED",
);
];
$error["fullFile"] = $error["file"];
$error["file"] = cleanPath($error["file"]);
$error["type"] = isset($errorConversion[$error["type"]]) ? $errorConversion[$error["type"]] : $error["type"];
@ -179,7 +180,7 @@ class CrashDump{
$this->addLine("THIS CRASH WAS CAUSED BY A PLUGIN");
$this->data["plugin"] = true;
$reflection = new \ReflectionClass("pocketmine\\plugin\\PluginBase");
$reflection = new \ReflectionClass(PluginBase::class);
$file = $reflection->getProperty("file");
$file->setAccessible(true);
foreach($this->server->getPluginManager()->getPlugins() as $plugin){
@ -228,7 +229,7 @@ class CrashDump{
$this->data["general"]["zend"] = zend_version();
$this->data["general"]["php_os"] = PHP_OS;
$this->data["general"]["os"] = Utils::getOS();
$this->addLine("PocketMine-MP version: " . $version->get(false) . " #" . $version->getNumber() . " [Protocol " . Info::CURRENT_PROTOCOL . "; API " . API_VERSION . "]");
$this->addLine("PocketMine-MP version: " . $version->get(false) . " #" . $version->getBuild() . " [Protocol " . Info::CURRENT_PROTOCOL . "; API " . API_VERSION . "]");
$this->addLine("Git commit: " . GIT_COMMIT);
$this->addLine("uname -a: " . php_uname("a"));
$this->addLine("PHP Version: " . phpversion());

File diff suppressed because it is too large Load Diff

View File

@ -65,18 +65,23 @@ namespace {
}
namespace pocketmine {
use LogLevel;
use pocketmine\utils\Binary;
use pocketmine\utils\MainLogger;
use pocketmine\utils\Utils;
use pocketmine\wizard\Installer;
use raklib\RakLib;
const VERSION = "Alpha_1.4dev";
const API_VERSION = "1.3.0";
const API_VERSION = "1.7.0";
const CODENAME = "絶好(Zekkou)ケーキ(Cake)";
const MINECRAFT_VERSION = "v0.9.5 alpha";
/*
* Startup code. Do not look at it, it may harm you.
* Most of them are hacks to fix date-related bugs, or basic functions used after this
* This is the only non-class based file on this project.
* Enjoy it as much as I did writing it. I don't want to do it again.
*/
if(\Phar::running(true) !== ""){
@define("pocketmine\\PATH", \Phar::running(true) . "/");
}else{
@ -89,56 +94,21 @@ namespace pocketmine {
exit(1);
}
if(!class_exists("SplClassLoader", false)){
require_once(\pocketmine\PATH . "src/spl/SplClassLoader.php");
if(!class_exists("ClassLoader", false)){
require_once(\pocketmine\PATH . "src/spl/ClassLoader.php");
require_once(\pocketmine\PATH . "src/spl/BaseClassLoader.php");
require_once(\pocketmine\PATH . "src/pocketmine/CompatibleClassLoader.php");
}
$autoloader = new \SplClassLoader();
$autoloader->setMode(\SplAutoloader::MODE_DEBUG);
$autoloader->add("pocketmine", [
\pocketmine\PATH . "src"
]);
$autoloader = new CompatibleClassLoader();
$autoloader->addPath(\pocketmine\PATH . "src");
$autoloader->addPath(\pocketmine\PATH . "src" . DIRECTORY_SEPARATOR . "spl");
$autoloader->addPath(\pocketmine\PATH . "src" . DIRECTORY_SEPARATOR . "raklib");
$autoloader->register(true);
if(!class_exists("raklib\\RakLib", false)){
require(\pocketmine\PATH . "src/raklib/raklib/RakLib.php");
}
RakLib::bootstrap($autoloader);
//Startup code. Do not look at it, it can harm you. Most of them are hacks to fix date-related bugs, or basic functions used after this
set_time_limit(0); //Who set it to 30 seconds?!?!
if(ini_get("date.timezone") == ""){ //No Timezone set
date_default_timezone_set("GMT");
if(strpos(" " . strtoupper(php_uname("s")), " WIN") !== false){
$time = time();
$time -= $time % 60;
//TODO: Parse different time & date formats by region. ¬¬ world
//Example: USA
@exec("time.exe /T", $hour);
$i = array_map("intval", explode(":", trim($hour[0])));
@exec("date.exe /T", $date);
$j = array_map("intval", explode(substr($date[0], 2, 1), trim($date[0])));
$offset = round((mktime($i[0], $i[1], 0, $j[1], $j[0], $j[2]) - $time) / 60) * 60;
}else{
@exec("date +%s", $t);
$offset = round((intval(trim($t[0])) - time()) / 60) * 60;
}
$daylight = (int) date("I");
$d = timezone_name_from_abbr("", $offset, $daylight);
@ini_set("date.timezone", $d);
date_default_timezone_set($d);
}else{
$d = @date_default_timezone_get();
if(strpos($d, "/") === false){
$d = timezone_name_from_abbr($d);
@ini_set("date.timezone", $d);
date_default_timezone_set($d);
}
}
gc_enable();
error_reporting(-1);
ini_set("allow_url_fopen", 1);
@ -149,15 +119,170 @@ namespace pocketmine {
ini_set("memory_limit", "256M"); //Default
define("pocketmine\\START_TIME", microtime(true));
$opts = getopt("", array("enable-ansi", "disable-ansi", "data:", "plugins:", "no-wizard"));
$opts = getopt("", ["enable-ansi", "disable-ansi", "data:", "plugins:", "no-wizard", "enable-profiler"]);
define("pocketmine\\DATA", isset($opts["data"]) ? realpath($opts["data"]) . DIRECTORY_SEPARATOR : \getcwd() . DIRECTORY_SEPARATOR);
define("pocketmine\\PLUGIN_PATH", isset($opts["plugins"]) ? realpath($opts["plugins"]) . DIRECTORY_SEPARATOR : \getcwd() . DIRECTORY_SEPARATOR . "plugins" . DIRECTORY_SEPARATOR);
define("pocketmine\\DATA", isset($opts["data"]) ? $opts["data"] . DIRECTORY_SEPARATOR : \getcwd() . DIRECTORY_SEPARATOR);
define("pocketmine\\PLUGIN_PATH", isset($opts["plugins"]) ? $opts["plugins"] . DIRECTORY_SEPARATOR : \getcwd() . DIRECTORY_SEPARATOR . "plugins" . DIRECTORY_SEPARATOR);
define("pocketmine\\ANSI", ((strpos(strtoupper(php_uname("s")), "WIN") === false or isset($opts["enable-ansi"])) and !isset($opts["disable-ansi"])));
define("pocketmine\\ANSI", (Utils::getOS() !== "win" or isset($opts["enable-ansi"])) and !isset($opts["disable-ansi"]));
@mkdir(\pocketmine\DATA, 0777, true);
//Logger has a dependency on timezone, so we'll set it to UTC until we can get the actual timezone.
date_default_timezone_set("UTC");
$logger = new MainLogger(\pocketmine\DATA . "server.log", \pocketmine\ANSI);
if(!ini_get("date.timezone")){
if(($timezone = detect_system_timezone()) and date_default_timezone_set($timezone)){
//Success! Timezone has already been set and validated in the if statement.
//This here is just for redundancy just in case some stupid program wants to read timezone data from the ini.
ini_set("date.timezone", $timezone);
}else{
//If system timezone detection fails or timezone is an invalid value.
if($response = Utils::getURL("http://ip-api.com/json")
and $ip_geolocation_data = json_decode($response, true)
and $ip_geolocation_data['status'] != 'fail'
and date_default_timezone_set($ip_geolocation_data['timezone']))
{
//Again, for redundancy.
ini_set("date.timezone", $ip_geolocation_data['timezone']);
}else{
ini_set("date.timezone", "UTC");
date_default_timezone_set("UTC");
$logger->warning("Timezone could not be automatically determined. An incorrect timezone will result in incorrect timestamps on console logs. It has been set to \"UTC\" by default. You can change it on the php.ini file.");
}
}
}else{
/*
* This is here so that stupid idiots don't come to us complaining and fill up the issue tracker when they put an incorrect timezone abbreviation in php.ini apparently.
*/
$default_timezone = date_default_timezone_get();
if(strpos($default_timezone, "/") === false){
$default_timezone = timezone_name_from_abbr($default_timezone);
ini_set("date.timezone", $default_timezone);
date_default_timezone_set($default_timezone);
}
}
function detect_system_timezone(){
switch(Utils::getOS()){
case 'win':
$regex = '/(?:Time Zone:\s*\()(UTC)(\+*\-*\d*\d*\:*\d*\d*)(?:\))/';
exec("systeminfo", $output);
$string = trim(implode("\n", $output));
//Detect the Time Zone string in systeminfo
preg_match($regex, $string, $matches);
if(!isset($matches[2]))
{
return false;
}
$offset = $matches[2];
if($offset == ""){
return "UTC";
}
return parse_offset($offset);
break;
case 'linux':
// Ubuntu / Debian.
if(file_exists('/etc/timezone')){
$data = file_get_contents('/etc/timezone');
if($data){
return trim($data);
}
}
// RHEL / CentOS
if(file_exists('/etc/sysconfig/clock')){
$data = parse_ini_file('/etc/sysconfig/clock');
if(!empty($data['ZONE'])){
return trim($data['ZONE']);
}
}
//Portable method for incompatible linux distributions.
$offset = trim(exec('date +%:z'));
if($offset == "+00:00"){
return "UTC";
}
return parse_offset($offset);
break;
case 'mac':
if(is_link('/etc/localtime')){
$filename = readlink('/etc/localtime');
if(strpos($filename, '/usr/share/zoneinfo/') === 0){
$timezone = substr($filename, 20);
return trim($timezone);
}
}
return false;
break;
default:
return false;
break;
}
}
/**
* @param string $offset In the format of +09:00, +02:00, -04:00 etc.
* @return string
*/
function parse_offset($offset){
//Make signed offsets unsigned for date_parse
if(strpos($offset, '-') !== false){
$negative_offset = true;
$offset = str_replace('-', '', $offset);
}else{
if(strpos($offset, '+') !== false){
$negative_offset = false;
$offset = str_replace('+', '', $offset);
}else{
return false;
}
}
$parsed = date_parse($offset);
$offset = $parsed['hour'] * 3600 + $parsed['minute'] * 60 + $parsed['second'];
//After date_parse is done, put the sign back
if($negative_offset == true){
$offset = -abs($offset);
}
//And then, look the offset up.
//timezone_name_from_abbr is not used because it returns false on some(most) offsets because it's mapping function is weird.
//That's been a bug in PHP since 2008!
foreach(timezone_abbreviations_list() as $zones){
foreach($zones as $timezone){
if($timezone['offset'] == $offset){
return $timezone['timezone_id'];
}
}
}
return false;
}
if(isset($opts["enable-profiler"])){
if(function_exists("profiler_enable")){
\profiler_enable();
$logger->notice("Execution is being profiled");
}else{
$logger->notice("No profiler found. Please install https://github.com/krakjoe/profiler");
}
}
function kill($pid){
switch(Utils::getOS()){
case "win":
@ -204,59 +329,12 @@ namespace pocketmine {
return rtrim(str_replace(["\\", ".php", "phar://", rtrim(str_replace(["\\", "phar://"], ["/", ""], \pocketmine\PATH), "/"), rtrim(str_replace(["\\", "phar://"], ["/", ""], \pocketmine\PLUGIN_PATH), "/")], ["/", "", "", "", ""], $path), "/");
}
function error_handler($errno, $errstr, $errfile, $errline, $trace = null){
global $lastError;
if(error_reporting() === 0){ //@ error-control
return false;
}
$errorConversion = array(
E_ERROR => "E_ERROR",
E_WARNING => "E_WARNING",
E_PARSE => "E_PARSE",
E_NOTICE => "E_NOTICE",
E_CORE_ERROR => "E_CORE_ERROR",
E_CORE_WARNING => "E_CORE_WARNING",
E_COMPILE_ERROR => "E_COMPILE_ERROR",
E_COMPILE_WARNING => "E_COMPILE_WARNING",
E_USER_ERROR => "E_USER_ERROR",
E_USER_WARNING => "E_USER_WARNING",
E_USER_NOTICE => "E_USER_NOTICE",
E_STRICT => "E_STRICT",
E_RECOVERABLE_ERROR => "E_RECOVERABLE_ERROR",
E_DEPRECATED => "E_DEPRECATED",
E_USER_DEPRECATED => "E_USER_DEPRECATED",
);
$type = ($errno === E_ERROR or $errno === E_WARNING or $errno === E_USER_ERROR or $errno === E_USER_WARNING) ? LogLevel::ERROR : LogLevel::NOTICE;
$errno = isset($errorConversion[$errno]) ? $errorConversion[$errno] : $errno;
if(($pos = strpos($errstr, "\n")) !== false){
$errstr = substr($errstr, 0, $pos);
}
$logger = MainLogger::getLogger();
$oldFile = $errfile;
$errfile = cleanPath($errfile);
$logger->log($type, "An $errno error happened: \"$errstr\" in \"$errfile\" at line $errline");
foreach(($trace = getTrace($trace === null ? 3 : 0, $trace)) as $i => $line){
$logger->debug($line);
}
$lastError = [
"type" => $type,
"message" => $errstr,
"fullFile" => $oldFile,
"file" => $errfile,
"line" => $errline,
"trace" => $trace
];
return true;
}
set_error_handler("\\pocketmine\\error_handler", E_ALL);
set_error_handler([\ExceptionHandler::class, "handler"], -1);
$errors = 0;
if(version_compare("5.4.0", PHP_VERSION) > 0){
$logger->critical("Use PHP >= 5.4.0");
if(version_compare("5.6.0", PHP_VERSION) > 0){
$logger->critical("You must use PHP >= 5.6");
++$errors;
}
@ -274,8 +352,8 @@ namespace pocketmine {
if(substr_count($pthreads_version, ".") < 2){
$pthreads_version = "0.$pthreads_version";
}
if(version_compare($pthreads_version, "2.0.4") < 0){
$logger->critical("pthreads >= 2.0.4 is required, while you have $pthreads_version.");
if(version_compare($pthreads_version, "2.0.8") < 0){
$logger->critical("pthreads >= 2.0.8 is required, while you have $pthreads_version.");
++$errors;
}
@ -353,14 +431,14 @@ namespace pocketmine {
$logger->debug("Stopping " . (new \ReflectionClass($thread))->getShortName() . " thread");
if($thread instanceof Thread){
$thread->kill();
if($thread->isRunning() or !$thread->join()){
sleep(1);
if($thread->isRunning()){
$thread->detach();
}
}elseif($thread instanceof Worker){
$thread->kill();
sleep(1);
if($thread->isRunning() or !$thread->join()){
if($thread->isRunning()){
$thread->detach();
}
}

File diff suppressed because it is too large Load Diff

View File

@ -29,6 +29,6 @@ abstract class Thread extends \Thread{
public final function start($options = PTHREADS_INHERIT_ALL){
ThreadManager::getInstance()->add($this);
return parent::start($options & ~PTHREADS_INHERIT_CLASSES);
return parent::start($options);
}
}

View File

@ -29,6 +29,6 @@ abstract class Worker extends \Worker{
public final function start($options = PTHREADS_INHERIT_ALL){
ThreadManager::getInstance()->add($this);
return parent::start($options & ~PTHREADS_INHERIT_CLASSES);
return parent::start($options);
}
}

View File

@ -29,8 +29,8 @@ class AcaciaWoodStairs extends Stair{
}
public function getDrops(Item $item){
return array(
array($this->id, 0, 1),
);
return [
[$this->id, 0, 1],
];
}
}

View File

@ -21,30 +21,31 @@
namespace pocketmine\block;
use pocketmine\math\AxisAlignedBB;
/**
* Air block
*/
class Air extends Transparent{
public $isActivable = false;
public $breakable = false;
public $isFlowable = true;
public $isTransparent = true;
public $isReplaceable = true;
public $isPlaceable = false;
public $hasPhysics = false;
public $isSolid = false;
public $isFullBlock = true;
protected $id = self::AIR;
protected $meta = 0;
protected $name = "Air";
protected $hardness = 0;
public function __construct(){
parent::__construct(self::AIR, 0, "Air");
$this->isActivable = false;
$this->breakable = false;
$this->isFlowable = true;
$this->isTransparent = true;
$this->isReplaceable = true;
$this->isPlaceable = false;
$this->hasPhysics = false;
$this->isSolid = false;
$this->isFullBlock = true;
$this->hardness = 0;
}
public function getBoundingBox(){
return new AxisAlignedBB(0, 0, 0, 0, 0, 0);
return null;
}
}

View File

@ -22,6 +22,8 @@
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\level\Level;
use pocketmine\math\AxisAlignedBB;
use pocketmine\network\protocol\ChatPacket;
use pocketmine\Player;
@ -33,14 +35,30 @@ class Bed extends Transparent{
$this->hardness = 1;
}
protected function recalculateBoundingBox(){
return new AxisAlignedBB(
$this->x,
$this->y,
$this->z,
$this->x + 1,
$this->y + 0.5625,
$this->z + 1
);
}
public function onActivate(Item $item, Player $player = null){
/*if($player instanceof Player and Server::getInstance()->api->time->getPhase($this->getLevel()) !== "night"){
$pk = new ChatPacket;
$time = $this->getLevel()->getTime() % Level::TIME_FULL;
$isNight = ($time >= Level::TIME_NIGHT and $time < Level::TIME_SUNRISE);
if($player instanceof Player and !$isNight){
$pk = new ChatPacket();
$pk->message = "You can only sleep at night";
$player->dataPacket($pk);
return true;
}*/
}
$blockNorth = $this->getSide(2); //Gets the blocks around them
$blockSouth = $this->getSide(3);
@ -57,17 +75,19 @@ class Bed extends Transparent{
$b = $blockEast;
}elseif($blockWest->getID() === $this->id and ($blockWest->meta & 0x08) === 0x08){
$b = $blockWest;
}elseif($player instanceof Player){
$pk = new ChatPacket;
$pk->message = "This bed is incomplete";
$player->dataPacket($pk);
}else{
if($player instanceof Player){
$pk = new ChatPacket();
$pk->message = "This bed is incomplete";
$player->dataPacket($pk);
}
return true;
}
}
if($player instanceof Player and $player->sleepOn($b) === false){
$pk = new ChatPacket;
$pk = new ChatPacket();
$pk->message = "This bed is occupied";
$player->dataPacket($pk);
}
@ -78,19 +98,19 @@ class Bed extends Transparent{
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
$down = $this->getSide(0);
if($down->isTransparent === false){
$faces = array(
$faces = [
0 => 3,
1 => 4,
2 => 2,
3 => 5,
);
];
$d = $player instanceof Player ? $player->getDirection() : 0;
$next = $this->getSide($faces[(($d + 3) % 4)]);
$downNext = $this->getSide(0);
if($next->isReplaceable === true and $downNext->isTransparent === false){
$meta = (($d + 3) % 4) & 0x03;
$this->getLevel()->setBlock($block, Block::get($this->id, $meta), true, false, true);
$this->getLevel()->setBlock($next, Block::get($this->id, $meta | 0x08), true, false, true);
$this->getLevel()->setBlock($block, Block::get($this->id, $meta), true, true);
$this->getLevel()->setBlock($next, Block::get($this->id, $meta | 0x08), true, true);
return true;
}
@ -107,34 +127,34 @@ class Bed extends Transparent{
if(($this->meta & 0x08) === 0x08){ //This is the Top part of bed
if($blockNorth->getID() === $this->id and $blockNorth->meta !== 0x08){ //Checks if the block ID and meta are right
$this->getLevel()->setBlock($blockNorth, new Air(), true, false, true);
$this->getLevel()->setBlock($blockNorth, new Air(), true, true);
}elseif($blockSouth->getID() === $this->id and $blockSouth->meta !== 0x08){
$this->getLevel()->setBlock($blockSouth, new Air(), true, false, true);
$this->getLevel()->setBlock($blockSouth, new Air(), true, true);
}elseif($blockEast->getID() === $this->id and $blockEast->meta !== 0x08){
$this->getLevel()->setBlock($blockEast, new Air(), true, false, true);
$this->getLevel()->setBlock($blockEast, new Air(), true, true);
}elseif($blockWest->getID() === $this->id and $blockWest->meta !== 0x08){
$this->getLevel()->setBlock($blockWest, new Air(), true, false, true);
$this->getLevel()->setBlock($blockWest, new Air(), true, true);
}
}else{ //Bottom Part of Bed
if($blockNorth->getID() === $this->id and ($blockNorth->meta & 0x08) === 0x08){
$this->getLevel()->setBlock($blockNorth, new Air(), true, false, true);
$this->getLevel()->setBlock($blockNorth, new Air(), true, true);
}elseif($blockSouth->getID() === $this->id and ($blockSouth->meta & 0x08) === 0x08){
$this->getLevel()->setBlock($blockSouth, new Air(), true, false, true);
$this->getLevel()->setBlock($blockSouth, new Air(), true, true);
}elseif($blockEast->getID() === $this->id and ($blockEast->meta & 0x08) === 0x08){
$this->getLevel()->setBlock($blockEast, new Air(), true, false, true);
$this->getLevel()->setBlock($blockEast, new Air(), true, true);
}elseif($blockWest->getID() === $this->id and ($blockWest->meta & 0x08) === 0x08){
$this->getLevel()->setBlock($blockWest, new Air(), true, false, true);
$this->getLevel()->setBlock($blockWest, new Air(), true, true);
}
}
$this->getLevel()->setBlock($this, new Air(), true, false, true);
$this->getLevel()->setBlock($this, new Air(), true, true);
return true;
}
public function getDrops(Item $item){
return array(
array(Item::BED, 0, 1),
);
return [
[Item::BED, 0, 1],
];
}
}

View File

@ -22,70 +22,19 @@
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\level\Level;
use pocketmine\Player;
class Beetroot extends Flowable{
class Beetroot extends Crops{
public function __construct($meta = 0){
parent::__construct(self::BEETROOT_BLOCK, $meta, "Beetroot Block");
$this->isActivable = true;
$this->hardness = 0;
}
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
$down = $this->getSide(0);
if($down->getID() === self::FARMLAND){
$this->getLevel()->setBlock($block, $this, true, false, true);
return true;
}
return false;
}
public function onActivate(Item $item, Player $player = null){
if($item->getID() === Item::DYE and $item->getDamage() === 0x0F){ //Bonemeal
$this->meta = 0x07;
$this->getLevel()->setBlock($this, $this, true, false, true);
$item->count--;
return true;
}
return false;
}
public function onUpdate($type){
if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //TODO: Replace with common break method
$this->getLevel()->dropItem($this, Item::get(Item::BEETROOT_SEEDS, 0, 1));
$this->getLevel()->setBlock($this, new Air(), false, false, true);
return Level::BLOCK_UPDATE_NORMAL;
}
}elseif($type === Level::BLOCK_UPDATE_RANDOM){
if(mt_rand(0, 2) == 1){
if($this->meta < 0x07){
++$this->meta;
$this->getLevel()->setBlock($this, $this, true, false, true);
return Level::BLOCK_UPDATE_RANDOM;
}
}else{
return Level::BLOCK_UPDATE_RANDOM;
}
}
return false;
}
public function getDrops(Item $item){
$drops = [];
if($this->meta >= 0x07){
$drops[] = array(Item::BEETROOT, 0, 1);
$drops[] = array(Item::BEETROOT_SEEDS, 0, mt_rand(0, 3));
$drops[] = [Item::BEETROOT, 0, 1];
$drops[] = [Item::BEETROOT_SEEDS, 0, mt_rand(0, 3)];
}else{
$drops[] = array(Item::BEETROOT_SEEDS, 0, 1);
$drops[] = [Item::BEETROOT_SEEDS, 0, 1];
}
return $drops;

View File

@ -29,8 +29,8 @@ class BirchWoodStairs extends Stair{
}
public function getDrops(Item $item){
return array(
array($this->id, 0, 1),
);
return [
[$this->id, 0, 1],
];
}
}

View File

@ -24,19 +24,22 @@
*/
namespace pocketmine\block;
use pocketmine\entity\Entity;
use pocketmine\entity\Villager;
use pocketmine\entity\Zombie;
use pocketmine\item\Item;
use pocketmine\level\Level;
use pocketmine\level\MovingObjectPosition;
use pocketmine\level\Position;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Vector3;
use pocketmine\metadata\Metadatable;
use pocketmine\metadata\MetadataValue;
use pocketmine\Player;
use pocketmine\plugin\Plugin;
abstract class Block extends Position implements Metadatable{
class Block extends Position implements Metadatable{
const AIR = 0;
const STONE = 1;
const GRASS = 2;
@ -164,7 +167,8 @@ abstract class Block extends Position implements Metadatable{
const MELON_BLOCK = 103;
const PUMPKIN_STEM = 104;
const MELON_STEM = 105;
const VINE = 106;
const VINES = 106;
const FENCE_GATE = 107;
const BRICK_STAIRS = 108;
const STONE_BRICK_STAIRS = 109;
@ -230,7 +234,7 @@ abstract class Block extends Position implements Metadatable{
const GLOWING_OBSIDIAN = 246;
const NETHER_REACTOR = 247;
public static $creative = array(
public static $creative = [
//Building
[Item::COBBLESTONE, 0],
[Item::STONE_BRICKS, 0],
@ -342,7 +346,7 @@ abstract class Block extends Position implements Metadatable{
[Item::SNOW_LAYER, 0],
[Item::GLASS, 0],
[Item::GLOWSTONE_BLOCK, 0],
//TODO: Vines
[Item::VINES, 0],
[Item::NETHER_REACTOR, 0],
[Item::LADDER, 0],
[Item::SPONGE, 0],
@ -359,7 +363,6 @@ abstract class Block extends Position implements Metadatable{
[Item::STONECUTTER, 0],
[Item::CHEST, 0],
[Item::FURNACE, 0],
//TODO: End Portal
[Item::END_PORTAL, 0],
[Item::DANDELION, 0],
[Item::POPPY, 0],
@ -500,15 +503,16 @@ abstract class Block extends Position implements Metadatable{
[Item::DYE, 9],
[Item::DYE, 8],
);
];
/** @var Block[] */
public static $list = [];
/** @var \SplFixedArray */
public static $list = null;
protected $id;
protected $meta;
protected $name;
protected $breakTime;
protected $hardness;
protected $name = "Unknown";
protected $breakTime = 0.20;
protected $hardness = 10;
public $hasEntityCollision = false;
public $isActivable = false;
public $breakable = true;
public $isFlowable = false;
@ -524,146 +528,149 @@ abstract class Block extends Position implements Metadatable{
public $z = 0;
public $frictionFactor = 0.6;
/** @var AxisAlignedBB */
protected $boundingBox = null;
public static function init(){
if(count(self::$list) === 0){
self::$list = array(
self::AIR => new Air(),
self::STONE => new Stone(),
self::GRASS => new Grass(),
self::DIRT => new Dirt(),
self::COBBLESTONE => new Cobblestone(),
self::PLANKS => new Planks(),
self::SAPLING => new Sapling(),
self::BEDROCK => new Bedrock(),
self::WATER => new Water(),
self::STILL_WATER => new StillWater(),
self::LAVA => new Lava(),
self::STILL_LAVA => new StillLava(),
self::SAND => new Sand(),
self::GRAVEL => new Gravel(),
self::GOLD_ORE => new GoldOre(),
self::IRON_ORE => new IronOre(),
self::COAL_ORE => new CoalOre(),
self::WOOD => new Wood(),
self::LEAVES => new Leaves(),
self::SPONGE => new Sponge(),
self::GLASS => new Glass(),
self::LAPIS_ORE => new LapisOre(),
self::LAPIS_BLOCK => new Lapis(),
self::SANDSTONE => new Sandstone(),
self::BED_BLOCK => new Bed(),
self::COBWEB => new Cobweb(),
self::TALL_GRASS => new TallGrass(),
self::DEAD_BUSH => new DeadBush(),
self::WOOL => new Wool(),
self::DANDELION => new Dandelion(),
self::POPPY => new CyanFlower(),
self::BROWN_MUSHROOM => new BrownMushroom(),
self::RED_MUSHROOM => new RedMushroom(),
self::GOLD_BLOCK => new Gold(),
self::IRON_BLOCK => new Iron(),
self::DOUBLE_SLAB => new DoubleSlab(),
self::SLAB => new Slab(),
self::BRICKS_BLOCK => new Bricks(),
self::TNT => new TNT(),
self::BOOKSHELF => new Bookshelf(),
self::MOSS_STONE => new MossStone(),
self::OBSIDIAN => new Obsidian(),
self::TORCH => new Torch(),
self::FIRE => new Fire(),
self::MONSTER_SPAWNER => new MonsterSpawner(),
self::WOOD_STAIRS => new WoodStairs(),
self::CHEST => new Chest(),
if(self::$list === null){
self::$list = new \SplFixedArray(256);
self::$list[self::AIR] = Air::class;;
self::$list[self::STONE] = Stone::class;;
self::$list[self::GRASS] = Grass::class;;
self::$list[self::DIRT] = Dirt::class;;
self::$list[self::COBBLESTONE] = Cobblestone::class;;
self::$list[self::PLANKS] = Planks::class;;
self::$list[self::SAPLING] = Sapling::class;;
self::$list[self::BEDROCK] = Bedrock::class;;
self::$list[self::WATER] = Water::class;;
self::$list[self::STILL_WATER] = StillWater::class;;
self::$list[self::LAVA] = Lava::class;;
self::$list[self::STILL_LAVA] = StillLava::class;;
self::$list[self::SAND] = Sand::class;;
self::$list[self::GRAVEL] = Gravel::class;;
self::$list[self::GOLD_ORE] = GoldOre::class;;
self::$list[self::IRON_ORE] = IronOre::class;;
self::$list[self::COAL_ORE] = CoalOre::class;;
self::$list[self::WOOD] = Wood::class;;
self::$list[self::LEAVES] = Leaves::class;;
self::$list[self::SPONGE] = Sponge::class;;
self::$list[self::GLASS] = Glass::class;;
self::$list[self::LAPIS_ORE] = LapisOre::class;;
self::$list[self::LAPIS_BLOCK] = Lapis::class;;
self::$list[self::SANDSTONE] = Sandstone::class;;
self::$list[self::BED_BLOCK] = Bed::class;;
self::$list[self::COBWEB] = Cobweb::class;;
self::$list[self::TALL_GRASS] = TallGrass::class;;
self::$list[self::DEAD_BUSH] = DeadBush::class;;
self::$list[self::WOOL] = Wool::class;;
self::$list[self::DANDELION] = Dandelion::class;;
self::$list[self::POPPY] = CyanFlower::class;;
self::$list[self::BROWN_MUSHROOM] = BrownMushroom::class;;
self::$list[self::RED_MUSHROOM] = RedMushroom::class;;
self::$list[self::GOLD_BLOCK] = Gold::class;;
self::$list[self::IRON_BLOCK] = Iron::class;;
self::$list[self::DOUBLE_SLAB] = DoubleSlab::class;;
self::$list[self::SLAB] = Slab::class;;
self::$list[self::BRICKS_BLOCK] = Bricks::class;;
self::$list[self::TNT] = TNT::class;;
self::$list[self::BOOKSHELF] = Bookshelf::class;;
self::$list[self::MOSS_STONE] = MossStone::class;;
self::$list[self::OBSIDIAN] = Obsidian::class;;
self::$list[self::TORCH] = Torch::class;;
self::$list[self::FIRE] = Fire::class;;
self::$list[self::MONSTER_SPAWNER] = MonsterSpawner::class;;
self::$list[self::WOOD_STAIRS] = WoodStairs::class;;
self::$list[self::CHEST] = Chest::class;;
self::DIAMOND_ORE => new DiamondOre(),
self::DIAMOND_BLOCK => new Diamond(),
self::WORKBENCH => new Workbench(),
self::WHEAT_BLOCK => new Wheat(),
self::FARMLAND => new Farmland(),
self::FURNACE => new Furnace(),
self::BURNING_FURNACE => new BurningFurnace(),
self::SIGN_POST => new SignPost(),
self::WOOD_DOOR_BLOCK => new WoodDoor(),
self::LADDER => new Ladder(),
self::$list[self::DIAMOND_ORE] = DiamondOre::class;;
self::$list[self::DIAMOND_BLOCK] = Diamond::class;;
self::$list[self::WORKBENCH] = Workbench::class;;
self::$list[self::WHEAT_BLOCK] = Wheat::class;;
self::$list[self::FARMLAND] = Farmland::class;;
self::$list[self::FURNACE] = Furnace::class;;
self::$list[self::BURNING_FURNACE] = BurningFurnace::class;;
self::$list[self::SIGN_POST] = SignPost::class;;
self::$list[self::WOOD_DOOR_BLOCK] = WoodDoor::class;;
self::$list[self::LADDER] = Ladder::class;;
self::COBBLESTONE_STAIRS => new CobblestoneStairs(),
self::WALL_SIGN => new WallSign(),
self::$list[self::COBBLESTONE_STAIRS] = CobblestoneStairs::class;;
self::$list[self::WALL_SIGN] = WallSign::class;;
self::IRON_DOOR_BLOCK => new IronDoor(),
self::REDSTONE_ORE => new RedstoneOre(),
self::GLOWING_REDSTONE_ORE => new GlowingRedstoneOre(),
self::$list[self::IRON_DOOR_BLOCK] = IronDoor::class;;
self::$list[self::REDSTONE_ORE] = RedstoneOre::class;;
self::$list[self::GLOWING_REDSTONE_ORE] = GlowingRedstoneOre::class;;
self::SNOW_LAYER => new SnowLayer(),
self::ICE => new Ice(),
self::SNOW_BLOCK => new Snow(),
self::CACTUS => new Cactus(),
self::CLAY_BLOCK => new Clay(),
self::SUGARCANE_BLOCK => new Sugarcane(),
self::$list[self::SNOW_LAYER] = SnowLayer::class;;
self::$list[self::ICE] = Ice::class;;
self::$list[self::SNOW_BLOCK] = Snow::class;;
self::$list[self::CACTUS] = Cactus::class;;
self::$list[self::CLAY_BLOCK] = Clay::class;;
self::$list[self::SUGARCANE_BLOCK] = Sugarcane::class;;
self::FENCE => new Fence(),
self::PUMPKIN => new Pumpkin(),
self::NETHERRACK => new Netherrack(),
self::SOUL_SAND => new SoulSand(),
self::GLOWSTONE_BLOCK => new Glowstone(),
self::$list[self::FENCE] = Fence::class;;
self::$list[self::PUMPKIN] = Pumpkin::class;;
self::$list[self::NETHERRACK] = Netherrack::class;;
self::$list[self::SOUL_SAND] = SoulSand::class;;
self::$list[self::GLOWSTONE_BLOCK] = Glowstone::class;;
self::LIT_PUMPKIN => new LitPumpkin(),
self::CAKE_BLOCK => new Cake(),
self::$list[self::LIT_PUMPKIN] = LitPumpkin::class;;
self::$list[self::CAKE_BLOCK] = Cake::class;;
self::TRAPDOOR => new Trapdoor(),
self::$list[self::TRAPDOOR] = Trapdoor::class;;
self::STONE_BRICKS => new StoneBricks(),
self::$list[self::STONE_BRICKS] = StoneBricks::class;;
self::IRON_BARS => new IronBars(),
self::GLASS_PANE => new GlassPane(),
self::MELON_BLOCK => new Melon(),
self::PUMPKIN_STEM => new PumpkinStem(),
self::MELON_STEM => new MelonStem(),
self::$list[self::IRON_BARS] = IronBars::class;;
self::$list[self::GLASS_PANE] = GlassPane::class;;
self::$list[self::MELON_BLOCK] = Melon::class;;
self::$list[self::PUMPKIN_STEM] = PumpkinStem::class;;
self::$list[self::MELON_STEM] = MelonStem::class;;
self::$list[self::VINE] = Vine::class;;
self::$list[self::FENCE_GATE] = FenceGate::class;;
self::$list[self::BRICK_STAIRS] = BrickStairs::class;;
self::$list[self::STONE_BRICK_STAIRS] = StoneBrickStairs::class;;
self::FENCE_GATE => new FenceGate(),
self::BRICK_STAIRS => new BrickStairs(),
self::STONE_BRICK_STAIRS => new StoneBrickStairs(),
self::$list[self::MYCELIUM] = Mycelium::class;;
self::$list[self::NETHER_BRICKS] = NetherBrick::class;;
self::MYCELIUM => new Mycelium(),
self::NETHER_BRICKS => new NetherBrick(),
self::$list[self::NETHER_BRICKS_STAIRS] = NetherBrickStairs::class;;
self::NETHER_BRICKS_STAIRS => new NetherBrickStairs(),
self::$list[self::END_PORTAL] = EndPortal::class;;
self::$list[self::END_STONE] = EndStone::class;;
self::$list[self::SANDSTONE_STAIRS] = SandstoneStairs::class;;
self::$list[self::EMERALD_ORE] = EmeraldOre::class;;
self::END_PORTAL => new EndPortal(),
self::END_STONE => new EndStone(),
self::SANDSTONE_STAIRS => new SandstoneStairs(),
self::EMERALD_ORE => new EmeraldOre(),
self::$list[self::EMERALD_BLOCK] = Emerald::class;;
self::$list[self::SPRUCE_WOOD_STAIRS] = SpruceWoodStairs::class;;
self::$list[self::BIRCH_WOOD_STAIRS] = BirchWoodStairs::class;;
self::$list[self::JUNGLE_WOOD_STAIRS] = JungleWoodStairs::class;;
self::$list[self::STONE_WALL] = StoneWall::class;;
self::EMERALD_BLOCK => new Emerald(),
self::SPRUCE_WOOD_STAIRS => new SpruceWoodStairs(),
self::BIRCH_WOOD_STAIRS => new BirchWoodStairs(),
self::JUNGLE_WOOD_STAIRS => new JungleWoodStairs(),
self::STONE_WALL => new StoneWall(),
self::$list[self::CARROT_BLOCK] = Carrot::class;;
self::$list[self::POTATO_BLOCK] = Potato::class;;
self::CARROT_BLOCK => new Carrot(),
self::POTATO_BLOCK => new Potato(),
self::$list[self::QUARTZ_BLOCK] = Quartz::class;;
self::$list[self::QUARTZ_STAIRS] = QuartzStairs::class;;
self::$list[self::DOUBLE_WOOD_SLAB] = DoubleWoodSlab::class;;
self::$list[self::WOOD_SLAB] = WoodSlab::class;;
self::$list[self::STAINED_CLAY] = StainedClay::class;;
self::QUARTZ_BLOCK => new Quartz(),
self::QUARTZ_STAIRS => new QuartzStairs(),
self::DOUBLE_WOOD_SLAB => new DoubleWoodSlab(),
self::WOOD_SLAB => new WoodSlab(),
self::STAINED_CLAY => new StainedClay(),
self::$list[self::LEAVES2] = Leaves2::class;;
self::$list[self::WOOD2] = Wood2::class;;
self::$list[self::ACACIA_WOOD_STAIRS] = AcaciaWoodStairs::class;;
self::$list[self::DARK_OAK_WOOD_STAIRS] = DarkOakWoodStairs::class;;
self::LEAVES2 => new Leaves2(),
self::WOOD2 => new Wood2(),
self::ACACIA_WOOD_STAIRS => new AcaciaWoodStairs(),
self::DARK_OAK_WOOD_STAIRS => new DarkOakWoodStairs(),
self::$list[self::HAY_BALE] = HayBale::class;;
self::$list[self::CARPET] = Carpet::class;;
self::$list[self::HARDENED_CLAY] = HardenedClay::class;;
self::$list[self::COAL_BLOCK] = Coal::class;;
self::HAY_BALE => new HayBale(),
self::CARPET => new Carpet(),
self::HARDENED_CLAY => new HardenedClay(),
self::COAL_BLOCK => new Coal(),
self::$list[self::PODZOL] = Podzol::class;;
self::$list[self::BEETROOT_BLOCK] = Beetroot::class;;
self::$list[self::STONECUTTER] = Stonecutter::class;;
self::$list[self::GLOWING_OBSIDIAN] = GlowingObsidian::class;;
self::$list[self::NETHER_REACTOR] = NetherReactor::class;;
self::PODZOL => new Podzol(),
self::BEETROOT_BLOCK => new Beetroot(),
self::STONECUTTER => new Stonecutter(),
self::GLOWING_OBSIDIAN => new GlowingObsidian(),
self::NETHER_REACTOR => new NetherReactor(),
);
}
}
@ -675,14 +682,22 @@ abstract class Block extends Position implements Metadatable{
* @return Block
*/
public static function get($id, $meta = 0, Position $pos = null){
if(isset(self::$list[$id])){
$block = clone self::$list[$id];
$block->setDamage($meta);
}else{
$block = new Generic($id, $meta);
try{
$block = self::$list[$id];
if($block !== null){
$block = new $block($meta);
}else{
$block = new Block($id, $meta);
}
}catch(\RuntimeException $e){
$block = new Block($id, $meta);
}
if($pos instanceof Position){
$block->position($pos);
if($pos !== null){
$block->x = $pos->x;
$block->y = $pos->y;
$block->z = $pos->z;
$block->level = $pos->level;
}
return $block;
@ -697,8 +712,69 @@ abstract class Block extends Position implements Metadatable{
$this->id = (int) $id;
$this->meta = (int) $meta;
$this->name = $name;
$this->breakTime = 0.20;
$this->hardness = 10;
}
/**
* Places the Block, using block space and block target, and side. Returns if the block has been placed.
*
* @param Item $item
* @param Block $block
* @param Block $target
* @param int $face
* @param float $fx
* @param float $fy
* @param float $fz
* @param Player $player = null
*
* @return bool
*/
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
return $this->getLevel()->setBlock($this, $this, true, true);
}
/**
* Returns if the item can be broken with an specific Item
*
* @param Item $item
*
* @return bool
*/
public function isBreakable(Item $item){
return $this->breakable;
}
/**
* Do the actions needed so the block is broken with the Item
*
* @param Item $item
*
* @return mixed
*/
public function onBreak(Item $item){
return $this->getLevel()->setBlock($this, new Air(), true, true);
}
/**
* Fires a block update on the Block
*
* @param int $type
*
* @return void
*/
public function onUpdate($type){
}
/**
* Do actions when activated by Item. Returns if it has done anything
*
* @param Item $item
* @param Player $player
*
* @return bool
*/
public function onActivate(Item $item, Player $player = null){
return $this->isActivable;
}
/**
@ -718,10 +794,14 @@ abstract class Block extends Position implements Metadatable{
/**
* @return int
*/
final public function getID(){
final public function getId(){
return $this->id;
}
public function addVelocityToEntity(Entity $entity, Vector3 $vector){
}
/**
* @return int
*/
@ -760,7 +840,7 @@ abstract class Block extends Position implements Metadatable{
return [];
}else{
return [
array($this->id, $this->meta, 1),
[$this->id, $this->meta, 1],
];
}
}
@ -800,41 +880,41 @@ abstract class Block extends Position implements Metadatable{
return "Block " . $this->name . " (" . $this->id . ":" . $this->meta . ")";
}
/**
* Returns if the item can be broken with an specific Item
*
* @param Item $item
*
* @return bool
*/
abstract function isBreakable(Item $item);
/**
* Do the actions needed so the block is broken with the Item
*
* @param Item $item
*
* @return mixed
*/
abstract function onBreak(Item $item);
/**
* Checks for collision against an AxisAlignedBB
*
* @param AxisAlignedBB $bb
* @param Block[] $list
*/
public function collidesWithBB(AxisAlignedBB $bb, &$list = array()){
public function collidesWithBB(AxisAlignedBB $bb, &$list = []){
$bb2 = $this->getBoundingBox();
if($bb2->intersectsWith($bb)){
if($bb2 !== null and $bb2->intersectsWith($bb)){
$list[] = $bb2;
}
}
/**
* @param Entity $entity
*/
public function onEntityCollide(Entity $entity){
}
/**
* @return AxisAlignedBB
*/
public function getBoundingBox(){
if($this->boundingBox !== null){
return $this->boundingBox;
}else{
return $this->boundingBox = $this->recalculateBoundingBox();
}
}
/**
* @return AxisAlignedBB
*/
protected function recalculateBoundingBox(){
return new AxisAlignedBB(
$this->x,
$this->y,
@ -845,40 +925,87 @@ abstract class Block extends Position implements Metadatable{
);
}
/**
* Places the Block, using block space and block target, and side. Returns if the block has been placed.
*
* @param Item $item
* @param Block $block
* @param Block $target
* @param int $face
* @param float $fx
* @param float $fy
* @param float $fz
* @param Player $player = null
*
* @return bool
*/
abstract function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null);
public function calculateIntercept(Vector3 $pos1, Vector3 $pos2){
$bb = $this->getBoundingBox();
if($bb === null){
return null;
}
/**
* Do actions when activated by Item. Returns if it has done anything
*
* @param Item $item
* @param Player $player
*
* @return bool
*/
abstract function onActivate(Item $item, Player $player = null);
$v1 = $pos1->getIntermediateWithXValue($pos2, $bb->minX);
$v2 = $pos1->getIntermediateWithXValue($pos2, $bb->maxX);
$v3 = $pos1->getIntermediateWithYValue($pos2, $bb->minY);
$v4 = $pos1->getIntermediateWithYValue($pos2, $bb->maxY);
$v5 = $pos1->getIntermediateWithZValue($pos2, $bb->minZ);
$v6 = $pos1->getIntermediateWithZValue($pos2, $bb->maxZ);
/**
* Fires a block update on the Block
*
* @param int $type
*
* @return void
*/
abstract function onUpdate($type);
if($v1 !== null and !$bb->isVectorInYZ($v1)){
$v1 = null;
}
if($v2 !== null and !$bb->isVectorInYZ($v2)){
$v2 = null;
}
if($v3 !== null and !$bb->isVectorInXZ($v3)){
$v3 = null;
}
if($v4 !== null and !$bb->isVectorInXZ($v4)){
$v4 = null;
}
if($v5 !== null and !$bb->isVectorInXY($v5)){
$v5 = null;
}
if($v6 !== null and !$bb->isVectorInXY($v6)){
$v6 = null;
}
$vector = $v1;
if($v2 !== null and ($vector === null or $pos1->distanceSquared($v2) < $pos1->distanceSquared($vector))){
$vector = $v2;
}
if($v3 !== null and ($vector === null or $pos1->distanceSquared($v3) < $pos1->distanceSquared($vector))){
$vector = $v3;
}
if($v4 !== null and ($vector === null or $pos1->distanceSquared($v4) < $pos1->distanceSquared($vector))){
$vector = $v4;
}
if($v5 !== null and ($vector === null or $pos1->distanceSquared($v5) < $pos1->distanceSquared($vector))){
$vector = $v5;
}
if($v6 !== null and ($vector === null or $pos1->distanceSquared($v6) < $pos1->distanceSquared($vector))){
$vector = $v6;
}
if($vector === null){
return null;
}
$f = -1;
if($vector === $v1){
$f = 4;
}elseif($vector === $v2){
$f = 5;
}elseif($vector === $v3){
$f = 0;
}elseif($vector === $v4){
$f = 1;
}elseif($vector === $v5){
$f = 2;
}elseif($vector === $v6){
$f = 3;
}
return MovingObjectPosition::fromBlock($this->x, $this->y, $this->z, $f, $vector->add($this->x, $this->y, $this->z));
}
public function setMetadata($metadataKey, MetadataValue $metadataValue){
if($this->getLevel() instanceof Level){

View File

@ -48,9 +48,9 @@ class Bricks extends Solid{
public function getDrops(Item $item){
if($item->isPickaxe() >= 1){
return array(
array(Item::BRICKS_BLOCK, 0, 1),
);
return [
[Item::BRICKS_BLOCK, 0, 1],
];
}else{
return [];
}

View File

@ -33,9 +33,8 @@ class BrownMushroom extends Flowable{
public function onUpdate($type){
if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
$this->getLevel()->dropItem($this, Item::get($this->id));
$this->getLevel()->setBlock($this, new Air(), false, false, true);
if($this->getSide(0)->isTransparent === true){
$this->getLevel()->useBreakOn($this);
return Level::BLOCK_UPDATE_NORMAL;
}
@ -47,11 +46,16 @@ class BrownMushroom extends Flowable{
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
$down = $this->getSide(0);
if($down->isTransparent === false){
$this->getLevel()->setBlock($block, $this, true, false, true);
$this->getLevel()->setBlock($block, $this, true, true);
return true;
}
return false;
}
public function getBoundingBox(){
return null;
}
}

View File

@ -39,29 +39,29 @@ class BurningFurnace extends Solid{
}
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
$faces = array(
$faces = [
0 => 4,
1 => 2,
2 => 5,
3 => 3,
);
];
$this->meta = $faces[$player instanceof Player ? $player->getDirection() : 0];
$this->getLevel()->setBlock($block, $this, true, false, true);
$nbt = new Compound(false, array(
$this->getLevel()->setBlock($block, $this, true, true);
$nbt = new Compound(false, [
new Enum("Items", []),
new String("id", Tile::FURNACE),
new Int("x", $this->x),
new Int("y", $this->y),
new Int("z", $this->z)
));
]);
$nbt->Items->setTagType(NBT::TAG_Compound);
new Furnace($this->getLevel()->getChunkAt($this->x >> 4, $this->z >> 4), $nbt);
Tile::createTile("Furnace", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt);
return true;
}
public function onBreak(Item $item){
$this->getLevel()->setBlock($this, new Air(), true, true, true);
$this->getLevel()->setBlock($this, new Air(), true, true);
return true;
}
@ -73,15 +73,15 @@ class BurningFurnace extends Solid{
if($t instanceof Furnace){
$furnace = $t;
}else{
$nbt = new Compound(false, array(
$nbt = new Compound(false, [
new Enum("Items", []),
new String("id", Tile::FURNACE),
new Int("x", $this->x),
new Int("y", $this->y),
new Int("z", $this->z)
));
]);
$nbt->Items->setTagType(NBT::TAG_Compound);
$furnace = new Furnace($this->getLevel()->getChunkAt($this->x >> 4, $this->z >> 4), $nbt);
$furnace = Tile::createTile("Furnace", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt);
}
if(($player->getGamemode() & 0x01) === 0x01){
@ -114,16 +114,7 @@ class BurningFurnace extends Solid{
public function getDrops(Item $item){
$drops = [];
if($item->isPickaxe() >= 1){
$drops[] = array(Item::FURNACE, 0, 1);
}
$t = $this->getLevel()->getTile($this);
if($t instanceof Furnace){
for($s = 0; $s < $t->getInventory()->getSize(); ++$s){
$slot = $t->getInventory()->getItem($s);
if($slot->getID() > Item::AIR and $slot->getCount() > 0){
$drops[] = array($slot->getID(), $slot->getDamage(), $slot->getCount());
}
}
$drops[] = [Item::FURNACE, 0, 1];
}
return $drops;

View File

@ -21,26 +21,56 @@
namespace pocketmine\block;
use pocketmine\entity\Entity;
use pocketmine\event\block\BlockGrowEvent;
use pocketmine\event\entity\EntityDamageByBlockEvent;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\item\Item;
use pocketmine\level\Level;
use pocketmine\math\Vector3 as Vector3;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Vector3;
use pocketmine\Player;
use pocketmine\Server;
class Cactus extends Transparent{
public $hasEntityCollision = true;
public function __construct($meta = 0){
parent::__construct(self::CACTUS, $meta, "Cactus");
$this->isFullBlock = false;
$this->hardness = 2;
}
protected function recalculateBoundingBox(){
return new AxisAlignedBB(
$this->x + 0.0625,
$this->y,
$this->z + 0.0625,
$this->x + 0.9375,
$this->y + 1,
$this->z + 0.9375
);
}
public function onEntityCollide(Entity $entity){
$ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_CONTACT, 1);
$entity->attack($ev->getFinalDamage(), $ev);
}
public function onUpdate($type){
if($type === Level::BLOCK_UPDATE_NORMAL){
$down = $this->getSide(0);
if($down->getID() !== self::SAND and $down->getID() !== self::CACTUS){ //Replace with common break method
$this->getLevel()->setBlock($this, new Air(), false);
$this->getLevel()->dropItem($this, Item::get($this->id));
return Level::BLOCK_UPDATE_NORMAL;
if($down->getID() !== self::SAND and $down->getID() !== self::CACTUS){
$this->getLevel()->useBreakOn($this);
}else{
for($side = 2; $side <= 5; ++$side){
$b = $this->getSide($side);
if(!$b->isFlowable){
$this->getLevel()->useBreakOn($this);
}
}
}
}elseif($type === Level::BLOCK_UPDATE_RANDOM){
if($this->getSide(0)->getID() !== self::CACTUS){
@ -48,18 +78,18 @@ class Cactus extends Transparent{
for($y = 1; $y < 3; ++$y){
$b = $this->getLevel()->getBlock(new Vector3($this->x, $this->y + $y, $this->z));
if($b->getID() === self::AIR){
$this->getLevel()->setBlock($b, new Cactus(), true, false, true);
break;
Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($b, new Cactus()));
if(!$ev->isCancelled()){
$this->getLevel()->setBlock($b, $ev->getNewState(), true);
}
}
}
$this->meta = 0;
$this->getLevel()->setBlock($this, $this, false);
$this->getLevel()->setBlock($this, $this);
}else{
++$this->meta;
$this->getLevel()->setBlock($this, $this, false);
$this->getLevel()->setBlock($this, $this);
}
return Level::BLOCK_UPDATE_RANDOM;
}
}
@ -74,7 +104,7 @@ class Cactus extends Transparent{
$block2 = $this->getSide(4);
$block3 = $this->getSide(5);
if($block0->isTransparent === true and $block1->isTransparent === true and $block2->isTransparent === true and $block3->isTransparent === true){
$this->getLevel()->setBlock($this, $this, true, false, true);
$this->getLevel()->setBlock($this, $this, true);
return true;
}
@ -84,8 +114,8 @@ class Cactus extends Transparent{
}
public function getDrops(Item $item){
return array(
array($this->id, 0, 1),
);
return [
[$this->id, 0, 1],
];
}
}

View File

@ -21,9 +21,12 @@
namespace pocketmine\block;
use pocketmine\event\entity\EntityRegainHealthEvent;
use pocketmine\item\Item;
use pocketmine\level\Level;
use pocketmine\math\AxisAlignedBB;
use pocketmine\Player;
use pocketmine\Server;
class Cake extends Transparent{
public function __construct($meta = 0){
@ -34,10 +37,24 @@ class Cake extends Transparent{
$this->hardness = 2.5;
}
protected function recalculateBoundingBox(){
$f = (1 + $this->getDamage() * 2) / 16;
return new AxisAlignedBB(
$this->x + $f,
$this->y,
$this->z + 0.0625,
$this->x + 1 - 0.0625,
$this->y + 0.5,
$this->z + 1 - 0.0625
);
}
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
$down = $this->getSide(0);
if($down->getID() !== self::AIR){
$this->getLevel()->setBlock($block, $this, true, false, true);
$this->getLevel()->setBlock($block, $this, true, true);
return true;
}
@ -48,7 +65,7 @@ class Cake extends Transparent{
public function onUpdate($type){
if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() === self::AIR){ //Replace with common break method
$this->getLevel()->setBlock($this, new Air(), true, false, true);
$this->getLevel()->setBlock($this, new Air(), true);
return Level::BLOCK_UPDATE_NORMAL;
}
@ -64,11 +81,14 @@ class Cake extends Transparent{
public function onActivate(Item $item, Player $player = null){
if($player instanceof Player and $player->getHealth() < 20){
++$this->meta;
$player->heal(3, "cake");
Server::getInstance()->getPluginManager()->callEvent($ev = new EntityRegainHealthEvent($player, 3, EntityRegainHealthEvent::CAUSE_EATING));
if(!$ev->isCancelled()){
$player->heal($ev->getAmount(), $ev);
}
if($this->meta >= 0x06){
$this->getLevel()->setBlock($this, new Air(), true, false, true);
$this->getLevel()->setBlock($this, new Air(), true);
}else{
$this->getLevel()->setBlock($this, $this, true, false, true);
$this->getLevel()->setBlock($this, $this, true);
}
return true;

View File

@ -23,12 +23,13 @@ namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\level\Level;
use pocketmine\math\AxisAlignedBB;
use pocketmine\Player;
class Carpet extends Flowable{
public function __construct($meta = 0){
parent::__construct(self::CARPET, $meta, "Carpet");
$names = array(
$names = [
0 => "White Carpet",
1 => "Orange Carpet",
2 => "Magenta Carpet",
@ -45,17 +46,29 @@ class Carpet extends Flowable{
13 => "Green Carpet",
14 => "Red Carpet",
15 => "Black Carpet",
);
];
$this->name = $names[$this->meta];
$this->hardness = 0;
$this->isFullBlock = false;
$this->isSolid = true;
}
protected function recalculateBoundingBox(){
return new AxisAlignedBB(
$this->x,
$this->y,
$this->z,
$this->x + 1,
$this->y + 0.0625,
$this->z + 1
);
}
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
$down = $this->getSide(0);
if($down->getID() !== self::AIR){
$this->getLevel()->setBlock($block, $this, true, false, true);
$this->getLevel()->setBlock($block, $this, true, true);
return true;
}
@ -65,9 +78,8 @@ class Carpet extends Flowable{
public function onUpdate($type){
if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() === self::AIR){ //TODO: Replace with common break method
$this->getLevel()->dropItem($this, Item::get($this->id, $this->meta, 1));
$this->getLevel()->setBlock($this, new Air(), true, false, true);
if($this->getSide(0)->getID() === self::AIR){
$this->getLevel()->useBreakOn($this);
return Level::BLOCK_UPDATE_NORMAL;
}

View File

@ -22,70 +22,18 @@
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\level\Level;
use pocketmine\Player;
class Carrot extends Flowable{
class Carrot extends Crops{
public function __construct($meta = 0){
parent::__construct(self::CARROT_BLOCK, $meta, "Carrot Block");
$this->isActivable = true;
$this->hardness = 0;
}
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
$down = $this->getSide(0);
if($down->getID() === self::FARMLAND){
$this->getLevel()->setBlock($block, $this, true, false, true);
return true;
}
return false;
}
public function onActivate(Item $item, Player $player = null){
if($item->getID() === Item::DYE and $item->getDamage() === 0x0F){ //Bonemeal
$this->meta = 0x07;
$this->getLevel()->setBlock($this, $this, true, false, true);
$item->count--;
return true;
}
return false;
}
public function onUpdate($type){
if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
//TODO
//Server::getInstance()->api->entity->drop($this, Item::get(CARROT, 0, 1));
$this->getLevel()->setBlock($this, new Air(), false, false, true);
return Level::BLOCK_UPDATE_NORMAL;
}
}elseif($type === Level::BLOCK_UPDATE_RANDOM){
if(mt_rand(0, 2) == 1){
if($this->meta < 0x07){
++$this->meta;
$this->getLevel()->setBlock($this, $this, true, false, true);
return Level::BLOCK_UPDATE_RANDOM;
}
}else{
return Level::BLOCK_UPDATE_RANDOM;
}
}
return false;
}
public function getDrops(Item $item){
$drops = [];
if($this->meta >= 0x07){
$drops[] = array(Item::CARROT, 0, mt_rand(1, 4));
$drops[] = [Item::CARROT, 0, mt_rand(1, 4)];
}else{
$drops[] = array(Item::CARROT, 0, 1);
$drops[] = [Item::CARROT, 0, 1];
}
return $drops;

View File

@ -22,6 +22,7 @@
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\math\AxisAlignedBB;
use pocketmine\nbt\NBT;
use pocketmine\nbt\tag\Compound;
use pocketmine\nbt\tag\Enum;
@ -41,15 +42,27 @@ class Chest extends Transparent{
$this->hardness = 15;
}
protected function recalculateBoundingBox(){
return new AxisAlignedBB(
$this->x + 0.0625,
$this->y,
$this->z + 0.0625,
$this->x + 0.9375,
$this->y + 0.9475,
$this->z + 0.9375
);
}
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
$faces = array(
$faces = [
0 => 4,
1 => 2,
2 => 5,
3 => 3,
);
];
$chest = false;
$chest = null;
$this->meta = $faces[$player instanceof Player ? $player->getDirection() : 0];
for($side = 2; $side <= 5; ++$side){
@ -68,18 +81,18 @@ class Chest extends Transparent{
}
}
$this->getLevel()->setBlock($block, $this, true, false, true);
$nbt = new Compound(false, array(
$this->getLevel()->setBlock($block, $this, true, true);
$nbt = new Compound(false, [
new Enum("Items", []),
new String("id", Tile::CHEST),
new Int("x", $this->x),
new Int("y", $this->y),
new Int("z", $this->z)
));
]);
$nbt->Items->setTagType(NBT::TAG_Compound);
$tile = new TileChest($this->getLevel()->getChunkAt($this->x >> 4, $this->z >> 4), $nbt);
$tile = Tile::createTile("Chest", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt);
if($chest instanceof TileChest){
if($chest instanceof TileChest and $tile instanceof TileChest){
$chest->pairWith($tile);
$tile->pairWith($chest);
}
@ -92,7 +105,7 @@ class Chest extends Transparent{
if($t instanceof TileChest){
$t->unpair();
}
$this->getLevel()->setBlock($this, new Air(), true, true, true);
$this->getLevel()->setBlock($this, new Air(), true, true);
return true;
}
@ -109,19 +122,19 @@ class Chest extends Transparent{
if($t instanceof TileChest){
$chest = $t;
}else{
$nbt = new Compound(false, array(
$nbt = new Compound(false, [
new Enum("Items", []),
new String("id", Tile::CHEST),
new Int("x", $this->x),
new Int("y", $this->y),
new Int("z", $this->z)
));
]);
$nbt->Items->setTagType(NBT::TAG_Compound);
$chest = new TileChest($this->getLevel()->getChunkAt($this->x >> 4, $this->z >> 4), $nbt);
$chest = Tile::createTile("Chest", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt);
}
if(($player->gamemode & 0x01) === 0x01){
if($player->isCreative()){
return true;
}
$player->addWindow($chest->getInventory());
@ -131,19 +144,8 @@ class Chest extends Transparent{
}
public function getDrops(Item $item){
$drops = array(
array($this->id, 0, 1),
);
$t = $this->getLevel()->getTile($this);
if($t instanceof TileChest){
for($s = 0; $s < $t->getRealInventory()->getSize(); ++$s){
$slot = $t->getRealInventory()->getItem($s);
if($slot->getID() > Item::AIR and $slot->getCount() > 0){
$drops[] = array($slot->getID(), $slot->getDamage(), $slot->getCount());
}
}
}
return $drops;
return [
[$this->id, 0, 1],
];
}
}

View File

@ -30,8 +30,8 @@ class Clay extends Solid{
}
public function getDrops(Item $item){
return array(
array(Item::CLAY, 0, 4),
);
return [
[Item::CLAY, 0, 4],
];
}
}

View File

@ -48,9 +48,9 @@ class Coal extends Solid{
public function getDrops(Item $item){
if($item->isPickaxe() >= 1){
return array(
array(Item::COAL_BLOCK, 0, 1),
);
return [
[Item::COAL_BLOCK, 0, 1],
];
}else{
return [];
}

View File

@ -48,9 +48,9 @@ class CoalOre extends Solid{
public function getDrops(Item $item){
if($item->isPickaxe() >= 1){
return array(
array(Item::COAL, 0, 1),
);
return [
[Item::COAL, 0, 1],
];
}else{
return [];
}

View File

@ -48,9 +48,9 @@ class Cobblestone extends Solid{
public function getDrops(Item $item){
if($item->isPickaxe() >= 1){
return array(
array(Item::COBBLESTONE, 0, 1),
);
return [
[Item::COBBLESTONE, 0, 1],
];
}else{
return [];
}

View File

@ -21,9 +21,13 @@
namespace pocketmine\block;
use pocketmine\entity\Entity;
use pocketmine\item\Item;
class Cobweb extends Flowable{
public $hasEntityCollision = true;
public function __construct(){
parent::__construct(self::COBWEB, 0, "Cobweb");
$this->isSolid = true;
@ -31,6 +35,10 @@ class Cobweb extends Flowable{
$this->hardness = 25;
}
public function onEntityCollide(Entity $entity){
$entity->fallDistance = 0;
}
public function getDrops(Item $item){
return [];
}

View File

@ -0,0 +1,100 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
namespace pocketmine\block;
use pocketmine\event\block\BlockGrowEvent;
use pocketmine\item\Item;
use pocketmine\level\Level;
use pocketmine\Player;
use pocketmine\Server;
abstract class Crops extends Flowable{
public $isActivable = true;
public $hardness = 0;
public function getBoundingBox(){
return null;
}
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
$down = $this->getSide(0);
if($down->getID() === self::FARMLAND){
$this->getLevel()->setBlock($block, $this, true, true);
return true;
}
return false;
}
public function onActivate(Item $item, Player $player = null){
if($item->getID() === Item::DYE and $item->getDamage() === 0x0F){ //Bonemeal
$block = clone $this;
$block->meta += mt_rand(2, 5);
if($block->meta > 7){
$block->meta = 7;
}
Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($this, $block));
if(!$ev->isCancelled()){
$this->getLevel()->setBlock($this, $ev->getNewState(), true, true);
}
$item->count--;
return true;
}
return false;
}
public function onUpdate($type){
if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){
$this->getLevel()->useBreakOn($this);
return Level::BLOCK_UPDATE_NORMAL;
}
}elseif($type === Level::BLOCK_UPDATE_RANDOM){
if(mt_rand(0, 2) == 1){
if($this->meta < 0x07){
$block = clone $this;
++$block->meta;
Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($this, $block));
if(!$ev->isCancelled()){
$this->getLevel()->setBlock($this, $ev->getNewState(), true, true);
}else{
return Level::BLOCK_UPDATE_RANDOM;
}
}
}else{
return Level::BLOCK_UPDATE_RANDOM;
}
}
return false;
}
}

View File

@ -31,10 +31,15 @@ class CyanFlower extends Flowable{
$this->hardness = 0;
}
public function getBoundingBox(){
return null;
}
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
$down = $this->getSide(0);
if($down->getID() === 2 or $down->getID() === 3 or $down->getID() === 60){
$this->getLevel()->setBlock($block, $this, true, false, true);
$this->getLevel()->setBlock($block, $this, true, true);
return true;
}
@ -44,9 +49,8 @@ class CyanFlower extends Flowable{
public function onUpdate($type){
if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //TODO: Replace with common break method
$this->getLevel()->dropItem($this, Item::get($this->id, 0, 1));
$this->getLevel()->setBlock($this, new Air(), false, false, true);
if($this->getSide(0)->isTransparent === true){
$this->getLevel()->useBreakOn($this);
return Level::BLOCK_UPDATE_NORMAL;
}

View File

@ -31,10 +31,15 @@ class Dandelion extends Flowable{
$this->hardness = 0;
}
public function getBoundingBox(){
return null;
}
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
$down = $this->getSide(0);
if($down->getID() === 2 or $down->getID() === 3 or $down->getID() === 60){
$this->getLevel()->setBlock($block, $this, true, false, true);
$this->getLevel()->setBlock($block, $this, true, true);
return true;
}
@ -44,10 +49,8 @@ class Dandelion extends Flowable{
public function onUpdate($type){
if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
//TODO
//Server::getInstance()->api->entity->drop($this, Item::get($this->id));
$this->getLevel()->setBlock($this, new Air(), false, false, true);
if($this->getSide(0)->isTransparent === true){
$this->getLevel()->useBreakOn($this);
return Level::BLOCK_UPDATE_NORMAL;
}

View File

@ -29,8 +29,8 @@ class DarkOakWoodStairs extends Stair{
}
public function getDrops(Item $item){
return array(
array($this->id, 0, 1),
);
return [
[$this->id, 0, 1],
];
}
}

View File

@ -30,6 +30,11 @@ class DeadBush extends Flowable{
$this->hardness = 0;
}
public function getBoundingBox(){
return null;
}
public function onUpdate($type){
if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method

View File

@ -42,9 +42,9 @@ class Diamond extends Solid{
public function getDrops(Item $item){
if($item->isPickaxe() >= 4){
return array(
array(Item::DIAMOND_BLOCK, 0, 1),
);
return [
[Item::DIAMOND_BLOCK, 0, 1],
];
}else{
return [];
}

View File

@ -42,9 +42,9 @@ class DiamondOre extends Solid{
public function getDrops(Item $item){
if($item->isPickaxe() >= 4){
return array(
array(Item::DIAMOND, 0, 1),
);
return [
[Item::DIAMOND, 0, 1],
];
}else{
return [];
}

View File

@ -25,16 +25,21 @@ use pocketmine\item\Item;
use pocketmine\Player;
class Dirt extends Solid{
public $isActivable = true;
protected $hardness = 2.5;
protected $id = self::DIRT;
protected $meta = 0;
protected $name = "Dirt";
public function __construct(){
parent::__construct(self::DIRT, 0, "Dirt");
$this->isActivable = true;
$this->hardness = 2.5;
}
public function onActivate(Item $item, Player $player = null){
if($item->isHoe()){
$item->useOn($this);
$this->getLevel()->setBlock($this, Block::get(Item::FARMLAND, 0), true, false, true);
$this->getLevel()->setBlock($this, Block::get(Item::FARMLAND, 0), true);
return true;
}

View File

@ -23,6 +23,7 @@ namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\level\Level;
use pocketmine\math\AxisAlignedBB;
use pocketmine\network\protocol\LevelEventPacket;
use pocketmine\Player;
use pocketmine\Server;
@ -34,6 +35,170 @@ abstract class Door extends Transparent{
$this->isSolid = false;
}
private function getFullDamage(){
$damage = $this->getDamage();
$flag = ($damage & 0x08) > 0;
if($flag){
$first = $this->getSide(0)->getDamage();
$second = $damage;
}else{
$first = $damage;
$second = $this->getSide(1)->getDamage();
}
$flag1 = ($second & 0x01) > 0;
return $first & 0x07 | ($flag ? 8 : 0) | ($flag1 ? 0x10 : 0);
}
protected function recalculateBoundingBox(){
$f = 0.1875;
$damage = $this->getFullDamage();
$bb = new AxisAlignedBB(
$this->x,
$this->y,
$this->z,
$this->x + 1,
$this->y + 2,
$this->z + 1
);
$j = $damage & 0x03;
$flag = (($damage & 0x04) > 0);
$flag1 = (($damage & 0x10) > 0);
if($j === 0){
if($flag){
if(!$flag1){
$bb->setBounds(
$this->x,
$this->y,
$this->z,
$this->x + 1,
$this->y + 1,
$this->z + $f
);
}else{
$bb->setBounds(
$this->x,
$this->y,
$this->z + 1 - $f,
$this->x + 1,
$this->y + 1,
$this->z + 1
);
}
}else{
$bb->setBounds(
$this->x,
$this->y,
$this->z,
$this->x + $f,
$this->y + 1,
$this->z + 1
);
}
}elseif($j === 1){
if($flag){
if(!$flag1){
$bb->setBounds(
$this->x + 1 - $f,
$this->y,
$this->z,
$this->x + 1,
$this->y + 1,
$this->z + 1
);
}else{
$bb->setBounds(
$this->x,
$this->y,
$this->z,
$this->x + $f,
$this->y + 1,
$this->z + 1
);
}
}else{
$bb->setBounds(
$this->x,
$this->y,
$this->z,
$this->x + 1,
$this->y + 1,
$this->z + $f
);
}
}elseif($j === 2){
if($flag){
if(!$flag1){
$bb->setBounds(
$this->x,
$this->y,
$this->z + 1 - $f,
$this->x + 1,
$this->y + 1,
$this->z + 1
);
}else{
$bb->setBounds(
$this->x,
$this->y,
$this->z,
$this->x + 1,
$this->y + 1,
$this->z + $f
);
}
}else{
$bb->setBounds(
$this->x + 1 - $f,
$this->y,
$this->z,
$this->x + 1,
$this->y + 1,
$this->z + 1
);
}
}elseif($j === 3){
if($flag){
if(!$flag1){
$bb->setBounds(
$this->x,
$this->y,
$this->z,
$this->x + $f,
$this->y + 1,
$this->z + 1
);
}else{
$bb->setBounds(
$this->x + 1 - $f,
$this->y,
$this->z,
$this->x + 1,
$this->y + 1,
$this->z + 1
);
}
}else{
$bb->setBounds(
$this->x,
$this->y,
$this->z + 1 - $f,
$this->x + 1,
$this->y + 1,
$this->z + 1
);
}
}
return $bb;
}
public function onUpdate($type){
if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() === self::AIR){ //Replace with common break method
@ -57,22 +222,22 @@ abstract class Door extends Transparent{
return false;
}
$direction = $player instanceof Player ? $player->getDirection() : 0;
$face = array(
$face = [
0 => 3,
1 => 4,
2 => 2,
3 => 5,
);
];
$next = $this->getSide($face[(($direction + 2) % 4)]);
$next2 = $this->getSide($face[$direction]);
$metaUp = 0x08;
if($next->getID() === $this->id or ($next2->isTransparent === false and $next->isTransparent === true)){ //Door hinge
$metaUp |= 0x01;
}
$this->getLevel()->setBlock($blockUp, Block::get($this->id, $metaUp), true, false, true); //Top
$this->meta = $player->getDirection() & 0x03;
$this->getLevel()->setBlock($block, $this, true, false, true); //Bottom
$this->getLevel()->setBlock($block, $this, true, true); //Bottom
$this->getLevel()->setBlock($blockUp, $b = Block::get($this->id, $metaUp), true); //Top
return true;
}
@ -83,15 +248,15 @@ abstract class Door extends Transparent{
if(($this->meta & 0x08) === 0x08){
$down = $this->getSide(0);
if($down->getID() === $this->id){
$this->getLevel()->setBlock($down, new Air(), true, false, true);
$this->getLevel()->setBlock($down, new Air(), true);
}
}else{
$up = $this->getSide(1);
if($up->getID() === $this->id){
$this->getLevel()->setBlock($up, new Air(), true, false, true);
$this->getLevel()->setBlock($up, new Air(), true);
}
}
$this->getLevel()->setBlock($this, new Air(), true, false, true);
$this->getLevel()->setBlock($this, new Air(), true);
return true;
}
@ -101,12 +266,12 @@ abstract class Door extends Transparent{
$down = $this->getSide(0);
if($down->getID() === $this->id){
$meta = $down->getDamage() ^ 0x04;
$this->getLevel()->setBlock($down, Block::get($this->id, $meta), true, false, true);
$this->getLevel()->setBlock($down, Block::get($this->id, $meta), true);
$players = $this->getLevel()->getUsingChunk($this->x >> 4, $this->z >> 4);
if($player instanceof Player){
unset($players[$player->getID()]);
}
$pk = new LevelEventPacket;
$pk = new LevelEventPacket();
$pk->x = $this->x;
$pk->y = $this->y;
$pk->z = $this->z;
@ -120,12 +285,12 @@ abstract class Door extends Transparent{
return false;
}else{
$this->meta ^= 0x04;
$this->getLevel()->setBlock($this, $this, true, false, true);
$this->getLevel()->setBlock($this, $this, true);
$players = $this->getLevel()->getUsingChunk($this->x >> 4, $this->z >> 4);
if($player instanceof Player){
unset($players[$player->getID()]);
}
$pk = new LevelEventPacket;
$pk = new LevelEventPacket();
$pk->x = $this->x;
$pk->y = $this->y;
$pk->z = $this->z;

View File

@ -26,7 +26,7 @@ use pocketmine\item\Item;
class DoubleSlab extends Solid{
public function __construct($meta = 0){
parent::__construct(self::DOUBLE_SLAB, $meta, "Double Slab");
$names = array(
$names = [
0 => "Stone",
1 => "Sandstone",
2 => "Wooden",
@ -34,7 +34,8 @@ class DoubleSlab extends Solid{
4 => "Brick",
5 => "Stone Brick",
6 => "Quartz",
);
7 => "",
];
$this->name = "Double " . $names[$this->meta & 0x07] . " Slab";
$this->hardness = 30;
}
@ -58,9 +59,9 @@ class DoubleSlab extends Solid{
public function getDrops(Item $item){
if($item->isPickaxe() >= 1){
return array(
array(Item::SLAB, $this->meta & 0x07, 2),
);
return [
[Item::SLAB, $this->meta & 0x07, 2],
];
}else{
return [];
}

View File

@ -26,14 +26,14 @@ use pocketmine\item\Item;
class DoubleWoodSlab extends Solid{
public function __construct($meta = 0){
parent::__construct(self::DOUBLE_WOOD_SLAB, $meta, "Double Wooden Slab");
$names = array(
$names = [
0 => "Oak",
1 => "Spruce",
2 => "Birch",
3 => "Jungle",
4 => "Acacia",
5 => "Dark Oak",
);
];
$this->name = "Double " . $names[$this->meta & 0x07] . " Wooden Slab";
$this->hardness = 15;
}
@ -56,9 +56,9 @@ class DoubleWoodSlab extends Solid{
}
public function getDrops(Item $item){
return array(
array(Item::WOOD_SLAB, $this->meta & 0x07, 2),
);
return [
[Item::WOOD_SLAB, $this->meta & 0x07, 2],
];
}
}

View File

@ -42,9 +42,9 @@ class Emerald extends Solid{
public function getDrops(Item $item){
if($item->isPickaxe() >= 4){
return array(
array(Item::EMERALD_BLOCK, 0, 1),
);
return [
[Item::EMERALD_BLOCK, 0, 1],
];
}else{
return [];
}

View File

@ -42,9 +42,9 @@ class EmeraldOre extends Solid{
public function getDrops(Item $item){
if($item->isPickaxe() >= 4){
return array(
array(Item::EMERALD, 0, 1),
);
return [
[Item::EMERALD, 0, 1],
];
}else{
return [];
}

View File

@ -21,11 +21,23 @@
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\math\AxisAlignedBB;
class EndPortal extends Solid{
public function __construct($meta = 0){
parent::__construct(self::END_PORTAL, $meta, "End Portal");
$this->hardness = 18000000;
}
protected function recalculateBoundingBox(){
return new AxisAlignedBB(
$this->x,
$this->y,
$this->z,
$this->x + 1,
$this->y + (($this->getDamage() & 0x04) > 0 ? 1 : 0.8125),
$this->z + 1
);
}
}

View File

@ -21,19 +21,52 @@
namespace pocketmine\block;
use pocketmine\entity\Entity;
use pocketmine\item\Item;
use pocketmine\level\Level;
use pocketmine\nbt\tag\Byte;
use pocketmine\nbt\tag\Compound;
use pocketmine\nbt\tag\Double;
use pocketmine\nbt\tag\Enum;
use pocketmine\nbt\tag\Float;
use pocketmine\nbt\tag\Int;
use pocketmine\Player;
class Fallable extends Solid{
abstract class Fallable extends Solid{
public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name);
$this->hasPhysics = true;
}
public $hasPhysics = true;
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
$ret = $this->getLevel()->setBlock($this, $this, true, false, true);
$ret = $this->getLevel()->setBlock($this, $this, true, true);
return $ret;
}
public function onUpdate($type){
if($this->hasPhysics === true and $type === Level::BLOCK_UPDATE_NORMAL){
$down = $this->getSide(0);
if($down->getID() === self::AIR or ($down instanceof Liquid)){
$fall = Entity::createEntity("FallingSand", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), new Compound("", [
"Pos" => new Enum("Pos", [
new Double("", $this->x + 0.5),
new Double("", $this->y),
new Double("", $this->z + 0.5)
]),
"Motion" => new Enum("Motion", [
new Double("", 0),
new Double("", 0),
new Double("", 0)
]),
"Rotation" => new Enum("Rotation", [
new Float("", 0),
new Float("", 0)
]),
"TileID" => new Int("TileID", $this->getID()),
"Data" => new Byte("Data", $this->getDamage()),
]));
$fall->spawnToAll();
}
}
}
}

View File

@ -22,6 +22,7 @@
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\math\AxisAlignedBB;
class Farmland extends Solid{
public function __construct($meta = 0){
@ -29,9 +30,21 @@ class Farmland extends Solid{
$this->hardness = 3;
}
public function getDrops(Item $item){
return array(
array(Item::DIRT, 0, 1),
protected function recalculateBoundingBox(){
return new AxisAlignedBB(
$this->x,
$this->y,
$this->z,
$this->x + 1,
$this->y + 0.9375,
$this->z + 1
);
}
public function getDrops(Item $item){
return [
[Item::DIRT, 0, 1],
];
}
}

View File

@ -22,6 +22,8 @@
namespace pocketmine\block;
use pocketmine\math\AxisAlignedBB;
class Fence extends Transparent{
public function __construct(){
parent::__construct(self::FENCE, 0, "Fence");
@ -29,4 +31,30 @@ class Fence extends Transparent{
$this->hardness = 15;
}
protected function recalculateBoundingBox(){
$flag = $this->canConnect($this->getSide(2));
$flag1 = $this->canConnect($this->getSide(3));
$flag2 = $this->canConnect($this->getSide(4));
$flag3 = $this->canConnect($this->getSide(5));
$f = $flag2 ? 0 : 0.375;
$f1 = $flag3 ? 1 : 0.625;
$f2 = $flag ? 0 : 0.375;
$f3 = $flag1 ? 1 : 0.625;
return new AxisAlignedBB(
$this->x + $f,
$this->y,
$this->z + $f2,
$this->x + $f1,
$this->y + 1,
$this->z + $f3
);
}
public function canConnect(Block $block){
return ($block->getID() !== self::FENCE and $block->getID() !== self::FENCE_GATE) ? $block->isSolid : true;
}
}

View File

@ -22,6 +22,7 @@
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\math\AxisAlignedBB;
use pocketmine\Player;
class FenceGate extends Transparent{
@ -36,39 +37,68 @@ class FenceGate extends Transparent{
$this->hardness = 15;
}
protected function recalculateBoundingBox(){
if(($this->getDamage() & 0x04) > 0){
return null;
}
$i = ($this->getDamage() & 0x03);
if($i === 2 and $i === 0){
return new AxisAlignedBB(
$this->x,
$this->y,
$this->z + 0.375,
$this->x + 1,
$this->y + 1,
$this->z + 0.625
);
}else{
return new AxisAlignedBB(
$this->x + 0.375,
$this->y,
$this->z,
$this->x + 0.625,
$this->y + 1,
$this->z + 1
);
}
}
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
$faces = array(
$faces = [
0 => 3,
1 => 0,
2 => 1,
3 => 2,
);
];
$this->meta = $faces[$player instanceof Player ? $player->getDirection() : 0] & 0x03;
$this->getLevel()->setBlock($block, $this, true, false, true);
$this->getLevel()->setBlock($block, $this, true, true);
return true;
}
public function getDrops(Item $item){
return array(
array($this->id, 0, 1),
);
return [
[$this->id, 0, 1],
];
}
public function onActivate(Item $item, Player $player = null){
$faces = array(
$faces = [
0 => 3,
1 => 0,
2 => 1,
3 => 2,
);
];
$this->meta = ($faces[$player instanceof Player ? $player->getDirection() : 0] & 0x03) | ((~$this->meta) & 0x04);
if(($this->meta & 0x04) === 0x04){
$this->isFullBlock = true;
}else{
$this->isFullBlock = false;
}
$this->getLevel()->setBlock($this, $this, true, false, true);
$this->getLevel()->setBlock($this, $this, true);
return true;
}

View File

@ -21,10 +21,18 @@
namespace pocketmine\block;
use pocketmine\entity\Entity;
use pocketmine\event\entity\EntityCombustByBlockEvent;
use pocketmine\event\entity\EntityDamageByBlockEvent;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\item\Item;
use pocketmine\level\Level;
use pocketmine\Server;
class Fire extends Flowable{
public $hasEntityCollision = true;
public function __construct($meta = 0){
parent::__construct(self::FIRE, $meta, "Fire");
$this->isReplaceable = true;
@ -33,6 +41,21 @@ class Fire extends Flowable{
$this->hardness = 0;
}
public function getBoundingBox(){
return null;
}
public function onEntityCollide(Entity $entity){
$ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_FIRE, 1);
$entity->attack($ev->getFinalDamage(), $ev);
$ev = new EntityCombustByBlockEvent($this, $entity, 8);
Server::getInstance()->getPluginManager()->callEvent($ev);
if(!$ev->isCancelled()){
$entity->setOnFire($ev->getDuration());
}
}
public function getDrops(Item $item){
return [];
}
@ -45,12 +68,12 @@ class Fire extends Flowable{
return false;
}
}
$this->getLevel()->setBlock($this, new Air(), true, false, true);
$this->getLevel()->setBlock($this, new Air(), true);
return Level::BLOCK_UPDATE_NORMAL;
}elseif($type === Level::BLOCK_UPDATE_RANDOM){
if($this->getSide(0)->getID() !== self::NETHERRACK){
$this->getLevel()->setBlock($this, new Air(), true, false, true);
$this->getLevel()->setBlock($this, new Air(), true);
return Level::BLOCK_UPDATE_NORMAL;
}

View File

@ -22,11 +22,10 @@
namespace pocketmine\block;
class Flowable extends Transparent{
public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name);
$this->isFlowable = true;
$this->isFullBlock = false;
$this->isSolid = false;
}
abstract class Flowable extends Transparent{
public $isFlowable = true;
public $isFullBlock = false;
public $isSolid = false;
}

View File

@ -1,77 +0,0 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\level\Level;
use pocketmine\Player;
class Generic extends Block{
/**
* @param int $id
* @param int $meta
* @param string $name
*/
public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name);
}
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
return $this->getLevel()->setBlock($this, $this, true, false, true);
}
public function isBreakable(Item $item){
return $this->breakable;
}
public function onBreak(Item $item){
return $this->getLevel()->setBlock($this, new Air(), true, false, true);
}
public function onUpdate($type){
if($this->hasPhysics === true and $type === Level::BLOCK_UPDATE_NORMAL){
$down = $this->getSide(0);
if($down->getID() === self::AIR or ($down instanceof Liquid)){
$data = array(
"x" => $this->x + 0.5,
"y" => $this->y + 0.5,
"z" => $this->z + 0.5,
"Tile" => $this->id,
);
/*$this->getLevel()->setBlock($this, new Air(), false, false, true);
//TODO
//$e = $server->api->entity->add($this->getLevel(), ENTITY_FALLING, FALLING_SAND, $data);
//$e->spawnToAll();
$server->api->block->blockUpdateAround(clone $this, Level::BLOCK_UPDATE_NORMAL, 1);*/
}
return false;
}
return false;
}
public function onActivate(Item $item, Player $player = null){
return $this->isActivable;
}
}

View File

@ -22,11 +22,9 @@
namespace pocketmine\block;
class GlassPane extends Transparent{
class GlassPane extends Thin{
public function __construct(){
parent::__construct(self::GLASS_PANE, 0, "Glass Pane");
$this->isFullBlock = false;
$this->isSolid = false;
}
}

View File

@ -54,9 +54,9 @@ class GlowingRedstoneOre extends Solid{
public function getDrops(Item $item){
if($item->isPickaxe() >= 4){
return array(
array(Item::REDSTONE_DUST, 0, mt_rand(4, 5)),
);
return [
[Item::REDSTONE_DUST, 0, mt_rand(4, 5)],
];
}else{
return [];
}

View File

@ -30,8 +30,8 @@ class Glowstone extends Transparent{
}
public function getDrops(Item $item){
return array(
array(Item::GLOWSTONE_DUST, 0, mt_rand(2, 4)),
);
return [
[Item::GLOWSTONE_DUST, 0, mt_rand(2, 4)],
];
}
}

View File

@ -42,9 +42,9 @@ class Gold extends Solid{
public function getDrops(Item $item){
if($item->isPickaxe() >= 4){
return array(
array(Item::GOLD_BLOCK, 0, 1),
);
return [
[Item::GOLD_BLOCK, 0, 1],
];
}else{
return [];
}

View File

@ -42,9 +42,9 @@ class GoldOre extends Solid{
public function getDrops(Item $item){
if($item->isPickaxe() >= 4){
return array(
array(Item::GOLD_ORE, 0, 1),
);
return [
[Item::GOLD_ORE, 0, 1],
];
}else{
return [];
}

View File

@ -21,18 +21,25 @@
namespace pocketmine\block;
use pocketmine\event\block\BlockSpreadEvent;
use pocketmine\item\Item;
use pocketmine\level\generator\object\TallGrass;
use pocketmine\level\generator\object\TallGrass as TallGrassObject;
use pocketmine\level\Level;
use pocketmine\math\Vector3;
use pocketmine\Player;
use pocketmine\Server;
use pocketmine\utils\Random;
class Grass extends Solid{
public $isActivable = true;
protected $hardness = 3;
protected $id = self::GRASS;
protected $meta = 0;
protected $name = "Grass";
public function __construct(){
parent::__construct(self::GRASS, 0, "Grass");
$this->isActivable = true;
$this->hardness = 3;
}
public function getDrops(Item $item){
@ -47,11 +54,13 @@ class Grass extends Solid{
$x = mt_rand($this->x - 1, $this->x + 1);
$y = mt_rand($this->y - 2, $this->y + 2);
$z = mt_rand($this->z - 1, $this->z + 1);
$block = $this->getLevel()->getBlockIdAt($x, $y, $z);
if($block === Block::DIRT){
$block = $this->getLevel()->getBlock(new Vector3($x, $y, $z));
$block = $this->getLevel()->getBlock(new Vector3($x, $y, $z));
if($block->getID() === Block::DIRT){
if($block->getSide(1) instanceof Transparent){
$this->getLevel()->setBlock($block, new Grass());
Server::getInstance()->getPluginManager()->callEvent($ev = new BlockSpreadEvent($block, $this, new Grass()));
if(!$ev->isCancelled()){
$this->getLevel()->setBlock($block, $ev->getNewState());
}
}
}
}
@ -60,7 +69,7 @@ class Grass extends Solid{
public function onActivate(Item $item, Player $player = null){
if($item->getID() === Item::DYE and $item->getDamage() === 0x0F){
$item->count--;
TallGrass::growGrass($this->getLevel(), $this, new Random(mt_rand()), 8, 2);
TallGrassObject::growGrass($this->getLevel(), $this, new Random(mt_rand()), 8, 2);
return true;
}elseif($item->isHoe()){

View File

@ -31,14 +31,14 @@ class Gravel extends Fallable{
public function getDrops(Item $item){
if(mt_rand(1, 10) === 1){
return array(
array(Item::FLINT, 0, 1),
);
return [
[Item::FLINT, 0, 1],
];
}
return array(
array(Item::GRAVEL, 0, 1),
);
return [
[Item::GRAVEL, 0, 1],
];
}
}

View File

@ -31,25 +31,25 @@ class HayBale extends Solid{
}
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
$faces = array(
$faces = [
0 => 0,
1 => 0,
2 => 0b1000,
3 => 0b1000,
4 => 0b0100,
5 => 0b0100,
);
];
$this->meta = ($this->meta & 0x03) | $faces[$face];
$this->getLevel()->setBlock($block, $this, true, false, true);
$this->getLevel()->setBlock($block, $this, true, true);
return true;
}
public function getDrops(Item $item){
return array(
array($this->id, 0, 1),
);
return [
[$this->id, 0, 1],
];
}
}

View File

@ -30,7 +30,7 @@ class Ice extends Transparent{
}
public function onBreak(Item $item){
$this->getLevel()->setBlock($this, new Water(), true, false, true);
$this->getLevel()->setBlock($this, new Water(), true);
return true;
}

View File

@ -44,9 +44,9 @@ class Iron extends Solid{
public function getDrops(Item $item){
if($item->isPickaxe() >= 3){
return array(
array(Item::IRON_BLOCK, 0, 1),
);
return [
[Item::IRON_BLOCK, 0, 1],
];
}else{
return [];
}

View File

@ -22,11 +22,9 @@
namespace pocketmine\block;
class IronBars extends Transparent{
class IronBars extends Thin{
public function __construct(){
parent::__construct(self::IRON_BARS, 0, "Iron Bars");
$this->isFullBlock = false;
$this->isSolid = false;
}
}

View File

@ -49,9 +49,9 @@ class IronDoor extends Door{
public function getDrops(Item $item){
if($item->isPickaxe() >= 1){
return array(
array(Item::IRON_DOOR, 0, 1),
);
return [
[Item::IRON_DOOR, 0, 1],
];
}else{
return [];
}

View File

@ -44,9 +44,9 @@ class IronOre extends Solid{
public function getDrops(Item $item){
if($item->isPickaxe() >= 3){
return array(
array(Item::IRON_ORE, 0, 1),
);
return [
[Item::IRON_ORE, 0, 1],
];
}else{
return [];
}

View File

@ -29,8 +29,8 @@ class JungleWoodStairs extends Stair{
}
public function getDrops(Item $item){
return array(
array($this->id, 0, 1),
);
return [
[$this->id, 0, 1],
];
}
}

View File

@ -21,11 +21,16 @@
namespace pocketmine\block;
use pocketmine\entity\Entity;
use pocketmine\item\Item;
use pocketmine\level\Level;
use pocketmine\math\AxisAlignedBB;
use pocketmine\Player;
class Ladder extends Transparent{
public $hasEntityCollision = true;
public function __construct($meta = 0){
parent::__construct(self::LADDER, $meta, "Ladder");
$this->isSolid = false;
@ -33,17 +38,68 @@ class Ladder extends Transparent{
$this->hardness = 2;
}
public function onEntityCollide(Entity $entity){
$entity->fallDistance = 0;
$entity->onGround = true;
}
protected function recalculateBoundingBox(){
$f = 0.125;
if($this->meta === 2){
return new AxisAlignedBB(
$this->x,
$this->y,
$this->z + 1 - $f,
$this->x + 1,
$this->y + 1,
$this->z + 1
);
}elseif($this->meta === 3){
return new AxisAlignedBB(
$this->x,
$this->y,
$this->z,
$this->x + 1,
$this->y + 1,
$this->z + $f
);
}elseif($this->meta === 4){
return new AxisAlignedBB(
$this->x + 1 - $f,
$this->y,
$this->z,
$this->x + 1,
$this->y + 1,
$this->z + 1
);
}elseif($this->meta === 5){
return new AxisAlignedBB(
$this->x,
$this->y,
$this->z,
$this->x + $f,
$this->y + 1,
$this->z + 1
);
}
return null;
}
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
if($target->isTransparent === false){
$faces = array(
$faces = [
2 => 2,
3 => 3,
4 => 4,
5 => 5,
);
];
if(isset($faces[$face])){
$this->meta = $faces[$face];
$this->getLevel()->setBlock($block, $this, true, false, true);
$this->getLevel()->setBlock($block, $this, true, true);
return true;
}
@ -65,8 +121,8 @@ class Ladder extends Transparent{
}
public function getDrops(Item $item){
return array(
array($this->id, 0, 1),
);
return [
[$this->id, 0, 1],
];
}
}

View File

@ -44,9 +44,9 @@ class Lapis extends Solid{
public function getDrops(Item $item){
if($item->isPickaxe() >= 3){
return array(
array(Item::LAPIS_BLOCK, 0, 1),
);
return [
[Item::LAPIS_BLOCK, 0, 1],
];
}else{
return [];
}

View File

@ -45,9 +45,9 @@ class LapisOre extends Solid{
public function getDrops(Item $item){
if($item->isPickaxe() >= 3){
return array(
array(Item::DYE, 4, mt_rand(4, 8)),
);
return [
[Item::DYE, 4, mt_rand(4, 8)],
];
}else{
return [];
}

View File

@ -21,134 +21,42 @@
namespace pocketmine\block;
use pocketmine\entity\Entity;
use pocketmine\event\entity\EntityCombustByBlockEvent;
use pocketmine\event\entity\EntityDamageByBlockEvent;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\item\Item;
use pocketmine\level\Level;
use pocketmine\level\Position;
use pocketmine\Player;
use pocketmine\Server;
class Lava extends Liquid{
public function __construct($meta = 0){
parent::__construct(self::LAVA, $meta, "Lava");
$this->hardness = 0;
}
public function onEntityCollide(Entity $entity){
$entity->fallDistance *= 0.5;
$ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_LAVA, 4);
$entity->attack($ev->getFinalDamage(), $ev);
$ev = new EntityCombustByBlockEvent($this, $entity, 15);
Server::getInstance()->getPluginManager()->callEvent($ev);
if(!$ev->isCancelled()){
$entity->setOnFire($ev->getDuration());
}
if($entity instanceof Player){
$entity->onGround = true;
}
}
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
$ret = $this->getLevel()->setBlock($this, $this, true, false, true);
$this->getLevel()->scheduleUpdate(clone $this, 40);
$ret = $this->getLevel()->setBlock($this, $this, true, false);
$this->getLevel()->scheduleUpdate($this, $this->tickRate());
return $ret;
}
public function getSourceCount(){
$count = 0;
for($side = 2; $side <= 5; ++$side){
if($this->getSide($side) instanceof Lava){
$b = $this->getSide($side);
$level = $b->meta & 0x07;
if($level == 0x00){
$count++;
}
}
}
return $count;
}
public function checkWater(){
for($side = 1; $side <= 5; ++$side){
$b = $this->getSide($side);
if($b instanceof Water){
$level = $this->meta & 0x07;
if($level == 0x00){
$this->getLevel()->setBlock($this, new Obsidian(), false, false, true);
}else{
$this->getLevel()->setBlock($this, new Cobblestone(), false, false, true);
}
}
}
}
public function getFrom(){
for($side = 0; $side <= 5; ++$side){
$b = $this->getSide($side);
if($b instanceof Lava){
$tlevel = $b->meta & 0x07;
$level = $this->meta & 0x07;
if(($tlevel + 2) == $level || ($side == 0x01 && $level == 0x01) || ($tlevel == 6 && $level == 7)){
return $b;
}
}
}
return null;
}
public function onUpdate($type){
return false;
$newId = $this->id;
$level = $this->meta & 0x07;
if($type !== Level::BLOCK_UPDATE_NORMAL){
return false;
}
if($this->checkWater()){
return;
}
$falling = $this->meta >> 3;
$down = $this->getSide(0);
$from = $this->getFrom();
if($from !== null || $level == 0x00){
if($level !== 0x07){
if($down instanceof Air || $down instanceof Lava){
$this->getLevel()->setBlock($down, new Lava(0x01), false, false, true);
Server::getInstance()->api->block->scheduleBlockUpdate(new Position($down, 0, 0, $this->level), 40, Level::BLOCK_UPDATE_NORMAL);
}else{
for($side = 2; $side <= 5; ++$side){
$b = $this->getSide($side);
if($b instanceof Lava){
}elseif($b->isFlowable === true){
$this->getLevel()->setBlock($b, new Lava(min($level + 2, 7)), false, false, true);
Server::getInstance()->api->block->scheduleBlockUpdate(Position::fromObject($b, $this->level), 40, Level::BLOCK_UPDATE_NORMAL);
}
}
}
}
}else{
//Extend Remove for Left Lavas
for($side = 2; $side <= 5; ++$side){
$sb = $this->getSide($side);
if($sb instanceof Lava){
$tlevel = $sb->meta & 0x07;
if($tlevel != 0x00){
for($s = 0; $s <= 5; $s++){
$ssb = $sb->getSide($s);
Server::getInstance()->api->block->scheduleBlockUpdate(Position::fromObject($ssb, $this->level), 40, Level::BLOCK_UPDATE_NORMAL);
}
$this->getLevel()->setBlock($sb, new Air(), false, false, true);
}
}
$b = $this->getSide(0)->getSide($side);
if($b instanceof Lava){
$tlevel = $b->meta & 0x07;
if($tlevel != 0x00){
for($s = 0; $s <= 5; $s++){
$ssb = $sb->getSide($s);
Server::getInstance()->api->block->scheduleBlockUpdate(Position::fromObject($ssb, $this->level), 40, Level::BLOCK_UPDATE_NORMAL);
}
$this->getLevel()->setBlock($b, new Air(), false, false, true);
}
}
//Server::getInstance()->api->block->scheduleBlockUpdate(Position::fromObject($b, $this->level), 10, Level::BLOCK_UPDATE_NORMAL);
}
$this->getLevel()->setBlock($this, new Air(), false, false, true);
}
return false;
}
}

View File

@ -21,9 +21,11 @@
namespace pocketmine\block;
use pocketmine\event\block\LeavesDecayEvent;
use pocketmine\item\Item;
use pocketmine\level\Level;
use pocketmine\Player;
use pocketmine\Server;
class Leaves extends Transparent{
const OAK = 0;
@ -35,12 +37,12 @@ class Leaves extends Transparent{
public function __construct($meta = 0){
parent::__construct(self::LEAVES, $meta, "Leaves");
$names = array(
$names = [
self::OAK => "Oak Leaves",
self::SPRUCE => "Spruce Leaves",
self::BIRCH => "Birch Leaves",
self::JUNGLE => "Jungle Leaves",
);
];
$this->name = $names[$this->meta & 0x03];
$this->hardness = 1;
}
@ -121,16 +123,13 @@ class Leaves extends Transparent{
$this->meta &= 0x03;
$visited = [];
$check = 0;
if($this->findLog($this, $visited, 0, $check) === true){
$this->getLevel()->setBlock($this, $this, false, false, true);
Server::getInstance()->getPluginManager()->callEvent($ev = new LeavesDecayEvent($this));
if($ev->isCancelled() or $this->findLog($this, $visited, 0, $check) === true){
$this->getLevel()->setBlock($this, $this, false, false);
}else{
$this->getLevel()->setBlock($this, new Air(), false, false, true);
if(mt_rand(1, 20) === 1){ //Saplings
$this->getLevel()->dropItem($this, Item::get($this->id, $this->meta & 0x03, 1));
}
if(($this->meta & 0x03) === self::OAK and mt_rand(1, 200) === 1){ //Apples
$this->getLevel()->dropItem($this, Item::get(Item::APPLE, 0, 1));
}
$this->getLevel()->useBreakOn($this);
return Level::BLOCK_UPDATE_NORMAL;
}
@ -142,19 +141,19 @@ class Leaves extends Transparent{
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
$this->meta |= 0x04;
$this->getLevel()->setBlock($this, $this, true, false, true);
$this->getLevel()->setBlock($this, $this, true);
}
public function getDrops(Item $item){
$drops = [];
if($item->isShears()){
$drops[] = array(Item::LEAVES, $this->meta & 0x03, 1);
$drops[] = [Item::LEAVES, $this->meta & 0x03, 1];
}else{
if(mt_rand(1, 20) === 1){ //Saplings
$drops[] = array(Item::SAPLING, $this->meta & 0x03, 1);
$drops[] = [Item::SAPLING, $this->meta & 0x03, 1];
}
if(($this->meta & 0x03) === self::OAK and mt_rand(1, 200) === 1){ //Apples
$drops[] = array(Item::APPLE, 0, 1);
$drops[] = [Item::APPLE, 0, 1];
}
}

View File

@ -21,18 +21,20 @@
namespace pocketmine\block;
use pocketmine\event\block\LeavesDecayEvent;
use pocketmine\item\Item;
use pocketmine\level\Level;
use pocketmine\Player;
use pocketmine\Server;
class Leaves2 extends Leaves{
public function __construct($meta = 0){
Transparent::__construct(self::LEAVES, $meta, "Leaves");
$names = array(
$names = [
self::ACACIA => "Acacia Leaves",
self::DARK_OAK => "Dark Oak Leaves",
);
];
$this->name = $names[$this->meta & 0x03];
$this->hardness = 1;
}
@ -113,13 +115,13 @@ class Leaves2 extends Leaves{
$this->meta &= 0x03;
$visited = [];
$check = 0;
if($this->findLog($this, $visited, 0, $check) === true){
$this->getLevel()->setBlock($this, $this, false, false, true);
Server::getInstance()->getPluginManager()->callEvent($ev = new LeavesDecayEvent($this));
if($ev->isCancelled() or $this->findLog($this, $visited, 0, $check) === true){
$this->getLevel()->setBlock($this, $this, false, false);
}else{
$this->getLevel()->setBlock($this, new Air(), false, false, true);
if(mt_rand(1, 20) === 1){ //Saplings
$this->getLevel()->dropItem($this, Item::get($this->id, $this->meta & 0x03, 1));
}
$this->getLevel()->useBreakOn($this);
return Level::BLOCK_UPDATE_NORMAL;
}
@ -131,16 +133,16 @@ class Leaves2 extends Leaves{
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
$this->meta |= 0x04;
$this->getLevel()->setBlock($this, $this, true, false, true);
$this->getLevel()->setBlock($this, $this, true);
}
public function getDrops(Item $item){
$drops = [];
if($item->isShears()){
$drops[] = array(Item::LEAVES2, $this->meta & 0x03, 1);
$drops[] = [Item::LEAVES2, $this->meta & 0x03, 1];
}else{
if(mt_rand(1, 20) === 1){ //Saplings
$drops[] = array(Item::SAPLING, $this->meta & 0x03, 1);
$drops[] = [Item::SAPLING, $this->meta & 0x03, 1];
}
}

View File

@ -22,13 +22,400 @@
namespace pocketmine\block;
class Liquid extends Transparent{
public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name);
$this->isLiquid = true;
$this->breakable = false;
$this->isReplaceable = true;
$this->isSolid = false;
$this->isFullBlock = true;
use pocketmine\entity\Entity;
use pocketmine\item\Item;
use pocketmine\level\Level;
use pocketmine\math\Vector3;
abstract class Liquid extends Transparent{
public $hasEntityCollision = true;
public $isLiquid = true;
public $breakable = false;
public $isReplaceable = true;
public $isSolid = false;
public $isFullBlock = true;
public $adjacentSources = 0;
public $isOptimalFlowDirection = [0, 0, 0, 0];
public $flowCost = [0, 0, 0, 0];
public function getFluidHeightPercent(){
$d = $this->meta;
if($d >= 8){
$d = 0;
}
return ($d + 1) / 9;
}
protected function getFlowDecay(Vector3 $pos){
if(!($pos instanceof Block)){
$pos = $this->getLevel()->getBlock($pos);
}
if($pos->getID() !== $this->getID()){
return -1;
}else{
return $pos->getDamage();
}
}
protected function getEffectiveFlowDecay(Vector3 $pos){
if(!($pos instanceof Block)){
$pos = $this->getLevel()->getBlock($pos);
}
if($pos->getID() !== $this->getID()){
return -1;
}
$decay = $pos->getDamage();
if($decay >= 8){
$decay = 0;
}
return $decay;
}
public function getFlowVector(){
$vector = new Vector3(0, 0, 0);
$decay = $this->getEffectiveFlowDecay($this);
for($j = 0; $j < 4; ++$j){
$x = $this->x;
$y = $this->y;
$z = $this->z;
if($j === 0){
--$x;
}elseif($j === 1){
++$x;
}elseif($j === 2){
--$z;
}elseif($j === 3){
++$z;
}
$sideBlock = $this->getLevel()->getBlock(new Vector3($x, $y, $z));
$blockDecay = $this->getEffectiveFlowDecay($sideBlock);
if($blockDecay < 0){
if(!$sideBlock->isFlowable){
continue;
}
$blockDecay = $this->getEffectiveFlowDecay($sideBlock->getSide(0));
if($blockDecay >= 0){
$realDecay = $blockDecay - ($decay - 8);
$vector = $vector->add(($sideBlock->x - $this->x) * $realDecay, ($sideBlock->y - $this->y) * $realDecay, ($sideBlock->z - $this->z) * $realDecay);
}
continue;
}else{
$realDecay = $blockDecay - $decay;
$vector = $vector->add(($sideBlock->x - $this->x) * $realDecay, ($sideBlock->y - $this->y) * $realDecay, ($sideBlock->z - $this->z) * $realDecay);
}
}
if($this->getDamage() >= 8){
$falling = false;
if(!$this->getLevel()->getBlock($this->add(0, 0, -1))->isFlowable){
$falling = true;
}elseif(!$this->getLevel()->getBlock($this->add(0, 0, 1))->isFlowable){
$falling = true;
}elseif(!$this->getLevel()->getBlock($this->add(-1, 0, 0))->isFlowable){
$falling = true;
}elseif(!$this->getLevel()->getBlock($this->add(1, 0, 0))->isFlowable){
$falling = true;
}elseif(!$this->getLevel()->getBlock($this->add(0, 1, -1))->isFlowable){
$falling = true;
}elseif(!$this->getLevel()->getBlock($this->add(0, 1, 1))->isFlowable){
$falling = true;
}elseif(!$this->getLevel()->getBlock($this->add(-1, 1, 0))->isFlowable){
$falling = true;
}elseif(!$this->getLevel()->getBlock($this->add(1, 1, 0))->isFlowable){
$falling = true;
}
if($falling){
$vector = $vector->normalize()->add(0, -6, 0);
}
}
return $vector->normalize();
}
public function addVelocityToEntity(Entity $entity, Vector3 $vector){
$flow = $this->getFlowVector();
$vector->x += $flow->x;
$vector->y += $flow->y;
$vector->z += $flow->z;
}
public function tickRate(){
if($this instanceof Water){
return 5;
}elseif($this instanceof Lava){
return 30;
}
return 0;
}
public function onUpdate($type){
if($type === Level::BLOCK_UPDATE_NORMAL){
$this->checkForHarden();
$this->getLevel()->scheduleUpdate($this, $this->tickRate());
}elseif($type === Level::BLOCK_UPDATE_SCHEDULED){
$decay = $this->getFlowDecay($this);
$multiplier = $this instanceof Lava ? 2 : 1;
$flag = true;
if($decay > 0){
$smallestFlowDecay = -100;
$this->adjacentSources = 0;
$smallestFlowDecay = $this->getSmallestFlowDecay($this->getSide(4), $smallestFlowDecay);
$smallestFlowDecay = $this->getSmallestFlowDecay($this->getSide(5), $smallestFlowDecay);
$smallestFlowDecay = $this->getSmallestFlowDecay($this->getSide(2), $smallestFlowDecay);
$smallestFlowDecay = $this->getSmallestFlowDecay($this->getSide(3), $smallestFlowDecay);
$k = $smallestFlowDecay + $multiplier;
if($k >= 8 or $smallestFlowDecay < 0){
$k = -1;
}
if(($topFlowDecay = $this->getFlowDecay($this->getSide(1))) >= 0){
if($topFlowDecay >= 8){
$k = $topFlowDecay;
}else{
$k = $topFlowDecay | 0x08;
}
}
if($this->adjacentSources >= 2 and $this instanceof Water){
$bottomBlock = $this->getSide(0);
if($bottomBlock->isSolid){
$k = 0;
}elseif($bottomBlock instanceof Water and $bottomBlock->getDamage() === 0){
$k = 0;
}
}
if($this instanceof Lava and $decay < 8 and $k < 8 and $k > 1 and mt_rand(0, 4) !== 0){
$k = $decay;
$flag = false;
}
if($k !== $decay){
$decay = $k;
if($decay < 0){
$this->getLevel()->setBlock($this, Block::get(Item::AIR), true);
}else{
$this->getLevel()->setBlock($this, Block::get($this->id, $decay), true);
$this->getLevel()->scheduleUpdate($this, $this->tickRate());
}
}elseif($flag){
//$this->getLevel()->scheduleUpdate($this, $this->tickRate());
//$this->updateFlow();
}
}else{
//$this->updateFlow();
}
$bottomBlock = $this->getSide(0);
if($bottomBlock->isFlowable or $bottomBlock instanceof Liquid){
if($this instanceof Lava and $bottomBlock instanceof Water){
$this->getLevel()->setBlock($bottomBlock, Block::get(Item::STONE), true);
return;
}
if($decay >= 8){
$this->getLevel()->setBlock($bottomBlock, Block::get($this->id, $decay), true);
$this->getLevel()->scheduleUpdate($bottomBlock, $this->tickRate());
}else{
$this->getLevel()->setBlock($bottomBlock, Block::get($this->id, $decay + 8), true);
$this->getLevel()->scheduleUpdate($bottomBlock, $this->tickRate());
}
}elseif($decay >= 0 and ($decay === 0 or !$bottomBlock->isFlowable)){
$flags = $this->getOptimalFlowDirections();
$l = $decay + $multiplier;
if($decay >= 8){
$l = 1;
}
if($l >= 8){
$this->checkForHarden();
return;
}
if($flags[0]){
$this->flowIntoBlock($this->getSide(4), $l);
}
if($flags[1]){
$this->flowIntoBlock($this->getSide(5), $l);
}
if($flags[2]){
$this->flowIntoBlock($this->getSide(2), $l);
}
if($flags[3]){
$this->flowIntoBlock($this->getSide(3), $l);
}
}
$this->checkForHarden();
}
}
private function flowIntoBlock(Block $block, $newFlowDecay){
if($block->isFlowable){
if($block->getID() > 0){
$this->getLevel()->useBreakOn($block);
}
$this->getLevel()->setBlock($block, Block::get($this->id, $newFlowDecay), true);
$this->getLevel()->scheduleUpdate($block, $this->tickRate());
}
}
private function calculateFlowCost(Block $block, $accumulatedCost, $previousDirection){
$cost = 1000;
for($j = 0; $j < 4; ++$j){
if(
($j === 0 and $previousDirection === 1) or
($j === 1 and $previousDirection === 0) or
($j === 2 and $previousDirection === 3) or
($j === 3 and $previousDirection === 2)
){
$x = $block->x;
$y = $block->y;
$z = $block->z;
if($j === 0){
--$x;
}elseif($j === 1){
++$x;
}elseif($j === 2){
--$z;
}elseif($j === 3){
++$z;
}
$blockSide = $this->getLevel()->getBlock(new Vector3($x, $y, $z));
if(!$blockSide->isFlowable and !($blockSide instanceof Liquid)){
continue;
}elseif($blockSide instanceof Liquid and $blockSide->getDamage() === 0){
continue;
}elseif($blockSide->getSide(0)->isFlowable){
return $accumulatedCost;
}
if($accumulatedCost >= 4){
continue;
}
$realCost = $this->calculateFlowCost($blockSide, $accumulatedCost + 1, $j);
if($realCost < $cost){
$cost = $realCost;
}
}
}
return $cost;
}
private function getOptimalFlowDirections(){
for($j = 0; $j < 4; ++$j){
$this->flowCost[$j] = 1000;
$x = $this->x;
$y = $this->y;
$z = $this->z;
if($j === 0){
--$x;
}elseif($j === 1){
++$x;
}elseif($j === 2){
--$z;
}elseif($j === 3){
++$z;
}
$block = $this->getLevel()->getBlock(new Vector3($x, $y, $z));
if(!$block->isFlowable and !($block instanceof Liquid)){
continue;
}elseif($block instanceof Liquid and $block->getDamage() === 0){
continue;
}elseif($block->getSide(0)->isFlowable){
$this->flowCost[$j] = 0;
}else{
$this->flowCost[$j] = $this->calculateFlowCost($block, 1, $j);
}
}
$minCost = $this->flowCost[0];
for($i = 1; $i < 4; ++$i){
if($this->flowCost[$i] < $minCost){
$minCost = $this->flowCost[$i];
}
}
for($i = 0; $i < 4; ++$i){
$this->isOptimalFlowDirection[$i] = ($this->flowCost[$i] === $minCost);
}
return $this->isOptimalFlowDirection;
}
private function getSmallestFlowDecay(Vector3 $pos, $decay){
$blockDecay = $this->getFlowDecay($pos);
if($blockDecay < 0){
return $decay;
}elseif($blockDecay === 0){
++$this->adjacentSources;
}elseif($blockDecay >= 8){
$blockDecay = 0;
}
return ($decay >= 0 && $blockDecay >= $decay) ? $decay : $blockDecay;
}
private function checkForHarden(){
if($this instanceof Lava){
$colliding = false;
for($side = 0; $side <= 5 and !$colliding; ++$side){
$colliding = $this->getSide($side) instanceof Water;
}
if($colliding){
if($this->getDamage() === 0){
$this->getLevel()->setBlock($this, Block::get(Item::OBSIDIAN), true);
}elseif($this->getDamage() <= 4){
$this->getLevel()->setBlock($this, Block::get(Item::COBBLESTONE), true);
}
}
}
}
public function getBoundingBox(){
return null;
}
}

View File

@ -31,14 +31,10 @@ class LitPumpkin extends Solid{
}
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
$faces = array(
0 => 4,
1 => 2,
2 => 5,
3 => 3,
);
$this->meta = $faces[$player->getDirection()];
$this->getLevel()->setBlock($block, $this, true, false, true);
if($player instanceof Player){
$this->meta = ((int) $player->getDirection() + 5) % 4;
}
$this->getLevel()->setBlock($block, $this, true, true);
return true;
}

View File

@ -30,8 +30,8 @@ class Melon extends Transparent{
}
public function getDrops(Item $item){
return array(
array(Item::MELON_SLICE, 0, mt_rand(3, 7)),
);
return [
[Item::MELON_SLICE, 0, mt_rand(3, 7)],
];
}
}

View File

@ -21,41 +21,31 @@
namespace pocketmine\block;
use pocketmine\event\block\BlockGrowEvent;
use pocketmine\item\Item;
use pocketmine\level\Level;
use pocketmine\Player;
use pocketmine\Server;
class MelonStem extends Flowable{
class MelonStem extends Crops{
public function __construct($meta = 0){
parent::__construct(self::MELON_STEM, $meta, "Melon Stem");
$this->isActivable = true;
$this->hardness = 0;
}
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
$down = $this->getSide(0);
if($down->getID() === self::FARMLAND){
$this->getLevel()->setBlock($block, $this, true, false, true);
return true;
}
return false;
}
public function onUpdate($type){
if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //TODO: Replace with common break method
$this->getLevel()->dropItem($this, Item::get(Item::MELON_SEEDS, 0, mt_rand(0, 2)));
$this->getLevel()->setBlock($this, new Air(), false, false, true);
if($this->getSide(0)->isTransparent === true){
$this->getLevel()->useBreakOn($this);
return Level::BLOCK_UPDATE_NORMAL;
}
}elseif($type === Level::BLOCK_UPDATE_RANDOM){
if(mt_rand(0, 2) == 1){
if($this->meta < 0x07){
++$this->meta;
$this->getLevel()->setBlock($this, $this, true, false, true);
$block = clone $this;
++$block->meta;
Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($this, $block));
if(!$ev->isCancelled()){
$this->getLevel()->setBlock($this, $ev->getNewState(), true);
}
return Level::BLOCK_UPDATE_RANDOM;
}else{
@ -68,7 +58,10 @@ class MelonStem extends Flowable{
$side = $this->getSide(mt_rand(2, 5));
$d = $side->getSide(0);
if($side->getID() === self::AIR and ($d->getID() === self::FARMLAND or $d->getID() === self::GRASS or $d->getID() === self::DIRT)){
$this->getLevel()->setBlock($side, new Melon(), true, false, true);
Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($side, new Melon()));
if(!$ev->isCancelled()){
$this->getLevel()->setBlock($side, $ev->getNewState(), true);
}
}
}
}
@ -79,23 +72,9 @@ class MelonStem extends Flowable{
return false;
}
public function onActivate(Item $item, Player $player = null){
if($item->getID() === Item::DYE and $item->getDamage() === 0x0F){ //Bonemeal
$this->meta = 0x07;
$this->getLevel()->setBlock($this, $this, true, false, true);
if(($player->gamemode & 0x01) === 0){
$item->count--;
}
return true;
}
return false;
}
public function getDrops(Item $item){
return array(
array(Item::MELON_SEEDS, 0, mt_rand(0, 2)),
);
return [
[Item::MELON_SEEDS, 0, mt_rand(0, 2)],
];
}
}

View File

@ -49,9 +49,9 @@ class MossStone extends Solid{
public function getDrops(Item $item){
if($item->isPickaxe() >= 1){
return array(
array(Item::MOSS_STONE, $this->meta, 1),
);
return [
[Item::MOSS_STONE, $this->meta, 1],
];
}else{
return [];
}

View File

@ -2,11 +2,11 @@
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
@ -21,7 +21,11 @@
namespace pocketmine\block;
use pocketmine\event\block\BlockSpreadEvent;
use pocketmine\item\Item;
use pocketmine\level\Level;
use pocketmine\math\Vector3;
use pocketmine\Server;
class Mycelium extends Solid{
public function __construct(){
@ -29,25 +33,27 @@ class Mycelium extends Solid{
$this->hardness = 2.5;
}
public function getDrops(Item $item){
return [
[Item::DIRT, 0, 1],
];
}
public function getDrops(Item $item){
return [
[Item::DIRT, 0, 1],
];
}
public function onUpdate($type){
if($type === Level::BLOCK_UPDATE_RANDOM){
//TODO: light levels
$x = mt_rand($this->x - 1, $this->x + 1);
$y = mt_rand($this->y - 2, $this->y + 2);
$z = mt_rand($this->z - 1, $this->z + 1);
$block = $this->getLevel()->getBlockIdAt($x, $y, $z);
if($block === Block::DIRT){
$block = $this->getLevel()->getBlock(new Vector3($x, $y, $z));
if($block->getSide(1) instanceof Transparent){
$this->getLevel()->setBlock($block, new Mycelium());
}
}
}
}
}
public function onUpdate($type){
if($type === Level::BLOCK_UPDATE_RANDOM){
//TODO: light levels
$x = mt_rand($this->x - 1, $this->x + 1);
$y = mt_rand($this->y - 2, $this->y + 2);
$z = mt_rand($this->z - 1, $this->z + 1);
$block = $this->getLevel()->getBlock(new Vector3($x, $y, $z));
if($block->getID() === Block::DIRT){
if($block->getSide(1) instanceof Transparent){
Server::getInstance()->getPluginManager()->callEvent($ev = new BlockSpreadEvent($block, $this, new Mycelium()));
if(!$ev->isCancelled()){
$this->getLevel()->setBlock($block, $ev->getNewState());
}
}
}
}
}
}

View File

@ -49,9 +49,9 @@ class NetherBrick extends Solid{
public function getDrops(Item $item){
if($item->isPickaxe() >= 1){
return array(
array(Item::NETHER_BRICKS, 0, 1),
);
return [
[Item::NETHER_BRICKS, 0, 1],
];
}else{
return [];
}

View File

@ -49,9 +49,9 @@ class Netherrack extends Solid{
public function getDrops(Item $item){
if($item->isPickaxe() >= 1){
return array(
array(Item::NETHERRACK, 0, 1),
);
return [
[Item::NETHERRACK, 0, 1],
];
}else{
return [];
}

View File

@ -40,9 +40,9 @@ class Obsidian extends Solid{
public function getDrops(Item $item){
if($item->isPickaxe() >= 5){
return array(
array(Item::OBSIDIAN, 0, 1),
);
return [
[Item::OBSIDIAN, 0, 1],
];
}else{
return [];
}

View File

@ -32,14 +32,14 @@ class Planks extends Solid{
public function __construct($meta = 0){
parent::__construct(self::PLANKS, $meta, "Wood Planks");
$names = array(
$names = [
self::OAK => "Oak Wood Planks",
self::SPRUCE => "Spruce Wood Planks",
self::BIRCH => "Birch Wood Planks",
self::JUNGLE => "Jungle Wood Planks",
self::ACACIA => "Acacia Wood Planks",
self::DARK_OAK => "Jungle Wood Planks",
);
];
$this->name = $names[$this->meta & 0x07];
$this->hardness = 15;
}

View File

@ -21,8 +21,6 @@
namespace pocketmine\block;
use pocketmine\item\Item;
class Podzol extends Solid{
public function __construct(){
parent::__construct(self::PODZOL, 0, "Podzol");

View File

@ -22,71 +22,18 @@
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\level\Level;
use pocketmine\Player;
class Potato extends Flowable{
class Potato extends Crops{
public function __construct($meta = 0){
parent::__construct(self::POTATO_BLOCK, $meta, "Potato Block");
$this->isActivable = true;
$this->hardness = 0;
}
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
$down = $this->getSide(0);
if($down->getID() === self::FARMLAND){
$this->getLevel()->setBlock($block, $this, true, false, true);
return true;
}
return false;
}
public function onActivate(Item $item, Player $player = null){
if($item->getID() === Item::DYE and $item->getDamage() === 0x0F){ //Bonemeal
$this->meta = 0x07;
$this->getLevel()->setBlock($this, $this, true, false, true);
if(($player->gamemode & 0x01) === 0){
$item->count--;
}
return true;
}
return false;
}
public function onUpdate($type){
if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //TODO: Replace with common break method
$this->getLevel()->dropItem($this, Item::get(Item::POTATO, 0, 1));
$this->getLevel()->setBlock($this, new Air(), false, false, true);
return Level::BLOCK_UPDATE_NORMAL;
}
}elseif($type === Level::BLOCK_UPDATE_RANDOM){
if(mt_rand(0, 2) == 1){
if($this->meta < 0x07){
++$this->meta;
$this->getLevel()->setBlock($this, $this, true, false, true);
return Level::BLOCK_UPDATE_RANDOM;
}
}else{
return Level::BLOCK_UPDATE_RANDOM;
}
}
return false;
}
public function getDrops(Item $item){
$drops = [];
if($this->meta >= 0x07){
$drops[] = array(Item::POTATO, 0, mt_rand(1, 4));
$drops[] = [Item::POTATO, 0, mt_rand(1, 4)];
}else{
$drops[] = array(Item::POTATO, 0, 1);
$drops[] = [Item::POTATO, 0, 1];
}
return $drops;

View File

@ -21,6 +21,8 @@
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\Player;
class Pumpkin extends Solid{
public function __construct(){
@ -28,4 +30,13 @@ class Pumpkin extends Solid{
$this->hardness = 5;
}
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
if($player instanceof Player){
$this->meta = ((int) $player->getDirection() + 5) % 4;
}
$this->getLevel()->setBlock($block, $this, true, true);
return true;
}
}

View File

@ -21,42 +21,31 @@
namespace pocketmine\block;
use pocketmine\event\block\BlockGrowEvent;
use pocketmine\item\Item;
use pocketmine\level\Level;
use pocketmine\Player;
use pocketmine\Server;
class PumpkinStem extends Flowable{
class PumpkinStem extends Crops{
public function __construct($meta = 0){
parent::__construct(self::PUMPKIN_STEM, $meta, "Pumpkin Stem");
$this->isActivable = true;
$this->hardness = 0;
}
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
$down = $this->getSide(0);
if($down->getID() === self::FARMLAND){
$this->getLevel()->setBlock($block, $this, true, false, true);
return true;
}
return false;
}
public function onUpdate($type){
if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
//TODO
//Server::getInstance()->api->entity->drop($this, Item::get(PUMPKIN_SEEDS, 0, mt_rand(0, 2)));
$this->getLevel()->setBlock($this, new Air(), false, false, true);
if($this->getSide(0)->isTransparent === true){
$this->getLevel()->useBreakOn($this);
return Level::BLOCK_UPDATE_NORMAL;
}
}elseif($type === Level::BLOCK_UPDATE_RANDOM){
if(mt_rand(0, 2) == 1){
if($this->meta < 0x07){
++$this->meta;
$this->getLevel()->setBlock($this, $this, true, false, true);
$block = clone $this;
++$block->meta;
Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($this, $block));
if(!$ev->isCancelled()){
$this->getLevel()->setBlock($this, $ev->getNewState(), true);
}
return Level::BLOCK_UPDATE_RANDOM;
}else{
@ -69,7 +58,10 @@ class PumpkinStem extends Flowable{
$side = $this->getSide(mt_rand(2, 5));
$d = $side->getSide(0);
if($side->getID() === self::AIR and ($d->getID() === self::FARMLAND or $d->getID() === self::GRASS or $d->getID() === self::DIRT)){
$this->getLevel()->setBlock($side, new Pumpkin(), true, false, true);
Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($side, new Pumpkin()));
if(!$ev->isCancelled()){
$this->getLevel()->setBlock($side, $ev->getNewState(), true);
}
}
}
}
@ -80,23 +72,9 @@ class PumpkinStem extends Flowable{
return false;
}
public function onActivate(Item $item, Player $player = null){
if($item->getID() === Item::DYE and $item->getDamage() === 0x0F){ //Bonemeal
$this->meta = 0x07;
$this->getLevel()->setBlock($this, $this, true, false, true);
if(($player->gamemode & 0x01) === 0){
$item->count--;
}
return true;
}
return false;
}
public function getDrops(Item $item){
return array(
array(Item::PUMPKIN_SEEDS, 0, mt_rand(0, 2)),
);
return [
[Item::PUMPKIN_SEEDS, 0, mt_rand(0, 2)],
];
}
}

View File

@ -26,12 +26,12 @@ use pocketmine\item\Item;
class Quartz extends Solid{
public function __construct($meta = 0){
parent::__construct(self::QUARTZ_BLOCK, $meta, "Quartz Block");
$names = array(
$names = [
0 => "Quartz Block",
1 => "Chiseled Quartz Block",
2 => "Quartz Pillar",
3 => "Quartz Pillar",
);
];
$this->name = $names[$this->meta & 0x03];
}
@ -55,9 +55,9 @@ class Quartz extends Solid{
public function getDrops(Item $item){
if($item->isPickaxe() >= 1){
return array(
array(Item::QUARTZ_BLOCK, $this->meta & 0x03, 1),
);
return [
[Item::QUARTZ_BLOCK, $this->meta & 0x03, 1],
];
}else{
return [];
}

View File

@ -31,12 +31,15 @@ class RedMushroom extends Flowable{
$this->hardness = 0;
}
public function getBoundingBox(){
return null;
}
public function onUpdate($type){
if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
//TODO
//Server::getInstance()->api->entity->drop($this, Item::get($this->id));
$this->getLevel()->setBlock($this, new Air(), false);
if($this->getSide(0)->isTransparent === true){
$this->getLevel()->useBreakOn($this);
return Level::BLOCK_UPDATE_NORMAL;
}
@ -48,7 +51,7 @@ class RedMushroom extends Flowable{
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
$down = $this->getSide(0);
if($down->isTransparent === false){
$this->getLevel()->setBlock($block, $this, true, false, true);
$this->getLevel()->setBlock($block, $this, true, true);
return true;
}

View File

@ -42,9 +42,9 @@ class RedstoneOre extends Solid{
public function getDrops(Item $item){
if($item->isPickaxe() >= 2){
return array(
array(Item::REDSTONE_DUST, 0, mt_rand(4, 5)),
);
return [
[Item::REDSTONE_DUST, 0, mt_rand(4, 5)],
];
}else{
return [];
}

View File

@ -26,11 +26,11 @@ use pocketmine\item\Item;
class Sandstone extends Solid{
public function __construct($meta = 0){
parent::__construct(self::SANDSTONE, $meta, "Sandstone");
$names = array(
$names = [
0 => "Sandstone",
1 => "Chiseled Sandstone",
2 => "Smooth Sandstone",
);
];
$this->name = $names[$this->meta & 0x03];
$this->hardness = 4;
}
@ -55,9 +55,9 @@ class Sandstone extends Solid{
public function getDrops(Item $item){
if($item->isPickaxe() >= 1){
return array(
array(Item::SANDSTONE, $this->meta & 0x03, 1),
);
return [
[Item::SANDSTONE, $this->meta & 0x03, 1],
];
}else{
return [];
}

View File

@ -37,22 +37,27 @@ class Sapling extends Flowable{
public function __construct($meta = Sapling::OAK){
parent::__construct(self::SAPLING, $meta, "Sapling");
$this->isActivable = true;
$names = array(
$names = [
0 => "Oak Sapling",
1 => "Spruce Sapling",
2 => "Birch Sapling",
3 => "Jungle Sapling",
4 => "Acacia Sapling",
5 => "Dark Oak Sapling",
);
];
$this->name = $names[$this->meta & 0x07];
$this->hardness = 0;
}
public function getBoundingBox(){
return null;
}
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
$down = $this->getSide(0);
if($down->getID() === self::GRASS or $down->getID() === self::DIRT or $down->getID() === self::FARMLAND){
$this->getLevel()->setBlock($block, $this, true, false, true);
$this->getLevel()->setBlock($block, $this, true, true);
return true;
}
@ -76,10 +81,8 @@ class Sapling extends Flowable{
public function onUpdate($type){
if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
//TODO
//Server::getInstance()->api->entity->drop($this, Item::get($this->id));
$this->getLevel()->setBlock($this, new Air(), false, false, true);
if($this->getSide(0)->isTransparent === true){
$this->getLevel()->useBreakOn($this);
return Level::BLOCK_UPDATE_NORMAL;
}
@ -89,7 +92,7 @@ class Sapling extends Flowable{
Tree::growTree($this->getLevel(), $this->x, $this->y, $this->z, new Random(mt_rand()), $this->meta & 0x07);
}else{
$this->meta |= 0x08;
$this->getLevel()->setBlock($this, $this, true, false, true);
$this->getLevel()->setBlock($this, $this, true);
return Level::BLOCK_UPDATE_RANDOM;
}
@ -102,8 +105,8 @@ class Sapling extends Flowable{
}
public function getDrops(Item $item){
return array(
array($this->id, $this->meta & 0x07, 1),
);
return [
[$this->id, $this->meta & 0x07, 1],
];
}
}

View File

@ -33,22 +33,27 @@ class SignPost extends Transparent{
$this->hardness = 5;
}
public function getBoundingBox(){
return null;
}
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
if($face !== 0){
$faces = array(
$faces = [
2 => 2,
3 => 3,
4 => 4,
5 => 5,
);
];
if(!isset($faces[$face])){
$this->meta = floor((($player->yaw + 180) * 16 / 360) + 0.5) & 0x0F;
$this->getLevel()->setBlock($block, Block::get(Item::SIGN_POST, $this->meta), true, false, true);
$this->getLevel()->setBlock($block, Block::get(Item::SIGN_POST, $this->meta), true);
return true;
}else{
$this->meta = $faces[$face];
$this->getLevel()->setBlock($block, Block::get(Item::WALL_SIGN, $this->meta), true, false, true);
$this->getLevel()->setBlock($block, Block::get(Item::WALL_SIGN, $this->meta), true);
return true;
}
@ -59,10 +64,8 @@ class SignPost extends Transparent{
public function onUpdate($type){
if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() === self::AIR){ //Replace with common break method
//TODO
//Server::getInstance()->api->entity->drop($this, Item::get(SIGN, 0, 1));
$this->getLevel()->setBlock($this, new Air(), true, true, true);
if($this->getSide(0)->getID() === self::AIR){
$this->getLevel()->useBreakOn($this);
return Level::BLOCK_UPDATE_NORMAL;
}
@ -78,8 +81,8 @@ class SignPost extends Transparent{
}
public function getDrops(Item $item){
return array(
array(Item::SIGN, 0, 1),
);
return [
[Item::SIGN, 0, 1],
];
}
}

View File

@ -22,12 +22,13 @@
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\math\AxisAlignedBB;
use pocketmine\Player;
class Slab extends Transparent{
public function __construct($meta = 0){
parent::__construct(self::SLAB, $meta, "Slab");
$names = array(
$names = [
0 => "Stone",
1 => "Sandstone",
2 => "Wooden",
@ -36,7 +37,7 @@ class Slab extends Transparent{
5 => "Stone Brick",
6 => "Quartz",
7 => "",
);
];
$this->name = (($this->meta & 0x08) === 0x08 ? "Upper " : "") . $names[$this->meta & 0x07] . " Slab";
if(($this->meta & 0x08) === 0x08){
$this->isFullBlock = true;
@ -46,15 +47,38 @@ class Slab extends Transparent{
$this->hardness = 30;
}
protected function recalculateBoundingBox(){
if(($this->meta & 0x08) > 0){
return new AxisAlignedBB(
$this->x,
$this->y + 0.5,
$this->z,
$this->x + 1,
$this->y + 1,
$this->z + 1
);
}else{
return new AxisAlignedBB(
$this->x,
$this->y,
$this->z,
$this->x + 1,
$this->y + 0.5,
$this->z + 1
);
}
}
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
$this->meta &= 0x07;
if($face === 0){
if($target->getID() === self::SLAB and ($target->getDamage() & 0x08) === 0x08 and ($target->getDamage() & 0x07) === ($this->meta & 0x07)){
$this->getLevel()->setBlock($target, Block::get(Item::DOUBLE_SLAB, $this->meta), true, false, true);
$this->getLevel()->setBlock($target, Block::get(Item::DOUBLE_SLAB, $this->meta), true);
return true;
}elseif($block->getID() === self::SLAB and ($block->getDamage() & 0x07) === ($this->meta & 0x07)){
$this->getLevel()->setBlock($block, Block::get(Item::DOUBLE_SLAB, $this->meta), true, false, true);
$this->getLevel()->setBlock($block, Block::get(Item::DOUBLE_SLAB, $this->meta), true);
return true;
}else{
@ -62,19 +86,19 @@ class Slab extends Transparent{
}
}elseif($face === 1){
if($target->getID() === self::SLAB and ($target->getDamage() & 0x08) === 0 and ($target->getDamage() & 0x07) === ($this->meta & 0x07)){
$this->getLevel()->setBlock($target, Block::get(Item::DOUBLE_SLAB, $this->meta), true, false, true);
$this->getLevel()->setBlock($target, Block::get(Item::DOUBLE_SLAB, $this->meta), true);
return true;
}elseif($block->getID() === self::SLAB and ($block->getDamage() & 0x07) === ($this->meta & 0x07)){
$this->getLevel()->setBlock($block, Block::get(Item::DOUBLE_SLAB, $this->meta), true, false, true);
$this->getLevel()->setBlock($block, Block::get(Item::DOUBLE_SLAB, $this->meta), true);
return true;
}
//TODO: check for collision
}elseif(!($player instanceof Player)){
}else{
if($block->getID() === self::SLAB){
if(($block->getDamage() & 0x07) === ($this->meta & 0x07)){
$this->getLevel()->setBlock($block, Block::get(Item::DOUBLE_SLAB, $this->meta), true, false, true);
$this->getLevel()->setBlock($block, Block::get(Item::DOUBLE_SLAB, $this->meta), true);
return true;
}
@ -85,13 +109,12 @@ class Slab extends Transparent{
$this->meta |= 0x08;
}
}
}else{
return false;
}
if($block->getID() === self::SLAB and ($target->getDamage() & 0x07) !== ($this->meta & 0x07)){
return false;
}
$this->getLevel()->setBlock($block, $this, true, false, true);
$this->getLevel()->setBlock($block, $this, true, true);
return true;
}
@ -116,9 +139,9 @@ class Slab extends Transparent{
public function getDrops(Item $item){
if($item->isPickaxe() >= 1){
return array(
array($this->id, $this->meta & 0x07, 1),
);
return [
[$this->id, $this->meta & 0x07, 1],
];
}else{
return [];
}

View File

@ -34,10 +34,15 @@ class SnowLayer extends Flowable{
$this->hardness = 0.5;
}
public function getBoundingBox(){
return null;
}
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
$down = $this->getSide(0);
if($down instanceof Solid){
$this->getLevel()->setBlock($block, $this, true, false, true);
$this->getLevel()->setBlock($block, $this, true);
return true;
}
@ -48,7 +53,7 @@ class SnowLayer extends Flowable{
public function onUpdate($type){
if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() === self::AIR){ //Replace with common break method
$this->getLevel()->setBlock($this, new Air(), true, false, true);
$this->getLevel()->setBlock($this, new Air(), true);
return Level::BLOCK_UPDATE_NORMAL;
}
@ -59,9 +64,9 @@ class SnowLayer extends Flowable{
public function getDrops(Item $item){
if($item->isShovel() !== false){
return array(
array(Item::SNOWBALL, 0, 1),
);
return [
[Item::SNOWBALL, 0, 1],
];
}
return [];

View File

@ -22,7 +22,7 @@
namespace pocketmine\block;
class Solid extends Generic{
abstract class Solid extends Block{
public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name);

View File

@ -22,10 +22,24 @@
namespace pocketmine\block;
use pocketmine\math\AxisAlignedBB;
class SoulSand extends Solid{
public function __construct(){
parent::__construct(self::SOUL_SAND, 0, "Soul Sand");
$this->hardness = 2.5;
}
protected function recalculateBoundingBox(){
return new AxisAlignedBB(
$this->x,
$this->y,
$this->z,
$this->x + 1,
$this->y + 1 - 0.125,
$this->z + 1
);
}
}

View File

@ -29,8 +29,8 @@ class SpruceWoodStairs extends Stair{
}
public function getDrops(Item $item){
return array(
array($this->id, 0, 1),
);
return [
[$this->id, 0, 1],
];
}
}

View File

@ -26,7 +26,7 @@ use pocketmine\item\Item;
class StainedClay extends Solid{
public function __construct($meta = 0){
parent::__construct(self::STAINED_CLAY, $meta, "Stained Clay");
$names = array(
$names = [
0 => "White Stained Clay",
1 => "Orange Stained Clay",
2 => "Magenta Stained Clay",
@ -43,7 +43,7 @@ class StainedClay extends Solid{
13 => "Green Stained Clay",
14 => "Red Stained Clay",
15 => "Black Stained Clay",
);
];
$this->name = $names[$this->meta];
$this->hardness = 30;
}

View File

@ -22,9 +22,10 @@
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\math\AxisAlignedBB;
use pocketmine\Player;
class Stair extends Transparent{
abstract class Stair extends Transparent{
public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name);
@ -36,27 +37,126 @@ class Stair extends Transparent{
$this->hardness = 30;
}
/*
public function collidesWithBB(AxisAlignedBB $bb, &$list = []){
$damage = $this->getDamage();
$j = $damage & 0x03;
$f = 0;
$f1 = 0.5;
$f2 = 0.5;
$f3 = 1;
if(($damage & 0x04) > 0){
$f = 0.5;
$f1 = 1;
$f2 = 0;
$f3 = 0.5;
}
if($bb->intersectsWith($bb2 = AxisAlignedBB::getBoundingBoxFromPool(
$this->x,
$this->y + $f,
$this->z,
$this->x + 1,
$this->y + $f1,
$this->z + 1
))){
$list[] = $bb2;
}
if($j === 0){
if($bb->intersectsWith($bb2 = AxisAlignedBB::getBoundingBoxFromPool(
$this->x + 0.5,
$this->y + $f2,
$this->z,
$this->x + 1,
$this->y + $f3,
$this->z + 1
))){
$list[] = $bb2;
}
}elseif($j === 1){
if($bb->intersectsWith($bb2 = AxisAlignedBB::getBoundingBoxFromPool(
$this->x,
$this->y + $f2,
$this->z,
$this->x + 0.5,
$this->y + $f3,
$this->z + 1
))){
$list[] = $bb2;
}
}elseif($j === 2){
if($bb->intersectsWith($bb2 = AxisAlignedBB::getBoundingBoxFromPool(
$this->x,
$this->y + $f2,
$this->z + 0.5,
$this->x + 1,
$this->y + $f3,
$this->z + 1
))){
$list[] = $bb2;
}
}elseif($j === 3){
if($bb->intersectsWith($bb2 = AxisAlignedBB::getBoundingBoxFromPool(
$this->x,
$this->y + $f2,
$this->z,
$this->x + 1,
$this->y + $f3,
$this->z + 0.5
))){
$list[] = $bb2;
}
}
}
*/
protected function recalculateBoundingBox(){
if(($this->getDamage() & 0x04) > 0){
return new AxisAlignedBB(
$this->x,
$this->y + 0.5,
$this->z,
$this->x + 1,
$this->y + 1,
$this->z + 1
);
}else{
return new AxisAlignedBB(
$this->x,
$this->y,
$this->z,
$this->x + 1,
$this->y + 0.5,
$this->z + 1
);
}
}
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
$faces = array(
$faces = [
0 => 0,
1 => 2,
2 => 1,
3 => 3,
);
];
$this->meta = $faces[$player->getDirection()] & 0x03;
if(($fy > 0.5 and $face !== 1) or $face === 0){
$this->meta |= 0x04; //Upside-down stairs
}
$this->getLevel()->setBlock($block, $this, true, false, true);
$this->getLevel()->setBlock($block, $this, true, true);
return true;
}
public function getDrops(Item $item){
if($item->isPickaxe() >= 1){
return array(
array($this->id, 0, 1),
);
return [
[$this->id, 0, 1],
];
}else{
return [];
}

View File

@ -21,8 +21,7 @@
namespace pocketmine\block;
class StillLava extends Liquid{
class StillLava extends Lava{
public function __construct($meta = 0){
parent::__construct(self::STILL_LAVA, $meta, "Still Lava");
$this->hardness = 500;

Some files were not shown because too many files have changed in this diff Show More