Compare commits

...

1580 Commits

Author SHA1 Message Date
6e6cda91ce Release 3.1.7 2018-09-11 11:45:17 +01:00
69500fe183 LightUpdate: Remove garbage left over from dab73d8950 2018-09-11 11:35:31 +01:00
c7d58db7eb Cleanup Entity age handling, fixed arrows despawning too quickly after long flight 2018-09-08 14:23:06 +01:00
a3b78236eb Server: don't catch Throwable for level ticking
this usually causes the console to get spammed with errors. Additionally, in the case where doTick() throws any exception, it's usually because we're in a state we didn't want to be in, so we really should not carry on trying to keep ticking when something breaks here. Instead, this should generate a crashdump.
2018-09-08 14:13:28 +01:00
c447d51e3f Bucket: use ItemFactory instead of self-clone
in the future Item->setDamage() will be removed.
2018-09-06 18:42:09 +01:00
b615cad22d 3.1.7 is next 2018-09-04 11:50:05 +01:00
b93e219231 Release 3.1.6 2018-09-04 11:44:05 +01:00
a4a9309193 Updated NBT dependency for bug fix 2018-09-04 11:43:38 +01:00
3a85e6cab9 Backport ce58294305 for 3.x line 2018-08-30 15:46:26 +01:00
17f1bf5512 3.1.6 is next 2018-08-29 16:08:45 +01:00
5179bb1d30 Release 3.1.5 2018-08-29 15:57:58 +01:00
6bff840293 Sync 3.1 and 3.0 branches 2018-08-29 15:55:14 +01:00
08897c6941 Release 3.0.12 2018-08-29 15:47:28 +01:00
dfe2aa9c67 Merge branch 'release/3.0' into release/3.1 2018-08-26 19:15:08 +01:00
4006be35d9 Update BinaryUtils dependency 2018-08-26 19:15:01 +01:00
c7af1cf785 Merge branch 'release/3.0' into release/3.1 2018-08-25 17:49:14 +01:00
22fcfffa53 PluginsCommand: remove useless private function 2018-08-25 16:09:51 +01:00
7dd53f2397 Replace unnecessary strlen > 0 calls with !== "" checks 2018-08-25 16:07:49 +01:00
298259b473 PluginsCommand: clean up garbage code 2018-08-25 16:05:25 +01:00
c123f2d10b SimpleCommandMap: clean up error reporting in registerServerAliases() 2018-08-25 15:43:23 +01:00
4cc7573a64 Merge branch 'release/3.0' into release/3.1 2018-08-22 15:40:43 +01:00
9d80802e53 Living: fixed some update conditions not being set 2018-08-22 15:40:32 +01:00
ec1e257e21 Entity: Fixed fire damage not taking effect in the void
this is an absurd bug that nobody would ever otherwise notice, but the problem is that the doOnFireTick() call isn't evaluated if hasUpdate is already true.
2018-08-22 15:36:31 +01:00
6fce2b3349 Merge branch 'release/3.0' into release/3.1 2018-08-19 19:52:30 +01:00
64ed8adefc Cactus: fixed place/break logic mismatch causing item spewing 2018-08-19 19:52:07 +01:00
91be5aba0c Merge branch 'release/3.0' into release/3.1 2018-08-19 16:00:25 +01:00
5df601c817 Add @see docs so PhpStorm can see dynamic constructor usages
PhpStorm can't see constructor usages when the class name is dynamic. This causes maintenance problems because cross-referencing constructors called like this doesn't show up dynamic calls.
2018-08-19 16:00:15 +01:00
1a47735d84 Merge branch 'release/3.0' into release/3.1 2018-08-19 13:59:34 +01:00
0cdf4d0c55 Spoon the TesterPlugin into the main repository
I am eating my own words this once, because having the tester plugin as a separate repository makes no sense - it is just added barriers to writing proper tests with no actual benefit. Since the tester plugin is specifically intended for CI, it doesn't make sense for it to be in its own module.
2018-08-19 13:58:13 +01:00
e6e28b74b5 Nuke the TesterPlugin submodule 2018-08-19 13:47:43 +01:00
72f46b4631 Merge branch 'release/3.0' into release/3.1 2018-08-19 11:22:51 +01:00
3892f2f404 Config: Properly prevent keys getting transformed into bools
The original regex almost completely failed at its objective, because it a) only worked if there was no value for the key, and b) did not prevent all such occurrences getting transformed, while quoting patterns that would not get transformed anyway.
2018-08-19 11:22:36 +01:00
4a1d67cb91 Merge branch 'release/3.0' into release/3.1 2018-08-17 19:47:34 +01:00
b4694092b7 Painting: fix motive not being saved 2018-08-17 19:47:26 +01:00
d99ee515c6 3.1.5 is next 2018-08-16 18:33:27 +01:00
17f7dc34be Release 3.1.4 2018-08-16 18:26:49 +01:00
a63d66c048 Sync 3.1 and 3.0 branches 2018-08-16 18:26:26 +01:00
95f6995ae0 3.0.12 is next 2018-08-16 18:25:31 +01:00
4a24d7909e Release 3.0.11 2018-08-16 18:14:04 +01:00
4e2387edc1 Merge branch 'release/3.0' into release/3.1 2018-08-16 15:52:12 +01:00
a5e38576ef ItemEntity: fixed using -1 for infinite pickup delay not working
closes #2382 (squash-merge)
2018-08-16 15:52:05 +01:00
381151dedc Merge branch 'release/3.0' into release/3.1 2018-08-15 13:48:36 +01:00
a604e6835e CoalOre: fixed ignoring silk touch for XP drops, closes #2374 2018-08-15 13:48:29 +01:00
142a6d7678 Merge branch 'release/3.0' into release/3.1 2018-08-14 15:03:22 +01:00
b2ca364de0 SplashPotion: Don't apply effects to entities which are not alive
fixes #2372
2018-08-14 15:03:15 +01:00
09ed40a921 Merge branch 'release/3.0' into release/3.1 2018-08-13 13:22:32 +01:00
565373cee6 OfflinePlayer: remove unnecessary getName() usages 2018-08-13 13:22:00 +01:00
c29723e3c4 OfflinePlayer: remove unnecessary strtolower() calls
closes #2371
2018-08-13 13:18:58 +01:00
a8811ab2b3 Fixed 1.5.0 PlayerSkinPacket protocol change that somehow disappeared
I am 100% sure I committed this change, but it isn't in the merge...
2018-08-11 19:59:44 +01:00
974583a853 Merge branch 'release/3.0' into release/3.1 2018-08-11 19:37:10 +01:00
03f8fe62d4 Fixed structure of GuiDataPickItemPacket
this changed in 1.2.0.7 beta and I didn't spot it.
2018-08-11 19:36:53 +01:00
699f35cc05 Merge branch 'release/3.0' into release/3.1 2018-08-07 18:49:06 +01:00
8fa196efc9 FallingBlock: fixed state not being saved 2018-08-07 18:48:52 +01:00
b1ab881b99 Merge branch 'release/3.0' into release/3.1 2018-08-07 14:32:28 +01:00
69c54e789a Clear the title bar when the server shutdown. 2018-08-07 14:31:39 +01:00
e33d1279fa Merge branch 'release/3.0' into release/3.1 2018-08-06 18:45:01 +01:00
9e1fa453ad Level: Fixed leak of global packets when no players are online
If a global packet was broadcasted when no players were online, it would be held in memory indefinitely (until a player joined).
2018-08-06 18:44:53 +01:00
6a05edb4e9 Merge branch 'release/3.0' into release/3.1 2018-08-05 11:33:02 +01:00
70635d0870 DropItemAction: Consider invalid if the target item is null
it's not possible to drop a null item.
2018-08-05 11:32:50 +01:00
46bd096f06 3.1.4 is next 2018-08-04 16:46:51 +01:00
51a8905fb3 Release 3.1.3 2018-08-04 16:41:16 +01:00
f954d7c3dc Bring 3.1 up to speed with 3.0 2018-08-04 16:40:40 +01:00
7ad0aa56b1 3.0.11 is next 2018-08-04 16:39:53 +01:00
1ff6f8846e disable dev flag 2018-08-04 16:30:23 +01:00
e6f53cc56b Merge branch 'release/3.0' into release/3.1 2018-08-03 20:07:46 +01:00
87f458f9bd AsyncPool: remove now-unnecessary isTerminated() call 2018-08-03 20:07:37 +01:00
5a7e575c3a AsyncPool: isCrashed() now returns true when a fatal error occurred
the fix for chunks earlier didn't fix...
2018-08-03 20:06:41 +01:00
20b37d0208 Merge branch 'release/3.0' into release/3.1 2018-08-03 18:50:14 +01:00
d6d98183ea MainLogger: Log messages and exception traces in a synchronized block
this ensures that stack traces are emitted coherently without messages from other threads landing in the middle.
2018-08-03 18:50:06 +01:00
89cf76363f Merge branch 'release/3.0' into release/3.1 2018-08-03 18:24:36 +01:00
9ff5c65fb6 Level: Make async chunk sending aware of faults
Previously any random error could occur during an AsyncTask preparing a chunk, and the Level would never know about it and thus never send the chunk.

I don't know how many invisible-chunk bug cases this fixes, but I expect it's quite a lot.
2018-08-03 18:23:32 +01:00
1532b0ef6d Level: Remove chunks from chunk send queue on unload
When a chunk request task crashes, these can get stuck and never get removed. This allows using /gc to collect the bad chunk in order to fix the bug.
2018-08-03 18:04:56 +01:00
61accee682 Merge branch 'release/3.0' into release/3.1 2018-08-02 14:43:44 +01:00
9ece971a2b Server: remove useless check from exceptionHandler()
this cannot be null... @shoghicp y u litter the code with these useless checks ???
2018-08-02 14:41:28 +01:00
5546c88f88 Server: Fixed parse errors getting reported to CA
this changed to throwing errors as of PHP 7
2018-08-02 14:40:36 +01:00
4c4761d200 back to dev 2018-07-30 15:21:10 +01:00
5492495d38 disable dev flag 2018-07-30 15:10:12 +01:00
6bef07db7c Empty merge of 3.0 into 3.1 2018-07-30 15:09:53 +01:00
e8c7ae595d back to dev 2018-07-30 15:08:32 +01:00
0d9f40873f disable dev flag 2018-07-30 14:57:51 +01:00
f7358cd7e1 Merge branch 'release/3.0' into release/3.1 2018-07-30 14:54:01 +01:00
a4aee98cba TimingsCommand: some code cleanup 2018-07-30 14:53:10 +01:00
a97c7d3132 Fix for timings 2018-07-30 14:42:16 +01:00
808d289610 Merge branch 'release/3.0' into release/3.1 2018-07-27 11:47:22 +01:00
4a1ed21e52 PluginManager: Fix patch level check to allow loading the plugin when the server's minor level is higher than the plugins declared minor level. 2018-07-27 11:46:24 +01:00
06c035bfe6 Merge branch 'release/3.0' into release/3.1 2018-07-26 14:40:24 +01:00
1b053c7928 Clean up pointless checks in Thread/Worker 2018-07-26 14:20:55 +01:00
c684f99cc4 Clean up Thread/Worker quit() 2018-07-26 14:17:01 +01:00
8d47a222b4 Merge branch 'release/3.0' into release/3.1 2018-07-26 10:25:13 +01:00
695793795e PluginManager: Remove dead $pluginParentTimer left over from 9e4d88a852 2018-07-26 10:25:01 +01:00
9f425bbe2b Merge branch 'release/3.0' into release/3.1 2018-07-25 15:30:31 +01:00
a4965842d6 Remove $handlerList from PlayerExperienceChangeEvent 2018-07-25 15:30:01 +01:00
d0339796b4 Added DATA_FLAG_SHOW_TRIDENT_ROPE 2018-07-24 17:19:06 +01:00
5e13e2e777 Merge branch 'release/3.0' into release/3.1 2018-07-21 09:53:31 +01:00
1ef6f5d166 ZippedResourcePack: Make manifest parse errors less useless 2018-07-21 09:53:16 +01:00
eccc249009 KillCommand: clean up old shitcode 2018-07-20 19:44:41 +01:00
4be36914d6 back to dev 2018-07-20 12:21:15 +01:00
e3ef1ecb30 another empty merge 2018-07-20 12:20:54 +01:00
dbaf7287bc back to dev 2018-07-20 12:20:24 +01:00
3640062142 disable dev flag 2018-07-20 12:12:26 +01:00
9af70283fd Empty merge 2018-07-20 12:11:58 +01:00
b3b240e25b disable dev flag 2018-07-20 12:05:14 +01:00
b18872fbc6 Merge branch 'release/3.0' into release/3.1 2018-07-20 11:57:06 +01:00
2b30ef1671 Revert "Living: fix knockback condition, take 2"
This reverts commit 0081e30a89.

The logic introduced by this commit is correct in MC JAVA 1.9+. Unfortunately, nobody likes 1.9+ for combat.
Some testing in MCPE vanilla made it apparent that this logic isn't correct for MCPE. The old logic is correct for pre-1.9 knockback.
2018-07-20 11:55:10 +01:00
dd8499e202 Merge branch 'release/3.0' into release/3.1 2018-07-20 11:30:27 +01:00
124ebf69c5 PlayStatusPacket: default to current protocol if not specified 2018-07-20 11:29:40 +01:00
4d1e56069d Merge branch 'release/3.0' into release/3.1 2018-07-18 15:14:27 +01:00
4274640845 Player: fixed on-ground state not being updated when walking horizontally
it's possible to walk off a tower while flying without moving vertically, and this code previously wouldn't detect that, leaving a gaping hole in the anti-cheat.
2018-07-18 15:14:18 +01:00
45d30d53cc back to dev 2018-07-17 18:33:36 +01:00
cfc8dfa369 disable dev flag 2018-07-17 18:21:02 +01:00
93a2f397c6 Merge branch 'mc-broken-ed-1.5' into release/3.1 2018-07-17 18:13:06 +01:00
62fc875cdc bump version 2018-07-17 18:12:49 +01:00
58b665985e back to dev 2018-07-17 18:09:24 +01:00
0f5c48e342 Disable dev flag for release 2018-07-17 16:59:00 +01:00
08ad5db05b Config: remove useless switch cases
CNF is the same type as PROPERTIES (it's an alias) so these cases are useless.
2018-07-17 16:56:47 +01:00
94e8623c75 Server: account for default provider being missing 2018-07-17 12:14:26 +01:00
921f7e8f6a Level: remove useless check from populateChunk()
this is already checked at the top of the function.
2018-07-16 17:36:36 +01:00
710e1d014d Entity: fixed 0-length motion vectors being passed to move()
this was an interesting bug.

This was discovered by making a projectile's drag 0, making its gravity a factor of its throw force (such that force / gravity = integer value), and then throwing it directly up. At the apex, an error would occur due to trying to do a ray trace with a zero vector.

This also led me to realize that there's an edge case in the current movement system - if an entity's motion reaches 0, it will stop getting movement updates. This can be undesirable when things such as gravity cause motion to become zero when throwing a projectile directly upwards. This will need to be fixed separately.
2018-07-16 12:08:13 +01:00
165aac1ba3 Merge branch 'release/3.0' into mc-broken-ed-1.5 2018-07-14 16:09:57 +01:00
7fc22d3227 Entity: fixed setNameTagAlwaysVisible()
mojang >.<

this doesn't fix the problem of invisibility making nametags hidden though.
2018-07-14 16:05:46 +01:00
7bfe487ee5 ConcretePowder: fixed a missed usage of Block::get() 2018-07-14 10:35:05 +01:00
d8cf835f92 BlockFactory: better handling for dodgy IDs
I thought I'd already dealt with this, but it seems not.
2018-07-13 12:31:22 +01:00
65e44364e5 Added some debug for raw packets and Query handling 2018-07-13 10:07:11 +01:00
ebbbc581ca Player: clean up cursor inventory when closing main inventory 2018-07-12 17:52:22 +01:00
8aa8280a63 Level: Make spawn protection always active regardless of op count (#2290)
I don't care if this matches PC behaviour or not. bugs.mojang.com is full of bug reports about this. Just search for "minecraft spawn protection not working" and you'll see what I mean.

If you want to disable spawn protection, actually disable it. This behaviour is something that most users are not aware of and find astonishing when they discover it.

This behaviour was copied from Minecraft PC, and it's nearly as unexpected there as it is here.

This commit reverses the stupidity done in eb0525e892.
2018-07-12 17:25:05 +01:00
6a637d9099 update pthreads version for travis 2018-07-12 17:23:52 +01:00
4a5ff32d2e hacks for NPC and floating text
I didn't think mojang could break this fucking game any worse
2018-07-11 19:45:48 +01:00
06b80a9536 Level: Make getSafeSpawn() account for non-generated chunks
fixes #2295

There is still an issue in that the spawn point will not be offset if the chunk is not generated, but this is better than the spawn point being down at y=0. The other issue is a job for another time.
2018-07-11 10:17:59 +01:00
b5dcdea6d8 Protocol changes for 1.5.0 "release"
what a piece of shit this version is...
2018-07-11 10:00:15 +01:00
b3ffce9729 back to dev 2018-07-11 09:14:38 +01:00
ce9f18c6b4 disable dev flag 2018-07-10 17:38:40 +01:00
9610c55b19 PluginManager: Skip methods not declared by instanceof Listener when registering handlers (#2293)
This is quite an interesting bug. If you have
```php
class A{
    public function onMove(PlayerMoveEvent $event){} //shouldn't be a handler because this class isn't a Listener
}

class B extends A implements Listener{}
```
then
```php
registerEvents(new B, $plugin);
```

then `A::onMove()` will be registered as an event handler even though `A` is not an instanceof `Listener`.

This was observed by noting that plugins which do something like `extends PluginBase implements Listener` causes `registerEvents()` to try and register `PluginBase` methods as event handlers, which could lead to astonishing behaviour.


then A::onMove() will be registered as an event handler even though A is not an instanceof Listener.

This was observed by noting that plugins which do something like "extends PluginBase implements Listener" causes registerEvents() to try and register PluginBase methods as event handlers, which could lead to astonishing behaviour.
2018-07-10 16:59:33 +01:00
b01b477a2a Properly fixed newline issues when parsing doc comments
fixes #2110 properly

fixed @notHandler and such not being detected when CRLF is used
2018-07-10 12:46:20 +01:00
2d454ae56f PluginManager: fixed bug in YML commands permission type checking 2018-07-08 16:19:46 +01:00
066c9d4fd4 PluginManager: simplify isPluginEnabled() 2018-07-08 16:16:39 +01:00
23829952c3 PermissibleBase: removed nonsensical code
it's not possible for this to be null, unless a child class doesn't call the constructor, and anything could break in that case anyway.
2018-07-08 13:04:51 +01:00
7ee98ff139 Config: fixed whitespace between key and = being invalid
it tolerates whitespace everywhere except here already ^.^
2018-07-08 11:54:06 +01:00
f1cab91ac9 Config: fixed interpreting invalid keys as empty strings
these should just be ignored completely.
2018-07-08 11:50:17 +01:00
e0bc9c5e96 back to dev 2018-07-07 19:20:55 +01:00
70caa00266 disable dev flag for release 2018-07-06 12:59:02 +01:00
ee7c838040 LoginPacket: barf on finding extraData multiple times
this fixes a potential exploit where clients could append JWTs signed with their own keys to the end of the chain containing fake XUID/UUID/username which would then overwrite the legitimate ones in earlier links.
This stems from the fact that the final link of the vanilla chain contains the client's own pubkey, so the client is able to append its own data to the end of the chain.
2018-07-06 12:54:43 +01:00
34e9e93210 PluginBase: fixed crashing on getConfig() when data dir doesn't exist
I considered making this instead save the default config instead of creating an empty config file, but that would be (albeit minor) a behavioural change which therefore belongs in 3.1.
2018-07-05 19:59:08 +01:00
5dbb0d177e Fixed double chest inventory desync issues, closes #2261 (#2279)
chest pairing really needs rewriting... this code really sucks
2018-07-05 17:42:30 +01:00
58f0ad3e3e Command: remove unnecessary getPermission() calls 2018-07-05 10:38:31 +01:00
0df3585c81 TellCommand: remove useless strtolower() and temp variable 2018-07-05 09:12:21 +01:00
697723b551 DoubleChestInventory: remove redundant clear() override
this calls setItem() which deals with the necessary logic anyway.
2018-07-04 20:06:42 +01:00
5926d80525 DoubleChestInventory: fixed wrong logic for setting items into the right-hand side 2018-07-04 20:04:40 +01:00
a57ec1b1ba Living: fixed death animation not being played when kill() is used
this fixes players having a random delayed despawn when using /kill on themselves
2018-06-29 16:49:40 +01:00
905259a4e1 Fixed not being able to place blocks inside dead players
closes #2265
2018-06-29 16:38:35 +01:00
ca6930006c back to dev 2018-06-29 12:30:08 +01:00
33eeeb856e disable dev flag 2018-06-29 12:21:56 +01:00
c43ce5c8fa RCONInstance: apply stfu operator 2018-06-29 12:16:17 +01:00
57cfe9fd43 Level: fixed logic for sending changed blocks to players
If there is an empty list of blocks in the changedBlocks array for a chunk, that means that blocks changed the normal way and then were later set the direct way in the same tick. This means that no action needs to be taken on these chunks.
2018-06-29 11:10:31 +01:00
d8824e7ee1 Level: discard changed blocks on chunk replace
this could cause issues when plugins replace chunks when blocks in the chunk have been changed on the same tick.
2018-06-29 11:06:33 +01:00
3455d0f3b9 Level: cleaned up some nonsensical code in setChunk() 2018-06-29 10:58:31 +01:00
6b2250cbce RCONInstance: terminate session on ECONNRESET errors 2018-06-24 17:32:51 +01:00
8dae497610 back to dev 2018-06-24 17:32:51 +01:00
cade15e2dd disable dev flag for release 2018-06-24 16:34:19 +01:00
d3e54db146 ExperienceOrb: stop tracking targets if they die while being tracked 2018-06-23 16:41:21 +01:00
0081e30a89 Living: fix knockback condition, take 2
onGround doesn't necessarily reflect 0 motion, because something else could change the motion prior to the onGround flag getting updated - for example 2 knockbacks in a row.
2018-06-23 14:30:26 +01:00
76174f1920 Explosion: avoid leaving arrows stuck in nonexistent blocks 2018-06-23 13:03:46 +01:00
dd6b5902a6 EmeraldOre: fixed not dropping XP on break 2018-06-22 21:35:58 +01:00
87852f2fe1 EmeraldOre: remove excess indentation 2018-06-22 21:31:22 +01:00
056d24c67d Add MUTTON as an ID constant
fixes crashdump #518862 - Unable to resolve "minecraft:mutton" to a valid item

PC refers to these as just mutton, but PE calls them muttonraw
2018-06-22 19:39:18 +01:00
484d34fe04 Living: Reset attack cooldown before applying post damage effects
this fixes things causing damage during post-damage calls coming back and being able to do even more damage
2018-06-22 17:47:11 +01:00
6c6630d845 Player: avoid doing some post-melee attack actions if attacking killed the attacker
This can happen when an attacker attacks a victim wearing thorns armour while having low health, which prior to this commit would cause the tool to be duplicated.
2018-06-22 17:17:40 +01:00
a5a236084f Living: don't applyPostDamageEffects() for dead mobs
this has already been seen to cause duplication bugs when thorns is used. Anything else that modifies inventory during applyPostDamageEffects() when the mob is possibly dead will also cause duplication issues.
2018-06-22 14:31:48 +01:00
641a5a5e23 fixed damaged anvils dropping the wrong items
they changed this in 1.2.13 to use regular masks instead of bitshifts. The item was fixed, but not the block.
2018-06-22 09:57:39 +01:00
ebacb8525f SignPost: fixed possible field read on null 2018-06-22 09:12:48 +01:00
579ab5866b Versions again 2018-06-22 09:12:48 +01:00
56b04fa0bb disable dev flag 2018-06-21 12:55:36 +01:00
95787c2be9 TaskScheduler: fixed tasks not getting destroyed when all tasks in scheduler are cancelled before next heartbeat
they got removed from the tasks array, but not from the queue (for performance reasons). The queue gets cleaned up by the heartbeat, but it was checking if there were things in the main array, not in the queue.

There are a couple of other bugs with cancelling tasks that this doesn't fix that are rather more complicated to deal with.
2018-06-21 12:49:08 +01:00
7b7be9618c PluginBase: fixed plugin task timings showing "Unknown" for plugin name 2018-06-21 12:05:30 +01:00
4a8232d591 MemoryManager: Fixed parent private properties not being visible in memory dumps 2018-06-21 12:03:05 +01:00
40e5a1aacb versions again 2018-06-21 12:03:05 +01:00
dbda044229 bump version 2018-06-19 18:34:19 +01:00
d2a037de71 InventoryTransaction: Avoid crashing when trying to compact slot changes with invalid slot numbers
fixes #2250
2018-06-19 18:31:13 +01:00
03510333dc Disable dev flag for 3.0.0 release 2018-06-18 19:46:23 +01:00
064e9464bc Removed --enable-profiler CLI option
krakjoe's profiler hasn't been updated since 2013. I doubt it's going to get updated in the near future. These days we use xdebug, which is either always on or always off.
2018-06-18 12:27:51 +01:00
2d3ce9e8b0 Remove some fully qualified function calls
PhpStorm can't see these or understand how they are being called, which is very annoying for bug hunting. Additionally, we already have the CodeOptimizer for this.
2018-06-18 12:23:19 +01:00
49f80830a7 Clean up unused imports 2018-06-18 12:10:27 +01:00
80daaf09b2 SendUsageTask: fixed oops x2 (thanks PhpStorm)
looks like this file was somehow missed during the refactor.
2018-06-18 12:08:55 +01:00
30ad3a1705 RCONInstance: inherit runtime-defined INI entries 2018-06-18 10:32:17 +01:00
4e7d1a7947 fixed doxyfile 2018-06-17 19:59:45 +01:00
da6439e3f4 SendUsageTask: fixed oops 2018-06-17 16:13:05 +01:00
5f2d4c36c0 Updated Language submodule 2018-06-17 13:04:34 +01:00
1f9bed275a Merged server and API version 2018-06-17 12:54:18 +01:00
77f3ca4d47 PluginManager: make isCompatibleApi() a bit less sub optimal 2018-06-17 11:13:48 +01:00
d88368ceb6 BlockBreakEvent: rename inconsistently-named function 2018-06-16 19:17:13 +01:00
f77a829a52 LevelDB: remove redundant check
Assume that entities on a chunk are not closed... none of the other providers check this
2018-06-16 18:00:26 +01:00
f315aca4c3 Tile: make saveNBT() return a CompoundTag
I don't know why I made it take a parameter for this...
2018-06-16 17:59:41 +01:00
9f7f62e9e5 Don't use Config for builtin JSON resources
it doesn't make sense to use a config in these cases, and also it just hides problems when the files are missing.
2018-06-16 16:35:47 +01:00
cc97f76ec9 Added plugin_data folder to .gitignore (#2243) 2018-06-15 12:49:08 +01:00
3b0aad38cf PocketMine.php: Stop telling noobs to use an installer that doesn't exist 2018-06-15 09:57:08 +01:00
a9b7cd1699 VersionString: Always consider dev builds less than release builds 2018-06-14 13:12:18 +01:00
37b65aac91 AutoUpdater: Use update info for build number instead of trying to parse the version number
the version number might not include the build number, particularly for releases.
2018-06-13 18:19:17 +01:00
ad7787e13b PluginLoader: fixed access protocol, updated devtools 2018-06-13 17:22:29 +01:00
7b0ce16b12 Fixed buckets being able to delete any block 2018-06-13 17:05:51 +01:00
0ff6b7b572 PluginManager: Track enabled plugins in a separate array 2018-06-13 16:54:04 +01:00
763e20ba4e Server: prevent stupidity with settings.async-workers 2018-06-13 16:44:40 +01:00
4b99285fd6 PocketMine.php: remove unused function 2018-06-13 16:33:48 +01:00
03a55d5e9d PocketMine.php: fixed pthreads version 2018-06-13 16:27:02 +01:00
fe29b89fd1 Store plugin data in <data path>/plugin_data in new installations
This will preserve the old behaviour for existing installations.
2018-06-13 12:57:41 +01:00
b0780c4d1d VersionString: Always show the patch version 2018-06-13 12:17:11 +01:00
c835c97aba Fixed phar plugins not reading resources correctly 2018-06-13 12:07:27 +01:00
78eae28a3e Updated dependencies to release versions 2018-06-13 11:17:07 +01:00
31c187f366 Bed: fixed recursion when setting state to something it already is
fixes #2236
2018-06-13 04:16:52 -04:00
2e6afa54c2 [ci skip] typo 2018-06-12 21:20:00 +01:00
e36a6dc8cc Stop RakLib spamming the console when php.ini has a bad timezone 2018-06-12 21:18:33 +01:00
2e9e44ba05 Moved JSON blobs to submodule 2018-06-12 18:49:18 +01:00
c9ec6f0a63 Remove JSON vanilla blobs in preparation for move to submodule 2018-06-12 18:45:37 +01:00
60836ebec9 Updated resources json to use base64 instead of hex 2018-06-12 18:32:26 +01:00
3def3cd502 Item: use base64 instead of hex for json encoding NBT 2018-06-12 18:31:35 +01:00
b5da6b1591 Added a pocketmine.yml kill switch for development builds 2018-06-12 17:11:01 +01:00
8a9af7bf2f Update and sync extension dependencies 2018-06-12 16:27:52 +01:00
8cfd5604cf PocketMine.php: remove 1.3 legacy things 2018-06-12 14:35:11 +01:00
f51743765d Start console reader in a more sensible place 2018-06-12 11:26:34 +01:00
0b9ce8a0d4 Remove server codename
This has long been a waste of time and creativity, and that's only going to continue to be the case now that we're going to be properly versioning. New codenames every couple of months is not worth the bother.
2018-06-12 10:51:49 +01:00
c3c360f589 Bump API to 3.0.0
This may raise a few eyebrows.

Does this mean that all the things that were planned for API 3.0.0 are done?
Not at all. The plans laid out in December 2016 for API 3.0.0 were far too ambitious, and as a result the ALPHA series dragged out forever (18 months now). This is a break away from those plans, to bring development and release flow back to some sort of sanity.

Does this mean that my plugins will stop breaking all the time now?
No, it does not! Development isn't going to stop, although breaking changes will be confined only to major API releases. It's anticipated that the major API version will be bumped as nearly as often as the ALPHA version was during the last 18 months. The reason for this return to 3.0.0 is to allow us to fine-tune our release flow so that plugin developers can get advantage of newer, non-breaking API features without having to bump the API in a breaking way.

What are the criteria for the API versions now?
- Major: This will be bumped for breaking changes, changes which will break plugins. it's expected that we'll roll out new major versions regularly.
- Minor: This will be bumped when non-breaking feature additions are made, such that API 3.0.0 plugins would still load on 3.1.0. However, plugins requiring 3.1.0 will not run on 3.0.0.
- Patch: This will be bumped for bugfix updates. Plugins requiring 3.0.0 will work on 3.0.1, but not vice versa.

TL;DR: This insanity has gone on far too long.
2018-06-12 10:39:49 +01:00
5a55d434ab Nuke plugin loaders from orbit
This features a near-total rewrite of PluginLoaders and some code associated with them.

Highlights:
- PluginManager->registerInterface() does not return anything, and now accepts a PluginLoader instance instead of a string.
- PluginLoader itself is drastically simplified. getPluginFilters(), enablePlugin() and disablePlugin() are now removed. loadPlugin() responsibilities are now solely confined to doing whatever is necessary to make the plugin's classes visible by the server, and does not emit log messages or check for data directories.
- PluginBase->init() and PluginBase->isInitialized() have been removed.
- Plugin interface now declares a signature for the constructor which implementations must comply with.
- Plugin interface now declares setEnabled().
2018-06-12 10:23:49 +01:00
19d2d6b91c PluginManager: use null coalesce in getPermission() 2018-06-11 16:38:27 +01:00
ff2e99ecdc McRegion: nbtDeserialize() cannot return null 2018-06-11 15:05:38 +01:00
07a156f5c4 BaseLevelProvider: remove leftover from b54197904d 2018-06-11 14:32:42 +01:00
13fe8ee96d PluginDescription: fix precedence issue with ?? and cast
this would cause issues if the api field was null or not found.
2018-06-11 13:53:49 +01:00
eb0276d459 Apply nullable and void typehints to events namespace 2018-06-11 13:49:16 +01:00
cfb10360ff Furnace: remove trailing whitespace 2018-06-11 13:31:05 +01:00
05af87e1d4 Strip empty lines at the end of classes 2018-06-11 13:19:23 +01:00
b3ea9606c7 Server: fixed doc comment for shutdown() 2018-06-11 12:32:38 +01:00
a080a9b75c Player: remove redundant parameter from checkNearEntities() 2018-06-11 12:25:01 +01:00
137a05c418 Player: remove useless return value from orderChunks() 2018-06-11 12:22:46 +01:00
245f5c6bef Player: remove obsolete TODO 2018-06-11 12:20:11 +01:00
3be6665e3d AsyncWorker IDs now start from 0 instead of 1
this now matches their IDs in the AsyncWorker pool, as used by submitTask().
2018-06-11 11:58:24 +01:00
8704d378d4 PluginBase::getResources() returns associative array (#2193)
Now, it has string keys, which is the path of the resource file relative to the resources folder.
2018-06-11 11:06:54 +01:00
b9718f9e87 Remove redundant second parameters for BlockFactory::get() 2018-06-11 11:03:23 +01:00
1d1e6966a2 Biome: remove useless abstract class 2018-06-11 11:00:33 +01:00
610b7bd8b0 RiverBiome: don't generate grass underwater 2018-06-11 10:58:30 +01:00
17607b8116 AsyncPool: added some void typehints 2018-06-11 10:41:40 +01:00
4c98d9d3ad AsyncPool: add a type doc to $size 2018-06-11 10:40:01 +01:00
7d5b3079bc AsyncPool: more documentation 2018-06-11 10:38:51 +01:00
88d83e0fca AsyncPool: Lazy-start AsyncWorkers when they are needed only
This changes how the AsyncPool works so that it does not immediately always start all of the workers in the pool.
Instead, workers will be started only when an idle worker was not found.
This allows for significant memory footprint reductions while idle.

In effect the async-workers setting in pocketmine.yml now dictates a _maximum_ pool size, not a fixed pool size.
2018-06-11 10:23:46 +01:00
4b221c0601 OceanBiome: don't inherit from GrassyBiome, change ground cover to gravel 2018-06-11 09:58:48 +01:00
e867427f71 Leaves: remove useless $check parameter
this is only written to and never read from.
2018-06-10 17:20:34 +01:00
c4c6c58615 Added some missing typehints 2018-06-10 17:18:55 +01:00
89643ff9af MainLogger: Added getFormat() and setFormat()
this allows plugins to easily alter the output of the console logger.
2018-06-10 10:49:12 +01:00
9657d50aeb MainLogger: workaround --disable-ansi not being respected on other threads 2018-06-10 10:24:49 +01:00
3725bea3e5 AsyncPool: Slightly reduce worker memory usage with more conservative start options
this results in a memory footprint reduction of maybe 4MB for a total of 8 workers. Not much, but it's something.
2018-06-10 10:18:07 +01:00
f3a84b332b Updated RakLib and SPL dependencies, allow any 0.3.x SPL 2018-06-09 20:13:27 +01:00
f6481eab8f Implemented an InventoryEventProcessor, fixes #1986 (#2176)
* Implemented InventoryEventProcessor, fixes #1986
Event processors can now be registered and unregistered at will. Entity inventory/armor change events are now handled by event processors instead of the inventories themselves, which allows enabling/disabling the calling of these events at will.
This now avoids stupid things happening when initializing inventory contents, since the callers for those events are now registered _after_ the contents are initialized.
2018-06-09 17:37:10 +01:00
8e5aca70b4 Entity: Avoid using close() during initEntity()
this simply conceals bugs and will cause astonishing behaviour.
2018-06-09 17:06:15 +01:00
85136b7b4a Entity: Attach to level & chunk after initEntity() call, not before
this avoids leaving garbage entities attached to chunks when exceptions are thrown during initEntity().
2018-06-09 16:59:22 +01:00
47742d74c8 Player: Drop load queue on level switch
This ensures that the player doesn't request bad chunks if it was teleported from an invalid level.
2018-06-09 16:21:41 +01:00
ca54c8d78e Merge branch 'master' of https://github.com/pmmp/pocketmine-mp 2018-06-09 16:21:01 +01:00
601811f0f8 Player: Account for the possibility of Level being null in switchLevel()
the Entity base also accounts for this, and assuming that this is automatically valid is causing lots of crashes. I am not sure of the circumstances under which this is suddenly becoming null, but this shouldn't assume that the level is valid nonetheless.
2018-06-09 16:20:51 +01:00
aeb551b317 Remove double use of spl_object_hash (#2226) 2018-06-09 14:15:50 +01:00
37b445f210 Updated Math dependency 2018-06-09 13:05:25 +01:00
d04991feb6 Level: Avoid chunk sending bugs caused by duplicate chunks with wrong coordinates
If the same chunk is set into multiple different places in the world, the chunk's position is no longer able to be relied on, because it will have the position of the last place it was set. This results in chunks not getting sent correctly when the same chunk is set in multiple places.

This avoids the bug by using known valid coordinates (using chunk hashes) to establish the real coordinates, and also adds an assert to notify developers should they unintentionally set a duplicate chunk by mistake.
2018-06-09 11:25:45 +01:00
c327b3d2c4 AsyncPool: be less dependent on Server in the code
The goal is to remove the Server things from here completely.
2018-06-08 20:08:23 +01:00
af69418a55 PlainBiome: reduce maximum elevation 2018-06-08 13:04:45 +01:00
8cd311bcb4 GroundCover: don't replace liquid with can-be-flowed-into blocks
fixes snow layers generating underwater
2018-06-08 11:15:19 +01:00
78ec3937bf BiomeSelector: drastically simplified implementation and made more robust
- Doesn't need to be pre-populated with biomes prior to calculating the heatmap - now population of biomes is entirely dependent on the lookup function, improving consistency
- Uses an abstract class method for lookup instead of callback (use anonymous class instead)
- Faster because the heatmap is directly populated with biomes instead of biome IDs, removing an unnecessary lookup.
2018-06-08 10:19:08 +01:00
4e3e807741 Biome: Added UnknownBiome class to avoid astonishing behaviour on unknown biomes 2018-06-08 10:19:08 +01:00
8c6161a4f2 Biome: make biomes list use an SplFixedArray 2018-06-08 10:19:08 +01:00
c8a87b14d5 PopulationTask: actually fix locks not getting released in generation errors 2018-06-07 23:53:59 +01:00
8fca7cc68d Apply some typehints to generators 2018-06-07 20:22:35 +01:00
45f940681a Make Normal->pickBiome() private 2018-06-07 20:21:26 +01:00
e3c97d7d5e Flat: clean up more garbage 2018-06-07 20:18:04 +01:00
172abef2a7 Flat: clean up generation of base chunk 2018-06-07 20:11:29 +01:00
709abb02e6 Generator: remove more dead incomplete code
again, this can be added when and if it's actually implemented.
2018-06-07 19:54:51 +01:00
428ca29e4b Remove dead bedrockDepth fields from generator
yes, this is not implemented yet. fields for this can be added when proper bedrock generation is implemented. For now, it's just dead code.
2018-06-07 19:52:56 +01:00
f61ad20f6b Remove a whole bunch of dead copy-pasted code from Nether generator 2018-06-07 19:51:27 +01:00
3c9af5cd6d Generator: small reduction of code duplication 2018-06-07 19:49:51 +01:00
996935e9b2 Cleaned up level seed handling 2018-06-07 19:39:24 +01:00
3707a41b67 Server: small cleanup to seed handling 2018-06-07 18:25:44 +01:00
354b2dc5d1 and an extra note just in case 2018-06-07 15:20:51 +01:00
0c70b83d81 LevelProvider: workaround bug fixed in b54197904d for previously-affected worlds 2018-06-07 15:18:42 +01:00
083a1e1ff6 GeneratorManager: Make addGenerator() throw exceptions instead of returning false 2018-06-07 14:34:26 +01:00
17b58357fb GeneratorManager: add documentation for functions 2018-06-07 14:30:19 +01:00
96a4dbb7d8 GeneratorManager: add typehints 2018-06-07 14:24:01 +01:00
5eec683110 Generator: Moved generator registering things to a separate GeneratorManager class
this isolates the concerns of the Generator class, and also removes cyclic dependencies between the Generator class and its descendents.
2018-06-07 13:48:01 +01:00
0bca3cd481 Generator: Move static noise functions to Noise instance methods 2018-06-07 13:40:10 +01:00
b54197904d Fixed imported worlds getting PM classpaths written into their level.dat for generator
This will not fix existing worlds affected by this bug.
2018-06-07 13:20:50 +01:00
fb484087a8 Entity: Remove unnecessary scheduleUpdate() call from initEntity()
this is already done by the constructor
2018-06-07 12:53:59 +01:00
14914781fc Added exception throws when a closed tile or entity attempts to schedule itself for updating
I can't believe it took so long to find what was causing these stdClass bugs.
2018-06-07 12:37:26 +01:00
fdd5b7b9c9 Entity: Fixed despawn flagging not kicking in until scheduling updates on entities 2018-06-07 12:34:23 +01:00
c83c0eb935 Entity: Move responsibility of checking for despawn to Level
this ensures that flagging for despawn will always work as intended, including when onUpdate() is overridden.
2018-06-07 12:31:21 +01:00
b331f8e1c9 AsyncWorker: added removeFromThreadStore()
and use it instead of overwriting with null things, which still occupies memory
2018-06-07 10:12:50 +01:00
ee787974f2 AsyncWorker: Use statics for thread-local worker storage instead of globals 2018-06-07 09:59:32 +01:00
73e56c8a36 Utils: Make kill() use static MainLogger instead of global variable 2018-06-07 09:29:53 +01:00
5f7c884255 Reduce AsyncWorker default memory limit to 256MB
a worker shouldn't be using as much memory as the main server thread would, so 1024MB is extremely excessive.
2018-06-06 18:49:48 +01:00
2b5e6b790f BanList: rename poorly-named parameter 2018-06-06 18:18:06 +01:00
1a21041d00 AsyncPool: Parameterize worker memory limit instead of calling back into Server 2018-06-06 18:00:56 +01:00
7b17a83227 Level: fix chunk locks not getting released on generation errors 2018-06-06 11:42:29 +01:00
edd150971e CommandReader: Use statics for thread-local storage instead of globals 2018-06-06 10:06:52 +01:00
38f4afb17c Make sure that test failures kill the build 2018-06-05 19:49:22 +01:00
9d16863b1a Convert some TesterPlugin tests into PHPUnit tests, add PHPUnit configuration 2018-06-05 19:33:21 +01:00
41a179e6e1 BlockFactory: fix bug in light filters which could result in negative light levels (and therefore wraparounds) 2018-06-05 18:12:45 +01:00
3a31c531af Level: remove unused import 2018-06-05 13:04:24 +01:00
e081b7dffa PermissibleBase: fix typehints of calculateChildPermissions() 2018-06-05 11:14:36 +01:00
0233ae1eb6 Updated TesterPlugin submodule 2018-06-04 21:17:48 +01:00
dce8ed9dd1 Eliminate more hard dependencies on MainLogger 2018-06-04 16:52:03 +01:00
35eaf38ca1 MemoryManager: parameterize an abstract \Logger to remove dependency on MainLogger 2018-06-04 13:30:48 +01:00
1d71f0cf43 AsyncWorker: added getLogger() 2018-06-04 13:29:38 +01:00
9644766df3 Merge pull request #2213: Scheduler API refactor, plugins now have their own schedulers
- Removed `Server->getScheduler()`. All plugins now have their own scheduler which is accessible using `Plugin->getScheduler()`. Aside from being syntactically more concise and pleasant, this also allows much more effective management of tasks when plugins are disabled.
- Removed `PluginTask` class. Before this PR it was necessary for plugin tasks to descend from `PluginTask` to ensure that the server could clean them up correctly on plugin disable. This is no longer necessary, so the `PluginTask` class has been removed. Plugins may now utilize the `Task` class as a base if they like.
- Added `Server->getAsyncPool()`. Since the global scheduler does not exist any more, it does not manage the server's `AsyncPool` any more. Additionally, `ServerScheduler` was previously bloated by a lot of `AsyncTask` related methods, which are now not necessary because direct access to `AsyncPool` is granted instead.

- `ServerScheduler`:
  - `ServerScheduler` has been renamed to `TaskScheduler` since it is now a general-purpose task scheduler which is non-dependent on the user. This allows much greater flexibility and also makes it possible to unit-test.
  - All `AsyncTask`/`AsyncPool` related methods have been removed - the task scheduler does not manage the async pool anymore.
    - Calls to `Server->getScheduler()->scheduleAsyncTask()` should be replaced with `Server->getAsyncPool()->submitTask()`.
    - Calls to `Server->getScheduler()->scheduleAsyncTaskToWorker()` should be replaced with and `Server->getAsyncPool()->submitTaskToWorker()`.

## Backwards compatibility
This poses significant backwards compatibility breaks for any plugins utilizing Tasks or AsyncTasks. These breaks are described above, along with basic upgrade steps. The upgrade process is quite straightforward.

## Follow-up
A large part of the goal with this pull request is to modularize these parts of the code so that they can be reused and also unit-tested. I would like to remove the existing test set from TesterPlugin at some stage when the AsyncPool can operate without a Server.

Because of the above, I am considering making further backwards incompatible changes directly to `AsyncTask` to remove the `Server` parameters from `onCompletion()` and `onProgressUpdate()`. These shouldn't be too difficult to upgrade from and can be prepared for in advance.
2018-06-04 11:54:43 +01:00
857f6dd5df Chunk: Share EmptySubChunk instance with other chunks on the same thread 2018-06-04 11:44:18 +01:00
0d177d5219 Entity: Clear dirty properties at the end of the constructor
this prevents sending duplicate properties immediately after entity spawn (due to properties getting set in the constructor).
2018-06-04 11:18:42 +01:00
fe21f0e916 Spawnable: change visibility of addAdditionalSpawnData() 2018-06-03 19:58:48 +01:00
4c1d29cdf7 Tile: remove unnecessary removeTag() calls
these CompoundTags are now ephemeral, so it's not necessary to remove potential garbage from them anymore.
2018-06-03 18:31:23 +01:00
fa21cd96c5 Tiles no longer store their NBT at runtime
This is a significant breaking change for anything utilizing Tiles as they now do not store their NBT at runtime anymore.
This is another step in the process of ridding PocketMine-MP of runtime NBT.

It can be noticed that all tiles are now using class fields to store properties instead of NBT, which is much faster, uses less memory and is also more concise when written in code.

Highlights:
- Tile->namedtag has been removed.
- Tile->saveNBT() now accepts a CompoundTag() parameter. Typically it's expected that this will be fed a newly-created CompoundTag (this part may be improved in the future).
- New internal methods Tile->readSaveData() and Tile->writeSaveData() have been added. Instead of overriding __construct() and saveNBT() to load and save properties from NBT, you should now implement these methods instead.

This is not final and will see further changes before it's done.
2018-06-03 18:29:08 +01:00
a22e5616f6 Fixed tile and furnace custom names not being visible
This is caused by the Spawnable constructor calling spawnToAll() before the tile is fully initialized. I really really really hate constructors that _DO_ things by themselves.
2018-06-03 17:02:00 +01:00
b6317fa7ce Sign: remove non-standard broken bad solution for editing
this never really worked properly and is a bad idea anyway. This was the cause of many sign-going-blank bugs before it was broken (by me), and since it's broken it's now useless. I don't think there's any practical way to make this work properly, so I leave it up to plugins to decide whether or not they want to cancel sign editing in protected areas. PocketMine-MP built-in spawn protection will already block this by default anyway.
2018-06-03 16:45:26 +01:00
b1cb63ebd6 Tile: make ContainerTrait and NameableTrait non-dependent on context-retained NBT 2018-06-03 16:32:05 +01:00
7b7917939a Cleaned up Container lock handling 2018-06-03 13:42:04 +01:00
6aaaaefd2f Make tiles less dependent on runtime NBT, use properties instead
This will ultimately culminate in the complete removal of runtime NBT, so plugins should also follow these steps if they have custom data.
2018-06-03 12:50:16 +01:00
1bb0337420 Tile: Improved Nameable and NameableTrait to cut down code duplication 2018-06-02 15:17:32 +01:00
b6b0bbde18 Level: remove nonsensical code from generateChunkCallback()
it's impossible for this to be null when we just set it to a Chunk object. It's assigned directly to the chunk index.
2018-06-01 19:47:47 +01:00
5d07f66d86 Travis: Limit worker count to 4
By default it starts 30 workers on Travis because there are 32 logical cores available. This is ridiculously excessive and pollutes the log with debug spam.
2018-06-01 18:58:30 +01:00
ec28612a12 BlockFactory: partial revert of 515e4aabc4
it's necessary to register these to fill the static property arrays. Someday these won't be necessary I hope...
2018-06-01 17:08:58 +01:00
6047810113 Level: remove useless null checks for fastDeserialize() returns 2018-06-01 17:02:29 +01:00
d535fe20a3 BlockFactory: split up static ID mapping registration from other things
this is actually HUGELY WASTEFUL on memory. An average of 3 MB is wasted per AsyncWorker on this.
2018-06-01 10:28:53 +01:00
515e4aabc4 BlockFactory: minor reduction in memory usage
removing useless array and don't pre-populate with UnknownBlock objects
2018-06-01 10:15:20 +01:00
f27c6fcf70 ResourcePack: slightly better handling of bad configs 2018-05-31 18:30:21 +01:00
7864a315f6 ResourcePackManager: cleaned up pack loading error handling 2018-05-31 17:58:47 +01:00
02b4eeeb9b TaskScheduler: Remove repeating tasks which throw exceptions 2018-05-31 14:10:59 +01:00
6b4b4e4bb1 TaskScheduler: remove redundant else branch 2018-05-31 13:01:06 +01:00
f2b8d6879f TaskScheduler: remove leftover code that makes no sense
this is impossible now that we have typehints
2018-05-31 12:52:29 +01:00
60212cef2f TaskScheduler: adjust disabled scheduler exception 2018-05-31 12:38:36 +01:00
15270f8329 Fixed plugin schedulers crashing after disable/reenable 2018-05-31 12:34:22 +01:00
05ef13b23a Merge branch 'master' into scheduler-nuke
# Conflicts:
#	src/pocketmine/level/Level.php
2018-05-31 10:40:10 +01:00
1b4723d816 AsyncWorker: don't require an attachable logger 2018-05-31 10:34:42 +01:00
c493d0e6ac Level: Stop unnecessarily initializing the generator on the main thread
this is just slowing down startup times for no good reason.
2018-05-31 10:22:44 +01:00
b3043f9552 Task: remove obsolete doc comment
not anymore sunshine
2018-05-30 21:30:43 +01:00
18fdbc2834 TaskScheduler: fix typo in isReady() parameter 2018-05-30 16:45:37 +01:00
a8c766be88 Remove TaskHandler dependency on MainLogger
This instead allows the exception to be caught by the scheduler and reported using its logger.
2018-05-30 16:00:25 +01:00
e20be3eeba Move task timings responsibility from scheduler to handler 2018-05-30 15:38:39 +01:00
51f43fb375 Removed global ServerScheduler - plugins now get their own isolated schedulers
This change breaks pretty much all API pertaining to synchronous task scheduling.

Significant changes:
- Server->getScheduler() has been removed
- Plugin->getScheduler() has been added - every plugin now has its own scheduler
- Because schedulers are now per-plugin, it is now unnecessary for PluginTask to exist because stopping plugin tasks on plugin disable is as simple as destroying the plugin's scheduler. Therefore PluginTask has now been removed and it is expected for things to now use the base Task class instead.

For the most part, plugins will simply need to change Plugin->getServer()->getScheduler()->... to Plugin->getScheduler()->...
Another highlight is that plugin tasks now no longer have global IDs - they are unique to each scheduler.
2018-05-30 14:11:11 +01:00
132746aa3d ServerScheduler: Require a Logger instance as ctor param, now non-dependent on Server
yay for unit-testing and reusability!!!
2018-05-30 12:29:19 +01:00
d03f36ebee First look at splitting up AsyncPool and ServerScheduler
This commit contains quite a few breaking changes with respect to how AsyncTasks are handled. This is necessary to allow separation of the ServerScheduler and the AsyncPool, because in the future the ServerScheduler may be removed and instead there will be isolated per-plugin sync-task schedulers - but we cannot have every plugin with its own worker pool for memory usage reasons if nothing else.

The following things have changed:
- ServerScheduler: scheduleAsyncTask(), scheduleAsyncTaskToWorker(), getAsyncTaskPoolSize(), increaseAsyncTaskPoolSize() and similar methods have all been removed. Additionally the static \$WORKERS field has been removed.
- Server: added API method getAsyncPool(). This grants you direct access to the server's AsyncPool. Calls to getScheduler()->scheduleAsyncTask() and scheduleAsyncTaskToWorker() should be replaced with getAsyncPool()->submitTask() and submitTaskToWorker() respectively.
2018-05-30 12:20:10 +01:00
7fce48d38c AsyncPool: Unstack tasks from workers before entering the below loop 2018-05-30 11:17:16 +01:00
b7ca045c51 updated TesterPlugin submodule 2018-05-29 20:11:29 +01:00
81957d133d AsyncTask: Rewrite how thread-local storage works, now non-dependent on Server or ServerScheduler
this implementation was god-awful bad and it was entirely avoidable to make it this complicated.

This utilizes the fact that pthreads treats static properties as thread-local. AsyncTask local storage now utilizes a \SplObjectStorage stored in an AsyncTask private static field.
2018-05-29 19:41:00 +01:00
299e4c8a85 ServerScheduler: remove nonsensical condition in addTask()
now that return type declarations exist, it's not possible for this to return a non-Plugin instance.
2018-05-29 18:17:49 +01:00
0a50b8cb9b Removed imports left over from 4f8f334436 2018-05-29 11:42:12 +01:00
6d53350291 Level: Moved LightPopulationTask out of generator namespace 2018-05-29 11:20:27 +01:00
ad61d70eee Level: added getBiome()
this will be needed for weather impl, amongst other things.
2018-05-29 11:10:06 +01:00
353a1d69db Level: move getHeightMap() to be more consistent 2018-05-29 11:10:06 +01:00
1d8b77f16e README: remove unnecessary and outdated section
Code dependencies can be seen in the code and in the composer.json file. Besides, there are additional third-party libraries used by PocketMine-MP now which are not listed in this section, and I don't plan to maintain it...
2018-05-29 10:42:59 +01:00
e3d2fa10a5 Item: added count parameter to pop()
this allows popping an arbitrary number of items from the stack, instead of just 1.
2018-05-29 10:21:04 +01:00
ad15ab5b42 EnchantCommand: use Item->isNull() instead of maths on ID 2018-05-28 19:45:37 +01:00
b003295d01 Player: reduce duplicated code in PlayerActionPacket handler 2018-05-28 19:38:29 +01:00
4f8f334436 Replaced usages of Math::floorFloat() with (int) floor() and Math::ceilFloat() with (int) ceil()
Once upon a time, these userland functions were faster than calling builtins, but not anymore. According to my test the Math functions are twice slower in PHP 7.2 with typehints and 50% slower without typehints.

Inlining is slightly faster than using builtins, but the difference is very small - not worth making the code look any more ugly than it does already.
2018-05-28 18:54:35 +01:00
71fdd59c4c Level: fine-tuned getCollisionCubes() a little bit
since we're getting the BBs anyway, what's the point in delegating this job to the block?
2018-05-28 17:41:12 +01:00
0a9ed059d6 Level: fixed logic of getCollisionBlocks() to match getCollisionCubes() 2018-05-28 17:40:05 +01:00
74c0863905 Living: fixed preventing effect expiry using events, closes #2208 2018-05-28 17:14:18 +01:00
87ff1c0382 Player: don't catch Throwable on transaction creation failure 2018-05-28 17:00:59 +01:00
2eaba7c936 Timings: added timings for Player->checkNearEntities() 2018-05-28 16:27:03 +01:00
3ee6bfca2a Updated Math dependency 2018-05-28 14:04:17 +01:00
63ab27550a Level: Use bitshifts instead of division in some cases 2018-05-28 14:02:32 +01:00
d612988882 Level: fixed more off-by-one errors
these are the same crap as the previous commit, but with whole chunks instead of blocks.
2018-05-28 14:00:00 +01:00
c9a0c381b1 Level: fixed logical errors in getCollisionBlocks() and getCollisionCubes()
This is the same bug that Entity->getBlocksAround() had, except this actually checks for BB intersections. What this means is that as a result of the bug, one extra layer of blocks is unnecessarily checked on the max sides of the BB.

For example:
Assume you have a BB with maxY -5.5
You're definitely colliding with block -6 (because you're inside it) and you want to check an extra block in case you hit something weird like a fence.
So you want to check _at most_ up to block -5 (inclusive).

Following this maths:
-5.5 + 1 = -4.5
ceil(-4.5) = -4

This causes us to check block -4 unnecessarily. This may be a performance waste - depending on the BB size it could be proportionally a lot of blocks getting unnecessarily checked. This has not been benchmarked.
2018-05-28 12:37:17 +01:00
982444949c Fixed typo in AsyncPool
asychronous -> asynchronous
2018-05-26 16:30:49 +01:00
8cf0fc63d8 Player: spawn at safe-spawn on level not found, instead of real spawn 2018-05-26 12:20:58 +01:00
c18ba38b74 Entity: avoid astonishing behaviour with motion vector modifications 2018-05-26 10:40:04 +01:00
3a1df1d99e LevelSoundEventPacket: added STOP_RECORD constant
this isn't actually a sound and as such doesn't have a stringy ID, so the script didn't see it.
2018-05-25 17:56:05 +01:00
8ccd13319c LevelSoundEventPacket: update constants
now with whitespace gaps generated because apparently some are missing... ugh!
2018-05-25 17:27:31 +01:00
c513d355cb Updated Snooze dependency 2018-05-25 13:52:12 +01:00
02b53785be Entity: added some new ID constants 2018-05-24 12:39:44 +01:00
9dd0ee7f05 Entity: replaced motion and lastMotion fields with vectors 2018-05-24 12:11:41 +01:00
595f1f58da Living: added knockback resistance attribute checks 2018-05-24 11:49:18 +01:00
509e8c5f6d ItemFactory: register some easy items
these are items that do nothing and/or are only used for crafting. As such they are simple to add.

Others will be added later on, but others require extra work and/or reverse engineering which I don't have time for now.
2018-05-23 19:48:30 +01:00
263cd900a8 Enchantment: update item type flags 2018-05-23 17:39:52 +01:00
164ce76ff5 Enchantment: apply typehints to PHP 7.2 standards 2018-05-23 17:28:40 +01:00
fbf760bafe Enchantment: implemented Vanishing 2018-05-23 17:23:56 +01:00
2c1afe5f2c ItemFactory: generate some TODOs 2018-05-23 13:42:19 +01:00
b109b457dc Item: added some new constants 2018-05-23 13:35:15 +01:00
e12e2897bb Enchantment: Add new constants
these aren't registered yet because they aren't implemented.
2018-05-23 12:34:58 +01:00
8f41384923 Item: remove workaround for anvils
they removed this in the 1.2.13 release. now the metadata matches the block.
2018-05-23 11:43:55 +01:00
acf29711c2 Implemented Totems, close #2198
Totem usage can be detected using the MODIFIER_TOTEM constant of EntityDamageEvent.

This does not currently support using the totem in the offhand because offhand is not implemented yet.
2018-05-23 10:06:35 +01:00
1c4dd4f280 Player: broadcast entity event to self as well when sending to all viewers
this fixes several bugs with entity events and removes the need for a hit animation hack.
2018-05-23 09:28:46 +01:00
faa88a55e4 EntityDamageEvent: break API
The general purpose of this is to split up base damage from modifiers.

- Added methods getBaseDamage(), setBaseDamage(), getOriginalBaseDamage(), getModifiers(), getOriginalModifiers()
- setDamage() renamed to setModifier() and type is now mandatory
- getDamage() renamed to getModifier() and type is now mandatory
- getOriginalDamage() renamed to getOriginalModifier() and type is now mandatory
- Removed MODIFIER_BASE constant
- Constructors now accept: float baseDamage, float[] modifiers instead of just float[] modifiers
2018-05-22 19:05:25 +01:00
c9ed517063 Merge branch 'release/alpha12' 2018-05-22 18:50:24 +01:00
28b0f5f86a UpdateBlockSyncedPacket: rename field 2018-05-22 18:49:41 +01:00
e87e2d4e52 UpdateBlockSyncedPacket: fix field visibility 2018-05-22 18:49:41 +01:00
86c27953ec NetworkBinaryStream: bail on unknown entity data types 2018-05-22 16:44:03 +01:00
5552704922 PluginBase->getResources() should only return files
Directories should not be returned. Previously it even returns resources\.. according to my test on Windows.
2018-05-21 17:25:57 +08:00
c7ac5dfd4b Fixed the doc comment in Plugin::getResources()
It returns SplFileInfo[] not string[]
2018-05-21 17:24:12 +08:00
bd9b59f401 Contributing: be more clear about committing on GitHub 2018-05-21 09:59:56 +01:00
2f03f5f6d5 Fix a grammar error in Player (#2197) 2018-05-20 21:27:40 +01:00
f4a26ddfd9 update Composer dependencies to get Snooze asserts
warning: there are bugs in this code! this will crash and burn without warning!!!!!
2018-05-20 12:57:23 +01:00
adb9390b53 Entity: Rename isInsideOfWater() to isUnderwater() 2018-05-19 18:10:43 +01:00
6111ce7df1 Human: don't hardcode max food 2018-05-19 16:48:21 +01:00
1f73c08762 Human: fix possible bug with food ticking
it updates it but doesn't take note of the updated value, which could cause the code below to be erroneously triggered.
2018-05-19 16:47:04 +01:00
2900167ffa Human: removed redundant isSprinting() check from doFoodTick()
this is checked in setSprinting() anyway.
2018-05-19 16:33:13 +01:00
11cc9f19ad Human: replace hardcoded difficulty values with constants in doFoodTick() 2018-05-19 16:32:30 +01:00
807af2e6fb Human: change doFoodTick() visibility to protected 2018-05-19 16:30:41 +01:00
f2511983cf Level: use increment operation for updating time 2018-05-19 16:05:08 +01:00
bac649137b Level: fixed doc comment for getSafeSpawn() 2018-05-19 14:02:54 +01:00
71224f51d5 Level: cleaned up some nonsensical code in getSafeSpawn()
it's impossible for this function to return false because $spawn is guaranteed to be a Vector3 when it's checked in instanceof.
2018-05-19 13:18:20 +01:00
6c3fc4af46 Level: switch order of addEntity() and removeEntity()
now it's consistent with addTile() and removeTile()
2018-05-19 13:14:11 +01:00
75d13be38e EnderChestInventory: remove unused import 2018-05-19 11:37:22 +01:00
9bc860f7a8 LevelDB: fixup extra-data handling, don't delete it - just don't read it
we'll need this once multi-layer block storages are implemented.
2018-05-19 11:35:54 +01:00
66963fbf9a Nuke block extradata
this has been superseded by multi-layer blockstorages in 1.2.14+
2018-05-19 11:03:28 +01:00
172c6420c1 Server: add type documentation for fields
found a few bugs in the process too
2018-05-19 10:55:34 +01:00
e7fc9227bc Server: fixed bug in alwaysTickPlayers config 2018-05-19 10:53:31 +01:00
13cd0cdcfd Server: cast result of getProperty() for networkCompressionAsync 2018-05-19 10:52:09 +01:00
0bb5e88b5c Hinting up Entity API to PHP 7.2 standards 2018-05-19 10:46:47 +01:00
389990e0a8 Entity: remove useless functions
these may be TODOs but I have no idea why or where they need to be implemented, so until they do they are useless clutter.
2018-05-18 20:09:55 +01:00
067aad9546 PocketMine.php: Remove unused \pocketmine\ANSI constant
Terminal::hasFormattingCodes() should be used instead (this is also portable across threads even if constants aren't inherited by child threads, provided that the child thread has an autoloader available.
2018-05-18 18:51:18 +01:00
b1a7606e82 PocketMine.php: Take dependency versions for granted
Since this is managed by Composer now, it's expected that users should install dependencies appropriately when running from source code. We have a few more dependencies than just RakLib and SPL which are version-critical which are not checked here, and I don't have the taste for adding more version checks here.

A better way would be to automatically detect outdated Composer autoloader and warn that dependencies might need updating, but I'm not sure how to do that off the hop. Users should prefer using prebuilt phars anyway - only developers and/or people who know what they are doing should be running the server from source code.
2018-05-18 18:47:12 +01:00
febba6e3a6 Tile: call parent constructor instead of duping code 2018-05-18 16:49:14 +01:00
d8dc89e7c8 EnderChestInventory: Removed unnecessary owner parameter 2018-05-18 16:46:48 +01:00
b75413e3c4 CommandReader: Use stream_isatty() instead of posix_isatty() (new in 7.2) 2018-05-18 16:46:48 +01:00
f08537a1e0 BlockMetadataStore: fix case of import
found by PHPStan static analysis tool
2018-05-18 16:46:48 +01:00
6643fa5f09 README: it's not Pocket Edition anymore 2018-05-18 14:54:50 +01:00
210e108574 Level: add a null coalesce
meant to add this before push but wasn't thinking clearly...
2018-05-18 11:28:52 +01:00
813437e3ee Level: Avoid unnecessary use of getChunk()
this is completely pointless.
2018-05-18 11:27:53 +01:00
24295ce02f Level: Avoid creating useless throwaway objects in sensitive functions 2018-05-18 11:05:41 +01:00
29fd26627e Level: Change isInWorld signature to use ints instead of floats
this is only used in one place, where it's being given floats, and it's 10% faster to use int for this because it won't convert it.

It is also 25% faster to remove typehints and 60% faster to inline it. We really need a proper PHP preprocessor for inlining.
2018-05-18 11:01:13 +01:00
22b91aaa24 SubChunkIteratorManager: Added method invalidate() to allow destroying stale chunk refs conveniently
this could be necessary for reusable long-life iterators when chunks get replaced.
2018-05-18 09:52:27 +01:00
f757ba1851 Merge branch 'release/alpha12' 2018-05-17 19:27:26 -04:00
8c1c8f34cc Player: confine command data resending on permission recalculate to post-spawn only
this fixes crashes when PurePerms causes this to be recalculated on player login - the client doesn't like receiving this before StartGame and crashes.

Confining this to post-spawn should not cause any issues since any permission recalculation in login events will be reflected immediately afterwards when the initial command data is sent anyway.

This same bug popped up at 1.1... I don't know why it wasn't fixed properly back then.
2018-05-17 19:26:42 -04:00
c285295037 Merge branch 'release/alpha12' 2018-05-17 18:40:24 +01:00
2034caf71c Merge branch 'mcpe-1.4.0-alpha12' into release/alpha12 2018-05-17 18:38:58 +01:00
89ccac7a8c updated blockIDs table 2018-05-17 16:17:26 +01:00
f6e71d8296 Protocol changes for 1.4.0 release
this is nearly the same as 1.5.0.0, except the skin packet premium boolean has been dropped.

This isn't production ready yet because the blockID table needs updating (waiting on MrARM to fix his script for that).
2018-05-17 10:36:16 +01:00
b333a0e24c PlayStatusPacket: add new constant 2018-05-17 10:33:18 +01:00
8312ad709e InventoryTransaction: Removed creationTime
this is no longer necessary because transactions now always arrive in a single packet.
2018-05-16 12:14:29 +01:00
63fc04b3dd thanks for being useless PhpStorm 2018-05-13 11:56:32 +01:00
34b8557094 Moved parseDocComment from PluginManager to Utils 2018-05-13 11:24:04 +01:00
edaef588ab CommandReader: remove unnecessary setClassLoader() call
this is already handled in start() anyway.
2018-05-12 12:47:28 +01:00
889222e9c5 MainLogger: Use PTHREADS_INHERIT_NONE
this thread doesn't need to inherit anything because its sole purpose is to write log messages to file.
2018-05-12 12:39:13 +01:00
8239c67b1a Enchantment: split up primary and secondary flags
closes #1911
2018-05-12 11:20:27 +01:00
ed65e91a3c Tree: avoid astonishing behaviour with dark-oak and acacia saplings
ref #1973, these should simply not grow at all since they are not implemented yet.
2018-05-12 10:03:20 +01:00
619390c5b7 Sapling: Account for light level when trying to grow on random ticks 2018-05-11 09:53:03 +01:00
7e70569ba2 Player: Send all open inventories instead of hardcoded selection
Players have a few associated inventories which might need sending nowadays, such as main, armour, offhand (not implemented yet), cursor, crafting (if it ever worked). Under these conditions we should be sending all open windows.
2018-05-11 09:28:59 +01:00
083ac8a770 Clean up Tool garbage leftovers
these were intended to be removed long ago, but other things came up and durability handling still depended on them.
2018-05-11 09:23:51 +01:00
b21572774a Tool: cleanup durability handling, closes #379
long overdue... this isn't quite as extensible as the original api3/blocks system was, but this is primarily intended to replace Item->useOn(). If plugins want to use it it can be extended later on.
2018-05-10 19:48:51 +01:00
b8523cb304 Merge branch 'remove-weak-position' 2018-05-10 13:53:07 +01:00
6ceb9af749 .-. 2018-05-10 12:51:39 +01:00
bcd197d7bb AsyncWorker: fixed __construct() signature 2018-05-10 12:50:09 +01:00
3148f692c1 AsyncWorker: No need to register static logger - it's inherited by default with pthreads 3.1.7 2018-05-10 12:49:03 +01:00
d8d22efc3b Server: avoid abusing Throwable in a couple of places 2018-05-10 12:46:13 +01:00
7b3653f75d SetupWizard: remove dead constant 2018-05-10 12:39:15 +01:00
9c5f7128a4 RCON: lots of cleanup, now notification-based instead of poll-based
This now utilizes Snooze in order to have the server wake up to process RCON commands ondemand, similar to how the CommandReader thread operates. This is better for performance and response times.

This also makes a few other changes:
- RCON thread will now waste less CPU since it uses a blocking select() with timeout to read
- Following from that, IPC sockets are used to allow interrupting select() from the RCON thread.
- Multiple threads for RCON has been removed (this is entirely unnecessary, reading data from sockets is not CPU-intensive, and a single thread is easier to work with)
2018-05-10 12:33:05 +01:00
1e4a97f921 Server: remove dead code from forceShutdown() 2018-05-10 11:30:50 +01:00
4d743ade45 CrashDump: resource hygiene 2018-05-10 11:29:16 +01:00
78b5cc993b Server: fixed signatures and type-checks for logger
this might not be a MainLogger instance, but it definitely has to be an \AttachableThreadedLogger instance.
2018-05-10 10:49:41 +01:00
5e91c05424 Server::getIp() now returns 0.0.0.0 if the IP string is empty 2018-05-10 10:25:44 +01:00
e7c5d14af3 Fix DoubleSlab name (#2177) 2018-05-09 21:17:35 +01:00
126a97b405 ServerKiller: fixed start/stop race condition
in some cases the main thread was trying to signal the server killer to stop before it was even started due to limited resources available for scheduling.
2018-05-09 20:59:56 +01:00
753ed3801d update RakLib version 2018-05-09 20:18:36 +01:00
68ef4b210d Allow RakLibServer to inherit constants (PATH const is needed for exception logging)
this is very annoying and needs a better fix.
2018-05-09 20:08:25 +01:00
c3822b795c CommandReader: use PTHREADS_INHERIT_NONE
probably not necessary to register autoloader, but just in case...
2018-05-09 20:02:51 +01:00
be0e85dfae CommandReader: fix notifier race condition crash, don't start self in constructor
self-start is extremely annoying!
2018-05-09 20:01:16 +01:00
72690ea7f5 RakLibInterface: start RakLibServer with PTHREADS_INHERIT_NONE
this is now OK since the logger colours will be initialized on the fly.
2018-05-09 20:00:09 +01:00
c9bd60123b Scheduler: shutdown async pool properly instead of relying on ThreadManager 2018-05-09 19:49:12 +01:00
05f4262e81 MainLogger: moved format to private variable 2018-05-09 18:14:46 +01:00
dd11bcaf11 Fixed #1979: logger colours don't show on other threads when classes are not inherited 2018-05-09 18:07:12 +01:00
b96adda14d MainLogger: Colorize at point of echo, not beforehand
this removes the need for a hack I had to do with ClientConsole to translate ANSI colour codes back into MC colour codes.
2018-05-09 18:04:16 +01:00
5c66c615bf Living: fix possible crash in getTargetBlock()
ArrayOutOfBoundsException is not thrown by SPL anymore since the exception handler throwing it was removed by @shoghicp. Regardless, it seems cleaner to to check it properly.
2018-05-09 17:11:37 +01:00
2ff2a2de08 FormattedCommandAlias: use multiple catch clauses 2018-05-09 16:58:55 +01:00
78f8d54f89 Merge branch 'release/alpha12' 2018-05-09 16:53:41 +01:00
5b6762d0d5 Fixed lang submodule version 2018-05-09 14:53:22 +01:00
2a0a2134d1 Server: Implemented an signal/sleep interrupt mechanism for ticking (#2171)
This allows other threads to notify the main thread to wake it up while it's sleeping between ticks, allowing reduction of processing latency.

Currently only RakLib and the CommandReader threads utilize this, but it's planned to extend it to more things in the near future.

CommandReader is now event-driven instead of poll-based - the server will not poll the CommandReader thread for messages each tick anymore.

RakLib utilizes this mechanism to get packets processed without delays to lower latency.

This now adds an extra dependency - `pocketmine/snooze` library contains the meat of the code used for this. See the Snooze repository for details.
2018-05-09 14:18:13 +01:00
e70af362d0 RCONInstance: fixup bad continues 2018-05-07 13:55:23 +01:00
24aab8365e RCONInstance: remove redundant size ref param from readPacket() 2018-05-07 13:53:34 +01:00
0e5504ed3f RCONInstance: add docs to fields, make 'stop' private 2018-05-07 13:52:33 +01:00
83008440c0 RCONInstance: replace hardcoded status values with constants
I thought I'd seen the worst of PM, but I haven't.........
2018-05-07 13:44:59 +01:00
b14dfa9f7e RCONInstance: Remove pointless code that makes pthreads segfault
pthreads doesn't play well with resources, and this code upsets it. Also, this code is utterly pointless.

The whole of RCON needs burning to the ground...
2018-05-07 10:05:05 +01:00
197102ca3d Level: fixed blocks not dropping when not broken by player
closes #2172
2018-05-05 21:50:28 +01:00
f497e43db3 SourceInterface: removed redundant return value from process() 2018-05-05 15:30:46 +01:00
38c3f00ef7 avoid crashes when XUID is null 2018-05-05 13:33:13 +01:00
396056c636 Sign: Pad exploded blob to appropriate size
I'm not sure how it's possible to get one of these blobs with less newlines than expected, but whatever I guess
closes #2152
2018-05-04 23:29:32 +01:00
dd1dfefd83 ItemEntity: remove unnecessary damage types restrictions
Invalid damage types are all restricted by other means anyway. This fixes items not getting killed by fire (close #2143) and cacti.
2018-05-04 22:57:28 +01:00
68638f9779 Fixed translations
Apparently the translation type doesn't translate unless this flag is set now...
2018-05-04 22:14:02 +01:00
7565b786e7 Implemented @notHandler annotation for event handlers - skip registering any handlers with this annotation (#2164)
It is somewhat reasonable to have a function in an event handler which accepts an Event parameter, but is not a handler. For example, multiple event handlers can redirect to the same function to process an event, but this function may not want to receive called events.

There are other ways to get around this, such as making the event handler protected/private, or adding a dummy parameter, but this way is cleaner and more explicit.

Relevant old-repo PR: PocketMine/PocketMine-MP#2143
2018-05-04 21:36:58 +01:00
ae0c1c185f Fixed wrong doccomment for Permission::$children 2018-05-04 15:31:00 +08:00
723251e800 Fixed bug in commit hash detection when output ends with newline 2018-05-03 16:37:05 +01:00
295016cbc1 DisconnectPacket: fix decoding 2018-05-02 16:56:48 +01:00
8228774ad4 Remove extra data, this time without API breaks
this is necessary because the next MCPE release will probably be made before the next PM release.
2018-05-02 12:08:44 +01:00
2a54726905 Updated runtimeIDs table
from https://github.com/MCMrARM/minecraft-block-ids/blob/master/blocks_270.json
2018-05-02 12:03:29 +01:00
8b225fc4ef New entity metadata flags and properties 2018-05-02 12:03:29 +01:00
a014b44b69 New PlayerActionPacket constants
anyone know what these are for? something to do with riptide but I didn't manage to find out what...
2018-05-02 12:03:29 +01:00
c7544c1d25 AvailableCommandsPacket: update arg types 2018-05-02 12:03:29 +01:00
eb28622823 Protocol changes for 1.5.0.0
this feels so strange to type... can we ditch the versioning system already?
2018-05-02 12:03:29 +01:00
68494f1c0d CraftingDataPacket: decode chemistry recipes correctly 2018-05-02 12:03:29 +01:00
27ea0d360f updated block IDs table
minified, from https://github.com/MCMrARM/minecraft-block-ids/blob/master/blocks_260.json
2018-05-02 12:03:29 +01:00
d384df1f2e fixed some mistakes in the protocol 2018-05-02 12:03:29 +01:00
fe8102c062 Silence another stupid spam bug 2018-05-02 12:03:29 +01:00
8b15d85469 bump versions for 1.2.20.1 beta 2018-05-02 12:03:29 +01:00
a5ba716232 Updated block ID mappings for 1.2.14 (thanks again MrARM) 2018-05-02 12:03:29 +01:00
db432bb024 Found some things in new packets 2018-05-02 12:03:29 +01:00
91486a23a5 some changes for 1.2.14.2 beta 2018-05-02 12:03:29 +01:00
d80c471ae1 Typehints on missed sound and particle APIs 2018-05-02 11:44:18 +01:00
b4068dfd2f remove unused import 2018-05-02 10:44:05 +01:00
3095eb544d Item: removed isTool()
this should be replaced with `instanceof Tool`.
2018-05-01 20:05:53 +01:00
0247dff909 Fixed mis-uses of Item->isTool()
this has been wrongly used to indicate a durable item, but not just tools are durable items.
2018-05-01 20:05:02 +01:00
5368120f13 Level: remove redundant getAutoSave() condition in close()
this is already checked by save() anyway.
2018-05-01 18:47:08 +01:00
2e7db552dc Level: __construct() now accepts a LevelProvider object instead of string, string
This is made possible by the removal of LevelProvider dependence on their Levels, and furthers the goal of #2024.
2018-05-01 18:43:11 +01:00
53c35aaa1d Server: remove unused variable from generateLevel() 2018-05-01 18:26:03 +01:00
3293074cfc Implement @softDepend annotation for event handlers - skip registering if the event class is undefined (#2162)
This allows plugins to soft-depend on other plugins without separating their listeners into a dedicated class for listening to that plugin.

This can be utilized by adding a `@softDepend PluginName` to the event handler's annotations.
If the plugin providing the event does not exist or is not loaded, then the handler will silently not be registered.
If it does exist and the event is not found, the original behaviour applies and an exception will be thrown.

This change should be fully backwards compatible.
2018-05-01 14:33:24 +01:00
d8f4dde5f3 PlayerHotbarPacket: remove unused import 2018-05-01 14:09:17 +01:00
dfa6cd2b7e Biome: Moved biome classes from level\generator\* to level\biome 2018-05-01 14:07:46 +01:00
e03d2b23f7 Sign: add some typehints where it wasn't previously possible 2018-05-01 14:00:23 +01:00
96a2fd7482 Server: fixed wonky doc comment for broadcastTitle() 2018-05-01 12:30:06 +01:00
88c56bcdc8 Server: move formattingCodes check to initial assignment of doTitleTick 2018-05-01 12:21:41 +01:00
2731fc3d0f Server: remove redundant return value from tick() 2018-05-01 12:17:11 +01:00
a02f178f80 PocketMine.php: add git hash length check "just in case" 2018-04-29 18:07:40 +01:00
96d26a77a1 Explosion: set block damage to zero on destruction 2018-04-16 14:30:54 +01:00
554fe4d14d Updated dependencies, require 64-bit PHP in composer.json 2018-04-16 10:19:17 +01:00
532269a484 Implemented block break XP drops 2018-04-15 19:03:18 +01:00
1e2122d854 avoid crashing in forceShutdown() if properties wasn't initialized yet 2018-04-14 12:45:03 +01:00
c276ef2b7f Updated dependency versions 2018-04-13 20:09:18 +01:00
5138bdc4bd Updated DevTools submodule 2018-04-13 17:38:51 +01:00
a30a157d8c API bump to 3.0.0-ALPHA12
Yes, I am not happy about this either. new-versioning has issues, and there hasn't been enough development and testing on it.
I didn't want to delay release to cram in a half-baked new versioning system, and it's ended up delayed anyway and new-versioning is still half-baked.
we're overdue a new release, so here it is.
2018-04-13 13:31:15 +01:00
e565cdeea4 Tile: remove unnecessary createAdditionalNBT() things
these things are filled in by the tiles' constructors anyway.
2018-04-13 11:50:04 +01:00
556a465c05 Container tiles: remove unnecessary ListTag Items creation
the existence of this tag is checked for anyway.
2018-04-13 11:27:11 +01:00
280f2b7259 always loose imports... 2018-04-13 11:25:52 +01:00
933b0e8b41 Furnace: cleanup, stop abusing NBT, stop spamming packets 2018-04-13 11:22:47 +01:00
58279d4cfe NetworkBinaryStream: fixed not decoding items with negative IDs correctly
negative IDs are used for new block-items.
2018-04-11 13:01:41 +01:00
1e21066c1c Server: remove redundant == true from setConfigBool() 2018-04-10 12:22:21 +01:00
76854da7ba Command: remove dead field 2018-04-10 12:11:27 +01:00
46cbcb0c42 Fixed fire with no nearby flammable blocks burning for too long 2018-04-10 10:07:14 +01:00
af9b0b019d Added BlockBurnEvent 2018-04-10 10:04:11 +01:00
7db8845375 Fire has a 1/3 chance of aging on a random or scheduled tick 2018-04-10 09:59:54 +01:00
f47f593555 Level: Removed fire hack from destroyBlockInternal()
this was causing unexpected behaviour particularly on burning trees, whereby fire would be unconditionally extinguished if the block below it was removed.
2018-04-10 09:59:40 +01:00
691df5c11d FlintSteel: remove instanceof Solid check
This makes the behaviour match vanilla. This will now allow Fire block itself to handle deletion of itself when the area is not suitable (now that the logic is implemented in Fire for this).

This allows attempting to place in invalid conditions, which is as expected. This will produce the sound and flash as per vanilla, as the fire extinguishes itself.
2018-04-10 09:59:27 +01:00
9a1d3aec6b Flammable blocks adjacent to fire now burn away
There are some strange bugs with blockupdating causing invisible client-side-only fires that need to be investigated.
2018-04-10 09:59:10 +01:00
670a53ba3b Fire: fixed logic of extinguishing 2018-04-10 09:58:58 +01:00
f22ad14c67 Block: added isFlammable() 2018-04-10 09:58:35 +01:00
64540f36be Block: added burnsForever() 2018-04-10 09:58:21 +01:00
e66b1953de Block: added flame encouragement and flammability properties 2018-04-10 09:58:08 +01:00
aa6666872a BlockFactory: added a hack for weird air blocks with non-zero damage values
I don't know what causes this to occur, but they should never have non-zero damage values, so we discard the metadata.
2018-04-09 16:35:31 +01:00
646455f6e8 fixed painting particles, removed DestroyParticle
it didn't last long because they changed how this works... yuk
2018-04-09 16:26:15 +01:00
05a1e61e5b Painting: polyfill height and width 2018-04-09 16:20:46 +01:00
5f52e00213 Fixed plugin loaders trying to load plugins they aren't able to load
closes #2125

This is an API break for things implementing the PluginLoader interface.
2018-04-09 15:54:20 +01:00
476ac39988 update PHP version requirements in composer files 2018-04-09 15:50:55 +01:00
5f1ae1059e Move min required PHP version to 7.2.0 2018-04-09 15:37:56 +01:00
08d8adae5b fixup some ResourcePack TODOs 2018-04-07 13:09:44 +01:00
8d988af7db EntityLink: added type constants 2018-04-07 11:35:36 +01:00
db5890fddb Rename more unknown things in the protocol 2018-04-07 11:35:35 +01:00
5b532fdcf5 Clean up on AddHangingEntityPacket and AddPaintingPacket
AddPainting is a subclass of AddHangingEntity in vanilla.
2018-04-07 11:35:35 +01:00
e85fc54037 LevelSoundEventPacket: found unknown field
wtf mojang
2018-04-07 11:35:35 +01:00
7fb237938c EntityLink: rename unknown field
close #1465
2018-04-07 11:35:35 +01:00
9a5f9c8586 PlayerListPacket: fixup on platformChatId stuff 2018-04-07 11:35:35 +01:00
4b16be7e0b PlayerListEntry: remove leftover TODO 2018-04-07 11:35:35 +01:00
47faf5a994 Human: Add support for 128x128 skins in isValidSkin() (#2140) 2018-04-07 09:00:08 +01:00
3f31f6d310 TimeCommand: Use Level constant instead of hardcoded value 2018-04-05 15:41:59 +01:00
c06c1c7ce0 Human: Added a hack for nametags
Apparently NAMETAG metadata is useless in AddPlayerPacket now, so it has to be sent separately.
2018-04-05 11:56:44 +01:00
a889a0e517 Workaround for player hitbox bug on respawn
this happens when a player respawns before their death animation ends. I don't know why, but their bounding box height suddenly becomes zero. This solves the bug by simply resending the height and width properties to viewers on respawn.

Closes #2135.
2018-04-04 20:11:16 +01:00
9ed0d9d36f added some data properties 2018-04-04 19:40:12 +01:00
3134fa2744 Fixed FloatingTextParticle YET AGAIN
how many fucking ways can you break nametags Mojang???
2018-04-04 16:59:39 +01:00
2660448601 Crafting: Match recipe based only on transaction inputs/outputs
As of 1.2.13 release, the client now skips the crafting grid step when it crafts with right-click on the recipe book. This means that we can't validate crafting based on the crafting grid contents anymore. The only way to do it now is to use the inputs and outputs calculated by the transaction balance.
2018-04-04 12:48:17 +01:00
eb354916d4 CraftingTransaction: simplifiy repetition calculation handling 2018-04-04 12:18:24 +01:00
033b44df5a CraftingTransaction: Start from pre-computed iteration count for input matching
This will be faster to bail out on failures.
2018-04-04 12:15:46 +01:00
ef2dd1de92 Inventory: Use exceptions to report back why a transaction failed
Returning false all the time could mean any one of a range of things. Throwing exceptions is better in that it allows us to catch them and see what actually broke.
2018-04-04 12:11:24 +01:00
5b7b2dd0e2 Merge changes from ALPHA11 for 1.2.13 2018-04-04 11:31:39 +01:00
3a10df634b Protocol bump for release 2018-04-04 11:13:36 +01:00
f1aecc3a71 Updated block IDs json from release (thanks MrARM) 2018-04-04 11:09:12 +01:00
42d04a4418 Allow use of 128x128 skins for last beta build (#2123) 2018-04-04 11:03:51 +01:00
3fe4ebc301 Found more unknown things 2018-04-04 11:03:36 +01:00
d97abfaa7b Found some unknown things 2018-04-04 11:03:25 +01:00
526f05631e fix metadata properties for new beta
there are more things than this, but I don't have time to figure them all out.
2018-04-04 11:03:05 +01:00
ebaef89e06 bump 2018-04-04 11:02:19 +01:00
6ab0cff9d3 Bump for 1.2.13.10
doesn't appear that anything of interest has changed
2018-04-04 11:01:46 +01:00
ae31ce1d25 LevelSoundEventPacket: updated sounds constants 2018-04-04 11:01:29 +01:00
a1cf5dbd1e fix doc inconsistency 2018-04-04 11:01:14 +01:00
c86132028e BlockFactory: add new "dynamic" fake runtime IDs for unknown legacy ID/meta combinations
This is basically how blockstate discovery would actually work in the full-blown system. This maps blocks with unrecognized blockstates to static runtimeIDs not known to the client.

This means that all blocks which don't have corresponding runtimeIDs in the new system will translate to update! blocks instead.

Mojang do this differently: they try to a) match id+meta, if that fails b) match id+0, and if that fails, then replace with update! block runtime ID. I can't do that here because I need to be able to convert both ways. They only need to be able to convert from legacy -> new.
2018-04-04 11:00:58 +01:00
5ce55bd3b0 duct tape for block ID remapping 2018-04-04 11:00:39 +01:00
c81f178cdb fix skins on 1.2.13.5
this is not the full changeset and more things are needed!
2018-04-04 10:59:09 +01:00
fc795b80ae Protocol changes for 1.2.10 2018-04-04 10:58:49 +01:00
99134de6b6 Updated NBT dependency
this needs further changes (particularly to Furnace) to stop things abusing NBT for runtime data handling, otherwise performance is going to drop off a cliff.
2018-04-04 10:29:32 +01:00
1fc388d6de DataPropertyManager: fix an unnecessary FQN 2018-04-02 12:34:05 +01:00
eba1ca030c Fix variadic type docs ...again
PhpStorm changed its mind how it wants these documenting in 2018.1, and apparently the correct syntax follows the PHP code.
2018-04-02 12:33:24 +01:00
8ce0fab8cc Remove unused imports 2018-04-02 12:26:13 +01:00
5ed2d6022c GiveCommand: don't catch Throwables
this caused me to think a thyntax error in my code was a syntax error in the NBT I was trying to parse.
2018-04-01 12:17:17 +01:00
37d085f793 UPnP: error messages on failure to portforward instead of silently failing 2018-03-31 12:51:17 +01:00
69c54de460 UPnP: remove useless 'or false' 2018-03-31 12:42:11 +01:00
b9d3bd22a3 Player: fixed getLastPlayed() being useless
this should only be set on quit, not on join.
2018-03-31 10:44:59 +01:00
d4d57aa9ea Merge branch 'feature/xp-event' 2018-03-30 12:46:53 +01:00
4ce1f228e6 Player: removed checkBlockCollision() override 2018-03-30 12:23:00 +01:00
4b03dbebba Entity: use temporalVector in checkBlockCollision() instead of creating a new Vector3 2018-03-30 12:21:37 +01:00
1d5978df98 Fixed falling blocks getting moved by currents, closes #2080 2018-03-30 12:20:59 +01:00
5d32587cf7 DeadBush: match placement condition with break condition, fixes #2116 2018-03-30 11:54:57 +01:00
d53258c943 EffectCommand: restrict range of values for duration, fixes #2055 2018-03-30 11:51:20 +01:00
773f760fff VanillaCommand: added getBoundedInt() 2018-03-30 11:48:42 +01:00
c20b16a0fe Living: fixed damage resistance negating >100% of damage, closes #2052 2018-03-30 11:31:43 +01:00
b151cb26a5 Fix deprecated event message (#2127) 2018-03-30 11:09:24 +01:00
49622cc2a5 NetworkBinaryStream: simplify read of canPlaceOn and canDestroy lists 2018-03-30 11:07:29 +01:00
56328f66a7 InventoryAction: remove useless creationTime field 2018-03-29 12:20:13 +01:00
f41a731493 DropItemAction: don't require a source item in constructor 2018-03-29 12:18:19 +01:00
ec332e3e60 Fill null UUIDs in CraftingDataPacket, remove all UUID things from CraftingRecipe
This allows deleting lots of code, and additionally provides a huge reduction in the compressed size of CraftingDataPacket. Since we don't care about these UUIDs (they are only used in CraftingEventPacket, which is broken and unused in PM) we fill them with zeros instead.
2018-03-29 12:05:23 +01:00
a1090623a2 CraftingRecipe: added methods to allow recipes to derive outputs from inputs
this will be needed for special recipes like shulker-box and banner recipes.
2018-03-29 12:05:22 +01:00
8572e9e560 Crafting: nuke
This commit brings in a much-needed rewrite of crafting transaction handling.

The following classes have been removed:
- CraftingTransferMaterialAction
- CraftingTakeResultAction

The following classes have significant changes:
- CraftingTransaction
	- All API methods have been removed and are now handled in CraftItemEvent
- CraftItemEvent
	- added the following:
		- getInputs()
		- getOutputs()
		- getRepetitions() (tells how many times a recipe was crafted in this event)
- Recipe interface:
	- Removed getResult() (individual recipes may handle this differently)
- CraftingRecipe interface
	- removed the following:
		- matchItems()
		- getExtraResults()
		- getAllResults()
	- added the following
		- getResults()
		- getIngredientList() : Item[], which must return a 1D array of items that should be consumed (wildcards accepted).
		- matchesCraftingGrid(CraftingGrid)
- ShapedRecipe
	- constructor now accepts string[], Item[], Item[]
- ShapelessRecipe
	- constructor now accepts Item[], Item[]
2018-03-29 12:05:22 +01:00
bc836aaec1 Make CraftingManager::sort() more cool with spaceship operators 😎 2018-03-29 11:45:12 +01:00
145a4fad0f CraftingManager: Make sort() static
this doesn't need access to $this
2018-03-29 11:45:06 +01:00
08c48d8145 CraftingRecipe: removed requiresCraftingTable()
the requirement for a crafting table is determined by the number of ingredients can fit on the grid (shapeless) or the max height and width (shaped). It's impossible to craft a big recipe with a small crafting table simply because you're not able to put the required resources into the grid.
2018-03-29 11:43:31 +01:00
81ecb56095 ShapedRecipe: fixed bug in constructor 2018-03-29 11:32:39 +01:00
a6d7365a28 Moved CraftingManager init to its own function
this allows the crafting manager to be re-initialized on the fly without recreating it.
2018-03-29 11:32:22 +01:00
1f4f8ab3f0 Inventory: Removed BigCraftingGrid, allow arbitrary size parameter
This is more flexible and requires less classes.
2018-03-29 11:24:28 +01:00
1420cd1fa5 InventoryTransaction: Added a more robust action flattening mechanism
This now handles the case where there are multiple options which could be taken, and opts for the first result which successfully ties all the actions together. Previously it would be entirely down to chance (ordering) whether the actions would get ordered successfully.
2018-03-29 11:23:52 +01:00
30a83544a0 don't break double chests 2018-03-27 10:23:18 +01:00
7e20385bdb BaseInventory: improved performance of getContents()
this old code is extremely inefficient. This showed up distinctly in my crafting bruteforce benchmarks, where I discovered that getContents() accounted for the vast majority of the time taken to match shaped recipes.
2018-03-27 10:13:55 +01:00
c7e803372c Inventory: added API method isSlotEmpty() 2018-03-26 09:24:00 +01:00
cf3638ad8d BaseInventory: fixed doc comment for slots field 2018-03-26 09:22:38 +01:00
0dd8fd2651 CraftingTransaction: fixed ingredient map trimming (again)
closes #2118
2018-03-25 13:46:39 +01:00
c0c684b12e Removed the need for paintings to check for destruction on schedule
Since we have a mechanism for triggering things on entities anyway, make use of it to do more than just forcing movement updates.
2018-03-25 13:15:10 +01:00
924334a776 Painting: fixed performance bug, close #2117 2018-03-25 13:06:02 +01:00
be7c27f60d Player: explicitly load chunk for player to spawn, fixes #2115
this is an ugly fix, but it'll do for now...
2018-03-25 12:45:51 +01:00
2b37b4a659 Player: close session in interface right at the top
I don't know why this would be anywhere _but_ here...
2018-03-24 13:00:44 +00:00
a4c50d3204 Remove unused imports 2018-03-24 11:59:15 +00:00
eb9f60f41c Entity: some minor cleanup to constructor 2018-03-24 11:52:23 +00:00
071aa44d29 Player: fixed facepalm 2018-03-24 11:05:03 +00:00
25089f5e70 Player: use setPosition() when jumping to off position 2018-03-24 10:58:31 +00:00
22dd8faf1d Player: don't jump to bad position when reverting movement 2018-03-24 10:57:59 +00:00
7354a55af8 Player: use vector methods for calculating diff on move 2018-03-24 10:50:09 +00:00
611f5d684b Player: removed redundant isFirst check for movement
Since the addition of resetLastMovements(), this code is useless.

Additionally, it doesn't make sense to ignore the first movement, because the first movement still _moves the player_ from point A to point B.
2018-03-24 10:40:30 +00:00
9a099d3f5d Player: remove a couple of useless lines from respawn()
teleport() handles these already.
2018-03-24 10:34:30 +00:00
5eb1ee3416 Position: use setLevel() in constructor to validate level 2018-03-24 10:02:10 +00:00
e4b6a18404 Player: removed redundant proxy function 2018-03-23 19:56:35 +00:00
364d278714 Player: removed useless condition for chunk ordering
This just causes it to attempt to spam chunk orders prior to the player spawning. It won't succeed, because the render distance is zero.

The other time this could occur is when teleporting into an unloaded chunk, but it's not necessary to continually spam chunk orders in that case, especially since chunk orders are done on teleport anyway.
2018-03-23 19:48:33 +00:00
c464d39401 Player: Order chunks immediately on receiving chunk radius request 2018-03-23 19:44:03 +00:00
a185b78486 Player: fixed logic of move-into-bad-chunk checks
particularly the hack with chunk switching was causing unexpected behaviour wrt. invisible players.
2018-03-23 19:34:45 +00:00
c19cf22ac5 Fixed #2110 2018-03-21 21:52:55 +08:00
d2fb32c28a PluginManager: added event call recursion limit, closes #2109
This prevents unexplained segfaults on accidental event call recursion by limiting the max depth of event call stack to 50. If another event attempts to be called, an exception will be thrown.
2018-03-21 10:40:08 +00:00
49fbbea7bf Implemented event handler inheritance, allow registering handlers for any valid event (#1792)
* Event handlers always handle subclass events. public static $handlerList no longer required.
* Removed $handlerList declarations
* HandlerList cleanup: Removed HandlerList->handlers and related bake methods
* Removed obsolete Event->getHandlers()
* EventPriority: Added fromString()
* PluginManager: throw exceptions on registering handlers with invalid priorities

This allows specifying a handler of `EntityDamageEvent` which will handle any instanceof it (as per current behaviour), AND also now allows specifying a handler specifically for `EntityDamageByEntityEvent`, which only handles `EntityDamageEvent`.

This was not previously possible due to limitations in the way handlers were registered.

Abstract events may not be handled unless they declare the `@allowHandle` PhpDoc tag.
2018-03-20 17:05:09 +00:00
1648fff916 Replaced Position->getLevel() null checks with isValid() 2018-03-20 11:10:36 +00:00
8d645b714f Position: Destroy references to Level in isValid() 2018-03-20 10:55:24 +00:00
403e996d2f Level: Removed WeakPosition
This is a bad fix for an issue found in one specific use-case. This is redundant because the only places this is used are places where it's guaranteed to be valid, or places where it is checked to be valid anyway.

The Level leak originally noted that led to the creation of this class is something I consider to be a non-issue, because all the heavy things will be cleaned up anyway.
2018-03-20 10:49:23 +00:00
73e09392b6 Timings: Clean up some terrible code, move namespaces 2018-03-19 19:05:51 +00:00
209e28dfe5 Level: Removed MovingObjectPosition 2018-03-19 16:58:45 +00:00
ac5a91b67e Cleaned up bool comparison mess 2018-03-19 14:10:55 +00:00
24c5d7557e Updated PreProcessor submodule 2018-03-19 12:44:54 +00:00
3d89bf5693 Updated PocketMine Math dependency 2018-03-18 18:08:24 +00:00
e48ec9fb71 Ore: replaced a sub-optimal multiply()->divide() on Vector2 2018-03-18 18:06:04 +00:00
95606b6e04 Generator: fixed a couple of hardcoded block IDs 2018-03-18 18:03:23 +00:00
c243daabe1 DumpMemoryCommand: removed token annoyance, use date/time to identify memory dumps by default 2018-03-18 12:17:31 +00:00
357674cb54 DumpMemoryCommand: move memory dumps to their own folder
this is for ease of ignoring in IDEs.
2018-03-18 12:06:15 +00:00
9d5eeb328e Player: cleanup how login verification is handled
Players are now only considered authenticated if they have an XUID AND have a keychain with a Mojang signature in it somewhere.
2018-03-17 18:44:26 +00:00
b2ee6b2ca5 Player: consolidate and add type docs for fields 2018-03-17 17:42:01 +00:00
2860e9e8ee Player: remove clientSecret (useless) 2018-03-17 16:44:34 +00:00
e82073834f Player: protect some fields 2018-03-17 16:43:34 +00:00
7fcc538a75 Level: clone Block object passed to setBlock() if set successfully
closes #2042
2018-03-17 16:35:10 +00:00
7f6b8ad7c2 Moved \pocketmine\math to a separate library 2018-03-17 12:45:55 +00:00
313b224bec Updated Composer dependency names and repo URLs 2018-03-17 12:19:14 +00:00
d12b1d3e07 Updated RakLib dependency 2018-03-17 11:27:56 +00:00
eeeef8df51 Fixed concrete powder not falling 2018-03-16 16:43:47 +00:00
9c786089f8 Level: don't create objects which aren't going to be used 2018-03-16 13:00:16 +00:00
e3cae7364f Level: don't send empty block update batches 2018-03-16 12:58:46 +00:00
d542bbc736 Level: Fixed race condition between direct and batched block updating
This happened when a block was set into the world with a direct update, when an entry for that block was already present in the changedBlocks map. This fixes the bug by removing the entry from the changedBlocks map to avoid sending outdated block updates in batches.
2018-03-16 11:44:57 +00:00
e88541b269 TeleportCommand: add /teleport alias 2018-03-16 10:49:57 +00:00
fdad965db8 Player: if command has aliases, add command name as alias if not found
closes #2106

For some strange reason, using aliases overwrites the original command name instead of coexisting with it. This is rather astonishing behaviour, and probably a bug in the client. However, this workaround is the same thing vanilla does (see /tp in vanilla).
2018-03-16 10:41:00 +00:00
dd844f7ad3 Position: call parent constructor 2018-03-15 10:29:21 +00:00
596c8a7b4f Tile: Removed cyclic dependence on Chunks
Chunks were used by tiles for a couple of things:
- 1. for coordinates - which can be gotten using bitshifts
- 2. setChanged() - which is unnecessary as seen in the previous commit

Removing this circular dependency was actually remarkably easy to do.
2018-03-15 10:21:42 +00:00
9c598d1345 Spawnable: don't mark chunk as changed onChanged()
this is unnecessary because a chunk is considered "changed" if it has tiles on it anyway.
2018-03-15 09:48:28 +00:00
a2af838b1d Level: fixed autosave not kicking in when entities are updated in a chunk (e.g. moving, dying, spawning) 2018-03-15 09:46:04 +00:00
bf97eab98f Block: remove redundant local variable from collidesWithBB() 2018-03-15 09:38:14 +00:00
a9a55e9558 GlowingRedstoneOre: fixed infinite recursion and crash on block update
closes #2104

The inheritance of GlowingRedstoneOre from RedstoneOre maybe should be reconsidered. They only share properties in reality.
2018-03-15 09:24:48 +00:00
95fb1d1602 AxisAlignedBB: added epsilon for floating-point comparison (#2101)
This fixes bugs where, for example, one cannot place a block below oneself at y=7.0.
2018-03-14 16:52:05 +00:00
fa644edef3 Entity: removed redundant return values for move() 2018-03-14 13:39:23 +00:00
ddc9dca8b4 Player: fixed being able to eat cake in creative
closes #2070
2018-03-13 18:32:08 +00:00
86eee429bb Block: Split onUpdate() into several functions, removed Level::BLOCK_UPDATE_* constants
This allows the removal of lots of ugly code, and also exposes lots of similarities with how this update type was handled. This can be further improved in the future to more generically handle cases.

I realized in the process of changing this, that it might actually be simpler to treat to treat scheduled updates and neighbour updates as one and the same. They use the same mechanism for being saved on chunks (TileTicks),
and doing that would make updating only require one queue instead of two.

RedstoneOre: use onActivate() to trigger glowing
this is not technically correct behaviour, but this preserves the current behaviour.
2018-03-13 17:29:46 +00:00
4f20a504e3 Level: remove dead function
this is handled by a queue now instead of ondemand, to avoid recursion bugs.
2018-03-13 11:46:23 +00:00
6a1f8640f6 Cactus: fix bugs in local block updating 2018-03-13 11:40:45 +00:00
8a0414f306 Server: Changed logic of isLevelGenerated() to prevent astonishing behaviour
Previously to this, a level would be considered "not generated" if no level providers registered as valid for that directory. This caused astonishing behaviour when the user's world has, for example, a mixture of .mca and .mcr region files - the world would instead get _re-generated_ according to the default level format, which might or might not load the existing regions depending on the format used for generation. This behaviour is utterly absurd.

This changes the behaviour of the generated check to check for a non-empty directory in the given path. Non-empty directories without recognized world files in them are now considered to have an unknown format.
2018-03-12 10:24:59 +00:00
d478661961 Minor cleanup to LevelDB constructor 2018-03-11 18:15:20 +00:00
b8064aa45c LevelDB: fixed more usages of CompoundTag ArrayAccess API 2018-03-11 17:55:35 +00:00
00f596c4f8 Level: typehint hashing methods 2018-03-11 16:42:57 +00:00
3f7b14bf59 Level: Remove dead generator leftovers
This is all handled by the population mechanism now. Nothing uses these things anymore since years.
2018-03-11 13:56:41 +00:00
ba0a256834 SplashPotion: fix max stack size 2018-03-11 13:43:45 +00:00
f2f8c235e7 Explosion: add exception throws for bad arguments 2018-03-11 13:06:29 +00:00
69b3bb183d Explosion: typehints and docs 2018-03-11 13:02:46 +00:00
cd35bd6872 git diff-tree --check $(git hash-object -t tree /dev/null) HEAD 2018-03-11 10:31:25 +00:00
d09a43cfef Added PlayerExperienceChangeEvent 2018-03-10 20:04:36 +00:00
40b995a435 Level: Fixed botch-job PR #2089
@zKoz210 Do not contribute to this repository again without first testing your changes.
2018-03-10 19:08:30 +00:00
590826b9bd Player: Disallow modifying NBT of tiles inside spawn protection 2018-03-10 18:19:17 +00:00
a5e87484d9 Player: removed superfluous null-check from setMotion()
this is already checked by broadcastMotion().
2018-03-10 17:08:00 +00:00
8a86e0825b Entity: Moved PrimedTNT and FallingSand to object\PrimedTNT and object\FallingBlock 2018-03-10 16:25:07 +00:00
b39bbffdc5 Entity: Moved and renamed entity\Item to entity\object\ItemEntity 2018-03-10 12:36:46 +00:00
bd3d2451bc Level: Added getRandomTickedBlocks() function (#2089) 2018-03-10 11:32:01 +00:00
606407933e ProjectileItem: fixed error when projectile entity is null 2018-03-10 10:59:22 +00:00
ad09e8c8d0 Implemented Bottle o' Enchanting 2018-03-10 10:53:03 +00:00
486edf0e55 Projectile: remove redundant parent onHit() calls 2018-03-10 10:31:24 +00:00
2ee01eb195 Projectile: fix stupidity with collided block IDs 2018-03-09 21:50:27 +00:00
9098502199 Item: added some foods, cleaned up Fish abomination
@PEMapModder GET A CLIENT ALREADY
2018-03-09 19:54:42 +00:00
b130374e46 EnderPearl: fixed max stack size 2018-03-09 19:19:21 +00:00
31106bc227 ItemFactory: Register Dragon's Breath item
this is only used for brewing, it doesn't need anything special.
2018-03-09 19:13:30 +00:00
cc1a3d695f Implemented basic Ender Pearls
this doesn't have full functionality yet (like spawning endermites) because some things aren't implemented yet.
2018-03-09 19:05:14 +00:00
8020780fc5 LevelEventPacket: added enderman teleport particle cloud constant 2018-03-09 17:20:35 +00:00
2f266a5922 Player: added a server-side forced cooldown mechanism
This is necessary because the stupid client constantly spams right-click actions if you carry on trying to eat/throw/whatever the item when cooldown is in effect. Therefore ender pearls would be fired like machine guns without these checks server side.
2018-03-09 14:45:01 +00:00
3827892e48 ArmorInventory: fixed debug spam when sending contents to the player itself 2018-03-09 13:23:51 +00:00
e06b78b0ee Implemented armor durability 2018-03-09 13:21:05 +00:00
74cff89df3 Instant Damage splash potions now deal knockback 2018-03-09 12:52:09 +00:00
a9957c3db3 Water bottles extinguish fires when hitting a block 2018-03-09 12:25:34 +00:00
2e9bf7e93b Implemented Splash Potions 2018-03-09 12:25:02 +00:00
dbcc69c2de LevelEventPacket: added useless constant 2018-03-09 11:35:08 +00:00
cdd3fe81e1 Projectile: allow using negative damage amounts to remove damage effects 2018-03-09 11:35:08 +00:00
a8a3eb3866 Added particles for snowballs and eggs 2018-03-09 11:35:07 +00:00
83a3c6f614 Arrow: added shake effect and strike sound 2018-03-09 11:35:07 +00:00
8cc6a32a04 Rewritten Projectile movement handling, added ProjectileHitBlockEvent and ProjectileHitEntityEvent, fixed a swathe of arrow-related bugs
I usually avoid mega-commits, but one thing led to another.
2018-03-09 11:35:07 +00:00
c1a2144f60 Particle: added some new constants 2018-03-09 10:42:59 +00:00
b2491a5874 CraftingTransaction: clean up some logic 2018-03-08 20:44:52 +00:00
2e125168c3 CraftingTransaction: Fixed ingredient map trimming
I really don't know why I made this so complicated to start with. This works much better and is much easier to read.

Fixes #2083.
2018-03-08 19:51:06 +00:00
5059a92b91 Fixed bow and throwable sounds 2018-03-08 13:20:26 +00:00
ea5db98d12 Player: fixed draining hunger when teleporting
this was caused by abe5d94d5b because player's lastBlah wasn't getting updated anymore.

Player movement handling really needs cleaning up, but for now this fixes the issue.
2018-03-08 12:18:22 +00:00
1f77c074e9 Level: Unload chunks prior to save() to avoid saving chunks twice on shutdown
save() calls saveChunks() which saves any chunks found to be modified. But chunk unloading does this anyway, so it's better to unload first and then trigger the save mechanism, to avoid saving chunks twice.
2018-03-07 19:47:54 +00:00
73a5788774 Door: remove unused local variable 2018-03-07 18:53:38 +00:00
dc3bf8546e Refactored effects handling, split up concerns of effect types and instances
Removed json insanity for effects

Split up effect types and effect instances

Saturation is an instant effect
2018-03-07 12:42:31 +00:00
c7f8796136 Implemented Paintings (#2073)
This supports vanilla placement of paintings, with overlap and collision checking.
Paintings are removed when a block is placed inside them or if any of their supporting blocks are removed.

As per vanilla, a random painting is chosen from the largest subset that will fit into the given space.
2018-03-07 09:03:30 +00:00
c5336776a5 Update ISSUE_TEMPLATE.md 2018-03-05 09:24:28 +00:00
b623c4aba1 Remove accidentally committed file 2018-03-04 15:17:14 +00:00
49a39fc7bd Split DestroyBlockParticle into two classes
this level-event is not only used for blocks, it's also used for paintings.
2018-03-04 13:11:38 +00:00
2e4519cb36 ExperienceOrb: fixed behaviour when placing blocks on top of them 2018-03-04 12:47:09 +00:00
2ff3b12376 Cleaned up projectile "collide" checks 2018-03-04 12:19:41 +00:00
9e4bccd8c0 updated Language submodule 2018-03-03 19:59:13 +00:00
1c5180b720 McRegion: don't assign regions to the index until all exception handling is done
it appears that errors are occurring in the exception handler when handling corrupted regions, leaving regions in the provider index with incomplete location tables. This causes strange-looking errors later down the line.

This moves the region assignment to the end of the condition to avoid leaving incomplete/corrupted regions in the location table when errors occur.
2018-03-02 18:30:45 +00:00
fa6d44ea9e Move Attribute and Effect init calls to Entity::init()
since entities are dependent on these, they should be here.
2018-03-02 10:05:50 +00:00
9d018e8d9e Level: cleaned up chunk loading error handling, close #2056
This now removes logging from the level providers (for the most part) and replaces it with exception throws and catches. The implementation using the providers should catch these exceptions if they are thrown.
2018-03-01 12:30:12 +00:00
ae2e1fdd5a McRegion: Make nbtDeserialize() and nbtSerialize() protected
Not really sure why these are still exposed publicly.
2018-03-01 10:42:27 +00:00
97bfcf6e71 Create support.yml 2018-03-01 10:28:32 +00:00
5457c7a202 Updated PocketMine-Language submodule 2018-03-01 09:53:14 +00:00
ee28296d60 Server: fixed authentication messages
why did I do this...
2018-03-01 09:32:04 +00:00
06af742bef wtf 2018-03-01 09:30:50 +00:00
6bdf5e15c0 Fixed a couple of mistakes in generateLevel() docs 2018-03-01 09:23:50 +00:00
d4eba3f4b1 Moved some things out of Server to appropriate init() functions 2018-03-01 09:18:40 +00:00
5a89e80873 Server: added getPlayerByUUID() and getPlayerByRawUUID()
closes #2047

Since the player list already indexes players by UUID, it's simple to just use that for fetching the player.

A possible future improvement could be to allow fetching an _offline_ player by UUID, but no capability to do that is yet available.
2018-03-01 09:09:34 +00:00
28e601bbb9 Tile: added handling for PC 1.11 save IDs 2018-02-28 19:58:18 +00:00
7e9f1324a7 Entity: fixed tiny sub optimal code in registerEntity() 2018-02-28 19:30:30 +00:00
973d5dc251 Small de-spaghettification of login handling
no need for these to be split up, it just makes the player login code flow look confusing.
2018-02-28 18:48:08 +00:00
533d139385 Server: Move removePlayer() to somewhere more sensible 2018-02-28 18:28:36 +00:00
6a94c8183c NetworkBinaryStream: Add clarification on array structure for gamerules
we need objects for this really
2018-02-28 18:10:47 +00:00
629a254639 Server: stop reporting exceptions as "notice" in crashdumps 2018-02-28 10:57:25 +00:00
732b931556 BatchPacket: use PacketPool::getPacket() instead of getPacketById()
this is what getPacket() is for.
2018-02-27 21:43:40 +00:00
2dd1878d57 Entity: remove dead field isPlayer 2018-02-27 17:01:28 +00:00
3104a312b2 ConsoleCommandSender: Remove useless function isPlayer()
This function is not declared in any useful places (like the CommandSender interface) and it is not present in Player (!!!). Additionally, an is-player check is better done with an instanceof so that type safety is enforced and IDEs can give auto-complete.

This is a BC break, but this is such a pointless function that it's probably not even worth mentioning.
2018-02-27 16:43:40 +00:00
d6d47feda9 Query: Send responses to the source interface only, instead of all the things
who the fuck wrote this shitty code?
2018-02-27 13:23:01 +00:00
0ba1b58ee0 always takes 2 commits to do one simple thing...
I really love Golang being so strict on this.
2018-02-27 12:34:28 +00:00
ab2df8b11b Removed Server->addRecipe()
This method is pointless extra bloat in Server. Use CraftingManager->registerRecipe() instead.
2018-02-27 12:33:32 +00:00
eb01dcaf60 Player: don't save data to disk on login
this is pointless, and it will get saved on disk on quit anyway.
2018-02-27 12:26:30 +00:00
f0535df96d Remove deprecated things 2018-02-27 11:59:16 +00:00
f903dbfe00 Server: Removed identifiers array
This is completely unnecessary and adds extra complexity for no good reason. Maybe it was used historically, but nowadays it is only used to identify players to send async-prepared batch packets to.

There are two alternative ways to do that:
1. use spl_object_hash() as the targets array in CompressBatchedTask
2. use ServerScheduler's object storage to retain references to the Player[] array.

I've opted for the second method.

Removing these identifiers allows great code simplification in removePlayer() and removes the need for those old stupid hacks.

This also includes a backwards-compatibility break by removing the $identifier parameter of Server->addPlayer().
2018-02-27 11:43:02 +00:00
e0d5c79848 Scheduler: Catch exceptions thrown from AsyncTask->onCompletion() 2018-02-27 11:33:16 +00:00
e024f381c9 Living: fixed cycle between armor inventory and holder not getting cleaned up on close
this was getting collected by the cycle GC, but it should have been dealt with properly like other inventories.
2018-02-27 11:08:09 +00:00
2a09aaf456 start.ps1: use -NoProfile for starting child
The child powershell is a workaround for an unidentified bug which causes colours to get messed up after using git in the same console window. However, loading profiles on the child is a major slowdown when starting the server, and for no good reason.
2018-02-27 09:54:29 +00:00
0ad8ea6e92 Remove unused imports 2018-02-24 19:01:09 +00:00
bd47852ca4 Allow Command::getPermissionMessage() to return null (#2057) 2018-02-24 18:15:27 +00:00
2b036b1a5c Added API method Living::hasEffects() (#2054) 2018-02-24 13:48:15 +00:00
e5ec8fa603 Entity: Use MoveEntityPacket teleport flag for teleporting
fixes entities getting movement interpolation between origin and destination
2018-02-24 12:25:25 +00:00
abe5d94d5b Entity: fixed teleport() not updating movement to players
cc @CortexPE
2018-02-24 12:22:03 +00:00
da5febc34a fix crash report 127835 2018-02-24 11:46:36 +00:00
3de5e132a2 CrashDump: fixed broken argv reporting 2018-02-22 22:05:35 +00:00
37e8c8d324 BanEntry: work around stupid bug in ext/date
https://bugs.php.net/bug.php?id=75992

When plugins do time-limited bans and users enter stupid time values, a shitty bug in ext/date gets triggered, but only when reading the ban entries from disk. DateTime->format() is able to produce formatted strings which have more than 4 digits in the year, which are then considered invalid. This works around it by trying to parse a formatted version on the fly to ensure that it is valid.

This also cleans up and improves ban list loading and handling.
2018-02-22 14:48:53 +00:00
aa11dbb928 Player: Add warnings for messing with movement checks 2018-02-20 13:50:30 +00:00
e7adaef2d2 Level: fix syncChunkLoad timer not getting stopped when no chunk is returned 2018-02-20 10:39:41 +00:00
6bf9ae0a18 Expose plugin.yml contents to plugins (#2043)
This allows plugins and libraries to rely on values in plugin.yml without parsing it again
2018-02-19 22:16:45 +00:00
e7b2dc87d6 Most pointless optimization ever (ServerKiller) 2018-02-19 12:20:31 +00:00
d7a02793fa PocketMine.php: update comment 2018-02-19 12:02:27 +00:00
6a996611f8 Move functions from PocketMine.php to Utils
This cleans a lot of mess out of the bootstrap file, and also has the added bonus that threads which do not inherit functions can now get access to them by autoloading Utils.
2018-02-19 11:56:22 +00:00
ad8d67137e Implemented critical hits (#1929) 2018-02-19 10:14:32 +00:00
cbbed6a6c1 Updated RakLib dependency 2018-02-19 10:01:56 +00:00
99ef3e6576 RakLibInterface: don't self-unregister from Network on crash
This is already done by the Network itself.
2018-02-18 11:52:55 +00:00
eeaf75ac85 Server: add typehint to addPlayer() 2018-02-17 19:54:56 +00:00
6954bfac4b Removed RakNet client ID parameters from Player
This is not used anywhere anymore and null is always filled for this, so it's pointless.

Also, this is an API break.
2018-02-17 19:51:04 +00:00
f27b62027c McRegion: fix some missed ArrayAccess usages of CompoundTag 2018-02-17 14:58:04 +00:00
093cb5b39e Updated PocketMine-NBT dependency 2018-02-17 14:29:20 +00:00
3f41628bf3 Merge branch 'legacy/alpha11' 2018-02-17 10:59:19 +00:00
a3fa8adf4a Fixed XP orbs trying to track players after teleport
closes #2028

@mal0ne-23, you are today's MVP.
2018-02-17 10:58:54 +00:00
08daf655e5 RakLibInterface: Remove useless function 2018-02-16 17:57:43 +00:00
61fc090cf2 Player: don't debloat skin geometry twice
This is already done in setSkin(), which is called below.
2018-02-16 14:27:16 +00:00
ecd830463c PlayerNetworkSessionAdapter: Remove dead TODO 2018-02-16 11:49:28 +00:00
ffe89f5e1b fixed Anvils item/block different logic handling, close #1910 2018-02-16 11:07:50 +00:00
88a05845c2 Item: Removed protected block field, items should now override getBlock() 2018-02-16 11:06:29 +00:00
2cabdca3f7 ItemFactory: Allow block-items to be overridden
Currently an ItemBlock is created for every Block requested, but this will need to change in the future (for Anvils because they have stupid bitshifts on the meta instead of a nice bitmask). This allows registering items in the ItemFactory with IDs lower than 256 and having them recognized.
2018-02-16 11:03:04 +00:00
be1ddb9f5b Item: Added API method getVanillaName()
This allows retrieving the name of an item without the custom name being plastered over the top. This will also allow weird things to have special functions for their names.
2018-02-16 10:57:02 +00:00
7fc3eeab00 Level: Remove redundant null checks for Item->getBlock()
this is typehinted to return Block, so these checks are pointless.
2018-02-16 10:45:54 +00:00
9395dbf9fa Player: added missing spawn protection check for frame item removal
fixes #2025
2018-02-16 10:35:16 +00:00
a7396d7ae9 Player: Cancel interaction on frames in spectator mode before calling the event, not after
This convention is used throughout the code to allow plugin developers to alter the behaviour of the event. In this case, it would instead produce unexpected behaviour when the event is not cancelled by a plugin.
2018-02-16 10:29:46 +00:00
3b632c2870 ItemFactory::fromString(): throw an exception on failure to parse meta value 2018-02-16 09:45:38 +00:00
7dd834bca0 Fixed API patch version being useless
Plugins will now be able to require a specific minimum patch version, in case they depend on bug fixes or whatever.
2018-02-15 21:45:46 +00:00
2b6e135c83 Switch to PSR-4 based autoloader
Since we don't use the PEAR-style namespacing convention, there's no reason to use PSR-0 autoloader.
We don't quite follow PSR-4 conventions because there is still a pocketmine subdirectory, but changing this might pollute the git history, so I'm wary of changing it.
2018-02-15 21:01:26 +00:00
c26e3aa9fa GiveCommand: Make invalid player checking logic less confusing
some code in this namespace is just total WTF...
2018-02-15 18:19:41 +00:00
aeba15c5c6 GiveCommand: don't crash when an invalid item is specified 2018-02-15 18:18:09 +00:00
4c583ec8ab ItemFactory: Throw exception on failure to parse string as an item in fromString()
closes #1487
2018-02-15 17:56:55 +00:00
af2435f199 Removed redundant checks from ItemFactory::init() and BlockFactory::init()
These are never called accidentally, or at least it's highly unlikely to do so. It might be reasonable to throw exceptions for this, but for the meantime they are redundant - extra indentation for no good reason.

This also removes the $force parameter from BlockFactory::init().
2018-02-15 17:42:03 +00:00
456987e212 ItemFactory: Don't initialize creative items in init()
Wanting initialized item factory does not require initializing the creative inventory. This is often useless and unwanted extra baggage (when this is used on threads for example).
2018-02-15 17:09:38 +00:00
8e6ec04abc Item: Replace a usage of hardcoded resource path with \pocketmine\RESOURCE_PATH 2018-02-15 12:24:57 +00:00
42a7b7fa36 More NBT updates
This library is going to be completely different before I'm done here >.>
2018-02-15 12:11:36 +00:00
ce4e0bf69c Tile: fixed copying of custom block data 2018-02-15 11:47:12 +00:00
dc84484c2b ContainerTrait: Add PhpDoc for ListTag iteration 2018-02-15 11:45:13 +00:00
e7e4645c0b Fixed a wide range of bugs with floating-point coordinates getting incorrectly int-casted
This causes lots of bugs in negative coordinates.

This fixes #1789 after world load & save.
2018-02-15 10:27:42 +00:00
4e9e285e37 Vector2: Fixed getFloorX() and getFloorY() logical flaws
(int) typecast does not round down, it truncates!!!!!!!! :yodaangry:
2018-02-15 10:24:35 +00:00
3962d32ffe Chunk: Remove obsolete checks for entity/tile coordinate mismatches
This code is no longer necessary, because entities are constructed with a Level instead of a Chunk since API 3.0.0-ALPHA4. This means that they will not get allocated in the wrong chunk at runtime after having been saved on the wrong chunk by something else (such as an older version of PM). They will instead be allocated in a chunk selected by bitshifting their coordinates.

This is necessary to be able to fix #1789 without causing entities affected by the infamous bitshift-on-floats bugs to inexplicably vanish.
2018-02-14 18:58:52 +00:00
a84aba5517 Replaced some bad usages of Vector3 get*() with their respective getFloor*() 2018-02-14 18:45:10 +00:00
0b82d5c8d4 Math: Fix typo in Matrix->subtract() name 2018-02-14 18:22:37 +00:00
3aef4c5a09 Merge branch 'legacy/alpha11' 2018-02-14 09:13:00 +00:00
6307952ae9 Server: bail on trying to send empty batch (issue #2020) 2018-02-14 09:12:52 +00:00
cacd0f5d8f Level: fixed global packet mechanism spamming empty batch packets every tick
This also spammed to nobody when the level is empty.

Closes #2020.
2018-02-14 09:12:07 +00:00
f66928c345 Player: patch exploits relating to quitting on death (#2017)
* Revert "Revert bad duct-tape fix that broke lots of other things"
This reverts commit 4a4900e5e7.

Player: Perform respawn actions when joining while dead
This fixes exploits related to #1567 by calling respawn logic on join when the player has zero health.
This is a shitty fix and doesn't solve the actual issues described in #1567, but it's a simple solution for the exploits related to it.
2018-02-13 21:23:31 +00:00
9abfd54cc1 Updated with ListTag changes from PocketMine-NBT 2018-02-13 16:50:49 +00:00
4a85311c5f Living: Remove redundant isAlive() check from kill()
This just causes unexpected bugs, and hides actual bugs.
2018-02-13 12:47:33 +00:00
8a4f6eb6c2 ArmorInventory: fixed slots not updating when set
closes #2014
2018-02-13 11:33:54 +00:00
6e7a693355 Tests: Make lint.sh a little more useful 2018-02-12 11:34:51 +00:00
b7bd8dc7f1 Human: fixed NPC skin crash after ByteArray change 2018-02-12 09:56:02 +00:00
b445825467 TextFormat: Moved toANSI() to Terminal, close #1995
This also removes a cyclic dependency between TextFormat and Terminal, meaning that TextFormat is now standalone without any external dependencies.

This is also an API break. Beware all ye who wander here, master = bleeding-edge!
2018-02-11 19:11:51 +00:00
98d6aea7fe Server: rename getResourcePackManager()
casual BC break, ain't nobody got time for deprecations!

closes #1797
2018-02-11 17:17:56 +00:00
b75d121c7e Human: remove obsolete TODO 2018-02-11 17:08:59 +00:00
88bbb03f12 Human: store cape & geometry data in NBT 2018-02-11 17:08:01 +00:00
9478bc281f Human: Save skin data as TAG_ByteArray instead of TAG_String
TAG_String has a UTF-8 payload, which makes it more expensive to work with. Also, skins can contain bytes which are not valid UTF-8 characters and will therefore be treated as corrupted by external tools.
Additionally a TAG_String can only hold 32767 bytes, which might become a problem in the future.

A TAG_ByteArray can hold up to 2GB of data, and there is no character encoding restrictions on it.
2018-02-11 16:50:00 +00:00
7ec886faa2 Updated PocketMine-NBT dependency with string corruption fix
This fix doesn't fix existing data, but it will prevent the bug happening in the future by capping the length of strings to 32767 bytes, and throwing an exception if too long.
2018-02-11 16:36:50 +00:00
610e62e2cd Timings: don't return the paste we just sent in the response 2018-02-11 11:56:16 +00:00
906442136b Merge branch 'legacy/alpha11' 2018-02-11 09:56:10 +00:00
3600542d78 Timings: fixed pastes not working after ubuntu pastebin update 2018-02-11 09:55:52 +00:00
3b36d46a8f Living: don't reset attack time on regaining health
fixes #2004 and related bugs
2018-02-10 20:53:39 +00:00
63fa6a36a9 Merge branch 'pr/1982' 2018-02-08 12:09:29 +00:00
e0ed877494 Protocol changes for 1.2.10 release
Looks like they reverted near enough everything they did in the beta.
2018-02-08 11:19:04 +00:00
bab2daf711 Protocol changes for 1.2.10 release
Looks like they reverted near enough everything they did in the beta.
2018-02-08 11:18:46 +00:00
5858025d90 Updated PocketMine-NBT dependency to fix CompoundTag bugs 2018-02-07 19:49:52 +00:00
dbac2abafb TextFormat: make colour matching regex less absurd 2018-02-07 11:31:49 +00:00
266d1cb935 Updated Composer dependencies 2018-02-07 10:22:31 +00:00
ffbb44673f Enchantment: fix mistake in Protection translation key 2018-02-07 10:15:31 +00:00
a84a8ecc14 Fixed 32-bit accident
gud fuckup
2018-02-06 21:39:15 +00:00
687886e70b PermissibleBase: remove useless destructor 2018-02-06 21:10:42 +00:00
bad323f5cc PocketMine.php: move stuff out of do{}while(false) that doesn't need to be in there 2018-02-06 19:13:57 +00:00
ca9f700fb0 PocketMine.php: refactor timezone handling into its own class
This removes lots of bloat from PocketMine.php, and this is also important for reusability across threads.
2018-02-06 19:09:24 +00:00
c51cc6b2fe Drop support for Zephir entirely
This extension hasn't been maintained in 4 years and it doesn't make sense to update it to PHP 7, since :shoghi: just dumped a blob of PHP into zephir. It's not worth the hassle of updating.

I prefer to modularise and then C-ify modules, so that they can be reused on their own.
2018-02-06 18:40:36 +00:00
03c66f0f86 PocketMine.php: clean up dependencies checking 2018-02-06 18:38:09 +00:00
610b041631 PocketMine.php: remove unused import 2018-02-06 18:25:59 +00:00
75289b1498 kill(): fix bug when running with POSIX extension but without pcntl
SIGKILL constant is defined by pcntl, not by posix. If pcntl is not compiled then bugs can occur when trying to kill() the server (such as during a crash).
2018-02-06 17:55:18 +00:00
4eea54780a start.cmd: pause on exit with error code in CMD
Closing the command window immediately when an error occurs is particularly unhelpful. This keeps the command window open so that the user can see what went wrong.

[ci skip]
2018-02-06 17:49:12 +00:00
e860d32b3a Merge branch 'text-container-move' 2018-02-06 13:13:19 +00:00
c4486d9ad7 Tile: Cleaned up utterly pointless overcomplicated code for inventories 2018-02-06 13:01:54 +00:00
8222b16d9a LevelDB: fixed leftover usage of the old CompoundTag API 2018-02-06 11:16:14 +00:00
dcb53b1cbb RCON: Use PTHREADS_INHERIT_NONE - these threads don't need baggage from upstairs 2018-02-05 17:27:00 +00:00
a52a2f6d26 RCON: register autoloader on RCON threads
fixes #1993
Interesting that this bug was never noticed before. Maybe because of the class getting loaded by PocketMine.php previously.
2018-02-04 22:24:19 +00:00
906d7eb176 Lang: Move TranslationContainer and TextContainer to \pocketmine\lang namespace
why the hell were they ever put in \pocketmine\event in the first place??

This change was suggested many months ago but I forgot all about it.
2018-02-04 20:03:30 +00:00
bf3f5532ac Server: duct tape for very early startup crashes
Exceptions occurring early in the start sequence (before BaseLang is initialized) will result in the server hanging and not killing process as expected. This works around that issue.
2018-02-04 19:53:11 +00:00
07bf1c9e22 Bump API version for release 2018-02-04 18:06:02 +00:00
b659a3d39f Server: more shutdown debug 2018-02-04 10:14:35 +00:00
68b30108be CrashDump: fix mis-reporting Composer dependency exceptions as plugin crashes
this is still not foolproof but whatever.
2018-02-03 19:27:59 +00:00
f223fb2876 Use realpath() to determine correct file path case for DATA and PLUGIN_PATH
fixes issues where cleanPath() doesn't remove these paths from crash traces
2018-02-03 19:21:13 +00:00
8bb785b7af Update pthreads for Travis 2018-02-03 14:17:42 +00:00
806a2005d7 added missing dependency check for OpenSSL
this is managed by Composer now so I didn't think to check it.
2018-02-03 01:03:59 +00:00
c794ced0ad fix dependencies order 2018-02-03 01:03:08 +00:00
f993358c5f fixed extremely stupid bug with player spawns
This was causing new players to inexplicably spawn in the wrong place when joining a world for the first time which had a different level name than folder name. With LevelDB worlds, this caused them to spawn wayyyy up at y=32767 for no good reason.
2018-02-02 16:00:28 +00:00
1c12be6bf2 README: Remove IRC
these channels have been dead for years.
2018-02-02 09:31:13 +00:00
a1d9b8486e README: Be more clear about "getting latest phar"
We don't want people to be using latest development builds, but that's the first thing people see when visiting Jenkins. We want them using releases instead.
2018-02-02 09:28:22 +00:00
9397356ce4 Server: fix crash when specifying settings.async-workers on the command-line 2018-02-01 17:58:49 +00:00
e56e363dcc DataPacket: rename split-screen bytes 2018-01-31 12:07:26 +00:00
18b287c3ea AsyncTask: Remove cleanObject() and calls to it
This is no longer needed. Doing worker GC (via collect()) frees the allocated memory anyway, so this function is now redundant.
2018-01-30 16:45:49 +00:00
9014eb72e9 TeleportCommand: Fixed the bug fix again
This all comes from a shitty bugfix by @PEMapModder. Should be applied globally really, but it wasn't - and not properly tested either :P
2018-01-30 15:08:11 +00:00
82948726ed Beware threads/workers might not inherit \pocketmine\PATH
if the inherit flags don't include PTHREADS_INHERIT_CONSTANTS, this code would fail. Store the Composer autoloader path in advance instead.
2018-01-30 14:50:19 +00:00
c601816586 Terminal::hasFormattingCodes() workaround for STDOUT not being defined
#1979

This isn't a full solution because formatting codes are still not applied correctly if the calling thread doesn't inherit classes.
2018-01-30 10:54:04 +00:00
54f7a88fbb Added getXuid() 2018-01-30 01:25:27 +03:00
d2d1df0447 MainLogger: Remove redundant condition
these are always ThreadedLoggerAttachments anyway, this code doesn't make sense.
2018-01-29 12:24:00 +00:00
f9b1afe4cf Fixed race condition causing exception log messages to sometimes not get written to disk when kill() is used
Synchronize with the logger thread when logging an exception or killing. This forces the main thread to wait for disk write to complete when logging exceptions or killing the process.
2018-01-29 12:04:23 +00:00
033cb8bd63 oops, wrong namespace 2018-01-28 13:08:11 +00:00
0ed9fcb641 Restrict VerifyLoginTask exception handling to known exceptions
everything else should produce a nice big stack trace for debugging purposes, because everything else is probably bugs

This fixes random exception error messages getting relayed to the client when a user does stupid things like editing the source code without knowing what they are doing.
2018-01-28 13:07:09 +00:00
efac23d4af Updated to new RakLib version 2018-01-27 19:10:55 +00:00
48dc1c38f7 Generator: fixed misuse of InvalidArgumentCountException 2018-01-27 12:46:09 +00:00
ffb3e2b47a Player: Fixed logical nonsense in removeWindow()
The only time this is set anyway is obviously if the ID is non-null.
2018-01-27 11:02:03 +00:00
ef816c0a52 Player: Fixed window ID of closing inventory always being -1
reported by @Muqsit, thank you sir
2018-01-27 11:00:08 +00:00
3e35bc38e2 Inventory: Fixed crash when breaking right half of a double chest while open 2018-01-27 10:57:04 +00:00
de0741f727 Item: remove unused imports 2018-01-26 17:12:00 -05:00
6fd4b9f1e2 Entity: Cater for old data with CustomNameVisible as a StringTag
This was a bug in older versions, fixed by 890f72dbf2. However since ALPHA10 this has been moved to the new, strict-ified CompoundTag API, which shits its pants when it encounters a tag of the wrong type.

Closes jojoe77777/Slapper#119
2018-01-26 20:01:04 +00:00
6c8a1a5b80 Item: Remove redundant Level parameter from onActivate()
there are three other sources this could be gotten from, an arbitrary level doesn't make sense.
2018-01-25 10:15:36 +00:00
3842ee15cf Item: Removed now-obsolete Cake class
>> As of 1.2, cake has a max stack size of 64, making this class redundant as its only purpose was to declare a stack size of 1.
2018-01-25 10:09:09 +00:00
6c71b443e8 Fixed armor not dropping (#1962) 2018-01-24 20:01:32 +00:00
4a4900e5e7 Revert bad duct-tape fix that broke lots of other things
Revert "Fixed players getting full health on rejoin after quitting on death"

This reverts commit 1d4bafb6ff.
2018-01-24 19:21:32 +00:00
26d4169fea EntityShootBowEvent: Remove unnecessary kill() 2018-01-24 19:17:08 +00:00
7d88a8b315 Player: Remove useless assignments from constructor 2018-01-24 18:22:23 +00:00
41592a04b7 InventoryTransactionPacket: Update some field names 2018-01-24 13:50:30 +00:00
1d4bafb6ff Fixed players getting full health on rejoin after quitting on death
This makes #1567 less exploitable. Now, players who attempt to exploit this bug will get stuck - they won't be able to move or do anything. Not ideal, because they won't be able to respawn either - but it's better than nothing.
2018-01-24 12:27:10 +00:00
28996f561f Player: Added a hack for knockback being messed up
This needs to be updated server side and isn't because of the way player movement is currently handled. Fixing this properly will require a lot more work than this.
2018-01-24 11:56:32 +00:00
0658c0851b Entity: Remove some unused properties 2018-01-24 11:37:01 +00:00
0df2064802 Implement armor damage protection enchantments (#1839) 2018-01-24 10:13:24 +00:00
6543d96910 Inventory: Split up armor and player inventory (#1957)
* Inventory: Split up PlayerInventory and armour handling
* Fixed other players don't see armour changes. This bug also exists on master.
2018-01-23 20:01:26 +00:00
0bf5ab76fb Remove WeakRef leftovers 2018-01-23 19:04:37 +00:00
8e1394bf53 MemoryManager: Use get_declared_classes() to build lists of static properties
This makes memory dumping independent from the autoloader implementation, and fixes #1958.
2018-01-23 18:23:53 +00:00
6ddbdc9dc1 Fixed worker memory dump crash
$GLOBALS does not exist at all on threads :(
2018-01-23 17:21:24 +00:00
2a8be527d7 Remove redundant paths from BaseClassLoader
Everything under src is now handled by the Composer autoloader, and SPL doesn't exist anymore (it's a Composer library now).
2018-01-23 17:03:04 +00:00
aca1422fca Updated pthreads version for Travis 2018-01-23 16:49:32 +00:00
b0d0932ed9 DoubleChestInventory: Fixed items getting rearranged in single chests when creating a double chest
I fixed this elsewhere more than 18 months ago, why is this still here?
2018-01-23 15:50:13 +00:00
fd5557861b Changed how login verification is handled, add more useful error messages
closes #1955
2018-01-28 14:13:59 +00:00
1de7c5b114 Inventory: Added includeEmpty parameter to getContents() 2018-01-22 22:33:57 +00:00
2fb580db26 Inventory: Removed need for Inventory to have an InventoryHolder
Inventory holders are now freed from BaseInventory. They are now declared by subclasses by convention, but are not required in most cases.

Ideally, this would be followed by the removal of the need for inventories to know their holders at all. They should just be simple containers of items.

This fixes #1560 by removing FakeBlockMenu.
2018-01-22 19:44:52 +00:00
e5ca22a9a6 Player: Simplified implementation of windows => window ID map
it is not necessary to reference the actual objects here. Doing so makes the implementation more confusing. Hashes are sufficient.
2018-01-22 18:58:19 +00:00
69ddaacc28 Inventory: Add a $send parameter to clearAll() 2018-01-22 18:39:39 +00:00
897a31e608 Player: Moved logic of setUsingItem()
plugins might be using this method, or the item may have been dropped involuntarily due to server-side logic. Therefore it should be handled when the transaction is received and not when the item is dropped into the world.
2018-01-22 18:36:48 +00:00
4943ff9dfc Not sure how this got missed :< 2018-01-21 19:36:42 +00:00
e36b38939c Lever: fix placement 2018-01-21 17:53:41 +00:00
ecb3f9aeac Level: Allow broadcastLevelEvent() to accept a null position to broadcast to everyone in the Level 2018-01-21 17:41:00 +00:00
f0696f77ef Level: Added global packet broadcast mechanism 2018-01-21 17:40:31 +00:00
6813838754 EntityDamageEvent: Remove redundant TODO
Armor does absorb lightning damage by default.
2018-01-21 17:40:03 +00:00
65fe19ca71 Entity: Fixed logic error in getBlocksAround() which caused yet another firebug
Try setting a fire at z = -204, then stand on the edge between -205 and -206.

The coordinates that a BB's corners are encapsulated in are always the floor()ed coordinates

If you stand at -205.0, your BB min is -205.3 and your BB max is -204.7, which then incorrectly tells you that the BB intersects with block -204
because ceil(-204.7) == -204
when you actually are only intersecting with -205 and -206
this is as bad as using (int) to floor integers :kms:
2018-01-21 15:43:03 +00:00
a4f5cab12d Entity: Added getDataPropertyManager() 2018-01-20 20:07:11 +00:00
29e06e30b2 Fix projectiles throwing errors on launching, fix #1942 (#1943)
* Fix Projectile::setOwningEntity() on null error
2018-01-20 18:07:53 +00:00
3939e2d9dd NetworkBinaryStream: add some typehints 2018-01-20 11:05:41 +00:00
2579438b84 NetworkBinaryStream: Use nullable typehint for putVector3Nullable() instead of default value
the parameter is not optional
2018-01-20 11:01:16 +00:00
95d42b9907 Network: Remove legacy Vector3 primitive encode/decode methods 2018-01-20 10:58:39 +00:00
2eb6e075ae Refactored entity metadata handling into its own class, with type-safe methods (#1876)
This includes several other changes, including:
- SLOT data properties now accept items directly
- POS data properties now accept floored Vector3s (in future this will be block positions) or null for 0,0,0
- VECTOR3F data properties now accept Vector3s or null for 0,0,0
2018-01-20 10:52:14 +00:00
8f928915d9 Merge PR #1936: Vector3:: setComponents() documentation fix
Vector3::setComponents() and override changes/removal
2018-01-19 08:12:44 +00:00
3af8cf48b2 Removed setComponents() override in Position 2018-01-18 19:03:53 -05:00
21c03670b6 PhpDoc fix for my sanity 2018-01-18 18:04:54 -05:00
0c868b16b6 Network: Added config to pocketmine.yml to allow changing max MTU size
This might be useful for people with older routers where the connection MTU is actually lower than the router allows.
2018-01-18 18:15:14 +00:00
1e67360048 SpawnEgg: Remove redundant isSurvival() check 2018-01-18 17:04:25 +00:00
3520dafd29 Entity: Make fall distance explicit float to shut a PhpStorm bug up 2018-01-18 16:52:17 +00:00
857b63ba8f Entity: Added recalculateBoundingBox() 2018-01-18 16:35:38 +00:00
9551e5b8e5 Durable: Allow subclasses to override behaviour when the item breaks 2018-01-18 14:37:22 +00:00
c7f15a556d Durable: Don't allow damage to exceed max damage 2018-01-18 14:34:50 +00:00
efca9f0450 Item: Moved getMaxDurability() to Durable class only, and make it abstract
It's only now used in the Durable class, so it does not make sense to keep it in Item anymore. This is a leftover from the days where Durable did not exist.
2018-01-18 14:16:30 +00:00
d728154e87 Level: Fixed entities getting deleted when switching levels
So this came from a bugfix (795d6c8ddf) which fixed a memory leak related to entities getting kill()ed on chunk unload.
HOWEVER, me2016 did NOT realize that this code is actually entirely pointless and causes unexpected behaviour.

removeEntity() is used in 2 places in the core code:
1. in Entity->close() (so close() doesn't need to be called again, obviously)
2. in Entity->switchLevel() (which then causes the entirely unexpected behaviour of close()ing the entity on level change.

Conclusion: This code is pointless. This fixes the bugfix.
2018-01-17 11:30:59 +00:00
2e1a167bed Arrow class: No need to import Item class with other name (#1932) 2018-01-17 10:59:50 +00:00
6f6e3aaa21 Fixed projectiles collding with spectator players
closes #1857
2018-01-17 10:57:04 +00:00
9c65a2b890 Furnace: Fixed lit furnaces dropping the wrong item
closes #1915
2018-01-17 10:24:01 +00:00
beb5bf6dda Add API methods: Entity::isInvisible(), Entity::setInvisible() (#1930)
* Make use of the API function in Effect class
2018-01-17 09:56:59 +00:00
7a5e5773b7 Updated RakLib dependency 2018-01-16 20:01:41 +00:00
f1b0a4f1de Not sure why we are still blaming @shoghicp for this :< 2018-01-15 11:17:01 +00:00
751345c736 Updated BinaryUtils dependency 2018-01-14 18:56:31 +00:00
e850f34d76 Fix TNT block not setting fuse NBT correctly (#1917) 2018-01-14 18:10:57 +00:00
8d7c65585c Enchantment: Implement Silk Touch (#1912) 2018-01-14 13:37:27 +00:00
96f6362117 Fixed glowing redstone ore giving itself when block-picked 2018-01-14 13:35:41 +00:00
66c768d453 PR template: Make clear that "tested" is not acceptable test information
[ci skip]
2018-01-14 11:44:29 +00:00
6fe7763db9 Contributing: require details of tests done
[ci skip]
2018-01-14 11:37:51 +00:00
fda97decaa Contributing: batch commit of changes
very hypocritical of me, I know...

[ci skip]
2018-01-14 11:35:04 +00:00
b3f44562e9 Contributing: updated example
[ci skip]
2018-01-14 11:04:46 +00:00
51350be190 CONTRIBUTING.md: fixed indentation
[ci skip]
2018-01-14 10:42:53 +00:00
7f4b5d282e Fixed plugin name validation
Invalid characters in plugin names are no longer stripped. They always result in a load error.

The behaviour of replacing spaces with underscores is not changed.
2018-01-14 18:28:19 +08:00
94feecd44b Enchantment: Implemented Unbreaking 2018-01-13 19:34:45 +00:00
45b02d92d4 Math: Added RayTraceResult, removed dependence on MovingObjectPosition
MOP doesn't make any sense anyway.

RayTraceResult is a container which represents the point at which a line hits a bounding box. No dependence on blocks or entities is wanted or needed.
MovingObjectPosition has API changes to allow it to wrap RayTraceResult, but nothing uses MOP anymore anyway.

This would allow modularisation of the pocketmine\\math namespace.
2018-01-12 14:28:41 +00:00
fe4b5498e6 Level: Fixed 2D block cache not getting counted correctly
Fixes #1903
Closes #1906, which, while a pretty solution, is very inefficient (see PR discussion). This is an optimization of microscopic proportions, but the point still stands.
2018-01-12 11:02:43 +00:00
98b36fd73e Enchantment: Implemented Efficiency
This is only needed server-side for block-break animation times.
2018-01-11 20:13:57 +00:00
07c7048433 Enchantment: Converted item type bitflags to hex 2018-01-11 20:09:42 +00:00
f09cf92197 Enchantment: Updated item type flags 2018-01-11 20:08:50 +00:00
98eba11da5 Human: Use Item->getEnchantmentLevel() for Respiration check 2018-01-11 18:32:46 +00:00
a6c1e02847 Enchantment: Register Respiration enchantment
First working enchantment on master. Hooray for 3 years late.

This works out of the box (the code checking for this enchantment already exists in Human->doAirSupplyTick()).
2018-01-11 18:32:22 +00:00
b04cee12ea Item: Added API method getEnchantmentLevel() 2018-01-11 18:22:29 +00:00
c4966404bb Moved NBT to Composer library 2018-01-11 14:18:09 +00:00
579c508761 Move Binary and BinaryStream to Composer library 2018-01-11 13:19:59 +00:00
43959bccb1 Change Composer package vendor name to pocketmine instead of pmmp, update dependencies 2018-01-11 13:16:27 +00:00
e6bd12dc2f Consolidated MCPE network binary handling methods into one class, remove protocol-specific methods from BinaryStream
Remove MCPE-network specific stuff from BinaryStream, added NetworkBinaryStream
This removes dependencies of BinaryStream on core code, while providing some consolidation of network handling code.
2018-01-11 12:28:56 +00:00
7daca754b1 BinaryStream: Fixed wrong header being included
This is currently harmless, except for adding a redundant extra use
statement. However harmless it is though, it is still incorrect.
2018-01-11 12:26:50 +00:00
cb90e30bcf Entity: Fixed intersecting with blocks they aren't actually intersecting with...
at the expense of magma no longer working (which will need to be done better anyway).

This:
- reverts the +0.01 outset which hugely exacerbated the lava bug (fixes #1892)
- adds a 0.001 inset (PC-style) which prevents entities incorrectly intersecting with diagonally adjacent blocks at far-ish coordinates (lava at x=4000, z=4000 is a good way to test this).

PR #1880 does also solve this issue, but again at the expense of magma. Since the bugfix does not require a big bounding-box handling refactor, it has been separated out.
2018-01-11 11:10:36 +00:00
71d11c73f0 Math: Kill BlockIterator, added a VoxelRayTrace class with level-independent generator functions (#1885)
This is a rather larger commit than I'm happy with, but oh well.

This kills off the enormously overcomplicated BlockIterator and replaces it with a VoxelRayTrace class containing ray tracing generator functions. These functions are independent of any Level. They yield Vector3 objects with current ray trace positions to allow implementations to handle the intercepted blocks in their own ways.

Living->getLineOfSight() now uses VoxelRayTrace instead of BlockIterator.
2018-01-10 20:14:36 +00:00
24116ba846 Remove old pthreads v2 workarounds
This used to cause problems in earlier versions of pthreads if PTHREADS_INHERIT_CLASSES was not used. This is no longer a problem in pthreads v3, because pthreads v3 copies passed threaded object classes under the hood, so there is no need to manually include them anymore.

Additionally, the files in these paths don't exist anymore.
2018-01-10 10:59:58 +00:00
a0683dbb0f Chunk: Remove useless code in fastDeserialize() 2018-01-08 21:38:30 +00:00
b6811b643c .gitignore: Ignore all directories starting with bin
This might cause problems later on, but it's unlikely. Right now however, I am tired of my various PHP version directories showing up in git untracked files.
2018-01-08 11:17:29 +00:00
4d2549b50a PlayerInventory: Fixed $send parameter not working for setting armour slots 2018-01-06 16:24:41 +00:00
1fb3274f37 Server: Make start() private
This should not be exposed to plugin use.
2018-01-06 15:04:58 +00:00
6772a69c55 Server: Prevent construction of more than one server instance at a time
I have no idea when one might choose to do this, but it could cause extremely undesirable effects, so it should be prevented.
2018-01-06 14:58:51 +00:00
266a253c03 Remove dead imports 2018-01-05 19:48:04 +00:00
c62e1abf2f Kill the instabreak anti-cheat
This is annoying and it requires that the server must match this precisely to not cause bugs. Additionally, this code shits its pants when the client hits a spot of network lag.

This can be implemented easily as a plugin. There is no reason whatsoever for this to be in the core.
2018-01-05 19:43:51 +00:00
55f405f5c2 Player: Extend acceptable block-break distance by 1
Survival reach distance is 6, but that's only a measure of how far the player must reach to hit any part of the target block. Measured from the centre, this again provides a possible corner reach which is too far away from the centre of the block by sqrt(3) / 2 blocks.

Simple fix - allow an extra block's distance.
2018-01-05 19:36:02 +00:00
8fbd0e58f0 Level: Fixed possible crash with changed blocks handling
Since chunks are unloaded before changed blocks are processed, there is a small chance that a block might get changed in a chunk, and then get unloaded due to not being in use, before the updates are broadcasted.
This is unlikely to ever happen since chunks usually don't get unloaded unless they don't have loaders anyway, but it could happen (?) if a chunk is forcefully unloaded.
2018-01-05 13:46:21 +00:00
418d099a2e Merge PR #1561: Implement XP 2018-01-05 12:53:48 +00:00
9d2eb5e911 Human: Added some void typehints 2018-01-05 12:30:03 +00:00
b6c1124d50 Move XP drop amount to Human instead of Player 2018-01-05 12:09:24 +00:00
03fda936a8 Added XP level-up sounds and refactored XP gain sound handling 2018-01-05 11:58:54 +00:00
684fd46d09 Entity: Throw exception when trying to get save ID of non registered entity 2018-01-04 21:05:17 +00:00
90fc649441 Fixed bad PhpDoc leftovers from NBT streams refactor 2018-01-04 20:32:06 +00:00
0410df77aa Drop experience on death 2018-01-04 19:33:37 +00:00
0f30467f62 Added Level->dropExperience() and API for splitting XP into orb sizes 2018-01-04 19:32:54 +00:00
a84910f04c Implemented XP orbs 2018-01-04 19:28:19 +00:00
3ee225caec Human: Refactored XP API methods 2018-01-04 19:15:26 +00:00
f963dbd10d Level: Added getNearestEntity()
This may be used for AI in the future.
2018-01-04 19:10:43 +00:00
debfbf0d93 Math: Added solveQuadratic()
will be used in future for XP. This is extracted from the experience work branch.
2018-01-04 15:58:54 +00:00
5c37d298a6 Player: Changed canInteract() default max diff to sqrt(3) / 2
This is needed because players can break blocks that are outside of their field of view. A player can be inside a block and be able to break that block, while looking up, which places its centre (which is where the interact check is done from) actually behind the player's field of view. This causes anti-cheat to be triggered and makes it impossible to break blocks one is inside.

This commit changes the max negative diff to be half of the distance between a block's centre and its corners (M_SQRT_3 / 2).
2018-01-04 15:46:49 +00:00
3ca162f23f Revert "Player: Remove obsolete maxDiff parameter from canInteract()"
This reverts commit a5c3fbdd7a.
2018-01-04 15:33:23 +00:00
5f48433c95 Bucket: Added sounds for bucket fill/empty 2018-01-03 14:27:41 +00:00
33352638a9 Bucket: Fixed appearing empty when picking up still liquids
Buckets already affected by this bug will still appear empty until used. After that they'll work fine.
2018-01-03 14:22:53 +00:00
db52501462 Bucket: Fixed stack size handling for empty buckets
GOD this code is horrible
close #1472
2018-01-03 14:12:04 +00:00
3a0cbd1cd4 Block: Cleaned up double-block break handling, close #1862, close #1525
This now removes the need for recursing around for structures comprised of multiple blocks. Instead, override getAffectedBlocks() to return all blocks that need to be deleted when the current block is deleted, and make sure that only one half of the block drops something. When a player breaks one of the blocks, all the blocks affected by that block will also be destroyed, creating particles and sounds where appropriate.

This fixes creative drops for double plants and beds.
2018-01-03 13:01:05 +00:00
1bdb68b7da EnderChest: Remove dead onBreak() code (follow-up to previous commit) 2018-01-03 12:10:36 +00:00
6ce728169e Chest: Remove redundant unpairing code from onBreak()
This is already done in the Level.
2018-01-03 12:08:35 +00:00
06a3c7c478 Entity: Write attributes in AddEntityPacket 2018-01-03 11:30:22 +00:00
70982c145b Level: Clarified documentation for loadChunk() and changed misleading parameter name 2018-01-02 18:08:43 +00:00
417f2d8998 Level: Clarified documentation on getChunk() 2018-01-02 18:05:30 +00:00
7339c4ac2f Player: Fixed not being able to interact with blocks in adventure mode, close #1848
This allows other undesired behaviour like flint&steel, buckets to work in adventure mode when they shouldn't, but that's a bug for another time.
2018-01-02 16:26:59 +00:00
43a0ede9d2 Player: Fix floating-point errors when float Vector3s are given to sleepOn()
In the future this will change to block positions and the Vector3 issue will cease to be an issue.

Closes #1871
2018-01-02 16:09:58 +00:00
c747c7d025 Throw exceptions when entities/tiles are created on chunks that don't exist
These assertions don't make sense. Since the chunk field is used below in both cases, the chunk should **never** be null no matter what.
2018-01-02 13:12:54 +00:00
c9e2e8980f Fixed some places entities/players use their chunk without checking if it is valid
This may be invalid in some cases, such as:
- chunk is not loaded
- entity is not fully constructed
- entity is a Player who has not yet completed the login sequence.
2018-01-02 12:57:04 +00:00
9a956692de Fixed wasteful throwaway objects used for spawn positions 2018-01-02 12:21:11 +00:00
d30a6b60b7 .gitignore: Ignore crashdumps directory
How did this never become a problem before?!
2018-01-02 12:09:31 +00:00
41873bb115 Merge PR #1864: LevelProviders refactor 2018-01-02 11:47:11 +00:00
8064152777 LevelProvider: Add documentation for doGarbageCollection() and close() 2018-01-02 11:39:51 +00:00
872df446bd Level: Remove redundant duplicate condition in unloadChunk() 2018-01-02 11:16:20 +00:00
376a615634 thanks for the warning PhpStorm... not 2018-01-02 11:14:01 +00:00
c16c9efdf3 Chunk: Rename unload() to onUnload()
this more accurately describes what the function does.
2018-01-02 10:50:22 +00:00
c3cc6f9880 Chunk: Clean up unnecessary checks in unload() 2018-01-02 10:48:01 +00:00
1e139743b8 Level: Do level provider GC every 5 minutes from level tick
this should solve #1183, pending further testing.
2018-01-02 10:23:57 +00:00
bde0ba1100 Level: Set chunk coordinates in setChunk()
The level provider used to do this in LevelProvider->setChunk(), but it does not anymore.
2018-01-01 13:13:47 +00:00
50f273c041 Vector2: Fixed ceil() and floor() totally broken logic
"So if I Vector2->ceil()->ceil() my vector2 magically gets incrementing values..." @Sandertv 2018
2018-01-01 12:57:34 +00:00
db095f9705 Updated PreProcessor submodule 2018-01-01 12:54:18 +00:00
f580f27ec7 LevelProvider: Updated documentation 2018-01-01 11:59:22 +00:00
a46029c0f6 LevelProvider: Nuked the complicated mess out of level providers
Level providers are now cut back to just an interface to a world's data. They don't keep their own chunk registries or any stupid shit like that because the Level already does that.

This furthers the goal of being able to move level I/O off the main thread, and also drastically decreases the complication of implementing level providers.
2018-01-01 11:21:46 +00:00
1a615591e2 LevelProvider: Remove cyclic dependency between Level and LevelProvider
This will now allow LevelProviders to be constructed on threads.
2018-01-01 10:50:13 +00:00
d19683b7dd LevelProvider: Remove some dead methods 2017-12-31 18:35:23 +00:00
f17b3b2a3b LevelProvider: Refactor providers to drop lots of duplicated code 2017-12-31 18:35:23 +00:00
a0a2ea01bc LevelDB: Check for LEVELDB_ZLIB_RAW_COMPRESSION when checking for the extension's presence
We always want to validate that the leveldb provided supports the world format.
2017-12-31 17:49:02 +00:00
5132ab6cd9 LevelDB: Remove redundant folder creation in generate()
This is pointless because the call below - which is _also_ recursively creating directories - will create this directory anyway.
2017-12-31 17:46:07 +00:00
256bdf2581 McRegion: Use MainLogger::getLogger()
another one bites the dust
2017-12-31 16:06:08 +00:00
8a3f8b4706 LevelProvider: Remove redundant method requestChunkTask()
This removes one more dependency that LevelProvider has on Level.
2017-12-31 16:05:58 +00:00
7264ce43ae McRegion: Added method pathToRegion() 2017-12-31 14:25:17 +00:00
66e475cbb8 Region: Remove RegionLoader/McRegion cyclic dependency 2017-12-30 19:59:35 +00:00
1e896efff9 McRegion: Added an assert 2017-12-30 19:49:44 +00:00
4db7a7e57f Region: Change chunk offset calculation in regions to use bitmasks
I don't know why it wasn't done like this to start with. However this has not been tested yet, so this goes on a different branch for now to test.
2017-12-30 19:41:58 +00:00
54b23968e7 McRegion: Refactor some ambiguous variable names 2017-12-30 18:59:01 +00:00
bcb080e2b9 Level: Make sleepTicks private, don't write directly 2017-12-30 18:41:13 +00:00
e5c58f9b04 Player: Add typehint for maxDistance parameter of canInteract()
Not sure why this was missing :<
2017-12-30 17:43:12 +00:00
af7aef70db Implemented TextFormat::colorize() (#1837)
Implemented TextFormat::colorize()
See 4c46087ffc for the initial discussion
2017-12-30 16:51:04 +00:00
3ea72a0bf9 Merge PR #1775: NBT streams refactor 2017-12-30 15:53:47 +00:00
be02fbb352 NBT: Add typehints to PHP 7.2 standards 2017-12-30 15:07:50 +00:00
a67f7e3930 Add header includes and preprocessor checks 2017-12-30 14:56:29 +00:00
965c19375f NBT: Split up concerns of endianness and varint NBT into their own classes, separate stream handling from NBT class
The remaining methods, constants and fields in the NBT class now pertain to generic NBT functionality (except for the matchList()/matchTree() methods, but that's a job for another time). All NBT I/O specific logic has now been moved to NBTStream and its descendents.
2017-12-30 14:55:45 +00:00
63edcb8934 Updated PreProcessor submodule 2017-12-30 14:15:33 +00:00
e7a012d69a Player: Remove dead imports 2017-12-30 12:42:42 +00:00
99c55ac889 Plugin: Fixed return type documentation for getResource() 2017-12-30 12:40:50 +00:00
f14adf5827 Updated RakLib dependency 2017-12-28 12:51:16 +00:00
c64b9ad63a MovingObjectPosition: Use asVector3() instead of creating a new vector the hard way 2017-12-26 15:37:00 +00:00
dda71b06ae AxisAlignedBB: Use elseif in calculate*Offset()
It's impossible for both of these conditions to be met in the same call.
2017-12-26 14:31:42 +00:00
3c4dca7fdb ZippedResourcePack: Handle json decoding errors correctly
Previously this would crash if it failed to decode the JSON (https://forums.pmmp.io/threads/texture-pack-shows-errors-not-working.4880/)
2017-12-25 19:01:02 +00:00
ddbc5cf960 Player: Use fmod() instead of modulo operator for yaw/pitch
the modulo (%) operator only operates on integers. If it's used on floats, they are silently casted to ints, which results in loss of accuracy. Fractions of a degree might not seem important, but for ray-tracing purposes a fraction of a degree can make the difference between hit and miss.
2017-12-24 19:48:43 +00:00
1edf69892a Fixed chorus fruit teleporting players into the void in superflat worlds 2017-12-24 16:27:58 +00:00
f10c2a2df2 FlowerPot: Fix drops retaining damage
close #1844
2017-12-23 17:54:22 +00:00
3bbdc5ab5b Implemented chorus fruit 2017-12-23 15:11:48 +00:00
082e3404c3 Potion: Implement potion effects 2017-12-23 15:07:39 +00:00
547833ae23 Effect: Add constants with vanilla names where missing 2017-12-23 14:48:56 +00:00
6e1df36188 Consumables refactor (#1796)
* Removed broken EntityEatEvents - these don't fit the pattern since they only apply to Human entities anyway. PlayerItemConsumeEvent and PlayerInteractEvent can be used for cancellation purposes, and plugins can do custom stuff without mess.

* Restrict item consuming to Living entities only

* Added FoodSource->requiresHunger()

* Only items implementing the Consumable interface can now be consumed.

* The effects from consuming items are now generic-ized by way of the Living->consume() function. This is overridden in Human to allow applying food and hunger.

* Fixed the hardcoded mess for buckets
2017-12-23 13:03:41 +00:00
329fe7d844 Effect: Implement Saturation effect
I thought I did this months ago, but apparently not. Whatever, it's here now.
2017-12-23 11:35:01 +00:00
b7aaf54a6f Effect: Fixed mistake in bitshifting with effect level in instant effects
This should be the amplifier, otherwise the effect will have double-effect on level 1.
2017-12-23 11:32:58 +00:00
6332814a04 Effect: Minor cleanup on Instant Health/Damage effect amplification 2017-12-23 11:23:29 +00:00
9d4818d360 Effect: Hunger is supposed to apply every tick
This fixes oddities in the behaviour noticeable with higher effect levels.
2017-12-23 11:15:23 +00:00
36f3accf4b Effect: Don't allow cancellation of expired effect removal, close #1770 2017-12-23 10:55:25 +00:00
8d08840ea4 Effect: Better fix for duration bug seen in 3614711a02 2017-12-23 10:45:59 +00:00
7f0d0c9d63 Revert "fixed negative effect durations when level tick rate is > 1"
This reverts commit 3614711a02.
2017-12-23 10:44:21 +00:00
bf55f03a3e Merge pull request #1842 from pmmp/issues/983-interact-fix
Fix direction checking for player interactions, close #983
2017-12-23 09:42:39 +00:00
a5c3fbdd7a Player: Remove obsolete maxDiff parameter from canInteract() 2017-12-22 20:38:39 +00:00
a8bf2191b9 Player: Do direction checks for interaction in 3D instead of 2D
This fixes #983, but I haven't yet tested if this will prevent cheating in an actual hacker scenario. Needs more tests.

Additionally, this should remove the need for the negative threshold - if the diff is less than 0, the player is almost definitely cheating.
2017-12-22 20:06:59 +00:00
0688a86f57 Player: Fixed interaction checks preventing placing blocks when stood on the corner of one when using crosshairs
This issue can be seen on W10 Edition. Stand on the corner of a block and turn so that the majority of the target block is behind you. Then look down and try to mine it.
2017-12-22 19:58:33 +00:00
2e11e448dd Player: Dump crafting grid on death, not on respawn
This fixes players managing to retain items by getting killed while they have something in the crafting grid.
2017-12-22 11:34:33 +00:00
8bf275cb8b Player: Execute PlayerPreLoginEvent before banlist/whitelist checks, close #1831 (#1833) 2017-12-22 11:19:56 +00:00
1896576a24 ResourcePackManager: Remove Server constructor dependency 2017-12-22 11:11:58 +00:00
8f811c29d7 ResourcePackManager: Remove redundant config property
This was only used in the constructor, there's no need to store it.
2017-12-22 11:05:47 +00:00
3a4f79629c ResourcePackManager: Add API method getPath() 2017-12-22 11:04:15 +00:00
375243860e Potion: Restrict item stack size to 1 2017-12-21 15:02:56 +00:00
a842a5319f Enchantment: Create constant name once, and reuse it
this is more readable and more maintainable.
2017-12-21 13:11:31 +00:00
c2b0f6af22 Enchantment: Simplify getEnchantment() with null coalesce
This is made possible by 0e538ee51d.
2017-12-21 13:02:24 +00:00
6490d99ac2 Enchantment: Added a TODO (calculating XP min/max level cost bounds) 2017-12-21 12:55:55 +00:00
e0b063ac85 Enchantment: Added max level property 2017-12-21 12:49:34 +00:00
12ac2f4ac7 Enchantment: Fixed rarity constant values to match vanilla
Rarity is used for "weighting" enchantments on enchantment tables and such. Therefore higher numbers mean the enchantment is more common. This changes the rarity values to match vanilla.
2017-12-21 12:48:35 +00:00
cc1951c7ba Enchantment: Remove activation type stuff
This isn't and won't be used anywhere.
2017-12-21 12:48:14 +00:00
0e538ee51d Enchantment: Split up enchantment type data and enchantment instance data (#1825)
* Enchantment: Split enchantment type data from instance data
This commit splits enchantments into (effectively) enchantment TYPES vs enchantment INSTANCES.

When applying an enchantment to an item, it only needs to know 2 things:
1. the enchantment ID (identifier) which is used to identify the TYPE
2. the enchantment LEVEL which is used to modify the enchantment's power IN THIS INSTANCE.

Therefore, the LEVEL is not an immutable property. However, all other properties of the currently-named "Enchantment" class are immutable type properties.
Currently, when applying an enchantment to an item, a copy of the enchantment object is created from the registry, and returned. This copies all of the properties contained by the type, which is obviously sub optimal.
2017-12-21 12:40:33 +00:00
1b4b832c8c Added a getEntry() to BanList (#1830) 2017-12-21 10:08:56 +00:00
4f8e4f0522 Add EOF newlines where missing (bulk) (#1836)
This should solve issues with people making GitHub PRs and having the web editor messing things up. GitHub Web Editor sucks :(
2017-12-20 11:56:36 +00:00
0ee78d2416 Update DevTools submodule, fix build 2017-12-17 15:01:05 +00:00
4c46087ffc TextFormat: Added EOL constant (for MCPE)
MCPE always uses LF for line endings. PHP_EOL might be LF, CRLF, or CR depending on the platform, so it should not be used for (for example) sending messages to players containing newlines.
2017-12-17 14:58:37 +00:00
bb3e72ea4b StringTag: Fixed bad error message for bad value type 2017-12-17 12:30:18 +00:00
914e4c9a72 Enchantment: Fix formatting issue 2017-12-16 13:04:25 +00:00
9fd7312629 EnchantCommand: Fix vanilla translation
This parameter isn't required server side, but it doesn't matter anyway.
2017-12-16 10:34:38 +00:00
24387d1efe Enchantment: Add some PhpDoc for fields 2017-12-16 10:01:42 +00:00
3853938ef3 Level: Manage block cache appropriately when loading/unloading/replacing chunks, close #1813 (#1823)
This changes the block cache to be a 2-dimensional hashmap of [chunkHash][blockHash]. This is needed to more effectively dispose of chunk-specific block caches when chunks are modified.

This now destroys the cache for specific chunk indexes in the following circumstances:
- When a chunk is unloaded (the cache isn't needed anymore)
- When a chunk is set into the world (for example, from the generator)
- When a chunk is loaded (probably unnecessary)

This resolves the ghost blocks bug many have been complaining about.
2017-12-16 09:49:48 +00:00
4ec8416f9a Level: Fix minor code duplication in setChunk() 2017-12-15 16:47:59 +00:00
8aff793a4f Fix drops for leaves, close #1821
Seems that leaves are another special case - they technically speaking accept any tool to break, but only drop when shears are used. They don't REQUIRE shears because if they did the break time would be longer for non-shears tools.
2017-12-15 10:14:24 +00:00
d93ded9047 merge 1.2.7 "changes" 2017-12-14 18:59:11 +00:00
fbd04b0fe7 Bump to 1.2.7 2017-12-14 18:56:32 +00:00
953f45c50f Altered armour handling, now works for damage other than PvP 2017-12-14 12:37:28 +00:00
1822abc862 Living: Apply absorption after effect damage reduction is checked 2017-12-14 12:03:12 +00:00
92e966686e Refactor Living->attack() into several methods 2017-12-14 11:39:05 +00:00
3f50f88e2c Player: Cleaned up how hurt animations are handled
Override Living->doHitAnimation() instead to ensure that the animation always gets sent to the player.
2017-12-14 11:34:09 +00:00
532600ab67 Player: Remove another redundant attack check
This is checked in Player->attack() anyway.
2017-12-14 11:03:13 +00:00
78f8fe602c Player: Remove redundant PvP check
This is already checked in a block lower down.
2017-12-14 10:59:17 +00:00
e75fbd7fb4 Changed Effect colours to use Color objects instead of arrays (#1814) 2017-12-14 10:21:07 +00:00
06f605879a Effect: Save and restore ambiency properly 2017-12-14 10:10:26 +00:00
4c7038f941 Effect: Added proper documentation on "ambiency" 2017-12-14 09:57:20 +00:00
4bd4d42b82 Fixed raw porkchop being inedible 2017-12-14 09:09:47 +00:00
f5ebfc3418 Effect: Added Fatal Poison effect
This is identical to normal Poison, except that it kills the victim. Parrots receive this effect when they are fed cookies.
2017-12-13 18:59:49 +00:00
4ae278686c Player: Hack anti-fly to ignore levitation 2017-12-13 18:50:56 +00:00
740786c99e PillarRotationHelper: Drop redundant commit 2017-12-13 18:39:16 +00:00
6abf880e44 Block: Drop unnecessary parameters for ItemFactory::get() 2017-12-13 18:37:04 +00:00
853411fa4f Merge pull request #1795 from pmmp/tools-refactor
Tools refactor
2017-12-13 18:04:12 +00:00
6e30d23254 Added missing properties for several blocks 2017-12-13 16:28:21 +00:00
717b36a983 Cleaned up non-trivial getDrops() stuff 2017-12-13 14:47:50 +00:00
90eed14cd6 Fixed cobweb drops 2017-12-13 14:46:58 +00:00
4452e6ac93 Merge branch 'master' into tools-refactor 2017-12-13 12:58:50 +00:00
66562f24fb Made Leaves drops more generic, fix dark oak leaves not dropping apples 2017-12-13 12:57:58 +00:00
56f1a6ba37 Block: Migrated all trivial drops code to getDropsForCompatibleTool()
getDrops() should now be overridden only for special cases. There are some non-trivial overrides left that are going to need some extra work to clean up.
2017-12-13 12:49:58 +00:00
8c47a338df Block: Remove unused imports 2017-12-13 12:44:21 +00:00
7c6535283e SnowLayer: Fixed tool requirement 2017-12-13 12:39:29 +00:00
c669819bbb Fixed stained/hardened clay being harvestable without a pickaxe, close #1803 2017-12-13 12:01:46 +00:00
50f3231629 Fixed being able to mine double stone slabs without a pickaxe 2017-12-13 11:34:41 +00:00
015cde2169 Merge branch 'master' into tools-refactor 2017-12-13 11:26:24 +00:00
dc064dfa2e Level: Fixed some unnecessary double uses of Level::blockHash() 2017-12-13 11:25:36 +00:00
131a6a4d19 Cache fix related to #1813: Don't cache blocks for chunks that don't exist 2017-12-13 10:47:12 +00:00
67a576722c Fixed item frames placed on invalid blocks, close #1804 2017-12-13 09:46:18 +00:00
b9b50dd5dc Added Block->getDropsForCompatibleTool(), removed lots of boilerplate code from subclasses
The function name is a little long-winded, but that can always be refactored later if needed. This provides a way for blocks requiring specific tools to override drops with non-standard stuff without needing to worry about what tool type was used.

It's also possible that passing the Item used here is actually entirely redundant, but again that can be fixed later.
2017-12-12 20:02:50 +00:00
da3640357c Rename Block->canBeBrokenWith() to isCompatibleWithTool() and add documentation
This name better describes it. "can be broken with" implies that items which this returns false for cannot destroy the block at all, which is incorrect. What this actually returns is whether the item is the best tool to use to break the block.
2017-12-12 19:51:31 +00:00
0004e7429f Added some documentation on harvest level properties 2017-12-12 16:55:00 +00:00
e2e6b7516a Removed WoodenTool classes
These were only needed for their fuel properties, which are the same for all tools of the wooden tier anyway.
2017-12-12 13:55:38 +00:00
b903161a5d Refactored tool efficiency handling
This fixes lots of bugs with things like wool, cobwebs, swords.
2017-12-12 13:55:36 +00:00
99fe63b2a3 Added harvest level properties to applicable blocks
this fixes block-breaking animations with wrong tools, and also finally resolves the long-standing hierarchy problem in Stair.
2017-12-12 13:54:17 +00:00
dbc180315e Declare tool harvest level as a property 2017-12-12 13:54:16 +00:00
45983acc0d Fixed too-fast break times with wrong tool types 2017-12-12 13:54:16 +00:00
a02af1053f Remove redundant overrides from WoodenTools 2017-12-12 13:54:16 +00:00
7de88b9040 Tool tier efficiency should still apply if the block can't be harvested
If you use an iron pickaxe on obsidian, it still mines faster because the tool types are compatible, even though the tool is not high enough.
2017-12-12 13:54:06 +00:00
58327d0514 Change block tool types to bitflags
This allows specification of multiple tool types for a block, such as cobwebs.
2017-12-12 13:51:33 +00:00
db31d13f96 Added Item->getBlockToolType() 2017-12-12 13:45:52 +00:00
55d0684565 Move block-breaking tool-type constants to a BlockToolType interface 2017-12-12 13:45:52 +00:00
7e3cd24444 Added TieredTool->getTier() 2017-12-12 13:45:51 +00:00
2088a43c56 Refactored tool hierarchy 2017-12-12 13:45:51 +00:00
3beccc47cd SlotChangeAction: Remove superfluous >= 0 inventorySlot check
This is done by slotExists() anyway.
2017-12-12 10:36:53 +00:00
dfc2d1dfe6 Stop hardcoding src/pocketmine/resources everywhere 2017-12-11 19:52:49 +00:00
1f1531810d Added \pocketmine\RESOURCE_PATH and Server->getResourcePath() 2017-12-11 19:52:20 +00:00
a5fc77749f Added -file (-f) option to start.ps1
This allows specifying a PocketMine-MP PHP file to execute (phar or source) to use to run the server, like start.sh. If not specified, auto-detection is used.
2017-12-11 19:40:02 +00:00
98cb7f2e10 Removed redundant filePath from Server constructor
This parameter is hardcoded to \pocketmine\PATH in PocketMine.php. Additionally, it does not make sense for the server source path to not be the server source path. \pocketmine\PATH is accessible from the Server context, therefore it should be used and does not need to be stored.
2017-12-11 19:25:06 +00:00
e58db75396 Level: Remove redundant null checks from useBreakOn()
These checks are not needed as of 3eae7a1875.
2017-12-11 16:31:43 +00:00
a94c669730 Fixed sword efficiency on anything that's not cobwebs 2017-12-11 12:57:18 +00:00
45ee115b67 Player: Fixed bad effects killing creative players
Players aren't supposed to take magic damage in creative... I don't know who added this, but it's wrong.
2017-12-10 20:50:50 +00:00
44e06f6a32 Player: Stop abusing getItemInHand() when we already have it stored 2017-12-10 17:08:56 +00:00
2e62c084a4 Oops! composer.lock wasn't up to date 2017-12-10 12:34:01 +00:00
a3622dfa9d Updated PocketMine-SPL dependency 2017-12-10 12:26:48 +00:00
7c8a29151c MemoryManager: Remove unused field (leftover from 59d9d6a7df) 2017-12-10 12:12:43 +00:00
8a90d159fe Cleanup unused imports 2017-12-10 12:09:46 +00:00
bf4076766e Living: Fixed passing FloatTag to setHealth() when HealF tag is present, close #1784 2017-12-09 20:31:14 +00:00
49dbd8b2c8 Living: Remove superfluous fire resistance check from dealFireDamage()
This is already checked in Living->attack(). It's preferable to allow it to be cancelled there since plugins can then un-cancel EntityDamageEvent to bypass the effect.
2017-12-07 17:32:50 +00:00
502dd14c67 Entity: Remove excess whitespace in doOnFireTick() 2017-12-07 17:28:37 +00:00
74239eec69 Living: Remove nonsensical >0 condition on boolean
Maybe this once returned integers, but it doesn't anymore.
2017-12-07 16:49:16 +00:00
3c936e1be8 Entity: removed dead maxFireTicks property 2017-12-07 16:37:32 +00:00
16fd37a039 Entity: Add getter & setter for fireTicks 2017-12-07 16:37:01 +00:00
1ce961f688 Merge branch 'command-reader-fix' 2017-12-07 13:55:48 +00:00
d80f711d18 CommandReader: Removed redundant else branch 2017-12-07 13:50:24 +00:00
ebd3d207e4 Fixed server not accepting commands after pressing ctrl+D (non-readline) 2017-12-07 13:42:34 +00:00
31f0437c96 fix readline crash when user presses ctrl+D 2017-12-07 13:41:58 +00:00
b06ca6eb0b Rename Living->callDeathEvent() to Living->onDeath() 2017-12-07 12:26:49 +00:00
67a09a9b16 Bump versions for 1.2.6
No changes. Mojang sucks.
2017-12-06 18:12:45 +00:00
51cec525ee Added methods for calculating sun angle and sky light level reduction by day time
Use real sky light level in Level->getFullLightAt()

close #1471
2017-12-06 12:40:52 +00:00
a5f4dda918 Added documentation for Level->addChunkPacket()
this method is confusingly named
2017-12-06 11:15:17 +00:00
e2d66ac96d Use Player->isBanned() instead of repeating code 2017-12-06 10:38:02 +00:00
d03fdd5f72 Liquids refactor, bug fixes and performance improvements (#1753)
* Added Liquid->getLiquidLevelDecreasePerBlock()

* Fixed lava turning into cobblestone when flowing over water

* Cache liquid flow vectors for faster entity movement

* Removed a condition that made lava impossible to get rid of
In the PC code, the equivalent code makes the delay between scheduled ticks 4 times longer. Here, it just breaks the code. I don't know what the 4x stuff is about, but this code does not produce the expected behaviour and lava works fine regardless.

* Fixed strange behaviour with liquids trying to flow into other liquids
Liquids should consider other liquids as a path of least resistance. However, they should not actually flow into them. This fixes a variety of CPU leak issues with falling water in large water bodies such as oceans.
This also fixes the plus-shape effect that liquid is supposed to produce when a source is placed above ground.

* Removed a bad optimization making liquids flowing down slopes behave undesirably

* Optimize performance of slope searching by limiting recursion depth based on previous path lengths
If we already found a step down on a previous run after 2 blocks, it doesn't make sense to continue allowing checking 4 blocks because the results will just be ignored. This allows limiting the number of recursion steps, which significantly improves the performance when flowing down slopes.
However, this will still be just as bad for performance on flat terrain as it was to start with.

* Make some Liquid methods only accept Blocks as parameters
these are only ever passed blocks anyway, doesn't make sense to allow vectors.

* Moved some things to local variables
these are each only used in one function, so it doesn't make sense for them to be class members.

* Fixed water flow down slopes going everywhere, but degraded performance again

* Lava should only search 2 blocks for a slope

* Stop wasting CPU calculating optimal flow directions for liquids with too-high decay
It calculates the flow directions and THEN doesn't use them when it
realizes the flow decay is too high. This is completely pointless.

* Use a less hacky method to handle lava flowing into water

* Doubled flow performance on flat terrain
Since calculateFlowCost() usually ends up visiting the same blocks about 6 times when on flat terrain, it makes sense to cache some stuff for when blocks get revisited so expensive dumb checks don't need to keep on being done. On my machine this produces a 50-60% performance improvement when flowing on flat terrain.

* Fixed missing return values in Liquid->onUpdate()
these return values aren't used anywhere, but we should be consistent

* Don't allow flowing back in the same direction we just came from
This reduces the recursions by about 30%, providing about the same percentage performance improvement.

* Remove Liquid's temporalVector (it's not used anymore)
primitive types for the win!

* Move liquid collide to its own method

* add sound for lava/water mix
2017-12-04 10:09:35 +00:00
990a48d858 Better error message when a level is unloaded during its level tick
Plugins may cause this issue unexpectedly by unloading levels directly during events such as EntityDamageEvent. This adds a better error message to allow developers to understand what is going on and create appropriate workarounds.
2017-12-04 10:01:55 +00:00
af68125872 Make Level->getName() less volatile
this resolves problems with crashes when getName() is called on an unloaded level. This obviously doesn't solve the root cause of the issue (level being accessed after unload) but since many things use the level name without checking if it's unloaded first, it's a bad idea for it to be volatile.

This resolves the server crash issue noted in #1527, where an exception is raised due to level unload during a tick, which subsequently causes a crash when trying to log the exception.
2017-12-04 09:57:53 +00:00
5a0afa9f88 Fixed broken logic in EntityEffectEvents, close #1767 (#1768) 2017-12-03 16:14:20 +00:00
c301788864 API bump 2017-12-02 17:22:05 +00:00
472bf1a1ef Kill off the JSON garbage in commands
kill it with fire!
2017-12-02 16:33:19 +00:00
1a4b653d07 Color: Fixed a confusing inconsistency in documentation 2017-12-02 16:17:27 +00:00
d9f0546cb3 Added Color::mix() 2017-12-02 16:17:12 +00:00
92a1f45175 Make Living::addEffect() return bool (#1755) 2017-12-01 16:56:37 +00:00
0afe20c382 Remove redundant overridden meta property from Air 2017-11-30 11:10:07 +00:00
e94db980d7 Fixed not being able to wear armour 2017-11-29 19:51:38 +00:00
2cb81b5f8d NetworkInventoryAction: Allow returning null to ignore weird transactions
Revert "Return null on unmatched inventory action and log details"

This reverts commit fd7fb10223.
2017-11-29 12:44:41 +00:00
78cf875080 Quick-fix for crafting with big crafting grid after cancelling PlayerInteractEvent on a crafting table
this is not an ideal solution, but it works. Crafting is messy and is going to need more refactoring. Fixes #1480
2017-11-28 19:23:26 +00:00
878f1bffb9 CraftingTransaction: Don't hardcode crafting grid sizes 2017-11-28 17:29:53 +00:00
98ac6fc7be Check inventory slot is in range in SlotChangeAction 2017-11-28 16:56:02 +00:00
88318d740a Use standard subchunk iterator code in Explosion
this causes a slight performance loss (<10%), but in a sane language this would be inlined anyway
2017-11-28 11:20:22 +00:00
d3e5733ea0 Significantly improved light population performance using subchunk
direct accessing

These changes produce upwards of 2x better performance (YMMV, also
depends on the circumstances).
2017-11-28 11:20:22 +00:00
4703715063 Added a SubChunkIteratorManager class for faster subchunk handling 2017-11-28 11:20:14 +00:00
523a7f0999 Fix a very rare light propagation bug
This could occur when light sources were placed near each other and one of them is removed, the other's light would not be propagated far enough because the node wasn't queued for updating although it was marked as if it was.
2017-11-27 19:43:56 +00:00
256527c953 Chunk: Fixed possible bug with Chunk->setBlockData()
to be honest this would probably never affect anything, but let's be consistent.
2017-11-27 19:26:20 +00:00
b93691a177 Chunk: Remove redundant assignment 2017-11-27 18:58:08 +00:00
48c5db4296 Chunk: Add some PhpDoc 2017-11-27 17:51:42 +00:00
c564655f9b Chunk: Remove unnecessary default values
these are assigned in the constructor anyway.
2017-11-27 17:49:08 +00:00
49301b0d74 Chunk: Use an SplFixedArray for subchunks 2017-11-27 17:46:48 +00:00
8bc733514b LevelDB: Fixed nonsensical array access in iterator loop 2017-11-27 17:21:26 +00:00
c1a6711514 Fix for explosions modifying the wrong subchunks under some circumstances 2017-11-27 17:11:52 +00:00
f477cfa1bf Fixed a mistake in AvailableCommandsPacket 2017-11-25 11:15:20 +00:00
1f5f67e087 Liquid: Removed a bad hack-fix, fixed mobs not moving when water flows around them
this breaks more than it appears to fix, and I can't reproduce any CPU
leaks when block updates are enabled, so I'm going to assume this is OK.
2017-11-24 17:23:12 +00:00
74967eed87 Liquid: Stop abusing getLevel() in performance-sensitive situations
Most of these methods are called from onUpdate(). It's unreasonable to
assume that the level might be null during a tick (unless a plugin
messes with a block update event or something, but that's undefined
behaviour anyway). Using getLevel() simply wastes processing time by
constantly checking if the level is closed.
2017-11-24 16:58:03 +00:00
b88ffa3bdf Fixed a mistake in Block->getSide() documentation
side() -> getSide()
2017-11-24 15:09:55 +00:00
79fd9b1c96 added RottenFlesh item 2017-11-24 10:46:55 +00:00
ed195e1167 phpdoc 2017-11-23 17:27:41 +00:00
667a54fd00 Store world height in the Level for faster access
this might look like a micro optimization, but it shows up big-time on profiler snapshots.
2017-11-23 17:24:37 +00:00
b22b493abb Fixed Player->onDeathUpdate() not being called
I did not realize this was going to be a problem... argh! stupid messy player impl D:
2017-11-23 14:23:57 +00:00
0badaeb8f4 bump max dead ticks to 25 so death smoke cloud works properly
I wish this wasn't client sided... it's a pain to get it synced properly.
2017-11-22 19:55:25 +00:00
c5ac6a7606 Remove redundant count() for effects ticking 2017-11-22 19:44:22 +00:00
e9951b1b1f Remove redundant condition for setBreathing() 2017-11-22 19:43:09 +00:00
47f94eebd1 Use maxDeadTicks instead of hardcoded 20 2017-11-22 18:58:58 +00:00
e9e22db1e7 Cleaned up death animation handling, removed dead ticking from non-Living entities 2017-11-22 17:17:47 +00:00
75e469c380 Fixed bad parameter names due to old code additions in Block->place() 2017-11-22 14:26:55 +00:00
686e1c4470 Implement ender chest (#1462) 2017-11-22 14:25:21 +00:00
8d59843020 Order tile constants alphabetically 2017-11-22 14:00:41 +00:00
580b30b768 update versions 2017-11-22 13:51:40 +00:00
589ca45825 Updated RakLib dependency (again) 2017-11-22 09:43:33 +00:00
88ad43971a constant visibility 2017-11-21 16:50:27 +00:00
1fd9994056 Merge branch 'master' into mcpe-1.2.5 2017-11-21 16:48:18 +00:00
808227d9a9 Hack for player spawning issue (ref. #1539) 2017-11-21 15:20:56 +00:00
74b074753f Bulk addition of constant visibilities
thanks PhpStorm inspections plugin for annoying the shit out of me until
I did this.
2017-11-21 14:44:10 +00:00
3f854127ca Updated RakLib depdendency 2017-11-21 14:36:23 +00:00
9da19b5f15 Added API methods for getting & setting armour dye colours 2017-11-21 14:10:33 +00:00
78d24b9183 Take 2: Fixed resource pack matching for uppercased UUIDs
fixed the wrong damned bug...
2017-11-21 11:29:12 +00:00
46afb7caf1 Fixed resource pack matching for uppercased UUIDs 2017-11-21 11:25:21 +00:00
0ee452773d Fixed missing getValue() implementation on CompoundTag 2017-11-21 10:52:00 +00:00
a39c9e8c8e add ResourcePack->getPath(), close #1559 2017-11-20 13:24:30 +00:00
32714d4564 Don't write server.properties to disk unless it's been modified at runtime 2017-11-20 10:04:39 +00:00
feade9d982 Added a flag to Config to allow detecting if it has been modified since it was last saved 2017-11-20 10:04:11 +00:00
373f085436 Fixed a usage of get(true) 2017-11-20 09:50:52 +00:00
d2416d335e Use keepMovement in spectator and when movement anti-cheat is disabled
this makes it much less expensive for players to move around when anti-cheat is disabled. And let's be honest... who uses this shit anyway
2017-11-19 19:31:03 +00:00
a8ad956b29 Fixed keepMovement logic 2017-11-19 19:28:04 +00:00
00a9ae6c95 make use of getSavableEntities() in Level->unloadChunk()
why couldn't I have thought of this before I changed this the first time >.>
2017-11-19 18:08:42 +00:00
a9df383346 generalized conditions for saving entities with chunks 2017-11-19 18:06:38 +00:00
19dc22d6b3 Chunk save: skip entities which won't be saved anyway
don't just hardcode this to players
2017-11-19 17:57:54 +00:00
2fd61163bf cleanup some chunks leftovers from 1.0 2017-11-19 17:52:36 +00:00
5640bcb0b8 add some new leveldb keys 2017-11-19 17:43:54 +00:00
ea3c7383fb Added support for handling MCPE 1.2 leveldb worlds
requires php-leveldb version >=0.2.1 and the latest version of
pmmp/leveldb-mcpe
2017-11-19 17:31:09 +00:00
7e496afdd1 Fixed issues with LevelDB worlds silently getting overwritten with the default format when LevelDB extension is not loaded
Always register the level provider (to allow detecting the world format) but throw exceptions if anything tries to use it without the extension being loaded.
2017-11-19 17:28:16 +00:00
3bc3a0bb49 Remove redundant inventory resend on gamemode change
inventory isn't modified, so there is no need to resend it
2017-11-19 15:34:29 +00:00
c75e62b38c Fix /gamemode output again 2017-11-19 15:28:34 +00:00
3a80ec4db8 Add bed too far message 2017-11-19 10:22:04 +00:00
8abad33048 Change TextFormat::WHITE to RESET in Server.php 2017-11-19 10:22:04 +00:00
a91a4489d4 Updated PocketMine-Language submodule 2017-11-19 10:21:06 +00:00
96348e0e44 Fix setMaxAirSupplyTicks() (#1555) 2017-11-19 01:40:46 +00:00
dd8a772d43 Removed handler for PlayerHotbarPacket
this thing is useless now, and the equipment stuff can be done with MobEquipmentPacket anyway.
2017-11-18 16:03:18 +00:00
dc553142c9 Remove redundant if/else in Player->checkGroundState() 2017-11-18 15:59:51 +00:00
81fe00a0a5 Slightly simplify Player->kick() 2017-11-18 15:56:58 +00:00
6facd8b50f Provide a way for plugins such as Specter to bypass chain verification 2017-11-18 12:44:18 +00:00
e709e3c653 Allow skin geometry name field to be missing
it's not needed, and plugins doing this might want to skip it
2017-11-18 12:32:31 +00:00
eaba105614 Durable: use new CompoundTag API 2017-11-18 11:13:35 +00:00
12bbc764ec Fixed Level->getSafeSpawn() looking for blocks in chunk 0,0 2017-11-17 20:45:29 +00:00
bee3c4f5cd Cleaned up error messages for submodules (they are Composer dependencies now) 2017-11-17 19:56:05 +00:00
bda40edebe Fixed default level spawning bug reported on forums
https://forums.pmmp.io/threads/pocketmine-mp-version-1-7dev-399-error-listtag-members-must-be-namedtags-got-integer-in-given.4561
2017-11-17 16:59:57 +00:00
5178373d8a fixed overoptimized code in getSafeSpawn(), close #1248 2017-11-17 13:58:03 +00:00
28188e5ef4 remove redundant count() for updateTiles 2017-11-17 13:47:54 +00:00
7c2dccd2a6 Replace Player->joined with Player->spawned, remove redundant field
spawned serves basically the same purpose as joined does.
2017-11-17 13:44:37 +00:00
adabfe78df no-op for PlayerAction START_SLEEPING
this is pretty pointless tbh
2017-11-17 13:30:25 +00:00
0fdceb6736 Remove useless sendNextChunk() condition
if the load queue is empty, it makes no difference whether we're spawned or not.
2017-11-17 13:24:31 +00:00
ffa9a91a95 Remove dead craftingType field from Player 2017-11-17 12:57:49 +00:00
78bb951942 Remove redundant survival check for exhaustion 2017-11-17 12:55:48 +00:00
7508524b7b Arrange login sequence code in a bit more chronological order 2017-11-17 12:47:57 +00:00
db4a8be240 Remove duplicated duplicated player code in Player 2017-11-17 12:39:12 +00:00
3fe9963c84 remove redundant arguments for Entity methods 2017-11-17 12:19:36 +00:00
db8a835a64 add a default value for Entity->setCanClimb() 2017-11-17 12:19:04 +00:00
460d540dbc Further cleanup on ListTag and CompoundTag usage 2017-11-17 11:43:32 +00:00
665130561e Further cleanup on NBT dynamic field access
not sure how I missed so many of these... there are probably lots more besides :(
2017-11-17 11:19:36 +00:00
48a7627b96 add constants for NBT tag names in WritableBook 2017-11-17 10:48:48 +00:00
235fc4cd2f remove redundant null coalesce 2017-11-17 10:45:14 +00:00
e0654b85ba get rid of dynamic field assignments
nearly there now... eventually
2017-11-17 10:43:51 +00:00
19315dfd06 Some cleanup on WritableBook code, get rid of some CompoundTag magic 2017-11-17 10:43:51 +00:00
f3ee605cd3 ignore doxygen files 2017-11-16 16:37:30 +00:00
976d5583cc Remove ItemFrame drops hack 2017-11-16 15:13:22 +00:00
6adc813a7f Fixed disable-block-ticking pocketmine.yml config not working 2017-11-16 14:45:00 +00:00
769f3f75cd added public doxygen configuration 2017-11-16 10:38:39 +00:00
432d90bddd quickfixes for command messages
these will have to be fixed properly at a later date
2017-11-16 08:56:01 +00:00
3a16985d45 Cleaned up item & arrow pickup code 2017-11-15 12:14:42 +00:00
bbbed22467 Save player data after PlayerQuitEvent (#1544), close #1543, close #1482
This reverses a bad solution for #1482 for level unloading on PlayerQuitEvent which caused more widespread issues with plugins doing other, more common things on player quit which directly affected the save data.
2017-11-15 11:16:02 +00:00
2794df34ab Basic implementation of banners, including API to modify them with ease. (#1331)
Banner crafting is NOT implemented yet.
2017-11-15 11:10:46 +00:00
73cd195e76 Merge branch 'master' into mcpe-1.2.5 2017-11-14 20:06:00 +00:00
0d2b171c2c Remove RakLib and SPL submodules, start using Composer 2017-11-14 19:37:58 +00:00
aa399a1109 migrate to new CompoundTag API (#1515) 2017-11-10 15:38:21 +00:00
d4494687d1 Fixed collision blocks not being recalculated after teleporting, close #1531 2017-11-09 15:11:42 +00:00
6fe45a69c8 Updated RakLib submodule 2017-11-09 14:44:38 +00:00
784ecef805 Remove unnecessary count() 2017-11-08 19:44:10 +00:00
41f363d0c1 Added encode for AvailableCommandsPacket, bring back command lists (no arguments yet) 2017-11-08 11:52:06 +00:00
827ee5ff33 more constants in Tile 2017-11-08 10:49:15 +00:00
a4e955c0a4 Merge branch 'master' into mcpe-1.2.5 2017-11-07 15:27:14 +00:00
733e61f815 add return typehints for Item fluent methods
to prevent issues like a2d4baf8b9 happening again >.>
2017-11-07 09:54:08 +00:00
0621d5c8ea Fixed JSON NBT parsing lists in /give 2017-11-07 09:50:59 +00:00
a2d4baf8b9 Fixed ItemBlock->setDamage() not returning a value 2017-11-07 09:44:34 +00:00
23bc97e098 Updated PocketMine-DevTools submodule 2017-11-07 09:36:58 +00:00
14e6e3694d Updated RakLib submodule 2017-11-07 09:35:00 +00:00
0e64c3dad8 fixed misusing isAlive(), close #1523 2017-11-07 09:32:38 +00:00
99f06c6c18 Fixed player hit animations 2017-11-06 14:41:48 +00:00
3ca9e6ae98 Merge branch 'master' into mcpe-1.2.5 2017-11-06 14:35:10 +00:00
fd0b07a0aa Added API to allow getting player latency 2017-11-06 14:33:27 +00:00
6ece799998 Updated RakLib submodule 2017-11-06 09:09:20 +00:00
a9c75a882a Updated PocketMine-SPL submodule 2017-11-05 20:51:26 +00:00
4437b67178 added some EntityEventPacket constants 2017-11-05 12:41:39 +00:00
34d2047ac3 A better error message for Server::getInstance() access on other threads 2017-11-05 18:40:47 +08:00
20d2ef9d38 Fixed players respawning in the wrong world
add() returns a Vector3 instance, not a Position instance... argh
2017-11-04 22:04:33 +00:00
eab7b93483 Fixed misuse of kill() and close() when deleting entities (#1490) 2017-11-04 19:30:48 +00:00
e84ab8fec2 Disable stats reporting by default on new installs
since we don't have a stats server at the moment, this simply causes long delays on server stop while the server instance attempts to communicate with stats.pocketmine.net.
2017-11-04 18:41:18 +00:00
a66a757f56 Cleaned up EntityEventPacket handling 2017-11-04 18:31:35 +00:00
ddb7fd12f2 removed obsolete EntityEvent broadcast 2017-11-04 18:28:29 +00:00
6ccb494f8d added API to get player language code
sadly this isn't particularly useful without something like the intl
extension to translate the language codes to ISO-632-1 codes like the
ones PocketMine-MP uses. However, this will do for now.
2017-11-04 15:50:00 +00:00
2ec7763bd6 Cosmetically improve UUID::equals() (#1517) 2017-11-04 10:45:05 +00:00
d663887f9c Merge branch 'master' into mcpe-1.2.5 2017-11-03 16:43:34 -04:00
6ebe3bfbea use Player->sendDataPacket() with immediate parameter 2017-11-03 19:00:08 +00:00
4533df17cf make username validation on login less stupid
why are we checking if the username is valid AFTER we already tried to set it? it might not even be a string
2017-11-03 18:49:28 +00:00
8ae663425f try...catch attempt to decode connection request in incompatible logins
to allow protocol version hacking without it being so damn inconvenient
2017-11-03 18:46:40 +00:00
e95b1d4b00 look for item IDs in ItemIds instead of Item
Item is likely to be more polluted by other constants which aren't item IDs.
2017-11-03 12:42:51 +00:00
8ad02c9a4e Remove redundant condition from ItemFactory
it's unrealistic to have a numeric constant name, so this condition is pointless.
2017-11-03 12:41:24 +00:00
754e088ee8 Change visibility of Block->boundingBox 2017-11-03 12:19:51 +00:00
451f5d0cd7 Fixed block-pick on crops giving the crop block itself 2017-11-03 12:17:38 +00:00
42ed03fd02 Merge branch 'left-click-spawn-prot' 2017-11-03 11:59:26 +00:00
b51ec9e606 rough work for CommandOutputPacket, no idea if it works 2017-11-01 20:12:13 +00:00
8d07f833fc updated CommandRequestPacket 2017-11-01 20:11:31 +00:00
372b97ba8f Revert "Patch %0 client translation exploit"
this bug was (FINALLY) fixed in 1.2.5.15

This reverts commit 378c3d7994.
2017-11-01 16:17:17 +00:00
dea2942062 bump to 141 2017-11-01 16:14:12 +00:00
3614711a02 fixed negative effect durations when level tick rate is > 1
thank you @Sandertv
2017-11-01 09:09:17 +00:00
dcdea6a1f4 Merge branch 'master' into mcpe-1.2.5 2017-10-31 21:52:16 +00:00
b7cd8dbfa9 Fixed CraftingManager->cloneItemMap() being utterly useless 2017-10-31 19:01:03 +00:00
1486b5aa71 make more properties in CraftingManager protected 2017-10-31 18:49:49 +00:00
f8e6438efe updated some NBT for tiles 2017-10-31 18:22:06 +00:00
caf9eaa2da rename field in EntityPickRequestPacket 2017-10-31 12:25:20 +00:00
6db5596b00 Added Jukebox window type ID 2017-10-30 18:37:42 +00:00
4ed1a39638 Updated DevTools submodule 2017-10-30 17:06:33 +00:00
a770e681dc Implemented Config->removeNested() (#1499) 2017-10-30 16:32:48 +00:00
a342a61037 nuke nestedCache when config is modified 2017-10-30 16:27:47 +00:00
91c256f1a9 Added Level->getTileAt() 2017-10-30 13:36:42 +00:00
93443992be Fixed chests not getting updated properly on pair/unpair, close #1514
it wasn't clearing spawn compound caches or chunk caches
2017-10-30 11:50:02 +00:00
ea09cc06c7 added UUID constants for MultiRecipe 2017-10-30 11:18:56 +00:00
67af4d3b65 Cleaned up PMAnvil implementation 2017-10-29 19:13:58 +00:00
4a78bfaa18 stop messing with my doc comments PhpStorm 2017-10-29 18:02:33 +00:00
bb6b100443 extended CompoundTag API to allow force-writes and returning defaults on bad tag types 2017-10-29 18:01:33 +00:00
8aca373194 added some docs to shut PhpStorm up 2017-10-29 13:02:19 +00:00
7e490ccdf2 broadcast player skin to all online players by default
otherwise we could end up with undesirable bugs like players having the wrong skin when travelling from another part of the world... the skin has to be sent to everyone to update the player list
2017-10-29 12:19:47 +00:00
991d321928 improved geometry debloating, also apply on skin changes 2017-10-29 12:14:16 +00:00
600d80331a Accept null for targets in Human->sendSkin()
For humans, it'll send to all viewers. For players, it'll send to all viewers, and the player itself.
2017-10-29 11:18:34 +00:00
f79e4237df Cache a compressed CraftingDataPacket to reduce workload on player join
this saves only a couple of ms per player join, but still worth it.
2017-10-29 09:57:55 +00:00
6ce9e79cd5 fix some minor documentation issues in Binary 2017-10-28 18:40:05 +01:00
e88aa385a3 make use of new pack() codes for longs 2017-10-28 14:04:41 +01:00
5303a710ac Updated RakLib submodule 2017-10-28 10:26:34 +01:00
dd085b35cc Merge branch 'master' into mcpe-1.2.5 2017-10-27 21:24:30 +01:00
6ff1088a57 fix chest AABB 2017-10-27 19:16:06 +01:00
d1db27016e s/facePos/clickVector/
clickVector better describes this
2017-10-27 19:05:26 +01:00
c55bc2d7e9 added use-item click vector to PlayerInteractEvent
now go and make some touchscreens with maps!
2017-10-27 19:00:17 +01:00
747477dfcf Changed potentially misleading parameter name in CompoundTag->getTagValue() 2017-10-27 11:04:03 +01:00
48fefae920 Added cache for tile spawn compounds
avoids expensive repetetive NBT writes on chunk sends when the tile hasn't been changed
2017-10-27 10:23:48 +01:00
52d0ad8a61 be yet more tolerant for on-ground checks on players 2017-10-26 23:23:11 +01:00
bddd7e0eee Fixed no fall damage when falling 3-4 blocks, close #891 2017-10-26 23:23:08 +01:00
883898682f Merge remote-tracking branch 'origin/master' into mcpe-1.2.5 2017-10-26 15:34:56 -04:00
daf457213d Updated RakLib submodule 2017-10-26 16:35:33 +01:00
bd2cb85861 changed type of EntityLink unknown field and added a constructor 2017-10-25 18:50:07 +01:00
1d651046c9 Compute time in milliseconds once and use it for both firstPlayed and lastPlayed
fixes issues where lastPlayed can be a tiny fraction of time into the future of firstPlayed when players join for the first time
2017-10-25 17:12:17 +01:00
1dea25d123 Fixed wrong translation key used for level generation errors 2017-10-25 16:42:49 +01:00
b6264d188e Change Server->getConfigBoolean() to getConfigBool()
to be consistent, deprecated the original
2017-10-25 16:30:39 +01:00
2635c85873 beware users putting garbage in pocketmine.yml 2017-10-25 12:54:53 +01:00
3b85e558ce Fixed bad documentation on Level->checkSpawnProtection() 2017-10-24 18:56:38 +01:00
d48880e31b Remove redundant assert 2017-10-24 17:40:22 +01:00
93d60a9beb Updated DevTools submodule 2017-10-24 16:23:04 +01:00
a82efc44aa wtf 2017-10-24 13:29:28 +01:00
6daa0135d5 Cancel PlayerInteractEvent automatically on left-click block when spawn protection is triggered 2017-10-24 13:11:19 +01:00
08092f17e0 Merge branch 'master' into mcpe-1.2.5 2017-10-24 10:24:37 +01:00
716c1f29b4 Fixed slabs again 2017-10-24 10:23:07 +01:00
0072af95cb Bump version to 1.2.5.12 and protocol changes 2017-10-23 20:04:47 +01:00
0df3b00de4 Fixed incompatible protocol message showing an empty pair of brackets when protocol is null
this happens if an exception occurs while or before trying to read the protocol version
2017-10-23 19:44:19 +01:00
13e5718463 Using BlockFactory instead of Block 2017-10-23 18:50:37 +01:00
270e0c076c Fixed items not removed when put in the lava 2017-10-23 18:50:37 +01:00
3765511317 rename WritableBook->swapPage() to swapPages() 2017-10-23 17:55:01 +01:00
8daa8deae9 Added Living->lookAt() 2017-10-23 17:29:20 +01:00
e055ce9526 Use translation for flight kick message (#1489) 2017-10-23 13:18:57 +01:00
3ed8855894 fix drop chance of rotten flesh 2017-10-23 12:35:57 +01:00
f25255e46c fix zombie drops 2017-10-23 12:24:34 +01:00
7db8345424 Added rough support for reading entity saves with multiple save IDs (for PC 1.11 compatibility)
this will still always save using the legacy format to remain compatible with PC < 1.11.

TODO: entirely separate entity NBT format from entity implementation for proper multi-format compatibility
2017-10-22 10:16:24 +01:00
bc7ba3b3c1 Found field of ShowProfilePacket 2017-10-21 14:53:49 +01:00
1dd2203ee5 Fixed burning mobs not getting onfire data flag set when read from disk
they'd just flash red and take damage for no apparent reason
2017-10-21 12:36:30 +01:00
554096953b Abuse property visibility to micro optimize CompoundTags
this produced a little less than 10% performance improvement under xdebug, and while the real-time benefit is negligible, it's harmless to have.
2017-10-20 20:07:54 +01:00
55a1731da3 Remove redundant asserting function in Binary
If this was an inline assert, it would be harmless. Since it's in a function, it contributes to a 20% performance loss when using these functions on a large scale regardless of whether assertions are enabled or not.
Additionally, there's no need to assert that we have enough bytes since unpack() will raise warnings if there isn't, which will trigger exceptions, and for readByte(), an undefined offset notice will be raised, which will also trigger an exception.

TL;DR: This is simply wasting CPU time for no good reason.
2017-10-20 19:23:04 +01:00
ba3fe20227 Fixed missing variant bitmask for Leaves, close #1478 2017-10-20 18:37:46 +01:00
7b04049bb7 Throw exceptions when trying to add closed entities or tiles to levels 2017-10-20 18:22:28 +01:00
30211bee82 Fixed excessive idle CPU usage for chunk ticking
"excessive" = 5%, after changes = 1.6% - YMMV, but that's my machine.
2017-10-20 15:54:22 +01:00
e318dc12a5 missed target 2017-10-20 15:36:59 +01:00
967ce99b03 Made incompatible PHP version messages more useful 2017-10-20 15:35:43 +01:00
9bdda54aec Fixed PocketMine.php compatibility with < PHP7 2017-10-20 15:34:03 +01:00
18e4e5364f Fixed getBlock() performance degradation caused by 781de3efab, added Level->getBlockAt() to avoid creating vectors everywhere 2017-10-20 13:22:49 +01:00
98cfd0b398 fix entity rotation changes not getting broadcast until the entity moves 2017-10-20 10:13:19 +01:00
a245615531 fixed non-living entities lingering for a second after being kill()ed
only living entities should have death animation time
2017-10-19 20:51:50 +01:00
0a19a2611a Re-organise some Entity methods 2017-10-19 19:03:11 +01:00
50be26958a Added a helper function Entity->createBaseNBT() to cut down on boilerplate code 2017-10-19 17:36:51 +01:00
67c6fca0ed Relocate a couple of Entity API methods and add some documentation 2017-10-19 17:05:27 +01:00
d99e9513b0 Remove some redundant constructor overrides 2017-10-19 16:42:14 +01:00
5a353012de Clean up some unused imports 2017-10-19 16:39:34 +01:00
087badcb48 Remove deprecated effects methods from Entity 2017-10-19 16:35:44 +01:00
d9769360fe Remove redundant code from Entity->entityBaseTick()
this will never be called because onUpdate() checks this and returns.
2017-10-19 16:32:45 +01:00
9fb93985d6 Cleaned up Entity->spawnTo() 2017-10-19 16:13:09 +01:00
2b22d5d8cc Added EntityIds interface with constants 2017-10-19 15:43:55 +01:00
2db13bd114 added throwable eggs and refactor some projectile logic
close #1473
2017-10-19 14:12:50 +01:00
11cc20972f extended death animation time 2017-10-19 13:39:51 +01:00
4821e7386d fixed entities despawning too soon when killed 2017-10-19 13:39:10 +01:00
584810780a Moved projectile-related classes to their own namespace 2017-10-19 12:27:44 +01:00
55de75b914 Let blast resistance be computed from hardness for flowable blocks
fixes several flowable blocks apparently not having any resistance to explosions
2017-10-19 11:50:21 +01:00
2a1a17aa7a Refactored button code, fix placement rotation 2017-10-19 11:36:30 +01:00
90165cf99d Implemented farmland hydration
TODO: make crops take notice of this
2017-10-19 11:23:54 +01:00
a4ca3f1d1c Updated PocketMine-Language submodule 2017-10-18 21:08:39 +01:00
f783789e5a fixed escape code unescaping in language files, close #1474 2017-10-18 20:43:35 +01:00
43be64baed Register some more items
the item-blocks will allow their blocks to be placed, but they still won't work until the blocks themselves are added.
2017-10-18 19:52:19 +01:00
5c92c8a9d3 added red sandstone and red sandstone stairs 2017-10-18 19:42:12 +01:00
d2dc49cd9c Refactor Slab logic away from WoodenSlab, added StoneSlab2 and its double 2017-10-18 19:27:54 +01:00
f148c366f9 Use Block->getVariant() more, get rid of hardcoded bitmasks 2017-10-18 17:46:24 +01:00
91d84aaff4 Fixed a direct Block construction that PhpStorm somehow couldn't see 2017-10-18 17:03:55 +01:00
6b78ba8c25 replace some hardcoded values with Vec3 constants 2017-10-18 17:03:18 +01:00
b9de2e8b4b Use bit operations for rotations instead of hardcoded values 2017-10-18 16:47:37 +01:00
15764543b4 Use PillarRotationHelper for hay bales 2017-10-18 16:41:43 +01:00
2c34648c3d fixed second half of double chest items getting deleted, close #1477 2017-10-18 12:29:57 +01:00
3e3157cbe1 fix tick diff debug spam when entities are spawned 2017-10-17 17:38:43 +01:00
07abd61f73 Added a FIXME for Entity->move() 2017-10-17 17:14:45 +01:00
a456b7cfca Disable movement anti-cheat by default
shit's useless and an annoyance.
2017-10-17 16:45:18 +01:00
ece37d1e19 Added more methods to PlayerIllegalMoveEvent 2017-10-17 16:14:41 +01:00
cccaade00c make Player#unloadChunk() method protected 2017-10-17 14:22:57 +01:00
7f0a961526 "Creator" tag on signs may not exist 2017-10-17 13:35:31 +01:00
68ac4f538f Added ContainerTrait, reduce copy-pasted code in Tile 2017-10-16 20:01:17 +01:00
f14b7cbf78 Renamed BlockEventPacket fields 2017-10-16 19:55:42 +01:00
f4ff5d81ea Added missing parent calls for saveNBT() in Chest and Furnace 2017-10-16 18:56:48 +01:00
28a840d161 Make use of CompoundTag->hasTag() 2017-10-16 18:32:08 +01:00
292e462ea0 Remove nullable return types on CompoundTag getters
this doesn't make sense because there are default value parameters for this
2017-10-16 18:22:45 +01:00
c8379efbce Added expectedClass parameter to hasTag() to allow type-checking 2017-10-16 17:26:12 +01:00
1b5746fd97 Use NamedTag::class for default expectedClass in CompoundTag->getTag() 2017-10-16 17:22:38 +01:00
4a0ac01697 Fix PhpStorm derp
wtf?
2017-10-16 17:02:00 +01:00
9bcb41fb21 Refactor misleading parameter names in CompoundTag
these are NBT tag classes, not the NBT tag type. The tag type is an integer which describes the tag on disk.
2017-10-16 17:00:57 +01:00
20b86bdea8 Cleaned up tile NBT handling, use new CompoundTag API methods 2017-10-16 16:48:24 +01:00
0b1a9ba062 Added more typehints to Tile namespace 2017-10-16 16:14:44 +01:00
45b003ac2e Removed unnecessary return from Sign 2017-10-16 16:10:33 +01:00
769a50faa5 Refactor confusing parameter names for Item->onActivate()
next: refactor the function itself
2017-10-16 13:30:36 +01:00
af85659c63 Remove redundant property from Tile 2017-10-16 12:35:32 +01:00
95fa1824c8 Use a trait for nameable tiles instead of repeating code 2017-10-16 12:32:10 +01:00
251d5d7946 Fixed some hardcoded values in Tree 2017-10-16 12:30:46 +01:00
3b5eb45ff5 More usages of Item->isNull() 2017-10-16 12:29:39 +01:00
fd847f02ad Added BaseInventory->dropContents() 2017-10-16 12:18:06 +01:00
18d3a97466 Anvil result slot is not a real inventory slot
like the crafting grid result slot, this doesn't actually exist, it's
just somewhere you get the result item from.
2017-10-16 12:00:43 +01:00
04668d534d Oops, these fields need to be filled 2017-10-16 11:50:34 +01:00
092cc2750f Added entity unique ID for Entity containers
minecart with chest for example
2017-10-16 11:49:34 +01:00
68809d992b Added BaseInventory->removeAllViewers() 2017-10-16 11:15:03 +01:00
1641183674 added some typehints to Item 2017-10-16 10:29:44 +01:00
72531209bf Added some constants for frequently-accessed item NBT tags 2017-10-16 10:24:32 +01:00
8c6ab3e634 Some cleanup to item NBT handling 2017-10-16 10:15:41 +01:00
97e2d64592 "Fixed" shift-clicking recipe book, close #1401
this is not an optimal solution because you'll still only get 1 crafting
event when the user actually crafted a lot of items, so this isn't very
nice for plugins to work with. However, for gameplay purposes it works,
so it'll do for now.
2017-10-15 18:08:32 +01:00
a547e2cca8 Fixed sub-optimal code in WritableBook 2017-10-15 10:14:02 +01:00
cdebb62c35 added typecast for forceLanguage property read 2017-10-14 23:26:00 +01:00
2e73fd7f8c Add missing setValue() override to LongTag
why did this take two commits ;-;
2017-10-14 22:24:17 +01:00
51906daad0 Add typehints and PhpDoc to NBT API 2017-10-14 22:07:25 +01:00
ce67bc620a add Travis Test data directory to gitignore 2017-10-14 22:06:07 +01:00
bcefc3a54b Flag expectedType as nullable 2017-10-14 20:45:37 +01:00
f5378ab604 Fixed assertion failure when using getTag() without specifying an expected type 2017-10-14 20:45:32 +01:00
dab7cfde1c Added new API methods in CompoundTag to allow developers to stay sane (#1469)
Added getters and setters to CompoundTag with type safety
we need generics so badly here it hurts

This is fully backwards compatible, however the following API methods have been added to the `CompoundTag` class:

- getTag(string $name, string $expectedType = null) : ?NamedTag
- getListTag(string $name) : ?ListTag
- getCompoundTag(string $name) : ?CompoundTag
- setTag(NamedTag $tag) : void
- removeTag(string ...$names) : void
- hasTag(string $name) : bool

- getTagValue(string $name, string $expectedType, $default = null)
- getByte(string $name, ?int $default = null) : ?int
- getShort(string $name, ?int $default = null) : ?int
- getInt(string $name, ?int $default = null) : ?int
- getLong(string $name, ?int $default = null) : ?int
- getFloat(string $name, ?float $default = null) : ?float
- getDouble(string $name, ?float $default = null) : ?float
- getByteArray(string $name, ?string $default = null) : ?string
- getString(string $name, ?string $default = null) : ?string
- getIntArray(string $name, ?array $default = null) : ?array

- setTagValue(string $name, string $tagType, $value) : void
- setByte(string $name, int $value) : void
- setShort(string $name, int $value) : void
- setInt(string $name, int $value) : void
- setLong(string $name, int $value) : void
- setFloat(string $name, float $value) : void
- setDouble(string $name, float $value) : void
- setByteArray(string $name, string $value) : void
- setString(string $name, string $value) : void
- setIntArray(string $name, array $value) : void
2017-10-14 18:36:02 +01:00
6e1318b522 Push minimum requirement to PHP 7.2.0RC3
there are needed ZTS bugfixes included in RC3. I didn't move this earlier because Travis didn't have an RC3 build.
2017-10-14 14:26:21 +01:00
cd8006e242 Use constructor parameter for ListTags instead of setTagType() and removed some unnecessary type setting 2017-10-14 13:49:24 +01:00
f5abed95ec added missing type doc to ListTag 2017-10-14 12:48:38 +01:00
489b9fc29b Added missing getter override for LongTag
adds a return typehint
2017-10-14 11:34:41 +01:00
b524b841c5 Reduced duplicated code in AxisAlignedBB->calculateIntercept() 2017-10-14 11:01:00 +01:00
41f292d995 BlockUpdateEvent doesn't allow changing the target block anyway 2017-10-14 10:10:19 +01:00
fd8a562e02 Fixed collision bugs caused by not clearing pre-computed outdated AABBs for blocks
take fences as an example: say you have fence1 and fence2 next to each other, like this:
|==|
and they are joined together
then delete the fence on the right
the left fence will then look like this
|
but the server would still think its collision boxes were like this:
|=
so you wouldn't be able to shoot arrows through that space.

This commit clears pre-computed bounding boxes when a block is set using Level->setBlock() (in case the block was previously already set and has pre-calculated outdated AABB). However, because of weird blocks like fences, glass and walls, they must also be cleared on neighbour block update (since connection state isn't shown in the block data).
2017-10-14 10:07:17 +01:00
cc553a157d Clean up BlockEventPacket handling for Chests and fix wrong data for chest open 2017-10-13 20:07:33 +01:00
a6d1cc27ec Fix for explosions not removing tiles, close #1450 (#1463) 2017-10-13 13:57:50 +01:00
d8c90be5b8 Make on-ground checking less fussy 2017-10-13 13:19:20 +01:00
060426ff12 Add ability to unregister a command completely, close #1229 (#1464) 2017-10-13 11:55:36 +01:00
eeea4fa06a Added some new blocks 2017-10-13 11:51:38 +01:00
401e33dd85 fix anvil bounding box 2017-10-13 11:18:19 +01:00
2893aac3ac ... 2017-10-13 11:06:10 +01:00
c5c74c1898 fixing glass & bars collision detection
so much duplicated code, it would be nice if Fence could inherit from Thin, but that causes too many issues with block connections.
2017-10-13 11:04:51 +01:00
423bea4b57 Fixed a couple of blocks incorrectly descending from Solid 2017-10-13 10:37:48 +01:00
e3567faa94 Anvils aren't non-solid, they are transparent
solid and transparent are not mutually exclusive!
2017-10-13 10:22:22 +01:00
4b5040dcc7 Blocks extending Thin ARE solid 2017-10-13 09:52:08 +01:00
21c79b0645 Use up to 2 AABBs for fence collision checks instead of 5
overlapping cuboids do fine
2017-10-13 09:40:29 +01:00
7b5df10b6a Reset position properly when reverting movement 2017-10-12 20:33:26 +01:00
c4fe9ad32d Remove pointless API method from PlayerMoveEvent 2017-10-12 19:59:32 +01:00
60b62a4890 fixed wall collision detection
walls have to be weird...
2017-10-12 19:36:06 +01:00
061a9444cc implemented multi AABB collision checks for fences and walls
fixes anti-cheat getting triggered when falling down between a square of fences
fixes not being able to shoot arrows between a square of fences
2017-10-12 18:33:26 +01:00
3eb73ab468 Abstracted Fence code away from wooden fences 2017-10-12 17:04:49 +01:00
15d6fd86e2 Added basic support for blocks with multiple AABBs, fixed stairs (#1303) 2017-10-12 16:29:24 +01:00
0c092a7ceb reduced size of arrow bounding box
as per MCPE addon data
2017-10-12 16:21:23 +01:00
b9501ef415 Remove unnecessary duplicated ray-trace code from Block
this isn't actually used anywhere, but "backwards compatibility"
2017-10-12 13:40:12 +01:00
5afe4fdb5b Use Vector3 constants instead of hardcoded integers 2017-10-12 13:32:17 +01:00
cc7ed7a28f Added some documentation to AxisAlignedBB 2017-10-12 12:22:13 +01:00
7e9b89e48a Make Entity->checkObstruction() less confusing 2017-10-12 11:59:02 +01:00
63fccd4682 farmland and grass path should die when a solid block is above them 2017-10-12 11:11:33 +01:00
35e7aca88f refactor some more stupid variable names 2017-10-12 10:45:22 +01:00
9413f155ce implement updating properly for multi-face vines 2017-10-12 10:21:08 +01:00
6569fdbe04 Refactor some variable names in Vine 2017-10-11 20:12:12 +01:00
d8b1757ebc added some nullable and void typehints to Block API 2017-10-11 18:45:40 +01:00
8f0ee84277 Cleaned up Ladder AABB calculation code 2017-10-11 18:25:16 +01:00
b7a9e10d49 Some cleanup to how tiles are created 2017-10-11 18:08:08 +01:00
be2d134994 Added API to allow flagging an entity not to be saved to disk when its chunk is saved (#1452) 2017-10-11 16:09:08 +01:00
7b1bfc0520 fix some typos in pocketmine.yml 2017-10-11 13:42:32 +01:00
59d9d6a7df Fixed logic for low memory chunk radius override 2017-10-11 13:40:13 +01:00
8d095dff6c Given some MemoryManager fields less confusing names 2017-10-11 13:27:33 +01:00
4981931c4a Remove reliability hacks for RakLib
bug was fixed in 691a7be66b
2017-10-11 10:59:27 +01:00
5dafabbec2 Updated RakLib submodule 2017-10-11 10:59:27 +01:00
2a5d954c67 fixed yaw/headyaw field order
I wish they'd stop changing this shit... this is the third or fourth time now?
2017-10-10 22:45:30 +01:00
287f08cbd1 Changed confusing MovePlayerPacket field name to be consistent with other packets 2017-10-10 21:56:17 +01:00
76469e1d5f Remove useless properties from pocketmine.yml
these have been here for years but have never been of any use, they just confuse new users.
2017-10-10 00:01:05 +01:00
c4c83e23ca Revert RakLib to 1830bb7
disconnect & transfer issues... no idea why
2017-10-09 20:30:44 +01:00
eccc7bf7b3 Moved EntityLink to its own type 2017-10-09 19:15:53 +01:00
78ca2f2e58 fix heads rotating 45 degrees when placed facing north 2017-10-09 18:12:56 +01:00
cef9c4621c added som PhpDoc to Tile 2017-10-09 17:27:34 +01:00
151681bd80 Remove some dead properties from Tile 2017-10-09 17:25:10 +01:00
327907988b Fixed a typo in Sign->setText() docs 2017-10-09 16:56:25 +01:00
97dbf61236 Remove some no-longer-needed item classes 2017-10-09 12:31:57 +01:00
2be8b576ef Changed constructor of ItemBlock to allow handling blocks with different item IDs, added more doors 2017-10-09 11:58:58 +01:00
6dbdefafdd Add the long-awaited Enchantment::registerEnchantment() API method
api3/blocks users: I am sorry I kept you waiting so long
2017-10-09 11:40:53 +01:00
9598b8cee4 Use API methods instead of directly setting properties 2017-10-09 11:38:52 +01:00
246c6daef6 how irritating 2017-10-09 11:30:11 +01:00
2601e35990 Cleaned up and added API for entity air supply, fixed oxygen being used in creative/spectator
this commit also includes respiration checks because it's cherry-picked
from api3/blocks, but respiration won't work until it's registered.
2017-10-09 11:28:40 +01:00
bdfd9c95dd Minor cleanup to attack handler 2017-10-09 11:02:00 +01:00
cd44551d64 Cleaned up checks for handling inventory transactions 2017-10-09 10:57:28 +01:00
cebb4b35f6 Fixed beds not getting deleted properly in survival
the anti-instabreak kicked in twice... damned anti-cheat... luckily the player is not needed for this part
2017-10-09 10:49:30 +01:00
7267f1a520 Fixed some usages of Item constants for Blocks
only cosmetic change
2017-10-09 10:37:19 +01:00
66a3354b31 Fixed not respawning adjacent tiles correctly when cancelling block break events 2017-10-09 10:30:48 +01:00
ac7384a2b4 Re-organise some Player methods
- group spawn-related methods
- group achievement-related methods
- move isSleeping()
- group name-related methods
- move Player->sendAllInventories()
- move Player->jump()
2017-10-09 10:25:33 +01:00
748beaaaa7 Changed a couple of very misleading default values
why on earth did I do this
2017-10-09 09:55:18 +01:00
58788b4bc7 Removed some unnecessary stuff PhpStorm complained about 2017-10-09 09:46:21 +01:00
ae76ac82c8 Removed unnecessary delegate packet handlers
let's keep all the TODOs in one place
2017-10-09 09:44:22 +01:00
e4000f8f03 Reorganise some packet methods in Player 2017-10-09 09:35:31 +01:00
ebcce43131 Don't hold player references for hiddenPlayers
they aren't needed, and this is just one more thing that could go wrong in Player->close() that could lead to leaks.
2017-10-09 09:20:44 +01:00
119913da30 Modified misleading comment (#1455)
The plugin isn't supposed to extend PluginTask, the task is
2017-10-09 07:52:40 +01:00
1a88f59b23 Moved some stuff from join to login
this is how it should be
2017-10-08 19:38:03 +01:00
fdfe70b9f2 Removed entity metadata setting from LoginPacket handler
why the f was this here
2017-10-08 19:10:49 +01:00
3bda1473e7 Removed outdated documentation for Player->getClientId() 2017-10-08 18:47:13 +01:00
29cd071108 Added some documentation on player UUIDs 2017-10-08 18:40:27 +01:00
1810088acf Use Player->isCreative() 2017-10-08 18:17:12 +01:00
51e4a62e7b Use setUsingItem() instead of directly setting data flags 2017-10-08 18:03:19 +01:00
aa91183504 Added Durable class, fixed some tools not breaking correctly, removed some boilerplate code 2017-10-08 15:54:31 +01:00
ae5aa31e7b Add Item->setNamedTagEntry() and Item->removeNamedTagEntry() 2017-10-08 15:06:30 +01:00
7239dbbb1a Merge remote-tracking branch 'origin/pr/1453' 2017-10-08 14:20:02 +01:00
3738ab1f8a Fixed villager professions being useless 2017-10-08 14:14:42 +01:00
8fafef2f7f Added tagType parameter to ListTag constructor, remove some boilerplate code 2017-10-08 13:28:01 +01:00
5b9515b20f Peaceful difficulty allows PvP 2017-10-08 13:57:25 +02:00
69e29236aa Remove some redundant code for checking existence of creative items
getCreativeItemIndex() does basically the same thing anyway
2017-10-08 12:50:53 +01:00
e8453b7872 Item->getNamedTag() now always returns a CompoundTag object, removed lots of boilerplate code
This change resulted from many complaints and ugly boilerplate code because getNamedTag() is only ever used when you want to read from the tag or modify it. If you have code that depends on this returning null, you should use hasCompoundTag() instead.
2017-10-08 12:41:57 +01:00
00bf190e54 Make Item->getNamedTag() a bit less ugly 2017-10-08 12:17:18 +01:00
81dee2f9fc Adding writable and written books. (#1397)
* Adding writable and written books.
* Added a PlayerEditBookEvent.
* Changed BookEditPacket field names.
2017-10-08 11:49:57 +01:00
f6875705a1 Found fields of PhotoTransferPacket
now if we could only get portfolios...
2017-10-08 11:25:27 +01:00
d294d5a91b Clarified location table doc for RegionLoader 2017-10-06 09:40:46 +01:00
a7e9aa4bc1 Fixed falling sand replacing wrong blocks when moved slightly by currents 2017-10-05 17:38:32 -04:00
628ff9449e Fixed respawn fall damage when dying while falling from causes other than fall damage
tl;dr: fall distance didn't get reset
2017-10-05 16:47:50 -04:00
7f5fe137d1 Added some type docs to RegionLoader 2017-10-05 18:47:32 +01:00
18448cbcb8 Fixed several bugs with statistics updating and resetting
- fixed ridiculous network stats when title ticker or console colours are disabled (shoghicp, what fit of madness led you to think this was a good idea)
- fixed network stats reporting kb/16ticks instead of kb/s
- fixed TPS reporting getting reset after 16 ticks instead of 20
- title ticker and MOTD is now updated every 20 ticks instead of 16
2017-10-05 16:48:50 +01:00
b0104099fe Add a couple of comments to pocketmine.yml to clarify settings usage 2017-10-04 14:44:52 +01:00
68195c64ce Remove dead COMPRESSION_LEVEL property from Level 2017-10-04 14:26:04 +01:00
27aa51bac4 Added some type docs to Level 2017-10-04 14:25:06 +01:00
eac1d76e8b Fixed Level->stopTime not being set 2017-10-04 14:08:23 +01:00
a8c6e14d02 Chunk cache is now non-optional, close #1448 2017-10-04 13:50:32 +01:00
bf68a6a9fc Fixed canUseChunkCache() logic (#1446)
Fix setting disable chunk cache on low memory being useless, fix chunk cache not working if low memory cache clear is enabled
2017-10-03 20:27:53 +01:00
4dfd171af0 Add flint-steel light sound, close #1434 2017-10-03 19:39:01 +01:00
fc9c264e77 Resend blocks around targeted blocks when interactions & block-break are cancelled, fixes #906
this solution is dumber but more effective (also solves the beds & doors placement problem)
2017-10-03 19:28:01 +01:00
04ba41c58c Remove redundant properties from recipes.json
- we don't use the UUIDs, and they change every time, this just pollutes the diffs and makes my contribs ridiculous
- we don't need the height/width of shaped recipes because the generated shape tells us what it is
2017-10-03 17:30:26 +01:00
736cc927ff Enable chunk caching by default
the footprint of compressed chunk batches is so small now that it doesn't make sense to disable it out of the box. The performance gains from caching chunks are more than worth it.
As of 1.2, the average footprint of these caches is usually ~2% or less of the size of the actual chunk itself. Moving around a lot will frequently cause the same chunks to get sent several times as it passes in and out of your render distance, and the chunk isn't even changing in that time, so the chunk is getting needlessly re-serialized over and over again. So even if your world is not static (for example a creative server) chunk caching will still offer benefits, and the memory expense is so small it's a no-brainer.
2017-10-03 13:16:30 +01:00
4be7885ee4 Remove redundant assignment in Level constructor 2017-10-03 12:57:30 +01:00
7dc5dc3a9f Restrict item meta values to max signed short value, closes #1101 2017-10-03 12:35:08 +01:00
f7ee78233b Item IDs should always be unsigned, treat them with appropriate measures (fixes #1376) 2017-10-03 12:28:50 +01:00
88807e8b22 Fixed Binary::unsignShort() being non-static 2017-10-03 12:21:09 +01:00
5a6812357b imports 2017-10-03 11:34:41 +01:00
ca401ec3f5 Force-close the crafting window only when doing crafting transactions
otherwise the client will crash when using right-click on the recipe book
2017-10-03 11:33:09 +01:00
9bbebaa071 Force-close the inventory window when crafting fails to avoid desync issues
mojang, why does this have to be hard work
2017-10-03 11:04:21 +01:00
76117e7fa0 Get XUID from LoginPacket after authentication, add Player->getXuid() 2017-10-02 18:51:51 +01:00
088a44ea3a Fixed bug reading pubkey from LoginPacket
this isn't part of extraData
2017-10-02 18:05:50 +01:00
b54f256fea Added a hack to cut down on excess skin geometry bloat
there are further ways this can be debloated, but non-pretty-printing it cuts the size down by ~70-80%.
2017-10-01 16:50:16 +01:00
c09d782503 Fix #145, take 2 (slab placement in half gaps doesn't work) (#1411) 2017-10-01 16:19:59 +01:00
b3b3ee7c56 Use transparent skin on FloatingTextParticle 2017-10-01 14:10:47 +01:00
ab5bbaa7bd Remove redundant property from Player 2017-10-01 12:19:11 +01:00
afa37bd2aa check range of valid compression values
zero is not allowed because it's pointless, just raise your compression threshold if you want zero compression.

Chunks will always be compressed regardless of threshold because they are huge. It doesn't make sense to allow uncompressed chunks when even compression level 1 will reduce their size 50x. The point of the last two (reverted) commits was to prevent compression level zero being used on chunks. Probably obvious that I was up late and not thinking very clearly.

Revert "Reduced chunk compression level to 7"

This reverts commit 49ac2555ce.

Revert "Always use best compression for chunks"

This reverts commit 42dd9d6abd.
2017-10-01 11:06:14 +01:00
49ac2555ce Reduced chunk compression level to 7
According to benchmarks 8 and 9 are simply orders of magnitude slower while not saving enough bytes to make it worth the performance loss. 7 is a good balance.
2017-10-01 09:20:14 +01:00
edd0189d59 Some improvements to issue template 2017-09-30 21:19:38 +01:00
b76b9d53fe Fixed drops for DeadBush 2017-09-30 21:04:39 +01:00
42dd9d6abd Always use best compression for chunks 2017-09-30 20:30:24 +01:00
9cd7f39c03 Fixed typo on ProjectileItem class (#1431) 2017-09-30 16:17:22 +01:00
f6e30d4225 s/online-mode/xbox-auth/
lots of servers are currently running in insecure mode without realizing because of old Genisys shit configs?!
2017-09-30 12:19:24 +01:00
27798c69ee fix collision detection not detecting fence & fence-gate, fixed nether-brick fence gate AABB, close #1299 2017-09-29 15:27:14 +01:00
a33be643c4 Fixed falling blocks not falling when placed above fire, close #1425
yes, hardcoding this is not a nice solution - PC also does this, want to fight?
2017-09-29 14:53:23 +01:00
a06ff3d96b Revert "Fixed falling blocks glitching when spawned"
This reverts commit 827ee5d4f9.

can't ever seem to get falling blocks right... should I blame mojang?
2017-09-29 14:22:03 +01:00
e6cecabf3f New skin API, add support for custom capes & custom geometry (#1416)
* Added support for changing skins ingame, custom capes & geometry
* Use PlayerSkinPacket for setting Human skin instead of PlayerList hack
2017-09-29 14:09:00 +01:00
c273a46537 Ditch crafting transaction if we get normal inventory action with incomplete crafting transaction 2017-09-28 20:07:07 +01:00
c448f4a3b5 Added handling for reflected ShapedRecipe crafting, close #1415 2017-09-28 18:45:22 +01:00
86b76bfcab Fixed trying to get pubkey that doesn't exist in VerifyLoginTask
bug was exposed by previous commit
2017-09-28 18:14:53 +01:00
7ba193dc2e Set ErrorException handler on AsyncWorkers 2017-09-28 18:01:31 +01:00
f565791e41 World loading: Actually use the data in each item instead of getProperty() 2017-09-28 16:38:10 +01:00
bc0434913e Fixed crash when a numeric world seed is set in pocketmine.yml 2017-09-28 16:35:19 +01:00
9bc8d8db79 Revert "Add buffering for non-immediate priority packets to reduce compression overhead"
This reverts commit 2162675b64.

This broke Human skins... it seems MCPE doesn't like you adding and
removing a player from the list in the same batch.
2017-09-28 14:29:17 +01:00
d0bf0ff083 Imports cleanup 2017-09-28 10:51:05 +01:00
7dc1fc54b1 Oops, didn't mean to commit this 2017-09-27 20:34:37 +01:00
bae42dc0d9 Fixed incorrect field names in PlayerSkinPacket 2017-09-27 17:55:04 +01:00
ab809f8a2b Updated RakLib submodule 2017-09-27 15:53:43 +01:00
2162675b64 Add buffering for non-immediate priority packets to reduce compression overhead 2017-09-27 14:06:42 +01:00
8f63117dac Use try...finally in Player->sendDataPacket() so we don't forget to stop timings 2017-09-27 13:52:25 +01:00
1c9b4f3e21 Fixed ItemBlocks retaining Level references after being placed, close #1395 2017-09-27 12:04:56 +01:00
48d2d7e422 Remove unused import from FoodSource 2017-09-27 12:01:55 +01:00
52bd042bde BaseInventory: Don't keep calling getSize() over and over and over again 2017-09-27 11:24:21 +01:00
4b63a22f8c More use of Item->isNull() 2017-09-27 11:05:40 +01:00
c47f1f572c Added API method Item->pop() 2017-09-27 10:56:04 +01:00
7a77bb0402 Login verification: guilty until proven innocent
assume it's invalid until we've verified everything
2017-09-27 10:29:01 +01:00
90cb018de2 Re-organise some Block code 2017-09-26 19:39:05 +01:00
992c4ce6a0 Added API method Block->getVariant() 2017-09-26 19:35:04 +01:00
78af87a572 ConcretePowder: add tool type 2017-09-26 19:00:53 +01:00
c79a5509f6 Implemented concrete powder
this is a little buggy with water updating due to a hack for liquids to fix a CPU leak (210bdc2436), but everything works fine when a block nearby gets updated.
2017-09-26 18:56:43 +01:00
827ee5d4f9 Fixed falling blocks glitching when spawned
this now (finally) works flawlessly
2017-09-26 18:33:34 +01:00
f5b0cbb337 Generated some TODOs for BlockFactory & ItemFactory 2017-09-26 16:15:35 +01:00
18777a9041 Remove useless EntityEventPacket
vanilla doesn't send this, and it doesn't do anything if we _do_ send it.
2017-09-26 12:50:36 +01:00
13d50aff62 don't break bows, stupid 2017-09-26 12:20:40 +01:00
5b191327bc Fixed players' arms staying stuck up after eating something 2017-09-26 12:14:10 +01:00
8811188e71 Split FoodSource up into two interfaces 2017-09-26 11:48:47 +01:00
38fad4b963 Implement difficulty per-world (#878)
* Moved Server::getDifficultyFromString() to Level
* Added ability to set difficulty in worlds section of pocketmine.yml for generation
2017-09-26 11:16:51 +01:00
e64076ec81 Disconnect 1.1 clients properly (HACK!) 2017-09-26 10:01:32 +01:00
ccbdb77618 Cleaned up LoginPacket handling, don't nuke the buffer 2017-09-26 09:49:35 +01:00
91c6086ae1 Updated PocketMine-Language submodule 2017-09-26 09:35:43 +01:00
85ec7d9732 Change default MOTD
"Minecraft: PE Server" is no longer accurate, "Minecraft: Bedrock
Edition Server" is too wordy, and "Minecraft: BE Server" just sounds
weird.

and I'm not calling it simply a "Minecraft Server"
2017-09-25 23:43:09 +01:00
10f597cd64 Stop hardcoding "PocketMine-MP" everywhere 2017-09-25 18:17:35 +01:00
957 changed files with 28520 additions and 53147 deletions

View File

@ -1,18 +1,19 @@
### Issue description
<!---
THIS ISSUE TRACKER IS FOR BUG REPORTING, NOT FOR HELP & SUPPORT. If you need help, use the links below.
THIS ISSUE TRACKER IS FOR BUG REPORTING, NOT FOR HELP & SUPPORT. If you need help, use the links below.
- http://pmmp.readthedocs.io/en/rtfd/ - Documentation
- https://forums.pmmp.io - PMMP Forums
-->
<!--- Any issues requesting updates to new versions of MCPE will be treated as spam. We do not need issues to tell us that there is a new version available. -->
<!---
Write a short description about the issue
If you are reporting a regression or unexpected behaviour, please include the below information:
Expected result: What were you expecting to happen?
Actual result: What actually happened?
Any issues requesting updates to new versions of MCPE will be treated as spam.
Please do not create issues for missing/un-implemented gameplay features - they will be closed.
-->
<!--- Write a short description about the issue -->
<!--- If you are reporting a regression or unexpected behaviour, please include the below information: -->
- Expected result: What were you expecting to happen?
- Actual result: What actually happened?
### Steps to reproduce the issue
<!--- help us find the problem by adding steps to reproduce the issue -->
1. ...
@ -21,13 +22,13 @@ Actual result: What actually happened?
### OS and versions
<!--- use the 'version' command in PocketMine-MP
NOTE: LATEST is not a valid version. PocketMine version should include Jenkins build number and/or git commit hash.
NOTE: LATEST is not a valid version. PocketMine-MP version should include Jenkins build number and/or git commit hash.
NO support whatsoever will be provided for forks or spoons of PocketMine. Issues relating to non-official distributions will be closed as spam. Please send such issues to whoever is responsible for the fork or spoon you are using.
NO support whatsoever will be provided for third-party modified variants of PocketMine-MP. Issues relating to third-party modifications will be closed as spam.
Note that 32-bit platforms are no longer supported by PocketMine-MP and issues concerning 32-bit platforms will be closed.
-->
* PocketMine-MP:
* PocketMine-MP: <!-- LATEST IS NOT A VALID VERSION -->
* PHP:
* Server OS:
* Game version: PE/Win10 (delete as appropriate)
@ -42,6 +43,6 @@ If the issue is **not** reproducible without plugins:
### Crashdump, backtrace or other files
- Do not paste crashdumps into an issue - please use our Crash Archive at https://crash.pmmp.io for submitting crash reports to not spam the issue tracker. Add links to your reports in the Crash Archive here.
- Please use gist or anything else to add other files and add links here
- Please use gist or anything else to add other files and add links here
* ...

View File

@ -33,4 +33,8 @@ Requires translations:
-->
## Tests
<!-- Attach scripts or actions to test this pull request, as well as the result -->
<!--
Details should be provided of tests done. Simply saying "tested" or equivalent is not acceptable.
Attach scripts or actions to test this pull request, as well as the result
-->

12
.github/support.yml vendored Normal file
View File

@ -0,0 +1,12 @@
# Configuration for support-requests - https://github.com/dessant/support-requests
# Label used to mark issues as support requests
supportLabel: "Support request"
# Comment to post on issues marked as support requests. Add a link
# to a support page, or set to `false` to disable
supportComment: >
This issue tracker is not a support forum. Please use the [forums](https://forums.pmmp.io) for support.
# Whether to close issues marked as support requests
close: true
# Whether to lock issues marked as support requests
lock: false

13
.gitignore vendored
View File

@ -1,14 +1,16 @@
players/*
worlds/*
plugin_data/*
plugins/*
bin/*
bin*/*
timings/*
crashdumps/*
*.log
*.txt
*.phar
server.properties
/pocketmine.yml
memoryDump_*/*
memory_dumps/*
resource_packs/
# Common IDEs
@ -29,4 +31,11 @@ Desktop.ini
/docs/build/
!/docs/requirements.txt
# Composer
vendor/*
# Travis files
test_data/*
# Doxygen
Documentation/*

13
.gitmodules vendored
View File

@ -1,10 +1,3 @@
[submodule "src/raklib"]
path = src/raklib
url = https://github.com/pmmp/RakLib.git
branch = master
[submodule "src/spl"]
path = src/spl
url = https://github.com/pmmp/PocketMine-SPL.git
[submodule "src/pocketmine/lang/locale"]
path = src/pocketmine/lang/locale
url = https://github.com/pmmp/PocketMine-Language.git
@ -14,6 +7,6 @@
[submodule "tests/plugins/PocketMine-DevTools"]
path = tests/plugins/PocketMine-DevTools
url = https://github.com/pmmp/PocketMine-DevTools.git
[submodule "tests/plugins/PocketMine-TesterPlugin"]
path = tests/plugins/PocketMine-TesterPlugin
url = https://github.com/pmmp/PocketMine-TesterPlugin.git
[submodule "src/pocketmine/resources/vanilla"]
path = src/pocketmine/resources/vanilla
url = https://github.com/pmmp/BedrockData.git

View File

@ -6,9 +6,9 @@ php:
before_script:
# - pecl install channel://pecl.php.net/pthreads-3.1.6
- echo | pecl install channel://pecl.php.net/yaml-2.0.2
- git clone https://github.com/krakjoe/pthreads.git
- git clone https://github.com/pmmp/pthreads.git
- cd pthreads
- git checkout 6c6b15138c923b69cfa46ee05fc2dd45da587287
- git checkout c8cfacda84f21032d6014b53e72bf345ac901dac
- phpize
- ./configure
- make
@ -18,7 +18,7 @@ before_script:
- composer install
script:
- ./tests/travis.sh
- ./tests/travis.sh -t4
notifications:
email: false

View File

@ -5,58 +5,48 @@
## Creating an Issue
- If you are reporting a bug:
- **make sure that you are using the latest supported version** before opening an issue.
- **test it on a clean test server, WITHOUT PLUGINS**, to see if the issue still occurs. If not then it may be a plugin issue. Please also indicate the result of such tests.
- [Search the issue tracker](https://github.com/pmmp/PocketMine-MP/issues?utf8=%E2%9C%93&q=is%3Aissue) to check if anyone has already reported it, to avoid needlessly creating duplicate issues. Make sure you also check closed issues, as an issue you think is valid may already have been resolved.
- If your issue is related to a plugin, **do not report here, contact the plugin's original author** instead.
- **make sure that you are using the latest supported version** before opening an issue.
- **test it on a clean test server, WITHOUT PLUGINS**, to see if the issue still occurs. If not then it may be a plugin issue. Please also indicate the result of such tests.
- **[Search the issue tracker](https://github.com/pmmp/PocketMine-MP/issues?utf8=%E2%9C%93&q=is%3Aissue)** to check if anyone has already reported it, to avoid needlessly creating duplicate issues. Make sure you also check closed issues, as an issue you think is valid may already have been resolved.
- **Do not report plugin issues here.** If your issue is related to a plugin, contact the plugin's original author instead.
- **Support requests are not bugs.** Issues such as "How do I do this" are not bugs and will be closed. If you need help, please see [here](README.md#discussion) and do not misuse our issue tracker.
- **No generic titles** such as "Question", "Help", "Crash Report" etc. A good issue report provides a quick summary in the title. If you just got a crash report but you don't understand it, please look for a line starting with `Message`. It summarizes the bug.
- Information must be provided in the issue body, not in the title. No tags like `[BUG]` are allowed in the title, including `[SOLVED]` for solved issues.
- Similarly, no generic issue reports. For bugs, it is the issue author's responsibility to provide us an issue that is **trackable, debuggable, reproducible, reported professionally and is an actual bug**.
<br><br>Valid issue reports must include instructions how to reproduce the issue or a crashdump/backtrace (unless the cause of the issue is obvious).
<br><br>**If you do not provide us with a summary or instructions on how to reproduce the issue, it will be treated as spam and will therefore be closed.**
<br><br>In simple words, if the issue cannot be properly confirmed to be valid or lacks required information, the issue will be closed until further information is provided.
- **Provide information in the issue body, not in the title.** No tags like `[BUG]` are allowed in the title, including `[SOLVED]` for solved issues.
- **No generic issue reports.** For bugs, it is the issue author's responsibility to provide us an issue that is **trackable, debuggable, reproducible, reported professionally and is an actual bug**.
<br>Valid issue reports must include instructions how to reproduce the issue or a crashdump/backtrace (unless the cause of the issue is obvious).
<br>**If you do not provide us with a summary or instructions on how to reproduce the issue, it will be treated as spam and will therefore be closed.**
<br>In simple words, if the issue cannot be properly confirmed to be valid or lacks required information, the issue will be closed until further information is provided.
- To express appreciation, objection, confusion or other supported reactions on pull requests, issues or comments on them, use GitHub [reactions](https://github.com/blog/2119-add-reactions-to-pull-requests-issues-and-comments) rather than posting an individual comment with an emoji only. This helps keeping the issue/pull request conversation clean and readable.
- If your issue is related to the PocketMine-MP website, forums, etc., please [talk to a human directly](README.md#discussion).
## Contributing Code
- To contribute code to the repository, [fork it on GitHub](https://github.com/pmmp/PocketMine-MP/fork), create a branch on your fork, and make your changes on your fork. You can then make a [pull request](https://github.com/pmmp/PocketMine-MP/pull/new) to the project to compare your branch to ours and propose your changes to our repository. We use the Pull Request system to allow members of the team to review changes before they are merged.
## Contributing
To contribute to the repository, [fork it on GitHub](https://github.com/pmmp/PocketMine-MP/fork), create a branch on your fork, and make your changes on your fork. You can then make a [pull request](https://github.com/pmmp/PocketMine-MP/pull/new) to the project to compare your branch to ours and propose your changes to our repository. We use the Pull Request system to allow members of the team to review changes before they are merged.
- By proposing a pull request to the project, you agree to your code being distributed within PocketMine-MP under the [LGPL license](LICENSE).
### Licensing
By proposing a pull request to the project, you agree to your code being distributed within PocketMine-MP under the [LGPL license](LICENSE).
- At PocketMine, **we enforce a very high standard for contributions**. This is because PocketMine-MP and its related projects are used very widely in production. While this might seem like we are being mean at times, **our priority is what is best for PocketMine-MP itself**. We try to ensure that our project's codebase is as clean as possible and ensure that only top-quality material makes it through to PocketMine-MP itself. **If a contribution does not live up to our standards, changes may be requested or the pull request may be closed.**
- **Your pull request will be checked and discussed in due time.** Since the team is scattered all around the world, your PR may not receive any attention for some time.
- **Avoid using GitHub Web Editor**. The web editor lacks most useful GIT features and **should only be used for very minor changes**. It is immediately clear if the web editor has been used, and if so the PR is more likely to be rejected. If you want to make serious contributions, **please learn how to use [GIT version control](https://git-scm.com/)**.
- **Do not copy-paste code**. There are potential license issues implicit with copy-pasting, and copy-paste usually indicates a lack of understanding of the actual code. Copy-pasted code is obvious a mile off and **any PR like this is likely to be closed**. If you want to use somebody else's code from a Git repository, **use [GIT's cherry-pick feature](https://git-scm.com/docs/git-cherry-pick)** to cherry-pick the commit. **Cherry-picking is the politer way to copy somebody's changes** and retains all the original accreditation, so there is no need for copy-pasted commits with descriptions like `Some code, thanks @exampleperson`.
- In addition to the above, **make sure you can explain your changes**. If you can't provide a good explanation of changes, your PR may be rejected.
### Contribution standards
- **We enforce a very high standard for contributions**. This is because PocketMine-MP and its related projects are used very widely in production. While this might seem like we are being mean at times, **our priority is what is best for PocketMine-MP itself**.
We try to ensure that our project's codebase is as clean as possible and ensure that only top-quality material makes it through to PocketMine-MP itself.
- **If a contribution does not meet our standards, changes may be requested or the pull request may be closed.**
### Pull requests
- **Create a new branch for each pull request.** Do not create a pull request with commits that exist in another pull request.
- **Code should use the same style as in PocketMine-MP.** See [below](#code-syntax) for an example.
- **The code must be clear** and written in English, comments included.
- **Use descriptive commit titles.** You can see an example [here](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html).
- **Try to stick to one change per commit.** This ensures that if you create a PR with several changes, we can decide which ones we wish to include and which ones not to include.
- **It is inadvisable to create pull requests with large commits** unless this has been discussed with the team beforehand. Large pull requests are difficult to review, and such pull requests may end up being closed. The only exception is when all features in the pull request are related to each other, and share the same core changes.
- **Do not include multiple unrelated changes in one commit.** An atomic style for commits is preferred - this means that changes included in a commit should be part of a single distinct change set. See [this link](https://www.freshconsulting.com/atomic-commits/) for more information on atomic commits. See the [documentation on `git add`](https://git-scm.com/docs/git-add) for information on how to isolate local changes for committing.
- **Your pull request will be checked and discussed in due time.** Since the team is scattered all around the world, your PR may not receive any attention for some time.
- **It is inadvisable to create large pull requests with lots of changes** unless this has been discussed with the team beforehand. Large pull requests are difficult to review, and such pull requests may end up being closed. The only exception is when all features in the pull request are related to each other, and share the same core changes.
- **You may be asked to rebase your pull request** if the branch becomes outdated and/or if possibly conflicting changes are made to the target branch. To see how to do this, read [this page](https://github.com/edx/edx-platform/wiki/How-to-Rebase-a-Pull-Request).
- **Details should be provided of tests done.** Simply saying "Tested" or equivalent is not acceptable.
### Code contributions
- **Avoid committing changes directly on GitHub. This includes use of the web editor, and also uploading files.** The web editor lacks most useful GIT features and **should only be used for very minor changes**. It is immediately clear if the web editor has been used, and if so the PR is more likely to be rejected. If you want to make serious contributions, **please learn how to use [GIT version control](https://git-scm.com/)**.
- **Do not copy-paste code**. There are potential license issues implicit with copy-pasting, and copy-paste usually indicates a lack of understanding of the actual code. Copy-pasted code is obvious a mile off and **any PR like this is likely to be closed**. If you want to use somebody else's code from a Git repository, **use [GIT's cherry-pick feature](https://git-scm.com/docs/git-cherry-pick)** to cherry-pick the commit. **Cherry-picking is the politer way to copy somebody's changes** and retains all the original accreditation, so there is no need for copy-pasted commits with descriptions like `Some code, thanks @exampleperson`.
- **Make sure you can explain your changes**. If you can't provide a good explanation of changes, your PR may be rejected.
- **Code should use the same style as in PocketMine-MP.** See [below](#code-syntax) for an example.
- **The code must be clear** and written in English, comments included.
**Thanks for contributing to PocketMine-MP!**
@ -78,17 +68,18 @@ It is mainly [PSR-2](https://github.com/php-fig/fig-standards/blob/master/accept
- Strings SHOULD use the double quote `"` except when the single quote is required.
- All code SHOULD have parameter and type declarations where possible.
- Strict types SHOULD be enabled on new files where it is sensible to do so.
- All constant declarations SHOULD be preceded by a visibility modifier.
```php
<?php
declare(strict_types = 1);
declare(strict_types=1);
namespace pocketmine\example;
class ExampleClass{
const EXAMPLE_CLASS_CONSTANT = 1;
public const EXAMPLE_CLASS_CONSTANT = 1;
public $examplePublicVariable = "defaultValue";
private $examplePrivateVariable;
@ -99,7 +90,7 @@ class ExampleClass{
* @param string $firstArgument the first argument
* @param string|null $secondArgument default null
*/
public function __construct(string $firstArgument, &$secondArgument = null){
public function __construct(string $firstArgument, ?string &$secondArgument = null){
if($firstArgument === "exampleValue"){ //Remember to use === instead of == when possible
//do things
}elseif($firstArgument === "otherValue"){
@ -119,7 +110,6 @@ class ExampleClass{
public function doStuff(string $stuff) : string{
return $stuff;
}
}
```
@ -133,4 +123,4 @@ class ExampleClass{
* 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.
* RFCs with complex voting options will specify the vote percentage or other details.

View File

@ -1,6 +1,6 @@
# [![PocketMine-MP](http://cdn.pocketmine.net/img/PocketMine-MP-h.png)](https://pmmp.io)
__A highly customisable, open source server software for Minecraft: Pocket Edition written in PHP__
__A highly customisable, open source server software for Minecraft: Bedrock Edition written in PHP__
[![Build Status](https://travis-ci.org/pmmp/PocketMine-MP.svg?branch=master)](https://travis-ci.org/pmmp/PocketMine-MP)
@ -10,7 +10,6 @@ If you don't find what you're looking for there, [talk to a human](#discussion).
### Discussion
- [Forums](https://forums.pmmp.io/)
- [#pmmp + #pocketmine channel IRC](http://webchat.freenode.net/?channels=pmmp,pocketmine)
### Plugins
There are a very wide range of already-written plugins available which you can use to customise your server. Check out [Poggit](https://poggit.pmmp.io), or just search GitHub.
@ -23,19 +22,10 @@ There are a very wide range of already-written plugins available which you can u
Yes you can! Contributions are welcomed provided that they comply with our [Contributing Guidelines](CONTRIBUTING.md). Please ensure you read the relevant sections of the guidelines carefully before making a Pull Request or opening an Issue.
### Where can I get the latest .phar?
Head over to our [official Jenkins server](https://jenkins.pmmp.io/)
- Latest release builds can be found in our [GitHub releases](https://github.com/pmmp/PocketMine-MP/releases).
- Latest bleeding-edge development builds (and other builds in the build job channels) can be found on our [Jenkins server](https://jenkins.pmmp.io/).
## Third-party Libraries/Protocols Used
* __[PHP Sockets](http://php.net/manual/en/book.sockets.php)__
* __[PHP mbstring](http://php.net/manual/en/book.mbstring.php)__
* __[PHP BCMath](http://php.net/manual/en/book.bc.php)__
* __[PHP pthreads](http://pthreads.org/)__ by _[krakjoe](https://github.com/krakjoe)_: Threading for PHP - Share Nothing, Do Everything.
* __[PHP YAML](https://code.google.com/p/php-yaml/)__ by _Bryan Davis_: The Yaml PHP Extension provides a wrapper to the LibYAML library.
* __[LibYAML](http://pyyaml.org/wiki/LibYAML)__ by _Kirill Simonov_: A YAML 1.1 parser and emitter written in C.
* __[cURL](http://curl.haxx.se/)__: cURL is a command line tool for transferring data with URL syntax
* __[Zlib](http://www.zlib.net/)__: A Massively Spiffy Yet Delicately Unobtrusive Compression Library
* __[Source RCON Protocol](https://developer.valvesoftware.com/wiki/Source_RCON_Protocol)__
* __[UT3 Query Protocol](http://wiki.unrealadmin.org/UT3_query_protocol)__
**Note: Please avoid development builds unless there is no other alternative for what you need.** Development builds are subject to changes at any time without notice, and it is likely that your server or plugins might break without warning.
## Licensing information

View File

@ -1,13 +1,16 @@
{
"name": "pmmp/pocketmine-mp",
"name": "pocketmine/pocketmine-mp",
"description": "A server software for Minecraft: Pocket Edition written in PHP",
"type": "project",
"homepage": "https://pmmp.io",
"license": "LGPL-3.0",
"require": {
"php": ">=7.2",
"php": ">=7.2.0",
"php-64bit": "*",
"ext-bcmath": "*",
"ext-curl": "*",
"ext-ctype": "*",
"ext-date": "*",
"ext-hash": "*",
"ext-json": "*",
"ext-mbstring": "*",
@ -20,14 +23,48 @@
"ext-spl": "*",
"ext-yaml": ">=2.0.0",
"ext-zip": "*",
"ext-zlib": ">=1.2.11"
"ext-zlib": ">=1.2.11",
"pocketmine/raklib": "^0.12.0",
"pocketmine/spl": "^0.3.0",
"pocketmine/binaryutils": "^0.1.0",
"pocketmine/nbt": "^0.2.1",
"pocketmine/math": "^0.2.0",
"pocketmine/snooze": "^0.1.0"
},
"autoload": {
"exclude-from-classmap": [
"src/spl/stubs"
],
"psr-0": {
"": ["src", "src/spl"]
"psr-4": {
"": ["src"]
}
}
},
"autoload-dev": {
"psr-4": {
"pocketmine\\": "tests/phpunit/"
}
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/pmmp/RakLib"
},
{
"type": "vcs",
"url": "https://github.com/pmmp/SPL"
},
{
"type": "vcs",
"url": "https://github.com/pmmp/BinaryUtils"
},
{
"type": "vcs",
"url": "https://github.com/pmmp/NBT"
},
{
"type": "vcs",
"url": "https://github.com/pmmp/Math"
},
{
"type": "vcs",
"url": "https://github.com/pmmp/Snooze"
}
]
}

227
composer.lock generated
View File

@ -1,11 +1,227 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "d4fecad9dce5314493052c870c8cf059",
"packages": [],
"content-hash": "3536995c56bfc3dbd6ccc0994e88a636",
"packages": [
{
"name": "pocketmine/binaryutils",
"version": "0.1.1",
"source": {
"type": "git",
"url": "https://github.com/pmmp/BinaryUtils.git",
"reference": "54efeb978be0ff9335022729fe63c1e2077bf1be"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/pmmp/BinaryUtils/zipball/54efeb978be0ff9335022729fe63c1e2077bf1be",
"reference": "54efeb978be0ff9335022729fe63c1e2077bf1be",
"shasum": ""
},
"require": {
"php": ">=7.2",
"php-64bit": "*"
},
"type": "library",
"autoload": {
"psr-4": {
"pocketmine\\utils\\": "src/"
}
},
"license": [
"LGPL-3.0"
],
"description": "Classes and methods for conveniently handling binary data",
"support": {
"source": "https://github.com/pmmp/BinaryUtils/tree/master",
"issues": "https://github.com/pmmp/BinaryUtils/issues"
},
"time": "2018-08-26T18:11:05+00:00"
},
{
"name": "pocketmine/math",
"version": "0.2.1",
"source": {
"type": "git",
"url": "https://github.com/pmmp/Math.git",
"reference": "ee299f5c9c444ca526c9c691b920f321458cf0b6"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/pmmp/Math/zipball/ee299f5c9c444ca526c9c691b920f321458cf0b6",
"reference": "ee299f5c9c444ca526c9c691b920f321458cf0b6",
"shasum": ""
},
"require": {
"php": ">=7.2.0",
"php-64bit": "*"
},
"type": "library",
"autoload": {
"psr-4": {
"pocketmine\\math\\": "src/"
}
},
"license": [
"LGPL-3.0"
],
"description": "PHP library containing math related code used in PocketMine-MP",
"support": {
"source": "https://github.com/pmmp/Math/tree/0.2.1",
"issues": "https://github.com/pmmp/Math/issues"
},
"time": "2018-08-15T15:43:27+00:00"
},
{
"name": "pocketmine/nbt",
"version": "0.2.1",
"source": {
"type": "git",
"url": "https://github.com/pmmp/NBT.git",
"reference": "a4ee39f313c6870153fb7c7e513b211217f7daf8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/pmmp/NBT/zipball/a4ee39f313c6870153fb7c7e513b211217f7daf8",
"reference": "a4ee39f313c6870153fb7c7e513b211217f7daf8",
"shasum": ""
},
"require": {
"php": ">=7.2.0",
"php-64bit": "*",
"pocketmine/binaryutils": "^0.1.0"
},
"type": "library",
"autoload": {
"psr-4": {
"pocketmine\\nbt\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"pocketmine\\nbt\\": "tests/phpunit/"
}
},
"license": [
"LGPL-3.0"
],
"description": "PHP library for working with Named Binary Tags",
"support": {
"source": "https://github.com/pmmp/NBT/tree/0.2.1",
"issues": "https://github.com/pmmp/NBT/issues"
},
"time": "2018-09-04T10:36:02+00:00"
},
{
"name": "pocketmine/raklib",
"version": "0.12.0",
"source": {
"type": "git",
"url": "https://github.com/pmmp/RakLib.git",
"reference": "922da28efd828e2af6c19db1676ea9b6a267071c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/pmmp/RakLib/zipball/922da28efd828e2af6c19db1676ea9b6a267071c",
"reference": "922da28efd828e2af6c19db1676ea9b6a267071c",
"shasum": ""
},
"require": {
"ext-bcmath": "*",
"ext-pthreads": ">=3.1.7dev",
"ext-sockets": "*",
"php": ">=7.2.0",
"php-64bit": "*",
"php-ipv6": "*",
"pocketmine/binaryutils": "^0.1.0",
"pocketmine/snooze": "^0.1.0",
"pocketmine/spl": "^0.3.0"
},
"type": "library",
"autoload": {
"psr-4": {
"raklib\\": "src/"
}
},
"license": [
"GPL-3.0"
],
"description": "A RakNet server implementation written in PHP",
"support": {
"source": "https://github.com/pmmp/RakLib/tree/0.12.0",
"issues": "https://github.com/pmmp/RakLib/issues"
},
"time": "2018-06-13T10:06:14+00:00"
},
{
"name": "pocketmine/snooze",
"version": "0.1.0",
"source": {
"type": "git",
"url": "https://github.com/pmmp/Snooze.git",
"reference": "3cc9d0164230889acb08e22cc126133809e9d346"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/pmmp/Snooze/zipball/3cc9d0164230889acb08e22cc126133809e9d346",
"reference": "3cc9d0164230889acb08e22cc126133809e9d346",
"shasum": ""
},
"require": {
"ext-pthreads": ">=3.1.7dev",
"php-64bit": ">=7.2.0"
},
"type": "library",
"autoload": {
"psr-4": {
"pocketmine\\snooze\\": "src/"
}
},
"license": [
"LGPL-3.0"
],
"description": "Thread notification management library for code using the pthreads extension",
"support": {
"source": "https://github.com/pmmp/Snooze/tree/0.1.0",
"issues": "https://github.com/pmmp/Snooze/issues"
},
"time": "2018-06-13T09:36:11+00:00"
},
{
"name": "pocketmine/spl",
"version": "0.3.1",
"source": {
"type": "git",
"url": "https://github.com/pmmp/SPL.git",
"reference": "ca3912099543ddc4b4b14f40e258d84ca547dfa5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/pmmp/SPL/zipball/ca3912099543ddc4b4b14f40e258d84ca547dfa5",
"reference": "ca3912099543ddc4b4b14f40e258d84ca547dfa5",
"shasum": ""
},
"type": "library",
"autoload": {
"exclude-from-classmap": [
"stubs"
],
"classmap": [
"./"
]
},
"license": [
"LGPL-3.0"
],
"description": "Standard library files required by PocketMine-MP and related projects",
"support": {
"source": "https://github.com/pmmp/SPL/tree/master"
},
"time": "2018-06-09T17:30:36+00:00"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
@ -15,9 +231,12 @@
"prefer-stable": false,
"prefer-lowest": false,
"platform": {
"php": ">=7.2",
"php": ">=7.2.0",
"php-64bit": "*",
"ext-bcmath": "*",
"ext-curl": "*",
"ext-ctype": "*",
"ext-date": "*",
"ext-hash": "*",
"ext-json": "*",
"ext-mbstring": "*",

2321
doxygen.conf Normal file

File diff suppressed because it is too large Load Diff

View File

@ -23,7 +23,7 @@ declare(strict_types=1);
namespace pocketmine;
use pocketmine\event\TranslationContainer;
use pocketmine\lang\TranslationContainer;
use pocketmine\utils\TextFormat;
/**
@ -116,7 +116,7 @@ abstract class Achievement{
public static function broadcast(Player $player, string $achievementId) : bool{
if(isset(Achievement::$list[$achievementId])){
$translation = new TranslationContainer("chat.type.achievement", [$player->getDisplayName(), TextFormat::GREEN . Achievement::$list[$achievementId]["name"] . TextFormat::RESET]);
if(Server::getInstance()->getConfigBoolean("announce-player-achievements", true) === true){
if(Server::getInstance()->getConfigBool("announce-player-achievements", true)){
Server::getInstance()->broadcastMessage($translation);
}else{
$player->sendMessage($translation);
@ -147,6 +147,4 @@ abstract class Achievement{
return false;
}
}

View File

@ -64,6 +64,8 @@ class CrashDump{
$this->extraData();
$this->encodeData();
fclose($this->fp);
}
public function getPath() : string{
@ -115,10 +117,10 @@ class CrashDump{
}
private function extraData(){
global $arguments;
global $argv;
if($this->server->getProperty("auto-report.send-settings", true) !== false){
$this->data["parameters"] = (array) $arguments;
$this->data["parameters"] = (array) $argv;
$this->data["server.properties"] = @file_get_contents($this->server->getDataPath() . "server.properties");
$this->data["server.properties"] = preg_replace("#^rcon\\.password=(.*)$#m", "rcon.password=******", $this->data["server.properties"]);
$this->data["pocketmine.yml"] = @file_get_contents($this->server->getDataPath() . "pocketmine.yml");
@ -148,7 +150,7 @@ class CrashDump{
$error = $lastExceptionError;
}else{
$error = (array) error_get_last();
$error["trace"] = getTrace(4); //Skipping CrashDump->baseCrash, CrashDump->construct, Server->crashDump
$error["trace"] = Utils::getTrace(4); //Skipping CrashDump->baseCrash, CrashDump->construct, Server->crashDump
$errorConversion = [
E_ERROR => "E_ERROR",
E_WARNING => "E_WARNING",
@ -167,7 +169,7 @@ class CrashDump{
E_USER_DEPRECATED => "E_USER_DEPRECATED"
];
$error["fullFile"] = $error["file"];
$error["file"] = cleanPath($error["file"]);
$error["file"] = Utils::cleanPath($error["file"]);
$error["type"] = $errorConversion[$error["type"]] ?? $error["type"];
if(($pos = strpos($error["message"], "\n")) !== false){
$error["message"] = substr($error["message"], 0, $pos);
@ -186,7 +188,7 @@ class CrashDump{
$this->addLine("Line: " . $error["line"]);
$this->addLine("Type: " . $error["type"]);
if(strpos($error["file"], "src/pocketmine/") === false and strpos($error["file"], "src/raklib/") === false and file_exists($error["fullFile"])){
if(strpos($error["file"], "src/pocketmine/") === false and strpos($error["file"], "vendor/pocketmine/") === false and file_exists($error["fullFile"])){
$this->addLine();
$this->addLine("THIS CRASH WAS CAUSED BY A PLUGIN");
$this->data["plugin"] = true;
@ -195,7 +197,7 @@ class CrashDump{
$file = $reflection->getProperty("file");
$file->setAccessible(true);
foreach($this->server->getPluginManager()->getPlugins() as $plugin){
$filePath = \pocketmine\cleanPath($file->getValue($plugin));
$filePath = Utils::cleanPath($file->getValue($plugin));
if(strpos($error["file"], $filePath) === 0){
$this->data["plugin"] = $plugin->getName();
$this->addLine("BAD PLUGIN: " . $plugin->getDescription()->getFullName());
@ -227,13 +229,13 @@ class CrashDump{
}
private function generalData(){
$version = new VersionString();
$version = new VersionString(\pocketmine\BASE_VERSION, \pocketmine\IS_DEVELOPMENT_BUILD, \pocketmine\BUILD_NUMBER);
$this->data["general"] = [];
$this->data["general"]["name"] = $this->server->getName();
$this->data["general"]["version"] = $version->get(false);
$this->data["general"]["version"] = $version->getFullVersion(false);
$this->data["general"]["build"] = $version->getBuild();
$this->data["general"]["protocol"] = ProtocolInfo::CURRENT_PROTOCOL;
$this->data["general"]["api"] = \pocketmine\API_VERSION;
$this->data["general"]["api"] = \pocketmine\BASE_VERSION;
$this->data["general"]["git"] = \pocketmine\GIT_COMMIT;
$this->data["general"]["raklib"] = RakLib::VERSION;
$this->data["general"]["uname"] = php_uname("a");
@ -241,7 +243,7 @@ class CrashDump{
$this->data["general"]["zend"] = zend_version();
$this->data["general"]["php_os"] = PHP_OS;
$this->data["general"]["os"] = Utils::getOS();
$this->addLine($this->server->getName() . " version: " . $version->get(false) . " #" . $version->getBuild() . " [Protocol " . ProtocolInfo::CURRENT_PROTOCOL . "; API " . API_VERSION . "]");
$this->addLine($this->server->getName() . " version: " . $version->getFullVersion(true) . " [Protocol " . ProtocolInfo::CURRENT_PROTOCOL . "]");
$this->addLine("Git commit: " . GIT_COMMIT);
$this->addLine("uname -a: " . php_uname("a"));
$this->addLine("PHP Version: " . phpversion());
@ -256,5 +258,4 @@ class CrashDump{
public function add($str){
fwrite($this->fp, $str);
}
}
}

View File

@ -24,10 +24,9 @@ declare(strict_types=1);
namespace pocketmine;
use pocketmine\event\server\LowMemoryEvent;
use pocketmine\event\Timings;
use pocketmine\scheduler\DumpWorkerMemoryTask;
use pocketmine\scheduler\GarbageCollectionTask;
use pocketmine\utils\MainLogger;
use pocketmine\timings\Timings;
use pocketmine\utils\Utils;
class MemoryManager{
@ -65,16 +64,14 @@ class MemoryManager{
private $garbageCollectionAsync;
/** @var int */
private $chunkRadiusOverride;
private $lowMemChunkRadiusOverride;
/** @var bool */
private $chunkCollect;
/** @var bool */
private $chunkTrigger;
private $lowMemChunkGC;
/** @var bool */
private $chunkCache;
private $lowMemDisableChunkCache;
/** @var bool */
private $cacheTrigger;
private $lowMemClearWorldCache;
/** @var bool */
private $dumpWorkers = true;
@ -129,12 +126,11 @@ class MemoryManager{
$this->garbageCollectionTrigger = (bool) $this->server->getProperty("memory.garbage-collection.low-memory-trigger", true);
$this->garbageCollectionAsync = (bool) $this->server->getProperty("memory.garbage-collection.collect-async-worker", true);
$this->chunkRadiusOverride = (int) $this->server->getProperty("memory.max-chunks.chunk-radius", 4);
$this->chunkCollect = (bool) $this->server->getProperty("memory.max-chunks.trigger-chunk-collect", true);
$this->chunkTrigger = (bool) $this->server->getProperty("memory.max-chunks.low-memory-trigger", true);
$this->lowMemChunkRadiusOverride = (int) $this->server->getProperty("memory.max-chunks.chunk-radius", 4);
$this->lowMemChunkGC = (bool) $this->server->getProperty("memory.max-chunks.trigger-chunk-collect", true);
$this->chunkCache = (bool) $this->server->getProperty("memory.world-caches.disable-chunk-cache", true);
$this->cacheTrigger = (bool) $this->server->getProperty("memory.world-caches.low-memory-trigger", true);
$this->lowMemDisableChunkCache = (bool) $this->server->getProperty("memory.world-caches.disable-chunk-cache", true);
$this->lowMemClearWorldCache = (bool) $this->server->getProperty("memory.world-caches.low-memory-trigger", true);
$this->dumpWorkers = (bool) $this->server->getProperty("memory.memory-dump.dump-async-worker", true);
gc_enable();
@ -151,7 +147,7 @@ class MemoryManager{
* @return bool
*/
public function canUseChunkCache() : bool{
return !($this->lowMemory and $this->chunkTrigger);
return !$this->lowMemory or !$this->lowMemDisableChunkCache;
}
/**
@ -162,7 +158,7 @@ class MemoryManager{
* @return int
*/
public function getViewDistance(int $distance) : int{
return $this->lowMemory ? (int) min($this->chunkRadiusOverride, $distance) : $distance;
return ($this->lowMemory and $this->lowMemChunkRadiusOverride > 0) ? (int) min($this->lowMemChunkRadiusOverride, $distance) : $distance;
}
/**
@ -176,13 +172,13 @@ class MemoryManager{
public function trigger(int $memory, int $limit, bool $global = false, int $triggerCount = 0){
$this->server->getLogger()->debug(sprintf("[Memory Manager] %sLow memory triggered, limit %gMB, using %gMB",
$global ? "Global " : "", round(($limit / 1024) / 1024, 2), round(($memory / 1024) / 1024, 2)));
if($this->cacheTrigger){
if($this->lowMemClearWorldCache){
foreach($this->server->getLevels() as $level){
$level->clearCache(true);
}
}
if($this->chunkTrigger and $this->chunkCollect){
if($this->lowMemChunkGC){
foreach($this->server->getLevels() as $level){
$level->doChunkGarbageCollection();
}
@ -246,9 +242,9 @@ class MemoryManager{
Timings::$garbageCollectorTimer->startTiming();
if($this->garbageCollectionAsync){
$size = $this->server->getScheduler()->getAsyncTaskPoolSize();
for($i = 0; $i < $size; ++$i){
$this->server->getScheduler()->scheduleAsyncTaskToWorker(new GarbageCollectionTask(), $i);
$pool = $this->server->getAsyncPool();
foreach($pool->getRunningWorkers() as $i){
$pool->submitTaskToWorker(new GarbageCollectionTask(), $i);
}
}
@ -267,13 +263,13 @@ class MemoryManager{
* @param int $maxStringSize
*/
public function dumpServerMemory(string $outputFolder, int $maxNesting, int $maxStringSize){
MainLogger::getLogger()->notice("[Dump] After the memory dump is done, the server might crash");
self::dumpMemory($this->server, $this->server->getLoader(), $outputFolder, $maxNesting, $maxStringSize);
$this->server->getLogger()->notice("[Dump] After the memory dump is done, the server might crash");
self::dumpMemory($this->server, $outputFolder, $maxNesting, $maxStringSize, $this->server->getLogger());
if($this->dumpWorkers){
$scheduler = $this->server->getScheduler();
for($i = 0, $size = $scheduler->getAsyncTaskPoolSize(); $i < $size; ++$i){
$scheduler->scheduleAsyncTaskToWorker(new DumpWorkerMemoryTask($outputFolder, $maxNesting, $maxStringSize), $i);
$pool = $this->server->getAsyncPool();
foreach($pool->getRunningWorkers() as $i){
$pool->submitTaskToWorker(new DumpWorkerMemoryTask($outputFolder, $maxNesting, $maxStringSize), $i);
}
}
}
@ -281,13 +277,15 @@ class MemoryManager{
/**
* Static memory dumper accessible from any thread.
*
* @param mixed $startingObject
* @param \ClassLoader $loader
* @param string $outputFolder
* @param int $maxNesting
* @param int $maxStringSize
* @param mixed $startingObject
* @param string $outputFolder
* @param int $maxNesting
* @param int $maxStringSize
* @param \Logger $logger
*
* @throws \ReflectionException
*/
public static function dumpMemory($startingObject, \ClassLoader $loader, string $outputFolder, int $maxNesting, int $maxStringSize){
public static function dumpMemory($startingObject, string $outputFolder, int $maxNesting, int $maxStringSize, \Logger $logger){
$hardLimit = ini_get('memory_limit');
ini_set('memory_limit', '-1');
gc_disable();
@ -309,7 +307,7 @@ class MemoryManager{
$staticProperties = [];
$staticCount = 0;
foreach($loader->getClasses() as $className){
foreach(get_declared_classes() as $className){
$reflection = new \ReflectionClass($className);
$staticProperties[$className] = [];
foreach($reflection->getProperties() as $property){
@ -331,9 +329,9 @@ class MemoryManager{
}
file_put_contents($outputFolder . "/staticProperties.js", json_encode($staticProperties, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
MainLogger::getLogger()->info("[Dump] Wrote $staticCount static properties");
$logger->info("[Dump] Wrote $staticCount static properties");
if($GLOBALS !== null){ //This might be null if we're on a different thread
if(isset($GLOBALS)){ //This might be null if we're on a different thread
$globalVariables = [];
$globalCount = 0;
@ -359,7 +357,7 @@ class MemoryManager{
}
file_put_contents($outputFolder . "/globalVariables.js", json_encode($globalVariables, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
MainLogger::getLogger()->info("[Dump] Wrote $globalCount global variables");
$logger->info("[Dump] Wrote $globalCount global variables");
}
self::continueDump($startingObject, $data, $objects, $refCounts, 0, $maxNesting, $maxStringSize);
@ -396,15 +394,22 @@ class MemoryManager{
$info["implements"] = implode(", ", $reflection->getInterfaceNames());
}
foreach($reflection->getProperties() as $property){
if($property->isStatic()){
continue;
}
for($original = $reflection; $reflection !== false; $reflection = $reflection->getParentClass()){
foreach($reflection->getProperties() as $property){
if($property->isStatic()){
continue;
}
if(!$property->isPublic()){
$property->setAccessible(true);
$name = $property->getName();
if($reflection !== $original and !$property->isPublic()){
$name = $reflection->getName() . ":" . $name;
}
if(!$property->isPublic()){
$property->setAccessible(true);
}
self::continueDump($property->getValue($object), $info["properties"][$name], $objects, $refCounts, 0, $maxNesting, $maxStringSize);
}
self::continueDump($property->getValue($object), $info["properties"][$property->getName()], $objects, $refCounts, 0, $maxNesting, $maxStringSize);
}
fwrite($obData, "$hash@$className: " . json_encode($info, JSON_UNESCAPED_SLASHES) . "\n");
@ -413,7 +418,7 @@ class MemoryManager{
}while($continue);
MainLogger::getLogger()->info("[Dump] Wrote " . count($objects) . " objects");
$logger->info("[Dump] Wrote " . count($objects) . " objects");
fclose($obData);
@ -423,7 +428,7 @@ class MemoryManager{
arsort($instanceCounts, SORT_NUMERIC);
file_put_contents($outputFolder . "/instanceCounts.js", json_encode($instanceCounts, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
MainLogger::getLogger()->info("[Dump] Finished!");
$logger->info("[Dump] Finished!");
ini_set('memory_limit', $hardLimit);
gc_enable();

View File

@ -44,7 +44,7 @@ class OfflinePlayer implements IPlayer, Metadatable{
public function __construct(Server $server, string $name){
$this->server = $server;
$this->name = $name;
if(file_exists($this->server->getDataPath() . "players/" . strtolower($this->getName()) . ".dat")){
if(file_exists($this->server->getDataPath() . "players/" . strtolower($this->name) . ".dat")){
$this->namedtag = $this->server->getOfflinePlayerData($this->name);
}else{
$this->namedtag = null;
@ -64,7 +64,7 @@ class OfflinePlayer implements IPlayer, Metadatable{
}
public function isOp() : bool{
return $this->server->isOp(strtolower($this->getName()));
return $this->server->isOp($this->name);
}
public function setOp(bool $value){
@ -72,47 +72,47 @@ class OfflinePlayer implements IPlayer, Metadatable{
return;
}
if($value === true){
$this->server->addOp(strtolower($this->getName()));
if($value){
$this->server->addOp($this->name);
}else{
$this->server->removeOp(strtolower($this->getName()));
$this->server->removeOp($this->name);
}
}
public function isBanned() : bool{
return $this->server->getNameBans()->isBanned(strtolower($this->getName()));
return $this->server->getNameBans()->isBanned($this->name);
}
public function setBanned(bool $value){
if($value === true){
$this->server->getNameBans()->addBan($this->getName(), null, null, null);
if($value){
$this->server->getNameBans()->addBan($this->name, null, null, null);
}else{
$this->server->getNameBans()->remove($this->getName());
$this->server->getNameBans()->remove($this->name);
}
}
public function isWhitelisted() : bool{
return $this->server->isWhitelisted(strtolower($this->getName()));
return $this->server->isWhitelisted($this->name);
}
public function setWhitelisted(bool $value){
if($value === true){
$this->server->addWhitelist(strtolower($this->getName()));
if($value){
$this->server->addWhitelist($this->name);
}else{
$this->server->removeWhitelist(strtolower($this->getName()));
$this->server->removeWhitelist($this->name);
}
}
public function getPlayer(){
return $this->server->getPlayerExact($this->getName());
return $this->server->getPlayerExact($this->name);
}
public function getFirstPlayed(){
return $this->namedtag instanceof CompoundTag ? $this->namedtag["firstPlayed"] : null;
return $this->namedtag instanceof CompoundTag ? $this->namedtag->getLong("firstPlayed", 0, true) : null;
}
public function getLastPlayed(){
return $this->namedtag instanceof CompoundTag ? $this->namedtag["lastPlayed"] : null;
return $this->namedtag instanceof CompoundTag ? $this->namedtag->getLong("lastPlayed", 0, true) : null;
}
public function hasPlayedBefore() : bool{
@ -134,6 +134,4 @@ class OfflinePlayer implements IPlayer, Metadatable{
public function removeMetadata(string $metadataKey, Plugin $owningPlugin){
$this->server->getPlayerMetadata()->removeMetadata($this, $metadataKey, $owningPlugin);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -24,150 +24,139 @@ declare(strict_types=1);
namespace {
const INT32_MIN = -0x80000000;
const INT32_MAX = 0x7fffffff;
function safe_var_dump(){
static $cnt = 0;
foreach(func_get_args() as $var){
switch(true){
case is_array($var):
echo str_repeat(" ", $cnt) . "array(" . count($var) . ") {" . PHP_EOL;
foreach($var as $key => $value){
echo str_repeat(" ", $cnt + 1) . "[" . (is_int($key) ? $key : '"' . $key . '"') . "]=>" . PHP_EOL;
++$cnt;
safe_var_dump($value);
--$cnt;
}
echo str_repeat(" ", $cnt) . "}" . PHP_EOL;
break;
case is_int($var):
echo str_repeat(" ", $cnt) . "int(" . $var . ")" . PHP_EOL;
break;
case is_float($var):
echo str_repeat(" ", $cnt) . "float(" . $var . ")" . PHP_EOL;
break;
case is_bool($var):
echo str_repeat(" ", $cnt) . "bool(" . ($var === true ? "true" : "false") . ")" . PHP_EOL;
break;
case is_string($var):
echo str_repeat(" ", $cnt) . "string(" . strlen($var) . ") \"$var\"" . PHP_EOL;
break;
case is_resource($var):
echo str_repeat(" ", $cnt) . "resource() of type (" . get_resource_type($var) . ")" . PHP_EOL;
break;
case is_object($var):
echo str_repeat(" ", $cnt) . "object(" . get_class($var) . ")" . PHP_EOL;
break;
case is_null($var):
echo str_repeat(" ", $cnt) . "NULL" . PHP_EOL;
break;
}
}
}
function dummy(){
}
}
namespace pocketmine {
use pocketmine\utils\Binary;
use pocketmine\utils\MainLogger;
use pocketmine\utils\ServerKiller;
use pocketmine\utils\Terminal;
use pocketmine\utils\Timezone;
use pocketmine\utils\Utils;
use pocketmine\utils\VersionString;
use pocketmine\wizard\SetupWizard;
use raklib\RakLib;
const VERSION = "1.7dev";
const API_VERSION = "3.0.0-ALPHA8";
const CODENAME = "[REDACTED]";
const NAME = "PocketMine-MP";
const BASE_VERSION = "3.1.7";
const IS_DEVELOPMENT_BUILD = false;
const BUILD_NUMBER = 0;
const MIN_PHP_VERSION = "7.2.0";
function critical_error($message){
echo "[ERROR] $message" . PHP_EOL;
}
/*
* 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(version_compare("7.2", PHP_VERSION) > 0){
echo "[CRITICAL] You must use PHP >= 7.2" . PHP_EOL;
echo "[CRITICAL] Please use the installer provided on the homepage." . PHP_EOL;
if(version_compare(MIN_PHP_VERSION, PHP_VERSION) > 0){
critical_error(\pocketmine\NAME . " requires PHP >= " . MIN_PHP_VERSION . ", but you have PHP " . PHP_VERSION . ".");
critical_error("Please refer to the installation instructions at http://pmmp.rtfd.io/en/rtfd/installation.html.");
exit(1);
}
if(!extension_loaded("pthreads")){
echo "[CRITICAL] Unable to find the pthreads extension." . PHP_EOL;
echo "[CRITICAL] Please use the installer provided on the homepage." . PHP_EOL;
if(PHP_INT_SIZE < 8){
critical_error("Running " . \pocketmine\NAME . " with 32-bit systems/PHP is no longer supported.");
critical_error("Please upgrade to a 64-bit system, or use a 64-bit PHP binary if this is a 64-bit system.");
critical_error("Please refer to the installation instructions at http://pmmp.rtfd.io/en/rtfd/installation.html.");
exit(1);
}
/* Dependencies check */
$errors = 0;
if(php_sapi_name() !== "cli"){
critical_error("You must run " . \pocketmine\NAME . " using the CLI.");
++$errors;
}
$extensions = [
"bcmath" => "BC Math",
"curl" => "cURL",
"ctype" => "ctype",
"date" => "Date",
"hash" => "Hash",
"json" => "JSON",
"mbstring" => "Multibyte String",
"openssl" => "OpenSSL",
"pcre" => "PCRE",
"phar" => "Phar",
"pthreads" => "pthreads",
"reflection" => "Reflection",
"sockets" => "Sockets",
"spl" => "SPL",
"yaml" => "YAML",
"zip" => "Zip",
"zlib" => "Zlib"
];
foreach($extensions as $ext => $name){
if(!extension_loaded($ext)){
critical_error("Unable to find the $name ($ext) extension.");
++$errors;
}
}
if(extension_loaded("pthreads")){
$pthreads_version = phpversion("pthreads");
if(substr_count($pthreads_version, ".") < 2){
$pthreads_version = "0.$pthreads_version";
}
if(version_compare($pthreads_version, "3.1.7dev") < 0){
critical_error("pthreads >= 3.1.7dev is required, while you have $pthreads_version.");
++$errors;
}
}
if(extension_loaded("leveldb")){
$leveldb_version = phpversion("leveldb");
if(version_compare($leveldb_version, "0.2.1") < 0){
critical_error("php-leveldb >= 0.2.1 is required, while you have $leveldb_version");
++$errors;
}
}
if(extension_loaded("pocketmine")){
critical_error("The native PocketMine extension is no longer supported.");
++$errors;
}
if($errors > 0){
critical_error("Please recompile PHP with the needed configuration, or refer to the installation instructions at http://pmmp.rtfd.io/en/rtfd/installation.html.");
exit(1);
}
error_reporting(-1);
set_error_handler(function($severity, $message, $file, $line){
if(error_reporting() & $severity){
throw new \ErrorException($message, 0, $severity, $file, $line);
}else{ //stfu operator
return true;
}
});
if(!extension_loaded("phar")){
echo "[CRITICAL] Unable to find the Phar extension." . PHP_EOL;
echo "[CRITICAL] Please use the installer provided on the homepage." . PHP_EOL;
exit(1);
}
if(\Phar::running(true) !== ""){
define('pocketmine\PATH', \Phar::running(true) . "/");
}else{
define('pocketmine\PATH', dirname(__FILE__, 3) . DIRECTORY_SEPARATOR);
}
$requiredSplVer = "0.0.1";
if(!is_file(\pocketmine\PATH . "src/spl/version.php")){
echo "[CRITICAL] Cannot find PocketMine-SPL or incompatible version." . PHP_EOL;
echo "[CRITICAL] Please update your submodules or use provided builds." . PHP_EOL;
exit(1);
}elseif(version_compare($requiredSplVer, require(\pocketmine\PATH . "src/spl/version.php")) > 0){
echo "[CRITICAL] Incompatible PocketMine-SPL submodule version ($requiredSplVer is required)." . PHP_EOL;
echo "[CRITICAL] Please update your submodules or use provided builds." . PHP_EOL;
exit(1);
}
define('pocketmine\COMPOSER_AUTOLOADER_PATH', \pocketmine\PATH . 'vendor/autoload.php');
if(is_file(\pocketmine\PATH . "vendor/autoload.php")){
require_once(\pocketmine\PATH . "vendor/autoload.php");
if(is_file(\pocketmine\COMPOSER_AUTOLOADER_PATH)){
require_once(\pocketmine\COMPOSER_AUTOLOADER_PATH);
}else{
echo "[CRITICAL] Composer autoloader not found" . PHP_EOL;
echo "[CRITICAL] Please initialize composer dependencies before running." . PHP_EOL;
critical_error("Composer autoloader not found.");
critical_error("Please install/update Composer dependencies or use provided builds.");
exit(1);
}
if(!class_exists("ClassLoader", false)){
require_once(\pocketmine\PATH . "src/spl/ClassLoader.php");
require_once(\pocketmine\PATH . "src/spl/BaseClassLoader.php");
}
set_error_handler([Utils::class, 'errorExceptionHandler']);
/*
* We now use the Composer autoloader, but this autoloader is still used by RakLib and for loading plugins.
* We now use the Composer autoloader, but this autoloader is still for loading plugins.
*/
$autoloader = new \BaseClassLoader();
$autoloader->addPath(\pocketmine\PATH . "src");
$autoloader->addPath(\pocketmine\PATH . "src" . DIRECTORY_SEPARATOR . "spl");
$autoloader->register(false);
if(!class_exists(RakLib::class)){
echo "[CRITICAL] Unable to find the RakLib library." . PHP_EOL;
echo "[CRITICAL] Please use provided builds or clone the repository recursively." . PHP_EOL;
exit(1);
}
if(version_compare(RakLib::VERSION, "0.8.1") < 0){
echo "[CRITICAL] RakLib version 0.8.1 is required, while you have version " . RakLib::VERSION . "." . PHP_EOL;
echo "[CRITICAL] Please update your submodules or use provided builds." . PHP_EOL;
exit(1);
}
set_time_limit(0); //Who set it to 30 seconds?!?!
ini_set("allow_url_fopen", '1');
@ -178,364 +167,64 @@ namespace pocketmine {
ini_set("memory_limit", '-1');
define('pocketmine\START_TIME', microtime(true));
$opts = getopt("", ["data:", "plugins:", "no-wizard", "enable-profiler"]);
define('pocketmine\RESOURCE_PATH', \pocketmine\PATH . 'src' . DIRECTORY_SEPARATOR . 'pocketmine' . DIRECTORY_SEPARATOR . 'resources' . 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);
$opts = getopt("", ["data:", "plugins:", "no-wizard"]);
Terminal::init();
define('pocketmine\ANSI', Terminal::hasFormattingCodes());
define('pocketmine\DATA', isset($opts["data"]) ? $opts["data"] . DIRECTORY_SEPARATOR : realpath(getcwd()) . DIRECTORY_SEPARATOR);
define('pocketmine\PLUGIN_PATH', isset($opts["plugins"]) ? $opts["plugins"] . DIRECTORY_SEPARATOR : realpath(getcwd()) . DIRECTORY_SEPARATOR . "plugins" . DIRECTORY_SEPARATOR);
if(!file_exists(\pocketmine\DATA)){
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 has a dependency on timezone
$tzError = Timezone::init();
$logger = new MainLogger(\pocketmine\DATA . "server.log");
$logger->registerStatic();
do{
$timezone = ini_get("date.timezone");
if($timezone !== ""){
/*
* This is here so that people don't come to us complaining and fill up the issue tracker when they put
* an incorrect timezone abbreviation in php.ini apparently.
*/
if(strpos($timezone, "/") === false){
$default_timezone = timezone_name_from_abbr($timezone);
if($default_timezone !== false){
ini_set("date.timezone", $default_timezone);
date_default_timezone_set($default_timezone);
break;
}else{
//Bad php.ini value, try another method to detect timezone
$logger->warning("Timezone \"$timezone\" could not be parsed as a valid timezone from php.ini, falling back to auto-detection");
}
}else{
date_default_timezone_set($timezone);
break;
foreach($tzError as $e){
$logger->warning($e);
}
unset($tzError);
if(extension_loaded("xdebug")){
$logger->warning(PHP_EOL . PHP_EOL . PHP_EOL . "\tYou are running " . \pocketmine\NAME . " with xdebug enabled. This has a major impact on performance." . PHP_EOL . PHP_EOL);
}
if(\Phar::running(true) === ""){
$logger->warning("Non-packaged " . \pocketmine\NAME . " installation detected. Consider using a phar in production for better performance.");
}
$version = new VersionString(\pocketmine\BASE_VERSION, \pocketmine\IS_DEVELOPMENT_BUILD, \pocketmine\BUILD_NUMBER);
define('pocketmine\VERSION', $version->getFullVersion(true));
$gitHash = str_repeat("00", 20);
if(\Phar::running(true) === ""){
if(Utils::execute("git rev-parse HEAD", $out) === 0 and $out !== false and strlen($out = trim($out)) === 40){
$gitHash = trim($out);
if(Utils::execute("git diff --quiet") === 1 or Utils::execute("git diff --cached --quiet") === 1){ //Locally-modified
$gitHash .= "-dirty";
}
}
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 program wants to read timezone data from the ini.
ini_set("date.timezone", $timezone);
break;
}
if($response = Utils::getURL("http://ip-api.com/json") //If system timezone detection fails or timezone is an invalid value.
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']);
break;
}
ini_set("date.timezone", "UTC");
date_default_timezone_set("UTC");
$logger->warning("Timezone could not be automatically determined or was set to an invalid value. 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.");
}while(false);
function detect_system_timezone(){
switch(Utils::getOS()){
case 'win':
$regex = '/(UTC)(\+*\-*\d*\d*\:*\d*\d*)/';
/*
* wmic timezone get Caption
* Get the timezone offset
*
* Sample Output var_dump
* array(3) {
* [0] =>
* string(7) "Caption"
* [1] =>
* string(20) "(UTC+09:30) Adelaide"
* [2] =>
* string(0) ""
* }
*/
exec("wmic timezone get Caption", $output);
$string = trim(implode("\n", $output));
//Detect the Time Zone string
preg_match($regex, $string, $matches);
if(!isset($matches[2])){
return false;
}
$offset = $matches[2];
if($offset == ""){
return "UTC";
}
return parse_offset($offset);
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);
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;
default:
return false;
}else{
$phar = new \Phar(\Phar::running(false));
$meta = $phar->getMetadata();
if(isset($meta["git"])){
$gitHash = $meta["git"];
}
}
/**
* @param string $offset In the format of +09:00, +02:00, -04:00 etc.
*
* @return string|bool
*/
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;
}
}
define('pocketmine\GIT_COMMIT', $gitHash);
$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":
exec("taskkill.exe /F /PID " . ((int) $pid) . " > NUL");
break;
case "mac":
case "linux":
default:
if(function_exists("posix_kill")){
posix_kill($pid, SIGKILL);
}else{
exec("kill -9 " . ((int) $pid) . " > /dev/null 2>&1");
}
}
}
/**
* @param object $value
* @param bool $includeCurrent
*
* @return int
*/
function getReferenceCount($value, $includeCurrent = true){
ob_start();
debug_zval_dump($value);
$ret = explode("\n", ob_get_contents());
ob_end_clean();
if(count($ret) >= 1 and preg_match('/^.* refcount\\(([0-9]+)\\)\\{$/', trim($ret[0]), $m) > 0){
return ((int) $m[1]) - ($includeCurrent ? 3 : 4); //$value + zval call + extra call
}
return -1;
}
function getTrace($start = 0, $trace = null){
if($trace === null){
if(function_exists("xdebug_get_function_stack")){
$trace = array_reverse(xdebug_get_function_stack());
}else{
$e = new \Exception();
$trace = $e->getTrace();
}
}
$messages = [];
$j = 0;
for($i = (int) $start; isset($trace[$i]); ++$i, ++$j){
$params = "";
if(isset($trace[$i]["args"]) or isset($trace[$i]["params"])){
if(isset($trace[$i]["args"])){
$args = $trace[$i]["args"];
}else{
$args = $trace[$i]["params"];
}
$params = implode(", ", array_map(function($value){
return (is_object($value) ? get_class($value) . " object" : gettype($value) . " " . (is_array($value) ? "Array()" : Utils::printable(@strval($value))));
}, $args));
}
$messages[] = "#$j " . (isset($trace[$i]["file"]) ? cleanPath($trace[$i]["file"]) : "") . "(" . ($trace[$i]["line"] ?? "") . "): " . (isset($trace[$i]["class"]) ? $trace[$i]["class"] . (($trace[$i]["type"] === "dynamic" or $trace[$i]["type"] === "->") ? "->" : "::") : "") . $trace[$i]["function"] . "(" . Utils::printable($params) . ")";
}
return $messages;
}
function cleanPath($path){
return str_replace(["\\", ".php", "phar://", str_replace(["\\", "phar://"], ["/", ""], \pocketmine\PATH), str_replace(["\\", "phar://"], ["/", ""], \pocketmine\PLUGIN_PATH)], ["/", "", "", "", ""], $path);
}
@define("INT32_MASK", is_int(0xffffffff) ? 0xffffffff : -1);
@ini_set("opcache.mmap_base", bin2hex(random_bytes(8))); //Fix OPCache address errors
$exitCode = 0;
do{
$errors = 0;
if(PHP_INT_SIZE < 8){
$logger->critical("Running PocketMine-MP with 32-bit systems/PHP is no longer supported. Please upgrade to a 64-bit system or use a 64-bit PHP binary.");
$exitCode = 1;
break;
}
if(php_sapi_name() !== "cli"){
$logger->critical("You must run PocketMine-MP using the CLI.");
++$errors;
}
$pthreads_version = phpversion("pthreads");
if(substr_count($pthreads_version, ".") < 2){
$pthreads_version = "0.$pthreads_version";
}
if(version_compare($pthreads_version, "3.1.7-dev") < 0){
$logger->critical("pthreads >= 3.1.7-dev is required, while you have $pthreads_version.");
++$errors;
}
if(extension_loaded("leveldb")){
$leveldb_version = phpversion("leveldb");
if(version_compare($leveldb_version, "0.2.0") < 0){
$logger->critical("php-leveldb >= 0.2.0 is required, while you have $leveldb_version");
++$errors;
}
}
if(extension_loaded("pocketmine")){
if(version_compare(phpversion("pocketmine"), "0.0.1") < 0){
$logger->critical("You have the native PocketMine extension, but your version is lower than 0.0.1.");
++$errors;
}elseif(version_compare(phpversion("pocketmine"), "0.0.4") > 0){
$logger->critical("You have the native PocketMine extension, but your version is higher than 0.0.4.");
++$errors;
}
}
if(extension_loaded("xdebug")){
$logger->warning(PHP_EOL . PHP_EOL . PHP_EOL . "\tYou are running PocketMine with xdebug enabled. This has a major impact on performance." . PHP_EOL . PHP_EOL);
}
$extensions = [
"bcmath" => "BC Math",
"curl" => "cURL",
"json" => "JSON",
"mbstring" => "Multibyte String",
"yaml" => "YAML",
"sockets" => "Sockets",
"zip" => "Zip",
"zlib" => "Zlib"
];
foreach($extensions as $ext => $name){
if(!extension_loaded($ext)){
$logger->critical("Unable to find the $name ($ext) extension.");
++$errors;
}
}
if($errors > 0){
$logger->critical("Please use the installer provided on the homepage, or recompile PHP again.");
$exitCode = 1;
break;
}
$gitHash = str_repeat("00", 20);
if(\Phar::running(true) === ""){
if(Utils::execute("git rev-parse HEAD", $out) === 0){
$gitHash = trim($out);
if(Utils::execute("git diff --quiet") === 1 or Utils::execute("git diff --cached --quiet") === 1){ //Locally-modified
$gitHash .= "-dirty";
}
}
}else{
$phar = new \Phar(\Phar::running(false));
$meta = $phar->getMetadata();
if(isset($meta["git"])){
$gitHash = $meta["git"];
}
}
define('pocketmine\GIT_COMMIT', $gitHash);
@define("ENDIANNESS", (pack("d", 1) === "\77\360\0\0\0\0\0\0" ? Binary::BIG_ENDIAN : Binary::LITTLE_ENDIAN));
@define("INT32_MASK", is_int(0xffffffff) ? 0xffffffff : -1);
@ini_set("opcache.mmap_base", bin2hex(random_bytes(8))); //Fix OPCache address errors
if(!file_exists(\pocketmine\DATA . "server.properties") and !isset($opts["no-wizard"])){
$installer = new SetupWizard();
if(!$installer->run()){
@ -544,25 +233,20 @@ namespace pocketmine {
}
}
if(\Phar::running(true) === ""){
$logger->warning("Non-packaged PocketMine-MP installation detected. Consider using a phar in production for better performance.");
}
ThreadManager::init();
new Server($autoloader, $logger, \pocketmine\PATH, \pocketmine\DATA, \pocketmine\PLUGIN_PATH);
new Server($autoloader, $logger, \pocketmine\DATA, \pocketmine\PLUGIN_PATH);
$logger->info("Stopping other threads");
$killer = new ServerKiller(8);
$killer->start();
$killer->start(PTHREADS_INHERIT_NONE);
usleep(10000); //Fixes ServerKiller not being able to start on single-core machines
if(ThreadManager::getInstance()->stopAll() > 0){
if(\pocketmine\DEBUG > 1){
echo "Some threads could not be stopped, performing a force-kill" . PHP_EOL . PHP_EOL;
}
kill(getmypid());
Utils::kill(getmypid());
}
}while(false);

File diff suppressed because it is too large Load Diff

View File

@ -30,6 +30,9 @@ abstract class Thread extends \Thread{
/** @var \ClassLoader */
protected $classLoader;
/** @var string|null */
protected $composerAutoloaderPath;
protected $isKilled = false;
public function getClassLoader(){
@ -37,6 +40,8 @@ abstract class Thread extends \Thread{
}
public function setClassLoader(\ClassLoader $loader = null){
$this->composerAutoloaderPath = \pocketmine\COMPOSER_AUTOLOADER_PATH;
if($loader === null){
$loader = Server::getInstance()->getLoader();
}
@ -51,10 +56,8 @@ abstract class Thread extends \Thread{
* (unless you are using a custom autoloader).
*/
public function registerClassLoader(){
require(\pocketmine\PATH . "vendor/autoload.php");
if(!interface_exists("ClassLoader", false)){
require(\pocketmine\PATH . "src/spl/ClassLoader.php");
require(\pocketmine\PATH . "src/spl/BaseClassLoader.php");
if($this->composerAutoloaderPath !== null){
require $this->composerAutoloaderPath;
}
if($this->classLoader !== null){
$this->classLoader->register(false);
@ -64,14 +67,10 @@ abstract class Thread extends \Thread{
public function start(?int $options = \PTHREADS_INHERIT_ALL){
ThreadManager::getInstance()->add($this);
if(!$this->isRunning() and !$this->isJoined() and !$this->isTerminated()){
if($this->getClassLoader() === null){
$this->setClassLoader();
}
return parent::start($options);
if($this->getClassLoader() === null){
$this->setClassLoader();
}
return false;
return parent::start($options);
}
/**
@ -80,12 +79,9 @@ abstract class Thread extends \Thread{
public function quit(){
$this->isKilled = true;
$this->notify();
if(!$this->isJoined()){
if(!$this->isTerminated()){
$this->join();
}
$this->notify();
$this->join();
}
ThreadManager::getInstance()->remove($this);

View File

@ -89,4 +89,4 @@ class ThreadManager extends \Volatile{
return $erroredThreads;
}
}
}

View File

@ -30,6 +30,8 @@ abstract class Worker extends \Worker{
/** @var \ClassLoader */
protected $classLoader;
/** @var string|null */
protected $composerAutoloaderPath;
protected $isKilled = false;
@ -38,6 +40,8 @@ abstract class Worker extends \Worker{
}
public function setClassLoader(\ClassLoader $loader = null){
$this->composerAutoloaderPath = \pocketmine\COMPOSER_AUTOLOADER_PATH;
if($loader === null){
$loader = Server::getInstance()->getLoader();
}
@ -52,10 +56,8 @@ abstract class Worker extends \Worker{
* (unless you are using a custom autoloader).
*/
public function registerClassLoader(){
require(\pocketmine\PATH . "vendor/autoload.php");
if(!interface_exists("ClassLoader", false)){
require(\pocketmine\PATH . "src/spl/ClassLoader.php");
require(\pocketmine\PATH . "src/spl/BaseClassLoader.php");
if($this->composerAutoloaderPath !== null){
require $this->composerAutoloaderPath;
}
if($this->classLoader !== null){
$this->classLoader->register(false);
@ -65,14 +67,10 @@ abstract class Worker extends \Worker{
public function start(?int $options = \PTHREADS_INHERIT_ALL){
ThreadManager::getInstance()->add($this);
if(!$this->isRunning() and !$this->isJoined() and !$this->isTerminated()){
if($this->getClassLoader() === null){
$this->setClassLoader();
}
return parent::start($options);
if($this->getClassLoader() === null){
$this->setClassLoader();
}
return false;
return parent::start($options);
}
/**
@ -81,16 +79,10 @@ abstract class Worker extends \Worker{
public function quit(){
$this->isKilled = true;
$this->notify();
if($this->isRunning()){
$this->shutdown();
while($this->unstack() !== null);
$this->notify();
$this->unstack();
}elseif(!$this->isJoined()){
if(!$this->isTerminated()){
$this->join();
}
$this->shutdown();
}
ThreadManager::getInstance()->remove($this);

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\math\AxisAlignedBB;
/**
@ -32,7 +33,6 @@ use pocketmine\item\Item;
class Air extends Transparent{
protected $id = self::AIR;
protected $meta = 0;
public function __construct(int $meta = 0){
$this->meta = $meta;
@ -66,10 +66,14 @@ class Air extends Transparent{
return false;
}
public function getBoundingBox(){
public function getBoundingBox() : ?AxisAlignedBB{
return null;
}
public function getCollisionBoxes() : array{
return [];
}
public function getHardness() : float{
return -1;
}
@ -77,5 +81,4 @@ class Air extends Transparent{
public function getBlastResistance() : float{
return 0;
}
}
}

View File

@ -25,27 +25,27 @@ namespace pocketmine\block;
use pocketmine\inventory\AnvilInventory;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\Tool;
use pocketmine\item\TieredTool;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Vector3;
use pocketmine\Player;
class Anvil extends Fallable{
const TYPE_NORMAL = 0;
const TYPE_SLIGHTLY_DAMAGED = 4;
const TYPE_VERY_DAMAGED = 8;
public const TYPE_NORMAL = 0;
public const TYPE_SLIGHTLY_DAMAGED = 4;
public const TYPE_VERY_DAMAGED = 8;
protected $id = self::ANVIL;
public function isSolid() : bool{
return false;
}
public function __construct(int $meta = 0){
$this->meta = $meta;
}
public function isTransparent() : bool{
return true;
}
public function getHardness() : float{
return 5;
}
@ -54,17 +54,49 @@ class Anvil extends Fallable{
return 6000;
}
public function getVariantBitmask() : int{
return 0x0c;
}
public function getName() : string{
static $names = [
self::TYPE_NORMAL => "Anvil",
self::TYPE_SLIGHTLY_DAMAGED => "Slightly Damaged Anvil",
self::TYPE_VERY_DAMAGED => "Very Damaged Anvil"
];
return $names[$this->meta & 0x0c] ?? "Anvil";
return $names[$this->getVariant()] ?? "Anvil";
}
public function getToolType() : int{
return Tool::TYPE_PICKAXE;
return BlockToolType::TYPE_PICKAXE;
}
public function getToolHarvestLevel() : int{
return TieredTool::TIER_WOODEN;
}
public function recalculateBoundingBox() : ?AxisAlignedBB{
$inset = 0.125;
if($this->meta & 0x01){ //east/west
return new AxisAlignedBB(
$this->x,
$this->y,
$this->z + $inset,
$this->x + 1,
$this->y + 1,
$this->z + 1 - $inset
);
}else{
return new AxisAlignedBB(
$this->x + $inset,
$this->y,
$this->z,
$this->x + 1 - $inset,
$this->y + 1,
$this->z + 1
);
}
}
public function onActivate(Item $item, Player $player = null) : bool{
@ -75,19 +107,9 @@ class Anvil extends Fallable{
return true;
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$direction = ($player !== null ? $player->getDirection() : 0) & 0x03;
$this->meta = ($this->meta & 0x0c) | $direction;
$this->meta = $this->getVariant() | $direction;
return $this->getLevel()->setBlock($blockReplace, $this, true, true);
}
public function getDrops(Item $item) : array{
if($item->isPickaxe() >= Tool::TIER_WOODEN){
return [
ItemFactory::get($this->getItemId(), $this->getDamage() & 0x0c, 1)
];
}
return [];
}
}
}

View File

@ -23,24 +23,20 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\event\TranslationContainer;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\lang\TranslationContainer;
use pocketmine\level\Level;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Vector3;
use pocketmine\nbt\tag\ByteTag;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\IntTag;
use pocketmine\nbt\tag\StringTag;
use pocketmine\Player;
use pocketmine\tile\Bed as TileBed;
use pocketmine\tile\Tile;
use pocketmine\utils\TextFormat;
class Bed extends Transparent{
const BITFLAG_OCCUPIED = 0x04;
const BITFLAG_HEAD = 0x08;
public const BITFLAG_OCCUPIED = 0x04;
public const BITFLAG_HEAD = 0x08;
protected $id = self::BED_BLOCK;
@ -58,7 +54,7 @@ class Bed extends Transparent{
return "Bed Block";
}
protected function recalculateBoundingBox(){
protected function recalculateBoundingBox() : ?AxisAlignedBB{
return new AxisAlignedBB(
$this->x,
$this->y,
@ -89,7 +85,7 @@ class Bed extends Transparent{
$this->getLevel()->setBlock($this, $this, false, false);
if(($other = $this->getOtherHalf()) !== null and !$other->isOccupied()){
if(($other = $this->getOtherHalf()) !== null and $other->isOccupied() !== $occupied){
$other->setOccupied($occupied);
}
}
@ -129,7 +125,7 @@ class Bed extends Transparent{
/**
* @return Bed|null
*/
public function getOtherHalf(){
public function getOtherHalf() : ?Bed{
$other = $this->getSide(self::getOtherHalfSide($this->meta, $this->isHeadPart()));
if($other instanceof Bed and $other->getId() === $this->getId() and $other->isHeadPart() !== $this->isHeadPart() and (($other->getDamage() & 0x03) === ($this->getDamage() & 0x03))){
return $other;
@ -146,7 +142,7 @@ class Bed extends Transparent{
return true;
}elseif($player->distanceSquared($this) > 4 and $player->distanceSquared($other) > 4){
//MCPE doesn't have messages for bed too far away
$player->sendMessage(new TranslationContainer(TextFormat::GRAY . "%tile.bed.tooFar"));
return true;
}
@ -175,29 +171,17 @@ class Bed extends Transparent{
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$down = $this->getSide(Vector3::SIDE_DOWN);
if(!$down->isTransparent()){
$meta = (($player instanceof Player ? $player->getDirection() : 0) - 1) & 0x03;
$next = $this->getSide(self::getOtherHalfSide($meta));
if($next->canBeReplaced() === true and !$next->getSide(Vector3::SIDE_DOWN)->isTransparent()){
if($next->canBeReplaced() and !$next->getSide(Vector3::SIDE_DOWN)->isTransparent()){
$this->getLevel()->setBlock($blockReplace, BlockFactory::get($this->id, $meta), true, true);
$this->getLevel()->setBlock($next, BlockFactory::get($this->id, $meta | self::BITFLAG_HEAD), true, true);
$nbt = new CompoundTag("", [
new StringTag("id", Tile::BED),
new ByteTag("color", $item->getDamage() & 0x0f),
new IntTag("x", $blockReplace->x),
new IntTag("y", $blockReplace->y),
new IntTag("z", $blockReplace->z)
]);
$nbt2 = clone $nbt;
$nbt2["x"] = $next->x;
$nbt2["z"] = $next->z;
Tile::createTile(Tile::BED, $this->getLevel(), $nbt);
Tile::createTile(Tile::BED, $this->getLevel(), $nbt2);
Tile::createTile(Tile::BED, $this->getLevel(), TileBed::createNBT($this, $face, $item, $player));
Tile::createTile(Tile::BED, $this->getLevel(), TileBed::createNBT($next, $face, $item, $player));
return true;
}
@ -206,25 +190,16 @@ class Bed extends Transparent{
return false;
}
public function onBreak(Item $item, Player $player = null) : bool{
$this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), true, true);
if(($other = $this->getOtherHalf()) !== null){
$this->getLevel()->useBreakOn($other, $item, $player, $player !== null); //make sure tiles get removed
}
return true;
}
public function getDrops(Item $item) : array{
public function getDropsForCompatibleTool(Item $item) : array{
if($this->isHeadPart()){
$tile = $this->getLevel()->getTile($this);
if($tile instanceof TileBed){
return [
ItemFactory::get($this->getItemId(), $tile->getColor(), 1)
ItemFactory::get($this->getItemId(), $tile->getColor())
];
}else{
return [
ItemFactory::get($this->getItemId(), 14, 1) //Red
ItemFactory::get($this->getItemId(), 14) //Red
];
}
}
@ -232,4 +207,15 @@ class Bed extends Transparent{
return [];
}
public function isAffectedBySilkTouch() : bool{
return false;
}
public function getAffectedBlocks() : array{
if(($other = $this->getOtherHalf()) !== null){
return [$this, $other];
}
return parent::getAffectedBlocks();
}
}

View File

@ -48,5 +48,4 @@ class Bedrock extends Solid{
public function isBreakable(Item $item) : bool{
return false;
}
}
}

View File

@ -38,16 +38,20 @@ class Beetroot extends Crops{
return "Beetroot Block";
}
public function getDrops(Item $item) : array{
public function getDropsForCompatibleTool(Item $item) : array{
if($this->meta >= 0x07){
return [
ItemFactory::get(Item::BEETROOT, 0, 1),
ItemFactory::get(Item::BEETROOT),
ItemFactory::get(Item::BEETROOT_SEEDS, 0, mt_rand(0, 3))
];
}
return [
ItemFactory::get(Item::BEETROOT_SEEDS, 0, 1)
ItemFactory::get(Item::BEETROOT_SEEDS)
];
}
}
public function getPickedItem() : Item{
return ItemFactory::get(Item::BEETROOT_SEEDS);
}
}

View File

@ -27,13 +27,12 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\entity\Entity;
use pocketmine\item\enchantment\Enchantment;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\Tool;
use pocketmine\level\Level;
use pocketmine\level\MovingObjectPosition;
use pocketmine\level\Position;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\RayTraceResult;
use pocketmine\math\Vector3;
use pocketmine\metadata\Metadatable;
use pocketmine\metadata\MetadataValue;
@ -67,7 +66,11 @@ class Block extends Position implements BlockIds, Metadatable{
protected $itemId;
/** @var AxisAlignedBB */
public $boundingBox = null;
protected $boundingBox = null;
/** @var AxisAlignedBB[]|null */
protected $collisionBoxes = null;
/**
* @param int $id The block type's ID, 0-255
@ -116,7 +119,7 @@ class Block extends Position implements BlockIds, Metadatable{
/**
* @param int $meta
*/
final public function setDamage(int $meta){
final public function setDamage(int $meta) : void{
if($meta < 0 or $meta > 0xf){
throw new \InvalidArgumentException("Block damage values must be 0-15, not $meta");
}
@ -136,6 +139,34 @@ class Block extends Position implements BlockIds, Metadatable{
return -1;
}
/**
* Returns the block meta, stripped of non-variant flags.
* @return int
*/
public function getVariant() : int{
return $this->meta & $this->getVariantBitmask();
}
/**
* AKA: Block->isPlaceable
* @return bool
*/
public function canBePlaced() : bool{
return true;
}
/**
* @return bool
*/
public function canBeReplaced() : bool{
return false;
}
public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector, int $face, bool $isClickedBlock) : bool{
return $blockReplace->canBeReplaced();
}
/**
* Places the Block, using block space and block target, and side. Returns if the block has been placed.
*
@ -143,12 +174,12 @@ class Block extends Position implements BlockIds, Metadatable{
* @param Block $blockReplace
* @param Block $blockClicked
* @param int $face
* @param Vector3 $facePos
* @param Vector3 $clickVector
* @param Player|null $player
*
* @return bool
*/
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
return $this->getLevel()->setBlock($this, $this, true, true);
}
@ -163,6 +194,51 @@ class Block extends Position implements BlockIds, Metadatable{
return true;
}
/**
* @return int
*/
public function getToolType() : int{
return BlockToolType::TYPE_NONE;
}
/**
* Returns the level of tool required to harvest this block (for normal blocks). When the tool type matches the
* block's required tool type, the tool must have a harvest level greater than or equal to this value to be able to
* successfully harvest the block.
*
* If the block requires a specific minimum tier of tiered tool, the minimum tier required should be returned.
* Otherwise, 1 should be returned if a tool is required, 0 if not.
*
* @see Item::getBlockToolHarvestLevel()
*
* @return int
*/
public function getToolHarvestLevel() : int{
return 0;
}
/**
* Returns whether the specified item is the proper tool to use for breaking this block. This checks tool type and
* harvest level requirement.
*
* In most cases this is also used to determine whether block drops should be created or not, except in some
* special cases such as vines.
*
* @param Item $tool
*
* @return bool
*/
public function isCompatibleWithTool(Item $tool) : bool{
if($this->getHardness() < 0){
return false;
}
$toolType = $this->getToolType();
$harvestLevel = $this->getToolHarvestLevel();
return $toolType === BlockToolType::TYPE_NONE or $harvestLevel === 0 or (
($toolType & $tool->getBlockToolType()) !== 0 and $tool->getBlockToolHarvestLevel() >= $harvestLevel);
}
/**
* Do the actions needed so the block is broken with the Item
*
@ -175,17 +251,63 @@ class Block extends Position implements BlockIds, Metadatable{
return $this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), true, true);
}
/**
* Fires a block update on the Block
* Returns the seconds that this block takes to be broken using an specific Item
*
* @param int $type
* @param Item $item
*
* @return bool|int
* @return float
*/
public function onUpdate(int $type){
public function getBreakTime(Item $item) : float{
$base = $this->getHardness();
if($this->isCompatibleWithTool($item)){
$base *= 1.5;
}else{
$base *= 5;
}
$efficiency = $item->getMiningEfficiency($this);
if($efficiency <= 0){
throw new \RuntimeException("Item efficiency is invalid");
}
$base /= $efficiency;
return $base;
}
/**
* Called when this block or a block immediately adjacent to it changes state.
*/
public function onNearbyBlockChange() : void{
}
/**
* Returns whether random block updates will be done on this block.
*
* @return bool
*/
public function ticksRandomly() : bool{
return false;
}
/**
* Called when this block is randomly updated due to chunk ticking.
* WARNING: This will not be called if ticksRandomly() does not return true!
*/
public function onRandomTick() : void{
}
/**
* Called when this block is updated by the delayed blockupdate scheduler in the level.
*/
public function onScheduledUpdate() : void{
}
/**
* Do actions when activated by Item. Returns if it has done anything
*
@ -206,14 +328,6 @@ class Block extends Position implements BlockIds, Metadatable{
return 10;
}
/**
* @deprecated
* @return float
*/
public function getResistance() : float{
return $this->getBlastResistance();
}
/**
* Returns the block's resistance to explosions. Usually 5x hardness.
* @return float
@ -222,13 +336,6 @@ class Block extends Position implements BlockIds, Metadatable{
return $this->getHardness() * 5;
}
/**
* @return int
*/
public function getToolType() : int{
return Tool::TYPE_NONE;
}
/**
* @return float
*/
@ -266,30 +373,6 @@ class Block extends Position implements BlockIds, Metadatable{
return false;
}
/**
* Returns whether random block updates will be done on this block.
*
* @return bool
*/
public function ticksRandomly() : bool{
return false;
}
/**
* AKA: Block->isPlaceable
* @return bool
*/
public function canBePlaced() : bool{
return true;
}
/**
* @return bool
*/
public function canBeReplaced() : bool{
return false;
}
/**
* @return bool
*/
@ -326,7 +409,7 @@ class Block extends Position implements BlockIds, Metadatable{
}
public function addVelocityToEntity(Entity $entity, Vector3 $vector){
public function addVelocityToEntity(Entity $entity, Vector3 $vector) : void{
}
@ -335,7 +418,7 @@ class Block extends Position implements BlockIds, Metadatable{
*
* @param Position $v
*/
final public function position(Position $v){
final public function position(Position $v) : void{
$this->x = (int) $v->x;
$this->y = (int) $v->y;
$this->z = (int) $v->z;
@ -351,59 +434,83 @@ class Block extends Position implements BlockIds, Metadatable{
* @return Item[]
*/
public function getDrops(Item $item) : array{
if($this->isCompatibleWithTool($item)){
if($this->isAffectedBySilkTouch() and $item->hasEnchantment(Enchantment::SILK_TOUCH)){
return $this->getSilkTouchDrops($item);
}
return $this->getDropsForCompatibleTool($item);
}
return [];
}
/**
* Returns an array of Items to be dropped when the block is broken using the correct tool type.
*
* @param Item $item
*
* @return Item[]
*/
public function getDropsForCompatibleTool(Item $item) : array{
return [
ItemFactory::get($this->getItemId(), $this->getDamage() & $this->getVariantBitmask(), 1)
ItemFactory::get($this->getItemId(), $this->getVariant())
];
}
/**
* Returns the seconds that this block takes to be broken using an specific Item
* Returns an array of Items to be dropped when the block is broken using a compatible Silk Touch-enchanted tool.
*
* @param Item $item
*
* @return float
* @return Item[]
*/
public function getBreakTime(Item $item) : float{
$base = $this->getHardness() * 1.5;
if($this->canBeBrokenWith($item)){
if($this->getToolType() === Tool::TYPE_SHEARS and $item->isShears()){
$base /= 15;
}elseif(
($this->getToolType() === Tool::TYPE_PICKAXE and ($tier = $item->isPickaxe()) !== false) or
($this->getToolType() === Tool::TYPE_AXE and ($tier = $item->isAxe()) !== false) or
($this->getToolType() === Tool::TYPE_SHOVEL and ($tier = $item->isShovel()) !== false)
){
switch($tier){
case Tool::TIER_WOODEN:
$base /= 2;
break;
case Tool::TIER_STONE:
$base /= 4;
break;
case Tool::TIER_IRON:
$base /= 6;
break;
case Tool::TIER_DIAMOND:
$base /= 8;
break;
case Tool::TIER_GOLD:
$base /= 12;
break;
}
}
}else{
$base *= 3.33;
}
if($item->isSword()){
$base *= 0.5;
}
return $base;
public function getSilkTouchDrops(Item $item) : array{
return [
ItemFactory::get($this->getItemId(), $this->getVariant())
];
}
public function canBeBrokenWith(Item $item) : bool{
return $this->getHardness() !== -1;
/**
* Returns how much XP will be dropped by breaking this block with the given item.
*
* @param Item $item
*
* @return int
*/
public function getXpDropForTool(Item $item) : int{
if($item->hasEnchantment(Enchantment::SILK_TOUCH) or !$this->isCompatibleWithTool($item)){
return 0;
}
return $this->getXpDropAmount();
}
/**
* Returns how much XP this block will drop when broken with an appropriate tool.
*
* @return int
*/
protected function getXpDropAmount() : int{
return 0;
}
/**
* Returns whether Silk Touch enchanted tools will cause this block to drop as itself. Since most blocks drop
* themselves anyway, this is implicitly true.
*
* @return bool
*/
public function isAffectedBySilkTouch() : bool{
return true;
}
/**
* Returns the item that players will equip when middle-clicking on this block.
* @return Item
*/
public function getPickedItem() : Item{
return ItemFactory::get($this->getItemId(), $this->getVariant());
}
/**
@ -415,14 +522,58 @@ class Block extends Position implements BlockIds, Metadatable{
}
/**
* Returns the Block on the side $side, works like Vector3::side()
* Returns the chance that the block will catch fire from nearby fire sources. Higher values lead to faster catching
* fire.
*
* @return int
*/
public function getFlameEncouragement() : int{
return 0;
}
/**
* Returns the base flammability of this block. Higher values lead to the block burning away more quickly.
*
* @return int
*/
public function getFlammability() : int{
return 0;
}
/**
* Returns whether fire lit on this block will burn indefinitely.
*
* @return bool
*/
public function burnsForever() : bool{
return false;
}
/**
* Returns whether this block can catch fire.
*
* @return bool
*/
public function isFlammable() : bool{
return $this->getFlammability() > 0;
}
/**
* Called when this block is burned away by being on fire.
*/
public function onIncinerate() : void{
}
/**
* Returns the Block on the side $side, works like Vector3::getSide()
*
* @param int $side
* @param int $step
*
* @return Block
*/
public function getSide($side, $step = 1){
public function getSide(int $side, int $step = 1){
if($this->isValid()){
return $this->getLevel()->getBlock(Vector3::getSide($side, $step));
}
@ -430,6 +581,45 @@ class Block extends Position implements BlockIds, Metadatable{
return BlockFactory::get(Block::AIR, 0, Position::fromObject(Vector3::getSide($side, $step)));
}
/**
* Returns the 4 blocks on the horizontal axes around the block (north, south, east, west)
*
* @return Block[]
*/
public function getHorizontalSides() : array{
return [
$this->getSide(Vector3::SIDE_NORTH),
$this->getSide(Vector3::SIDE_SOUTH),
$this->getSide(Vector3::SIDE_WEST),
$this->getSide(Vector3::SIDE_EAST)
];
}
/**
* Returns the six blocks around this block.
*
* @return Block[]
*/
public function getAllSides() : array{
return array_merge(
[
$this->getSide(Vector3::SIDE_DOWN),
$this->getSide(Vector3::SIDE_UP)
],
$this->getHorizontalSides()
);
}
/**
* Returns a list of blocks that this block is part of. In most cases, only contains the block itself, but in cases
* such as double plants, beds and doors, will contain both halves.
*
* @return Block[]
*/
public function getAffectedBlocks() : array{
return [$this];
}
/**
* @return string
*/
@ -445,22 +635,48 @@ class Block extends Position implements BlockIds, Metadatable{
* @return bool
*/
public function collidesWithBB(AxisAlignedBB $bb) : bool{
$bb2 = $this->getBoundingBox();
foreach($this->getCollisionBoxes() as $bb2){
if($bb->intersectsWith($bb2)){
return true;
}
}
return $bb2 !== null and $bb->intersectsWith($bb2);
return false;
}
/**
* @param Entity $entity
*/
public function onEntityCollide(Entity $entity){
public function onEntityCollide(Entity $entity) : void{
}
/**
* @return AxisAlignedBB[]
*/
public function getCollisionBoxes() : array{
if($this->collisionBoxes === null){
$this->collisionBoxes = $this->recalculateCollisionBoxes();
}
return $this->collisionBoxes;
}
/**
* @return AxisAlignedBB[]
*/
protected function recalculateCollisionBoxes() : array{
if($bb = $this->recalculateBoundingBox()){
return [$bb];
}
return [];
}
/**
* @return AxisAlignedBB|null
*/
public function getBoundingBox(){
public function getBoundingBox() : ?AxisAlignedBB{
if($this->boundingBox === null){
$this->boundingBox = $this->recalculateBoundingBox();
}
@ -470,7 +686,7 @@ class Block extends Position implements BlockIds, Metadatable{
/**
* @return AxisAlignedBB|null
*/
protected function recalculateBoundingBox(){
protected function recalculateBoundingBox() : ?AxisAlignedBB{
return new AxisAlignedBB(
$this->x,
$this->y,
@ -481,119 +697,73 @@ class Block extends Position implements BlockIds, Metadatable{
);
}
/**
* Clears any cached precomputed objects, such as bounding boxes. This is called on block neighbour update and when
* the block is set into the world to remove any outdated precomputed things such as AABBs and force recalculation.
*/
public function clearCaches() : void{
$this->boundingBox = null;
$this->collisionBoxes = null;
}
/**
* @param Vector3 $pos1
* @param Vector3 $pos2
*
* @return MovingObjectPosition|null
* @return RayTraceResult|null
*/
public function calculateIntercept(Vector3 $pos1, Vector3 $pos2){
$bb = $this->getBoundingBox();
if($bb === null){
public function calculateIntercept(Vector3 $pos1, Vector3 $pos2) : ?RayTraceResult{
$bbs = $this->getCollisionBoxes();
if(empty($bbs)){
return 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);
/** @var RayTraceResult|null $currentHit */
$currentHit = null;
/** @var int|float $currentDistance */
$currentDistance = PHP_INT_MAX;
if($v1 !== null and !$bb->isVectorInYZ($v1)){
$v1 = null;
foreach($bbs as $bb){
$nextHit = $bb->calculateIntercept($pos1, $pos2);
if($nextHit === null){
continue;
}
$nextDistance = $nextHit->hitVector->distanceSquared($pos1);
if($nextDistance < $currentDistance){
$currentHit = $nextHit;
$currentDistance = $nextDistance;
}
}
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));
return $currentHit;
}
public function setMetadata(string $metadataKey, MetadataValue $newMetadataValue){
if($this->getLevel() instanceof Level){
$this->getLevel()->getBlockMetadata()->setMetadata($this, $metadataKey, $newMetadataValue);
if($this->isValid()){
$this->level->getBlockMetadata()->setMetadata($this, $metadataKey, $newMetadataValue);
}
}
public function getMetadata(string $metadataKey){
if($this->getLevel() instanceof Level){
return $this->getLevel()->getBlockMetadata()->getMetadata($this, $metadataKey);
if($this->isValid()){
return $this->level->getBlockMetadata()->getMetadata($this, $metadataKey);
}
return null;
}
public function hasMetadata(string $metadataKey) : bool{
if($this->getLevel() instanceof Level){
return $this->getLevel()->getBlockMetadata()->hasMetadata($this, $metadataKey);
if($this->isValid()){
return $this->level->getBlockMetadata()->hasMetadata($this, $metadataKey);
}
return false;
}
public function removeMetadata(string $metadataKey, Plugin $owningPlugin){
if($this->getLevel() instanceof Level){
$this->getLevel()->getBlockMetadata()->removeMetadata($this, $metadataKey, $owningPlugin);
if($this->isValid()){
$this->level->getBlockMetadata()->removeMetadata($this, $metadataKey, $owningPlugin);
}
}
}

View File

@ -30,8 +30,6 @@ use pocketmine\level\Position;
* Manages block registration and instance creation
*/
class BlockFactory{
/** @var \SplFixedArray<Block> */
private static $list = null;
/** @var \SplFixedArray<Block> */
private static $fullList = null;
@ -50,277 +48,284 @@ class BlockFactory{
/** @var \SplFixedArray<float> */
public static $blastResistance = null;
/** @var int[] */
public static $staticRuntimeIdMap = [];
/** @var int[] */
public static $legacyIdMap = [];
/** @var int */
private static $lastRuntimeId = 0;
/**
* Initializes the block factory. By default this is called only once on server start, however you may wish to use
* this if you need to reset the block factory back to its original defaults for whatever reason.
*
* @param bool $force
*/
public static function init(bool $force = false){
if(self::$list === null or $force){
self::$list = new \SplFixedArray(256);
self::$fullList = new \SplFixedArray(4096);
public static function init() : void{
self::$fullList = new \SplFixedArray(4096);
self::$light = new \SplFixedArray(256);
self::$lightFilter = new \SplFixedArray(256);
self::$solid = new \SplFixedArray(256);
self::$hardness = new \SplFixedArray(256);
self::$transparent = new \SplFixedArray(256);
self::$diffusesSkyLight = new \SplFixedArray(256);
self::$blastResistance = new \SplFixedArray(256);
self::$light = new \SplFixedArray(256);
self::$lightFilter = new \SplFixedArray(256);
self::$solid = new \SplFixedArray(256);
self::$hardness = new \SplFixedArray(256);
self::$transparent = new \SplFixedArray(256);
self::$diffusesSkyLight = new \SplFixedArray(256);
self::$blastResistance = new \SplFixedArray(256);
self::registerBlock(new Air());
self::registerBlock(new Stone());
self::registerBlock(new Grass());
self::registerBlock(new Dirt());
self::registerBlock(new Cobblestone());
self::registerBlock(new Planks());
self::registerBlock(new Sapling());
self::registerBlock(new Bedrock());
self::registerBlock(new Water());
self::registerBlock(new StillWater());
self::registerBlock(new Lava());
self::registerBlock(new StillLava());
self::registerBlock(new Sand());
self::registerBlock(new Gravel());
self::registerBlock(new GoldOre());
self::registerBlock(new IronOre());
self::registerBlock(new CoalOre());
self::registerBlock(new Wood());
self::registerBlock(new Leaves());
self::registerBlock(new Sponge());
self::registerBlock(new Glass());
self::registerBlock(new LapisOre());
self::registerBlock(new Lapis());
//TODO: DISPENSER
self::registerBlock(new Sandstone());
self::registerBlock(new NoteBlock());
self::registerBlock(new Bed());
self::registerBlock(new PoweredRail());
self::registerBlock(new DetectorRail());
//TODO: STICKY_PISTON
self::registerBlock(new Cobweb());
self::registerBlock(new TallGrass());
self::registerBlock(new DeadBush());
//TODO: PISTON
//TODO: PISTONARMCOLLISION
self::registerBlock(new Wool());
self::registerBlock(new Air());
self::registerBlock(new Stone());
self::registerBlock(new Grass());
self::registerBlock(new Dirt());
self::registerBlock(new Cobblestone());
self::registerBlock(new Planks());
self::registerBlock(new Sapling());
self::registerBlock(new Bedrock());
self::registerBlock(new Water());
self::registerBlock(new StillWater());
self::registerBlock(new Lava());
self::registerBlock(new StillLava());
self::registerBlock(new Sand());
self::registerBlock(new Gravel());
self::registerBlock(new GoldOre());
self::registerBlock(new IronOre());
self::registerBlock(new CoalOre());
self::registerBlock(new Wood());
self::registerBlock(new Leaves());
self::registerBlock(new Sponge());
self::registerBlock(new Glass());
self::registerBlock(new LapisOre());
self::registerBlock(new Lapis());
//TODO: DISPENSER
self::registerBlock(new Sandstone());
self::registerBlock(new NoteBlock());
self::registerBlock(new Bed());
self::registerBlock(new PoweredRail());
self::registerBlock(new DetectorRail());
//TODO: STICKY_PISTON
self::registerBlock(new Cobweb());
self::registerBlock(new TallGrass());
self::registerBlock(new DeadBush());
//TODO: PISTON
//TODO: PISTONARMCOLLISION
self::registerBlock(new Wool());
self::registerBlock(new Dandelion());
self::registerBlock(new Flower());
self::registerBlock(new BrownMushroom());
self::registerBlock(new RedMushroom());
self::registerBlock(new Gold());
self::registerBlock(new Iron());
self::registerBlock(new DoubleStoneSlab());
self::registerBlock(new StoneSlab());
self::registerBlock(new Bricks());
self::registerBlock(new TNT());
self::registerBlock(new Bookshelf());
self::registerBlock(new MossyCobblestone());
self::registerBlock(new Obsidian());
self::registerBlock(new Torch());
self::registerBlock(new Fire());
self::registerBlock(new MonsterSpawner());
self::registerBlock(new WoodenStairs(Block::OAK_STAIRS, 0, "Oak Stairs"));
self::registerBlock(new Chest());
//TODO: REDSTONE_WIRE
self::registerBlock(new DiamondOre());
self::registerBlock(new Diamond());
self::registerBlock(new CraftingTable());
self::registerBlock(new Wheat());
self::registerBlock(new Farmland());
self::registerBlock(new Furnace());
self::registerBlock(new BurningFurnace());
self::registerBlock(new SignPost());
self::registerBlock(new WoodenDoor(Block::OAK_DOOR_BLOCK, 0, "Oak Door Block", Item::OAK_DOOR));
self::registerBlock(new Ladder());
self::registerBlock(new Rail());
self::registerBlock(new CobblestoneStairs());
self::registerBlock(new WallSign());
self::registerBlock(new Lever());
self::registerBlock(new StonePressurePlate());
self::registerBlock(new IronDoor());
self::registerBlock(new WoodenPressurePlate());
self::registerBlock(new RedstoneOre());
self::registerBlock(new GlowingRedstoneOre());
self::registerBlock(new RedstoneTorchUnlit());
self::registerBlock(new RedstoneTorch());
self::registerBlock(new StoneButton());
self::registerBlock(new SnowLayer());
self::registerBlock(new Ice());
self::registerBlock(new Snow());
self::registerBlock(new Cactus());
self::registerBlock(new Clay());
self::registerBlock(new Sugarcane());
self::registerBlock(new Dandelion());
self::registerBlock(new Flower());
self::registerBlock(new BrownMushroom());
self::registerBlock(new RedMushroom());
self::registerBlock(new Gold());
self::registerBlock(new Iron());
self::registerBlock(new DoubleStoneSlab());
self::registerBlock(new StoneSlab());
self::registerBlock(new Bricks());
self::registerBlock(new TNT());
self::registerBlock(new Bookshelf());
self::registerBlock(new MossyCobblestone());
self::registerBlock(new Obsidian());
self::registerBlock(new Torch());
self::registerBlock(new Fire());
self::registerBlock(new MonsterSpawner());
self::registerBlock(new WoodenStairs(Block::OAK_STAIRS, 0, "Oak Stairs"));
self::registerBlock(new Chest());
//TODO: REDSTONE_WIRE
self::registerBlock(new DiamondOre());
self::registerBlock(new Diamond());
self::registerBlock(new CraftingTable());
self::registerBlock(new Wheat());
self::registerBlock(new Farmland());
self::registerBlock(new Furnace());
self::registerBlock(new BurningFurnace());
self::registerBlock(new SignPost());
self::registerBlock(new WoodenDoor(Block::OAK_DOOR_BLOCK, 0, "Oak Door", Item::OAK_DOOR));
self::registerBlock(new Ladder());
self::registerBlock(new Rail());
self::registerBlock(new CobblestoneStairs());
self::registerBlock(new WallSign());
self::registerBlock(new Lever());
self::registerBlock(new StonePressurePlate());
self::registerBlock(new IronDoor());
self::registerBlock(new WoodenPressurePlate());
self::registerBlock(new RedstoneOre());
self::registerBlock(new GlowingRedstoneOre());
self::registerBlock(new RedstoneTorchUnlit());
self::registerBlock(new RedstoneTorch());
self::registerBlock(new StoneButton());
self::registerBlock(new SnowLayer());
self::registerBlock(new Ice());
self::registerBlock(new Snow());
self::registerBlock(new Cactus());
self::registerBlock(new Clay());
self::registerBlock(new Sugarcane());
//TODO: JUKEBOX
self::registerBlock(new WoodenFence());
self::registerBlock(new Pumpkin());
self::registerBlock(new Netherrack());
self::registerBlock(new SoulSand());
self::registerBlock(new Glowstone());
//TODO: PORTAL
self::registerBlock(new LitPumpkin());
self::registerBlock(new Cake());
//TODO: REPEATER_BLOCK
//TODO: POWERED_REPEATER
//TODO: INVISIBLEBEDROCK
self::registerBlock(new Trapdoor());
//TODO: MONSTER_EGG
self::registerBlock(new StoneBricks());
self::registerBlock(new BrownMushroomBlock());
self::registerBlock(new RedMushroomBlock());
self::registerBlock(new IronBars());
self::registerBlock(new GlassPane());
self::registerBlock(new Melon());
self::registerBlock(new PumpkinStem());
self::registerBlock(new MelonStem());
self::registerBlock(new Vine());
self::registerBlock(new FenceGate(Block::OAK_FENCE_GATE, 0, "Oak Fence Gate"));
self::registerBlock(new BrickStairs());
self::registerBlock(new StoneBrickStairs());
self::registerBlock(new Mycelium());
self::registerBlock(new WaterLily());
self::registerBlock(new NetherBrick(Block::NETHER_BRICK_BLOCK, 0, "Nether Bricks"));
self::registerBlock(new NetherBrickFence());
self::registerBlock(new NetherBrickStairs());
self::registerBlock(new NetherWartPlant());
self::registerBlock(new EnchantingTable());
self::registerBlock(new BrewingStand());
//TODO: CAULDRON_BLOCK
//TODO: END_PORTAL
self::registerBlock(new EndPortalFrame());
self::registerBlock(new EndStone());
//TODO: DRAGON_EGG
self::registerBlock(new RedstoneLamp());
self::registerBlock(new LitRedstoneLamp());
//TODO: DROPPER
self::registerBlock(new ActivatorRail());
self::registerBlock(new CocoaBlock());
self::registerBlock(new SandstoneStairs());
self::registerBlock(new EmeraldOre());
self::registerBlock(new EnderChest());
self::registerBlock(new TripwireHook());
self::registerBlock(new Tripwire());
self::registerBlock(new Emerald());
self::registerBlock(new WoodenStairs(Block::SPRUCE_STAIRS, 0, "Spruce Stairs"));
self::registerBlock(new WoodenStairs(Block::BIRCH_STAIRS, 0, "Birch Stairs"));
self::registerBlock(new WoodenStairs(Block::JUNGLE_STAIRS, 0, "Jungle Stairs"));
//TODO: COMMAND_BLOCK
//TODO: BEACON
self::registerBlock(new CobblestoneWall());
self::registerBlock(new FlowerPot());
self::registerBlock(new Carrot());
self::registerBlock(new Potato());
self::registerBlock(new WoodenButton());
self::registerBlock(new Skull());
self::registerBlock(new Anvil());
self::registerBlock(new TrappedChest());
self::registerBlock(new WeightedPressurePlateLight());
self::registerBlock(new WeightedPressurePlateHeavy());
//TODO: COMPARATOR_BLOCK
//TODO: POWERED_COMPARATOR
self::registerBlock(new DaylightSensor());
self::registerBlock(new Redstone());
self::registerBlock(new NetherQuartzOre());
//TODO: HOPPER_BLOCK
self::registerBlock(new Quartz());
self::registerBlock(new QuartzStairs());
self::registerBlock(new DoubleWoodenSlab());
self::registerBlock(new WoodenSlab());
self::registerBlock(new StainedClay());
self::registerBlock(new StainedGlassPane());
self::registerBlock(new Leaves2());
self::registerBlock(new Wood2());
self::registerBlock(new WoodenStairs(Block::ACACIA_STAIRS, 0, "Acacia Stairs"));
self::registerBlock(new WoodenStairs(Block::DARK_OAK_STAIRS, 0, "Dark Oak Stairs"));
//TODO: SLIME
self::registerBlock(new Fence());
self::registerBlock(new Pumpkin());
self::registerBlock(new Netherrack());
self::registerBlock(new SoulSand());
self::registerBlock(new Glowstone());
//TODO: PORTAL
self::registerBlock(new LitPumpkin());
self::registerBlock(new Cake());
//TODO: REPEATER_BLOCK
//TODO: POWERED_REPEATER
//TODO: INVISIBLEBEDROCK
self::registerBlock(new Trapdoor());
//TODO: MONSTER_EGG
self::registerBlock(new StoneBricks());
self::registerBlock(new BrownMushroomBlock());
self::registerBlock(new RedMushroomBlock());
self::registerBlock(new IronBars());
self::registerBlock(new GlassPane());
self::registerBlock(new Melon());
self::registerBlock(new PumpkinStem());
self::registerBlock(new MelonStem());
self::registerBlock(new Vine());
self::registerBlock(new FenceGate(Block::OAK_FENCE_GATE, 0, "Oak Fence Gate"));
self::registerBlock(new BrickStairs());
self::registerBlock(new StoneBrickStairs());
self::registerBlock(new Mycelium());
self::registerBlock(new WaterLily());
self::registerBlock(new NetherBrick(Block::NETHER_BRICK_BLOCK, 0, "Nether Bricks"));
self::registerBlock(new NetherBrickFence());
self::registerBlock(new NetherBrickStairs());
self::registerBlock(new NetherWartPlant());
self::registerBlock(new EnchantingTable());
self::registerBlock(new BrewingStand());
//TODO: CAULDRON_BLOCK
//TODO: END_PORTAL
self::registerBlock(new EndPortalFrame());
self::registerBlock(new EndStone());
//TODO: DRAGON_EGG
self::registerBlock(new RedstoneLamp());
self::registerBlock(new LitRedstoneLamp());
//TODO: DROPPER
self::registerBlock(new ActivatorRail());
self::registerBlock(new CocoaBlock());
self::registerBlock(new SandstoneStairs());
self::registerBlock(new EmeraldOre());
//TODO: ENDER_CHEST
self::registerBlock(new TripwireHook());
self::registerBlock(new Tripwire());
self::registerBlock(new Emerald());
self::registerBlock(new WoodenStairs(Block::SPRUCE_STAIRS, 0, "Spruce Stairs"));
self::registerBlock(new WoodenStairs(Block::BIRCH_STAIRS, 0, "Birch Stairs"));
self::registerBlock(new WoodenStairs(Block::JUNGLE_STAIRS, 0, "Jungle Stairs"));
//TODO: COMMAND_BLOCK
//TODO: BEACON
self::registerBlock(new CobblestoneWall());
self::registerBlock(new FlowerPot());
self::registerBlock(new Carrot());
self::registerBlock(new Potato());
self::registerBlock(new WoodenButton());
self::registerBlock(new Skull());
self::registerBlock(new Anvil());
self::registerBlock(new TrappedChest());
self::registerBlock(new WeightedPressurePlateLight());
self::registerBlock(new WeightedPressurePlateHeavy());
//TODO: COMPARATOR_BLOCK
//TODO: POWERED_COMPARATOR
self::registerBlock(new DaylightSensor());
self::registerBlock(new Redstone());
self::registerBlock(new NetherQuartzOre());
//TODO: HOPPER_BLOCK
self::registerBlock(new Quartz());
self::registerBlock(new QuartzStairs());
self::registerBlock(new DoubleWoodenSlab());
self::registerBlock(new WoodenSlab());
self::registerBlock(new StainedClay());
self::registerBlock(new StainedGlassPane());
self::registerBlock(new Leaves2());
self::registerBlock(new Wood2());
self::registerBlock(new WoodenStairs(Block::ACACIA_STAIRS, 0, "Acacia Stairs"));
self::registerBlock(new WoodenStairs(Block::DARK_OAK_STAIRS, 0, "Dark Oak Stairs"));
//TODO: SLIME
self::registerBlock(new IronTrapdoor());
self::registerBlock(new Prismarine());
self::registerBlock(new SeaLantern());
self::registerBlock(new HayBale());
self::registerBlock(new Carpet());
self::registerBlock(new HardenedClay());
self::registerBlock(new Coal());
self::registerBlock(new PackedIce());
self::registerBlock(new DoublePlant());
self::registerBlock(new StandingBanner());
self::registerBlock(new WallBanner());
//TODO: DAYLIGHT_DETECTOR_INVERTED
self::registerBlock(new RedSandstone());
self::registerBlock(new RedSandstoneStairs());
self::registerBlock(new DoubleStoneSlab2());
self::registerBlock(new StoneSlab2());
self::registerBlock(new FenceGate(Block::SPRUCE_FENCE_GATE, 0, "Spruce Fence Gate"));
self::registerBlock(new FenceGate(Block::BIRCH_FENCE_GATE, 0, "Birch Fence Gate"));
self::registerBlock(new FenceGate(Block::JUNGLE_FENCE_GATE, 0, "Jungle Fence Gate"));
self::registerBlock(new FenceGate(Block::DARK_OAK_FENCE_GATE, 0, "Dark Oak Fence Gate"));
self::registerBlock(new FenceGate(Block::ACACIA_FENCE_GATE, 0, "Acacia Fence Gate"));
//TODO: REPEATING_COMMAND_BLOCK
//TODO: CHAIN_COMMAND_BLOCK
self::registerBlock(new IronTrapdoor());
self::registerBlock(new Prismarine());
self::registerBlock(new SeaLantern());
self::registerBlock(new HayBale());
self::registerBlock(new Carpet());
self::registerBlock(new HardenedClay());
self::registerBlock(new Coal());
self::registerBlock(new PackedIce());
self::registerBlock(new DoublePlant());
self::registerBlock(new WoodenDoor(Block::SPRUCE_DOOR_BLOCK, 0, "Spruce Door", Item::SPRUCE_DOOR));
self::registerBlock(new WoodenDoor(Block::BIRCH_DOOR_BLOCK, 0, "Birch Door", Item::BIRCH_DOOR));
self::registerBlock(new WoodenDoor(Block::JUNGLE_DOOR_BLOCK, 0, "Jungle Door", Item::JUNGLE_DOOR));
self::registerBlock(new WoodenDoor(Block::ACACIA_DOOR_BLOCK, 0, "Acacia Door", Item::ACACIA_DOOR));
self::registerBlock(new WoodenDoor(Block::DARK_OAK_DOOR_BLOCK, 0, "Dark Oak Door", Item::DARK_OAK_DOOR));
self::registerBlock(new GrassPath());
self::registerBlock(new ItemFrame());
//TODO: CHORUS_FLOWER
self::registerBlock(new Purpur());
//TODO: DAYLIGHT_DETECTOR_INVERTED
//TODO: RED_SANDSTONE
//TODO: RED_SANDSTONE_STAIRS
//TODO: DOUBLE_STONE_SLAB2
//TODO: STONE_SLAB2
self::registerBlock(new FenceGate(Block::SPRUCE_FENCE_GATE, 0, "Spruce Fence Gate"));
self::registerBlock(new FenceGate(Block::BIRCH_FENCE_GATE, 0, "Birch Fence Gate"));
self::registerBlock(new FenceGate(Block::JUNGLE_FENCE_GATE, 0, "Jungle Fence Gate"));
self::registerBlock(new FenceGate(Block::DARK_OAK_FENCE_GATE, 0, "Dark Oak Fence Gate"));
self::registerBlock(new FenceGate(Block::ACACIA_FENCE_GATE, 0, "Acacia Fence Gate"));
//TODO: REPEATING_COMMAND_BLOCK
//TODO: CHAIN_COMMAND_BLOCK
self::registerBlock(new PurpurStairs());
self::registerBlock(new WoodenDoor(Block::SPRUCE_DOOR_BLOCK, 0, "Spruce Door Block", Item::SPRUCE_DOOR));
self::registerBlock(new WoodenDoor(Block::BIRCH_DOOR_BLOCK, 0, "Birch Door Block", Item::BIRCH_DOOR));
self::registerBlock(new WoodenDoor(Block::JUNGLE_DOOR_BLOCK, 0, "Jungle Door Block", Item::JUNGLE_DOOR));
self::registerBlock(new WoodenDoor(Block::ACACIA_DOOR_BLOCK, 0, "Acacia Door Block", Item::ACACIA_DOOR));
self::registerBlock(new WoodenDoor(Block::DARK_OAK_DOOR_BLOCK, 0, "Dark Oak Door Block", Item::DARK_OAK_DOOR));
self::registerBlock(new GrassPath());
self::registerBlock(new ItemFrame());
//TODO: CHORUS_FLOWER
//TODO: PURPUR_BLOCK
//TODO: UNDYED_SHULKER_BOX
self::registerBlock(new EndStoneBricks());
//TODO: FROSTED_ICE
self::registerBlock(new EndRod());
//TODO: END_GATEWAY
//TODO: PURPUR_STAIRS
self::registerBlock(new Magma());
self::registerBlock(new NetherWartBlock());
self::registerBlock(new NetherBrick(Block::RED_NETHER_BRICK, 0, "Red Nether Bricks"));
self::registerBlock(new BoneBlock());
//TODO: END_BRICKS
//TODO: FROSTED_ICE
self::registerBlock(new EndRod());
//TODO: END_GATEWAY
//TODO: SHULKER_BOX
self::registerBlock(new GlazedTerracotta(Block::PURPLE_GLAZED_TERRACOTTA, 0, "Purple Glazed Terracotta"));
self::registerBlock(new GlazedTerracotta(Block::WHITE_GLAZED_TERRACOTTA, 0, "White Glazed Terracotta"));
self::registerBlock(new GlazedTerracotta(Block::ORANGE_GLAZED_TERRACOTTA, 0, "Orange Glazed Terracotta"));
self::registerBlock(new GlazedTerracotta(Block::MAGENTA_GLAZED_TERRACOTTA, 0, "Magenta Glazed Terracotta"));
self::registerBlock(new GlazedTerracotta(Block::LIGHT_BLUE_GLAZED_TERRACOTTA, 0, "Light Blue Glazed Terracotta"));
self::registerBlock(new GlazedTerracotta(Block::YELLOW_GLAZED_TERRACOTTA, 0, "Yellow Glazed Terracotta"));
self::registerBlock(new GlazedTerracotta(Block::LIME_GLAZED_TERRACOTTA, 0, "Lime Glazed Terracotta"));
self::registerBlock(new GlazedTerracotta(Block::PINK_GLAZED_TERRACOTTA, 0, "Pink Glazed Terracotta"));
self::registerBlock(new GlazedTerracotta(Block::GRAY_GLAZED_TERRACOTTA, 0, "Grey Glazed Terracotta"));
self::registerBlock(new GlazedTerracotta(Block::SILVER_GLAZED_TERRACOTTA, 0, "Light Grey Glazed Terracotta"));
self::registerBlock(new GlazedTerracotta(Block::CYAN_GLAZED_TERRACOTTA, 0, "Cyan Glazed Terracotta"));
self::registerBlock(new Magma());
self::registerBlock(new NetherWartBlock());
self::registerBlock(new NetherBrick(Block::RED_NETHER_BRICK, 0, "Red Nether Bricks"));
self::registerBlock(new BoneBlock());
self::registerBlock(new GlazedTerracotta(Block::BLUE_GLAZED_TERRACOTTA, 0, "Blue Glazed Terracotta"));
self::registerBlock(new GlazedTerracotta(Block::BROWN_GLAZED_TERRACOTTA, 0, "Brown Glazed Terracotta"));
self::registerBlock(new GlazedTerracotta(Block::GREEN_GLAZED_TERRACOTTA, 0, "Green Glazed Terracotta"));
self::registerBlock(new GlazedTerracotta(Block::RED_GLAZED_TERRACOTTA, 0, "Red Glazed Terracotta"));
self::registerBlock(new GlazedTerracotta(Block::BLACK_GLAZED_TERRACOTTA, 0, "Black Glazed Terracotta"));
self::registerBlock(new Concrete());
self::registerBlock(new ConcretePowder());
//TODO: SHULKER_BOX
self::registerBlock(new GlazedTerracotta(Block::PURPLE_GLAZED_TERRACOTTA, 0, "Purple Glazed Terracotta"));
self::registerBlock(new GlazedTerracotta(Block::WHITE_GLAZED_TERRACOTTA, 0, "White Glazed Terracotta"));
self::registerBlock(new GlazedTerracotta(Block::ORANGE_GLAZED_TERRACOTTA, 0, "Orange Glazed Terracotta"));
self::registerBlock(new GlazedTerracotta(Block::MAGENTA_GLAZED_TERRACOTTA, 0, "Magenta Glazed Terracotta"));
self::registerBlock(new GlazedTerracotta(Block::LIGHT_BLUE_GLAZED_TERRACOTTA, 0, "Light Blue Glazed Terracotta"));
self::registerBlock(new GlazedTerracotta(Block::YELLOW_GLAZED_TERRACOTTA, 0, "Yellow Glazed Terracotta"));
self::registerBlock(new GlazedTerracotta(Block::LIME_GLAZED_TERRACOTTA, 0, "Lime Glazed Terracotta"));
self::registerBlock(new GlazedTerracotta(Block::PINK_GLAZED_TERRACOTTA, 0, "Pink Glazed Terracotta"));
self::registerBlock(new GlazedTerracotta(Block::GRAY_GLAZED_TERRACOTTA, 0, "Grey Glazed Terracotta"));
self::registerBlock(new GlazedTerracotta(Block::SILVER_GLAZED_TERRACOTTA, 0, "Light Grey Glazed Terracotta"));
self::registerBlock(new GlazedTerracotta(Block::CYAN_GLAZED_TERRACOTTA, 0, "Cyan Glazed Terracotta"));
//TODO: CHORUS_PLANT
self::registerBlock(new StainedGlass());
self::registerBlock(new GlazedTerracotta(Block::BLUE_GLAZED_TERRACOTTA, 0, "Blue Glazed Terracotta"));
self::registerBlock(new GlazedTerracotta(Block::BROWN_GLAZED_TERRACOTTA, 0, "Brown Glazed Terracotta"));
self::registerBlock(new GlazedTerracotta(Block::GREEN_GLAZED_TERRACOTTA, 0, "Green Glazed Terracotta"));
self::registerBlock(new GlazedTerracotta(Block::RED_GLAZED_TERRACOTTA, 0, "Red Glazed Terracotta"));
self::registerBlock(new GlazedTerracotta(Block::BLACK_GLAZED_TERRACOTTA, 0, "Black Glazed Terracotta"));
self::registerBlock(new Concrete());
//TODO: CONCRETEPOWDER
self::registerBlock(new Podzol());
self::registerBlock(new Beetroot());
self::registerBlock(new Stonecutter());
self::registerBlock(new GlowingObsidian());
self::registerBlock(new NetherReactor());
//TODO: INFO_UPDATE
//TODO: INFO_UPDATE2
//TODO: MOVINGBLOCK
//TODO: OBSERVER
//TODO: STRUCTURE_BLOCK
//TODO: CHORUS_PLANT
self::registerBlock(new StainedGlass());
//TODO: RESERVED6
self::registerBlock(new Podzol());
self::registerBlock(new Beetroot());
self::registerBlock(new Stonecutter());
self::registerBlock(new GlowingObsidian());
self::registerBlock(new NetherReactor());
//TODO: INFO_UPDATE
//TODO: INFO_UPDATE2
//TODO: MOVINGBLOCK
//TODO: OBSERVER
//TODO: RESERVED6
foreach(self::$list as $id => $block){
if($block === null){
self::registerBlock(new UnknownBlock($id));
}
for($id = 0, $size = self::$fullList->getSize() >> 4; $id < $size; ++$id){
if(self::$fullList[$id << 4] === null){
self::registerBlock(new UnknownBlock($id));
}
}
}
@ -338,15 +343,13 @@ class BlockFactory{
* @throws \RuntimeException if something attempted to override an already-registered block without specifying the
* $override parameter.
*/
public static function registerBlock(Block $block, bool $override = false){
public static function registerBlock(Block $block, bool $override = false) : void{
$id = $block->getId();
if(!$override and self::isRegistered($id)){
throw new \RuntimeException("Trying to overwrite an already registered block");
}
self::$list[$id] = clone $block;
for($meta = 0; $meta < 16; ++$meta){
$variant = clone $block;
$variant->setDamage($meta);
@ -357,7 +360,7 @@ class BlockFactory{
self::$transparent[$id] = $block->isTransparent();
self::$hardness[$id] = $block->getHardness();
self::$light[$id] = $block->getLightLevel();
self::$lightFilter[$id] = $block->getLightFilter() + 1; //opacity plus 1 standard light filter
self::$lightFilter[$id] = min(15, $block->getLightFilter() + 1); //opacity plus 1 standard light filter
self::$diffusesSkyLight[$id] = $block->diffusesSkyLight();
self::$blastResistance[$id] = $block->getBlastResistance();
}
@ -387,9 +390,9 @@ class BlockFactory{
}
if($pos !== null){
$block->x = $pos->x;
$block->y = $pos->y;
$block->z = $pos->z;
$block->x = $pos->getFloorX();
$block->y = $pos->getFloorY();
$block->z = $pos->getFloorZ();
$block->level = $pos->level;
}
@ -411,7 +414,50 @@ class BlockFactory{
* @return bool
*/
public static function isRegistered(int $id) : bool{
$b = self::$list[$id];
$b = self::$fullList[$id << 4];
return $b !== null and !($b instanceof UnknownBlock);
}
}
public static function registerStaticRuntimeIdMappings() : void{
/** @var mixed[] $runtimeIdMap */
$runtimeIdMap = json_decode(file_get_contents(\pocketmine\RESOURCE_PATH . "runtimeid_table.json"), true);
foreach($runtimeIdMap as $obj){
self::registerMapping($obj["runtimeID"], $obj["id"], $obj["data"]);
}
}
/**
* @internal
*
* @param int $id
* @param int $meta
*
* @return int
*/
public static function toStaticRuntimeId(int $id, int $meta = 0) : int{
/*
* try id+meta first
* if not found, try id+0 (strip meta)
* if still not found, return update! block
*/
return self::$staticRuntimeIdMap[($id << 4) | $meta] ?? self::$staticRuntimeIdMap[$id << 4] ?? self::$staticRuntimeIdMap[BlockIds::INFO_UPDATE << 4];
}
/**
* @internal
*
* @param int $runtimeId
*
* @return int[] [id, meta]
*/
public static function fromStaticRuntimeId(int $runtimeId) : array{
$v = self::$legacyIdMap[$runtimeId];
return [$v >> 4, $v & 0xf];
}
private static function registerMapping(int $staticRuntimeId, int $legacyId, int $legacyMeta) : void{
self::$staticRuntimeIdMap[($legacyId << 4) | $legacyMeta] = $staticRuntimeId;
self::$legacyIdMap[$staticRuntimeId] = ($legacyId << 4) | $legacyMeta;
self::$lastRuntimeId = max(self::$lastRuntimeId, $staticRuntimeId);
}
}

View File

@ -25,255 +25,255 @@ namespace pocketmine\block;
interface BlockIds{
const AIR = 0;
const STONE = 1;
const GRASS = 2;
const DIRT = 3;
const COBBLESTONE = 4;
const PLANKS = 5, WOODEN_PLANKS = 5;
const SAPLING = 6;
const BEDROCK = 7;
const FLOWING_WATER = 8;
const STILL_WATER = 9, WATER = 9;
const FLOWING_LAVA = 10;
const LAVA = 11, STILL_LAVA = 11;
const SAND = 12;
const GRAVEL = 13;
const GOLD_ORE = 14;
const IRON_ORE = 15;
const COAL_ORE = 16;
const LOG = 17, WOOD = 17;
const LEAVES = 18;
const SPONGE = 19;
const GLASS = 20;
const LAPIS_ORE = 21;
const LAPIS_BLOCK = 22;
const DISPENSER = 23;
const SANDSTONE = 24;
const NOTEBLOCK = 25, NOTE_BLOCK = 25;
const BED_BLOCK = 26;
const GOLDEN_RAIL = 27, POWERED_RAIL = 27;
const DETECTOR_RAIL = 28;
const STICKY_PISTON = 29;
const COBWEB = 30, WEB = 30;
const TALLGRASS = 31, TALL_GRASS = 31;
const DEADBUSH = 32, DEAD_BUSH = 32;
const PISTON = 33;
const PISTONARMCOLLISION = 34, PISTON_ARM_COLLISION = 34;
const WOOL = 35;
public const AIR = 0;
public const STONE = 1;
public const GRASS = 2;
public const DIRT = 3;
public const COBBLESTONE = 4;
public const PLANKS = 5, WOODEN_PLANKS = 5;
public const SAPLING = 6;
public const BEDROCK = 7;
public const FLOWING_WATER = 8;
public const STILL_WATER = 9, WATER = 9;
public const FLOWING_LAVA = 10;
public const LAVA = 11, STILL_LAVA = 11;
public const SAND = 12;
public const GRAVEL = 13;
public const GOLD_ORE = 14;
public const IRON_ORE = 15;
public const COAL_ORE = 16;
public const LOG = 17, WOOD = 17;
public const LEAVES = 18;
public const SPONGE = 19;
public const GLASS = 20;
public const LAPIS_ORE = 21;
public const LAPIS_BLOCK = 22;
public const DISPENSER = 23;
public const SANDSTONE = 24;
public const NOTEBLOCK = 25, NOTE_BLOCK = 25;
public const BED_BLOCK = 26;
public const GOLDEN_RAIL = 27, POWERED_RAIL = 27;
public const DETECTOR_RAIL = 28;
public const STICKY_PISTON = 29;
public const COBWEB = 30, WEB = 30;
public const TALLGRASS = 31, TALL_GRASS = 31;
public const DEADBUSH = 32, DEAD_BUSH = 32;
public const PISTON = 33;
public const PISTONARMCOLLISION = 34, PISTON_ARM_COLLISION = 34;
public const WOOL = 35;
const DANDELION = 37, YELLOW_FLOWER = 37;
const POPPY = 38, RED_FLOWER = 38;
const BROWN_MUSHROOM = 39;
const RED_MUSHROOM = 40;
const GOLD_BLOCK = 41;
const IRON_BLOCK = 42;
const DOUBLE_STONE_SLAB = 43;
const STONE_SLAB = 44;
const BRICK_BLOCK = 45;
const TNT = 46;
const BOOKSHELF = 47;
const MOSSY_COBBLESTONE = 48, MOSS_STONE = 48;
const OBSIDIAN = 49;
const TORCH = 50;
const FIRE = 51;
const MOB_SPAWNER = 52, MONSTER_SPAWNER = 52;
const OAK_STAIRS = 53, WOODEN_STAIRS = 53;
const CHEST = 54;
const REDSTONE_WIRE = 55;
const DIAMOND_ORE = 56;
const DIAMOND_BLOCK = 57;
const CRAFTING_TABLE = 58, WORKBENCH = 58;
const WHEAT_BLOCK = 59;
const FARMLAND = 60;
const FURNACE = 61;
const BURNING_FURNACE = 62, LIT_FURNACE = 62;
const SIGN_POST = 63, STANDING_SIGN = 63;
const OAK_DOOR_BLOCK = 64, WOODEN_DOOR_BLOCK = 64;
const LADDER = 65;
const RAIL = 66;
const COBBLESTONE_STAIRS = 67, STONE_STAIRS = 67;
const WALL_SIGN = 68;
const LEVER = 69;
const STONE_PRESSURE_PLATE = 70;
const IRON_DOOR_BLOCK = 71;
const WOODEN_PRESSURE_PLATE = 72;
const REDSTONE_ORE = 73;
const GLOWING_REDSTONE_ORE = 74, LIT_REDSTONE_ORE = 74;
const UNLIT_REDSTONE_TORCH = 75;
const LIT_REDSTONE_TORCH = 76, REDSTONE_TORCH = 76;
const STONE_BUTTON = 77;
const SNOW_LAYER = 78;
const ICE = 79;
const SNOW = 80, SNOW_BLOCK = 80;
const CACTUS = 81;
const CLAY_BLOCK = 82;
const REEDS_BLOCK = 83, SUGARCANE_BLOCK = 83;
const JUKEBOX = 84;
const FENCE = 85;
const PUMPKIN = 86;
const NETHERRACK = 87;
const SOUL_SAND = 88;
const GLOWSTONE = 89;
const PORTAL = 90;
const JACK_O_LANTERN = 91, LIT_PUMPKIN = 91;
const CAKE_BLOCK = 92;
const REPEATER_BLOCK = 93, UNPOWERED_REPEATER = 93;
const POWERED_REPEATER = 94;
const INVISIBLEBEDROCK = 95, INVISIBLE_BEDROCK = 95;
const TRAPDOOR = 96, WOODEN_TRAPDOOR = 96;
const MONSTER_EGG = 97;
const STONEBRICK = 98, STONE_BRICK = 98, STONE_BRICKS = 98;
const BROWN_MUSHROOM_BLOCK = 99;
const RED_MUSHROOM_BLOCK = 100;
const IRON_BARS = 101;
const GLASS_PANE = 102;
const MELON_BLOCK = 103;
const PUMPKIN_STEM = 104;
const MELON_STEM = 105;
const VINE = 106, VINES = 106;
const FENCE_GATE = 107, OAK_FENCE_GATE = 107;
const BRICK_STAIRS = 108;
const STONE_BRICK_STAIRS = 109;
const MYCELIUM = 110;
const LILY_PAD = 111, WATERLILY = 111, WATER_LILY = 111;
const NETHER_BRICK_BLOCK = 112;
const NETHER_BRICK_FENCE = 113;
const NETHER_BRICK_STAIRS = 114;
const NETHER_WART_PLANT = 115;
const ENCHANTING_TABLE = 116, ENCHANTMENT_TABLE = 116;
const BREWING_STAND_BLOCK = 117;
const CAULDRON_BLOCK = 118;
const END_PORTAL = 119;
const END_PORTAL_FRAME = 120;
const END_STONE = 121;
const DRAGON_EGG = 122;
const REDSTONE_LAMP = 123;
const LIT_REDSTONE_LAMP = 124;
const DROPPER = 125;
const ACTIVATOR_RAIL = 126;
const COCOA = 127, COCOA_BLOCK = 127;
const SANDSTONE_STAIRS = 128;
const EMERALD_ORE = 129;
const ENDER_CHEST = 130;
const TRIPWIRE_HOOK = 131;
const TRIPWIRE = 132, TRIP_WIRE = 132;
const EMERALD_BLOCK = 133;
const SPRUCE_STAIRS = 134;
const BIRCH_STAIRS = 135;
const JUNGLE_STAIRS = 136;
const COMMAND_BLOCK = 137;
const BEACON = 138;
const COBBLESTONE_WALL = 139, STONE_WALL = 139;
const FLOWER_POT_BLOCK = 140;
const CARROTS = 141, CARROT_BLOCK = 141;
const POTATOES = 142, POTATO_BLOCK = 142;
const WOODEN_BUTTON = 143;
const MOB_HEAD_BLOCK = 144, SKULL_BLOCK = 144;
const ANVIL = 145;
const TRAPPED_CHEST = 146;
const LIGHT_WEIGHTED_PRESSURE_PLATE = 147;
const HEAVY_WEIGHTED_PRESSURE_PLATE = 148;
const COMPARATOR_BLOCK = 149, UNPOWERED_COMPARATOR = 149;
const POWERED_COMPARATOR = 150;
const DAYLIGHT_DETECTOR = 151, DAYLIGHT_SENSOR = 151;
const REDSTONE_BLOCK = 152;
const NETHER_QUARTZ_ORE = 153, QUARTZ_ORE = 153;
const HOPPER_BLOCK = 154;
const QUARTZ_BLOCK = 155;
const QUARTZ_STAIRS = 156;
const DOUBLE_WOODEN_SLAB = 157;
const WOODEN_SLAB = 158;
const STAINED_CLAY = 159, STAINED_HARDENED_CLAY = 159, TERRACOTTA = 159;
const STAINED_GLASS_PANE = 160;
const LEAVES2 = 161;
const LOG2 = 162, WOOD2 = 162;
const ACACIA_STAIRS = 163;
const DARK_OAK_STAIRS = 164;
const SLIME = 165, SLIME_BLOCK = 165;
public const DANDELION = 37, YELLOW_FLOWER = 37;
public const POPPY = 38, RED_FLOWER = 38;
public const BROWN_MUSHROOM = 39;
public const RED_MUSHROOM = 40;
public const GOLD_BLOCK = 41;
public const IRON_BLOCK = 42;
public const DOUBLE_STONE_SLAB = 43;
public const STONE_SLAB = 44;
public const BRICK_BLOCK = 45;
public const TNT = 46;
public const BOOKSHELF = 47;
public const MOSSY_COBBLESTONE = 48, MOSS_STONE = 48;
public const OBSIDIAN = 49;
public const TORCH = 50;
public const FIRE = 51;
public const MOB_SPAWNER = 52, MONSTER_SPAWNER = 52;
public const OAK_STAIRS = 53, WOODEN_STAIRS = 53;
public const CHEST = 54;
public const REDSTONE_WIRE = 55;
public const DIAMOND_ORE = 56;
public const DIAMOND_BLOCK = 57;
public const CRAFTING_TABLE = 58, WORKBENCH = 58;
public const WHEAT_BLOCK = 59;
public const FARMLAND = 60;
public const FURNACE = 61;
public const BURNING_FURNACE = 62, LIT_FURNACE = 62;
public const SIGN_POST = 63, STANDING_SIGN = 63;
public const OAK_DOOR_BLOCK = 64, WOODEN_DOOR_BLOCK = 64;
public const LADDER = 65;
public const RAIL = 66;
public const COBBLESTONE_STAIRS = 67, STONE_STAIRS = 67;
public const WALL_SIGN = 68;
public const LEVER = 69;
public const STONE_PRESSURE_PLATE = 70;
public const IRON_DOOR_BLOCK = 71;
public const WOODEN_PRESSURE_PLATE = 72;
public const REDSTONE_ORE = 73;
public const GLOWING_REDSTONE_ORE = 74, LIT_REDSTONE_ORE = 74;
public const UNLIT_REDSTONE_TORCH = 75;
public const LIT_REDSTONE_TORCH = 76, REDSTONE_TORCH = 76;
public const STONE_BUTTON = 77;
public const SNOW_LAYER = 78;
public const ICE = 79;
public const SNOW = 80, SNOW_BLOCK = 80;
public const CACTUS = 81;
public const CLAY_BLOCK = 82;
public const REEDS_BLOCK = 83, SUGARCANE_BLOCK = 83;
public const JUKEBOX = 84;
public const FENCE = 85;
public const PUMPKIN = 86;
public const NETHERRACK = 87;
public const SOUL_SAND = 88;
public const GLOWSTONE = 89;
public const PORTAL = 90;
public const JACK_O_LANTERN = 91, LIT_PUMPKIN = 91;
public const CAKE_BLOCK = 92;
public const REPEATER_BLOCK = 93, UNPOWERED_REPEATER = 93;
public const POWERED_REPEATER = 94;
public const INVISIBLEBEDROCK = 95, INVISIBLE_BEDROCK = 95;
public const TRAPDOOR = 96, WOODEN_TRAPDOOR = 96;
public const MONSTER_EGG = 97;
public const STONEBRICK = 98, STONE_BRICK = 98, STONE_BRICKS = 98;
public const BROWN_MUSHROOM_BLOCK = 99;
public const RED_MUSHROOM_BLOCK = 100;
public const IRON_BARS = 101;
public const GLASS_PANE = 102;
public const MELON_BLOCK = 103;
public const PUMPKIN_STEM = 104;
public const MELON_STEM = 105;
public const VINE = 106, VINES = 106;
public const FENCE_GATE = 107, OAK_FENCE_GATE = 107;
public const BRICK_STAIRS = 108;
public const STONE_BRICK_STAIRS = 109;
public const MYCELIUM = 110;
public const LILY_PAD = 111, WATERLILY = 111, WATER_LILY = 111;
public const NETHER_BRICK_BLOCK = 112;
public const NETHER_BRICK_FENCE = 113;
public const NETHER_BRICK_STAIRS = 114;
public const NETHER_WART_PLANT = 115;
public const ENCHANTING_TABLE = 116, ENCHANTMENT_TABLE = 116;
public const BREWING_STAND_BLOCK = 117;
public const CAULDRON_BLOCK = 118;
public const END_PORTAL = 119;
public const END_PORTAL_FRAME = 120;
public const END_STONE = 121;
public const DRAGON_EGG = 122;
public const REDSTONE_LAMP = 123;
public const LIT_REDSTONE_LAMP = 124;
public const DROPPER = 125;
public const ACTIVATOR_RAIL = 126;
public const COCOA = 127, COCOA_BLOCK = 127;
public const SANDSTONE_STAIRS = 128;
public const EMERALD_ORE = 129;
public const ENDER_CHEST = 130;
public const TRIPWIRE_HOOK = 131;
public const TRIPWIRE = 132, TRIP_WIRE = 132;
public const EMERALD_BLOCK = 133;
public const SPRUCE_STAIRS = 134;
public const BIRCH_STAIRS = 135;
public const JUNGLE_STAIRS = 136;
public const COMMAND_BLOCK = 137;
public const BEACON = 138;
public const COBBLESTONE_WALL = 139, STONE_WALL = 139;
public const FLOWER_POT_BLOCK = 140;
public const CARROTS = 141, CARROT_BLOCK = 141;
public const POTATOES = 142, POTATO_BLOCK = 142;
public const WOODEN_BUTTON = 143;
public const MOB_HEAD_BLOCK = 144, SKULL_BLOCK = 144;
public const ANVIL = 145;
public const TRAPPED_CHEST = 146;
public const LIGHT_WEIGHTED_PRESSURE_PLATE = 147;
public const HEAVY_WEIGHTED_PRESSURE_PLATE = 148;
public const COMPARATOR_BLOCK = 149, UNPOWERED_COMPARATOR = 149;
public const POWERED_COMPARATOR = 150;
public const DAYLIGHT_DETECTOR = 151, DAYLIGHT_SENSOR = 151;
public const REDSTONE_BLOCK = 152;
public const NETHER_QUARTZ_ORE = 153, QUARTZ_ORE = 153;
public const HOPPER_BLOCK = 154;
public const QUARTZ_BLOCK = 155;
public const QUARTZ_STAIRS = 156;
public const DOUBLE_WOODEN_SLAB = 157;
public const WOODEN_SLAB = 158;
public const STAINED_CLAY = 159, STAINED_HARDENED_CLAY = 159, TERRACOTTA = 159;
public const STAINED_GLASS_PANE = 160;
public const LEAVES2 = 161;
public const LOG2 = 162, WOOD2 = 162;
public const ACACIA_STAIRS = 163;
public const DARK_OAK_STAIRS = 164;
public const SLIME = 165, SLIME_BLOCK = 165;
const IRON_TRAPDOOR = 167;
const PRISMARINE = 168;
const SEALANTERN = 169, SEA_LANTERN = 169;
const HAY_BALE = 170, HAY_BLOCK = 170;
const CARPET = 171;
const HARDENED_CLAY = 172;
const COAL_BLOCK = 173;
const PACKED_ICE = 174;
const DOUBLE_PLANT = 175;
const STANDING_BANNER = 176;
const WALL_BANNER = 177;
const DAYLIGHT_DETECTOR_INVERTED = 178, DAYLIGHT_SENSOR_INVERTED = 178;
const RED_SANDSTONE = 179;
const RED_SANDSTONE_STAIRS = 180;
const DOUBLE_STONE_SLAB2 = 181;
const STONE_SLAB2 = 182;
const SPRUCE_FENCE_GATE = 183;
const BIRCH_FENCE_GATE = 184;
const JUNGLE_FENCE_GATE = 185;
const DARK_OAK_FENCE_GATE = 186;
const ACACIA_FENCE_GATE = 187;
const REPEATING_COMMAND_BLOCK = 188;
const CHAIN_COMMAND_BLOCK = 189;
public const IRON_TRAPDOOR = 167;
public const PRISMARINE = 168;
public const SEALANTERN = 169, SEA_LANTERN = 169;
public const HAY_BALE = 170, HAY_BLOCK = 170;
public const CARPET = 171;
public const HARDENED_CLAY = 172;
public const COAL_BLOCK = 173;
public const PACKED_ICE = 174;
public const DOUBLE_PLANT = 175;
public const STANDING_BANNER = 176;
public const WALL_BANNER = 177;
public const DAYLIGHT_DETECTOR_INVERTED = 178, DAYLIGHT_SENSOR_INVERTED = 178;
public const RED_SANDSTONE = 179;
public const RED_SANDSTONE_STAIRS = 180;
public const DOUBLE_STONE_SLAB2 = 181;
public const STONE_SLAB2 = 182;
public const SPRUCE_FENCE_GATE = 183;
public const BIRCH_FENCE_GATE = 184;
public const JUNGLE_FENCE_GATE = 185;
public const DARK_OAK_FENCE_GATE = 186;
public const ACACIA_FENCE_GATE = 187;
public const REPEATING_COMMAND_BLOCK = 188;
public const CHAIN_COMMAND_BLOCK = 189;
const SPRUCE_DOOR_BLOCK = 193;
const BIRCH_DOOR_BLOCK = 194;
const JUNGLE_DOOR_BLOCK = 195;
const ACACIA_DOOR_BLOCK = 196;
const DARK_OAK_DOOR_BLOCK = 197;
const GRASS_PATH = 198;
const FRAME_BLOCK = 199, ITEM_FRAME_BLOCK = 199;
const CHORUS_FLOWER = 200;
const PURPUR_BLOCK = 201;
public const SPRUCE_DOOR_BLOCK = 193;
public const BIRCH_DOOR_BLOCK = 194;
public const JUNGLE_DOOR_BLOCK = 195;
public const ACACIA_DOOR_BLOCK = 196;
public const DARK_OAK_DOOR_BLOCK = 197;
public const GRASS_PATH = 198;
public const FRAME_BLOCK = 199, ITEM_FRAME_BLOCK = 199;
public const CHORUS_FLOWER = 200;
public const PURPUR_BLOCK = 201;
const PURPUR_STAIRS = 203;
public const PURPUR_STAIRS = 203;
const UNDYED_SHULKER_BOX = 205;
const END_BRICKS = 206;
const FROSTED_ICE = 207;
const END_ROD = 208;
const END_GATEWAY = 209;
public const UNDYED_SHULKER_BOX = 205;
public const END_BRICKS = 206;
public const FROSTED_ICE = 207;
public const END_ROD = 208;
public const END_GATEWAY = 209;
const MAGMA = 213;
const NETHER_WART_BLOCK = 214;
const RED_NETHER_BRICK = 215;
const BONE_BLOCK = 216;
public const MAGMA = 213;
public const NETHER_WART_BLOCK = 214;
public const RED_NETHER_BRICK = 215;
public const BONE_BLOCK = 216;
const SHULKER_BOX = 218;
const PURPLE_GLAZED_TERRACOTTA = 219;
const WHITE_GLAZED_TERRACOTTA = 220;
const ORANGE_GLAZED_TERRACOTTA = 221;
const MAGENTA_GLAZED_TERRACOTTA = 222;
const LIGHT_BLUE_GLAZED_TERRACOTTA = 223;
const YELLOW_GLAZED_TERRACOTTA = 224;
const LIME_GLAZED_TERRACOTTA = 225;
const PINK_GLAZED_TERRACOTTA = 226;
const GRAY_GLAZED_TERRACOTTA = 227;
const SILVER_GLAZED_TERRACOTTA = 228;
const CYAN_GLAZED_TERRACOTTA = 229;
public const SHULKER_BOX = 218;
public const PURPLE_GLAZED_TERRACOTTA = 219;
public const WHITE_GLAZED_TERRACOTTA = 220;
public const ORANGE_GLAZED_TERRACOTTA = 221;
public const MAGENTA_GLAZED_TERRACOTTA = 222;
public const LIGHT_BLUE_GLAZED_TERRACOTTA = 223;
public const YELLOW_GLAZED_TERRACOTTA = 224;
public const LIME_GLAZED_TERRACOTTA = 225;
public const PINK_GLAZED_TERRACOTTA = 226;
public const GRAY_GLAZED_TERRACOTTA = 227;
public const SILVER_GLAZED_TERRACOTTA = 228;
public const CYAN_GLAZED_TERRACOTTA = 229;
const BLUE_GLAZED_TERRACOTTA = 231;
const BROWN_GLAZED_TERRACOTTA = 232;
const GREEN_GLAZED_TERRACOTTA = 233;
const RED_GLAZED_TERRACOTTA = 234;
const BLACK_GLAZED_TERRACOTTA = 235;
const CONCRETE = 236;
const CONCRETEPOWDER = 237, CONCRETE_POWDER = 237;
public const BLUE_GLAZED_TERRACOTTA = 231;
public const BROWN_GLAZED_TERRACOTTA = 232;
public const GREEN_GLAZED_TERRACOTTA = 233;
public const RED_GLAZED_TERRACOTTA = 234;
public const BLACK_GLAZED_TERRACOTTA = 235;
public const CONCRETE = 236;
public const CONCRETEPOWDER = 237, CONCRETE_POWDER = 237;
const CHORUS_PLANT = 240;
const STAINED_GLASS = 241;
public const CHORUS_PLANT = 240;
public const STAINED_GLASS = 241;
const PODZOL = 243;
const BEETROOT_BLOCK = 244;
const STONECUTTER = 245;
const GLOWINGOBSIDIAN = 246, GLOWING_OBSIDIAN = 246;
const NETHERREACTOR = 247, NETHER_REACTOR = 247;
const INFO_UPDATE = 248;
const INFO_UPDATE2 = 249;
const MOVINGBLOCK = 250, MOVING_BLOCK = 250;
const OBSERVER = 251;
const STRUCTURE_BLOCK = 252;
public const PODZOL = 243;
public const BEETROOT_BLOCK = 244;
public const STONECUTTER = 245;
public const GLOWINGOBSIDIAN = 246, GLOWING_OBSIDIAN = 246;
public const NETHERREACTOR = 247, NETHER_REACTOR = 247;
public const INFO_UPDATE = 248;
public const INFO_UPDATE2 = 249;
public const MOVINGBLOCK = 250, MOVING_BLOCK = 250;
public const OBSERVER = 251;
public const STRUCTURE_BLOCK = 252;
const RESERVED6 = 255;
public const RESERVED6 = 255;
}

View File

@ -21,21 +21,19 @@
declare(strict_types=1);
namespace pocketmine\block;
/**
* Math related classes, like matrices, bounding boxes and vector
* Types of tools that can be used to break blocks
* Blocks may allow multiple tool types by combining these bitflags
*/
namespace pocketmine\math;
interface BlockToolType{
public const TYPE_NONE = 0;
public const TYPE_SWORD = 1 << 0;
public const TYPE_SHOVEL = 1 << 1;
public const TYPE_PICKAXE = 1 << 2;
public const TYPE_AXE = 1 << 3;
public const TYPE_SHEARS = 1 << 4;
abstract class Math{
public static function floorFloat($n) : int{
$i = (int) $n;
return $n >= $i ? $i : $i - 1;
}
public static function ceilFloat($n) : int{
$i = (int) ($n + 1);
return $n >= $i ? $i : $i - 1;
}
}
}

View File

@ -25,7 +25,7 @@ namespace pocketmine\block;
use pocketmine\block\utils\PillarRotationHelper;
use pocketmine\item\Item;
use pocketmine\item\Tool;
use pocketmine\item\TieredTool;
use pocketmine\math\Vector3;
use pocketmine\Player;
@ -46,10 +46,14 @@ class BoneBlock extends Solid{
}
public function getToolType() : int{
return Tool::TYPE_PICKAXE;
return BlockToolType::TYPE_PICKAXE;
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function getToolHarvestLevel() : int{
return TieredTool::TIER_WOODEN;
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$this->meta = PillarRotationHelper::getMetaFromFace($this->meta, $face);
return $this->getLevel()->setBlock($blockReplace, $this, true, true);
}
@ -57,13 +61,4 @@ class BoneBlock extends Solid{
public function getVariantBitmask() : int{
return 0x03;
}
public function getDrops(Item $item) : array{
if($item->isPickaxe() >= Tool::TIER_WOODEN){
return parent::getDrops($item);
}
return [];
}
}
}

View File

@ -25,7 +25,6 @@ namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\Tool;
class Bookshelf extends Solid{
@ -44,10 +43,10 @@ class Bookshelf extends Solid{
}
public function getToolType() : int{
return Tool::TYPE_AXE;
return BlockToolType::TYPE_AXE;
}
public function getDrops(Item $item) : array{
public function getDropsForCompatibleTool(Item $item) : array{
return [
ItemFactory::get(Item::BOOK, 0, 3)
];
@ -57,4 +56,11 @@ class Bookshelf extends Solid{
return 300;
}
}
public function getFlameEncouragement() : int{
return 30;
}
public function getFlammability() : int{
return 20;
}
}

View File

@ -23,7 +23,7 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Tool;
use pocketmine\item\TieredTool;
class BrewingStand extends Transparent{
@ -42,7 +42,11 @@ class BrewingStand extends Transparent{
}
public function getToolType() : int{
return Tool::TYPE_PICKAXE;
return BlockToolType::TYPE_PICKAXE;
}
public function getToolHarvestLevel() : int{
return TieredTool::TIER_WOODEN;
}
public function getVariantBitmask() : int{
@ -50,4 +54,4 @@ class BrewingStand extends Transparent{
}
//TODO
}
}

View File

@ -23,7 +23,7 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Tool;
use pocketmine\item\TieredTool;
class BrickStairs extends Stair{
@ -42,11 +42,14 @@ class BrickStairs extends Stair{
}
public function getToolType() : int{
return Tool::TYPE_PICKAXE;
return BlockToolType::TYPE_PICKAXE;
}
public function getToolHarvestLevel() : int{
return TieredTool::TIER_WOODEN;
}
public function getName() : string{
return "Brick Stairs";
}
}
}

View File

@ -23,8 +23,7 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\Tool;
use pocketmine\item\TieredTool;
class Bricks extends Solid{
@ -43,18 +42,14 @@ class Bricks extends Solid{
}
public function getToolType() : int{
return Tool::TYPE_PICKAXE;
return BlockToolType::TYPE_PICKAXE;
}
public function getToolHarvestLevel() : int{
return TieredTool::TIER_WOODEN;
}
public function getName() : string{
return "Bricks";
}
public function getDrops(Item $item) : array{
if($item->isPickaxe() >= Tool::TIER_WOODEN){
return parent::getDrops($item);
}
return [];
}
}
}

View File

@ -34,4 +34,4 @@ class BrownMushroom extends RedMushroom{
public function getLightLevel() : int{
return 1;
}
}
}

View File

@ -33,9 +33,9 @@ class BrownMushroomBlock extends RedMushroomBlock{
return "Brown Mushroom Block";
}
public function getDrops(Item $item) : array{
public function getDropsForCompatibleTool(Item $item) : array{
return [
Item::get(Item::BROWN_MUSHROOM, 0, mt_rand(0, 2))
];
}
}
}

View File

@ -24,13 +24,8 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\Tool;
use pocketmine\item\TieredTool;
use pocketmine\math\Vector3;
use pocketmine\nbt\NBT;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\IntTag;
use pocketmine\nbt\tag\ListTag;
use pocketmine\nbt\tag\StringTag;
use pocketmine\Player;
use pocketmine\tile\Furnace as TileFurnace;
use pocketmine\tile\Tile;
@ -39,6 +34,8 @@ class BurningFurnace extends Solid{
protected $id = self::BURNING_FURNACE;
protected $itemId = self::FURNACE;
public function __construct(int $meta = 0){
$this->meta = $meta;
}
@ -52,14 +49,18 @@ class BurningFurnace extends Solid{
}
public function getToolType() : int{
return Tool::TYPE_PICKAXE;
return BlockToolType::TYPE_PICKAXE;
}
public function getToolHarvestLevel() : int{
return TieredTool::TIER_WOODEN;
}
public function getLightLevel() : int{
return 13;
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$faces = [
0 => 4,
1 => 2,
@ -68,26 +69,8 @@ class BurningFurnace extends Solid{
];
$this->meta = $faces[$player instanceof Player ? $player->getDirection() : 0];
$this->getLevel()->setBlock($blockReplace, $this, true, true);
$nbt = new CompoundTag("", [
new ListTag("Items", []),
new StringTag("id", Tile::FURNACE),
new IntTag("x", $this->x),
new IntTag("y", $this->y),
new IntTag("z", $this->z)
]);
$nbt->Items->setTagType(NBT::TAG_Compound);
if($item->hasCustomName()){
$nbt->CustomName = new StringTag("CustomName", $item->getCustomName());
}
if($item->hasCustomBlockData()){
foreach($item->getCustomBlockData() as $key => $v){
$nbt->{$key} = $v;
}
}
Tile::createTile("Furnace", $this->getLevel(), $nbt);
Tile::createTile(Tile::FURNACE, $this->getLevel(), TileFurnace::createNBT($this, $face, $item, $player));
return true;
}
@ -96,21 +79,11 @@ class BurningFurnace extends Solid{
if($player instanceof Player){
$furnace = $this->getLevel()->getTile($this);
if(!($furnace instanceof TileFurnace)){
$nbt = new CompoundTag("", [
new ListTag("Items", []),
new StringTag("id", Tile::FURNACE),
new IntTag("x", $this->x),
new IntTag("y", $this->y),
new IntTag("z", $this->z)
]);
$nbt->Items->setTagType(NBT::TAG_Compound);
$furnace = Tile::createTile("Furnace", $this->getLevel(), $nbt);
$furnace = Tile::createTile(Tile::FURNACE, $this->getLevel(), TileFurnace::createNBT($this));
}
if(isset($furnace->namedtag->Lock) and $furnace->namedtag->Lock instanceof StringTag){
if($furnace->namedtag->Lock->getValue() !== $item->getCustomName()){
return true;
}
if(!$furnace->canOpenWith($item->getCustomName())){
return true;
}
$player->addWindow($furnace->getInventory());
@ -122,12 +95,4 @@ class BurningFurnace extends Solid{
public function getVariantBitmask() : int{
return 0;
}
public function getDrops(Item $item) : array{
if($item->isPickaxe() >= Tool::TIER_WOODEN){
return parent::getDrops($item);
}
return [];
}
}
}

View File

@ -0,0 +1,51 @@
<?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/
*
*
*/
declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\math\Vector3;
use pocketmine\Player;
abstract class Button extends Flowable{
public function __construct(int $meta = 0){
$this->meta = $meta;
}
public function getVariantBitmask() : int{
return 0;
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
//TODO: check valid target block
$this->meta = $face;
return $this->level->setBlock($this, $this, true, true);
}
public function onActivate(Item $item, Player $player = null) : bool{
//TODO
return true;
}
}

View File

@ -28,7 +28,6 @@ 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\AxisAlignedBB;
use pocketmine\math\Vector3;
use pocketmine\Player;
@ -54,7 +53,7 @@ class Cactus extends Transparent{
return "Cactus";
}
protected function recalculateBoundingBox(){
protected function recalculateBoundingBox() : ?AxisAlignedBB{
return new AxisAlignedBB(
$this->x + 0.0625,
@ -66,60 +65,59 @@ class Cactus extends Transparent{
);
}
public function ticksRandomly() : bool{
return true;
}
public function onEntityCollide(Entity $entity){
public function onEntityCollide(Entity $entity) : void{
$ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_CONTACT, 1);
$entity->attack($ev);
}
public function onUpdate(int $type){
if($type === Level::BLOCK_UPDATE_NORMAL){
$down = $this->getSide(Vector3::SIDE_DOWN);
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->canBeFlowedInto()){
$this->getLevel()->useBreakOn($this);
}
}
}
}elseif($type === Level::BLOCK_UPDATE_RANDOM){
if($this->getSide(Vector3::SIDE_DOWN)->getId() !== self::CACTUS){
if($this->meta === 0x0f){
for($y = 1; $y < 3; ++$y){
$b = $this->getLevel()->getBlock(new Vector3($this->x, $this->y + $y, $this->z));
if($b->getId() === self::AIR){
Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($b, BlockFactory::get(Block::CACTUS)));
if(!$ev->isCancelled()){
$this->getLevel()->setBlock($b, $ev->getNewState(), true);
}
}
}
$this->meta = 0;
$this->getLevel()->setBlock($this, $this);
}else{
++$this->meta;
$this->getLevel()->setBlock($this, $this);
public function onNearbyBlockChange() : void{
$down = $this->getSide(Vector3::SIDE_DOWN);
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->isSolid()){
$this->getLevel()->useBreakOn($this);
break;
}
}
}
return false;
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function ticksRandomly() : bool{
return true;
}
public function onRandomTick() : void{
if($this->getSide(Vector3::SIDE_DOWN)->getId() !== self::CACTUS){
if($this->meta === 0x0f){
for($y = 1; $y < 3; ++$y){
$b = $this->getLevel()->getBlockAt($this->x, $this->y + $y, $this->z);
if($b->getId() === self::AIR){
Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($b, BlockFactory::get(Block::CACTUS)));
if(!$ev->isCancelled()){
$this->getLevel()->setBlock($b, $ev->getNewState(), true);
}
}
}
$this->meta = 0;
$this->getLevel()->setBlock($this, $this);
}else{
++$this->meta;
$this->getLevel()->setBlock($this, $this);
}
}
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$down = $this->getSide(Vector3::SIDE_DOWN);
if($down->getId() === self::SAND or $down->getId() === self::CACTUS){
$block0 = $this->getSide(Vector3::SIDE_NORTH);
$block1 = $this->getSide(Vector3::SIDE_SOUTH);
$block2 = $this->getSide(Vector3::SIDE_WEST);
$block3 = $this->getSide(Vector3::SIDE_EAST);
if($block0->isTransparent() === true and $block1->isTransparent() === true and $block2->isTransparent() === true and $block3->isTransparent() === true){
if(!$block0->isSolid() and !$block1->isSolid() and !$block2->isSolid() and !$block3->isSolid()){
$this->getLevel()->setBlock($this, $this, true);
return true;
@ -132,4 +130,4 @@ class Cactus extends Transparent{
public function getVariantBitmask() : int{
return 0;
}
}
}

View File

@ -23,11 +23,10 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\entity\Effect;
use pocketmine\event\entity\EntityEatBlockEvent;
use pocketmine\entity\EffectInstance;
use pocketmine\entity\Living;
use pocketmine\item\FoodSource;
use pocketmine\item\Item;
use pocketmine\level\Level;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Vector3;
use pocketmine\Player;
@ -45,10 +44,10 @@ class Cake extends Transparent implements FoodSource{
}
public function getName() : string{
return "Cake Block";
return "Cake";
}
protected function recalculateBoundingBox(){
protected function recalculateBoundingBox() : ?AxisAlignedBB{
$f = $this->getDamage() * 0.125; //1 slice width
@ -62,7 +61,7 @@ class Cake extends Transparent implements FoodSource{
);
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$down = $this->getSide(Vector3::SIDE_DOWN);
if($down->getId() !== self::AIR){
$this->getLevel()->setBlock($blockReplace, $this, true, true);
@ -73,37 +72,24 @@ class Cake extends Transparent implements FoodSource{
return false;
}
public function onUpdate(int $type){
if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(Vector3::SIDE_DOWN)->getId() === self::AIR){ //Replace with common break method
$this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), true);
return Level::BLOCK_UPDATE_NORMAL;
}
public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_DOWN)->getId() === self::AIR){ //Replace with common break method
$this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), true);
}
return false;
}
public function getDrops(Item $item) : array{
public function getDropsForCompatibleTool(Item $item) : array{
return [];
}
public function isAffectedBySilkTouch() : bool{
return false;
}
public function onActivate(Item $item, Player $player = null) : bool{
//TODO: refactor this into generic food handling
if($player instanceof Player and $player->getFood() < $player->getMaxFood()){
$player->getServer()->getPluginManager()->callEvent($ev = new EntityEatBlockEvent($player, $this));
if(!$ev->isCancelled()){
$player->addFood($ev->getFoodRestore());
$player->addSaturation($ev->getSaturationRestore());
foreach($ev->getAdditionalEffects() as $effect){
$player->addEffect($effect);
}
$this->getLevel()->setBlock($this, $ev->getResidue());
return true;
}
if($player !== null){
$player->consumeObject($this);
return true;
}
return false;
@ -117,6 +103,13 @@ class Cake extends Transparent implements FoodSource{
return 0.4;
}
public function requiresHunger() : bool{
return true;
}
/**
* @return Block
*/
public function getResidue(){
$clone = clone $this;
$clone->meta++;
@ -127,9 +120,13 @@ class Cake extends Transparent implements FoodSource{
}
/**
* @return Effect[]
* @return EffectInstance[]
*/
public function getAdditionalEffects() : array{
return [];
}
public function onConsume(Living $consumer) : void{
$this->level->setBlock($this, $this->getResidue());
}
}

View File

@ -25,7 +25,6 @@ namespace pocketmine\block;
use pocketmine\block\utils\ColorBlockMetaHelper;
use pocketmine\item\Item;
use pocketmine\level\Level;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Vector3;
use pocketmine\Player;
@ -50,7 +49,7 @@ class Carpet extends Flowable{
return ColorBlockMetaHelper::getColorFromMeta($this->meta) . " Carpet";
}
protected function recalculateBoundingBox(){
protected function recalculateBoundingBox() : ?AxisAlignedBB{
return new AxisAlignedBB(
$this->x,
@ -62,7 +61,7 @@ class Carpet extends Flowable{
);
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$down = $this->getSide(Vector3::SIDE_DOWN);
if($down->getId() !== self::AIR){
$this->getLevel()->setBlock($blockReplace, $this, true, true);
@ -73,16 +72,17 @@ class Carpet extends Flowable{
return false;
}
public function onUpdate(int $type){
if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(Vector3::SIDE_DOWN)->getId() === self::AIR){
$this->getLevel()->useBreakOn($this);
return Level::BLOCK_UPDATE_NORMAL;
}
public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_DOWN)->getId() === self::AIR){
$this->getLevel()->useBreakOn($this);
}
return false;
}
}
public function getFlameEncouragement() : int{
return 30;
}
public function getFlammability() : int{
return 20;
}
}

View File

@ -38,9 +38,13 @@ class Carrot extends Crops{
return "Carrot Block";
}
public function getDrops(Item $item) : array{
public function getDropsForCompatibleTool(Item $item) : array{
return [
ItemFactory::get(Item::CARROT, 0, $this->meta >= 0x07 ? mt_rand(1, 4) : 1)
];
}
}
public function getPickedItem() : Item{
return ItemFactory::get(Item::CARROT);
}
}

View File

@ -24,14 +24,8 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\Tool;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Vector3;
use pocketmine\nbt\NBT;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\IntTag;
use pocketmine\nbt\tag\ListTag;
use pocketmine\nbt\tag\StringTag;
use pocketmine\Player;
use pocketmine\tile\Chest as TileChest;
use pocketmine\tile\Tile;
@ -53,21 +47,22 @@ class Chest extends Transparent{
}
public function getToolType() : int{
return Tool::TYPE_AXE;
return BlockToolType::TYPE_AXE;
}
protected function recalculateBoundingBox(){
protected function recalculateBoundingBox() : ?AxisAlignedBB{
//these are slightly bigger than in PC
return new AxisAlignedBB(
$this->x + 0.0625,
$this->x + 0.025,
$this->y,
$this->z + 0.0625,
$this->x + 0.9375,
$this->y + 0.9475,
$this->z + 0.9375
$this->z + 0.025,
$this->x + 0.975,
$this->y + 0.95,
$this->z + 0.975
);
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$faces = [
0 => 4,
1 => 2,
@ -95,26 +90,7 @@ class Chest extends Transparent{
}
$this->getLevel()->setBlock($blockReplace, $this, true, true);
$nbt = new CompoundTag("", [
new ListTag("Items", []),
new StringTag("id", Tile::CHEST),
new IntTag("x", $this->x),
new IntTag("y", $this->y),
new IntTag("z", $this->z)
]);
$nbt->Items->setTagType(NBT::TAG_Compound);
if($item->hasCustomName()){
$nbt->CustomName = new StringTag("CustomName", $item->getCustomName());
}
if($item->hasCustomBlockData()){
foreach($item->getCustomBlockData() as $key => $v){
$nbt->{$key} = $v;
}
}
$tile = Tile::createTile("Chest", $this->getLevel(), $nbt);
$tile = Tile::createTile(Tile::CHEST, $this->getLevel(), TileChest::createNBT($this, $face, $item, $player));
if($chest instanceof TileChest and $tile instanceof TileChest){
$chest->pairWith($tile);
@ -124,16 +100,6 @@ class Chest extends Transparent{
return true;
}
public function onBreak(Item $item, Player $player = null) : bool{
$t = $this->getLevel()->getTile($this);
if($t instanceof TileChest){
$t->unpair();
}
$this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), true, true);
return true;
}
public function onActivate(Item $item, Player $player = null) : bool{
if($player instanceof Player){
@ -142,21 +108,13 @@ class Chest extends Transparent{
if($t instanceof TileChest){
$chest = $t;
}else{
$nbt = new CompoundTag("", [
new ListTag("Items", []),
new StringTag("id", Tile::CHEST),
new IntTag("x", $this->x),
new IntTag("y", $this->y),
new IntTag("z", $this->z)
]);
$nbt->Items->setTagType(NBT::TAG_Compound);
$chest = Tile::createTile("Chest", $this->getLevel(), $nbt);
$chest = Tile::createTile(Tile::CHEST, $this->getLevel(), TileChest::createNBT($this));
}
if(
!$this->getSide(Vector3::SIDE_UP)->isTransparent() or
($chest->isPaired() and !$chest->getPair()->getBlock()->getSide(Vector3::SIDE_UP)->isTransparent()) or
(isset($chest->namedtag->Lock) and $chest->namedtag->Lock instanceof StringTag and $chest->namedtag->Lock->getValue() !== $item->getCustomName())
!$chest->canOpenWith($item->getCustomName())
){
return true;
}
@ -174,4 +132,4 @@ class Chest extends Transparent{
public function getFuelTime() : int{
return 300;
}
}
}

View File

@ -25,7 +25,6 @@ namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\Tool;
class Clay extends Solid{
@ -40,16 +39,16 @@ class Clay extends Solid{
}
public function getToolType() : int{
return Tool::TYPE_SHOVEL;
return BlockToolType::TYPE_SHOVEL;
}
public function getName() : string{
return "Clay Block";
}
public function getDrops(Item $item) : array{
public function getDropsForCompatibleTool(Item $item) : array{
return [
ItemFactory::get(Item::CLAY_BALL, 0, 4)
];
}
}
}

View File

@ -23,8 +23,7 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\Tool;
use pocketmine\item\TieredTool;
class Coal extends Solid{
@ -39,22 +38,26 @@ class Coal extends Solid{
}
public function getToolType() : int{
return Tool::TYPE_PICKAXE;
return BlockToolType::TYPE_PICKAXE;
}
public function getToolHarvestLevel() : int{
return TieredTool::TIER_WOODEN;
}
public function getName() : string{
return "Coal Block";
}
public function getDrops(Item $item) : array{
if($item->isPickaxe() >= Tool::TIER_WOODEN){
return parent::getDrops($item);
}
return [];
}
public function getFuelTime() : int{
return 16000;
}
}
public function getFlameEncouragement() : int{
return 5;
}
public function getFlammability() : int{
return 5;
}
}

View File

@ -25,7 +25,7 @@ namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\Tool;
use pocketmine\item\TieredTool;
class CoalOre extends Solid{
@ -40,21 +40,24 @@ class CoalOre extends Solid{
}
public function getToolType() : int{
return Tool::TYPE_PICKAXE;
return BlockToolType::TYPE_PICKAXE;
}
public function getToolHarvestLevel() : int{
return TieredTool::TIER_WOODEN;
}
public function getName() : string{
return "Coal Ore";
}
public function getDrops(Item $item) : array{
if($item->isPickaxe() >= Tool::TIER_WOODEN){
return [
ItemFactory::get(Item::COAL, 0, 1)
];
}
return [];
public function getDropsForCompatibleTool(Item $item) : array{
return [
ItemFactory::get(Item::COAL)
];
}
}
protected function getXpDropAmount() : int{
return mt_rand(0, 2);
}
}

View File

@ -23,8 +23,7 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\Tool;
use pocketmine\item\TieredTool;
class Cobblestone extends Solid{
@ -35,7 +34,11 @@ class Cobblestone extends Solid{
}
public function getToolType() : int{
return Tool::TYPE_PICKAXE;
return BlockToolType::TYPE_PICKAXE;
}
public function getToolHarvestLevel() : int{
return TieredTool::TIER_WOODEN;
}
public function getName() : string{
@ -45,12 +48,4 @@ class Cobblestone extends Solid{
public function getHardness() : float{
return 2;
}
public function getDrops(Item $item) : array{
if($item->isPickaxe() >= Tool::TIER_WOODEN){
return parent::getDrops($item);
}
return [];
}
}
}

View File

@ -23,7 +23,7 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Tool;
use pocketmine\item\TieredTool;
class CobblestoneStairs extends Stair{
@ -38,11 +38,14 @@ class CobblestoneStairs extends Stair{
}
public function getToolType() : int{
return Tool::TYPE_PICKAXE;
return BlockToolType::TYPE_PICKAXE;
}
public function getToolHarvestLevel() : int{
return TieredTool::TIER_WOODEN;
}
public function getName() : string{
return "Cobblestone Stairs";
}
}
}

View File

@ -23,13 +23,13 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Tool;
use pocketmine\item\TieredTool;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Vector3;
class CobblestoneWall extends Transparent{
const NONE_MOSSY_WALL = 0;
const MOSSY_WALL = 1;
public const NONE_MOSSY_WALL = 0;
public const MOSSY_WALL = 1;
protected $id = self::COBBLESTONE_WALL;
@ -37,12 +37,12 @@ class CobblestoneWall extends Transparent{
$this->meta = $meta;
}
public function isSolid() : bool{
return false;
public function getToolType() : int{
return BlockToolType::TYPE_PICKAXE;
}
public function getToolType() : int{
return Tool::TYPE_PICKAXE;
public function getToolHarvestLevel() : int{
return TieredTool::TIER_WOODEN;
}
public function getHardness() : float{
@ -57,38 +57,37 @@ class CobblestoneWall extends Transparent{
return "Cobblestone Wall";
}
protected function recalculateBoundingBox(){
protected function recalculateBoundingBox() : ?AxisAlignedBB{
//walls don't have any special collision boxes like fences do
$north = $this->canConnect($this->getSide(Vector3::SIDE_NORTH));
$south = $this->canConnect($this->getSide(Vector3::SIDE_SOUTH));
$west = $this->canConnect($this->getSide(Vector3::SIDE_WEST));
$east = $this->canConnect($this->getSide(Vector3::SIDE_EAST));
$n = $north ? 0 : 0.25;
$s = $south ? 1 : 0.75;
$w = $west ? 0 : 0.25;
$e = $east ? 1 : 0.75;
if($north and $south and !$west and !$east){
$w = 0.3125;
$e = 0.6875;
}elseif(!$north and !$south and $west and $east){
$n = 0.3125;
$s = 0.6875;
$inset = 0.25;
if(
$this->getSide(Vector3::SIDE_UP)->getId() === Block::AIR and //if there is a block on top, it stays as a post
(
($north and $south and !$west and !$east) or
(!$north and !$south and $west and $east)
)
){
//If connected to two sides on the same axis but not any others, AND there is not a block on top, there is no post and the wall is thinner
$inset = 0.3125;
}
return new AxisAlignedBB(
$this->x + $w,
$this->x + ($west ? 0 : $inset),
$this->y,
$this->z + $n,
$this->x + $e,
$this->z + ($north ? 0 : $inset),
$this->x + 1 - ($east ? 0 : $inset),
$this->y + 1.5,
$this->z + $s
$this->z + 1 - ($south ? 0 : $inset)
);
}
public function canConnect(Block $block){
return ($block->getId() !== self::COBBLESTONE_WALL and $block->getId() !== self::FENCE_GATE) ? $block->isSolid() and !$block->isTransparent() : true;
return $block instanceof static or $block instanceof FenceGate or ($block->isSolid() and !$block->isTransparent());
}
}

View File

@ -25,7 +25,7 @@ namespace pocketmine\block;
use pocketmine\entity\Entity;
use pocketmine\item\Item;
use pocketmine\item\Tool;
use pocketmine\item\ItemFactory;
class Cobweb extends Flowable{
@ -48,19 +48,24 @@ class Cobweb extends Flowable{
}
public function getToolType() : int{
return Tool::TYPE_SWORD;
return BlockToolType::TYPE_SWORD | BlockToolType::TYPE_SHEARS;
}
public function onEntityCollide(Entity $entity){
public function getToolHarvestLevel() : int{
return 1;
}
public function onEntityCollide(Entity $entity) : void{
$entity->resetFallDistance();
}
public function getDrops(Item $item) : array{
//TODO: correct drops
return [];
public function getDropsForCompatibleTool(Item $item) : array{
return [
ItemFactory::get(Item::STRING)
];
}
public function diffusesSkyLight() : bool{
return true;
}
}
}

View File

@ -23,7 +23,7 @@ declare(strict_types=1);
namespace pocketmine\block;
class CocoaBlock extends Solid{
class CocoaBlock extends Transparent{
protected $id = self::COCOA_BLOCK;
@ -35,5 +35,17 @@ class CocoaBlock extends Solid{
return "Cocoa Block";
}
public function getHardness() : float{
return 0.2;
}
public function getToolType() : int{
return BlockToolType::TYPE_AXE;
}
//TODO
public function isAffectedBySilkTouch() : bool{
return false;
}
}

View File

@ -24,8 +24,7 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\block\utils\ColorBlockMetaHelper;
use pocketmine\item\Item;
use pocketmine\item\Tool;
use pocketmine\item\TieredTool;
class Concrete extends Solid{
@ -44,15 +43,10 @@ class Concrete extends Solid{
}
public function getToolType() : int{
return Tool::TYPE_PICKAXE;
return BlockToolType::TYPE_PICKAXE;
}
public function getDrops(Item $item) : array{
if($item->isPickaxe() >= Tool::TIER_WOODEN){
return parent::getDrops($item);
}
return [];
public function getToolHarvestLevel() : int{
return TieredTool::TIER_WOODEN;
}
}
}

View File

@ -0,0 +1,75 @@
<?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/
*
*
*/
declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\block\utils\ColorBlockMetaHelper;
class ConcretePowder extends Fallable{
protected $id = self::CONCRETE_POWDER;
public function __construct(int $meta = 0){
$this->meta = $meta;
}
public function getName() : string{
return ColorBlockMetaHelper::getColorFromMeta($this->meta) . " Concrete Powder";
}
public function getHardness() : float{
return 0.5;
}
public function getToolType() : int{
return BlockToolType::TYPE_SHOVEL;
}
public function onNearbyBlockChange() : void{
if(($block = $this->checkAdjacentWater()) !== null){
$this->level->setBlock($this, $block);
}else{
parent::onNearbyBlockChange();
}
}
/**
* @return null|Block
*/
public function tickFalling() : ?Block{
return $this->checkAdjacentWater();
}
/**
* @return null|Block
*/
private function checkAdjacentWater() : ?Block{
for($i = 1; $i < 6; ++$i){ //Do not check underneath
if($this->getSide($i) instanceof Water){
return BlockFactory::get(Block::CONCRETE, $this->meta);
}
}
return null;
}
}

View File

@ -23,9 +23,8 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\inventory\BigCraftingGrid;
use pocketmine\inventory\CraftingGrid;
use pocketmine\item\Item;
use pocketmine\item\Tool;
use pocketmine\Player;
class CraftingTable extends Solid{
@ -45,13 +44,12 @@ class CraftingTable extends Solid{
}
public function getToolType() : int{
return Tool::TYPE_AXE;
return BlockToolType::TYPE_AXE;
}
public function onActivate(Item $item, Player $player = null) : bool{
if($player instanceof Player){
$player->setCraftingGrid(new BigCraftingGrid($player));
$player->craftingType = 1;
$player->setCraftingGrid(new CraftingGrid($player, CraftingGrid::SIZE_BIG));
}
return true;
@ -60,4 +58,4 @@ class CraftingTable extends Solid{
public function getFuelTime() : int{
return 300;
}
}
}

View File

@ -25,14 +25,13 @@ namespace pocketmine\block;
use pocketmine\event\block\BlockGrowEvent;
use pocketmine\item\Item;
use pocketmine\level\Level;
use pocketmine\math\Vector3;
use pocketmine\Player;
use pocketmine\Server;
abstract class Crops extends Flowable{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
if($blockReplace->getSide(Vector3::SIDE_DOWN)->getId() === Block::FARMLAND){
$this->getLevel()->setBlock($blockReplace, $this, true, true);
@ -65,34 +64,31 @@ abstract class Crops extends Flowable{
return false;
}
public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_DOWN)->getId() !== Block::FARMLAND){
$this->getLevel()->useBreakOn($this);
}
}
public function ticksRandomly() : bool{
return true;
}
public function onUpdate(int $type){
if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(Vector3::SIDE_DOWN)->getId() !== Block::FARMLAND){
$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));
public function onRandomTick() : void{
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;
}
if(!$ev->isCancelled()){
$this->getLevel()->setBlock($this, $ev->getNewState(), true, true);
}
}else{
return Level::BLOCK_UPDATE_RANDOM;
}
}
}
public function isAffectedBySilkTouch() : bool{
return false;
}
}
}

View File

@ -24,7 +24,6 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\level\Level;
use pocketmine\math\Vector3;
use pocketmine\Player;
@ -41,7 +40,7 @@ class Dandelion extends Flowable{
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$down = $this->getSide(Vector3::SIDE_DOWN);
if($down->getId() === Block::GRASS or $down->getId() === Block::DIRT or $down->getId() === Block::FARMLAND){
$this->getLevel()->setBlock($blockReplace, $this, true, true);
@ -52,15 +51,17 @@ class Dandelion extends Flowable{
return false;
}
public function onUpdate(int $type){
if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(Vector3::SIDE_DOWN)->isTransparent() === true){
$this->getLevel()->useBreakOn($this);
return Level::BLOCK_UPDATE_NORMAL;
}
public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_DOWN)->isTransparent()){
$this->getLevel()->useBreakOn($this);
}
return false;
}
}
public function getFlameEncouragement() : int{
return 60;
}
public function getFlammability() : int{
return 100;
}
}

View File

@ -43,5 +43,9 @@ class DaylightSensor extends Transparent{
return 300;
}
public function getToolType() : int{
return BlockToolType::TYPE_AXE;
}
//TODO
}

View File

@ -23,8 +23,10 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\level\Level;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\math\Vector3;
use pocketmine\Player;
class DeadBush extends Flowable{
@ -38,17 +40,43 @@ class DeadBush extends Flowable{
return "Dead Bush";
}
public function onUpdate(int $type){
if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(Vector3::SIDE_DOWN)->isTransparent() === true){
$this->getLevel()->useBreakOn($this);
return Level::BLOCK_UPDATE_NORMAL;
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
if(!$this->getSide(Vector3::SIDE_DOWN)->isTransparent()){
return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player);
}
return false;
}
}
public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_DOWN)->isTransparent()){
$this->getLevel()->useBreakOn($this);
}
}
public function getToolType() : int{
return BlockToolType::TYPE_SHEARS;
}
public function getToolHarvestLevel() : int{
return 1;
}
public function getDrops(Item $item) : array{
if(!$this->isCompatibleWithTool($item)){
return [
ItemFactory::get(Item::STICK, 0, mt_rand(0, 2))
];
}
return parent::getDrops($item);
}
public function getFlameEncouragement() : int{
return 60;
}
public function getFlammability() : int{
return 100;
}
}

View File

@ -23,8 +23,7 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\Tool;
use pocketmine\item\TieredTool;
class Diamond extends Solid{
@ -43,14 +42,10 @@ class Diamond extends Solid{
}
public function getToolType() : int{
return Tool::TYPE_PICKAXE;
return BlockToolType::TYPE_PICKAXE;
}
public function getDrops(Item $item) : array{
if($item->isPickaxe() >= Tool::TIER_IRON){
return parent::getDrops($item);
}
return [];
public function getToolHarvestLevel() : int{
return TieredTool::TIER_IRON;
}
}
}

View File

@ -25,7 +25,7 @@ namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\Tool;
use pocketmine\item\TieredTool;
class DiamondOre extends Solid{
@ -44,16 +44,20 @@ class DiamondOre extends Solid{
}
public function getToolType() : int{
return Tool::TYPE_PICKAXE;
return BlockToolType::TYPE_PICKAXE;
}
public function getDrops(Item $item) : array{
if($item->isPickaxe() >= Tool::TIER_IRON){
return [
ItemFactory::get(Item::DIAMOND, 0, 1)
];
}
return [];
public function getToolHarvestLevel() : int{
return TieredTool::TIER_IRON;
}
}
public function getDropsForCompatibleTool(Item $item) : array{
return [
ItemFactory::get(Item::DIAMOND)
];
}
protected function getXpDropAmount() : int{
return mt_rand(3, 7);
}
}

View File

@ -23,8 +23,8 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Hoe;
use pocketmine\item\Item;
use pocketmine\item\Tool;
use pocketmine\Player;
class Dirt extends Solid{
@ -40,7 +40,7 @@ class Dirt extends Solid{
}
public function getToolType() : int{
return Tool::TYPE_SHOVEL;
return BlockToolType::TYPE_SHOVEL;
}
public function getName() : string{
@ -51,8 +51,8 @@ class Dirt extends Solid{
}
public function onActivate(Item $item, Player $player = null) : bool{
if($item->isHoe()){
$item->useOn($this);
if($item instanceof Hoe){
$item->applyDamage(1);
if($this->meta === 1){
$this->getLevel()->setBlock($this, BlockFactory::get(Block::DIRT), true);
}else{
@ -64,4 +64,4 @@ class Dirt extends Solid{
return false;
}
}
}

View File

@ -24,7 +24,6 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\level\Level;
use pocketmine\level\sound\DoorSound;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Vector3;
@ -54,7 +53,7 @@ abstract class Door extends Transparent{
return $down & 0x07 | ($isUp ? 8 : 0) | ($isRight ? 0x10 : 0);
}
protected function recalculateBoundingBox(){
protected function recalculateBoundingBox() : ?AxisAlignedBB{
$f = 0.1875;
$damage = $this->getFullDamage();
@ -201,26 +200,20 @@ abstract class Door extends Transparent{
return $bb;
}
public function onUpdate(int $type){
if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(Vector3::SIDE_DOWN)->getId() === self::AIR){ //Replace with common break method
$this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), false);
if($this->getSide(Vector3::SIDE_UP) instanceof Door){
$this->getLevel()->setBlock($this->getSide(Vector3::SIDE_UP), BlockFactory::get(Block::AIR), false);
}
return Level::BLOCK_UPDATE_NORMAL;
public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_DOWN)->getId() === self::AIR){ //Replace with common break method
$this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), false);
if($this->getSide(Vector3::SIDE_UP) instanceof Door){
$this->getLevel()->setBlock($this->getSide(Vector3::SIDE_UP), BlockFactory::get(Block::AIR), false);
}
}
return false;
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
if($face === Vector3::SIDE_UP){
$blockUp = $this->getSide(Vector3::SIDE_UP);
$blockDown = $this->getSide(Vector3::SIDE_DOWN);
if($blockUp->canBeReplaced() === false or $blockDown->isTransparent() === true){
if(!$blockUp->canBeReplaced() or $blockDown->isTransparent()){
return false;
}
$direction = $player instanceof Player ? $player->getDirection() : 0;
@ -233,36 +226,19 @@ abstract class Door extends Transparent{
$next = $this->getSide($faces[($direction + 2) % 4]);
$next2 = $this->getSide($faces[$direction]);
$metaUp = 0x08;
if($next->getId() === $this->getId() or ($next2->isTransparent() === false and $next->isTransparent() === true)){ //Door hinge
if($next->getId() === $this->getId() or (!$next2->isTransparent() and $next->isTransparent())){ //Door hinge
$metaUp |= 0x01;
}
$this->setDamage($player->getDirection() & 0x03);
$this->getLevel()->setBlock($blockReplace, $this, true, true); //Bottom
$this->getLevel()->setBlock($blockUp, $b = BlockFactory::get($this->getId(), $metaUp), true); //Top
$this->getLevel()->setBlock($blockUp, BlockFactory::get($this->getId(), $metaUp), true); //Top
return true;
}
return false;
}
public function onBreak(Item $item, Player $player = null) : bool{
if(($this->getDamage() & 0x08) === 0x08){
$down = $this->getSide(Vector3::SIDE_DOWN);
if($down->getId() === $this->getId()){
$this->getLevel()->setBlock($down, BlockFactory::get(Block::AIR), true);
}
}else{
$up = $this->getSide(Vector3::SIDE_UP);
if($up->getId() === $this->getId()){
$this->getLevel()->setBlock($up, BlockFactory::get(Block::AIR), true);
}
}
$this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), true);
return true;
}
public function onActivate(Item $item, Player $player = null) : bool{
if(($this->getDamage() & 0x08) === 0x08){ //Top
$down = $this->getSide(Vector3::SIDE_DOWN);
@ -286,4 +262,32 @@ abstract class Door extends Transparent{
public function getVariantBitmask() : int{
return 0;
}
}
public function getDropsForCompatibleTool(Item $item) : array{
if(($this->meta & 0x08) === 0){ //bottom half only
return parent::getDropsForCompatibleTool($item);
}
return [];
}
public function isAffectedBySilkTouch() : bool{
return false;
}
public function getAffectedBlocks() : array{
if(($this->getDamage() & 0x08) === 0x08){
$down = $this->getSide(Vector3::SIDE_DOWN);
if($down->getId() === $this->getId()){
return [$this, $down];
}
}else{
$up = $this->getSide(Vector3::SIDE_UP);
if($up->getId() === $this->getId()){
return [$this, $up];
}
}
return parent::getAffectedBlocks();
}
}

View File

@ -25,12 +25,11 @@ namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\level\Level;
use pocketmine\math\Vector3;
use pocketmine\Player;
class DoublePlant extends Flowable{
const BITFLAG_TOP = 0x08;
public const BITFLAG_TOP = 0x08;
protected $id = self::DOUBLE_PLANT;
@ -51,10 +50,10 @@ class DoublePlant extends Flowable{
4 => "Rose Bush",
5 => "Peony"
];
return $names[$this->meta & 0x07] ?? "";
return $names[$this->getVariant()] ?? "";
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$id = $blockReplace->getSide(Vector3::SIDE_DOWN)->getId();
if(($id === Block::GRASS or $id === Block::DIRT) and $blockReplace->getSide(Vector3::SIDE_UP)->canBeReplaced()){
$this->getLevel()->setBlock($blockReplace, $this, false, false);
@ -79,51 +78,50 @@ class DoublePlant extends Flowable{
return (
$other->getId() === $this->getId() and
($other->getDamage() & 0x07) === ($this->getDamage() & 0x07) and
$other->getVariant() === $this->getVariant() and
($other->getDamage() & self::BITFLAG_TOP) !== ($this->getDamage() & self::BITFLAG_TOP)
);
}
public function onUpdate(int $type){
if($type === Level::BLOCK_UPDATE_NORMAL){
$down = $this->getSide(Vector3::SIDE_DOWN);
if(!$this->isValidHalfPlant() or (($this->meta & self::BITFLAG_TOP) === 0 and $down->isTransparent())){
$this->getLevel()->useBreakOn($this);
return Level::BLOCK_UPDATE_NORMAL;
}
public function onNearbyBlockChange() : void{
if(!$this->isValidHalfPlant() or (($this->meta & self::BITFLAG_TOP) === 0 and $this->getSide(Vector3::SIDE_DOWN)->isTransparent())){
$this->getLevel()->useBreakOn($this);
}
return false;
}
public function onBreak(Item $item, Player $player = null) : bool{
if(parent::onBreak($item, $player) and $this->isValidHalfPlant()){
$this->getLevel()->useBreakOn($this->getSide(($this->meta & self::BITFLAG_TOP) !== 0 ? Vector3::SIDE_DOWN : Vector3::SIDE_UP), $item, $player, $player !== null);
}
return false;
}
public function getVariantBitmask() : int{
return 0x07;
}
public function getToolType() : int{
return ($this->meta === 2 or $this->meta === 3) ? BlockToolType::TYPE_SHEARS : BlockToolType::TYPE_NONE;
}
public function getToolHarvestLevel() : int{
return ($this->meta === 2 or $this->meta === 3) ? 1 : 0; //only grass or fern require shears
}
public function getDrops(Item $item) : array{
if($this->meta & self::BITFLAG_TOP){
if(!$item->isShears() and ($this->meta === 2 or $this->meta === 3)){ //grass or fern
if(mt_rand(0, 24) === 0){
return [
ItemFactory::get(Item::SEEDS, 0, 1)
];
}
return [];
if($this->isCompatibleWithTool($item)){
return parent::getDrops($item);
}
return parent::getDrops($item);
if(mt_rand(0, 24) === 0){
return [
ItemFactory::get(Item::SEEDS)
];
}
}
return [];
}
}
public function getAffectedBlocks() : array{
if($this->isValidHalfPlant()){
return [$this, $this->getSide(($this->meta & self::BITFLAG_TOP) !== 0 ? Vector3::SIDE_DOWN : Vector3::SIDE_UP)];
}
return parent::getAffectedBlocks();
}
}

View File

@ -0,0 +1,50 @@
<?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/
*
*
*/
declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
abstract class DoubleSlab extends Solid{
public function __construct(int $meta = 0){
$this->meta = $meta;
}
abstract public function getSlabId() : int;
public function getName() : string{
return "Double " . BlockFactory::get($this->getSlabId(), $this->getVariant())->getName();
}
public function getDropsForCompatibleTool(Item $item) : array{
return [
ItemFactory::get($this->getSlabId(), $this->getVariant(), 2)
];
}
public function isAffectedBySilkTouch() : bool{
return false;
}
}

View File

@ -23,16 +23,14 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\Tool;
use pocketmine\item\TieredTool;
class DoubleStoneSlab extends Solid{
class DoubleStoneSlab extends DoubleSlab{
protected $id = self::DOUBLE_STONE_SLAB;
public function __construct(int $meta = 0){
$this->meta = $meta;
public function getSlabId() : int{
return self::STONE_SLAB;
}
public function getHardness() : float{
@ -40,31 +38,10 @@ class DoubleStoneSlab extends Solid{
}
public function getToolType() : int{
return Tool::TYPE_PICKAXE;
return BlockToolType::TYPE_PICKAXE;
}
public function getName() : string{
static $names = [
0 => "Stone",
1 => "Sandstone",
2 => "Wooden",
3 => "Cobblestone",
4 => "Brick",
5 => "Stone Brick",
6 => "Quartz",
7 => "Nether Brick"
];
return "Double " . $names[$this->meta & 0x07] . " Slab";
public function getToolHarvestLevel() : int{
return TieredTool::TIER_WOODEN;
}
public function getDrops(Item $item) : array{
if($item->isPickaxe() >= Tool::TIER_WOODEN){
return [
ItemFactory::get(Item::STONE_SLAB, $this->getDamage() & 0x07, 2)
];
}
return [];
}
}
}

View File

@ -0,0 +1,33 @@
<?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/
*
*
*/
declare(strict_types=1);
namespace pocketmine\block;
class DoubleStoneSlab2 extends DoubleStoneSlab{
protected $id = self::DOUBLE_STONE_SLAB2;
public function getSlabId() : int{
return self::STONE_SLAB2;
}
}

View File

@ -23,16 +23,12 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\Tool;
class DoubleWoodenSlab extends Solid{
class DoubleWoodenSlab extends DoubleSlab{
protected $id = self::DOUBLE_WOODEN_SLAB;
public function __construct(int $meta = 0){
$this->meta = $meta;
public function getSlabId() : int{
return self::WOODEN_SLAB;
}
public function getHardness() : float{
@ -40,25 +36,14 @@ class DoubleWoodenSlab extends Solid{
}
public function getToolType() : int{
return Tool::TYPE_AXE;
return BlockToolType::TYPE_AXE;
}
public function getName() : string{
static $names = [
0 => "Oak",
1 => "Spruce",
2 => "Birch",
3 => "Jungle",
4 => "Acacia",
5 => "Dark Oak"
];
return "Double " . ($names[$this->meta & 0x07] ?? "") . " Wooden Slab";
public function getFlameEncouragement() : int{
return 5;
}
public function getDrops(Item $item) : array{
return [
ItemFactory::get(Item::WOODEN_SLAB, $this->getDamage() & 0x07, 2)
];
public function getFlammability() : int{
return 20;
}
}
}

View File

@ -23,8 +23,7 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\Tool;
use pocketmine\item\TieredTool;
class Emerald extends Solid{
@ -39,18 +38,14 @@ class Emerald extends Solid{
}
public function getToolType() : int{
return Tool::TYPE_PICKAXE;
return BlockToolType::TYPE_PICKAXE;
}
public function getToolHarvestLevel() : int{
return TieredTool::TIER_IRON;
}
public function getName() : string{
return "Emerald Block";
}
public function getDrops(Item $item) : array{
if($item->isPickaxe() >= Tool::TIER_IRON){
return parent::getDrops($item);
}
return [];
}
}
}

View File

@ -25,7 +25,7 @@ namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\Tool;
use pocketmine\item\TieredTool;
class EmeraldOre extends Solid{
@ -40,20 +40,24 @@ class EmeraldOre extends Solid{
}
public function getToolType() : int{
return Tool::TYPE_PICKAXE;
return BlockToolType::TYPE_PICKAXE;
}
public function getToolHarvestLevel() : int{
return TieredTool::TIER_IRON;
}
public function getHardness() : float{
return 3;
}
public function getDrops(Item $item) : array{
if($item->isPickaxe() >= Tool::TIER_IRON){
return [
ItemFactory::get(Item::EMERALD, 0, 1)
];
}
return [];
public function getDropsForCompatibleTool(Item $item) : array{
return [
ItemFactory::get(Item::EMERALD)
];
}
}
protected function getXpDropAmount() : int{
return mt_rand(3, 7);
}
}

View File

@ -25,12 +25,10 @@ namespace pocketmine\block;
use pocketmine\inventory\EnchantInventory;
use pocketmine\item\Item;
use pocketmine\item\Tool;
use pocketmine\item\TieredTool;
use pocketmine\math\Vector3;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\IntTag;
use pocketmine\nbt\tag\StringTag;
use pocketmine\Player;
use pocketmine\tile\EnchantTable as TileEnchantTable;
use pocketmine\tile\Tile;
class EnchantingTable extends Transparent{
@ -41,26 +39,10 @@ class EnchantingTable extends Transparent{
$this->meta = $meta;
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$this->getLevel()->setBlock($blockReplace, $this, true, true);
$nbt = new CompoundTag("", [
new StringTag("id", Tile::ENCHANT_TABLE),
new IntTag("x", $this->x),
new IntTag("y", $this->y),
new IntTag("z", $this->z)
]);
if($item->hasCustomName()){
$nbt->CustomName = new StringTag("CustomName", $item->getCustomName());
}
if($item->hasCustomBlockData()){
foreach($item->getCustomBlockData() as $key => $v){
$nbt->{$key} = $v;
}
}
Tile::createTile(Tile::ENCHANT_TABLE, $this->getLevel(), $nbt);
Tile::createTile(Tile::ENCHANT_TABLE, $this->getLevel(), TileEnchantTable::createNBT($this, $face, $item, $player));
return true;
}
@ -78,7 +60,11 @@ class EnchantingTable extends Transparent{
}
public function getToolType() : int{
return Tool::TYPE_PICKAXE;
return BlockToolType::TYPE_PICKAXE;
}
public function getToolHarvestLevel() : int{
return TieredTool::TIER_WOODEN;
}
public function onActivate(Item $item, Player $player = null) : bool{
@ -90,12 +76,4 @@ class EnchantingTable extends Transparent{
return true;
}
public function getDrops(Item $item) : array{
if($item->isPickaxe() >= Tool::TIER_WOODEN){
return parent::getDrops($item);
}
return [];
}
}
}

View File

@ -54,7 +54,7 @@ class EndPortalFrame extends Solid{
return false;
}
protected function recalculateBoundingBox(){
protected function recalculateBoundingBox() : ?AxisAlignedBB{
return new AxisAlignedBB(
$this->x,
@ -65,4 +65,4 @@ class EndPortalFrame extends Solid{
$this->z + 1
);
}
}
}

View File

@ -40,7 +40,7 @@ class EndRod extends Flowable{
return "End Rod";
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
if($face === Vector3::SIDE_UP or $face === Vector3::SIDE_DOWN){
$this->meta = $face;
}else{
@ -61,7 +61,7 @@ class EndRod extends Flowable{
return 14;
}
protected function recalculateBoundingBox(){
protected function recalculateBoundingBox() : ?AxisAlignedBB{
$m = $this->meta & ~0x01;
$width = 0.375;
@ -101,4 +101,4 @@ class EndRod extends Flowable{
public function getVariantBitmask() : int{
return 0;
}
}
}

View File

@ -23,7 +23,7 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Tool;
use pocketmine\item\TieredTool;
class EndStone extends Solid{
@ -38,10 +38,14 @@ class EndStone extends Solid{
}
public function getToolType() : int{
return Tool::TYPE_PICKAXE;
return BlockToolType::TYPE_PICKAXE;
}
public function getToolHarvestLevel() : int{
return TieredTool::TIER_WOODEN;
}
public function getHardness() : float{
return 3;
}
}
}

View File

@ -21,23 +21,31 @@
declare(strict_types=1);
namespace pocketmine\item;
namespace pocketmine\block;
use pocketmine\item\TieredTool;
class EndStoneBricks extends Solid{
protected $id = self::END_BRICKS;
class WoodenPickaxe extends Tool{
public function __construct(int $meta = 0){
parent::__construct(self::WOODEN_PICKAXE, $meta, "Wooden Pickaxe");
$this->meta = $meta;
}
public function isPickaxe(){
return Tool::TIER_WOODEN;
public function getName() : string{
return "End Stone Bricks";
}
public function getFuelTime() : int{
return 200;
public function getHardness() : float{
return 0.8;
}
public function getAttackPoints() : int{
return 3;
public function getToolType() : int{
return BlockToolType::TYPE_PICKAXE;
}
public function getToolHarvestLevel() : int{
return TieredTool::TIER_WOODEN;
}
}

View File

@ -0,0 +1,109 @@
<?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/
*
*
*/
declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\TieredTool;
use pocketmine\math\Vector3;
use pocketmine\Player;
use pocketmine\tile\EnderChest as TileEnderChest;
use pocketmine\tile\Tile;
class EnderChest extends Chest{
protected $id = self::ENDER_CHEST;
public function getHardness() : float{
return 22.5;
}
public function getBlastResistance() : float{
return 3000;
}
public function getLightLevel() : int{
return 7;
}
public function getName() : string{
return "Ender Chest";
}
public function getToolType() : int{
return BlockToolType::TYPE_PICKAXE;
}
public function getToolHarvestLevel() : int{
return TieredTool::TIER_WOODEN;
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$faces = [
0 => 4,
1 => 2,
2 => 5,
3 => 3
];
$this->meta = $faces[$player instanceof Player ? $player->getDirection() : 0];
$this->getLevel()->setBlock($blockReplace, $this, true, true);
Tile::createTile(Tile::ENDER_CHEST, $this->getLevel(), TileEnderChest::createNBT($this, $face, $item, $player));
return true;
}
public function onActivate(Item $item, Player $player = null) : bool{
if($player instanceof Player){
$t = $this->getLevel()->getTile($this);
$enderChest = null;
if($t instanceof TileEnderChest){
$enderChest = $t;
}else{
$enderChest = Tile::createTile(Tile::ENDER_CHEST, $this->getLevel(), TileEnderChest::createNBT($this));
}
if(!$this->getSide(Vector3::SIDE_UP)->isTransparent()){
return true;
}
$player->getEnderChestInventory()->setHolderPosition($enderChest);
$player->addWindow($player->getEnderChestInventory());
}
return true;
}
public function getDropsForCompatibleTool(Item $item) : array{
return [
ItemFactory::get(Item::OBSIDIAN, 0, 8)
];
}
public function getFuelTime() : int{
return 0;
}
}

View File

@ -24,43 +24,31 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\entity\Entity;
use pocketmine\level\Level;
use pocketmine\math\Vector3;
use pocketmine\nbt\tag\ByteTag;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\DoubleTag;
use pocketmine\nbt\tag\FloatTag;
use pocketmine\nbt\tag\IntTag;
use pocketmine\nbt\tag\ListTag;
abstract class Fallable extends Solid{
public function onUpdate(int $type){
if($type === Level::BLOCK_UPDATE_NORMAL){
$down = $this->getSide(Vector3::SIDE_DOWN);
if($down->getId() === self::AIR or ($down instanceof Liquid)){
$this->level->setBlock($this, BlockFactory::get(Block::AIR), true, true);
$fall = Entity::createEntity("FallingSand", $this->getLevel(), new CompoundTag("", [
new ListTag("Pos", [
new DoubleTag("", $this->x + 0.5),
new DoubleTag("", $this->y),
new DoubleTag("", $this->z + 0.5)
]),
new ListTag("Motion", [
new DoubleTag("", 0),
new DoubleTag("", 0),
new DoubleTag("", 0)
]),
new ListTag("Rotation", [
new FloatTag("", 0),
new FloatTag("", 0)
]),
new IntTag("TileID", $this->getId()),
new ByteTag("Data", $this->getDamage())
]));
public function onNearbyBlockChange() : void{
$down = $this->getSide(Vector3::SIDE_DOWN);
if($down->getId() === self::AIR or $down instanceof Liquid or $down instanceof Fire){
$this->level->setBlock($this, BlockFactory::get(Block::AIR), true);
$nbt = Entity::createBaseNBT($this->add(0.5, 0, 0.5));
$nbt->setInt("TileID", $this->getId());
$nbt->setByte("Data", $this->getDamage());
$fall = Entity::createEntity("FallingSand", $this->getLevel(), $nbt);
if($fall !== null){
$fall->spawnToAll();
}
}
}
}
/**
* @return null|Block
*/
public function tickFalling() : ?Block{
return null;
}
}

View File

@ -25,9 +25,8 @@ namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\Tool;
use pocketmine\level\Level;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Vector3;
class Farmland extends Transparent{
@ -46,14 +45,11 @@ class Farmland extends Transparent{
}
public function getToolType() : int{
return Tool::TYPE_SHOVEL;
return BlockToolType::TYPE_SHOVEL;
}
public function ticksRandomly() : bool{
return true;
}
protected function recalculateBoundingBox(){
protected function recalculateBoundingBox() : ?AxisAlignedBB{
return new AxisAlignedBB(
$this->x,
$this->y,
@ -64,17 +60,55 @@ class Farmland extends Transparent{
);
}
public function onUpdate(int $type){
if($type === Level::BLOCK_UPDATE_RANDOM){
//TODO: hydration
public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_UP)->isSolid()){
$this->level->setBlock($this, BlockFactory::get(Block::DIRT), true);
}
}
public function ticksRandomly() : bool{
return true;
}
public function onRandomTick() : void{
if(!$this->canHydrate()){
if($this->meta > 0){
$this->meta--;
$this->level->setBlock($this, $this, false, false);
}else{
$this->level->setBlock($this, BlockFactory::get(Block::DIRT), false, true);
}
}elseif($this->meta < 7){
$this->meta = 7;
$this->level->setBlock($this, $this, false, false);
}
}
protected function canHydrate() : bool{
//TODO: check rain
$start = $this->add(-4, 0, -4);
$end = $this->add(4, 1, 4);
for($y = $start->y; $y <= $end->y; ++$y){
for($z = $start->z; $z <= $end->z; ++$z){
for($x = $start->x; $x <= $end->x; ++$x){
$id = $this->level->getBlockIdAt($x, $y, $z);
if($id === Block::STILL_WATER or $id === Block::FLOWING_WATER){
return true;
}
}
}
}
return false;
}
public function getDrops(Item $item) : array{
public function getDropsForCompatibleTool(Item $item) : array{
return [
ItemFactory::get(Item::DIRT, 0, 1)
ItemFactory::get(Item::DIRT)
];
}
}
public function isAffectedBySilkTouch() : bool{
return false;
}
}

View File

@ -23,73 +23,86 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Tool;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Vector3;
class Fence extends Transparent{
const FENCE_OAK = 0;
const FENCE_SPRUCE = 1;
const FENCE_BIRCH = 2;
const FENCE_JUNGLE = 3;
const FENCE_ACACIA = 4;
const FENCE_DARKOAK = 5;
protected $id = self::FENCE;
abstract class Fence extends Transparent{
public function __construct(int $meta = 0){
$this->meta = $meta;
}
public function getHardness() : float{
return 2;
public function getThickness() : float{
return 0.25;
}
public function getToolType() : int{
return Tool::TYPE_AXE;
}
public function getName() : string{
static $names = [
self::FENCE_OAK => "Oak Fence",
self::FENCE_SPRUCE => "Spruce Fence",
self::FENCE_BIRCH => "Birch Fence",
self::FENCE_JUNGLE => "Jungle Fence",
self::FENCE_ACACIA => "Acacia Fence",
self::FENCE_DARKOAK => "Dark Oak Fence"
];
return $names[$this->meta & 0x07] ?? "Unknown";
}
protected function recalculateBoundingBox(){
$north = $this->canConnect($this->getSide(Vector3::SIDE_NORTH));
$south = $this->canConnect($this->getSide(Vector3::SIDE_SOUTH));
$west = $this->canConnect($this->getSide(Vector3::SIDE_WEST));
$east = $this->canConnect($this->getSide(Vector3::SIDE_EAST));
$n = $north ? 0 : 0.375;
$s = $south ? 1 : 0.625;
$w = $west ? 0 : 0.375;
$e = $east ? 1 : 0.625;
protected function recalculateBoundingBox() : ?AxisAlignedBB{
$width = 0.5 - $this->getThickness() / 2;
return new AxisAlignedBB(
$this->x + $w,
$this->x + ($this->canConnect($this->getSide(Vector3::SIDE_WEST)) ? 0 : $width),
$this->y,
$this->z + $n,
$this->x + $e,
$this->z + ($this->canConnect($this->getSide(Vector3::SIDE_NORTH)) ? 0 : $width),
$this->x + 1 - ($this->canConnect($this->getSide(Vector3::SIDE_EAST)) ? 0 : $width),
$this->y + 1.5,
$this->z + $s
$this->z + 1 - ($this->canConnect($this->getSide(Vector3::SIDE_SOUTH)) ? 0 : $width)
);
}
protected function recalculateCollisionBoxes() : array{
$inset = 0.5 - $this->getThickness() / 2;
/** @var AxisAlignedBB[] $bbs */
$bbs = [];
$connectWest = $this->canConnect($this->getSide(Vector3::SIDE_WEST));
$connectEast = $this->canConnect($this->getSide(Vector3::SIDE_EAST));
if($connectWest or $connectEast){
//X axis (west/east)
$bbs[] = new AxisAlignedBB(
$this->x + ($connectWest ? 0 : $inset),
$this->y,
$this->z + $inset,
$this->x + 1 - ($connectEast ? 0 : $inset),
$this->y + 1.5,
$this->z + 1 - $inset
);
}
$connectNorth = $this->canConnect($this->getSide(Vector3::SIDE_NORTH));
$connectSouth = $this->canConnect($this->getSide(Vector3::SIDE_SOUTH));
if($connectNorth or $connectSouth){
//Z axis (north/south)
$bbs[] = new AxisAlignedBB(
$this->x + $inset,
$this->y,
$this->z + ($connectNorth ? 0 : $inset),
$this->x + 1 - $inset,
$this->y + 1.5,
$this->z + 1 - ($connectSouth ? 0 : $inset)
);
}
if(empty($bbs)){
//centre post AABB (only needed if not connected on any axis - other BBs overlapping will do this if any connections are made)
return [
new AxisAlignedBB(
$this->x + $inset,
$this->y,
$this->z + $inset,
$this->x + 1 - $inset,
$this->y + 1.5,
$this->z + 1 - $inset
)
];
}
return $bbs;
}
public function canConnect(Block $block){
return ($block instanceof Fence or $block instanceof FenceGate) ? true : $block->isSolid() and !$block->isTransparent();
return $block instanceof static or $block instanceof FenceGate or ($block->isSolid() and !$block->isTransparent());
}
public function getFuelTime() : int{
return 300;
}
}

View File

@ -24,7 +24,6 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\Tool;
use pocketmine\level\sound\DoorSound;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Vector3;
@ -37,11 +36,11 @@ class FenceGate extends Transparent{
}
public function getToolType() : int{
return Tool::TYPE_AXE;
return BlockToolType::TYPE_AXE;
}
protected function recalculateBoundingBox(){
protected function recalculateBoundingBox() : ?AxisAlignedBB{
if(($this->getDamage() & 0x04) > 0){
return null;
@ -69,7 +68,7 @@ class FenceGate extends Transparent{
}
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$this->meta = ($player instanceof Player ? ($player->getDirection() - 1) & 0x03 : 0);
$this->getLevel()->setBlock($blockReplace, $this, true, true);
@ -95,4 +94,12 @@ class FenceGate extends Transparent{
public function getFuelTime() : int{
return 300;
}
public function getFlameEncouragement() : int{
return 5;
}
public function getFlammability() : int{
return 20;
}
}

View File

@ -23,13 +23,13 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\entity\Arrow;
use pocketmine\entity\Entity;
use pocketmine\entity\projectile\Arrow;
use pocketmine\event\block\BlockBurnEvent;
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\math\Vector3;
use pocketmine\Server;
@ -61,11 +61,7 @@ class Fire extends Flowable{
return true;
}
public function ticksRandomly() : bool{
return true;
}
public function onEntityCollide(Entity $entity){
public function onEntityCollide(Entity $entity) : void{
$ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_FIRE, 1);
$entity->attack($ev);
@ -79,39 +75,94 @@ class Fire extends Flowable{
}
}
public function getDrops(Item $item) : array{
public function getDropsForCompatibleTool(Item $item) : array{
return [];
}
public function onUpdate(int $type){
if($type === Level::BLOCK_UPDATE_NORMAL){
for($s = 0; $s <= 5; ++$s){
$side = $this->getSide($s);
if($side->getId() !== self::AIR and !($side instanceof Liquid)){
return false;
}
}
public function onNearbyBlockChange() : void{
if(!$this->getSide(Vector3::SIDE_DOWN)->isSolid() and !$this->hasAdjacentFlammableBlocks()){
$this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), true);
}else{
$this->level->scheduleDelayedBlockUpdate($this, mt_rand(30, 40));
}
}
return Level::BLOCK_UPDATE_NORMAL;
}elseif($type === Level::BLOCK_UPDATE_RANDOM){
if($this->getSide(Vector3::SIDE_DOWN)->getId() !== self::NETHERRACK){
if(mt_rand(0, 2) === 0){
if($this->meta === 0x0F){
$this->level->setBlock($this, BlockFactory::get(Block::AIR));
}else{
$this->meta++;
$this->level->setBlock($this, $this);
}
public function ticksRandomly() : bool{
return true;
}
return Level::BLOCK_UPDATE_NORMAL;
public function onRandomTick() : void{
$down = $this->getSide(Vector3::SIDE_DOWN);
$result = null;
if($this->meta < 15 and mt_rand(0, 2) === 0){
$this->meta++;
$result = $this;
}
$canSpread = true;
if(!$down->burnsForever()){
//TODO: check rain
if($this->meta === 15){
if(!$down->isFlammable() and mt_rand(0, 3) === 3){ //1/4 chance to extinguish
$canSpread = false;
$result = BlockFactory::get(Block::AIR);
}
}elseif(!$this->hasAdjacentFlammableBlocks()){
$canSpread = false;
if(!$down->isSolid() or $this->meta > 3){ //fire older than 3, or without a solid block below
$result = BlockFactory::get(Block::AIR);
}
}
}
if($result !== null){
$this->level->setBlock($this, $result);
}
$this->level->scheduleDelayedBlockUpdate($this, mt_rand(30, 40));
if($canSpread){
//TODO: raise upper bound for chance in humid biomes
foreach($this->getHorizontalSides() as $side){
$this->burnBlock($side, 300);
}
//vanilla uses a 250 upper bound here, but I don't think they intended to increase the chance of incineration
$this->burnBlock($this->getSide(Vector3::SIDE_UP), 350);
$this->burnBlock($this->getSide(Vector3::SIDE_DOWN), 350);
//TODO: fire spread
}
}
public function onScheduledUpdate() : void{
$this->onRandomTick();
}
private function hasAdjacentFlammableBlocks() : bool{
for($i = 0; $i <= 5; ++$i){
if($this->getSide($i)->isFlammable()){
return true;
}
}
return false;
}
}
private function burnBlock(Block $block, int $chanceBound) : void{
if(mt_rand(0, $chanceBound) < $block->getFlammability()){
$this->level->getServer()->getPluginManager()->callEvent($ev = new BlockBurnEvent($block, $this));
if(!$ev->isCancelled()){
$block->onIncinerate();
if(mt_rand(0, $this->meta + 9) < 5){ //TODO: check rain
$this->level->setBlock($block, BlockFactory::get(Block::FIRE, min(15, $this->meta + (mt_rand(0, 4) >> 2))));
}else{
$this->level->setBlock($block, BlockFactory::get(Block::AIR));
}
}
}
}
}

View File

@ -23,6 +23,8 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\math\AxisAlignedBB;
abstract class Flowable extends Transparent{
public function canBeFlowedInto() : bool{
@ -33,15 +35,11 @@ abstract class Flowable extends Transparent{
return 0;
}
public function getBlastResistance() : float{
return 0;
}
public function isSolid() : bool{
return false;
}
protected function recalculateBoundingBox(){
protected function recalculateBoundingBox() : ?AxisAlignedBB{
return null;
}
}
}

View File

@ -24,20 +24,19 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\level\Level;
use pocketmine\math\Vector3;
use pocketmine\Player;
class Flower extends Flowable{
const TYPE_POPPY = 0;
const TYPE_BLUE_ORCHID = 1;
const TYPE_ALLIUM = 2;
const TYPE_AZURE_BLUET = 3;
const TYPE_RED_TULIP = 4;
const TYPE_ORANGE_TULIP = 5;
const TYPE_WHITE_TULIP = 6;
const TYPE_PINK_TULIP = 7;
const TYPE_OXEYE_DAISY = 8;
public const TYPE_POPPY = 0;
public const TYPE_BLUE_ORCHID = 1;
public const TYPE_ALLIUM = 2;
public const TYPE_AZURE_BLUET = 3;
public const TYPE_RED_TULIP = 4;
public const TYPE_ORANGE_TULIP = 5;
public const TYPE_WHITE_TULIP = 6;
public const TYPE_PINK_TULIP = 7;
public const TYPE_OXEYE_DAISY = 8;
protected $id = self::RED_FLOWER;
@ -60,7 +59,7 @@ class Flower extends Flowable{
return $names[$this->meta] ?? "Unknown";
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$down = $this->getSide(Vector3::SIDE_DOWN);
if($down->getId() === Block::GRASS or $down->getId() === Block::DIRT or $down->getId() === Block::FARMLAND){
$this->getLevel()->setBlock($blockReplace, $this, true);
@ -71,15 +70,17 @@ class Flower extends Flowable{
return false;
}
public function onUpdate(int $type){
if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(Vector3::SIDE_DOWN)->isTransparent()){
$this->getLevel()->useBreakOn($this);
return Level::BLOCK_UPDATE_NORMAL;
}
public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_DOWN)->isTransparent()){
$this->getLevel()->useBreakOn($this);
}
return false;
}
}
public function getFlameEncouragement() : int{
return 60;
}
public function getFlammability() : int{
return 100;
}
}

View File

@ -24,22 +24,16 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\level\Level;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Vector3;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\IntTag;
use pocketmine\nbt\tag\ShortTag;
use pocketmine\nbt\tag\StringTag;
use pocketmine\Player;
use pocketmine\tile\FlowerPot as TileFlowerPot;
use pocketmine\tile\Tile;
class FlowerPot extends Flowable{
const STATE_EMPTY = 0;
const STATE_FULL = 1;
public const STATE_EMPTY = 0;
public const STATE_FULL = 1;
protected $id = self::FLOWER_POT_BLOCK;
protected $itemId = Item::FLOWER_POT;
@ -49,10 +43,10 @@ class FlowerPot extends Flowable{
}
public function getName() : string{
return "Flower Pot Block";
return "Flower Pot";
}
protected function recalculateBoundingBox(){
protected function recalculateBoundingBox() : ?AxisAlignedBB{
return new AxisAlignedBB(
$this->x + 0.3125,
$this->y,
@ -63,42 +57,20 @@ class FlowerPot extends Flowable{
);
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
if($this->getSide(Vector3::SIDE_DOWN)->isTransparent()){
return false;
}
$this->getLevel()->setBlock($blockReplace, $this, true, true);
$nbt = new CompoundTag("", [
new StringTag("id", Tile::FLOWER_POT),
new IntTag("x", $blockReplace->x),
new IntTag("y", $blockReplace->y),
new IntTag("z", $blockReplace->z),
new ShortTag("item", 0),
new IntTag("mData", 0)
]);
if($item->hasCustomBlockData()){
foreach($item->getCustomBlockData() as $key => $v){
$nbt->{$key} = $v;
}
}
Tile::createTile(Tile::FLOWER_POT, $this->getLevel(), $nbt);
Tile::createTile(Tile::FLOWER_POT, $this->getLevel(), TileFlowerPot::createNBT($this, $face, $item, $player));
return true;
}
public function onUpdate(int $type){
if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(Vector3::SIDE_DOWN)->isTransparent() === true){
$this->getLevel()->useBreakOn($this);
return Level::BLOCK_UPDATE_NORMAL;
}
public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_DOWN)->isTransparent()){
$this->getLevel()->useBreakOn($this);
}
return false;
}
public function onActivate(Item $item, Player $player = null) : bool{
@ -112,19 +84,17 @@ class FlowerPot extends Flowable{
$this->setDamage(self::STATE_FULL); //specific damage value is unnecessary, it just needs to be non-zero to show an item.
$this->getLevel()->setBlock($this, $this, true, false);
$pot->setItem($item);
$pot->setItem($item->pop());
if($player instanceof Player){
if($player->isSurvival()){
$item->setCount($item->getCount() - 1);
$player->getInventory()->setItemInHand($item->getCount() > 0 ? $item : ItemFactory::get(Item::AIR));
}
}
return true;
}
public function getDrops(Item $item) : array{
$items = parent::getDrops($item);
public function getVariantBitmask() : int{
return 0;
}
public function getDropsForCompatibleTool(Item $item) : array{
$items = parent::getDropsForCompatibleTool($item);
$tile = $this->getLevel()->getTile($this);
if($tile instanceof TileFlowerPot){
@ -137,4 +107,7 @@ class FlowerPot extends Flowable{
return $items;
}
}
public function isAffectedBySilkTouch() : bool{
return false;
}
}

View File

@ -35,4 +35,4 @@ class Furnace extends BurningFurnace{
public function getLightLevel() : int{
return 0;
}
}
}

View File

@ -41,7 +41,7 @@ class Glass extends Transparent{
return 0.3;
}
public function getDrops(Item $item) : array{
public function getDropsForCompatibleTool(Item $item) : array{
return [];
}
}
}

View File

@ -41,7 +41,7 @@ class GlassPane extends Thin{
return 0.3;
}
public function getDrops(Item $item) : array{
public function getDropsForCompatibleTool(Item $item) : array{
return [];
}
}
}

View File

@ -25,7 +25,7 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\Tool;
use pocketmine\item\TieredTool;
use pocketmine\math\Vector3;
use pocketmine\Player;
@ -36,10 +36,14 @@ class GlazedTerracotta extends Solid{
}
public function getToolType() : int{
return Tool::TYPE_PICKAXE;
return BlockToolType::TYPE_PICKAXE;
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function getToolHarvestLevel() : int{
return TieredTool::TIER_WOODEN;
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
if($player !== null){
$faces = [
0 => 4,
@ -56,12 +60,4 @@ class GlazedTerracotta extends Solid{
public function getVariantBitmask() : int{
return 0;
}
public function getDrops(Item $item) : array{
if($item->isPickaxe() >= Tool::TIER_WOODEN){
return parent::getDrops($item);
}
return [];
}
}
}

View File

@ -24,6 +24,8 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\TieredTool;
class GlowingObsidian extends Solid{
protected $id = self::GLOWING_OBSIDIAN;
@ -47,4 +49,12 @@ class GlowingObsidian extends Solid{
public function getBlastResistance() : float{
return 50;
}
}
public function getToolType() : int{
return BlockToolType::TYPE_PICKAXE;
}
public function getToolHarvestLevel() : int{
return TieredTool::TIER_DIAMOND;
}
}

View File

@ -23,12 +23,15 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\level\Level;
use pocketmine\item\Item;
use pocketmine\Player;
class GlowingRedstoneOre extends RedstoneOre{
protected $id = self::GLOWING_REDSTONE_ORE;
protected $itemId = self::REDSTONE_ORE;
public function getName() : string{
return "Glowing Redstone Ore";
}
@ -37,13 +40,19 @@ class GlowingRedstoneOre extends RedstoneOre{
return 9;
}
public function onUpdate(int $type){
if($type === Level::BLOCK_UPDATE_SCHEDULED or $type === Level::BLOCK_UPDATE_RANDOM){
$this->getLevel()->setBlock($this, BlockFactory::get(Block::REDSTONE_ORE, $this->meta), false, false);
return Level::BLOCK_UPDATE_WEAK;
}
public function onActivate(Item $item, Player $player = null) : bool{
return false;
}
}
public function onNearbyBlockChange() : void{
}
public function ticksRandomly() : bool{
return true;
}
public function onRandomTick() : void{
$this->getLevel()->setBlock($this, BlockFactory::get(Block::REDSTONE_ORE, $this->meta), false, false);
}
}

View File

@ -25,7 +25,6 @@ namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\Tool;
class Glowstone extends Transparent{
@ -44,16 +43,16 @@ class Glowstone extends Transparent{
}
public function getToolType() : int{
return Tool::TYPE_PICKAXE;
return BlockToolType::TYPE_PICKAXE;
}
public function getLightLevel() : int{
return 15;
}
public function getDrops(Item $item) : array{
public function getDropsForCompatibleTool(Item $item) : array{
return [
ItemFactory::get(Item::GLOWSTONE_DUST, 0, mt_rand(2, 4))
];
}
}
}

View File

@ -23,8 +23,7 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\Tool;
use pocketmine\item\TieredTool;
class Gold extends Solid{
@ -43,14 +42,10 @@ class Gold extends Solid{
}
public function getToolType() : int{
return Tool::TYPE_PICKAXE;
return BlockToolType::TYPE_PICKAXE;
}
public function getDrops(Item $item) : array{
if($item->isPickaxe() >= Tool::TIER_IRON){
return parent::getDrops($item);
}
return [];
public function getToolHarvestLevel() : int{
return TieredTool::TIER_IRON;
}
}
}

View File

@ -23,8 +23,7 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\Tool;
use pocketmine\item\TieredTool;
class GoldOre extends Solid{
@ -43,14 +42,10 @@ class GoldOre extends Solid{
}
public function getToolType() : int{
return Tool::TYPE_PICKAXE;
return BlockToolType::TYPE_PICKAXE;
}
public function getDrops(Item $item) : array{
if($item->isPickaxe() >= Tool::TIER_IRON){
return parent::getDrops($item);
}
return [];
public function getToolHarvestLevel() : int{
return TieredTool::TIER_IRON;
}
}
}

View File

@ -24,11 +24,11 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\event\block\BlockSpreadEvent;
use pocketmine\item\Hoe;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\Tool;
use pocketmine\item\Shovel;
use pocketmine\level\generator\object\TallGrass as TallGrassObject;
use pocketmine\level\Level;
use pocketmine\math\Vector3;
use pocketmine\Player;
use pocketmine\utils\Random;
@ -50,12 +50,12 @@ class Grass extends Solid{
}
public function getToolType() : int{
return Tool::TYPE_SHOVEL;
return BlockToolType::TYPE_SHOVEL;
}
public function getDrops(Item $item) : array{
public function getDropsForCompatibleTool(Item $item) : array{
return [
ItemFactory::get(Item::DIRT, 0, 1)
ItemFactory::get(Item::DIRT)
];
}
@ -63,44 +63,35 @@ class Grass extends Solid{
return true;
}
public function onUpdate(int $type){
if($type === Level::BLOCK_UPDATE_RANDOM){
$lightAbove = $this->level->getFullLightAt($this->x, $this->y + 1, $this->z);
if($lightAbove < 4 and BlockFactory::$lightFilter[$this->level->getBlockIdAt($this->x, $this->y + 1, $this->z)] >= 3){ //2 plus 1 standard filter amount
//grass dies
$this->level->getServer()->getPluginManager()->callEvent($ev = new BlockSpreadEvent($this, $this, BlockFactory::get(Block::DIRT)));
public function onRandomTick() : void{
$lightAbove = $this->level->getFullLightAt($this->x, $this->y + 1, $this->z);
if($lightAbove < 4 and BlockFactory::$lightFilter[$this->level->getBlockIdAt($this->x, $this->y + 1, $this->z)] >= 3){ //2 plus 1 standard filter amount
//grass dies
$this->level->getServer()->getPluginManager()->callEvent($ev = new BlockSpreadEvent($this, $this, BlockFactory::get(Block::DIRT)));
if(!$ev->isCancelled()){
$this->level->setBlock($this, $ev->getNewState(), false, false);
}
}elseif($lightAbove >= 9){
//try grass spread
for($i = 0; $i < 4; ++$i){
$x = mt_rand($this->x - 1, $this->x + 1);
$y = mt_rand($this->y - 3, $this->y + 1);
$z = mt_rand($this->z - 1, $this->z + 1);
if(
$this->level->getBlockIdAt($x, $y, $z) !== Block::DIRT or
$this->level->getBlockDataAt($x, $y, $z) === 1 or
$this->level->getFullLightAt($x, $y + 1, $z) < 4 or
BlockFactory::$lightFilter[$this->level->getBlockIdAt($x, $y + 1, $z)] >= 3
){
continue;
}
$this->level->getServer()->getPluginManager()->callEvent($ev = new BlockSpreadEvent($b = $this->level->getBlockAt($x, $y, $z), $this, BlockFactory::get(Block::GRASS)));
if(!$ev->isCancelled()){
$this->level->setBlock($this, $ev->getNewState(), false, false);
$this->level->setBlock($b, $ev->getNewState(), false, false);
}
return Level::BLOCK_UPDATE_RANDOM;
}elseif($lightAbove >= 9){
//try grass spread
$vector = $this->asVector3();
for($i = 0; $i < 4; ++$i){
$vector->x = mt_rand($this->x - 1, $this->x + 1);
$vector->y = mt_rand($this->y - 3, $this->y + 1);
$vector->z = mt_rand($this->z - 1, $this->z + 1);
if(
$this->level->getBlockIdAt($vector->x, $vector->y, $vector->z) !== Block::DIRT or
$this->level->getBlockDataAt($vector->x, $vector->y, $vector->z) === 1 or
$this->level->getFullLightAt($vector->x, $vector->y + 1, $vector->z) < 4 or
BlockFactory::$lightFilter[$this->level->getBlockIdAt($vector->x, $vector->y + 1, $vector->z)] >= 3
){
continue;
}
$this->level->getServer()->getPluginManager()->callEvent($ev = new BlockSpreadEvent($this->level->getBlock($vector), $this, BlockFactory::get(Block::GRASS)));
if(!$ev->isCancelled()){
$this->level->setBlock($vector, $ev->getNewState(), false, false);
}
}
return Level::BLOCK_UPDATE_RANDOM;
}
}
return false;
}
public function onActivate(Item $item, Player $player = null) : bool{
@ -109,13 +100,13 @@ class Grass extends Solid{
TallGrassObject::growGrass($this->getLevel(), $this, new Random(mt_rand()), 8, 2);
return true;
}elseif($item->isHoe()){
$item->useOn($this);
}elseif($item instanceof Hoe){
$item->applyDamage(1);
$this->getLevel()->setBlock($this, BlockFactory::get(Block::FARMLAND));
return true;
}elseif($item->isShovel() and $this->getSide(Vector3::SIDE_UP)->getId() === Block::AIR){
$item->useOn($this);
}elseif($item instanceof Shovel and $this->getSide(Vector3::SIDE_UP)->getId() === Block::AIR){
$item->applyDamage(1);
$this->getLevel()->setBlock($this, BlockFactory::get(Block::GRASS_PATH));
return true;

View File

@ -25,8 +25,8 @@ namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\Tool;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Vector3;
class GrassPath extends Transparent{
@ -41,10 +41,10 @@ class GrassPath extends Transparent{
}
public function getToolType() : int{
return Tool::TYPE_SHOVEL;
return BlockToolType::TYPE_SHOVEL;
}
protected function recalculateBoundingBox(){
protected function recalculateBoundingBox() : ?AxisAlignedBB{
return new AxisAlignedBB(
$this->x,
$this->y,
@ -59,9 +59,15 @@ class GrassPath extends Transparent{
return 0.6;
}
public function getDrops(Item $item) : array{
public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_UP)->isSolid()){
$this->level->setBlock($this, BlockFactory::get(Block::DIRT), true);
}
}
public function getDropsForCompatibleTool(Item $item) : array{
return [
ItemFactory::get(Item::DIRT, 0, 1)
ItemFactory::get(Item::DIRT)
];
}
}
}

View File

@ -25,7 +25,6 @@ namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\Tool;
class Gravel extends Fallable{
@ -44,17 +43,16 @@ class Gravel extends Fallable{
}
public function getToolType() : int{
return Tool::TYPE_SHOVEL;
return BlockToolType::TYPE_SHOVEL;
}
public function getDrops(Item $item) : array{
public function getDropsForCompatibleTool(Item $item) : array{
if(mt_rand(1, 10) === 1){
return [
ItemFactory::get(Item::FLINT, 0, 1)
ItemFactory::get(Item::FLINT)
];
}
return parent::getDrops($item);
return parent::getDropsForCompatibleTool($item);
}
}
}

View File

@ -23,7 +23,7 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Tool;
use pocketmine\item\TieredTool;
class HardenedClay extends Solid{
@ -38,10 +38,14 @@ class HardenedClay extends Solid{
}
public function getToolType() : int{
return Tool::TYPE_PICKAXE;
return BlockToolType::TYPE_PICKAXE;
}
public function getToolHarvestLevel() : int{
return TieredTool::TIER_WOODEN;
}
public function getHardness() : float{
return 1.25;
}
}
}

View File

@ -23,6 +23,7 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\block\utils\PillarRotationHelper;
use pocketmine\item\Item;
use pocketmine\math\Vector3;
use pocketmine\Player;
@ -43,17 +44,8 @@ class HayBale extends Solid{
return 0.5;
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
$faces = [
0 => 0,
1 => 0,
2 => 0b1000,
3 => 0b1000,
4 => 0b0100,
5 => 0b0100
];
$this->meta = ($this->meta & 0x03) | $faces[$face];
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$this->meta = PillarRotationHelper::getMetaFromFace($this->meta, $face);
$this->getLevel()->setBlock($blockReplace, $this, true, true);
return true;
@ -62,4 +54,12 @@ class HayBale extends Solid{
public function getVariantBitmask() : int{
return 0x03;
}
}
public function getFlameEncouragement() : int{
return 60;
}
public function getFlammability() : int{
return 20;
}
}

View File

@ -23,9 +23,8 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\enchantment\Enchantment;
use pocketmine\item\Item;
use pocketmine\item\Tool;
use pocketmine\level\Level;
use pocketmine\Player;
class Ice extends Transparent{
@ -53,29 +52,27 @@ class Ice extends Transparent{
}
public function getToolType() : int{
return Tool::TYPE_PICKAXE;
return BlockToolType::TYPE_PICKAXE;
}
public function onBreak(Item $item, Player $player = null) : bool{
return $this->getLevel()->setBlock($this, BlockFactory::get(Block::WATER), true);
if(!$item->hasEnchantment(Enchantment::SILK_TOUCH)){
return $this->getLevel()->setBlock($this, BlockFactory::get(Block::WATER), true);
}
return parent::onBreak($item, $player);
}
public function ticksRandomly() : bool{
return true;
}
public function onUpdate(int $type){
if($type === Level::BLOCK_UPDATE_RANDOM){
if($this->level->getHighestAdjacentBlockLight($this->x, $this->y, $this->z) >= 12){
$this->level->useBreakOn($this);
return $type;
}
public function onRandomTick() : void{
if($this->level->getHighestAdjacentBlockLight($this->x, $this->y, $this->z) >= 12){
$this->level->useBreakOn($this);
}
return false;
}
public function getDrops(Item $item) : array{
public function getDropsForCompatibleTool(Item $item) : array{
return [];
}
}
}

View File

@ -23,8 +23,7 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\Tool;
use pocketmine\item\TieredTool;
class Iron extends Solid{
@ -39,18 +38,14 @@ class Iron extends Solid{
}
public function getToolType() : int{
return Tool::TYPE_PICKAXE;
return BlockToolType::TYPE_PICKAXE;
}
public function getToolHarvestLevel() : int{
return TieredTool::TIER_STONE;
}
public function getHardness() : float{
return 5;
}
public function getDrops(Item $item) : array{
if($item->isPickaxe() >= Tool::TIER_STONE){
return parent::getDrops($item);
}
return [];
}
}
}

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