Compare commits

...

1552 Commits

Author SHA1 Message Date
7a77d3dc30 Merge branch 'stable'
# Conflicts:
#	resources/vanilla
2019-07-30 19:00:50 +01:00
ece28e5d7b World: avoid triggering light updates when the target block light level/filter haven't changed 2019-07-30 18:01:23 +01:00
3eb1a56985 Merge branch 'stable'
# Conflicts:
#	resources/vanilla
#	src/pocketmine/world/World.php
2019-07-30 15:38:38 +01:00
cf1b140d57 fix chunks with entities & tiles not being saved after first autosave
this bug was introduced by 211836274f, which did not take into consideration that the dirty flag is cleared after the first time the chunk is saved, meaning that later entity and tile changes wouldn't be saved.
I considered this fix more elegant than reverting the bug commit.
2019-07-29 19:38:47 +01:00
2ecdea2cc6 LevelDB: increase default block size to 64KB
this might be a little too big, but it's definitely better than the leveldb default 4KB, since most of our data is bigger than 4KB.
2019-07-29 18:54:27 +01:00
334d15339f updated Math dependency 2019-07-29 18:25:32 +01:00
c40074d0bf Entity: remove unused import 2019-07-29 18:25:05 +01:00
96d8790028 rename Entity->propertyManager -> Entity->networkProperties 2019-07-29 18:24:29 +01:00
452cfe2f59 World: drop getChunkEntities(), use getChunk()->getEntities()
everywhere this function is used, it should be assumed/expected that the chunk in question is already present and loaded.
2019-07-29 18:20:33 +01:00
a4042e5d18 World: fix more implicit chunk loading bugs (getCollidingEntities(), getNearbyEntities(), getNearestEntity()) 2019-07-29 18:07:17 +01:00
1111d0d4c7 World: remove dead function getChunkTiles() 2019-07-29 18:00:23 +01:00
17a3ca066e fix wrong type for Fuel tag on brewing stand 2019-07-29 17:50:02 +01:00
52412e9c21 remove remaining dependencies on Bearing 2019-07-29 17:45:23 +01:00
a621bf66ff Remove implied dependence on Facing/Bearing constant values
this introduces mapping tables for redundancy for when those things change or disappear.
2019-07-29 17:43:36 +01:00
18d05f57b5 Merge branch 'next-minor' 2019-07-29 17:33:08 +01:00
23b00bea5b Merge branch 'stable' into next-minor 2019-07-29 17:31:06 +01:00
f3f8cd98de World: fixed scheduled updates causing chunk loading
this probably needs to be backported.
2019-07-29 17:17:05 +01:00
b98dad6f63 Fixed WritableBook PC format deserialization 2019-07-29 16:37:40 +01:00
e06ab0869a mostly rewrite internal entity metadata handling
- Only sync the metadata set when needed for sending
- Don't use metadata set for storing data, add properties instead
- Use objects inside metadata sets instead of arrays
2019-07-28 19:40:47 +01:00
6c0ae6bf0b fuck off PhpStorm 2019-07-27 19:22:33 +01:00
379a40c13a break up the pocketmine\network\mcpe\protocol\types namespace
this namespace nesting is getting out of hand, but it's more manageable this way.
2019-07-27 19:19:48 +01:00
c9ecd04353 rename DataPropertyManager -> EntityMetadataCollection 2019-07-27 19:10:18 +01:00
cde2c10c1d AsyncTask: partial backport of 6ac0c517f5 (simplify TLS)
- deprecated AsyncTask::peekLocal()
- AsyncTask::fetchLocal() no longer deletes stored data
2019-07-27 15:09:42 +01:00
34ed2980e5 Merge branch 'next-minor' 2019-07-27 14:59:38 +01:00
87fb42cabd Merge branch 'stable' into next-minor 2019-07-27 14:53:13 +01:00
6566dd8c8f AsyncPool: Remove useless warning about complex data leftovers
this is automatically cleaned up anyway, so this warning is just redundant noise.
2019-07-27 14:44:40 +01:00
1e65ac0d85 Merge branch 'stable' into next-minor 2019-07-27 14:40:31 +01:00
cb247a5f28 AsyncTask: Deprecate methods removed in 2c4f2810d2 2019-07-26 19:52:26 +01:00
bb048fb361 Merge branch 'stable' into next-minor 2019-07-26 19:50:17 +01:00
7275952fc2 added some missing legacy ID constants
i'm not sure why my script missed these
2019-07-26 19:08:50 +01:00
a91a86bf1d Removing achievements 2019-07-26 18:07:31 +01:00
b543744534 Rename Solid -> Opaque
the old naming was misleading, particularly in conjunction with isSolid().
2019-07-22 19:56:01 +01:00
e95b9fa432 Block: use isSameType() in some places 2019-07-22 19:23:28 +01:00
72c0af2e82 Merge branch 'stable' 2019-07-22 17:39:44 +01:00
80d277f1b5 removed return value of ChunkManager->setBlockAt() and World->setBlock() 2019-07-21 18:55:22 +01:00
703ae3a172 Merge branch 'master' of https://github.com/pmmp/PocketMine-MP 2019-07-21 18:53:25 +01:00
6fdcb09891 fix PhpStorm's screwup with World->setBlock() doc comment
it's not the first time i've seen it do this, and i still have no idea why it does this.
2019-07-21 18:52:33 +01:00
a9c6489e08 updated consistency check for e388ac9c8b 2019-07-21 13:11:59 +01:00
e388ac9c8b implemented lantern 2019-07-20 17:48:09 +01:00
08a654760c Allow PlayerInfo to contain additional metadata 2019-07-20 15:19:17 +01:00
1e057394c0 Utils: added cloneCallback() and cloneObjectArray() to reduce list copying boilerplate 2019-07-19 19:19:04 +01:00
47b120fa0e crafting: avoid unnecessary recipe mutability 2019-07-19 19:11:36 +01:00
556beacdbf make PlayerAchievementAwardedEvent less useless 2019-07-19 18:59:06 +01:00
b4df1ac547 Remove Achievement::broadcast(), remove cyclic dependency, inline code in Player 2019-07-19 18:47:18 +01:00
3965c9419d Merge branch 'stable' 2019-07-19 18:20:38 +01:00
14d79c205b TranslationContainer: remove redundant setters
i'd like to make this completely immutable, but there are some problems to solve first.
2019-07-19 18:09:00 +01:00
99bba66f13 Block no longer implements BlockLegacyIds 2019-07-19 17:49:59 +01:00
1fee70abfb Item no longer implements ItemIds 2019-07-19 17:43:06 +01:00
ac12911561 move network entity IDs to network namespace
we're going to need a dedicated data package, because this stuff isn't just network-specific.
2019-07-19 15:33:30 +01:00
0ebd3e6ca2 fix /effect crash 2019-07-19 14:10:19 +01:00
5a5ce84ebc yucky fix for crash on invalid keychain 2019-07-19 14:01:21 +01:00
a4c7744188 [ci skip] changelog updates 2019-07-19 13:53:44 +01:00
c5ebc12f1a Merge remote-tracking branch 'origin/stable' 2019-07-19 13:45:53 +01:00
5e8c92b1da Fix test failure #3047 2019-07-19 13:42:03 +01:00
a8fa3ba434 Add test for whether item retains it's display properties after deserialization (#3047) 2019-07-19 13:06:07 +01:00
b5b4133c5d Item: fixed always-false null checks on getNamedTag() result 2019-07-18 19:45:59 +01:00
e22986f065 EffectCommand: Remove support for internal MCPE effect IDs 2019-07-18 19:30:20 +01:00
3632e07cdb EffectCommand: Remove internal ID from translated message 2019-07-18 19:29:43 +01:00
64948f38d0 Separate effect registry from base Effect class 2019-07-18 15:49:58 +01:00
728aa8aae7 RegistryTrait: Alias internal methods by default
it's always necessary to wrap these methods with the appropriate typehints.
2019-07-17 19:59:28 +01:00
1a1feefd3e Pull tier info out of TieredTool, create ToolTier enum 2019-07-17 18:06:49 +01:00
7954a81602 fixing finality and constructor visibility on some enums 2019-07-17 18:04:15 +01:00
ccf165b107 mark some assumed-immutable classes as final 2019-07-17 16:24:29 +01:00
6aba9fadfc Encapsulate Item enchantment handling parts within a trait for scope isolation
as a happy side effect, this makes the Item class smaller, makes the code easier to read, and also makes the code more easily testable.
2019-07-17 16:12:13 +01:00
af73c5f2b1 Make EnchantmentInstance immutable, remove enchantment clone from Item
it doesn't make sense to set the level of an existing enchantment instance because under the old API it would have no effect anyway (if it was returned from an itemstack) or you had access to the constructor (if applying a new enchantment). Allowing this to be mutable creates needless complexity and performance headaches.
2019-07-17 16:03:08 +01:00
fec8c75fd8 [ci skip] changelog: document more misc API changes 2019-07-17 15:55:28 +01:00
74572fde08 [ci skip] changelog: add some information about NBT handling changes 2019-07-17 15:52:52 +01:00
ad4ed1c95c [ci skip] expand changelog on item changes 2019-07-17 14:46:43 +01:00
382d97a178 Merge branch 'stable' 2019-07-17 13:58:43 +01:00
b57dcebb6f Living: tighten validity checks on health NBT, don't use generic getValue() (it could return anything) 2019-07-16 19:59:15 +01:00
711ea3185d update composer dependencies 2019-07-16 19:53:47 +01:00
ff21977461 Item: simplify equals()
getNamedTag() can't return null anymore.
2019-07-16 18:11:09 +01:00
49a6821195 fix @return hints on Item fluent methods 2019-07-16 18:06:21 +01:00
8f64d6b053 Don't mess with NBT when creating signed books 2019-07-16 17:59:39 +01:00
73a847123b WritableBookBase: Make setPages() fluent 2019-07-16 17:59:01 +01:00
3d0e47ba14 WritableBookBase: Don't expose page deque on the API
putting this stuff on the API creates a nightmare because DS structures are both mutable and by-reference, so they have to be manually copied everywhere.
2019-07-16 17:52:58 +01:00
27352486a0 Remove item NBT runtime usage, marginalize to serialize/deserialize
this is a more tame version of my initial attempt to firehose item NBT. It marginalizes the use of item NBT to the places where it's needed on interfaces, leaving the internals clean to operate on whatever they like.
2019-07-16 16:51:45 +01:00
d624c38ab1 Remove dead proxy functions Item::get(), Block::get() and Item::fromString()
with the introduction of the VanillaBlocks and VanillaItems API, it's expected that plugins will no longer need these methods.
2019-07-16 14:31:04 +01:00
52de5a6e49 Removed remaining usages of Item::get() 2019-07-16 14:27:32 +01:00
484f2f43c0 fixed merge error, close #3030 2019-07-14 19:29:16 +01:00
0ba3121c43 Merge branch 'stable' 2019-07-14 19:19:33 +01:00
f637f14e4a VanillaItems: fixing gold -> golden 2019-07-13 19:24:17 +01:00
1391e4826f ItemFactory: fix name consistency gold -> golden, close #3020 2019-07-13 19:21:00 +01:00
544bbf849d Merge branch 'stable' 2019-07-13 18:17:04 +01:00
6a93eb8361 Merge branch 'stable' 2019-07-13 18:08:45 +01:00
12ee885432 Bookshelf: fix drop count 2019-07-11 14:14:01 +01:00
39bcd2ec3d added VanillaItems static interface and start using it where possible 2019-07-10 14:44:55 +01:00
e8fe3d0664 Replace some ItemFactory blockitem fetches with VanillaBlocks::THING()->asItem() 2019-07-09 18:30:02 +01:00
41705db687 fix banner block picking 2019-07-09 18:21:08 +01:00
08e1f6405c implemented Carved Pumpkin 2019-07-09 17:56:09 +01:00
b6efb33b91 improved VanillaBlocks registry 2019-07-09 17:33:00 +01:00
c07396442c Merge branch 'stable' 2019-07-09 15:57:02 +01:00
5f959a148f chunkutils: remove dead legacy code 2019-07-09 14:44:01 +01:00
5a2e84eb9f LightArray: added fill(), remove duplicated code 2019-07-09 13:49:54 +01:00
4264923f4f SubChunk: get rid of dead light getters and setters
these were here for fast access, but that fast access path now goes through getBlock(Sky)LightArray() instead.
2019-07-09 13:43:01 +01:00
c1212eab8e EmptySubChunk: get rid of useless allocations 2019-07-09 13:38:26 +01:00
bda9bd2f2d Merge branch 'experimental/vanilla-block-registry' 2019-07-08 19:38:09 +01:00
9ef5f9518c generator: prevent access to chunks that don't exist on this thread
the generator shouldn't be creating chunks that it wasn't given.
2019-07-08 18:29:19 +01:00
fe3a4baddb added StairShape enum
this has no practical value to plugins yet, but it will in the future.
2019-07-08 18:08:52 +01:00
c42817f02f optimizing lighting performance a little 2019-07-08 15:39:57 +01:00
007aee72f8 SubChunk: remove BlockLegacyIds dependency, allow parameterising default block 2019-07-08 15:01:11 +01:00
4e2f430f06 shift default left instead of set value right
don't remove metadata bits for block comparison, because they could be part of the ID.
2019-07-08 14:53:19 +01:00
cdab3e967a Extract a LightArray unit from SubChunk 2019-07-08 14:37:48 +01:00
2cab22fd38 Merge branch 'stable' 2019-07-07 18:10:19 +01:00
f9bfaa0c6a Merge branch 'stable' 2019-07-06 19:41:00 +01:00
5274a0fe3c Extract an ExperienceManager unit from Human 2019-07-06 19:31:39 +01:00
da0358529a Extract a HungerManager unit from Human 2019-07-06 18:50:34 +01:00
4d7c18f65b first look at a giant static interface for block fetching 2019-07-06 17:29:40 +01:00
119cb083bf [ci skip] update changelog 2019-07-06 15:22:27 +01:00
5c25f770c2 World: reduce legacy id/meta dependencies 2019-07-06 15:21:45 +01:00
f3995f7cb0 Destroy EffectManager <-> Living cyclic reference on close (#2993) 2019-07-06 15:18:09 +01:00
a2bb6a41d9 World: some cleanup to random blocktick registry 2019-07-06 15:16:03 +01:00
ce77e283ab Revert "fix race condition between chunk generation and light population"
This reverts commit 80747814fb.
2019-07-05 19:56:58 +01:00
13de99315b fixed some artifacts getting cut in half 2019-07-05 19:56:31 +01:00
80747814fb fix race condition between chunk generation and light population 2019-07-05 19:40:33 +01:00
bda3631c24 Merge branch 'stable' 2019-07-05 19:21:49 +01:00
124640737a Explosion: make use of fromFullBlock()
this is in preparation for out-phasing legacy IDs.
2019-07-05 17:58:15 +01:00
ceeed57118 Player: remove iusername premature optimization 2019-07-05 17:28:37 +01:00
45b0cbc796 Human: remove getRawUniqueId() premature optimization
this is never used in a hot path and presents a potential for inconsistency.
2019-07-05 17:17:48 +01:00
2e01bd1029 cleanup imports from f356bf0893 2019-07-05 16:34:22 +01:00
77919b70b2 Stop cloning Color objects
since these are now immutable, there's no need to clone them.
2019-07-05 16:20:56 +01:00
f356bf0893 Extracted an EffectManager unit from Living 2019-07-05 16:15:58 +01:00
fe850a184c deal with fern mapping properly 2019-07-05 15:14:03 +01:00
2bd2e1125c Block: don't be stupid in getSide() 2019-07-05 15:04:13 +01:00
b021cc2138 ItemFactory: add PhpDoc for getAllRegistered() 2019-07-05 13:46:06 +01:00
453c5a329d Tile: remove useless code 2019-07-05 13:41:18 +01:00
ceb6529ee3 encapsulate light recalculation logic inside LightUpdate classes
now we can do a standard light recalculation from anywhere.
2019-07-04 19:55:48 +01:00
3d118a415c Merge branch 'stable' 2019-07-04 18:48:53 +01:00
3bdf740597 formatting 2019-07-04 18:04:23 +01:00
9ed13bf112 Color: make use of intdiv() 2019-07-04 18:03:45 +01:00
a125980ada utils: Color is now immutable
as is always the case with mutability, allowing this creates lots of complications that aren't worth the hassle.
2019-07-04 18:00:48 +01:00
062e692069 AAAAAAAAAAAAAAAAAAAA 2019-07-03 20:02:33 +01:00
1d96c1810f wtf PhpStorm 2019-07-03 19:20:24 +01:00
4c5d8c12dd [ci skip] more updates to changelog 2019-07-03 18:32:20 +01:00
134a87ec7d BlockFactory: regenerate TODOs 2019-07-03 18:26:01 +01:00
ee885bb725 shorten BlockToolType constants 2019-07-03 17:57:11 +01:00
85051554c4 disallow logins from players with phony XUIDs
this simplifies XUID handling.
2019-07-03 16:47:02 +01:00
e07523056d Merge branch 'stable' 2019-07-03 16:35:29 +01:00
4a6d4953f2 updated consistency check for previous commit 2019-07-03 16:19:24 +01:00
80b29250c8 added all the element blocks 2019-07-03 16:17:17 +01:00
02bbf50dbe Make DragonEgg::teleport public (#2992) 2019-07-03 15:04:17 +01:00
5b02ca8a64 InGamePacketHandler: return unhandled for command requests without a leading /
some clients send things without the /, f.e. websocket stuff, and we aren't ready to handle that properly yet. The result is that the command gets dumped directly into the chat instead of being unhandled.
2019-07-03 14:34:22 +01:00
720254f64f fix crash on falling block above the height limit, closes #2803 2019-07-02 19:56:26 +01:00
d23eeff832 FallingBlock: remove useless check 2019-07-02 19:54:56 +01:00
206b397ee1 Living: drop useless knockBack() parameters, closes #2634 2019-07-02 19:52:51 +01:00
b0a85155d7 [ci skip] add inventory changes to changelog 2019-07-02 14:06:11 +01:00
b90be8dc5f fix PhpStorm's screwups 2019-07-01 18:49:07 +01:00
7aa4d974ef move crafting stuff to pocketmine\crafting namespace 2019-07-01 18:47:09 +01:00
601ba4264d [ci skip] added incomplete changelog for 4.0 2019-07-01 17:42:18 +01:00
a325b1f3a1 Merge branch 'next-minor' 2019-07-01 17:19:57 +01:00
9e993aa83f ClosureTask: drop requirement for void return type
this creates unnecessary boilerplate for many inline usages.
2019-07-01 17:19:19 +01:00
fab12707ae Merge branch 'stable' into next-minor 2019-07-01 17:18:20 +01:00
b1ef1026ee WorldManager: Use the world's own logger to report tick overload 2019-07-01 15:24:45 +01:00
1156d5bdba batch optimize imports 2019-06-30 14:51:44 +01:00
5e5f43242e Extract a HandlerListManager unit from HandlerList 2019-06-30 14:49:09 +01:00
68bff6cf69 moved RegisteredListener to event namespace 2019-06-30 14:31:53 +01:00
80d4eeaa3c fix some occurrences of terrain truncation during generation 2019-06-29 11:14:34 +01:00
0d769aab48 Removed anti-noclip checks 2019-06-29 11:10:20 +01:00
44a205b1cc Remove MainLogger singleton and remaining MainLogger hard-dependencies 2019-06-28 16:36:17 +01:00
a4b50e57a4 move player arm swing processing to server side 2019-06-28 15:08:51 +01:00
e7733718b6 divide network\mcpe namespace into more subnamespaces 2019-06-27 19:39:59 +01:00
872b6ed708 Switch back to using fast-serialize for chunk send prepare
network serialize on the main thread is 3-5x more expensive than fast-serialize right now.
2019-06-27 19:28:47 +01:00
0e4966dfdf Split ProcessLoginTask into two tasks: 1) verify, 2) server handshake 2019-06-27 18:09:43 +01:00
193a41566d NetworkSession: Show the correct name on the player list 2019-06-27 17:04:36 +01:00
1749b57a83 ChunkManager: drop light-related methods
these were added in 2017 with the intent of async'ifying light updates. However, light updates now use an optimized code path which bypasses these functions completely, rendering them useless.
2019-06-27 16:56:46 +01:00
6da2bd4bb3 SimpleChunkManager: implement last-access performance optimization
this improves performance of writing blocks by ~30%.
2019-06-27 16:53:24 +01:00
45f5f112dd SubChunkIteratorManager now accepts $create as a moveTo() parameter instead of in the constructor 2019-06-27 16:22:56 +01:00
6f087190f4 SimpleChunkManager: added $create parameter 2019-06-27 16:13:14 +01:00
a279648c68 FastChunkSerializer: optimize palette writing 2019-06-27 15:42:10 +01:00
6838a1e07a BossEventPacket: fix crash in ::unknown6() 2019-06-27 15:16:06 +01:00
f3882dd658 Entity: remove more useless classes
these were slated for removal some time ago, but it never happened because they were used in the API. This is no longer the case on 4.0, so these classes are now entirely useless.
2019-06-27 14:23:24 +01:00
2ba76bd97d Convert UPnP into network interface
closes #2710, closes #2751
2019-06-27 13:41:58 +01:00
7f56f27505 some cleanup to held item handling 2019-06-26 19:40:40 +01:00
61d443bf4e Living: remove sendPotionEffects() network crap 2019-06-26 19:17:38 +01:00
9fe073fa73 move RakLib-specific components to mcpe\raklib namespace 2019-06-26 18:36:42 +01:00
3f9493bcd0 Remove another NetworkSession <-> NetworkInterface cyclic dependency 2019-06-26 18:22:32 +01:00
7eaca6bbaa Separate packet-sender functionality from NetworkInterface, break cyclic dependency between NetworkInterface and NetworkSession 2019-06-26 18:19:29 +01:00
9cedfeb2b2 Use the appropriate synchronization for held item rollbacks 2019-06-26 17:56:39 +01:00
f62d9cbb99 Player: rename equipItem() to selectHotbarSlot() 2019-06-26 15:52:01 +01:00
7bdb99ae8b Player: fixed consumable relying on undefined network behaviour to set using-item flags 2019-06-26 15:47:16 +01:00
eee039a490 Player: don't fire events on equipItem() when sending the same slot 2019-06-26 15:32:57 +01:00
ee72680f44 Removing "metadata": overengineered useless Bukkit copy-pasta
the intentions of this are good, but the usability is terrible and it's not fit for purpose. Since there are a total of zero plugins on Poggit which use this garbage, it makes more sense to eliminate the technical debt. See #2766 for discussion about replacing this.
2019-06-26 14:43:21 +01:00
26178b4435 InventoryManager: remove redundant cyclic dependency 2019-06-26 13:57:52 +01:00
9bebc6c69d PreSpawnPacketHandler: drop useless sending time
this is already sent in StartGamePacket.
2019-06-26 13:46:53 +01:00
4448919a8b Consider unknown chunk formats as corrupted
the reasoning for this is that the world version number should have accounted for a chunk format change. If it didn't, then we assume any chunk with a wrong version number is corrupted, since the handling of unknown formats is the same as that of corrupted chunks.
2019-06-26 13:22:45 +01:00
42b1c45fa5 Player: remove deprecated parameter from sendPopup() 2019-06-25 19:41:00 +01:00
a6395c9ac7 allow use of any iterable for enum initialization
this allows possible use of generators
2019-06-25 19:37:31 +01:00
44b7239847 SetDefaultGameTypePacket: added ::create()
not using this yet, but it was in my workspace and it might come in useful
2019-06-25 19:28:30 +01:00
e8d9acb59f added NoteSound and NoteInstrument enum 2019-06-25 19:26:18 +01:00
73938486fc added PaintingPlaceSound 2019-06-25 18:39:02 +01:00
6bbae4b2df SetDifficultyPacket: added create() 2019-06-25 18:34:12 +01:00
ec25a71396 Merge branch 'stable' 2019-06-25 18:16:36 +01:00
ff55f5e9ac Make BlockInventory non-abstract 2019-06-25 17:45:07 +01:00
8c2ca098e1 updated BedrockData submodule 2019-06-25 17:31:10 +01:00
f152ae9cbf EntityFactory: Allow registering entities without legacy numeric IDs associated
this shit really ought to be broken up into factories for each world format.
2019-06-25 17:23:41 +01:00
c19c42a934 PlayerBlockPickEvent: pre-cancel the event when picking would fail in survival 2019-06-25 16:30:07 +01:00
edccce1419 added ChunkListenerNoOpTrait to reduce chunklistener boilerplate 2019-06-25 16:23:43 +01:00
d85a27c5b2 BanList: remove useless Server dependency 2019-06-25 15:54:26 +01:00
8ec25b59a3 Remove useless $items parameter from inventory constructors 2019-06-25 15:43:55 +01:00
94ee33e47b Moved common Thread parts to trait 2019-06-25 14:57:40 +01:00
75a4136ab2 Player: fix bug in unloadChunk() causing entity artifacts on world change 2019-06-25 14:17:56 +01:00
de10e401bf Fixed wrong chunks being sent to players post-teleport or post-world-change 2019-06-25 13:41:03 +01:00
d15284e638 work on moving inventory network functionality to network layer 2019-06-25 13:28:01 +01:00
9f09dc3dd7 Player: Log a debug message when GC kicks in
I use this frequently to identify leaks. This isn't expected to appear immediately after disconnect, but it shouldn't take long to appear.
2019-06-24 17:46:30 +01:00
91580ce321 fix bug in InventoryCloseEvent 2019-06-24 17:27:12 +01:00
181cfef731 Remove a whole bunch of useless crap from PluginLogger
this is pretty much just an implementation of a NTS attachable logger now. It should probably be converted into a trait.
2019-06-23 19:39:40 +01:00
197a56e3e1 move BookEditPacket handler out of Player 2019-06-23 19:23:20 +01:00
3103579ba6 Merge branch 'stable' 2019-06-22 20:26:21 +01:00
6db2a3a0fb Merge branch 'next-minor' 2019-06-22 19:49:18 +01:00
51f299f196 Merge branch 'stable' into next-minor 2019-06-22 19:46:23 +01:00
0273bd4f53 Merge branch 'next-minor' 2019-06-22 16:05:17 +01:00
2bb52cf811 Merge branch 'stable' into next-minor 2019-06-22 16:03:28 +01:00
6afc689529 Add Level->getTimeOfDay(), closes #2908 (#2979) 2019-06-22 16:00:18 +01:00
ce74549ba3 Use 10 bits for Y coordinate in blockhash
fixes #2553
2019-06-22 15:53:56 +01:00
ff8ca99c9f CrashDump: revert removal of RCON password redact in 738e310798
there's guaranteed to be some plant pot who uses 4.0, leaks his RCON password, downgrades back to 3.x, and then gets hacked.
2019-06-18 19:53:43 +01:00
c5707f6174 update DevTools submodule 2019-06-18 18:58:53 +01:00
2559f5ec2b Moved Player-related classes to pocketmine\player namespace 2019-06-18 18:51:36 +01:00
e82a40b2ba forgot to stage this for b18bd4f33c 2019-06-18 17:37:38 +01:00
c66af4648c Move thread-related classes from pocketmine to pocketmine\thread namespace 2019-06-18 17:36:25 +01:00
075f49aef0 don't send double disconnect messages 2019-06-18 16:22:41 +01:00
709963f90a shut up PhpStorm 2019-06-18 16:07:43 +01:00
b18bd4f33c rename SessionHandler -> PacketHandler 2019-06-18 16:02:46 +01:00
87c3636d44 ResourcePacksSessionHandler: moar debug 2019-06-18 15:10:58 +01:00
94299534b3 NetworkSession: fix some blind spots on logging 2019-06-18 15:01:44 +01:00
9df2ca3655 fixup some formatting issues 2019-06-18 14:12:37 +01:00
bb675ac99b Set parallel bootstrap file if the extension is loaded 2019-06-18 14:05:39 +01:00
7b049b6db1 NetworkSession: use a better check for timeout 2019-06-17 17:30:42 +01:00
e0a9ea2573 Player: clean up some crazy spawn logic in constructor
this was probably a leftover from some old code, I guess
2019-06-17 17:07:31 +01:00
db3305cb16 Remove Entity->isClosed() checks from places where they don't make sense
in all of these cases, this is just potentially concealing bugs. Closed entities should never appear at these points.
2019-06-17 16:39:46 +01:00
92e81e3298 Player: move some respawn net sync logic to NetworkSession 2019-06-17 16:27:04 +01:00
3c677bd3ec added PermissibleDelegateTrait to cut down boilerplate in Player and ConsoleCommandSender 2019-06-17 16:10:13 +01:00
20f092a685 Living: Do not use spl_object_id() for identifying effects
it's possible for these to have different IDs if they were cloned, serialized or copied between threads.
2019-06-17 15:58:33 +01:00
fe98b6c765 EnumTrait: rename getEnumName() -> name()
this is more concise and brings it more in line with Java.
2019-06-17 14:55:25 +01:00
c45c1c930e SetEntityMotionPacket: Mark as garbage serverbound 2019-06-17 14:22:08 +01:00
b344427a30 Added a hack to allow dropping garbage serverbound packets sent by a buggy client 2019-06-17 14:20:29 +01:00
698193622a WorldManager: rename get/setAutoSaveTicks() to get/setAutoSaveInterval()
this is less ambiguous.
2019-06-16 18:23:13 +01:00
4878fc4c93 Merge branch 'stable' 2019-06-16 17:18:17 +01:00
b71bb867f4 DefaultPermissions: remove pocketmine.command.reload 2019-06-16 16:52:47 +01:00
94180cda72 Merge branch 'next-minor' 2019-06-16 16:42:05 +01:00
5a17a0d1aa Merge branch 'stable' into next-minor 2019-06-16 16:37:23 +01:00
b38c81c96f backport f84a1729c: Inventory: added swap() function 2019-06-16 16:35:34 +01:00
0fabc0c199 backport b8d1eb20b: EntityDeathEvent: add XP amount API, closes #2690 2019-06-16 16:31:03 +01:00
ec5598dbb1 Deprecate things removed in acb794e72 and 97c836f19 2019-06-16 15:37:27 +01:00
5d3b4f23a3 Merge branch 'next-minor' 2019-06-16 14:52:37 +01:00
7b98d203f4 Merge branch 'stable' into next-minor 2019-06-16 14:47:01 +01:00
4635b93f4d backport 23071d257 + deprecations: Extract process-related functions from Utils into a separate Process class 2019-06-16 14:40:51 +01:00
a8433697ad backport aaaddd1fd: Terminal: stick a RESET on the end when writing a newline 2019-06-16 14:25:16 +01:00
680cdb8e3e backport f5dbbea5f: Utils: added recursiveUnlink() 2019-06-16 14:20:05 +01:00
eaa78fe849 backport 205e13d88: Config: add getPath() (#2758)
Config->getPath() returns the path of the config i.e. the place where the config file is located.
2019-06-16 14:18:50 +01:00
eedea4998b Terminal: Added write() and writeLine() to allow easily emitting Minecraft-formatted text to the console 2019-06-16 14:16:14 +01:00
4e5a80c481 Recipe: deprecate interface 2019-06-16 14:12:49 +01:00
4d54dc30c1 crafting: deprecate some stuff that's been removed on bleeding edge 2019-06-16 14:11:08 +01:00
ac5339414a Merge branch 'stable' into next-minor
# Conflicts:
#	build/preprocessor
2019-06-16 14:08:06 +01:00
4e734989bc fixing add/remove items from anvil & enchanting table
the functionality of these don't work yet, but the inventories work more correctly now.
2019-06-15 18:56:42 +01:00
93b83b4189 Player: Window system now only allows 1 window at a time 2019-06-15 18:19:09 +01:00
312a755a27 Player: rename $windows to $inventoryNetworkIdMap 2019-06-15 15:51:43 +01:00
a94541c531 Split CreativeInventoryAction into two new action types 2019-06-15 14:40:15 +01:00
4bbf1d56dc NetworkInventoryAction: shorten exception message
This is logged with the network session's logger, which provides context information already.
2019-06-15 14:27:11 +01:00
50a7fc0ba3 Rework inventory window open/close handling
- This fixes InventoryOpenEvent and InventoryCloseEvent being fired for persistent windows. Close #2950
- The ability to specify a custom network ID to assign the inventory to in addWindow() has been removed.
- The ability to assign a non-removable window in addWindow() has been removed.
- The ability to remove non-removable windows in removeWindow() and removeAllWindows() has been removed. This was previously needed for internal purposes.
2019-06-15 14:23:02 +01:00
c77e75fa93 FastChunkSerializer: fix typo 2019-06-14 19:42:50 +01:00
468340d55b this was stupid 2019-06-14 19:41:19 +01:00
8356285b66 Consistently call InventoryCloseEvent
this wasn't being fired when a plugin did the removal.
2019-06-14 19:39:35 +01:00
f671f2ebfa Inventory: drop useless proxy functions 2019-06-14 19:37:45 +01:00
787d305c2a Player: call InventoryOpenEvent consistently 2019-06-14 19:32:38 +01:00
2cb6fda286 Moved network chunk serializing code to network\mcpe namespace 2019-06-14 18:25:06 +01:00
08de657c8d Extract FastChunkSerializer unit from Chunk
this functionality doesn't directly pertain to Chunk functionality.
2019-06-14 18:19:46 +01:00
92035ac2ec Chunk: drop premature optimizations 2019-06-14 18:07:13 +01:00
722da5e88d Simplify hasChanged handling for chunk init
we always want chunks to be saved if they have tiles or entities
2019-06-14 18:00:37 +01:00
c8eefddfc0 Chunk: fix tiles not being loaded from NBT in some cases 2019-06-14 17:59:00 +01:00
211836274f World: remove redundant checks
when entities are added and removed which are savable, the dirty flag is set anyway, so these checks aren't needed.
2019-06-14 17:47:39 +01:00
9e9de1e8ba Log a debug message when receiving a mismatch transaction 2019-06-13 19:52:53 +01:00
da4c646d27 Simplify InventoryAction implementation
none of these action types are able to fail now.
2019-06-13 18:35:05 +01:00
44be2179c4 SlotChangeAction: fix feedback loop 2019-06-13 18:31:25 +01:00
8551d1e282 Remove Inventory->sendSlot() and Inventory->sendContents()
the plan is to remove this from inventory entirely and use listeners for this.
2019-06-13 18:14:11 +01:00
7ba1dd3242 BaseInventory: remove setSize()
no inventory is designed to deal with this. Changing this can break transactions, specialized logic like double chest / furnace and more.
2019-06-13 17:24:17 +01:00
f128fc1849 Merge branch 'stable' 2019-06-13 16:07:00 +01:00
6bd67730eb AsyncWorker: use a shorter name on logs 2019-06-13 14:00:26 +01:00
e95d81e04b Server: fix possible comparison bug in load orders 2019-06-12 19:50:27 +01:00
31f0576725 Server: remove useless constructor assignment 2019-06-12 19:47:51 +01:00
8afea36919 Clean up some internal commands protocol handling 2019-06-12 19:35:14 +01:00
4364d2a942 AvailableCommandsPacket: Clean up internals
this is still disgusting, but it's a little more bearable now.
2019-06-12 16:54:30 +01:00
9765d78a5d Merge branch 'stable' 2019-06-11 19:19:32 +01:00
858f440bcf TimingsHandler: return the result of $closure() for easier usage
this isn't type safe, but it doesn't matter a whole lot, and there's nothing we can do about it without generics.
2019-06-11 15:04:30 +01:00
de6053de11 TimingsHandler: use a try/finally block in time() 2019-06-11 14:54:54 +01:00
f349a58f2b TimingsHandler: added time(Closure) function
I find myself often using try/finally blocks to avoid accidentally forgetting to stop a timer. This allows a cleaner more concise way of doing it.
2019-06-11 14:46:19 +01:00
1c69226187 NetworkSession: add an extra debug 2019-06-11 09:55:32 +01:00
8e6f21afad clean up gamemode net sync 2019-06-10 19:58:14 +01:00
f0d56f25b6 Moved creative inventory sync to NetworkSession 2019-06-10 19:54:24 +01:00
dd45753fa9 NetworkSession: add some more debug 2019-06-10 19:47:02 +01:00
3ac0c98199 De-spaghettify spawn notification handling 2019-06-10 19:31:54 +01:00
714393820f MainLogger: Use millisecond precision on log timestamps 2019-06-10 19:14:08 +01:00
3175a319a2 Merge branch 'stable'
# Conflicts:
#	resources/vanilla
#	src/pocketmine/VersionInfo.php
2019-06-10 18:20:01 +01:00
419fc418fe SubChunk: reduce memory usage on fast-deserialized chunks
this saves about 25MB RAM on an idle server on HEAD commit with 856 chunks loaded.
2019-06-10 15:52:21 +01:00
261ba017a6 Merge branch 'stable' 2019-06-10 11:15:17 +08:00
c1f900ab18 Start using transactions for block placement 2019-06-08 18:56:27 +01:00
f84040a7ad FlowerPot (tile): Allow BlockFactory to determine id/data validity 2019-06-08 17:55:50 +01:00
1b629d7ac0 implement daylight sensor power recalculation 2019-06-08 17:52:47 +01:00
73964e6e2f Always do chunk relighting for unlit chunks on load
this is necessary because we stopped saving light info some time ago, so it has to be calculated on load for things to work properly.
2019-06-08 17:47:55 +01:00
ad1b9e5cdd fix item pickup animation 2019-06-08 17:35:56 +01:00
43dfc8ae0f Remove update mechanism for tiles, delegate to block instead
block handles triggering tile update on furnace for now.
2019-06-08 15:44:38 +01:00
fefc9b5278 wtf PhpStorm 2019-06-07 19:36:56 +01:00
5e88fda824 added BrewingStand tile (implementation incomplete)
since we already have a partial implementation of brewing stand, we should also have the corresponding tile so that PM doesn't create any more busted blocks.
2019-06-07 19:29:26 +01:00
3bc8244673 proper remapping for the old all-sided-log bug block 2019-06-07 19:25:44 +01:00
659cad0eff BlockFactory: added a hacky method to allow block state remapping
we need this for fixing old data in some cases
2019-06-07 18:31:37 +01:00
f30cee15ca added Dried Kelp block 2019-06-07 18:03:17 +01:00
a2274429ab Chest: constrain pair positions to immediately horizontally adjacent blocks
under normal circumstances a chest will never pair with a chest which isn't directly next to it anyway.
2019-06-07 17:24:59 +01:00
cc6296b019 Furnace: give some properties clearer names 2019-06-07 15:41:32 +01:00
7eb9b33fd6 Extract a CreativeInventory unit from Item
this will probably undergo further changes, but I'm primarily interested in just encapsulating the existing functionality for now.
2019-06-07 14:24:03 +01:00
41039cecc1 Furnace: remove redundant network properties
these properties are continuously updating when the furnace is active, but they never trigger cache destruction, which means this is sending outdated garbage over the network, which is entirely unnecessary anyway.
2019-06-07 14:15:47 +01:00
857092cf65 Furnace: Use the correct method to sync furnace fuel max burn time to the client 2019-06-07 14:06:17 +01:00
741d2a7380 devtools rollback 2019-06-07 10:49:58 +01:00
b0071ed703 Revert "remove PluginBase->getFile()"
This reverts commit 67321bb3f6.
2019-06-07 10:44:52 +01:00
b5805c2d0a Extract a ResourceLoader unit from PluginBase
this will allow addressing the resource accessing crash issue for script plugins, once fully implemented.
2019-06-06 19:32:23 +01:00
67321bb3f6 remove PluginBase->getFile()
this is in preparation for opening the doors to more exotic kinds of plugin loaders, such as eval()d or web plugins.
2019-06-06 18:35:47 +01:00
d176f6f1ca update DevTools submodule 2019-06-06 18:35:05 +01:00
f8a7766880 PluginBase: remove useless function
it's possible to check the loader instance instead of doing this, and we're gunning to get rid of the path from the plugin base.
2019-06-06 18:22:20 +01:00
44c791f03e Thread/Worker run() are now final, to set up common environment things 2019-06-06 16:44:32 +01:00
e07f3e8e65 fine, variadics are annoying and this is easy to break ... 2019-06-06 15:12:46 +01:00
5c5fbf9b78 fixed oopses in 287c8c2dd4 2019-06-06 15:09:35 +01:00
32c832c87e Merge branch 'stable'
# Conflicts:
#	resources/vanilla
#	src/pocketmine/Server.php
#	src/pocketmine/item/Item.php
#	src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter.php
#	src/pocketmine/network/mcpe/RakLibInterface.php
#	src/pocketmine/network/query/QueryHandler.php
#	src/pocketmine/utils/Utils.php
2019-06-06 15:04:05 +01:00
61afc7b62c NetworkSession: report the zlib error that happened 2019-06-06 14:16:04 +01:00
9f0a184a5d Packet: Remove mayHaveUnreadBytes()
this was an old hack to prevent debug spam being emitted when we halted decoding of logins over breaking protocol changes. Since then, we've gone back to trying to decode the packet regardless, so this property is useless.
2019-06-05 15:37:35 +01:00
3b5df90b0b BossEventPacket: add some functions to ease creation 2019-06-05 15:14:37 +01:00
287c8c2dd4 Added static create() functions for many packets
There are a few motivations here:
1) Less boilerplate code (this can be written inline)
2) It's possible to provide multiple constructors for different packet variations to reduce the chance of errors.
3) It makes things catch fire on updates in ways that static analysers can understand.
2019-06-05 15:00:08 +01:00
09afb8e772 Living: don't create MobEffectPacket directly 2019-06-04 19:53:08 +01:00
cda565ba8c Merge branch 'stable'
# Conflicts:
#	resources/vanilla
#	src/pocketmine/inventory/ArmorInventory.php
2019-06-04 18:19:47 +01:00
6f29fe063f move PlayerListPacket sending responsibility to NetworkSession 2019-06-04 18:02:36 +01:00
89d4f596bd World: add and use a prefixed logger in some places 2019-06-04 14:23:40 +01:00
3c3e5a9850 ConsoleCommandSender: Do not hard-depend on MainLogger
this dependency makes it impossible to swap out.
2019-06-04 14:06:45 +01:00
5d16a48361 FormatConverter: Follow the standard format for log prefix 2019-06-04 14:04:29 +01:00
0ae3c734ea RakLibInterface: remove unused variable 2019-06-04 14:00:01 +01:00
f5b149a022 RakLibInterface: Use the session's own logger to report handling errors 2019-06-04 13:56:52 +01:00
6743234461 AutoUpdater: add a prefixed logger 2019-06-04 13:51:17 +01:00
e69ab60034 MemoryManager: use prefixed loggers 2019-06-04 13:49:07 +01:00
3569f8dfbe QueryHandler: move to a prefixed logger 2019-06-04 13:44:35 +01:00
df0acea2f4 Player: add a prefixed logger 2019-06-03 19:30:26 +01:00
56a4e8c032 Hopper: add more boilerplate code to fix inventory leak 2019-06-03 19:17:13 +01:00
7a05c46ff6 Merge branch 'stable'
# Conflicts:
#	resources/vanilla
2019-06-03 18:21:49 +01:00
8e24e5655a Merge branch 'stable'
# Conflicts:
#	resources/vanilla
#	src/pocketmine/entity/Attribute.php
2019-06-03 17:45:25 +01:00
087df45a3c added some effect ID constants 2019-06-03 16:17:36 +01:00
9d42bc3c0c updated consistency check for ad79e6cd8e 2019-06-01 12:12:55 +01:00
ad79e6cd8e partial implementation of hopper (just enough to load/save all data) 2019-05-31 19:32:19 +01:00
e091cfe1de interface Container extends InventoryHolder 2019-05-31 18:59:18 +01:00
df8db3b8e3 Merge branch 'stable' 2019-05-31 17:13:13 +01:00
efe30ffb07 Merge branch 'stable'
# Conflicts:
#	resources/vanilla
2019-05-31 15:31:32 +01:00
1049ffecc9 Sound->encode() now accepts Vector3|null
this will be needed for proper no-relative sound support.
2019-05-30 19:51:27 +01:00
77ace57985 BlockEventPacket: added a ::create() method 2019-05-30 19:44:29 +01:00
790c2cd4b7 added missing Monster Spawner tile 2019-05-30 19:26:16 +01:00
1bf5c74053 added missing DaylightSensor tile 2019-05-30 19:00:38 +01:00
f18da8d879 Added missing tile for Note Block
this doesn't come with a full impl because that requires some further changes like adding materials, which is out of the scope of this commit. This is here to prevent additional data loss in imported worlds.
2019-05-30 18:53:20 +01:00
ece4d99c1e fix crash on invalid NBT during itemstack decoding 2019-05-30 09:53:20 +01:00
3d8cd54f16 Update composer dependencies 2019-05-30 04:26:06 -04:00
f3daf612ee Merge branch 'stable' 2019-05-27 19:12:29 +01:00
bcff124953 BaseRail: move reconnect attempt to post-place hook 2019-05-27 17:55:19 +01:00
28f3322337 Block: add onPostPlace() hook 2019-05-27 17:30:57 +01:00
11d21448fc Utils: remove dead function 2019-05-27 17:12:33 +01:00
7eb8d8e366 Require Closures in more places instead of callable
Non-closure callables have strange context-dependent behaviour and are slower to call than a closure. It's possible to use Closure::fromCallable() in the origin scope, which guarantees that the callable will remain callable no matter where it's used.
2019-05-27 17:11:35 +01:00
2720ff9607 Skin: debloat geometry in constructor directly 2019-05-27 16:45:55 +01:00
89242543b9 Clean up Skin error handling, close #2926
Skin->__construct() now does all the validation.
2019-05-27 16:20:46 +01:00
0a891f5408 Move some things out of LoginPacket and into the handler 2019-05-27 16:06:53 +01:00
3902a3c28c Require opting into receiving cancelled events instead of opting out (#2906)
Warning for plugin developers: This is a silent BC break. It won't raise any errors.

This alters the default behaviour of event handlers to **not** receive cancelled events by default.
It is now required to opt into receiving cancelled events by using the @handleCancelled directive (or the handleCancelled parameter where it's appropriate).

The ambiguous @ignoreCancelled directive is now ignored.

Ramifications:
- The majority of handlers with `if($event->isCancelled()) return;` no longer need such checks.
- Handlers with `@ignoreCancelled true` or `@ignoreCancelled` annotations can have them removed.
- Handlers which want to receive cancelled events need to use `@handleCancelled`.
2019-05-27 15:47:58 +01:00
2eb498b84c ItemFactory: add getAllRegistered() 2019-05-26 19:45:47 +01:00
c1a7d86670 leveldb: more historical versions 2019-05-26 19:35:18 +01:00
e6048e115e leveldb: add more chunk versions 2019-05-26 18:01:24 +01:00
2c40fbfe11 add some TODOs for tiles 2019-05-26 16:27:20 +01:00
33d1203bfd Player: move sendAllInventories() to network layer 2019-05-26 15:58:03 +01:00
85718e2750 Clean up a bunch of garbage in Furnace 2019-05-26 15:43:46 +01:00
32e03cd92d DoubleChestInventory: remove duplicated code 2019-05-26 15:01:32 +01:00
685f5d562b DoubleChestInventory: fixed use of void result 2019-05-26 14:48:52 +01:00
d23dbc69f1 BlockFactory: Alias some classes to improve readability 2019-05-25 19:59:24 +01:00
a44d47fd3c BlockFactory: Consistently use aliases to refer to tiles 2019-05-25 19:25:42 +01:00
b329cac3d2 Move pocketmine\tile\* to pocketmine\block\tile\* 2019-05-25 19:23:43 +01:00
066eadd687 Move responsibility of copying block-picked item NBT to Block instead of Player 2019-05-25 19:00:11 +01:00
c29523baf4 added a bunch of new blocks 2019-05-24 19:59:03 +01:00
54216c2fee Block: Blow away a bunch of useless classes 2019-05-24 19:38:43 +01:00
d25ecbebd4 Merge branch 'stable' 2019-05-24 17:33:51 +01:00
3ea8da2dd3 Use EnumTrait->equals() instead of direct comparison
It's not guaranteed that objects provided are the same as those in the enum registry, so they can't be directly compared.

Implementing comparison with === would require some kind of __equals() implementation or an extension to hook into such functionality.
2019-05-24 17:21:44 +01:00
9ce1e29a17 Player: fixed bow shooting, closes #2931 2019-05-24 15:58:00 +01:00
1c99602a3f Player: give some inventory vars clearer names 2019-05-20 19:38:53 +01:00
297ca25123 remove usage of inventory network IDs for marking permanent windows 2019-05-20 16:45:46 +01:00
cd0f0cb66c missed this in previous commit 2019-05-20 16:45:00 +01:00
d6ce3f82b1 Inventory: remove redundant return values 2019-05-20 16:30:00 +01:00
c21a25efb9 move more rollback handling to network handlers, out of Player 2019-05-20 16:13:14 +01:00
04d0b6c054 don't spam listeners with slot-change notifications when doing a content change 2019-05-20 15:45:15 +01:00
c13b352b76 fix armour not being set correctly on entity spawn 2019-05-20 15:31:23 +01:00
d9bc48bb01 CraftingGrid: Remove redundant overrides
the network session knows not to send this stuff because it's not associated with any window ID.
2019-05-20 15:15:20 +01:00
bca0833035 Clean up handling of armour sync 2019-05-19 16:56:10 +01:00
cd103cefcc Redesign inventory listening API
given that inventory listeners are no longer allowed to fiddle with the outcome of changing contents, it's now possible to allow having multiple listeners receiving events.

It's likely that this will be used for network inventory sync in the near future.
2019-05-19 16:36:38 +01:00
dec6c9f49b Removed EntityInventoryChangeEvent and EntityArmorChangeEvent
there is nothing that these events do that can't be fulfilled by transactions. They complicate the internal implementation and produce unexpected behaviour for plugins when cancelled.

TL;DR: Use transactions. That's what they are there for.
2019-05-19 16:02:03 +01:00
67affcea32 move more packet logic to net session
it seems like net session is turning into a giant dumping ground for sending API ... this needs to be cleaned up somehow.
2019-05-19 15:48:01 +01:00
57219abc9d fix test failure 2019-05-18 20:20:33 +01:00
c3c2dd3988 Rename SimpleSessionHandler -> InGameSessionHandler
the "simple" name comes from the early days of this refactor before I started splitting everything up into their own units. This handler is now in good enough condition to have a proper name.
2019-05-18 19:13:41 +01:00
fa9fcea189 SimpleSessionHandler: Do not read blocks from world in onFailedBlockAction()
the world will do this anyway, so we can reduce our code burden here.
2019-05-18 19:11:23 +01:00
d44ec702b0 Added BlockDataValidator::read5MinusHorizontalFacing() 2019-05-18 17:42:03 +01:00
b11d3b0401 CraftingDataPacket: Fixed uncaught exception in decode
this is not exploitable because it's not a serverbound packet, but it should be fixed nonetheless.
2019-05-18 17:19:44 +01:00
cd8645ff20 Removed PalettedBlockArray stub
the SubChunkConverter stub was accidentally removed in dd914e0752, but no great harm done ...
2019-05-18 15:15:20 +01:00
6de0b48c1f PacketBatch: Always encode packets freshly, never reuse buffers
this causes bugs when a packet is modified during events and then re-sent to a player. Since we can't control this, we can't allow this kind of buffer reuse.

The only notable case where this will cause loss of performance is when broadcasting a series of packet(s) which accumulate to less than 256 bytes, which is reasonably cheap to encode anyway.
In addition, removing this caching is one roadblock to moving this serialization to native code, which will make it vastly faster.
2019-05-17 18:04:51 +01:00
64f7f558a4 Merge branch 'stable'
# Conflicts:
#	resources/vanilla
#	src/pocketmine/entity/Human.php
2019-05-17 17:43:30 +01:00
0f398bbe66 LevelDB: Added conversion of legacy extradata -> 4D subchunk block layers 2019-05-17 17:15:45 +01:00
f7a9da4e92 PillarRotationTrait: Allow axis shift to be defined by the includer 2019-05-16 18:02:03 +01:00
dd914e0752 Block: move all legacy metadata constants into a dedicated class
this makes it easier to see what is using metadata (and makes it easier to get rid of later).
2019-05-16 16:55:44 +01:00
1898db840d BlockFactory: more collapsible region things 2019-05-16 14:36:02 +01:00
642c16dfe7 added some //region ... //endregion 2019-05-16 14:35:34 +01:00
ff2600a0d0 Regenerated TODOs for BlockFactory and ItemFactory
also added //region and //endregion for IDE collapsibility
2019-05-16 14:20:51 +01:00
5024de38b8 added more types of stone slab 2019-05-15 18:15:25 +01:00
9ea684581f Merge remote-tracking branch 'origin/stable' 2019-05-13 18:17:42 +01:00
fd413b512e Remove useless Dandelion class
this class is line-for-line identical to the Flower class.
2019-05-12 18:42:49 +01:00
10831821be Anvil: fix wrong visibility for recalculateBoundingBox() 2019-05-12 17:58:45 +01:00
85c6eb5003 Fence: cleanup some BB handling 2019-05-12 16:22:41 +01:00
166d821bcf Stair: some BB handling cleanup 2019-05-12 16:22:20 +01:00
d6b720b55d Wall: minor BB calculation cleanup 2019-05-12 16:21:52 +01:00
a19651a8dc Painting: reduce complexity of getPaintingBB()
this makes it easier to unit-test.
2019-05-12 16:15:31 +01:00
adf4639625 Painting: Clean up painful BB calculation code 2019-05-12 16:10:51 +01:00
db4dac6d45 World: Remove incorrect isSolid() check for placement collision check
isSolid() != can be collided with. That's decided by the collision boxes provided, if any.
2019-05-12 16:00:38 +01:00
90e6073202 Vine: Clean up awful bounding-box calculation
the logic here is deceptively simple, just obscured by a lot of really nasty code.
2019-05-12 15:58:28 +01:00
41d754de5a Vine: fix bug when reading state multiple times 2019-05-12 15:03:44 +01:00
c99846e069 Unify Item constructor style
this exposed a few more dead classes.
2019-05-11 18:24:21 +01:00
51f96b195e ItemFactory: fix wrong typehint 2019-05-11 18:02:18 +01:00
0bf7fd2c0d Partially revert "Separate block break-info to a separate dynamic unit"
This reverts commit 9e72bc91a2.
2019-05-11 09:46:20 +01:00
650e186481 Removed bad assumption that every Flowable descendent is an instant-breaking block
I'm wondering if there is even a point to Flowable at this point. Half of the blocks inheriting from it do not break instantly, or have some other modification to tool requirements.
2019-05-10 17:00:01 +01:00
01ad568256 Air: use BlockBreakInfo::indestructible() 2019-05-10 16:30:14 +01:00
9e72bc91a2 Separate block break-info to a separate dynamic unit 2019-05-10 16:24:59 +01:00
3be5de4570 Separate WoodenTrapdoor from Trapdoor, fixed iron trapdoors being valid furnace fuel, closes #2914 for bleeding-edge 2019-05-09 19:30:18 +01:00
5eb3c52a37 added PunchBlockParticle, encapsulate more network logic 2019-05-09 15:40:58 +01:00
51a8c2be9d Player: Move rollback responsibility to network for interact/break block
Custom player implementations might not need rollbacks (f.e. Specter).
2019-05-09 14:54:56 +01:00
ca7c23c137 Player: remove dead functions
these functions belong in the network session, and they are currently just proxies for them. In the future we might have players who don't have IPs at all depending on how they connected (for example Specter) so this stuff shouldn't be in here.
2019-05-08 19:47:25 +01:00
4634baeb02 Player: don't repeat yourself 2019-05-08 19:38:57 +01:00
cf73c7f5c1 Cleanup to world provider exception handling 2019-05-08 18:26:41 +01:00
a51c06116a Merge branch 'stable' 2019-05-08 17:04:37 +01:00
19ac0811f4 Player: remove deprecated title functions 2019-05-08 16:44:18 +01:00
a331c5e13f Player: reduce SetTitlePacket creation boilerplate
it's better to encapsulate all this logic in one place so that third party developers can more easily understand this, and also to reduce the amount of crap we have in Player.
2019-05-08 16:43:05 +01:00
9fbf41b9a1 Merge branch 'stable' 2019-05-08 15:41:17 +01:00
fc90cdcc95 fix #2910 WorldManager->getLevel() missed in refactor 2019-05-08 14:05:42 +01:00
cf0c0e72a9 Assume the player is online when they are, uh, assumed to be online
the checks removed here should never be hit under normal circumstances. If they were hit, they'd just conceal bugs which would cause a crash to happen later anyway.
2019-05-07 19:49:06 +01:00
78bb6f4a0c Reduce complexity of chunk sending system 2019-05-07 19:26:01 +01:00
51548d1a27 World: remove useless internal function
this just complicates the logic for no reason. It had a purpose once, but no longer.
2019-05-07 18:51:26 +01:00
c1a483a36d move entity spawning logic back to Player 2019-05-07 18:35:04 +01:00
d7a7ab5102 Move Entity despawn logic back to Player
this is not network-session specific, and different implementations will need to do this.
2019-05-07 18:01:23 +01:00
66481fedeb Entity: Protect internal methods setPosition() and setPositionAndRotation()
teleport() should be used instead (or setRotation() for rotation-only changes).
2019-05-07 17:38:33 +01:00
00944eff72 Removed EntityWorldChangeEvent
there's nothing that can be done with this event that can't be done with EntityTeleportEvent. Having this extra event needlessly increases system complexity.
2019-05-07 17:37:10 +01:00
cb3a225d45 Merge remote-tracking branch 'origin/stable' 2019-05-07 17:28:07 +01:00
3cd6e12e71 Renaming "Level" -> "World" (#2907)
This has been a pain point for a long time due to the misleading nature of the name "level". It's also confusing when trying to do things like getting the XP level of the player or such, and also does not translate well to other languages.

This transition was already executed on the UI some time ago (language strings) and now it's time for the same change to occur on the API.

This will burn a lot of plugins, but they'll acclimatize. Despite the scary size of this PR, there isn't actually so many changes to make. Most of this came from renaming `Position->getLevel()` to `Position->getWorld()`, or cosmetic changes like changing variable names or doc comments.
2019-05-07 14:47:28 +01:00
427e334426 rename PacketStream to PacketBatch 2019-05-06 19:58:02 +01:00
ce61c6e0fd PacketStream: added fromPackets() sugar 2019-05-06 19:54:42 +01:00
3415edf600 PacketStream: add @throws 2019-05-06 17:46:37 +01:00
c2771eba88 use the appropriate API for decoding packet batches 2019-05-06 17:46:17 +01:00
82974e0271 NullSessionHandler: possibly premature optimization 2019-05-06 17:28:56 +01:00
685481b172 NetworkSession: improve GC performance without crashing everything
this is necessary because some handlers have circular references to the session, which causes GC lag collecting them. This change allows them to be collected immediately without nuking internal state.
2019-05-06 16:43:05 +01:00
5250a432d1 NetworkSession: add a dedicated PrefixedLogger, clean up some boilerplate code 2019-05-06 16:32:34 +01:00
7ae84944ca protocol: add some missing interfaces for new packets 2019-05-02 17:35:54 +01:00
6b4c11febb Merge branch 'next-minor' 2019-05-02 17:26:02 +01:00
9fd922fe6a Merge branch 'stable' into next-minor 2019-05-02 17:25:29 +01:00
af07ffb292 Merge branch 'next-minor' 2019-05-02 16:44:50 +01:00
fdaf9dce73 Merge branch 'stable' into next-minor 2019-05-02 16:39:05 +01:00
0317b0f22d Merge branch 'next-minor' 2019-05-02 15:07:38 +01:00
732e27751c Merge branch 'stable' into next-minor 2019-05-02 15:04:23 +01:00
1730415643 Player: remove useless checks from spawnTo(), closes #2897
this was caused by changes on 4.0, but this code is nonetheless useless.
2019-05-01 14:43:11 -04:00
293311569d Merge branch 'next-minor' 2019-05-01 18:55:49 +01:00
932c489de1 Rename addTitle/addSubTitle/addActionBarMessage prefixes to "send", deprecated old variants
closes #2896

these deprecated methods will be removed in 4.0.
2019-05-01 18:54:20 +01:00
67e75d6c0a Moved DataPropertyManager to network namespace
this is _extremely_ network-focused code.
2019-04-26 18:57:44 +01:00
854a2f5135 Move a giant heap of network garbage out of Entity 2019-04-26 18:52:38 +01:00
ea8c723092 EntityFactory: added some documentation 2019-04-26 18:15:31 +01:00
854c3a816c LevelManager::generateLevel(): avoid multiple return points
this could cause unexpected results if additional code is added after background generation in the future.
2019-04-26 18:05:34 +01:00
7c7f42eba6 Added API method to get & set autosave interval 2019-04-26 18:01:40 +01:00
6aa8276532 Revert "Player: removed useless addActionBarMessage()"
This reverts commit 7d22b2a6d7.
2019-04-26 15:41:19 +01:00
6a2d1fbdda Merge branch 'stable' 2019-04-26 15:06:46 +01:00
4ca40a21ae Merge remote-tracking branch 'origin/stable' 2019-04-26 06:24:07 -04:00
7ec926867f Merge branch 'stable' 2019-04-25 20:54:23 +01:00
7d712d68c4 Merge branch 'stable' 2019-04-25 18:31:22 +01:00
c5ca623124 Merge branch 'stable' 2019-04-25 15:27:13 +01:00
a3dea09e2a sync with latest codegen changes 2019-04-25 15:19:15 +01:00
ffb0ed80a2 resync RakLib dependency 2019-04-22 22:29:54 +01:00
6af84caba6 Merge branch 'stable' 2019-04-21 17:52:57 +01:00
0dac982f16 Merge branch 'stable' 2019-04-21 16:56:53 +01:00
86cc151e60 Revert "Network: Each interface now keeps its own statistics"
This reverts commit 7720a0534e.
2019-04-18 15:45:03 -04:00
7720a0534e Network: Each interface now keeps its own statistics
this allows more detailed analysis.
2019-04-18 19:57:40 +01:00
f933ce31dd Merge branch 'stable' 2019-04-18 19:40:22 +01:00
752e398970 AsyncTask: TLS now supports storing multiple values (now requires a key/value pair) 2019-04-18 18:58:31 +01:00
a4c7ec077b Fixed possible crash in ChunkRequestTask 2019-04-18 17:45:14 +01:00
5913d5038b Cleaned up Entity->close() handling 2019-04-18 17:23:48 +01:00
cc01dfe8df Player: protect usedChunks 2019-04-18 16:20:56 +01:00
d68501c748 fixed spawn-radius: 0 2019-04-18 16:12:20 +01:00
939dfd9269 First look at separating chunk sending from Level 2019-04-17 19:33:37 +01:00
0973e39697 Level: Fixed ChunkListeners not receiving some events when no loaders are using a chunk 2019-04-17 16:13:40 +01:00
3468f006a2 Use AsyncTask->onError() for chunk task crash tracking 2019-04-17 16:00:17 +01:00
e62bbd4754 AsyncTask: added onError() main thread hook, closes #2512 2019-04-16 17:44:14 +01:00
b4f6c1e1a6 Merge branch 'stable' 2019-04-15 18:58:53 +01:00
209ae51a67 Merge branch 'stable' 2019-04-15 16:11:49 +01:00
e506c7f7de Call BlockTeleportEvent when dragon egg teleports (#2840) 2019-04-14 17:46:22 +01:00
cfd4580388 sync NBT network string length cap 2019-04-14 17:14:44 +01:00
9b0b8b9a0c Sync NBT dependency 2019-04-14 17:11:56 +01:00
8a1c362db7 Server: remove dead function getDefaultGamemode()
this was functionally identical to getGamemode() and is now just a red herring.
2019-04-13 14:31:58 +01:00
6428ca2a42 Merge branch '3.7' 2019-04-13 14:27:14 +01:00
c4b4575c74 Refuse to load plugins with ambiguous minAPI versions
closes #2381
2019-04-12 19:51:43 +01:00
bf2851f324 Move API checking to its own class so it can be unit-tested 2019-04-12 19:45:41 +01:00
5f23fffdda Merge remote-tracking branch 'origin/3.7' 2019-04-12 18:33:13 +01:00
342b48b758 VersionString: Use the correct bitwise operators 2019-04-12 18:32:15 +01:00
c310a0c50c Merge branch '3.7' 2019-04-06 15:35:58 +01:00
c49ead1a4c Merge branch '3.7' 2019-04-05 18:49:02 +01:00
e07b3f534b Merge branch '3.7' 2019-04-05 09:36:57 +01:00
86a5a50330 Generator: remove more useless functions
these are red herrings for plugin developers since they are not used.
2019-04-04 17:53:25 +01:00
5a989d82bb Generator: remove useless function getName() 2019-04-04 16:43:04 +01:00
e6a1f0eb8d Command: remove duplicated code 2019-04-03 18:06:22 +01:00
0e3e984db9 Player: Disconnects no longer nuke player internals, (mostly) fixes #1239
there are some problems that haven't been accounted for yet, but this fixes all the direct crashes.
2019-04-03 17:44:34 +01:00
a0b8d9a64e Merge branch '3.7' 2019-04-03 17:39:45 +01:00
f901c2a612 Player: move some functions to a more sensible place
let's keep disconnect-related logic grouped together.
2019-04-02 19:57:10 +01:00
f332550e52 Player: move toggle* rollback handling to network session
this allows network sessions to react to it how they want, or (in the case of things like Specter) perhaps ignore it.
2019-04-02 19:49:53 +01:00
80a6fc5dd1 BlockFactory: remove deprecated functions 2019-04-02 19:15:29 +01:00
b6e453a5f4 LegacyAnvilChunkTrait: remove obsolete TODO 2019-04-02 19:13:41 +01:00
7d22b2a6d7 Player: removed useless addActionBarMessage()
this is exactly the same as sendTip().
2019-04-02 18:43:14 +01:00
e5756dbf0b Move a whole bunch of packet crap to NetworkSession 2019-04-02 18:31:16 +01:00
2c4f2810d2 AsyncTask: Remove misleading methods getFromThreadStore(),saveToThreadStore(),removeFromThreadStore()
These methods are commonly mixed up when we talk about thread-local storage. What these things actually do is store persistent data on the worker thread.
2019-04-02 14:57:11 +01:00
6214a9398d Player: remove sendWhisper()
this can be done with a standard translated message, and with more customizability.
2019-03-31 19:25:09 +01:00
f0b85936cf Improved /tell 2019-03-31 19:08:35 +01:00
c59a2d1b93 More hasFiniteResources() usages 2019-03-31 16:51:43 +01:00
f8ce7797db Player: add hasFiniteResources() 2019-03-31 16:40:54 +01:00
42a263a9df GameMode is now an enum 2019-03-31 16:19:36 +01:00
0017c0087a oopsie woopsie 2019-03-31 16:17:01 +01:00
8c19f6cac8 EnumTrait: throw InvalidArgumentException from fromString()
this is more in line with expected behaviour, since this might be used to process arbitrary user input. Only calling an undefined magic static method should throw an Error.
2019-03-31 16:07:42 +01:00
cdeb3ea5a6 Sync NBT dependency 2019-03-30 19:53:24 +00:00
aff2e0c86c Merge branch '3.7' 2019-03-30 19:19:02 +00:00
004e81ea35 XpLevelUpSound: fixed crash on non-multiples of 5 2019-03-30 18:44:30 +00:00
3ea5260935 Sync composer dependencies 2019-03-30 18:28:42 +00:00
1fd4077907 MainLogger: Always use CRITICAL for logException() 2019-03-29 15:28:11 +00:00
f638845ef6 Merge branch '3.7' 2019-03-29 15:16:27 +00:00
260fa50db4 Register Edu compound items 2019-03-28 14:23:42 +00:00
de193d41a0 Server: fixed console not receiving user broadcast channel messages
I'm not entirely clear how this managed to work to begin with really, but it's now fixed properly.
2019-03-27 23:53:39 +00:00
649ce5080b StatusCommand: don't use config for reading global limit 2019-03-27 19:24:06 +00:00
0e806854b9 Server: clean up startup order a little 2019-03-27 19:16:39 +00:00
3de08bf452 Convert PluginLoadOrder into enum 2019-03-27 18:28:40 +00:00
2091354927 UUID: add type docs 2019-03-27 15:39:41 +00:00
d8c81c0a11 UUID: remove useless default values
these are overwritten by the constructor, so they have no use here.
2019-03-27 15:39:06 +00:00
7b2b43c0ca .................... 2019-03-26 19:56:03 +00:00
0aebb3f4fb Clean up LevelSoundEvent handling 2019-03-26 19:53:40 +00:00
e1504c668e LevelSoundEventPacket: more helpers 2019-03-26 18:23:02 +00:00
10db57655e clean up some direct LevelEvent usages for sounds 2019-03-26 18:06:12 +00:00
37b5ad8350 Remove remaining direct protocol usages for particles 2019-03-26 17:00:00 +00:00
1bf0802275 LevelEventPacket: added create() to reduce boilerplate code 2019-03-26 16:49:00 +00:00
7333e7118e Server: remove useless function 2019-03-26 15:52:34 +00:00
c98801402b Network: silence unhandled packet message on bad raw packet 2019-03-26 15:13:36 +00:00
a9c76c2424 NetworkInterface: remove unused function 2019-03-26 15:09:43 +00:00
161d5bd6b8 Merge branch '3.7' 2019-03-26 15:02:17 +00:00
01e048c4d1 Move networkStart message to where we actually start network
i.e. the point at which a normal user can reasonably expect to be able to connect to the server ...
2019-03-26 14:07:32 +00:00
ca22223b62 PlayerDeathEvent: fixed constructor signature, closes #2835
can we ban multi-type parameters already? this is tiresome...
2019-03-25 14:55:25 +00:00
999174b0a7 Server: Delay RakLib start until after world loading
fixes #2816
2019-03-25 14:49:12 +00:00
0811ce81e5 Query: remove useless noise
why do we need 3 log messages for something that does ... basically nothing?
2019-03-24 19:53:20 +00:00
23071d257e Extract process-related functions from Utils into a separate Process class 2019-03-24 18:57:32 +00:00
1ea5316a37 Whose idea was it to make this public... 2019-03-24 18:38:26 +00:00
97ccc6e880 Network: Don't ignore retval of raw handlers 2019-03-24 18:31:32 +00:00
d0940e4be2 Fixed raw packets in the buffer pre-ban still getting processed post-ban 2019-03-24 18:26:52 +00:00
6990d6239e Network: Added RawPacketHandler interface, query handler is now a component 2019-03-24 18:02:19 +00:00
a753c1342d Clean up Query cache handling, remove useless timeouts
the timeout was entirely useless, because:
- when shorter than 25.6 seconds (512 ticks) it would cause caches to be needlessly destroyed and regenerated
- when longer than 25.6 seconds, just made outdated caches persist for longer, even after the query info was regenerated.

This now uses a mark-dirty model to deal with caches, which means that plugin modifications to the query data will be reflected immediately, regardless of when they are made. Previously, modifying the result of Server->getQueryInformation() would have inconsistent results.
2019-03-24 17:43:02 +00:00
9c76fb7d96 Implemented plugin loading whitelist/blacklist by config file (#2783) 2019-03-24 16:18:13 +00:00
aea775c7c6 TallGrass: fixed seeds never being dropped when support is removed 2019-03-23 19:58:35 +00:00
d9134f28e4 Rename CobblestoneWall -> Wall 2019-03-23 19:50:07 +00:00
2a3e6dcf00 Rename BlockIds -> BlockLegacyIds 2019-03-23 19:46:31 +00:00
79ef8e0803 Replace all legacy blockID references with BlockIds:: 2019-03-23 19:44:33 +00:00
f84d7ad70d sync block TODOs 2019-03-23 19:21:11 +00:00
be0436b2a0 fix consistency check (again) 2019-03-23 19:20:52 +00:00
397713247d SeaPickle: fix drops 2019-03-23 19:19:38 +00:00
6efdac63d0 added new Wood block 2019-03-23 19:18:25 +00:00
06a37cc462 Fixed "wood" collision
why the fuck Mojang...
2019-03-23 19:08:17 +00:00
e088da320c ItemEntity: fixed mineWood achievement not working for acacia/dark-oak 2019-03-23 19:06:35 +00:00
d51ca0b655 Leaves: use instanceof Wood instead of legacy ID checks 2019-03-23 19:02:07 +00:00
a2f42a7016 Updated block/item ID constants from 1.10 2019-03-23 18:54:45 +00:00
1e096a408a Cram Nether Portal
again, this is here for the state handling and the implementation is unfinished.
2019-03-23 18:38:14 +00:00
74e134136d Make Infested Stone blocks known
this is not remotely a complete implementation, it's just here to make PM aware of these states so that world conversion can be handled correctly. A full implementation will come later.

Any blocks added in this fashion should be marked with a //TODO so future maintainers can find which blocks need work.
2019-03-23 18:28:29 +00:00
a8fa8572e1 partial sea pickle implementation 2019-03-23 18:11:27 +00:00
3c283aa700 fix consistency check (again) 2019-03-23 15:45:39 +00:00
905cb7544a hack in different wood sign types 2019-03-23 15:44:28 +00:00
765c5963a8 Block: move a function 2019-03-23 15:01:35 +00:00
53bb05a6a7 Fixed different woodtype boats being missing 2019-03-23 14:51:58 +00:00
034bd716c8 Clean up WritableBook hierarchy 2019-03-23 14:36:03 +00:00
a74a4b579d wtf @sandertv 2019-03-23 12:56:02 +00:00
98f56087de make composer happy 2019-03-23 12:53:00 +00:00
15c6554d8a Updated RakLib dependency 2019-03-23 12:52:50 +00:00
d4fe004375 More consistent fluency in Item API 2019-03-23 12:20:35 +00:00
1045088668 Move more packet handling logic out of Player
there is now only (1) packet handler remaining in Player. The reason I haven't targeted this is because it needs improvements of its own.
2019-03-23 12:12:30 +00:00
1bc37a1a8a Player: Clean up movement processing, now API-ified 2019-03-23 11:33:32 +00:00
9cddfdf8ec Revert "Move core permissions to default_permissions.yml"
This reverts commit 5fac5c7281.
2019-03-23 10:41:50 +00:00
1d1a416afe Player: Move construction logic to the top 2019-03-23 10:39:19 +00:00
f3309d3aec Player: remove some field defaults 2019-03-23 10:29:16 +00:00
9ec62643d5 Player construction now happens when we're ready to create the player entity
this fixes a wide range of bugs with the initial spawn sequence, and allows to simplify a whole lot of player setup logic.
2019-03-23 10:13:14 +00:00
433dab078b DataPacket events now use network sessions instead of players 2019-03-23 09:52:03 +00:00
afbd016611 Server: remove useless function 2019-03-22 19:38:33 +00:00
712e077bc1 Server: remove useless debug message
leveldb is now mandatory, so this message will always be emitted.
2019-03-22 19:31:10 +00:00
9904810f24 BaseInventory: Remove getDefaultSize()
it's possible to want to initialize dynamically-sized inventories which don't have a default size.
2019-03-22 19:21:41 +00:00
60225a378f Player: fixed block-picking logic
this now matches vanilla (with some minor intentional differences) and works in survival.
2019-03-22 18:28:36 +00:00
f84a1729c6 Inventory: added swap() function 2019-03-22 18:11:32 +00:00
8e48c61daf Merge branch '3.7' 2019-03-22 15:07:46 +00:00
9b11e39efc use ?? 2019-03-22 15:03:46 +00:00
d03f0aab37 Remove /reload (#2823)
For many years, this has been the cause of many users (particularly plugin devs) confusion. The reality is that /reload has little to no practical value. It does not reload plugin source code (contrary to popular belief).
2019-03-22 15:01:11 +00:00
6ec2a69417 Removed .docker/Dockerfile
1. The current Dockerfile is not directly related to the project, but just our very complex highly-coupled full-of-hacks build/release/deploy system.
2. We are no longer using Docker Hub Builder. An internal Dockerfile will be used on our Jenkins server instead, using the correct upstream phar build to prevent race conditions.
2019-03-22 12:51:50 +08:00
3dbed830ef Fixed entities not loading on imported MCPE worlds 2019-03-21 20:03:10 +00:00
b8d1eb20b0 EntityDeathEvent: add XP amount API, closes #2690 2019-03-21 19:53:14 +00:00
89c0836047 Fixed paintings dropping multiple times, closes #2774 2019-03-21 19:46:43 +00:00
9ad7f74501 Merge branch '3.7' 2019-03-21 19:02:55 +00:00
588ebe446f Fixed Chunk->setFullBlock() not creating new subchunks, closes #2821 2019-03-21 18:47:24 +00:00
8c536c248d Updating for latest PocketMine-NBT changes 2019-03-21 15:58:22 +00:00
1ac255f955 fix some formatting issues 2019-03-21 15:46:07 +00:00
2966e87aae BlockFactory: Regenerate TODO list 2019-03-21 14:33:56 +00:00
2e5ef4ba03 Merge remote-tracking branch 'origin/3.7' 2019-03-20 21:35:13 +00:00
cc78c9ef18 Merge branch '3.6' 2019-03-18 08:58:59 +00:00
8de9e61651 Item: Remove get/set/removeNamedTagEntry() 2019-03-17 17:49:09 +00:00
5830ca958b Further out-phasing of legacy ID/meta
this paves the way for making internal IDs fully dynamic.
2019-03-17 16:01:04 +00:00
6f54b53f7a thanks for being useless PhpStorm
these problems didn't show up in any inspections until I opened the fucking files...
2019-03-17 15:53:59 +00:00
87928038e6 sync deps 2019-03-17 15:19:47 +00:00
7d72b8e756 leveldb: use writebatch for chunk saving (faster I/O)
i don't know why this wasn't already using a writebatch, but it should have been.
2019-03-15 16:45:47 +00:00
9205bbaa42 ... why is this not saved on provider close...? 2019-03-15 04:43:19 -04:00
a91f49220c Chunk: Do not mark as changed on lighting updates
Since we don't save light to disk anymore, we don't need to care if a light update took place. This improves I/O performance.
2019-03-14 16:34:14 +00:00
62185d476b RegionLoader: Fixed performance issue converting huge worlds
I was big nub when i wrote this code.
2019-03-14 15:22:44 +00:00
1e0f1e5b1a RegionLoader: Stop unnecessarily writing location header on close
Any time a region is modified, the location header is written anyway, so this is entirely unnecessary.
2019-03-14 15:06:13 +00:00
d080d3bae0 RegionLoader: Write location table changes when deleting chunks 2019-03-14 15:02:15 +00:00
41d13b6f06 Player: remove dead condition
this can't be reached because the only place it's called is from Level->actuallyDoTick(), where it won't appear until long after the player is logged in.
2019-03-14 14:47:20 +00:00
a1ffaffa7f Don't record player on stats until they actually exist 2019-03-14 14:46:19 +00:00
ebfe9caca3 Move too-early-send check to NetworkSession 2019-03-14 14:45:30 +00:00
26a5d97499 Some cleanup to player net session handling for connect/disconnect 2019-03-14 14:32:43 +00:00
fa7a4dc22e Fixed warning of bad default format on new installs 2019-03-13 21:43:07 +00:00
34758e3bc6 RegionLevelProvider: clean up coordinate extraction, fixed a stupid bug 2019-03-13 17:35:09 +00:00
08c399529d RegionLevelProvider: Unload regions when finished scanning them, fixes running out of file descriptors during conversion 2019-03-13 17:32:34 +00:00
ad19696364 Make Effect and Enchantment functions less verbose 2019-03-13 15:26:21 +00:00
01904adf49 Improve enum implementations, move some components to traits
The reason this uses a trait is because `self` refers to the including class in a trait, which offers a small amount of automatic type safety.
If we had templates or generics, this would be a generic class instead.
2019-03-13 15:10:31 +00:00
7f4b76aa86 Implemented blue ice 2019-03-12 19:38:03 +00:00
0e1a88f7e5 Armor: Implement right-click to equip, closes #2641 2019-03-12 19:01:36 +00:00
8b9eeb0b7f Clean up Armor classes 2019-03-12 18:53:51 +00:00
2e4b3d3d46 Sync legacyID map (thanks @MCMrARM) 2019-03-11 17:38:02 +00:00
1d4f44d259 Updated BlockFactory consistency check data 2019-03-10 19:53:55 +00:00
13bea6c787 Updated Travis configuration 2019-03-10 19:53:55 +00:00
48427290c9 Regenerated BlockFactory TODOs 2019-03-10 19:53:55 +00:00
437750785f Implemented barrier block 2019-03-10 19:53:55 +00:00
c2a069afd3 Implemented a bunch of new wood blocks 2019-03-10 19:53:24 +00:00
84bbd14a21 fixed wrong generator being set on converted worlds 2019-03-10 19:53:24 +00:00
85e1b77cae fix crash in getHighestBlockAt() 2019-03-10 19:53:24 +00:00
18e16f8615 Fixed blockID truncation 2019-03-10 19:53:24 +00:00
7aa4c18afa Fixed assert failure in SubChunk 2019-03-10 19:53:24 +00:00
a858103e6b Support paletted subchunks, drop all formats except leveldb 2019-03-10 19:53:24 +00:00
dfc26395e2 Fixed missing logger injection 2019-03-10 19:53:23 +00:00
8cb24547ff Goodbye McRegion o/ 2019-03-10 19:53:23 +00:00
8d83d59cf0 Work around collisions in backup names 2019-03-10 19:53:23 +00:00
a0a8026cba Implemented automatic world format conversion 2019-03-10 19:53:23 +00:00
ae9f57ac28 Revert "Remove hacks for triggering adjacent light refill"
This reverts commit 1dca9074d5.
This change introduced performance issues with transparent blocks.
2019-03-10 19:50:35 +00:00
c266f86b1b ItemEntity: introduce controls for despawn timers (#2769)
This opts _not_ to expose item "age" a la #2753 because "age" is a misleading term for it. In addition, further inspection of the problem led me to realize that exposing control of that AND despawn timeout was more complicated than simply having a despawn delay timer exactly like the pickup delay one. Everyone knows a countdown timer stops at 0, so this way we don't need any method to control the limit.

Closes #2667
Closes #2753
2019-03-10 12:05:21 +00:00
c05bc6a53e Merge branch '3.6' 2019-03-10 12:03:39 +00:00
4c10476b15 Empty merge 2019-03-10 11:43:31 +00:00
3079fd0251 Fixed test failures introduced by 6fe366e1ac 2019-03-09 19:05:32 +00:00
b9208eb1fb Merge branch '3.6' 2019-03-09 19:04:37 +00:00
2ae09f635b Add more output to consistency check script
this helps catching state mapping bugs.
2019-03-09 17:19:17 +00:00
6fe366e1ac Added some missing block properties 2019-03-09 16:49:37 +00:00
8f1bc5d497 Flatten wall_banner and wall_sign into single blocks (#2798)
This comes with some problems, but the problems are more bearable than the previous code.
2019-03-08 16:37:26 +00:00
bb718faa2e Merge branch '3.6' 2019-03-08 13:57:32 +00:00
c68ee1d9d9 LevelDB: Mark chunks as changed when upgraded from an older chunk format 2019-03-08 13:55:56 +00:00
2b6a62be77 Fixed BlockFactory corruption with signs and banners 2019-03-05 15:32:06 +00:00
3f66600271 RegionLoader: Extract location table validation to separate function 2019-03-05 13:28:56 +00:00
f2404804d7 RegionLoader: clean up lastSector handling 2019-03-05 13:18:14 +00:00
07a9c35ee2 RegionLoader: Use objects instead of arrays 2019-03-05 13:10:17 +00:00
4d9b074641 Merge branch '3.6' 2019-03-05 12:10:16 +00:00
e31603fc45 Merge branch '3.6' 2019-03-05 11:21:55 +00:00
2795ad674b add boilerplate code to check for generator validity
perhaps we should use an enum for this...?
2019-03-05 09:36:22 +00:00
2cad7166b1 GeneratorManager::getGeneratorName() now throws InvalidArgumentException on unregistered generator classes
the old behaviour allowed a bug in the world converter to go unnoticed.
2019-03-05 09:30:22 +00:00
3789f4d643 Merge branch 'master' of https://github.com/pmmp/pocketmine-mp 2019-03-04 12:03:45 +00:00
f87dac7bb2 Merge branch '3.6' 2019-03-04 12:02:36 +00:00
5017e61cb2 ItemFrame: fixed cloning null 2019-03-03 21:12:52 +00:00
f83e5c195c fixed tiles and entities not getting saved on fast-deserialized chunks 2019-03-03 18:26:05 +00:00
54ef965b2a Added warnings when unknown entities and tiles are removed 2019-03-03 18:02:34 +00:00
f5dbbea5f5 Utils: added recursiveUnlink() 2019-03-03 17:39:23 +00:00
3509b26751 LevelProvider: added calculateChunkCount()
this will be used to provide progress information to the user during world conversion.
2019-03-03 17:32:57 +00:00
1bb9b3d3ab Discard light information from disk storage
this makes world conversion faster and offers the opportunity to correct age-old lighting bugs.
2019-03-03 16:22:44 +00:00
6e00ab2069 Chunk: add getNBTentities() and getNBTtiles()
this shit is horrible, but it's needed for now...
2019-03-03 14:00:46 +00:00
93cd00ae8f Remove dead settings from pocketmine.yml 2019-03-03 13:28:18 +00:00
c3e66e0adc LevelManager: add debug message when a level takes too long to tick 2019-03-03 13:26:16 +00:00
6bd43a8215 Firehose auto-tick-rate anti-feature, closes #2665 2019-03-03 13:24:53 +00:00
d9880de2ef LevelManager: improve debug message for autosave 2019-03-03 12:43:02 +00:00
743d91a670 Merge branch '3.6' 2019-03-03 12:38:19 +00:00
fc9a61859a Item: remove misleading methods & premature optimization 2019-03-03 12:36:46 +00:00
abbdd7efdd Item: make __toString() use base64 for displaying NBT 2019-03-03 12:33:28 +00:00
1c79d43d88 Merge branch '3.6' 2019-03-03 11:59:53 +00:00
0573838be3 rename submodules 2019-03-03 11:47:00 +00:00
158f81b427 Merge branch '3.6' 2019-03-03 11:15:40 +00:00
2bffd5cc1c Add timer measurements for autosave 2019-03-02 18:20:25 +00:00
382488dd07 sync locale submodule 2019-03-02 17:20:37 +00:00
808259dccd Introduce CancellableClosureTask
before anyone picks a fight about the naming, take it up with shoghi... let's be consistently wrong at least
2019-03-02 10:45:01 +00:00
6c8fa8ae28 More nullable and void typehints 2019-03-02 10:29:11 +00:00
1f5c901f29 ext-ds is now required 2019-03-01 20:03:16 +00:00
418d0f12fb Slab: placement logic clean up
past me was full of shit, because blockReplace is the same as blockClicked when we click a single slab top/bottom to make a double slab, and the logic is identical to the below block with that in mind.
2019-03-01 19:15:24 +00:00
d961b272c7 Remove Tool <-> Block circular dependency in efficiency calculation 2019-03-01 18:18:56 +00:00
72233a509d preprocessor fix 2019-03-01 18:08:03 +00:00
e9125af51d Revamp Banner API (still rather ghetto)
this needs more work, like signs do.
2019-03-01 17:57:07 +00:00
80ac0180b3 Remove redundant isAffectedBySilkTouch() overrides
this was needed previously to prevent dropping blockitems when these blocks were destroyed. Now the item form is always yielded instead.
2019-03-01 13:34:32 +00:00
12dfcc9eb6 Banner: Sort lines lexicographically ascending 2019-03-01 11:06:42 +00:00
1e9e179ec0 Fixed Block consistency check failure since 943906cc6b 2019-03-01 08:24:25 +00:00
741d061415 NoteBlock: added //TODO 2019-02-28 19:59:33 +00:00
943906cc6b Partial comparator implementation
this supports placement, toggling compare/subtract mode, simple stuff. No redstone functionality yet.
This is needed for blockstate mapping in blockfactory.
2019-02-28 19:26:47 +00:00
7b23baa020 FlowerPot: yield contained plant when block-picking 2019-02-28 17:49:48 +00:00
97a1d997e8 ItemFrame: yield framed item when block-picking, fixes [1] in #2706 2019-02-28 17:47:32 +00:00
d679fb7546 Block: Rename onActivate() -> onInteract() 2019-02-28 17:35:30 +00:00
c9eb642afd PacketPool: missing @throws 2019-02-28 17:15:06 +00:00
08e799c35a Once again... add a missing file... 2019-02-28 17:14:04 +00:00
5cca4b5e31 Revamp Sign API, flatten API into blocks 2019-02-28 17:10:37 +00:00
f680a239f7 NetworkSession: some exception handling cleanup 2019-02-28 16:36:03 +00:00
13b9fd7b66 RakLibInterface: Add error ID to make logs searchable when players report legitimate issues 2019-02-28 16:31:14 +00:00
d528fdddfa DataPacket: Remove useless abstract function
this is declared in the Packet interface, so it doesn't need to be here anymore.
2019-02-28 16:20:58 +00:00
fb02071a9d Traits suck. Fixed missed getDamage() from 9ad0ea85c7 2019-02-27 16:50:51 +00:00
08673172c7 Grass: Avoid usage of meta 2019-02-27 13:03:23 +00:00
9ad0ea85c7 Rename two misleadingly-named functions 2019-02-27 12:59:12 +00:00
ba616ed8a7 Player: Don't rely on magic numbers for gamemodes 2019-02-27 11:01:26 +00:00
31336a0d09 missed one 2019-02-27 10:37:13 +00:00
2d8480d801 Inventory: remove a bunch of crap from interface
some of these (notably the on* methods) are internal and shouldn't be exposed via interface (same crap as Plugin->onEnable() onDisable() etc) and the rest of the stuff is entirely unused.
2019-02-27 10:36:05 +00:00
9b3230aa9c Merge branch '3.6' 2019-02-27 10:19:58 +00:00
440dd21550 Merge branch '3.6' 2019-02-26 19:59:24 +00:00
ceaf969203 EnderChest: fix hierarchy 2019-02-26 19:41:56 +00:00
cb91afcc00 Added SkullType enum, some cleanup to skull handling
this is still more ugly than I'd like it to be because of the way the blockfactory currently works.
2019-02-26 18:27:30 +00:00
edf4a719d5 DyeColor: add RGB colour values 2019-02-26 17:16:35 +00:00
202aef9846 fix failing tests 2019-02-26 16:35:33 +00:00
d7e73705c2 consistency check regen script now emits which states were added/removed 2019-02-26 16:35:14 +00:00
9afcd72fb6 Flatten FlowerPot tile into its block (mostly) 2019-02-26 16:31:38 +00:00
53af7f5da8 Implemented dragon egg 2019-02-26 15:35:37 +00:00
2d51622b12 Implemented frosted ice 2019-02-26 15:34:48 +00:00
6124f93cb4 Player: Clean up item frame drop-item hack
This is now re-routed through a newly-created attack-block handler.
Closes #339
2019-02-25 18:40:04 +00:00
fb378d9091 BlockFactory: fixed auto complete 2019-02-24 18:41:12 +00:00
0f7f5362b8 Revert "Block: Get rid of state bitmasks"
This reverts commit b7b05e729e.

Apparently this was premature, because we still need these things to deal with default state remapping.
2019-02-24 18:30:18 +00:00
6cb263fcca BlockFactory: enforce stricter checks
this can help catch out variant-related bugs.
2019-02-24 17:59:09 +00:00
b7b05e729e Block: Get rid of state bitmasks
This story dates back to the days when getVariantBitmask() was introduced. The purpose of this function was to allow the variant info to be extracted from the metadata, for use with item drops. This was later changed to state bitmask for reasons I don't clearly recall.
In the great 4.0 refactor, we now store variant magic numbers separately, so we don't need any generic bitmask to split up variant and state information anymore. Variant is now only ever serialized and never deserialized. The same thing goes for blockIDs. States are read from the world by matching the full stateID against a table of prefilled known blocks, so the variant doesn't need to be deserialized - only the state does, and the state metadata readers already do bit fuckery by themselves and don't need this mask - notice how little actual changes were required to get rid of this?
2019-02-24 14:42:53 +00:00
023fecabac Added an annoying consistency check for BlockFactory
This test is intended to enforce that the BlockFactory always has the same blocks in it from one commit to the next. Since there are a lot of changes going on right now around this, it's important that this is checked because bugs can go under the radar when large changes are happening.

The consistency check will need to be regenerated whenever a new block is registered, new states are found or when things are removed.
2019-02-24 13:56:55 +00:00
6edd4fd9c7 BlockFactory: added getAllKnownStates() 2019-02-24 13:40:59 +00:00
73305a7425 oops, formatting issue 2019-02-24 13:22:11 +00:00
899081e1b9 Level: fixed randomTickBlocks, also delete some useless code
the randomTickBlocks thing is populated with state IDs anyway, not variants...
2019-02-24 13:10:45 +00:00
369a1e1472 Tripwire: fixed block picking 2019-02-24 12:41:44 +00:00
832ad0501a Tripwire: added missing flag
it's unclear what the purpose of this flag is. It appears to always be set on placement and is never changed at any other time. The result is that the hitbox becomes larger when it is set.
2019-02-24 12:19:15 +00:00
a3907377f5 Merge branch '3.6' 2019-02-24 12:14:40 +00:00
97687f2236 Dye, banner and bed items now store DyeColor objects instead of using magic meta values 2019-02-24 10:48:40 +00:00
0bd1c1529e Block: Rename getItem() to asItem()
this has clearer meaning and is less likely to collide with other things.
2019-02-24 10:23:40 +00:00
ff35736bf9 ItemFrame: added ROTATIONS constant 2019-02-23 18:27:47 +00:00
998dcb421e Flatten Item Frame implementation into its block (mostly)
This exposes nice API on the ItemFrame class, while keeping the tile bullshit out of sight so that we can remove it later on.
2019-02-23 18:19:31 +00:00
878c704597 Remove another dead function 2019-02-23 17:15:50 +00:00
49f9605620 Level: Allow tiles to be sent with regular block updates 2019-02-23 17:01:59 +00:00
eadb1d310e Level->sendBlocks() now syncs tiles 2019-02-23 16:53:29 +00:00
e1ef52c7c3 TileFactory: remove dead function 2019-02-23 15:57:53 +00:00
991483938c SubChunk: remove legacy crap 2019-02-23 13:18:37 +00:00
66a1b35767 Merge branch '3.6' 2019-02-23 11:05:23 +00:00
0daf695825 Merge branch '3.6' 2019-02-23 10:51:28 +00:00
f669677d17 BlockTest: fixed failing test
this is a bad fix, but it doesn't matter a whole lot. The problem stems from furnace not having a valid 0 variant, so things go haywire when the default mapped 0 variant is registered to LIT_FURNACE because the default state is of course unlit.
2019-02-22 18:56:14 +00:00
707faef0f7 BlockTest: remove redundant name test
name is mandatory in the constructor now, so this isn't necessary anymore.
2019-02-22 18:54:21 +00:00
0f2f05fbb9 Merge branch '3.6' 2019-02-22 18:14:17 +00:00
9c085799e6 Removed leftover import from 3d1502c9ad 2019-02-22 12:56:14 +00:00
c26544475e More PHP 7.1 nullables 2019-02-22 12:55:34 +00:00
73a565355b Make some forced-optional nullable parameters non-optional, PHP 7.1 style
these parameters did not make any sense to be optional, but were forced to be this way because of the way nullable types worked before 7.1.
2019-02-22 12:54:00 +00:00
a5c260352d Infect remaining places with PHP 7.1 nullable typehints 2019-02-22 12:16:45 +00:00
461233db09 ItemFactory: Sort items lexicographically ascending 2019-02-22 11:52:22 +00:00
3037f45a0c Implement new dye types, split bonemeal and cocoa beans into their own classes 2019-02-22 11:43:48 +00:00
2bfcd25848 Fixed typo in Repeater name 2019-02-21 18:41:04 -05:00
fd4a441f3a Level: add unregisterChunkListenerFromAll()
it's not expected for chunk listeners to have to track all the chunks they are listening to under normal circumstances.
2019-02-21 14:51:16 +00:00
f9da0f3ece Sapling: remove dead TODO 2019-02-21 13:09:05 +00:00
eabd8ce026 Fixup pressure plate hierarchy 2019-02-21 13:06:08 +00:00
28d01025b0 Improve consistency of handling coloured and wooden blocks
this is ugly, but less ugly than the earlier version.
2019-02-21 12:13:21 +00:00
0120585aee Block: name is no longer nullable 2019-02-21 11:37:21 +00:00
e063c567be Merge remote-tracking branch 'origin/master' into block-id-object 2019-02-21 10:41:25 +00:00
6ab171d629 Fixed unit tests 2019-02-21 10:41:06 +00:00
635fb5dde4 Clean up ID flattening hacks 2019-02-21 10:38:29 +00:00
3d1502c9ad Apparently yaml_parse_file() doesn't respect access protocol 2019-02-20 17:11:26 -05:00
89fce7712a Block: Clean up internal constructor inconsistencies
I don't dare look how big this commit is or how many bugs it introduced...
2019-02-20 19:21:51 +00:00
e93464f318 SnowLayer: fixed 8x layers being replaceable
this also fixes some placement bugs.
2019-02-20 16:29:34 +00:00
5fac5c7281 Move core permissions to default_permissions.yml
this is one of the few things that is actually better suited to a YAML file than code
closes #2594
2019-02-20 16:22:45 +00:00
7aa263d320 PermissionParser: add emitPermissions() 2019-02-20 16:21:25 +00:00
efc2d72d5f Move permission parsing to dedicated PermissionParser class 2019-02-20 16:20:48 +00:00
58cafc853f s/level/world (strings only)
we should look at doing this for code too, but for now I'm not planning to break everyone's plugins.
2019-02-20 15:33:46 +00:00
9354929cad added a whole bunch of tests for enchantment handling 2019-02-20 14:43:57 +00:00
7170d9009d Enchantment: more static getters, firehose magic numbers
This is similar in nature to 646fea5a4e.

On a side note: Migrating this way is a pain in the ass due to lack of types. What the heck is int supposed to mean?!?!?!?! At least if we wanted to go _back_ to magic numbers, it would be easy to locate everything with an Enchantment typehint...
2019-02-20 13:45:50 +00:00
646fea5a4e Effect: Introduce a bunch of static getters, change a bunch of API to use objects
This introduces static getters for every currently-known effect type. At some point in the near future, the magic number constants (which are really network IDs, by the way) will disappear.

Migrating:
- If you used constants (like any sensible person would): for the most part it's just a case of adding a () anywhere you used an Effect constant.
- If you hardcoded magic numbers: ... well, have fun fixing your code, and I reserve the right to say "I told you so" :)

This achieves multiple goals:
1) creating an EffectInstance for application is much less verbose (see diff for examples, especially the Potion class)
2) plugin devs cannot use magic numbers to apply effects anymore and are forced to use type-safe objects. :)

This is a warning shot for plugin devs who use magic numbers. More changes like this are coming in the not-too-distant future.
2019-02-20 12:05:17 +00:00
15d4201c3a Fixed tests broken by 88c4b836f0 2019-02-20 11:16:08 +00:00
2c8a065b94 Standardise SNAKE_CASE for surrogate enums 2019-02-20 11:14:07 +00:00
36e9db4c07 Generate methods for surrogate enums, nip stupidity in the bud
this also allows changing the internal implementation later without breaking plugins.
2019-02-20 11:09:22 +00:00
88c4b836f0 Make factory register methods less verbose 2019-02-20 10:24:44 +00:00
f351a86653 Flatten double slabs into Slab pseudo-variant 2019-02-19 11:14:06 +00:00
18f765338c Slab: fixed replacing $blockReplace not creating double slab when not clicking on the replaced block itself 2019-02-19 11:09:11 +00:00
bf71ddb0b5 Snow layers now fall as expected 2019-02-19 10:01:57 +00:00
a4c3ee20b2 Extract Fallable into trait + interface
Traits are inferior to components in pretty much every aspect imaginable :(
2019-02-19 09:58:10 +00:00
6174f1e0ae Pumpkin: fix BC issue, fix lit pumpkin rotation 2019-02-18 20:02:23 +00:00
6f4cec6465 add some blocks introduced in 1.9 2019-02-18 20:01:50 +00:00
a95ecb3ff9 FenceGate: implement in-wall checks 2019-02-18 19:00:58 +00:00
6f7c63e2a8 ItemFrame: add has-map bit
this makes the frame appear to cover the full block instead of the usual size.
2019-02-18 17:41:15 +00:00
8f26c3a2d4 Fix bonemeal count not reduced by CocoaBlock (#2773) 2019-02-18 16:31:07 +00:00
12dd6adfcc Block: Derive light filter level based on isTransparent() return
this might be dynamic.
2019-02-18 13:27:22 +00:00
6cdd716c34 Merge branch '3.6' 2019-02-18 13:12:29 +00:00
b8adfd6948 edu: implement coloured and underwater torches 2019-02-18 11:37:57 +00:00
cd733c658b Implement hard glass & hard glass pane 2019-02-18 10:50:29 +00:00
ab58d46a7f Merge branch '3.6' 2019-02-17 16:12:21 -05:00
00b92eaa40 BlockFactory: Sort entries lexicographically ascending 2019-02-17 19:44:48 +00:00
1bc6483608 Fixed Dockerfile permission issues 2019-02-17 18:10:40 +00:00
9b372f8435 Merge branch 'master' of https://github.com/pmmp/pocketmine-mp 2019-02-17 17:09:13 +00:00
3bbc0b5d5f Merge branch '3.6' 2019-02-17 17:08:44 +00:00
9137eb0757 Added Dockerfile 2019-02-18 00:52:52 +08:00
c2735286ab Merge branch '3.6' 2019-02-17 11:35:07 +00:00
7ea1f4fc91 Sign: fixed merge leftovers from 6424dc9c82 2019-02-17 11:10:17 +00:00
84cf7c11e6 Fixed some overlooked returns from dce08b4e88 2019-02-17 06:01:08 -05:00
22a21ecfd6 BlockTransaction: Take world in constructor 2019-02-16 19:57:55 +00:00
0794c94b4b Rename BlockWriteBatch -> BlockTransaction 2019-02-16 19:53:15 +00:00
b252be1c7a Added ItemFactory::air() sugar
This makes it easier to create air stacks without accidents, and also reduces the amount of throwaway air objects which get created.
2019-02-16 12:19:54 +00:00
0ac7164b16 Inventory: remove dropContents(), remove circular dependency 2019-02-16 12:19:46 +00:00
f49d590794 Level: remove getTiles(), more removal of tiles from user interface 2019-02-15 16:27:00 +00:00
65ce1a7581 Block: fixed correct-type tiles getting overwritten
this manifested by crashing the server whenever someone used a furnace.
2019-02-15 13:37:57 +00:00
01255c5368 Updated RakLib to get ITC efficiency enhancements 2019-02-15 12:29:16 +00:00
19f0d7f336 NetworkSession: Don't apply handlers to a disconnected session
closes #2756
2019-02-15 10:11:31 +00:00
dce08b4e88 Introduce Item use results - can be success, fail or none
closes #2693, closes #2705, closes #2734
2019-02-14 19:21:29 +00:00
d9bbe99b83 Merge branch '3.6' 2019-02-14 17:25:21 +00:00
d8a25020f1 Merge branch '3.6' 2019-02-14 16:17:39 +00:00
6424dc9c82 Merge branch '3.6' 2019-02-14 16:04:32 +00:00
205e13d880 Config: add getPath() (#2758)
Config->getPath() returns the path of the config i.e. the place where the config file is located.
2019-02-14 10:58:19 +00:00
470879c9bf Merge branch '3.6' 2019-02-13 14:53:20 +00:00
7b6d76871c Block: add face and clickVector to onActivate() parameters, closes #267
this is an old old old issue, i don't know why it wasn't addressed sooner.
2019-02-13 14:29:59 +00:00
55be0716d8 Use DyeColor instead of ints for banners 2019-02-13 13:49:44 +00:00
01e7ebeb5c Automate creation and deletion of Tiles for appropriate blocks
closes #880
2019-02-13 12:27:13 +00:00
260c5dcf00 Clean up tile destruction 2019-02-13 12:02:04 +00:00
1496eefb8b Regenerated TODOs for item and b,locks
this sucks because it doesn't tell us anything about things that are meta values of other things (like dyes), but it's enough to start with.
2019-02-12 19:15:19 +00:00
59b62eaeba Merge branch '3.6' 2019-02-12 16:59:06 +00:00
d30316101a Of course, there was a bug in the script... 2019-02-12 16:30:31 +00:00
5227679602 sync item/block magic numbers with 1.9.0.15 2019-02-12 16:01:25 +00:00
7b3993730a Block: Replace Color and WoodType magic numbers with type-safe objects
this provides automatic type safety without the need for magic number value checking everywhere.
2019-02-12 13:52:59 +00:00
18440f612f Merge branch '3.6' 2019-02-10 17:40:09 +00:00
b6bcb47deb Network->unregisterInterface() is now less useless
Interfaces are now automatically shut down when unregistered.
2019-02-10 17:07:58 +00:00
9ebd559907 Merge branch '3.6' 2019-02-10 13:59:44 +00:00
0c89159cf2 Merge branch '3.6' 2019-02-09 19:22:00 +00:00
1a8a04eab8 Merge branch '3.5' 2019-02-07 17:12:49 +00:00
b7973ef782 Merge branch '3.5' 2019-02-05 16:58:34 +00:00
d23e32622e Clean up internal inconsistency in Color 2019-02-05 13:52:34 +00:00
c6a5829a92 Entity: remove dead function 2019-02-04 19:54:18 +00:00
c872b120d0 Entity->entityBaseTick() is now protected 2019-02-04 19:54:06 +00:00
acd0a8f2d4 fix possible crash in Projectile 2019-02-04 19:53:55 +00:00
537afbc23b EffectInstance: Require positive amplifiers, closes #2723 2019-02-04 19:53:28 +00:00
55cd1f263d SnowLayer: implement layers, closes #2657 2019-02-04 19:53:17 +00:00
923b1ad9a6 Split up ChunkLoader and ChunkListener 2019-02-04 19:53:03 +00:00
2c0f91ce50 Player: clean up chunk selection code 2019-02-04 19:52:36 +00:00
ce8d9fa9f4 Player: load chunks when registering as a loader, closes #2726
populateChunk() _sometimes_ does this, but not if the chunk is locked. This means that the empty chunk needed to prevent the shit hitting the fan isn't created when chunks are locked. This change resolves the problem because registerChunkLoader() calls loadChunk() with the create parameter as true when autoload is used. This is a shitty fix but it's the simplest one we have right now, and it works well.
2019-02-04 19:52:03 +00:00
002f030970 EnderPearl: make a hack less messy 2019-02-04 19:51:49 +00:00
dbae667dec Silence more InteractPacket noise 2019-02-04 19:51:38 +00:00
ad6ae20d6b Server: fixed getOfflinePlayerData() trying to load terrain (?!?!?!?), closes #2725
getOfflinePlayerData() will now return NULL if there is no stored data for a given player. The responsibility of checking the spawn point is now delegated to the Player, after it registers a chunk loader on its spawn chunk.
2019-02-04 19:51:11 +00:00
3e58708130 Add some missing @throws annotations 2019-02-04 19:50:43 +00:00
8387c08db2 Level: remove unused variable 2019-02-04 19:50:24 +00:00
c9f9f551f4 Merge branch '3.5' into master-rollback 2019-02-04 19:47:21 +00:00
c124aae219 Merge branch '3.5' 2019-01-30 13:09:43 +00:00
5c24ac604a Merge branch '3.5' 2019-01-30 11:14:47 +00:00
90f3cb95d8 Merge branch '3.5' 2019-01-29 17:34:12 +00:00
c5f0665853 Merge branch '3.5' 2019-01-29 14:05:00 +00:00
b6ecab1d49 Merge remote-tracking branch 'origin/3.5' 2019-01-29 12:53:38 +00:00
ceddf6f5d8 Merge branch '3.5' 2019-01-28 17:52:11 +00:00
c3bbb8905c Human: simplify setFood() 2019-01-28 17:33:58 +00:00
78dfcc5f2d Move Effect and EffectInstance to entity\effect namespace 2019-01-28 15:41:07 +00:00
a6237958e8 Level: fix another crashy edge case in chunk ticking
this also removes a bias towards the chunk that the player is on, because this makes such chunks tick faster than adjacent chunks.
2019-01-27 20:41:47 +00:00
9ec40c421f Split up Effects into a bunch of classes
Server-side levitation now works too.
2019-01-27 19:45:15 +00:00
729ae8bab7 Level: fixed adjacent chunk loading check 2019-01-27 16:20:38 +00:00
ac551cf248 Entity: add addMotion() to allow updating motion vector
this allows updating motion without needing to create new objects for the task.
2019-01-27 15:43:57 +00:00
bccc07633c Entity: Allow disabling gravity for a mob 2019-01-27 15:42:46 +00:00
6f9c4eb8e8 Merge branch '3.5' 2019-01-27 15:08:26 +00:00
0b1bdec3ac GameMode::fromString() now throws InvalidArgumentException 2019-01-26 17:09:54 +00:00
e86ff7d988 Merge branch '3.5' 2019-01-26 17:00:04 +00:00
d378371cc8 Transition to spl_object_id() 2019-01-26 15:06:38 +00:00
1e708db26c Server: fixed wrong doc type on broadcastMessage() 2019-01-26 15:03:15 +00:00
d052b1a45f Server: reduce code duplication in broadcast handling 2019-01-26 15:02:07 +00:00
d6e44c7475 Sync composer dependencies 2019-01-26 14:11:45 +00:00
eac8f639a7 Level: Simplify internal chunk ticking handling 2019-01-26 13:48:43 +00:00
519f6e2668 Merge branch '3.5' 2019-01-26 12:08:21 +00:00
939f3efa3b Merge branch '3.5' 2019-01-25 19:44:08 +00:00
6ee484e401 ChunkLoader: remove getLoaderId() (take 2) 2019-01-25 18:58:01 +00:00
bb27c76d13 Merge branch '3.5' 2019-01-25 17:12:00 +00:00
8a0f5cd7c9 Merge branch '3.5' 2019-01-25 13:19:40 +00:00
9d69154da5 Merge branch '3.5' 2019-01-24 18:45:06 +00:00
469b24b0a5 Remove built-in spawn protection
Users should use the new BasicSpawnProtection plugin instead.
2019-01-24 16:56:15 +00:00
df09b0101a Merge branch '3.5' 2019-01-24 11:50:19 +00:00
738e310798 Strip out RCON, closes #2686
Users should move to the new RconServer plugin instead.
2019-01-23 20:39:16 +00:00
61e04d5284 Merge branch '3.5' 2019-01-23 16:48:12 +00:00
6277787e0a Convert Particle to interface 2019-01-23 12:18:24 +00:00
d2284d5c47 Move Particle IDs to protocol namespace 2019-01-23 12:16:01 +00:00
23a18a8eb6 Convert Sound into interface 2019-01-23 12:10:24 +00:00
2356991022 Merge branch '3.5' 2019-01-22 22:27:07 +00:00
17fee801e6 RCON: remove unnecessary function 2019-01-22 13:43:55 +00:00
1ebc101ded fixed crash on dev build self-shutdown 2019-01-22 13:38:50 +00:00
48a99937b9 more exception handling cleanup 2019-01-22 13:37:46 +00:00
053defb7dc Updated RakLib dependency 2019-01-21 14:19:15 +00:00
4ae6428641 Level: rename getCollisionCubes() -> getCollisionBoxes()
these aren't cubes! shoghi, please read the dictionary.
2019-01-20 18:11:20 +00:00
425ad6101f Block: rename onEntityCollide() -> onEntityInside()
this better describes what the hook is for.
2019-01-20 18:09:47 +00:00
d586a18a16 Updated BedrockData submodule 2019-01-20 16:57:25 +00:00
ae7d6cc4a2 Merge branch '3.5' 2019-01-20 15:53:47 +00:00
467caf347d NetworkSession: Consistently don't use 0x prefix 2019-01-20 11:06:47 +00:00
5d8568b1a4 Add NetworkSession->getDisplayName(), clean up ip/port ad-hoc usages 2019-01-20 11:05:12 +00:00
842eb0200e Merge branch '3.5' 2019-01-19 19:14:39 +00:00
f9c067db50 Merge branch '3.5' 2019-01-19 17:48:57 +00:00
6df983da3e Merge branch '3.5' 2019-01-19 16:24:41 +00:00
9d8a70d5cf Level: use appropriate exceptions 2019-01-19 14:55:09 +00:00
65927e6965 Minor cleanup to Player NBT creation garbage 2019-01-19 14:32:20 +00:00
d3f9d1f3e7 Merge branch '3.5' 2019-01-19 13:57:42 +00:00
179fb9c7cb Fixed tree trunk generation bug introduced by ac87319aed
Blocks were being overwritten in the writebatch which hadn't yet been set, so reading them from the world yielded air blocks instead of trunk, allowing the generation to overwrite blocks which should have been logs.
2019-01-19 13:41:28 +00:00
6b7710e62b Introduce dedicated NBT data exceptions, fix up some corrupted chunk handling 2019-01-19 12:43:47 +00:00
c5998a92a8 PluginManager: clean up some Throwable abuse 2019-01-17 23:34:59 +00:00
c5df2f6f0d Remove another Throwable abuse 2019-01-17 22:43:52 +00:00
2dee7e9e0f Properly handle Query packet errors 2019-01-17 22:22:53 +00:00
38cf8d157d Max players check now works properly
This now includes all connected sessions, whether they are considered online or not.
2019-01-17 21:40:10 +00:00
41676cb4d4 Server: remove some useless methods 2019-01-17 21:01:31 +00:00
bbc8bc4df5 Move some error handling stuff to SPL 2019-01-17 19:16:03 +00:00
e341f3dce2 Level: rename getName() to getDisplayName() 2019-01-17 16:46:56 +00:00
76f1ee1827 Add restrictions on packet send directions with interfaces
This prevents plugins sending wrong packets at the compiler level (or would, if we had a compiler). It's more robust than a getter for client/server and throwing an exception since a static analysis tool can detect faults created by sending wrong packets from the server. This is also used to deny service to dodgy clients which send wrong packets to the server to attack it.
2019-01-17 12:51:24 +00:00
b82e00ffdf Extract a Packet interface from DataPacket
this is in preparation for clientbound/serverbound packet separation. I did this already on another branch, but the changeset was dependent on a massive refactor to split apart packets and binarystream which i'm still not fully happy with.
2019-01-17 12:21:56 +00:00
9c0ebb6350 Minor formatting fixes 2019-01-16 22:14:40 +00:00
38afe22b79 Move Event cancellable parts to trait 2019-01-16 22:14:25 +00:00
2e7e56de1e Merge branch '3.5' 2019-01-16 21:52:03 +00:00
2656993223 AAAAAAAAAAAAAAAAAAAAAAAAAAAAA 2019-01-16 21:31:17 +00:00
fc98f4c42b Address more error cases, some minor cleanup 2019-01-16 21:30:31 +00:00
44ef9fc577 LoginPacket: account for some missed error cases 2019-01-16 21:00:28 +00:00
c9c6a5dc94 Fixed some doc comments 2019-01-16 20:48:26 +00:00
23269da1a6 Fixed the disaster of packet receive error handling 2019-01-16 19:53:48 +00:00
ddc2bed63f Add an API change request template 2019-01-16 19:21:37 +00:00
8bc33a849a Remove built-in pcntl support
This is a bolt-on feature that can't be disabled and causes serious grief for Unix server users, because it prevents ctrl+c aborting the server the normal way.
Instead, we prefer introducing a plugin to implement this functionality, so that users can opt-in or opt-out.
2019-01-16 14:13:08 -05:00
390501ec35 Merge branch '3.5' 2019-01-16 18:57:17 +00:00
728bc95d73 NetworkSession: remove premature GC optimization
The only cyclic references here are both destroyed during normal collection directly (net interface removes from sessions array, player destroys its session reference), so there's no need to destroy them again here. This just causes a giant swathe of potential crashes for no real benefit.

close #2669
2019-01-16 16:50:16 +00:00
acdd0fec5f NetworkSession: player may be null 2019-01-16 16:19:39 +00:00
f647b1b7a5 Some cleanup to internal sounds handling 2019-01-15 21:32:41 +00:00
c34a4f45d4 Merge branch '3.5' 2019-01-15 14:46:03 +00:00
f882f557fb Merge branch '3.5' 2019-01-15 10:33:58 +00:00
242c7e3777 Grass: remove premature optimization
this is reading full-block from the chunk every access, which is slower than accessing the level block-cache.
2019-01-14 23:14:31 +00:00
797aabdf15 Entity: Protect move() to avoid stupidity 2019-01-14 19:57:46 +00:00
ff5cb84b81 Server: fixed an oops 2019-01-13 21:00:16 +00:00
3e1aa3e2b4 Network: remove Server dependency 2019-01-13 20:41:17 +00:00
9c53b41851 Added PlayerInfo, Player is no longer accessible during PlayerPreLoginEvent 2019-01-13 19:32:30 +00:00
d2082c0383 Explosion: Recalculate light on destroyed blocks
this has been a bug for a long long time. I think the reason it was never addressed is because of the performance impact associated with it. However, that performance impact is now gone thanks to light update batching.
2019-01-13 14:22:35 +00:00
1dca9074d5 Remove hacks for triggering adjacent light refill 2019-01-13 14:17:56 +00:00
82788774b0 Level: Queue all block updates until the end of tick
this allows deduplicating block updates when lots of adjacent blocks are set on a tick, which has beneficial effects on performance. It also fixes #2659.

Future scope:
- Use this mechanism to deal with explosions properly.
- Don't execute block updates for air blocks.
2019-01-13 13:24:02 +00:00
d2768188e8 LevelManager: remove unnecessary message 2019-01-12 19:52:28 +00:00
5052b75565 Separate Level management functionality from Server, clean up a bunch of mess 2019-01-12 19:11:05 +00:00
27761ac26e Fixed casing: Gamemode -> GameMode
it's two words, not one.
2019-01-12 16:19:31 +00:00
a756519e6b Move gamemode constants & functions to their own class
future enhancements:
- make gamemode an object containing information about abilities that players have in this gamemode (gamemodes are just predefined ability sets)
- get the magic numbers out of the API
2019-01-12 16:10:14 +00:00
49bdd92faa LoginPacket: Assert that extradata must exist 2019-01-11 17:56:18 +00:00
e9f023fe69 LoginPacket: fix corruption false-positives in offline mode 2019-01-11 17:55:58 +00:00
19614ed25e Entity: move some NBT usages out of constructor, fix missing property defaults 2019-01-10 21:01:19 +00:00
f4d07f0c1e Merge branch '3.5' 2019-01-10 19:31:01 +00:00
1f54760dae Config: Make load() private 2019-01-10 18:03:15 +00:00
5d8fa2e126 Crash main server thread when RakLib dies
this way we get crashdumps and find out what's actually wrong with RakLib in the wild.
2019-01-09 19:04:12 +00:00
cc230034f9 Fixed TransactionData->actions default value, closes #2652 2019-01-09 14:15:06 +00:00
b9ce6537a8 Sync composer dependencies (master) 2019-01-09 00:22:42 +00:00
8452c7bdbd Sync composer dependencies 2019-01-09 00:18:55 +00:00
2924303169 Sync NBT dependency 2019-01-07 22:38:04 +00:00
9c16caf27b Fixed an edge-case in AvailableCommandsPacket decoding 2019-01-07 22:23:51 +00:00
4f50119b74 LoginPacket: Cater for more error cases
This now doesn't crash unexpectedly at the first sign of broken data.
2019-01-07 14:45:44 +00:00
8663be8504 moar issue templates 2019-01-07 00:59:16 +00:00
78cb6445a5 Introduce TileFactory 2019-01-07 00:20:24 +00:00
7d827a1c65 Introduce EntityFactory
This contains all of the static stuff that was previously embedded in the Entity static root. This solves a bunch of problems like circular dependencies between parent and child classes, encapsulating logic and reducing the size of the enormous Entity.php.
2019-01-06 23:54:29 +00:00
b1cef8509a Revamp Entity construction
This is a similar refactor to the one I recently did for tiles.

- Entity::createEntity() is removed. In its place are Entity::create() (runtime creation, use where you'd use a constructor, accepts a ::class parameter, throws exceptions on unknown entities) and Entity::createFromData() (internal, used to restore entities from chunks, swallows unknown entities and returns null).
- Entity::registerEntity() is renamed to Entity::register().
- Added Entity::override() to allow overriding factory classes without touching save IDs. This allows more cleanly extending & overriding entities. This method only allows overriding registered Entity classes with children of that class, which makes code using the factory much more sane and allows to provide safety guarantees which make the code less nasty.
- Entity::getKnownEntityTypes() is renamed to Entity::getKnownTypes().
- ProjectileItem::getProjectileEntityType() now returns a ::class constant instead of a stringy ID.
- Cleaned up a bunch of nasty code, particularly in Bow.
2019-01-06 23:33:36 +00:00
3ae722867c Merge branch '3.5' 2019-01-06 20:19:18 +00:00
f0733f6ab6 Merge branch '3.5' 2019-01-06 01:09:34 +00:00
f80eeee20f Merge branch '3.5' 2019-01-05 18:59:13 +00:00
cdf2f98e26 Merge branch '3.5' 2019-01-05 17:41:26 +00:00
532def67ab Merge branch '3.5' 2019-01-05 11:12:34 +00:00
d83f024a1f Merge branch '3.5' 2019-01-05 09:27:16 +00:00
226db35cf9 Merge branch '3.5' 2019-01-04 23:56:53 +00:00
d8d04aeb53 fixup some imports 2019-01-04 23:49:32 +00:00
adc1069ed2 Merge branch '3.5' 2019-01-04 23:28:44 +00:00
febf1b1801 Merge branch '3.5' 2019-01-04 11:46:12 +00:00
7a4e2371e6 master-specific PHPStan nits 2019-01-04 00:40:09 +00:00
e1064a9e36 Merge branch '3.5' 2019-01-04 00:37:48 +00:00
8ef15d728a HandshakeSessionHandler: fix a doc comment bug
thank you PHPStan ❤️
2019-01-03 22:36:31 +00:00
c559dfccfe DataPacket: encode() and decode() are now final, encodePayload() and decodePayload() are now abstract 2019-01-03 21:14:54 +00:00
60687d8d6c Merge branch '3.5' 2019-01-03 18:02:33 +00:00
9840a3c980 Merge branch '3.5' 2019-01-03 17:29:53 +00:00
4d15eb3327 Cleaned up the InventoryTransactionPacket decoding clusterfuck
@shoghicp, y u do dis... I almost created a sub-packet architecture to deal with this shit :(

This mess really ought to be split into multiple packets. Perhaps the PacketPool can be extended to do that in the future.
2019-01-03 17:24:30 +00:00
134956ac58 Add a Support issue template
maybe this will guide people who don't read into shooting themselves in the foot automatically >:)
2019-01-03 16:37:48 +00:00
5806ce9205 add a Crash issue template
valid crashdumps are usually self explanatory and include all required information like OS/version/etc, so there's no need to force reporters to rewrite a bunch of extra information that should already be in the crashdump.
2019-01-03 16:32:21 +00:00
7853076d80 Merge branch 'master' of https://github.com/pmmp/pocketmine-mp 2019-01-03 15:45:33 +00:00
19fa6f5e8f Merge branch '3.5' 2019-01-03 15:44:48 +00:00
6ad405950a Update support.yml 2019-01-03 00:01:20 +00:00
71f123c616 Merge branch '3.5'
# Conflicts:
#	resources/locale
2019-01-02 21:25:57 +00:00
5bb414620c Merge branch '3.5' 2019-01-02 15:05:19 +00:00
171be946c6 Network: burn some deprecated stuff 2019-01-01 20:53:33 +00:00
f81bbd60e8 Avoid use of internal fields in BinaryStream 2019-01-01 16:42:14 +00:00
4a629e1a26 DataPacket: remove dead function clean() 2019-01-01 15:43:05 +00:00
c6a32ccf2a Merge branch 'release/3.5' 2019-01-01 14:08:20 +00:00
ff3d2ba19e Fixed no-NBT banner items always placing black banners, closes #2624 2018-12-31 22:04:08 +00:00
3b183447b0 Merge branch 'release/3.5' 2018-12-31 21:52:48 +00:00
8415e49a7f Merge branch 'release/3.5' 2018-12-30 19:06:37 +00:00
c6036fb012 Merge branch 'master' of https://github.com/pmmp/pocketmine-mp 2018-12-30 17:33:54 +00:00
ae497a828f Merge branch 'release/3.5' 2018-12-30 17:33:31 +00:00
1e58144a38 Add Discord link to issue template 2018-12-30 17:19:25 +00:00
39c0fa6103 Merge branch 'release/3.5' 2018-12-29 20:58:12 +00:00
2e5465e328 Updated RakLib dependency 2018-12-29 20:13:28 +00:00
7b3115c00c Moved network NBT serializer into network namespace 2018-12-29 20:12:00 +00:00
ac87319aed Introduce a "block write-batch" concept (#2555)
Make use of writebatch to generate trees, doors and double plants safely

- Fixes #2441 
- Fixes #2548 
- Closes #2498
2018-12-29 12:00:14 +00:00
aaaddd1fd6 Terminal: stick a RESET on the end when writing a newline 2018-12-29 11:54:44 +00:00
d86107e22a Terminal: Added write() and writeLine() to allow easily emitting Minecraft-formatted text to the console 2018-12-29 11:28:25 +00:00
498bffb34f Fixed --enable-ansi and --disable-ansi not being respected on threads
this causes some breakage to the behaviour of Terminal, and for that reason this is going on 4.0.

Terminal::hasFormattingCodes() will no longer auto-detect whether colour codes are supported.
2018-12-29 11:23:32 +00:00
10ac322b8f Merge branch 'release/3.5' 2018-12-29 00:04:33 +00:00
23954c4cda RegionLoader: Remove dead/broken code
garbage collection does need to be implemented, but I was looking at this code and found so many fucking bugs I decided it wasn't worth the effort of fixing.
2018-12-28 23:03:24 +00:00
baf278831e Merge branch 'release/3.5' 2018-12-28 19:32:48 +00:00
e6381297c7 NetworkCipher: fix some missing typehints 2018-12-28 17:35:37 +00:00
3ebd7e8ba6 Add network-wide API to filter raw packets by regex, stricter validation for Query 2018-12-28 16:30:52 +00:00
f06e67a792 Allow plugins to disable background generation (#2613) 2018-12-28 14:34:54 +00:00
78a80a6958 Tighten validity checks for block metadata
This filters out over 200 invalid states which were previously considered just fine, including zero-width cakes, buttons with broken facing values, furnace/chest with crazy values, and more.
2018-12-28 14:33:09 +00:00
333773bf14 Merge branch 'release/3.5' 2018-12-28 13:04:17 +00:00
045868783c Merge branch 'master' of https://github.com/pmmp/pocketmine-mp 2018-12-28 12:56:01 +00:00
e9d43aa44f Fixed MainLogger not being assigned as global on async workers 2018-12-28 12:55:49 +00:00
f64cef7eb6 ItemFactory: Get rid of $multiple crap
this is required in a specialized format, which doesn't make any sense. Plugins with multiple packed item formats should parse them themselves.
2018-12-28 11:55:52 +00:00
ab75e89d95 Fixed generation changes in recent builds compared to 3.x
this was caused by improper RNG sanitization and a recent cleanup refactor.
2018-12-27 17:36:41 -05:00
cf20f0e23a Merge branch 'release/3.5' 2018-12-27 15:53:12 +00:00
8564efc011 Sync item and block legacy IDs 2018-12-27 15:02:14 +00:00
b8f8a81704 Merge branch 'release/3.5' 2018-12-26 23:18:33 +00:00
ba33d8340a Merge branch 'release/3.5' 2018-12-26 22:26:44 +00:00
a6cd9ae029 Implemented #2556: don't send tile NBT updates until the end of tick
this eliminates spam when tile spawn NBT changes a lot during a tick, for example the lines of a sign being updated.

closes #2556
2018-12-26 22:18:52 +00:00
2c6381632c Allow Tiles to decide how to copy data from an item 2018-12-26 20:01:14 +00:00
f6983efec1 Revamp Tile creation (again)
This breaks down the handling of tile creation even further.
- Introduced a static Tile::override() method to allow overriding the construction class for a specific type of chest. This applies to classes as opposed to save IDs, so you can override Chest::class with MyCustomChest::class and it will take effect for any Chest save ID.
- Removed MCPE stringy save ID constants from public Tile interface. These are now only used for creating saved tiles from a stored chunk, and saving them.
- Renamed Tile::registerTile() to register()
- Tile::create() and Tile::createFromItem() now accept a class parameter instead of a stringy save ID.
- Tile::create() and Tile::createFromItem() were changed to throw \InvalidArgumentException on unknown/unregistered tile types. They also now never return null, but always (except in exception cases) return an object which is an instanceof the base class specified.
2018-12-26 19:21:37 +00:00
9f4bb440bd Move server-full/banned/whitelisted controls into PlayerPreLoginEvent
This allows plugins to more easily control the behaviour of server-full, whitelisting and banning. A message can be assigned for each, with a plugin custom reason taking the final priority if set.

This system solves several edge case problems in the Bukkit version by allowing kick reasons to be combined, so that removing one kick reason will roll back the final reason to the next highest, instead of just allowing the player through completely.
Only one message will be shown at point of disconnection, for consistency with the old behaviour.
The message priority is as follows (for all cases, only if set):
- Plugin reason
- Server full
- Whitelist enabled
- Player is banned

This also brings us one step closer to separating Player and NetworkSession.
2018-12-26 13:46:44 +00:00
02efa93e3a PlayerPreLoginEvent: New, more elegant way to control authentication requirement
Previously the only way to deal with this was to cancel the PlayerKickEvent generated by lack of authentication. Now, plugins can decide whether auth should be required for a specific player. The default is whatever xbox-auth is set to in server.properties.

cc @Johnmacrocraft
2018-12-23 18:24:33 +00:00
f313d06070 Merge branch 'release/3.5' 2018-12-23 14:04:29 +00:00
0e108341d7 Merge branch 'release/3.5' 2018-12-22 17:37:32 +00:00
1520bccf7d Merge branch 'master' of https://github.com/pmmp/pocketmine-mp 2018-12-22 13:31:40 +00:00
e5cb48bec2 Merge branch 'release/3.5' 2018-12-22 13:31:18 +00:00
17e5f60410 Add community Discord to Discussion section 2018-12-22 11:24:04 +00:00
16ffd99005 Merge branch 'release/3.5' 2018-12-21 18:40:04 +00:00
b709e21622 Merge branch 'release/3.5' 2018-12-21 17:27:02 +00:00
a2e4fdc8a2 Merge branch 'release/3.5' 2018-12-20 20:02:16 +00:00
2506947641 Merge branch 'release/3.5' 2018-12-20 20:01:02 +00:00
20aaa8373a Sound no longer extends Vector3 2018-12-16 14:26:42 +00:00
3c520aa786 Particle no longer extends Vector3 2018-12-16 14:15:41 +00:00
ebf9cb3e62 Merge branch 'release/3.5' 2018-12-16 14:13:35 +00:00
19edacbea9 BanIpCommand: fix crash when banning by playername, closes #2578 2018-12-15 13:59:10 +00:00
c5262fdf61 Merge branch 'release/3.5' 2018-12-14 17:32:58 +00:00
e0558d2551 Merge branch 'release/3.5' 2018-12-14 10:03:36 +00:00
125cc28aa0 Merge branch 'release/3.5' 2018-12-13 10:54:30 +00:00
e92aac847c Merge branch 'release/3.5' 2018-12-13 09:56:54 +00:00
ffa733fe0c Merge branch 'release/3.5' 2018-12-12 19:51:41 +00:00
a9dc447f8f Tile: make createFromData() retrieve the ID by itself 2018-12-11 14:56:25 +00:00
d72e4cb9a1 Tile: remove createNBT(), add create(), createFromData(), createFromItem() 2018-12-10 19:40:37 +00:00
6dbceda3e8 Tile: Fill defaults and move code to constructors where appropriate
this is leftovers from when NBT was required to construct a tile.
2018-12-10 18:35:26 +00:00
7d594ac6d8 Merge branch 'release/3.4' 2018-12-09 19:28:52 +00:00
7f0667a1f0 Merge branch 'release/3.4' 2018-12-09 15:36:23 +00:00
9fed25d3a5 Merge branch 'release/3.4' 2018-12-08 17:08:25 +00:00
8dbeda69a7 Make use of Facing::rotateY() to reduce boilerplate 2018-12-07 10:49:12 +00:00
1cac2b098e Merge branch 'release/3.4' 2018-12-06 21:08:47 +00:00
39e383a175 Entity: add getHorizontalFacing(), clean up some boilerplate code 2018-12-05 20:27:43 +00:00
f60d13548e Fix another stupid recursion bug 2018-12-05 20:10:00 +00:00
c53d3c28fb Register a couple of simple missing redstone blocks 2018-12-05 19:11:54 +00:00
281d8fd813 Redstone torch is lit by default 2018-12-05 15:07:18 +00:00
2014ebccd8 Make state setters fluent, clean up some BlockFactory noise 2018-12-05 15:03:59 +00:00
ceef3110d7 Remove dead function 2018-12-05 14:09:19 +00:00
cd5b81bdb9 ChunkManager: Remove getBlockIdAt()/setBlockIdAt()/getBlockDataAt()/setBlockDataAt(), add getBlockAt() and setBlockAt() 2018-12-04 22:27:00 +00:00
8dd2ea22b8 Level: make use of fromFullState() in getBlockAt() 2018-12-04 22:05:00 +00:00
47e62b1b38 Level: Add setBlockAt() which accepts integers instead of Vector3 2018-12-04 21:59:58 +00:00
b50e29085e Remove InventoryEventProcessor, use closures instead 2018-12-04 19:02:26 +00:00
05e968d9fd Merge branch 'release/3.4' 2018-12-04 18:40:54 +00:00
bfe766e626 oops, a merge error 2018-12-04 13:22:29 +00:00
8fc11c6ce0 Merge remote-tracking branch 'origin/release/3.4' 2018-12-04 13:18:56 +00:00
8051fa4f6d Remove some direct Position->level accesses 2018-12-03 21:39:17 +00:00
9fb365306a Make Block->position() accept Level,x,y,z instead of Position
since this is an internal method, it doesn't make sense to force a single parameter that requires potentially constructing a separate object just for the parameters, so we pass primitives instead, which are also easier to typehint against.
2018-12-03 21:18:22 +00:00
c3623478c1 Merge branch 'release/3.4' 2018-12-03 18:33:44 +00:00
302c509b9f Merge branch 'release/3.4' 2018-12-03 16:17:26 +00:00
df9534e220 Merge branch 'release/3.4' 2018-12-02 16:44:03 +00:00
5936205760 Merge branch 'release/3.4' 2018-12-01 16:51:32 +00:00
206f913d2b Merge branch 'release/3.4' 2018-12-01 10:10:52 +00:00
c46475ac4a Merge branch 'release/3.4' 2018-11-30 19:28:06 +00:00
16006f9175 Make Tile constructors non-dependent on NBT 2018-11-30 17:05:36 +00:00
a2253e9e7d Flatten still liquid blocks into a liquid block property 2018-11-30 16:06:35 +00:00
ed531c0009 Merge branch 'release/3.4' 2018-11-29 19:57:35 +00:00
790ef0325c Merge branch 'release/3.4' 2018-11-29 18:47:25 +00:00
c3063ccc44 Remove useless CustomInventory class 2018-11-29 14:40:15 +00:00
650a2eee4b Tile: remove unused import 2018-11-27 20:04:47 +00:00
5024713291 Fixed population artifacts always generating in the bottom subchunk, closes #2538 2018-11-26 14:29:06 +00:00
20f0e344d6 Merge branch 'release/3.4' 2018-11-26 14:02:59 +00:00
328ee40d5d Bring back support for all-sided logs, properly this time 2018-11-25 19:52:45 +00:00
c809365c39 Make RedstoneRail class abstract 2018-11-25 19:22:00 +00:00
8fe3f6ef1b Player now drops the contents of temporary inventories
these inventories are just glorified crafting tables.
2018-11-25 17:13:35 +00:00
a9a647855b Remove useless Recipe interface 2018-11-25 17:08:09 +00:00
2ef91f6e2e Merge branch 'release/3.4' 2018-11-25 16:36:46 +00:00
d0e2cdb54c Tile: remove server field
it would be nice to get rid of the server dependency entirely... perhaps craftingmanager should be a singleton? it's contextless after all...
2018-11-25 15:58:24 +00:00
d8ea8fa0f0 Use Block objects more instead of legacy ID/meta crap 2018-11-25 14:55:12 +00:00
7399e9036a Block: add method isSameState() to allow black-box comparison of blockstates 2018-11-25 14:53:57 +00:00
4698c723bd Merge branch 'release/3.4' 2018-11-25 14:36:20 +00:00
7ddcd2941b More AxisAlignedBB::one() usages 2018-11-24 19:49:15 +00:00
fcd81ada04 Make Thin use dynamic state properties 2018-11-24 19:44:32 +00:00
0fec58730b Level: fixed recursion bug when reading dynamic states
calculating dynamic states in some cases requires getting properties from neighbouring blocks, but getting these blocks also causes their dynamic states to be calculated, leading to a bouncing recursion.
This change allows retrieving blocks without calculating dynamic state information, if the call was generated by calculating dynamic state information.
Since these blocks are incomplete, they should not be cached and are only used to allow another adjacent block to complete its state. It is therefore not possible for a block's dynamic states to depend on another block's dynamic states.

This recursion bug was observable by running /gc and walking into a door, which would cause the server to freeze and crash.
2018-11-24 19:44:31 +00:00
d426d18b77 Add dynamic shape property for stairs 2018-11-24 19:44:31 +00:00
1170b66fd5 Automate creation of tiles when they are used to store block properties 2018-11-24 19:44:31 +00:00
3f3bdaeba5 Use dynamic state detection to localize stateinfo stored in tiles (hack) 2018-11-24 19:43:02 +00:00
3af293f024 Added a mechanism for blocks to detect dynamic state properties from surroundings 2018-11-24 19:43:02 +00:00
b2201c8c59 Further cleanup to general AABB handling 2018-11-24 19:17:03 +00:00
d5ae4ad141 Sync Math dependency 2018-11-24 18:34:49 +00:00
101de7adda Update Math dependency, obliterate some nasty code from Block 2018-11-23 19:41:52 +00:00
4c848bb4c1 docs fixes 2018-11-22 17:07:36 +00:00
8b350808ef Fixed merge error 2018-11-22 16:56:44 +00:00
98efd27543 Remove ability to set blockID and blockdata independently
This was the cause of many inconsistency and broken world bugs. In the future (once we switch to paletted chunks) this won't be possible anyway. For now, some temporary API is provided to allow modifying chunkdata directly, but it is required that **both** must be provided.
2018-11-22 16:53:22 +00:00
507d47a6f5 Merge branch 'release/3.4' 2018-11-22 16:49:30 +00:00
a4e81674c3 Merge branch 'release/3.4' 2018-11-17 18:13:03 +00:00
f7ba4f553c Merge branch 'release/3.4' 2018-11-17 16:30:19 +00:00
e67b1a20de Merge remote-tracking branch 'origin/release/3.4' 2018-11-17 14:47:35 +00:00
20dad95755 Liquid: don't try to flow out of the world, close #2510
this fix is only required for master, although it could be backported.
2018-11-14 17:48:14 +00:00
5d7feaaf21 Remove EventExecutor, event handlers now use closures (#2525)
This cleans up some cargo-cult code poorly copied from Bukkit, which has negative performance effects and also makes internal event handling more complex than necessary.

## API changes
- Removed `EventExecutor` and `MethodEventExecutor`.
- A listener is no longer required for an event handler to be registered. Closure objects can now be used directly provided that they meet the conditions for registration.
- `PluginManager->registerEvent()` signature has changed: the `Listener` and `EventExecutor` parameters have been removed and a `\Closure $handler` has been added in its place.
- `RegisteredListener` now requires a `Closure` parameter instead of `Listener, EventExecutor`.

## Behavioural changes
These changes reduce the execution complexity involved with calling an event handler. Since event calls can happen in hot paths, this may have visible positive effects on performance.

Initial testing reveals a performance improvement of ~15% per event handler call compared to the old method.
2018-11-13 21:04:47 +00:00
ddef7bb09b Merge branch 'master' of https://github.com/pmmp/pocketmine-mp 2018-11-13 18:31:34 +00:00
3fb8029dff Merge branch 'release/3.4' 2018-11-13 18:25:03 +00:00
3c86944a7c Item: make addEnchantment(), removeEnchantment() and removeEnchantments() fluent (#2523) 2018-11-13 16:48:13 +00:00
45caec874e Merge branch 'release/3.4' 2018-11-12 22:18:28 +00:00
3031128520 Merge branch 'release/3.4' 2018-11-11 19:52:05 +00:00
e16171e37e Merge branch 'release/3.4' 2018-11-11 12:39:01 +00:00
95bf3ab7a8 Merge branch 'release/3.4' 2018-11-11 11:15:54 +00:00
2965109484 Merge branch 'release/3.4' 2018-11-10 22:37:17 +00:00
3a6af3327f Encapsulate plugin.yml commands handling inside PluginBase, removed CommandExecutor requirement from Plugin interface
This removes the need for custom Plugin implementations to implement onCommand().

In the future it's planned to remove plugin.yml commands completely and have them registered similarly to how events are handled.
2018-11-09 19:50:52 +00:00
8b9ec5dde3 Merge branch 'release/3.4' 2018-11-07 22:11:27 +00:00
0b03e3c95b Update dependencies, fix travis failure 2018-11-05 21:20:42 +00:00
67a5f3f557 Register MainLogger as SPL global, remove hard MainLogger dependency from many areas, break a bunch of cyclic dependencies 2018-11-05 19:01:59 +00:00
ed8569a3f4 Remove Collectable class, fix memory leak on AsyncTask fatal error 2018-11-05 17:26:22 +00:00
c201a0e909 Move language submodule to resources/
again, this isn't source code.
2018-11-05 09:49:21 +00:00
ce7718f0d1 Move resources/ directory out of src/
this isn't source code and as such doesn't belong in here.
2018-11-05 09:46:43 +00:00
2a5ab1f397 Merge branch 'release/3.4' 2018-11-04 23:33:10 +00:00
6437078c8b TaskScheduler: remove deprecated constructor parameter 2018-11-04 23:30:04 +00:00
0028ce0ed2 Merge branch 'release/3.4' 2018-11-04 23:25:05 +00:00
2a43d9ecb6 Merge remote-tracking branch 'origin/release/3.4' 2018-11-04 22:56:03 +00:00
1c9137aa94 Merge branch 'release/3.4' 2018-11-04 22:18:15 +00:00
38d419fb29 Level: use isInWorld() where appropriate 2018-11-04 12:59:34 +00:00
6e05b5cc4b Merge branch 'release/3.4' 2018-11-04 11:57:40 +00:00
0e87cf801e Merge branch 'release/3.4' 2018-11-03 19:44:00 +00:00
652256a109 Merge branch 'release/3.4' 2018-11-03 16:58:19 +00:00
e94dd367ef Merge branch 'release/3.4' 2018-11-03 15:46:31 +00:00
1b4c65e74d Merge branch 'release/3.4' 2018-11-03 12:12:59 +00:00
acd3116591 Merge branch 'release/3.4' 2018-11-01 15:51:50 +00:00
4879eac946 Merge branch 'release/3.4' 2018-10-30 15:43:27 +00:00
d011fc518e Fixed wooden doors not dropping when removing supporting block, closes #2436 (#2496) 2018-10-29 16:16:57 +00:00
95be571481 Fixed Item->equals() not working for no-NBT items since 9bb3c93285 2018-10-29 12:45:39 +00:00
3760307a88 Merge branch 'release/3.4' 2018-10-29 12:42:29 +00:00
a6c31b72ae Level: throw exceptions on bad positions in setBlock() 2018-10-28 16:42:16 +00:00
7607e484dd Expose chunk locking to the API 2018-10-28 16:32:56 +00:00
1e8b153662 Further cleanup to Simplex/Noise hierarchy 2018-10-28 16:30:18 +00:00
e1795dfd49 Fixed wtf in Durable->setDamage() exception throw 2018-10-27 21:50:14 +01:00
f4105fd91a Noise: remove a ton of dead code 2018-10-27 17:04:53 +01:00
ff28c982ac Kick out unnecessary Perlin class
the code in here isn't used anywhere except as a base for Simplex, so it makes more sense to flatten it and get rid of the crap.
2018-10-27 16:33:58 +01:00
9bb3c93285 Remove network-serialized item NBT from API layer, item NBT is now retained for the lifetime of the stack 2018-10-27 15:26:01 +01:00
d2513ff908 Merge branch 'release/3.4' 2018-10-26 20:09:11 +01:00
0ef81e701a ItemFactory: Use a simple hashmap for item types
this is slower but yields less complicated code. Since this isn't in a hot path it's acceptable for this to slow down a little for the sake of sanity.
2018-10-26 18:38:24 +01:00
93131b4d92 Rename some meta usages to variant 2018-10-26 18:20:37 +01:00
7dd3b5b996 Durable: fixed leftover wtf from damage refactor 2018-10-26 18:17:34 +01:00
327c8361bd Remove variant parameters from TieredTool 2018-10-26 18:16:31 +01:00
f438736af5 Make some item constructor variant parameters mandatory 2018-10-26 16:51:02 +01:00
51e13104dc oops, missed one 2018-10-26 16:49:25 +01:00
712cafa0cc Item: remove redundant meta constructor params
these ctor params should only be used for variants in the ItemFactory registration, but all of these items have no non-zero variants anyway.
2018-10-26 16:29:14 +01:00
88b3df76eb Merge branch 'release/3.4' 2018-10-25 19:36:56 +01:00
c6a160d362 Merge branch 'release/3.4' 2018-10-25 18:42:19 +01:00
212d72657a AsyncPool: Switch to a more efficient collection algorithm, revamp internals (#2493)
This greatly improves GC performance by being more intelligent about how it collects garbage tasks. It knows that if X task in the queue is not finished, none of the tasks behind it can be finished either, so there's no point checking them.

This also presents the opportunity to cleanup a lot of async pool internals, so I've taken it and torched a lot of garbage.
2018-10-25 15:36:38 +01:00
a7eaec13b9 Merge branch 'release/3.4' 2018-10-24 15:53:13 +01:00
2aaac5a425 Merge branch 'release/3.4' 2018-10-24 12:18:04 +01:00
011b9ae159 Update to latest NBT lib version 2018-10-23 16:47:00 +01:00
a49abff099 Merge remote-tracking branch 'origin/release/3.4' 2018-10-22 17:46:37 +01:00
90482e79bc Merge branch 'release/3.4' 2018-10-21 18:23:54 +01:00
00b567e397 Merge branch 'master' of https://github.com/pmmp/pocketmine-mp 2018-10-21 15:33:42 +01:00
e9a4acda1d Merge branch 'release/3.4' 2018-10-21 15:32:57 +01:00
62db7727c0 Remove legacy issue template 2018-10-21 15:23:46 +01:00
08cf7e489f Update issue templates 2018-10-21 15:23:06 +01:00
742fbc25c3 BlockFactory: fixed 0 being assumed to be default if used
this defeated the whole point of adding this code ...
2018-10-20 21:42:34 +01:00
159c3a1a91 Merge branch 'release/3.4' 2018-10-20 19:20:22 +01:00
bae140dc02 Entity: remove dead code 2018-10-20 19:05:39 +01:00
fb128d0276 Merge branch 'release/3.4' 2018-10-20 16:43:25 +01:00
605e7e08ed Remove some deprecated methods 2018-10-20 15:29:43 +01:00
e035be8498 Remove some master-only usages of addGlobalPacket() 2018-10-20 15:27:08 +01:00
831a35ec69 Merge branch 'release/3.4' 2018-10-20 15:26:17 +01:00
517a21c418 RegionLoader: remove unused constant 2018-10-20 14:19:27 +01:00
d60c19551b Merge branch 'release/3.4' 2018-10-19 18:53:24 +01:00
93b8a6c44a Level: fix light removal bugs caused by 48a5eeb3a4 and 19e68f98a7
BlockFactory::\$lightFilter and Block->getLightFilter() are not equivalent.
2018-10-19 18:52:42 +01:00
7642298b4f Merge branch 'release/3.4' 2018-10-19 15:56:07 +01:00
39808dd94f Actually merge branch 'release/3.4' this time 2018-10-19 15:35:23 +01:00
d88b32da91 Drop useless numeric IDs for attributes, use strings instead 2018-10-19 15:29:01 +01:00
20b87b7875 Level: reduce complexity of populateChunk() 2018-10-19 15:29:01 +01:00
a2a6286e1c ItemFactory: clean up some unnecessary code
this try/catch isn't needed because the list offset derivation function will deal with invalid IDs anyway.
2018-10-19 15:29:01 +01:00
e7494fff96 - the fix didn't fix
this is a mess

it would be nice not to have to start the server to find these kinds of bugs >.<
2018-10-19 15:29:01 +01:00
f81849e550 ItemFactory: fix special case handling for durable items, close #2483 2018-10-19 15:29:01 +01:00
9284e53f9e Added failing test case for #2483 2018-10-19 15:29:00 +01:00
ec5af0398e VersionString: use appropriate regex for number matching 2018-10-19 15:29:00 +01:00
7d74ebbebc Merge branch 'release/3.3' 2018-10-16 09:51:30 +01:00
70054de575 Clean up garbage in Tree populators 2018-10-15 19:42:16 +01:00
cfee0a4e0b Merge branch 'release/3.3' 2018-10-14 11:08:50 +01:00
1b572d3e40 Level: rename unload to onUnload()
again, this is an intentional rug-jerk, along with a clearer naming.
2018-10-13 15:43:43 +01:00
bb286dea91 Server: more elegant isLevelGenerated() check 2018-10-13 15:37:26 +01:00
39d1196e4c Leaves: fix performance issue introduced by block meta nuke 2018-10-13 12:28:33 +01:00
f671da99a6 BlockFactory: fix failing test 2018-10-12 21:40:45 +01:00
7af7783cc8 BlockFactory: Register block to id|variant without setting state to allow non-zero default states
This will be needed to deal with things like chest/furnace which don't use 0 as a valid state (these both use facing horizontal for rotation, and vertical is invalid, so 0 would mean downwards facing which is invalid.
2018-10-12 20:05:44 +01:00
0520598584 BlockFactory: skip blockstates which corrupt the metadata
if the metadata doesn't match what was inputted when reading back, it's an invalid state and should not be registered.
2018-10-12 19:49:26 +01:00
873b64259d Torch: remove trailing comma 2018-10-12 19:07:43 +01:00
d151a89037 Vine: don't break when a supported vine is above, closes #2452 2018-10-12 18:38:52 +01:00
c96203b528 Set immobile flag on player pre-spawn
The client likes to fall involuntarily as soon as PLAYER_SPAWN PlayStatus is sent, which causes debug spam on the PM side and then movement reversions if falling far enough. This now prevents the client moving until the server knows the client has spawned.
2018-10-12 17:08:22 +01:00
acb794e728 Remove garbage from Entity(De)SpawnEvent
These methods:
a) add concrete dependencies
b) are pointless (event->getEntity() instanceof Creature, anyone? an IDE can better understand this as well...)
c) encourage bad code (they don't enforce type contracts the same way an instanceof check does - oh, and why not let's add an is*() for every new mob that gets added ever?
2018-10-12 16:35:51 +01:00
97c836f199 Remove nasty network crap from API 2018-10-12 16:31:17 +01:00
a944641509 Torch: Fix placement issues when clicking the bottom of a block, closes #2453 (#2474) 2018-10-12 12:26:44 +01:00
9901e61d65 Merge branch 'release/3.3' 2018-10-12 09:32:17 +01:00
9ac7c75e5b Merge branch 'release/3.3' 2018-10-11 19:44:06 +01:00
d583dc25c3 Merge branch 'release/3.3' 2018-10-10 13:45:31 +01:00
2e265423c7 Fixed NBT leveldata fixer never getting called 2018-10-10 04:44:45 -04:00
e2af394c81 Revert "Level: Identify chunk loaders by their object ID"
This reverts commit 3bb450244f.

PhpStorm you lying piece of shit... you only showed me the usages in Level!

This change should be revised and redone later.
2018-10-10 03:59:07 -04:00
9b31484655 Merge branch 'release/3.3' 2018-10-09 22:53:44 +01:00
3bb450244f Level: Identify chunk loaders by their object ID
chunkloader ID is completely unnecessary extra complication. spl_object_hash() would be fine for this as well, but a number is better. Since it's unique for the object lifetime (and the Level keeps a ref to loaders) this system should work just fine.
2018-10-09 16:32:34 +01:00
a653289c40 Rename Plugin->setEnabled() with a more clear name
This is intended to break API in order to jerk the rug out from underneath plugin developers who have been misusing this without noticing the side effects.
2018-10-08 13:06:51 +01:00
24677e1d79 Prevent undefined behaviour when accessing async worker thread-store from outside the worker itself 2018-10-08 13:01:12 +01:00
a0f3c03b50 oopsie woopsie
I made a fucky wucky! a wittle fucko boingo!
2018-10-08 12:59:47 +01:00
6ac0c517f5 Improve and simplify AsyncTask thread-local storage
This is now self-maintaining and doesn't rely on the async pool to wipe its ass on task completion. Instead, the garbage collector will cause thread-local data to be automatically released when the async task is garbage-collected on the main thread.
2018-10-08 12:48:44 +01:00
2bc663968e Merge branch 'release/3.3' 2018-10-07 19:45:38 +01:00
db9b235aa5 Merge branch 'release/3.3' 2018-10-07 17:48:32 +01:00
cc876b0e03 Merge branch 'release/3.3' 2018-10-07 16:36:43 +01:00
8d1400115e fixed unsupported leveldb format versions crashing the server 2018-10-07 15:42:59 +01:00
e13764832d Merge branch 'release/3.3' 2018-10-07 15:34:14 +01:00
7c1432526f Remove pointless ID maths from Level 2018-10-07 15:28:10 +01:00
139aaa5577 Protect Item->count 2018-10-07 14:34:04 +01:00
82c718cff0 Split Bucket into multiple classes 2018-10-07 14:03:13 +01:00
706082deb1 Fixed Flat generator using item ID/damage to build block layers 2018-10-07 12:01:43 +01:00
36548a335c Fixed some items disappeared after 5fb7825485 2018-10-06 21:30:21 +01:00
5fb7825485 Flatten Item variants, remove Item->setDamage() 2018-10-06 20:09:11 +01:00
14ef4558c2 Allow BlockFactory to handle position setting of newly created blocks 2018-10-06 19:06:49 +01:00
cdb17b1cee Fixed broken test 2018-10-06 17:39:11 +01:00
a430f7f4f7 Allow static properties and state masks to vary based on variant 2018-10-06 17:33:28 +01:00
9338061390 Update composer lock dependencies 2018-10-06 15:10:43 +01:00
785df3789d Remove now-unused internal function 2018-10-06 14:46:38 +01:00
7ee4fd55d3 Merge branch 'release/3.3' 2018-10-06 14:45:19 +01:00
78bb0145aa Remove unused imports from Block namespace 2018-10-05 18:31:06 +01:00
4608ecde9b Merge branch 'release/3.3' 2018-10-05 18:29:37 +01:00
495a0b1dc2 Merge branch 'release/3.3' 2018-10-05 18:11:33 +01:00
47f43c5e6b Remove some internal constants from public API 2018-10-04 20:03:11 +01:00
b407eba1a3 Apply typehints to level\format\io namespace 2018-10-04 19:59:26 +01:00
b214601a82 Silence PhpStorm complaining about hardcoded classpaths 2018-10-04 19:58:39 +01:00
a273a0c8a9 Fixed remaining cases of undefined behaviour on ambiguous world format
It was still possible to produce undefined behaviour by creating a db folder in a region-based world, or adding regions to a leveldb world. This now solves the problem completely by refusing to load the world if multiple formats match the world.
2018-10-04 19:43:31 +01:00
0cc4bc48cc Move generator classpath hack out of BaseLevelProvider 2018-10-04 18:55:20 +01:00
49e47edcf5 Separate level data handling from the main LevelProvider 2018-10-04 18:45:02 +01:00
f23bba053b Merge branch 'release/3.3' 2018-10-04 16:41:11 +01:00
b0f1863c4f Region loaders don't need to know their own coordinates 2018-10-04 16:37:19 +01:00
41f335e7d9 Level: Remove setSeed()
Seed is immutable information about the world, like its generator type, generator options, name, etc. We don't allow changing any of those things, so why the fuck would we allow changing the seed? This makes no sense at all.

I'm removing this because a) its existence makes no sense, and b) it will not produce the behaviour expected from such a function (what even is the expected behaviour???)
2018-10-04 16:24:07 +01:00
4d9d4d7c60 More cleanups to level provider hierarchy, move more garbage out of BaseLevelProvider 2018-10-04 16:02:55 +01:00
4f421d561c BaseLevelProvider: clean up not-exists error handling disaster
It checks for the existence of (and creates) the world directory if it doesn't exist. But what sense does this make when the world obviously doesn't exist in this case and must be generated first?
2018-10-04 15:41:18 +01:00
f787552e97 Remove LevelProvider::getProviderName()
This is problematic because child level providers can forget to override the provider name of their parents, and then override them by error. Instead, they should be used in a mapping fashion to make sure they are unique and not inherited.
Also, the old method did not permit registering multiple aliases for the same provider. This now makes that possible.
2018-10-04 14:56:42 +01:00
65b49dec71 Refactor hierarchy of Region-based world formats
In the future, McRegion and PMAnvil will become deprecated legacy formats which we won't support for writing anymore. However, this brings complications because Anvil (which would not be deprecated) would be sandwiched between its deprecated base (McRegion) and its deprecated child (PMAnvil), complicating the implementation (particularly for PMAnvil).

This abstracts away the generic Region-based world functionality into a separate class, making McRegion, Anvil and PMAnvil all inherit from it directly. Since only the chunk formats are different, they are more accurately siblings rather than parent-child (although Anvil and PMAnvil are cousins, ish).
2018-10-04 14:19:19 +01:00
eaf6b316c7 I always commit this submodule when I don't want it, and not when I do 2018-10-04 12:52:09 +01:00
050e972add Clean up default level provider management 2018-10-04 12:49:46 +01:00
23132b899c Added LevelProvider->getAllChunks() method
this returns a generator which yields known chunks. This will be used in the future for world format conversions.
2018-10-03 19:43:16 +01:00
8a062f440d Chunk: remove column methods
these were (mostly) unused, and the places they were used breaks the interface definitions. It also exposes internals that are sensitive to change.
2018-10-03 18:35:39 +01:00
77fd57e11a Removed wtf from Liquid 2018-10-01 16:20:35 -04:00
94936d0f6b Fixed CPU leak in falling water block updating
The cause of this was the flow decay of falling water changing, but the flow decay is ignored for falling water. This caused the block to be repeatedly set to itself, triggering local block updates, causing the disease to spread in large falling water bodies and cause immense amounts of lag.
2018-10-01 16:15:49 -04:00
74486d6880 Remove some state meta constants from API visibility 2018-09-30 14:43:55 +01:00
274a4d892f Rail: detect state and then place, not vice versa 2018-09-30 14:35:57 +01:00
1a2312418b Fixed assert failure when placing northeast/northwest powered rails 2018-09-30 14:17:30 +01:00
5344c0a627 Merge branch 'release/3.3' 2018-09-29 15:39:40 +01:00
8e6a5813ea Don't auto-create tiles on activate
this complicates the code unnecessarily and doesn't produce the desired effect in most cases anyway.
2018-09-28 20:12:41 +01:00
594a2041b6 Trapdoor: fix bad meth in comment 2018-09-28 16:44:30 +01:00
2600cf5977 Split some block variants into their own classes where behaviour differs 2018-09-28 16:21:03 +01:00
e038c4295d Clean up abhorrent mess of Slab placement code 2018-09-27 18:46:01 +01:00
35d51570be Add and make use of Block->isSameType() 2018-09-27 17:59:06 +01:00
8910c93de1 Slab: slight reduction of code repetition 2018-09-27 16:45:06 +01:00
73f1480e10 Merge branch 'release/3.3' 2018-09-27 16:36:57 +01:00
0b49ec46c6 Deduplicate Pumpkin/Melon stem code 2018-09-27 16:24:35 +01:00
75f364fcf2 Level: Remove obsolete \$direct parameter from setBlock()
this parameter was previously used to send blocks with a different set of flags, immediately, to players. However, the flags have been demonstrated useless and the direct sending is pointless now since packets are buffered now per session, so we might as well take advantage of the batched block update sending.
2018-09-27 16:15:07 +01:00
16f2ac14b3 Clean up block update sending, remove UpdateBlockPacket flag constants
These flags are not intended for network use, instead they are supposed to be used internally by the game. For network, we only need to care about the 0x02 flag (send to players) because that's necessary for the client to render the block.
2018-09-27 15:56:08 +01:00
8a8f1d84ff EnchantingTable: fix BB 2018-09-27 11:29:23 +01:00
e6a1398992 EndRod: fix BB rotation on X/Z axes
this was very apparent with the new code, less so with the magic meta values...
2018-09-27 02:36:39 -04:00
ac3509aa3d Updated BedrockData submodule
this change won't be backported to other branches due to technical limitations that can't be easily solved without API breaks.
2018-09-26 19:58:03 +01:00
f2c960cfd8 Added on/off handling for buttons and levers 2018-09-26 19:19:35 +01:00
ebf5ccea8a Merge branch 'release/3.3' 2018-09-26 13:12:54 +01:00
896ecb52f4 Merge branch 'release/3.3' 2018-09-24 18:27:26 -04:00
9651b3f470 Crops: micro optimization - check age before generating random number (faster)
I don't have any idea how much benefit this will provide in real terms, but it may be significant.
2018-09-24 16:48:19 +01:00
a195e940db Fixed BB and right-click action for daylight sensor 2018-09-24 16:37:18 +01:00
a77e05f875 Implement corner stair BB handling 2018-09-24 16:25:17 +01:00
0b989925d7 whitespace 2018-09-23 18:41:57 +01:00
c501c740a1 Get rid of Block->canPassThrough()
This is only implemented in 1 place where the collision box should just be zero anyway, so there's no point this existing.

There's a lot of other blocks which should have bounding boxes without collision boxes as well, but that's outside the scope of this commit.
2018-09-23 17:05:03 +01:00
3eca64e893 Merge branch 'release/3.3' 2018-09-23 16:45:22 +01:00
4f200c5183 Merge branch 'release/3.3' 2018-09-23 16:35:53 +01:00
8873efc303 Duplicate block IDs into ItemIds to allow for split
this will be necessary to deal with negative IDs (if I choose to do that), and it'll also be necessary if I decide to do any shift hacks to merge ID/variant for block IDs, because we don't want such things to affect items before we're ready to deal with that.
2018-09-23 15:53:16 +01:00
1427da0aeb Clean up item handling of blocks 2018-09-23 14:21:37 +01:00
ed1c511c3c Hacks for dealing with negative item IDs... 2018-09-23 14:14:58 +01:00
9d2e9e1663 Fixed torch facing bug with wrong metadata
torches cannot face down
2018-09-21 19:45:52 +01:00
3edf3a3a80 Entity: remove unused import 2018-09-21 19:34:18 +01:00
02d5f4da85 fix merge error 2018-09-21 19:32:59 +01:00
a093ba3ed9 thanks git 2018-09-21 19:30:04 +01:00
4a7f8fd9d9 Implemented behaviour for cocoa pods 2018-09-21 19:28:31 +01:00
56d9943b0d Nuke Block->meta, split into variant and state properties, lots of cleanup
This is a major change to the way block metadata is handled within the PM core. This separates variant metadata (which really ought to be part of the ID) from state metadata, and in a couple of cases flattens separate states of blocks together.

The result of this is that invalid variants can be much more easily detected, and additionally state handling is much cleaner since meta is only needed at the serialize layer instead of throughout the code.
2018-09-21 19:28:10 +01:00
a55ab54ddb Merge branch 'release/3.3' 2018-09-20 19:02:48 +01:00
eab7424955 Merge branch 'release/3.3' 2018-09-20 17:05:01 +01:00
960fdb433e Merge branch 'release/3.3' 2018-09-20 16:50:11 +01:00
9b4d82630b BlockFactory: remove $solid
this is premature optimization and will run into problems once we enter the flattening.
2018-09-20 16:26:15 +01:00
19e68f98a7 Level: Remove unnecessary BlockFactory::$lightFilter usage 2018-09-20 16:16:28 +01:00
668da0772a WaterLily: fixed broken placement logic 2018-09-20 12:49:36 +01:00
058bd07319 Merge branch 'release/3.3' 2018-09-20 10:04:42 +01:00
7da51ae97e Fixed ItemBlocks passing the wrong block name to their constructors 2018-09-19 17:51:28 +01:00
d92e79ba54 Level: fix crashdump #754691 2018-09-19 17:39:31 +01:00
0f33459632 missed this because it was too far to the right of the screen... 2018-09-19 16:20:54 +01:00
d291345ed7 Clean up some unused imports 2018-09-19 16:20:16 +01:00
caca097300 Merge branch 'release/3.3' 2018-09-19 16:18:53 +01:00
dbe0ee2d44 BlockFactory: don't pre-populate gaps with UnknownBlock objects
this produces a minor reduction in memory usage.
2018-09-19 15:17:39 +01:00
ef038d9625 Level: use block directly in updateBlockSkyLight() 2018-09-19 15:07:24 +01:00
48a5eeb3a4 BlockFactory: remove some useless static arrays 2018-09-19 15:06:58 +01:00
a80d5bb6a8 Leaf log search is type agnostic
any wood type will do
2018-09-19 08:47:40 +01:00
01f12d6147 Merge branch 'release/3.3' 2018-09-18 12:32:12 +01:00
c721503b7a Merge branch 'release/3.3' 2018-09-18 12:22:32 +01:00
31e4093882 Remove some remaining hardcoded meta maps 2018-09-16 18:00:16 +01:00
8aab51c532 Merge branch 'release/3.3' 2018-09-16 17:47:41 +01:00
1bb4daa7d1 Fixed mess of rotations being inverted 2018-09-16 17:37:36 +01:00
f7f06c993d Make block constructors not write to this->meta directly 2018-09-16 14:10:40 +01:00
ed8b8a13a3 Vine: cleanup BB calculation 2018-09-16 12:20:10 +01:00
54e19a6d2f Vine: fixed north check being missing 2018-09-15 17:10:57 +01:00
932705e114 Merge branch 'release/3.3' 2018-09-14 17:10:39 +01:00
0e5cbca983 PlayerInteractEvent: cleanup constructor now that block isn't optional anymore 2018-09-14 16:30:22 +01:00
db2567f965 Separate use-item action from PlayerInteractEvent
This solves the age-old issue of PlayerInteractEvent firing twice when a player clicks a block with an item in the hand.

API changes:
- Removed PlayerInteractEvent constants LEFT_CLICK_AIR, RIGHT_CLICK_AIR and PHYSICAL.
- PlayerInteractEvent no longer fires when the player right-clicks the air.
- Added new event PlayerItemUseEvent.
2018-09-14 16:24:29 +01:00
b660bcdb65 Merge branch 'release/3.3' 2018-09-14 16:20:22 +01:00
1f3c0524d9 Merge branch 'release/3.3' 2018-09-14 11:06:31 +01:00
d4580fa683 Cleanup Sugarcane placement code 2018-09-13 19:49:55 +01:00
8ad57f7ca0 Painting: use Facing::rotate() 2018-09-13 19:36:03 +01:00
2b8405e6ee Make use of Bearing::opposite() 2018-09-13 19:35:47 +01:00
f488e594f6 Remove hardcoded facing literals in for loops 2018-09-13 19:34:27 +01:00
65684eec99 Door: fixed bad rotation when no player is specified 2018-09-13 18:36:50 +01:00
0406c49ba9 Leaves: improve log search algorithm to fix vanilla inconsistencies 2018-09-13 17:30:23 +01:00
3b772f54e9 Leaves: make more findLog() params optional 2018-09-13 16:49:22 +01:00
fee42e9f34 Leaves: Replace a big mess of code with something nice and simple (#2432) 2018-09-13 16:36:10 +01:00
c0962a47be Block: Use parent::place() instead of setBlock() directly 2018-09-13 12:54:03 +01:00
54342ab0ce Remove ridiculous code in Ladder 2018-09-12 19:56:17 +01:00
778eb5fb33 Block: Make getId(), getDamage(), setDamage() non-final
In the future, these methods will be used to derive ID/meta on the fly from properties instead of using them internally.
2018-09-12 19:40:19 +01:00
e0574008b4 AsyncPool: Move removeTasks() functionality inside shutdown()
there's no need for a loop if we just have the workers shutdown directly, because they'll block until all tasks are done anyway.
2018-09-12 18:08:42 +01:00
653fa1213e Added an event for handling duplicate logins (#2430) 2018-09-12 11:23:48 +01:00
535d4e2c9b Added NetworkSession->getPlayer() 2018-09-12 10:51:37 +01:00
ebc1524f9a Merge remote-tracking branch 'origin/release/3.3' 2018-09-12 10:39:49 +01:00
dd2861dd1a Merge branch 'release/3.3' 2018-09-11 19:49:51 +01:00
e50ba18bbd Merge branch 'release/3.3' 2018-09-11 12:28:18 +01:00
b3902ed76f Merge branch 'release/3.3' 2018-09-11 11:40:54 +01:00
f03ab76c83 Remove imports left over from 5ce2d5e072 2018-09-10 17:51:13 +01:00
37190c9a65 Apply typehints to all AsyncTask methods
Since we're breaking API here anyway, no point in holding back on this.
2018-09-10 15:54:01 +01:00
d62e00cc74 AsyncPool: Remove Server dependency (API breaks included)
This brings two plugin-breaking changes: AsyncTask->onCompletion() and AsyncTask->onProgressUpdate() no longer accept Server parameters.

This now allows for the functionality of AsyncPool and AsyncTask to be tested outside of a Server.
2018-09-10 15:48:59 +01:00
5ce2d5e072 Clean up to Generator creation, remove getSeed() from ChunkManager interface
it's the generator's responsibility to know about the seed, not the chunkmanager's. This now reduces the complexity of implementing and using a chunkmanager.
2018-09-10 13:28:15 +01:00
0d152a2139 Merge branch 'release/3.3' 2018-09-08 14:30:16 +01:00
3bd224ae1a Merge branch 'release/3.3' 2018-09-06 19:31:11 +01:00
bd091eb744 Merge branch 'release/3.3' 2018-09-06 19:15:53 +01:00
f218868338 Separate facing/bearing handling from Vector3, deobfusticate a ton of @shoghicp old code 2018-09-05 19:56:14 +01:00
99fb267333 Merge branch 'release/3.3' 2018-09-04 15:58:24 +01:00
034472bfe7 Merge branch 'release/3.3' 2018-09-04 11:58:19 +01:00
bc7cefff77 Merge branch 'release/3.3' 2018-08-31 16:20:06 +01:00
71ece194e4 Merge branch 'release/3.3' 2018-08-30 15:47:12 +01:00
9553df0f03 Sync master and 3.3 branches 2018-08-30 11:07:02 +01:00
5b75c5953f Merge branch 'mcpe-1.6-master' 2018-08-29 17:27:59 +01:00
b2c0bba86e Merge branch 'release/3.2' into mcpe-1.6-master 2018-08-29 17:27:48 +01:00
cf7071de3d 3.2.1 is next 2018-08-29 17:25:31 +01:00
9b49d09714 LevelProvider: Added methods to get and set rain/lightning level and times 2018-08-28 15:02:45 +01:00
91064b3209 Merge branch 'release/3.2' 2018-08-26 19:15:23 +01:00
66e46e1c07 Level: use chunk records for tile reading in getTileAt()
the previous revision caused a crash when clicking on the bottom of the world due to a block hash being out of bounds.
2018-08-26 18:57:08 +01:00
b99decc585 Merge branch 'mcpe-1.6' into mcpe-1.6-master 2018-08-26 18:06:22 +01:00
fa77a4fa58 Merge branch 'master' into mcpe-1.6-master 2018-08-26 18:06:18 +01:00
5d1ec1ad49 Server: remove deprecated parameter from findEntity() 2018-08-25 18:38:10 +01:00
3b62926721 Merge branch 'release/3.2' 2018-08-25 18:37:27 +01:00
4fb1f8dd76 Merge branch 'release/3.2' 2018-08-25 17:49:28 +01:00
d6376a236d Player: assign allowFlight directly instead of using setter
fixes #2397

This was changed by a4939b6bf1 without apparent reason. It causes AdventureSettings to be sent too early.
2018-08-22 19:20:21 +01:00
286e062086 Merge branch 'release/3.2' 2018-08-22 15:42:00 +01:00
b5aa80b375 Merge branch 'release/3.2' 2018-08-21 19:54:40 +01:00
f830eddd59 Merge branch 'mcpe-1.6' into mcpe-1.6-master 2018-08-21 17:55:48 +01:00
ac8565fc2e Merge remote-tracking branch 'origin/release/3.2' 2018-08-19 19:54:34 +01:00
358d8b7af7 Merge branch 'release/3.2' 2018-08-19 19:52:51 +01:00
848bce193c Chunk: change tile storage hash function to unbind Y coordinate
this isn't strictly needed but it is more scalable in the case of future build height limit lifts.
2018-08-19 16:56:50 +01:00
7c41bfcdf3 Removed Tile numeric runtime IDs, use block hashes instead
Tiles are level-local and are not indexed globally like entities. There is pretty much zero point to them having numeric runtime IDs.
2018-08-19 16:37:04 +01:00
92aeab0d00 Merge branch 'release/3.2' 2018-08-19 16:03:04 +01:00
475ec413e5 Removed deprecated ServerCommandEvent and RemoteServerCommandEvent
if you get rekt by these changes... USE A RELEASE like we've been telling you for so long!
2018-08-19 14:23:41 +01:00
b629738312 Merge branch 'release/3.2' 2018-08-19 14:06:34 +01:00
aa55cd9acf Merge branch 'release/3.2' 2018-08-19 13:01:54 +01:00
1177a381c8 Merge branch 'release/3.2' 2018-08-19 11:45:16 +01:00
3a1f0eca7c Merge branch 'release/3.2' 2018-08-19 11:23:04 +01:00
9ad30e239a Merge branch 'release/3.2' 2018-08-19 10:37:20 +01:00
06d7ee283d Player: Don't use iusername in cases where it's useless
these calls all do strtolower() anyway, so having iusername here just makes it confusing.
2018-08-18 13:42:00 +01:00
a306421737 Entity: remove lastX lastY lastZ lastYaw lastPitch, replace with lastLocation object field 2018-08-18 13:38:19 +01:00
f8e3b0b16b Support bot: Be a little less rude 2018-08-18 13:22:53 +01:00
bbd878986d Merge branch 'master' of https://github.com/pmmp/pocketmine-mp 2018-08-17 19:48:44 +01:00
44daf57fbb Merge branch 'release/3.2' 2018-08-17 19:48:18 +01:00
2438d20971 Fixed zero-compression being ignored for small packets 2018-08-16 22:23:09 +01:00
24d0102ffb Merge branch 'release/3.2' 2018-08-16 18:34:13 +01:00
718ca40379 Merge branch 'release/3.2' 2018-08-16 15:52:25 +01:00
d32b9ec5dc Player: remove useless write to NBT
the parent constructor doesn't care about this tag, and the tag is discarded afterwards.
2018-08-15 14:56:02 +01:00
2ee0436f46 Continued cleanup of runtime entity NBT removal
it's no longer necessary to force-write these, since the NBT is now ephemeral. Any tag type mismatches should be dealt with on read, after which the original tag will be discarded anyway.
2018-08-15 14:50:58 +01:00
30fcfac8cf Merge branch 'release/3.2' 2018-08-15 13:48:52 +01:00
728142b113 Level: remove useless check for RIGHT_CLICK_AIR
it's impossible for this to fire because of the condition immediately above, and makes no sense anyway...
2018-08-14 19:39:06 +01:00
b3d8d10bec Player: move flight toggling to its own method 2018-08-14 19:21:13 +01:00
d8198d8130 Fixed setItemInHand() regressions when placing or breaking blocks
this was causing any items set into the hand during these events _at all_ to get overwritten, rather than just tools. That's a bit of a problem for buckets because buckets rely on a bad hack to handle the modified items.

This doesn't fix the tools bug, but that's a job for another time.
2018-08-14 16:44:14 +01:00
cef1fe9524 Merge branch 'release/3.2' 2018-08-14 16:11:42 +01:00
0ae9b41062 Merge branch 'release/3.2' 2018-08-14 15:03:37 +01:00
ce58294305 ProcessLoginTask: check connected status instead of closed status
connected is what we're looking for here, as opposed to an entity being marked as garbage.
2018-08-14 14:39:01 +01:00
0273e2484e Kill entity runtime NBT (#2361) 2018-08-14 13:33:02 +01:00
4b7300de8d Use openssl_digest() instead of hash() in network hot code
openssl_digest() is TWICE as fast as hash() on my machine for the same data and same algorithm. I can only guess that OpenSSL is more optimized than PHP ext/standard :)
2018-08-13 19:56:20 +01:00
59a51a6c75 ArmorInventory: use broadcast for sending armour updates 2018-08-13 16:12:25 +01:00
f2fd505bae ArmorInventory: fixed missed usages of dataPacket()
these were missed because PhpStorm couldn't infer the variable types in foreach, and there were no type docs to help it out.
2018-08-13 15:57:59 +01:00
78671bafe3 Remove unnecessary DataPacket->encode() calls 2018-08-13 15:52:55 +01:00
15bac8c58a Implement send buffering and queuing for network sessions (#2358)
Async compression and broadcasts are now reliable and don't have race condition bugs.
This features improved performance and significantly reduced bandwidth wastage.

Reduce Level broadcast latency by ticking network after levels. This ensures that session buffers get flushed as soon as possible after level tick, if level broadcasts were done.
2018-08-13 14:37:18 +01:00
22c8077bdf Merge branch 'release/3.2' 2018-08-13 13:22:47 +01:00
078a2486b5 Merge branch 'release/3.2' 2018-08-11 20:00:01 +01:00
dbf5d9e985 Merge branch 'release/3.2' 2018-08-11 19:37:55 +01:00
10f14beb4b Fixed intermittent crash on player disconnect when async compression is enabled 2018-08-11 19:12:23 +01:00
0d9968f305 Added donation methods 2018-08-11 15:22:58 +01:00
9c94ebcf82 Updated DevTools submodule to get bloat fixes 2018-08-08 16:58:13 +01:00
82bd6c5b34 Merge branch 'release/3.2' 2018-08-07 19:06:46 +01:00
d3fa8e0a0a Merge branch 'release/3.2' 2018-08-07 18:49:21 +01:00
ec9ef891ee Player: clean up some runtime usages of NBT
the goal is to get rid of this completely, but that's slightly complicated by the mess that is player creation right now.
2018-08-07 18:27:22 +01:00
16b789a528 Player: remove useless checks from save()
this should never be called for a player with an empty username (because data isn't saved unless the player was spawned) and the instanceof is laughable.
2018-08-07 17:37:55 +01:00
55ac1c80c9 Player: replace redundant usage of Server->broadcast() 2018-08-07 17:33:57 +01:00
12a7436aea Merge branch 'release/3.2' 2018-08-07 14:43:34 +01:00
202fb08792 Merge branch 'release/3.2' 2018-08-07 14:39:56 +01:00
3fa9712a1e Merge branch 'release/3.2' 2018-08-07 14:32:47 +01:00
bd993b2342 Merge remote-tracking branch 'origin/release/3.2' 2018-08-07 12:34:07 +01:00
4597899ac3 Merge branch 'release/3.2' 2018-08-06 21:34:07 +01:00
e5b69deccf Merge branch 'release/3.2' 2018-08-06 20:53:16 +01:00
4142666df8 Level: clean up and remove checkTime() 2018-08-06 19:00:00 +01:00
fb0cc0804c Merge branch 'release/3.2' 2018-08-06 18:45:53 +01:00
ff6d590d0c PlayerInventory: Send updates to viewers automatically on setItemInHand() 2018-08-05 19:31:21 +01:00
c90e3e351d PlayerBlockPickEvent: remove setResultItem()
the same behaviour can be achieved by cancelling the event and setting the held item manually. Allowing this to be changed increases the complexity of dealing with survival block picking.
2018-08-05 19:07:23 +01:00
6fcb221453 Remove useless crap from ChunkLoader interface
these methods are not used anywhere and are unnecessary extra baggage for any implementation.
2018-08-05 18:38:51 +01:00
90f80782d4 Player: remove useless return value from dropItem() 2018-08-05 12:55:12 +01:00
ea9415961b Player: remove useless check from dropItem()
the transaction system will deal with this now, and if a plugin wants to make a player drop a null item, they are free to do so.
2018-08-05 12:53:31 +01:00
5df56a1bac Clean up some AnimatePacket boilerplate code 2018-08-05 12:39:36 +01:00
d81388f62c Merge branch 'release/3.2' 2018-08-05 12:21:06 +01:00
ac832f94a8 Merge branch 'release/3.2' 2018-08-05 11:33:20 +01:00
a5383b4a82 Use SetLocalPlayerAsInitializedPacket for spawning, fixed a bunch of bugs
this should fix forms not working during PlayerJoinEvent, and also removes the spurious PlayerItemHeldEvent firing on spawn bug.

The player MUST now send this packet. Bots take note.
2018-08-05 10:45:41 +01:00
25660843c5 Player: Obliterate InventoryTransactionPacket handler, add some new methods 2018-08-04 20:01:32 +01:00
905c0c825c Merge branch 'release/3.2' 2018-08-04 16:47:35 +01:00
83077309ef Merge branch 'release/3.2' 2018-08-04 16:03:46 +01:00
20f3b82d52 Be less dependent on AsyncTask->onCompletion() Server parameter
this is going to get removed soon.
2018-08-04 15:56:14 +01:00
779d92c656 BulkCurlTask: Remove complexData parameter (BC break)
This is a leftover from when it was necessary to pass complex data to the AsyncTask constructor in order to have it locally-stored. Since this has now been superseded by storeLocal(), it doesn't make sense for this parameter to exist anymore.
2018-08-04 14:44:20 +01:00
2cb6307e5b Merge branch 'release/3.2' 2018-08-03 20:08:01 +01:00
2170411cf8 Merge branch 'release/3.2' 2018-08-03 18:50:37 +01:00
425b1aa6f5 Merge branch 'master' of https://github.com/pmmp/pocketmine-mp 2018-08-03 18:25:21 +01:00
588d6c4b26 Merge branch 'release/3.2' 2018-08-03 18:24:50 +01:00
0e44e5b681 Update ISSUE_TEMPLATE.md 2018-08-03 09:02:53 +01:00
10ba3d6359 Network: add ability to tick sessions
moved responsibility for login timeout checks to NetworkSession instead of Server
2018-08-02 17:39:09 +01:00
e43496e7e4 Network: clean up ticking handling, RakLib only processes on Snooze notification 2018-08-02 17:14:21 +01:00
7560880168 Added DataPacketBroadcastEvent, refactor broadcast handling, close #1521
batchPackets() is now considered internal and shouldn't be used by plugins.

Added Server->broadcastPackets(Player[], DataPacket[]) : bool
2018-08-02 15:54:30 +01:00
c345e6f22c Merge branch 'release/3.2' 2018-08-02 14:43:59 +01:00
af6b279e54 Player: Ensure we always get flagged as closed when parent constructor was never called
This was causing unexpected bugs when players got disconnected during the login sequence.
2018-08-01 17:28:30 +01:00
809b33033e Player: Use connected status instead of Entity->closed flag 2018-08-01 17:27:32 +01:00
1ef538b69e LoginSessionHandler: fix crash when disconnected during login handling 2018-07-31 19:40:24 +01:00
47cf6e4833 Fixed not being able to disable encryption 2018-07-31 18:51:57 +01:00
32a78e679a Fixed JWT padding 2018-07-31 18:36:36 +01:00
488c03c200 Make timings for player network more detailed 2018-07-31 16:34:15 +01:00
2bf6764112 Implemented network encryption (#2343)
For those who fuss about performance, you can disable the `network.enable-encryption` option to use sessions without encryption.
2018-07-31 15:54:18 +01:00
62cb7963dc Remove deprecated functions for 4.0.0
If any moron starts complaining that their plugins broke, tell them to use 3.x... thanks
2018-07-31 14:37:54 +01:00
4e8a256a53 Language: use null coalesce for get() and internalGet() 2018-07-30 17:29:13 +01:00
58b46179f9 Language: make internal function not public
this is only used within the Language class anyway.
2018-07-30 17:27:48 +01:00
0d9952d53e Rename BaseLang -> Language 2018-07-30 17:07:19 +01:00
d26631d8e0 Clean up BaseLang error handling, throw exceptions instead 2018-07-30 17:00:52 +01:00
cab2d52ff8 Merge branch 'release/3.2' 2018-07-30 15:21:50 +01:00
fd3456e831 Merge branch 'release/3.2' 2018-07-30 14:54:15 +01:00
14f144b6f6 Merge branch 'release/3.2' 2018-07-30 09:36:53 +01:00
bdd42d6a78 Added NetworkSession->sendEncoded(), clean up some code 2018-07-27 18:39:14 +01:00
2647b3f404 VerifyLoginTask: remove unnecessary wordwrap()
I don't recall why this was needed, but it's not.
2018-07-27 18:33:10 +01:00
7541a6070f Player: clean up handling of authentication 2018-07-27 18:04:13 +01:00
f3cf64c2cf Security vulnerability reporting for dummies 2018-07-27 12:27:29 +01:00
df45e8a2cc Merge branch 'release/3.2' 2018-07-27 11:47:43 +01:00
eb738d1d72 Apply more typehints to generator namespace 2018-07-26 19:31:18 +01:00
edb03e8a9b Remove more dead code from the generator
this stuff is useless broken crap that just makes noise in inspections for no good reason... bye
2018-07-26 19:21:38 +01:00
20a5b75622 PluginBase: fixed error always being emitted on saveConfig()
This now throws exceptions... let's let the caller deal with this instead, it makes more sense anyway
2018-07-26 19:14:16 +01:00
c3bc751b04 Merge branch 'release/3.2' 2018-07-26 16:00:46 +01:00
be37236c76 Deduplicate code for general classpath registries 2018-07-26 15:21:03 +01:00
e016693779 Test one extra case for LevelProviderManager 2018-07-26 15:17:16 +01:00
d305a1342f Make Tile::registerTile() and Entity::registerEntity() throw exceptions instead of returning false 2018-07-26 14:55:55 +01:00
b9769c407b Merge branch 'release/3.2' 2018-07-26 14:40:39 +01:00
522f0f5c25 Config: remove dead field 2018-07-26 14:05:38 +01:00
7e81a09409 Merge branch 'release/3.2' 2018-07-26 14:03:39 +01:00
e6cbdd090e Merge branch 'release/3.2' 2018-07-26 10:25:25 +01:00
203d7e23f4 Merge branch 'release/3.2' 2018-07-25 20:57:57 +01:00
057d4fc62f Merge branch 'release/3.2' 2018-07-25 18:52:26 +01:00
98b34aaac8 Merge remote-tracking branch 'origin/release/3.2' 2018-07-25 15:51:39 +01:00
7f87714dae Merge branch 'release/3.2' 2018-07-25 15:30:50 +01:00
c09a774da7 Merge branch 'release/3.2' 2018-07-24 17:19:24 +01:00
4059e1f84c Merge branch 'release/3.2' 2018-07-24 16:33:37 +01:00
622fe99982 NetworkSession: Don't crash on failure to decode compressed batches
this could be an outdated version (pre-1.1 for example).
2018-07-23 14:38:46 +01:00
cc84ec8629 Fixed Player/NetworkSession/SessionHandler cycle memory leak
NetworkSession and some SessionHandlers hold cyclic refs to each other, stopping them getting destroyed. Unfortunately, these also reference the player, stopping that getting destroyed too.

The cycle garbage collector will deal with this, but it's best to get rid of the cyclic refs for immediate collection.
2018-07-22 13:41:06 +01:00
fe1df70923 Player: be less horrible and leave a deprecated proxy for dataPacket() 2018-07-22 12:20:13 +01:00
c1843ac2d4 Player: remove dataPacket() and directDataPacket()
I considered renaming sendDataPacket() to dataPacket() to reduce the BC breaks, but the parameter set has changed, which might cause astonishing behaviour, so it's better to break it in a loud way. Also, this has a clearer name.
2018-07-22 12:04:53 +01:00
85105ed066 Inseparable set of network changes - these all need each other to work
- Separated player handling and creation from network interfaces
- Rewire disconnects to make them not be recursive
- Batching now uses sessions instead of players
- Fixed DisconnectPacket getting sent to players who disconnect of their own accord
2018-07-21 20:03:05 +01:00
a86d3fe071 PlayerCreationEvent: Remove useless crap from constructor 2018-07-21 18:42:18 +01:00
b93318b2cf RakLibInterface: Use NetworkSession API for getting IP instead of Player
soon the network interfaces won't be dealing with Players at all.
2018-07-21 18:41:15 +01:00
ca1a0c8643 Move responsibility for ping handling to NetworkSession 2018-07-21 16:33:12 +01:00
57e5b1309d NetworkSession: Stop processing batch if player gets disconnected during handling 2018-07-21 16:27:30 +01:00
34d64be427 CompressBatchedTask: players aren't strings 2018-07-21 16:10:25 +01:00
dc29b4dc3f Merge branch 'release/3.2' 2018-07-21 15:57:56 +01:00
01a9e53394 Config: Clean up error handling, throw exceptions instead of returning false (#2314)
This also has the happy side effect of removing a cyclic dependency between Config and Server. There's only the dependency on MainLogger left to get rid of now.
2018-07-21 15:50:58 +01:00
c5bf746e4c typo 2018-07-21 14:45:22 +01:00
7d8624b12f ResourcePacksSessionHandler: clean up error reporting 2018-07-21 14:44:54 +01:00
da876cc8f3 ResourcePacksSessionHandler: Prevent clients requesting the same chunk more than once
Currently this can be used to attack the server by spamming requests for the same chunks forever. This commit prevents that by disconnecting the client if a chunk is requested more than 1 time. It is not necessary to allow more than 1 request per chunk, since RakNet should ensure that these are always delivered correctly.
2018-07-21 14:31:34 +01:00
d6e61e3e00 ResourcePacksSessionHandler: Account for out-of-bounds chunk requests 2018-07-21 14:19:24 +01:00
b9cd96f6e0 ResourcePacksSessionHandler: remove useless brackets 2018-07-21 13:36:20 +01:00
25a5394152 Merge phase 1 of network refactor - session handler rewrite
There are further changes that need to be done yet, but this section is now ready for showtime.
2018-07-21 10:03:17 +01:00
bfc372c6fb Merge branch 'release/3.2' 2018-07-21 09:53:50 +01:00
c257a791e1 ResourcePacksSessionHandler: move max pack chunk size to const 2018-07-21 09:37:15 +01:00
59f6821c29 Allow parameterizing ResourcePackManager to session handler
this will open the way (in the future) for custom managers to be used, instead of a global thing.
2018-07-20 20:08:12 +01:00
30c044f028 Unwrap more code from packet handlers 2018-07-20 18:48:46 +01:00
015ee90571 Split PlayerActionPacket handling into two classes, death is now a session state 2018-07-20 18:11:29 +01:00
f626b9e8a0 Initial mass migration to session handlers
This introduces several new session handlers, splitting up session handling into several new states:

- Login: Only allows handling the LoginPacket. This is the only time LoginPacket can be sent, and it'll be discarded when sent at any other time.
- Resource packs: Handles only the resource packs sequence (downloading packs and such). This is the only time ResourcePackClientResponse and ResourcePackChunkRequest will be handled.
- Pre-spawn: Only chunk radius requests are accepted during this state.

SimpleNetworkHandler handles all the "rest" of the logic that hasn't yet been separated out into their own dedicated handlers. There's also a NullNetworkHandler which discards all packets while it's active.

This solves a large number of issues with the security of the login sequence. It solves a range of possible DoS attacks and crashes, while also allowing great code simplification and cleanup.
2018-07-20 17:09:04 +01:00
97a1483f75 Player: remove useless crap from "constructor"
1. this isn't really the player constructor
2. this shit isn't needed until we start using the player as an actual player
2018-07-20 15:38:53 +01:00
a4939b6bf1 Player: re-structure a whole bunch of construction mess
This consolidates the Player entity construction and makes it more organized and consistent. There is of course a lot more work to do apart from this on player construction.
2018-07-20 15:34:47 +01:00
7633136a86 Player: move max players check to somewhere that makes sense 2018-07-20 13:22:08 +01:00
3cd105ff33 Remove remnants of needACK functionality
this has been broken for a long time and hasn't been used for even longer.
2018-07-20 13:07:06 +01:00
0fecb79add Player: separate some PlayerActionPacket handling logic out into their own functions
these are public, because later on the session handler will be calling these instead of the player itself.
2018-07-20 13:02:36 +01:00
aae19d45b7 Player: remove useless handleDataPacket() leftover 2018-07-20 12:41:16 +01:00
57a86d9ed7 Player: remove useless InteractPacket handler
all the things we cared about in here don't exist anymore, so there's no sense in the handler still existing. It can be restored when we want to use the things it still does.
2018-07-20 12:39:48 +01:00
25cfcada26 Player: clean up container close handling 2018-07-20 12:36:44 +01:00
e16f20affa NetworkSession: added getHandler() and setHandler(), SessionHandler->setUp() now not useless 2018-07-20 12:36:44 +01:00
08621604cd PacketPool: remove redundant comment
this was added to signify that these were normal, while BatchPacket was a hack. Since this has now been corrected, there's no need for the comment.
2018-07-20 12:36:44 +01:00
cdcafb1e75 PacketPool: Properly deal with varint packet IDs now that BatchPacket is gone 2018-07-20 12:36:44 +01:00
64ecc373be Split up session base logic and packet handling
this will allow for mutable packet handlers which can be used to cleanly implement multi-stage game sessions.
2018-07-20 12:36:44 +01:00
bdd9a7eb52 Kill BatchPacket, clean up batching related things
DataPacketSendEvent and DataPacketReceiveEvent will no longer capture BatchPackets
In most places strings are now used instead of DataPackets, to remove limitations on what data can be sent to a network interface
Removed CraftingManager's cyclic dependency on Server

There is a lot more work to do aside from this, but this commit is intended to clean up what is necessary to fix the handling of BatchPacket.
2018-07-20 12:36:44 +01:00
85647c03bf Move IP/port to NetworkSession 2018-07-20 12:36:43 +01:00
f969f3b77f Flatten NetworkSession hierarchy in preparation for refactor 2018-07-20 12:36:43 +01:00
bf4c6e4c2b Merge branch 'release/3.2' 2018-07-20 12:21:56 +01:00
f77ab468e3 Merge branch 'release/3.2' 2018-07-20 11:57:21 +01:00
424e9f4a49 Merge branch 'release/3.2' 2018-07-20 11:30:46 +01:00
1144620f2b Level: minor de-spaghettification of chunk requesting
Now the Level tells the player to request chunks on tick, instead of the server doing it.
2018-07-18 16:49:58 +01:00
e57dd3e8ba Merge branch 'release/3.2' 2018-07-18 15:14:41 +01:00
36e197e2a9 Move more session logic out of Player 2018-07-18 12:48:58 +01:00
4d1e2d1b3a Rename SourceInterface -> NetworkInterface
SourceInterface doesn't make sense really...
2018-07-18 11:03:21 +01:00
965f0d670d Improve documentation of SourceInterface and AdvancedSourceInterface 2018-07-18 11:01:16 +01:00
bc9a387b0b Fixed merge error 2018-07-17 18:46:27 +01:00
df3870a112 Merge branch 'release/3.2' 2018-07-17 18:35:43 +01:00
f47d6ee683 Merge branch 'release/3.1' 2018-07-17 16:57:08 +01:00
73afa22f50 Merge branch 'release/3.1' 2018-07-17 14:53:03 +01:00
ddc118a562 Merge branch 'release/3.1' 2018-07-17 12:02:33 +01:00
1f023bdcef Merge branch 'release/3.1' 2018-07-17 10:13:00 +01:00
70f874a559 Merge branch 'release/3.1' 2018-07-16 12:08:29 +01:00
e502280b20 Merge branch 'release/3.1' 2018-07-14 19:28:47 +01:00
4962d9df97 Merge branch 'release/3.1' 2018-07-14 16:06:08 +01:00
340de1c478 Merge branch 'release/3.1' 2018-07-14 11:57:32 +01:00
fbbb6f3beb Merge branch 'release/3.1' 2018-07-14 10:39:34 +01:00
25022b3144 Merge branch 'release/3.1' 2018-07-13 12:38:41 +01:00
599a64c80c Merge branch 'release/3.1' 2018-07-12 19:32:14 +01:00
ee5165b040 Merge branch 'release/3.1' 2018-07-12 18:04:26 +01:00
83065024f7 Merge branch 'release/3.1' 2018-07-11 10:21:24 +01:00
33ad4de981 Merge branch 'release/3.1' 2018-07-11 09:16:55 +01:00
eb8eac42b8 Merge branch 'release/3.1' 2018-07-10 12:48:14 +01:00
80ebc0bc5f Merge branch 'release/3.1' 2018-07-09 18:44:55 +01:00
46ea0186e4 Merge branch 'release/3.1' 2018-07-09 10:06:44 +01:00
9c80e349ce Merge branch 'release/3.1' 2018-07-08 12:17:18 +01:00
258b4f9dde ChunkRequestTask: add docs and typehints 2018-07-07 19:35:40 +01:00
78d27dc3e4 Move ChunkRequestTask to pocketmine\network\mcpe namespace
it has a lot to do with network and little to do with world I/O (load/save).
2018-07-07 19:34:11 +01:00
7e7cd6c995 Merge branch 'release/3.1' 2018-07-07 19:22:51 +01:00
b23c947060 Merge branch 'release/3.1' 2018-07-06 13:12:22 +01:00
4ccbb8b21a Merge branch 'release/3.1' 2018-07-05 17:43:19 +01:00
120eb8e362 CompressBatchedTask: move to pocketmine\network\mcpe namespace 2018-07-05 13:38:33 +01:00
2907de81ad Apply typehints to more general pocketmine\network namespace 2018-07-05 13:36:23 +01:00
950465d283 as always, missed one - I blame PhpStorm 2018-07-05 13:35:04 +01:00
2bba3a0805 Apply typehints to pocketmine\network\mcpe\protocol namespace
this is pulled from network-nuke in order to reduce the size of the diff.
2018-07-05 13:19:15 +01:00
fbd4f4a849 Merge branch 'release/3.1' 2018-07-05 12:11:26 +01:00
399870bf31 Merge branch 'release/3.1' 2018-07-02 16:58:22 +01:00
2252f7498d Merge branch 'release/3.1' 2018-07-02 16:57:01 +01:00
5dc4e17a96 Updated TesterPlugin submodule 2018-06-29 20:11:32 +01:00
49bca0d5a1 Remove a whole bunch of crap from the Plugin public interface (#2268)
- remove onLoad(), onEnable(), onDisable()
- remove Config related methods
- remove getResource(), saveResource(), getResources()

did I troll any readers so far?

On a more serious note, these methods do not need to be declared in this interface because they are either hooks (`onLoad()`, `onEnable()`, `onDisable()`) or methods only used from within `PluginBase` and its children. They are not intended to be public API, and for this reason they don't need to be exposed in the interface.
2018-06-29 20:04:10 +01:00
3846ee3d1d reorganize and optimize start.sh (#2267) 2018-06-29 14:48:29 +01:00
d49a41f788 Merge branch 'release/3.1' 2018-06-29 12:31:04 +01:00
4a11ded185 Merge branch 'release/3.1' 2018-06-29 12:19:32 +01:00
fc8dc8a497 Merge branch 'release/3.1' 2018-06-24 17:34:57 +01:00
cfee9aa117 Merge branch 'release/3.1' 2018-06-24 12:07:57 +01:00
884ebe632d Merge branch 'release/3.1' 2018-06-23 13:04:20 +01:00
d67149376d Merge branch 'release/3.1' 2018-06-22 17:48:09 +01:00
78aa1ee22e Merge branch 'release/3.1' 2018-06-22 13:42:29 +01:00
f60b0e5cc7 Server: more dev build warnings 2018-06-22 09:40:33 +01:00
9a6a5e2088 submodule updates 2018-06-22 09:36:07 +01:00
23085bf9b3 Merge branch 'master' of https://github.com/pmmp/pocketmine-mp 2018-06-22 09:14:03 +01:00
0948c65276 Merge branch 'release/3.x' 2018-06-22 09:13:49 +01:00
2308eadf53 Add ExamplePlugin to README 2018-06-21 22:15:50 +01:00
eddd626461 Trapdoor: fixed condition for side checking 2018-06-21 20:13:26 +01:00
8a65941489 reeeeee 2018-06-21 20:01:27 +01:00
99a0c2a188 Block: Make recalculation of BB non-dependent on block position
This now computes BBs relative to 0,0,0 and then offsets them as appropriate. This requires less boilerplate code and also furthers the goal of separating block types from instances.
2018-06-21 19:58:28 +01:00
1114 changed files with 40510 additions and 33767 deletions

2
.gitignore vendored
View File

@ -1,5 +1,6 @@
players/*
worlds/*
world_conversion_backups/*
plugin_data/*
plugins/*
bin*/*
@ -10,6 +11,7 @@ crashdumps/*
*.phar
server.properties
/pocketmine.yml
/plugin_list.yml
memory_dumps/*
resource_packs/
server.lock

8
.gitmodules vendored
View File

@ -1,5 +1,5 @@
[submodule "src/pocketmine/lang/locale"]
path = src/pocketmine/lang/locale
[submodule "resources/locale"]
path = resources/locale
url = https://github.com/pmmp/PocketMine-Language.git
[submodule "tests/preprocessor"]
path = build/preprocessor
@ -7,6 +7,6 @@
[submodule "tests/plugins/PocketMine-DevTools"]
path = tests/plugins/PocketMine-DevTools
url = https://github.com/pmmp/PocketMine-DevTools.git
[submodule "src/pocketmine/resources/vanilla"]
path = src/pocketmine/resources/vanilla
[submodule "resources/vanilla"]
path = resources/vanilla
url = https://github.com/pmmp/BedrockData.git

View File

@ -1,3 +1,4 @@
dist: xenial
language: php
php:
@ -5,8 +6,26 @@ php:
- 7.3
before_script:
- LEVELDB_VERSION=f1463cb0b2486b0caf7d42ca3c7684545e875f04
- curl -fsSL "https://github.com/pmmp/leveldb-mcpe/archive/f1463cb0b2486b0caf7d42ca3c7684545e875f04.tar.gz" | tar -zx
- mv leveldb-mcpe-$LEVELDB_VERSION leveldb-mcpe
- cd leveldb-mcpe && make -j4 && mv out-shared/libleveldb.* . && cd ..
- git clone https://github.com/reeze/php-leveldb.git leveldb
- cd leveldb
- git checkout 9bcae79f71b81a5c3ea6f67e45ae9ae9fb2775a5
- phpize
- ./configure --with-leveldb=../leveldb-mcpe && make && make install
- cd ..
- git clone https://github.com/pmmp/ext-chunkutils2.git chunkutils
- cd chunkutils
- git checkout d8d762a597ac0da6f333f862096d6af0e6286b75
- phpize
- ./configure && make && make install
- cd ..
# - pecl install channel://pecl.php.net/pthreads-3.1.6
- echo | pecl install channel://pecl.php.net/yaml-2.0.4
- pecl install channel://pecl.php.net/crypto-0.3.1
- pecl install channel://pecl.php.net/ds-1.2.8
- git clone https://github.com/pmmp/pthreads.git
- cd pthreads
- git checkout 6ca019c58b4fa09ee2ff490f2444e34bef0773d0
@ -16,6 +35,8 @@ before_script:
- make install
- cd ..
- echo "extension=pthreads.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
- echo "extension=chunkutils2.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
- echo "extension=leveldb.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
- composer install
script:

765
changelogs/4.0-snapshot.md Normal file
View File

@ -0,0 +1,765 @@
# 4.0.0-SNAPSHOT-1907XX (2019-07-XX)
This major version features substantial changes throughout the core, including significant API changes, new world format support, performance improvements and a network revamp.
## Core
### General
- A new "plugin greylist" feature has been introduced, which allows whitelisting or blacklisting plugins from loading.
- The `/reload` command has been removed.
- The `/effect` command no longer supports numeric IDs - it's now required to use names.
- Remote console (RCON) has been removed. The [RconServer](https://github.com/pmmp/RconServer) plugin is provided as a substitute.
- Spawn protection has been removed. The [BasicSpawnProtection](https://github.com/pmmp/BasicSpawnProtection) plugin is provided as a substitute.
- CTRL+C signal handling has been removed. The [PcntlSignalHandler](https://github.com/pmmp/PcntlSignalHandler) plugin is provided as a substitute.
- Player movement anti-cheat has been removed. Its corresponding `pocketmine.yml` setting `player.anti-cheat.allow-movement-cheats` has been removed.
- The `pocketmine_chunkutils` PHP extension has been dropped.
- New PHP extensions are required by this version:
- [ds](https://github.com/php-ds/ext-ds)
- [chunkutils2](https://github.com/pmmp/ext-chunkutils2)
### World format support
- Modern Minecraft Bedrock world formats are now supported.
- Automatic conversion of deprecated world formats is now implemented.
- The following world formats have been deprecated and will be **automatically converted on load to a new format**:
- `mcregion`
- `anvil`
- `pmanvil`
- 256 build-height is now supported in all worlds (facilitated by automatic conversion).
- Extended blocks are now supported (facilitated by automatic conversion).
- Unsupported world formats no longer causes a crash, but a graceful shutdown instead.
- World corruption no longer causes a crash.
### Logger revamp
- Many components now have a dedicated logger which automatically adds [prefixes] to their messages.
- Main logger now includes milliseconds in timestamps.
### Network
This version features substantial changes to the network system, improving coherency, reliability and modularity.
#### Minecraft Bedrock packet encryption
- This fixes replay attacks where hackers steal and replay player logins.
- A new setting has been added to `pocketmine.yml`: `network.enable-encryption` which is `true` by default.
#### Packet receive error handling has been overhauled
- Only `BadPacketException` is now caught during packet decode and handling. This requires that all decoding MUST perform proper data error checking.
- Throwing a `BadPacketException` from decoding will now cause players to be kicked with the message `Packet processing error`.
- The disconnect message includes a random hex ID to help server owners identify the problems reported by their players.
- Throwing any other exception will now cause a server crash. `Internal server error` has been removed.
- It is now illegal to send a clientbound packet to the server. Doing so will result in the client being kicked with the message `Unexpected non-serverbound packet`.
#### New packet handler system
- Packet handlers have been separated from NetworkSession into a dedicated packet handler structure.
- A network session may have exactly 1 handler at a time, which is mutable and may be replaced at any time. This allows packet handling logic to be broken up into multiple stages:
- preventing undefined behaviour when sending wrong packets at the wrong time (they'll now be silently dropped)
- allowing the existence of ephemeral state-specific logic (for example stricter resource packs download checks)
- Packet handlers are now almost entirely absent from `Player` and instead appear in their own dedicated units.
- Almost all game logic that was previously locked up inside packet handlers in `Player` has been extracted into new API methods. See Player API changes for details.
## API
### General
- Most places which previously allowed `callable` now only allow `\Closure`. This is because closures have more consistent behaviour and are more performant.
- `void` and `?nullable` parameter and return types have been applied in many places.
- Everything in the `pocketmine\metadata` namespace and related implementations have been removed.
### Block
- Blocks with IDs >= 256 are now supported.
- Block state and variant metadata have been separated.
- Variant is considered an extension of ID and is immutable.
- `Block->setDamage()` has been removed. `Block->readStateFromData()` is now used for state deserialization.
- Tile entities are now created and deleted automatically when `World->setBlock()` is used with a block that requires a tile entity.
- Some tile entities' API has been exposed on their corresponding `Block` classes, with the tile entity classes being deprecated.
- The `pocketmine\tile` namespace has been relocated to `pocketmine\block\tile`.
- `Block->recalculateBoundingBox()` and `Block->recalculateCollisionBoxes()` are now expected to return AABBs relative to `0,0,0` instead of their own position.
- Block break-info has been extracted into a new dynamic `BlockBreakInfo` unit. The following methods have been moved:
- `Block->getBlastResistance()` -> `BlockBreakInfo->getBlastResistance()`
- `Block->getBreakTime()` -> `BlockBreakInfo->getBreakTime()`
- `Block->getHardness()` -> `BlockBreakInfo->getHardness()`
- `Block->getToolHarvestLevel()` -> `BlockBreakInfo->getToolHarvestLevel()`
- `Block->getToolType()` -> `BlockBreakInfo->getToolType()`
- `Block->isBreakable()` -> `BlockBreakInfo->isBreakable()`
- `Block->isCompatibleWithTool()` -> `BlockBreakInfo->isToolCompatible()`
- The following API methods have been added:
- `Block->asItem()`: returns an itemstack corresponding to the block
- `Block->isSameState()`: returns whether the block is the same as the parameter, including state information
- `Block->isSameType()`: returns whether the block is the same as the parameter, without state information
- The following hooks have been added:
- `Block->onAttack()`: called when a player in survival left-clicks the block to try to start breaking it
- `Block->onPostPlace()`: called directly after placement in the world, handles things like rail connections and chest pairing
- The following API methods have been renamed:
- `Block->getDamage()` -> `Block->getMeta()`
- `Block->onActivate()` -> `Block->onInteract()`
- `Block->onEntityCollide()` -> `Block->onEntityInside()`
- The following API methods have changed signatures:
- `Block->onInteract()` now has the signature `onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool`
- The following API methods have been removed:
- `Block->canPassThrough()`
- `Block->setDamage()`
- `Block::get()`: this was superseded by `BlockFactory::get()` a long time ago
- The following classes have been renamed:
- `BlockIds` -> `BlockLegacyIds`
- `CobblestoneWall` -> `Wall`
- `NoteBlock` -> `Note`
- `SignPost` -> `Sign`
- `StandingBanner` -> `Banner`
- The following classes have been removed:
- `Bricks`
- `BurningFurnace`
- `CobblestoneStairs`
- `Dandelion`
- `DoubleSlab`
- `DoubleStoneSlab`
- `EndStone`
- `GlowingRedstoneOre`
- `GoldOre`
- `Gold`
- `IronDoor`
- `IronOre`
- `IronTrapdoor`
- `Iron`
- `Lapis`
- `NetherBrickFence`
- `NetherBrickStairs`
- `Obsidian`
- `PurpurStairs`
- `Purpur`
- `QuartzStairs`
- `Quartz`
- `RedSandstoneStairs`
- `RedSandstone`
- `SandstoneStairs`
- `Sandstone`
- `StainedClay`
- `StainedGlassPane`
- `StainedGlass`
- `StoneBrickStairs`
- `StoneBricks`
- `StoneSlab2`
- `StoneSlab`
- `Stone`
- `WallBanner`
- `WallSign`
- `Wood2`
- `BlockToolType` constants have been renamed to remove the `TYPE_` prefix.
### Command
- The following classes have been removed:
- `RemoteConsoleCommandSender`
- The following API methods have signature changes:
- `Command->setPermission()` argument is now mandatory (but still nullable).
- `CommandSender->setScreenLineHeight()` argument is now mandatory (but still nullable).
### Entity
#### General
- The following API methods have been added:
- `ItemEntity->getDespawnDelay()`
- `ItemEntity->setDespawnDelay()`
- `Human->getHungerManager()`
- `Human->getXpManager()`
- The following methods have signature changes:
- `Entity->entityBaseTick()` is now `protected`.
- `Entity->move()` is now `protected`.
- `Living->knockBack()` now accepts `float, float, float` (the first two parameters have been removed).
- `Living->getEffects()` now returns `EffectManager` instead of `Effect[]`.
- The following classes have been added:
- `effect\EffectManager`: contains effect-management functionality extracted from `Living`
- `HungerManager`: contains hunger-management functionality extracted from `Human`
- `ExperienceManager`: contains XP-management functionality extracted from `Human`
- The following API methods have been moved / renamed:
- `Living->removeAllEffects()` -> `EffectManager->clear()`
- `Living->removeEffect()` -> `EffectManager->remove()`
- `Living->addEffect()` -> `EffectManager->add()`
- `Living->getEffect()` -> `EffectManager->get()`
- `Living->hasEffect()` -> `EffectManager->has()`
- `Living->hasEffects()` -> `EffectManager->hasEffects()`
- `Living->getEffects()` -> `EffectManager->all()`
- `Human->getFood()` -> `HungerManager->getFood()`
- `Human->setFood()` -> `HungerManager->setFood()`
- `Human->getMaxFood()` -> `HungerManager->getMaxFood()`
- `Human->addFood()` -> `HungerManager->addFood()`
- `Human->isHungry()` -> `HungerManager->isHungry()`
- `Human->getSaturation()` -> `HungerManager->getSaturation()`
- `Human->setSaturation()` -> `HungerManager->setSaturation()`
- `Human->addSaturation()` -> `HungerManager->addSaturation()`
- `Human->getExhaustion()` -> `HungerManager->getExhaustion()`
- `Human->setExhaustion()` -> `HungerManager->setExhaustion()`
- `Human->exhaust()` -> `HungerManager->exhaust()`
- `Human->getXpLevel()` -> `ExperienceManager->getXpLevel()`
- `Human->setXpLevel()` -> `ExperienceManager->setXpLevel()`
- `Human->addXpLevels()` -> `ExperienceManager->addXpLevels()`
- `Human->subtractXpLevels()` -> `ExperienceManager->subtractXpLevels()`
- `Human->getXpProgress()` -> `ExperienceManager->getXpProgress()`
- `Human->setXpProgress()` -> `ExperienceManager->setXpProgress()`
- `Human->getRemainderXp()` -> `ExperienceManager->getRemainderXp()`
- `Human->getCurrentTotalXp()` -> `ExperienceManager->getCurrentTotalXp()`
- `Human->setCurrentTotalXp()` -> `ExperienceManager->setCurrentTotalXp()`
- `Human->addXp()` -> `ExperienceManager->addXp()`
- `Human->subtractXp()` -> `ExperienceManager->subtractXp()`
- `Human->getLifetimeTotalXp()` -> `ExperienceManager->getLifetimeTotalXp()`
- `Human->setLifetimeTotalXp()` -> `ExperienceManager->setLifetimeTotalXp()`
- `Human->canPickupXp()` -> `ExperienceManager->canPickupXp()`
- `Human->onPickupXp()` -> `ExperienceManager->onPickupXp()`
- `Human->resetXpCooldown()` -> `ExperienceManager->resetXpCooldown()`
- The following API methods have been removed:
- `Human->getRawUniqueId()`: use `Human->getUniqueId()->toBinary()` instead
- The following classes have been removed:
- `Creature`
- `Damageable`
- `Monster`
- `NPC`
- `Rideable`
- `Vehicle`
- `Skin` now throws exceptions on creation if given invalid data.
#### Effect
- All `Effect` related classes have been moved to the `pocketmine\entity\effect` namespace.
- Effect functionality embedded in the `Effect` class has been separated out into several classes. The following classes have been added:
- `AbsorptionEffect`
- `HealthBoostEffect`
- `HungerEffect`
- `InstantDamageEffect`
- `InstantEffect`
- `InstantHealthEffect`
- `InvisibilityEffect`
- `LevitationEffect`
- `PoisonEffect`
- `RegenerationEffect`
- `SaturationEffect`
- `SlownessEffect`
- `SpeedEffect`
- `WitherEffect`
- Negative effect amplifiers are now explicitly disallowed due to undefined behaviour they created.
- The following API methods have been renamed:
- `Effect::registerEffect()` -> `Effect::register()`
- `Effect::getEffect()` -> `Effect::get()`
- `Effect::getEffectByName()` -> `Effect::fromString()`
- Static getter methods for all registered enchantment types have been added. `Effect::getEffect(Effect::WHATEVER)` should be replaced by `VanillaEffects::WHATEVER()`.
- All effect registry functionality has been removed from the `Effect` base class and migrated to the `VanillaEffects` class.
#### Removal of runtime entity NBT
- Entities no longer keep their NBT alive at runtime.
- `Entity->namedtag` has been removed.
- `Entity->saveNBT()` now returns a newly created `CompoundTag` instead of modifying the previous one in-place.
- `Entity->initEntity()` now accepts a `CompoundTag` parameter.
#### Entity creation
- Entity class overriding is now explicitly supported, without needing to touch save IDs.
- Entity classes can be overridden using `EntityFactory::override()`. The provided replacement class **must** be a subclass of the existing class. If the existing class isn't there, an exception will be thrown.
- Attempting to register an entity to a save ID that is already registered will now cause an exception to be thrown.
- Registering entities will now throw exceptions on error cases instead of returning `false`.
- Entity creation has now been split into two paths:
- `EntityFactory::create()`: Creates an entity by the given class. This accepts arguments to be passed to the entity constructor. This function is guaranteed to return an entity which is an instanceof the given class.
- `EntityFactory::createFromData()`: Creates an entity from save data. This may return any `Entity` class or `NULL`. This function is internal and shouldn't be used by plugins.
- It is no longer possible to directly create an entity by save ID. This is discouraged because save IDs are internal and format-dependent.
- The following API methods have been moved:
- `Entity::registerEntity()` -> `EntityFactory::register()`
- `Entity::createEntity()` -> `EntityFactory::create()`
- `Entity::getKnownEntityTypes()` -> `EntityFactory::getKnownTypes()`
- `Entity::createBaseNBT()` -> `EntityFactory::createBaseNBT()`
- The following API methods have been removed:
- `Entity->getSaveId()`
#### WIP removal of entity network metadata
- All network metadata related constants have been removed from the `Entity` class and moved to the protocol layer. It is intended to remove network metadata from the API entirely, but this has not yet been completed.
- `Entity::DATA_FLAG_*` constants have been moved to `pocketmine\network\mcpe\protocol\types\EntityMetadataFlags`.
- `Entity::DATA_TYPE_*` constants have been moved to `pocketmine\network\mcpe\protocol\types\EntityMetadataTypes`.
- `Entity::DATA_*` constants have been moved to `pocketmine\network\mcpe\protocol\types\EntityMetadataProperties`.
- `DataPropertyManager` has been moved to the `pocketmine\network\mcpe\protocol\types` namespace, and as such isn't considered part of the API anymore.
### Event
#### Internal event system no longer depends on `Listener`s
- The internal event processing system no longer depends on `Listener` objects. Arbitrary closures can now be used, provided that they satisfy the standard requirements to be a handler.
- This change improves performance of event handler calling by approximately 15%. This does not include anything plugins are doing.
- The following classes have been removed:
- `pocketmine\plugin\EventExecutor`
- `pocketmine\plugin\MethodEventExecutor`
- `RegisteredListener->__construct()` now requires `Closure` instead of `Listener, EventExecutor` as the leading parameters.
- `RegisteredListener->getListener()` has been removed.
#### Default cancelled handling behaviour has changed
- Handler functions will now **not receive cancelled events by default**. This is a **silent BC break**, i.e. it won't raise errors, but it might cause bugs.
- `@ignoreCancelled` is now no longer respected.
- `@handleCancelled` has been added. This allows opting _into_ receiving cancelled events (it's the opposite of `@ignoreCancelled`).
#### `PlayerPreLoginEvent` changes
- The `Player` object no longer exists at this phase of the login. Instead, a `PlayerInfo` object is provided, along with connection information.
- Ban, server-full and whitelist checks are now centralized to `PlayerPreLoginEvent`. It's no longer necessary (or possible) to intercept `PlayerKickEvent` to handle these types of disconnects.
- Multiple kick reasons may be set to ensure that the player is still removed if there are other reasons for them to be disconnected and one of them is cleared. For example, if a player is banned and the server is full, clearing the ban flag will still cause the player to be disconnected because the server is full.
- Plugins may set custom kick reasons. Any custom reason has absolute priority.
- If multiple flags are set, the kick message corresponding to the highest priority reason will be shown. The priority (as of this snapshot) is as follows:
- Custom (highest priority)
- Server full
- Whitelisted
- Banned
- The `PlayerPreLoginEvent::KICK_REASON_PRIORITY` constant contains a list of kick reason priorities, highest first.
- The following constants have been added:
- `PlayerPreLoginEvent::KICK_REASON_PLUGIN`
- `PlayerPreLoginEvent::KICK_REASON_SERVER_FULL`
- `PlayerPreLoginEvent::KICK_REASON_SERVER_WHITELISTED`
- `PlayerPreLoginEvent::KICK_REASON_BANNED`
- `PlayerPreLoginEvent::KICK_REASON_PRIORITY`: ordered list of kick reason priorities, highest first
- The following API methods have been added:
- `PlayerPreLoginEvent->clearAllKickReasons()`
- `PlayerPreLoginEvent->clearKickReason()`
- `PlayerPreLoginEvent->getFinalKickMessage()`: the message to be shown to the player with the current reason list in place
- `PlayerPreLoginEvent->getIp()`
- `PlayerPreLoginEvent->getKickReasons()`: returns an array of flags indicating kick reasons, must be empty to allow joining
- `PlayerPreLoginEvent->getPlayerInfo()`
- `PlayerPreLoginEvent->getPort()`
- `PlayerPreLoginEvent->isAllowed()`
- `PlayerPreLoginEvent->isAuthRequired()`: whether XBL authentication will be enforced
- `PlayerPreLoginEvent->isKickReasonSet()`
- `PlayerPreLoginEvent->setAuthRequired()`
- `PlayerPreLoginEvent->setKickReason()`
- The following API methods have been changed:
- `PlayerPreLoginEvent->getKickMessage()` now has the signature `getKickMessage(int $flag) : ?string`
- The following API methods have been removed:
- `PlayerPreLoginEvent->setKickMessage()`
- `PlayerPreLoginEvent->getPlayer()`
#### Other changes
- Disconnecting players during events no longer crashes the server (although it might cause other side effects).
- `PlayerKickEvent` is no longer fired for disconnects that occur before the player completes the initial login sequence (i.e. completing downloading resource packs).
- Cancellable events must now implement `CancellableTrait` to get the cancellable components needed to satisfy interface requirements.
- `PlayerInteractEvent` is no longer fired when a player activates an item. This fixes the age-old complaint of `PlayerInteractEvent` firing multiple times when interacting once. The following constants have been removed:
- `PlayerInteractEvent::LEFT_CLICK_AIR`
- `PlayerInteractEvent::RIGHT_CLICK_AIR`
- `PlayerInteractEvent::PHYSICAL`
- The following events have been added:
- `PlayerItemUseEvent`: player activating their held item, for example to throw it.
- `BlockTeleportEvent`: block teleporting, for example dragon egg when attacked.
- The following events have been removed:
- `EntityArmorChangeEvent`
- `EntityInventoryChangeEvent`
- `EntityLevelChangeEvent` - `EntityTeleportEvent` with world checks should be used instead.
- `NetworkInterfaceCrashEvent`
- `PlayerCheatEvent`
- `PlayerIllegalMoveEvent`
- The following API methods have been added:
- `EntityDeathEvent->getXpDropAmount()`
- `EntityDeathEvent->setXpDropAmount()`
- `PlayerDeathEvent->getXpDropAmount()`
- `PlayerDeathEvent->setXpDropAmount()`
- The following API methods have been removed:
- `PlayerPreLoginEvent->getPlayer()`
- The following API methods have been moved:
- `Event->isCancelled()` -> `CancellableTrait->isCancelled()`: this was a stub which threw `BadMethodCallException` if the class didn't implement `Cancellable`; now this is simply not available on non-cancellable events
- `Event->setCancelled()` -> `CancellableTrait->setCancelled()`
- `HandlerList::unregisterAll()` -> `HandlerListManager->unregisterAll()`
- `HandlerList::getHandlerListFor()` -> `HandlerListManager->getListFor()`
- `HandlerList::getHandlerLists()` -> `HandlerListManager->getAll()`
- The following classes have been moved:
- `pocketmine\plugin\RegisteredListener` -> `pocketmine\event\RegisteredListener`
### Inventory
- All crafting and recipe related classes have been moved to the `pocketmine\crafting` namespace.
- The following classes have been added:
- `CallbackInventoryChangeListener`
- `CreativeInventory`: contains the creative functionality previously embedded in `pocketmine\item\Item`, see Item changes for details
- `InventoryChangeListener`: allows listening (but not interfering with) events in an inventory.
- `transaction\CreateItemAction`
- `transaction\DestroyItemAction`
- The following classes have been renamed:
- `ContainerInventory` -> `BlockInventory`
- The following classes have been removed:
- `CustomInventory`
- `InventoryEventProcessor`
- `Recipe`
- `transaction\CreativeInventoryAction`
- The following API methods have been added:
- `Inventory->addChangeListeners()`
- `Inventory->getChangeListeners()`
- `Inventory->removeChangeListeners()`
- `Inventory->swap()`: swaps the contents of two slots
- The following API methods have been removed:
- `BaseInventory->getDefaultSize()`
- `BaseInventory->setSize()`
- `Inventory->close()`
- `Inventory->dropContents()`
- `Inventory->getName()`
- `Inventory->getTitle()`
- `Inventory->onSlotChange()`
- `Inventory->open()`
- `Inventory->sendContents()`
- `Inventory->sendSlot()`
- `InventoryAction->onExecuteFail()`
- `InventoryAction->onExecuteSuccess()`
- `PlayerInventory->sendCreativeContents()`
- The following API methods have signature changes:
- `Inventory->clear()` now returns `void` instead of `bool`.
- `Inventory->setItem()` now returns `void` instead of `bool`.
- `InventoryAction->execute()` now returns `void` instead of `bool`.
- `BaseInventory->construct()` no longer accepts a list of items to initialize with.
- `PlayerInventory->setItemInHand()` now sends the update to viewers of the player.
### Item
#### General
- `Item->count` is no longer public.
- The hierarchy of writable books has been changed: `WritableBook` and `WrittenBook` now extend `WritableBookBase`.
- The following API methods have signature changes:
- `WritableBookBase->setPages()` now accepts `WritableBookPage[]` instead of `CompoundTag[]`.
- `ItemFactory::get()` no longer accepts `string` for the `tags` parameter.
- `ItemFactory::fromString()` no longer accepts a `$multiple` parameter and now only returns `Item`, not `Item|Item[]`.
- The following methods are now fluent:
- `WritableBookBase->setPages()`
- `Item->addEnchantment()`
- `Item->removeEnchantment()`
- `Item->removeEnchantments()`
- `Armor->setCustomColor()`
- `WrittenBook->setTitle()`
- `WrittenBook->setAuthor()`
- `WrittenBook->setGeneration()`
- The following API methods have been removed:
- `Item->getNamedTagEntry()`
- `Item->removeNamedTagEntry()`
- `Item->setDamage()`: "Damage" is now immutable for all items except `Durable` descendents.
- `Item->setNamedTagEntry()`
- `Item::get()`: this was superseded by `ItemFactory::get()` a long time ago
- `Item::fromString()`: this was superseded by `ItemFactory::fromString()` a long time ago
- `Item->setCompoundTag()`
- `Item->getCompoundTag()`
- `Item->hasCompoundTag()`
- `ProjectileItem->getProjectileEntityType()`
- The following methods have been renamed:
- `Item->getDamage()` -> `Item->getMeta()`
- The following methods have been moved to `pocketmine\inventory\CreativeInventory`:
- `Item::addCreativeItem()` -> `CreativeInventory::add()`
- `Item::clearCreativeItems()` -> `CreativeInventory::clear()`
- `Item::getCreativeItemIndex()` -> `CreativeInventory::getItemIndex()`
- `Item::getCreativeItems()` -> `CreativeInventory::getAll()`
- `Item::initCreativeItems()` -> `CreativeInventory::init()`
- `Item::isCreativeItem()` -> `CreativeInventory::contains()`
- `Item::removeCreativeItem()` -> `CreativeInventory::remove()`
- The following classes have been added:
- `ArmorTypeInfo`
- `Boots`
- `Chestplate`
- `Fertilizer`
- `Helmet`
- `Leggings`
- `LiquidBucket`
- `MilkBucket`
- `WritableBookBase`
- `WritableBookPage`
- The following API methods have been added:
- `Armor->getArmorSlot()`
- `ProjectileItem->getProjectileEntityClass()`: returns the class of projectile to be created when thrown
- The following classes have been removed:
- `ChainBoots`
- `ChainChestplate`
- `ChainHelmet`
- `ChainLeggings`
- `DiamondBoots`
- `DiamondChestplate`
- `DiamondHelmet`
- `DiamondLeggings`
- `GoldBoots`
- `GoldChestplate`
- `GoldHelmet`
- `GoldLeggings`
- `IronBoots`
- `IronChesplate`
- `IronHelmet`
- `IronLeggings`
- `LeatherBoots`
- `LeatherCap`
- `LeatherPants`
- `LeatherTunic`
#### NBT handling
- Serialized NBT byte array caches are no longer stored on itemstacks. These caches were a premature optimization used for network layer serialization and as such were dependent on the network NBT format.
- Internal NBT usage has been marginalized. It's no longer necessary to immediately write changes to NBT. The following hooks have been added:
- `Item->serializeCompoundTag()`
- `Item->deserializeCompoundTag()`
- It's planned to remove runtime NBT from items completely, but this currently presents unresolved backwards-compatibility problems.
#### Enchantment
- The following API methods have been renamed:
- `Enchantment::registerEnchantment()` -> `Enchantment::register()`
- `Enchantment::getEnchantment()` -> `Enchantment::get()`
- `Enchantment::getEnchantmentByName()` -> `Enchantment::fromString()`
- Static getter methods for all registered enchantment types have been added. `Enchantment::getEnchantment(Enchantment::WHATEVER)` should be replaced by `Enchantment::WHATEVER()`.
### Lang
- The following classes have been renamed:
- `BaseLang` -> `Language`
- `LanguageNotFoundException` has been added. This is thrown when trying to construct a `Language` which doesn't exist in the server files.
### Network
- The following fields have been removed:
- `Network::$BATCH_THRESHOLD`
- The following classes have been renamed:
- `SourceInterface` -> `NetworkInterface`
- `AdvancedSourceInterface` -> `AdvancedNetworkInterface`
- The following classes have been moved:
- `CompressBatchedTask` -> `mcpe\CompressBatchTask`
- `level\format\io\ChunkRequestTask` -> `mcpe\ChunkRequestTask`
- `mcpe\RakLibInterface` -> `mcpe\raklib\RakLibInterface`
- The following classes have been removed:
- `mcpe\PlayerNetworkSessionAdapter`
- The following methods have been removed:
- `NetworkInterface->putPacket()`
- `NetworkInterface->close()`
- `NetworkInterface->emergencyShutdown()`
- `NetworkInterface` now represents a more generic interface to be implemented by any network component, as opposed to specifically a player network interface.
- Everything under the `rcon` subnamespace has been removed.
- `upnp\UPnP` has significant changes. It's now a network component instead of a pair of static methods.
### Permission
- Added `PermissibleDelegateTrait` to reduce boilerplate for users of `PermissibleBase`. This trait is used by `ConsoleCommandSender` and `Player`.
- The following API methods have been moved:
- `Permission::getByName()` -> `PermissionParser::defaultFromString()`
- `Permission::loadPermissions()` -> `PermissionParser::loadPermissions()`
- `Permission::loadPermission()` -> `PermissionParser::loadPermission()`
- The following API methods have been added:
- `PermissionParser::emitPermissions()`
- The following API methods have changes:
- `PermissionParser::defaultFromString()` now throws `InvalidArgumentException` on unknown values.
### Player
- The following classes have moved to the new `pocketmine\player` namespace:
- `Achievement`
- `GameMode`
- `IPlayer`
- `OfflinePlayer`
- `PlayerInfo`
- `Player`
- The following constants have been removed:
- `Player::SURVIVAL` - use `GameMode::SURVIVAL()`
- `Player::CREATIVE` - use `GameMode::CREATIVE()`
- `Player::ADVENTURE` - use `GameMode::ADVENTURE()`
- `Player::SPECTATOR` - use `GameMode::SPECTATOR()`
- `Player::VIEW` - use `GameMode::SPECTATOR()`
- (almost) all packet handlers have been removed from `Player`. They are now encapsulated within the network layer.
- The following API methods have been added:
- `Player->attackBlock()`: attack (left click) the target block, e.g. to start destroying it (survival)
- `Player->attackEntity()`: melee-attack (left click) the target entity (if within range)
- `Player->breakBlock()`: destroy the target block in the current world (immediately)
- `Player->consumeHeldItem()`: consume the previously activated item, e.g. eating food
- `Player->continueBreakBlock()`: punch the target block during destruction in survival, advancing break animation and creating particles
- `Player->hasFiniteResources()`
- `Player->interactBlock()`: interact (right click) the target block in the current world
- `Player->interactEntity()`: interact (right click) the target entity, e.g. to apply a nametag (not implemented yet)
- `Player->pickBlock()`: picks (mousewheel click) the target block in the current world
- `Player->releaseHeldItem()`: release the previously activated item, e.g. shooting a bow
- `Player->selectHotbarSlot()`: select the specified hotbar slot
- `Player->stopBreakBlock()`: cease attacking a previously attacked block
- `Player->toggleFlight()`: tries to start / stop flying (fires events, may be cancelled)
- `Player->updateNextPosition()`: sets the player's next attempted move location (fires events, may be cancelled)
- `Player->useHeldItem()`: activate the held item, e.g. throwing a snowball
- The following API methods have been removed:
- `Player->addActionBarMessage()`: replaced by `sendActionBarMessage()`
- `Player->addSubTitle()`: replaced by `sendSubTitle()`
- `Player->addTitle()`: replaced by `sendTitle()`
- `Player->getAddress()`: replaced by `NetworkSession->getIp()`
- `Player->getPing()`: moved to `NetworkSession`
- `Player->getPort()`: moved to `NetworkSession`
- `Player->updatePing()`: moved to `NetworkSession`
### Plugin
- API version checks are now more strict. It is no longer legal to declare multiple minimum versions on the same major version. Doing so will now cause the plugin to fail to load with the message `Multiple minimum API versions found for some major versions`.
- `plugin.yml` YAML commands loading is now internalized inside `PluginBase`.
- `PluginManager->registerEvent()` now has a simpler signature: `registerEvent(string $event, \Closure $handler, int $priority, Plugin $plugin, bool $handleCancelled = false)`. The provided closure must accept the specified event class as its only parameter. See [Event API changes](#event) for more details.
- The following classes have been removed:
- `PluginLogger`
- The following interface requirements have been removed:
- `Plugin->onEnable()`: this is now internalized inside `PluginBase`
- `Plugin->onDisable()`: same as above
- `Plugin->onLoad()`: same as above
- `Plugin` no longer extends `CommandExecutor`. This means that `Plugin` implementations don't need to implement `onCommand()` anymore.
- The following hook methods have changed visibility:
- `PluginBase->onEnable()` changed from `public` to `protected`
- `PluginBase->onDisable()` changed from `public` to `protected`
- `PluginBase->onLoad()` changed from `public` to `protected`
- The following hook methods have been renamed:
- `Plugin->setEnabled()` -> `Plugin->onEnableStateChange()`. This change was made to force plugin developers misusing this hook to stop, and to give it a name that better describes what it does.
- The following (deprecated) API methods have been removed:
- `PluginManager->callEvent()`: use `Event->call()` instead
- `PluginManager->addPermission()`: use `PermissionManager` instead
- `PluginManager->getDefaultPermSubscriptions()`: use `PermissionManager` instead
- `PluginManager->getDefaultPermissions()`: use `PermissionManager` instead
- `PluginManager->getPermission()`: use `PermissionManager` instead
- `PluginManager->getPermissionSubscriptions()`: use `PermissionManager` instead
- `PluginManager->getPermissions()`: use `PermissionManager` instead
- `PluginManager->recalculatePermissionDefaults()`: use `PermissionManager` instead
- `PluginManager->removePermission()`: use `PermissionManager` instead
- `PluginManager->subscribeToDefaultPerms()`: use `PermissionManager` instead
- `PluginManager->subscribeToPermission()`: use `PermissionManager` instead
- `PluginManager->unsubscribeFromDefaultPerms()`: use `PermissionManager` instead
- `PluginManager->unsubscribeFromPermission()`: use `PermissionManager` instead
- It is no longer permitted to throw exceptions from `PluginBase->onEnable()` or `PluginBase->onLoad()`. Doing so will now cause the server to crash.
### Scheduler
#### Thread-local storage for AsyncTasks
- TLS has been completely rewritten in this release to be self contained, more robust and easier to use.
- Now behaves more like simple properties. `storeLocal()` writes, `fetchLocal()` reads.
- Self-contained and doesn't depend on the async pool to clean up after it.
- Values are automatically removed from storage when the `AsyncTask` is garbage-collected, just like a regular property.
- Supports storing multiple values, differentiated by string names.
- `fetchLocal()` can now be used multiple times. It no longer deletes the stored value.
- The following classes have been removed:
- `FileWriteTask`
- The following methods have been removed:
- `AsyncTask->peekLocal()`: use `fetchLocal()` instead
- The following methods have signature changes:
- `AsyncTask->storeLocal()` now has the signature `storeLocal(string $key, mixed $complexData) : void`
- `AsyncTask->fetchLocal()` now has the signature `fetchLocal(string $key) : mixed`
#### Other changes
- `AsyncPool` uses a new, significantly more performant algorithm for task collection.
- `BulkCurlTask` has had the `$complexData` constructor parameter removed.
- `pocketmine\Collectable` has been removed, and is no longer extended by `AsyncTask`.
- The following hooks have been added:
- `AsyncTask->onError()`: called on the main thread when an uncontrolled error was detected in the async task, such as a memory failure
- The following hooks have signature changes:
- `AsyncTask->onCompletion()` no longer accepts a `Server` parameter, and has a `void` return type.
- `AsyncTask->onProgressUpdate()` no longer accepts a `Server` parameter, and has a `void` return type.
- The following API methods have been removed:
- `AsyncTask->getFromThreadStore()`: use `AsyncTask->worker->getFromThreadStore()`
- `AsyncTask->removeFromThreadStore()`: use `AsyncTask->worker->removeFromThreadStore()`
- `AsyncTask->saveToThreadStore()`: use `AsyncTask->worker->saveToThreadStore()`
### Server
- The following API methods have been removed:
- `reloadWhitelist()`
- `getLevelMetadata()`
- `getPlayerMetadata()`
- `getEntityMetadata()`
- `getDefaultGamemode()`
- `getLoggedInPlayers()`
- `onPlayerLogout()`
- `addPlayer()`
- `removePlayer()`
- `reload()`
- `getSpawnRadius()`
- `enablePlugin()`
- `disablePlugin()`
- `getGamemodeString()` - replaced by `pocketmine\player\GameMode->getTranslationKey()`
- `getGamemodeName()` - replaced by `pocketmine\player\GameMode->name()`
- `getGamemodeFromString()` - replaced by `GameMode::fromString()`
- The following API methods have changed:
- `getOfflinePlayerData()` no longer creates data when it doesn't exist.
### Level / World
#### General
- All references to `Level` in the context of "world" have been changed to `World`.
- The `pocketmine\level` namespace has been renamed to `pocketmine\world`
- All classes containing the world `Level` in the name in the "world" context have been changed to `World`.
- `Position->getLevel()` has been renamed to `Position->getWorld()`, and `Position->level` has been renamed to `Position->world`.
- Extracted a `WorldManager` unit from `Server`
- `Server->findEntity()` -> `WorldManager->findEntity()`
- `Server->generateLevel()` -> `WorldManager->generateWorld()`
- `Server->getAutoSave()` -> `WorldManager->getAutoSave()`
- `Server->getDefaultLevel()` -> `WorldManager->getDefaultWorld()`
- `Server->getLevel()` -> `WorldManager->getWorld()`
- `Server->getLevelByName()` -> `WorldManager->getWorldByName()`
- `Server->getLevels()` -> `WorldManager->getWorlds()`
- `Server->isLevelGenerated()` -> `WorldManager->isWorldGenerated()`
- `Server->isLevelLoaded()` -> `WorldManager->isWorldLoaded()`
- `Server->loadLevel()` -> `WorldManager->loadWorld()`
- `Server->setAutoSave()` -> `WorldManager->setAutoSave()`
- `Server->setDefaultLevel()` -> `WorldManager->setDefaultWorld()`
- `Server->unloadLevel()` -> `WorldManager->unloadWorld()`
- Added `WorldManager->getAutoSaveTicks()` and `WorldManager->setAutoSaveTicks()` to allow controlling the autosave interval.
- The following classes have been added:
- `BlockTransaction`: allows creating batch commits of block changes with validation conditions - if any block can't be applied, the whole transaction fails to apply.
- `ChunkListenerNoOpTrait`: contains default no-op stubs for chunk listener implementations
- `ChunkListener`: interface allowing subscribing to events happening on a given chunk
- The following API methods have been added:
- `World->registerChunkListener()`
- `World->unregisterChunkListener()`
- The following API methods have been removed:
- `ChunkLoader->getLoaderId()` (now object ID is used)
- The following API methods have changed signatures:
- `World->addParticle()` now has the signature `addParticle(Vector3 $pos, Particle $particle, ?Player[] $players = null) : void`
- `World->addSound()` now has the signature `addSound(?Vector3 $pos, Sound $sound, ?Player[] $players = null) : void`
- `World->getRandomTickedBlocks()` now returns `bool[]` instead of `SplFixedArray`.
- `World->addRandomTickedBlock()` now accepts `Block` instead of `int, int`.
- `World->removeRandomTickedBlock()` now accepts `Block` instead of `int, int`.
- `World->setBlock()` has had the `$direct` parameter removed.
- The following API methods have been renamed / moved:
- `Level->getCollisionCubes()` -> `World->getCollisionBoxes()`
- Extracted a unit `pocketmine\world\format\io\FastChunkSerializer` from `Chunk`:
- `Chunk->fastDeserialize()` -> `FastChunkSerializer::deserialize()`
- `Chunk->fastSerialize()` -> `FastChunkSerializer::serialize()`
- A `ChunkListener` interface has been extracted from `ChunkLoader`. The following methods have been moved:
- `ChunkLoader->onBlockChanged()` -> `ChunkListener->onBlockChanged()`
- `ChunkLoader->onChunkChanged()` -> `ChunkListener->onChunkChanged()`
- `ChunkLoader->onChunkLoaded()` -> `ChunkListener->onChunkLoaded()`
- `ChunkLoader->onChunkPopulated()` -> `ChunkListener->onChunkPopulated()`
- `ChunkLoader->onChunkUnloaded()` -> `ChunkListener->onChunkUnloaded()`
#### Particles
- `pocketmine\world\particle\Particle` no longer extends `pocketmine\math\Vector3`, and has been converted to an interface.
- Added the following `Particle` classes:
- `DragonEggTeleportParticle`
- `PunchBlockParticle`
#### Sounds
- `pocketmine\world\sound\Sound` no longer extends `pocketmine\math\Vector3`, and has been converted to an interface.
- `Sound->encode()` now accepts `?\pocketmine\math\Vector3`. `NULL` may be passed for sounds which are global.
- Added the following classes:
- `ArrowHitSound`
- `BlockBreakSound`
- `BlockPlaceSound`
- `BowShootSound`
- `BucketEmptyLavaSound`
- `BucketEmptyWaterSound`
- `BucketFillLavaSound`
- `BucketFillWaterSound`
- `ChestCloseSound`
- `ChestOpenSound`
- `EnderChestCloseSound`
- `EnderChestOpenSound`
- `ExplodeSound`
- `FlintSteelSound`
- `ItemBreakSound`
- `NoteInstrument`
- `NoteSound`
- `PaintingPlaceSound`
- `PotionSplashSound`
- `RedstonePowerOffSound`
- `RedstonePowerOnSound`
- `ThrowSound`
- `XpCollectSound`
- `XpLevelUpSound`
### Utils
- `Terminal::hasFormattingCodes()` no longer auto-detects the availability of formatting codes. Instead it's necessary to use `Terminal::init()` with no parameters to initialize, or `true` or `false` to override.
- `Config->save()` no longer catches exceptions thrown during emitting to disk.
- The following new classes have been added:
- `InternetException`
- `Internet`
- `Process`
- The following API methods have been added:
- `Color::fromRGBA()`
- `Config->getPath()`: returns the path to the config on disk
- `Terminal::write()`: emits a Minecraft-formatted text line without newline
- `Terminal::writeLine()`: emits a Minecraft-formatted text line with newline
- `Utils::recursiveUnlink()`: recursively deletes a directory and its contents
- The following deprecated API redirects have been removed:
- `Utils::execute()`: moved to `Process`
- `Utils::getIP()`: moved to `Internet`
- `Utils::getMemoryUsage()`: moved to `Process`
- `Utils::getRealMemoryUsage()`: moved to `Process`
- `Utils::getThreadCount()`: moved to `Process`
- `Utils::getURL()`: moved to `Internet`
- `Utils::kill()`: moved to `Process`
- `Utils::postURL()`: moved to `Internet`
- `Utils::simpleCurl()`: moved to `Internet`
- The following API fields have been removed / hidden:
- `Utils::$ip`
- `Utils::$online`
- `Utils::$os`
- The following API methods have signature changes:
- `Internet::simpleCurl()` now requires a `Closure` for its `onSuccess` parameter instead of `callable`.
- The following API methods have been removed:
- `Color->setA()`
- `Color->setR()`
- `Color->setG()`
- `Color->setB()`
- `Color->toABGR()`
- `Color->toBGRA()`
- `Color::fromABGR()`
- `Utils::getCallableIdentifier()`

View File

@ -8,11 +8,16 @@
"php": ">=7.2.0",
"php-64bit": "*",
"ext-bcmath": "*",
"ext-chunkutils2": "^0.1.0",
"ext-curl": "*",
"ext-crypto": "^0.3.1",
"ext-ctype": "*",
"ext-date": "*",
"ext-ds": "^1.2.7",
"ext-gmp": "*",
"ext-hash": "*",
"ext-json": "*",
"ext-leveldb": "^0.2.1",
"ext-mbstring": "*",
"ext-openssl": "*",
"ext-pcre": "*",
@ -24,14 +29,16 @@
"ext-yaml": ">=2.0.0",
"ext-zip": "*",
"ext-zlib": ">=1.2.11",
"pocketmine/raklib": "^0.12.5",
"pocketmine/spl": "^0.3.0",
"mdanter/ecc": "^0.5.0",
"pocketmine/raklib": "dev-master",
"pocketmine/spl": "dev-master",
"pocketmine/binaryutils": "^0.1.9",
"pocketmine/nbt": "^0.2.10",
"pocketmine/math": "^0.2.0",
"pocketmine/nbt": "dev-master",
"pocketmine/math": "dev-master",
"pocketmine/snooze": "^0.1.0",
"daverandom/callback-validator": "dev-master",
"adhocore/json-comment": "^0.0.7"
"adhocore/json-comment": "^0.0.7",
"particle/validator": "^2.3"
},
"autoload": {
"psr-4": {

270
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "377d9e0ab5f1a9a4ef9b664706d26f5b",
"content-hash": "3f4e9e3e4dfdd48390caf564839e8b46",
"packages": [
{
"name": "adhocore/json-comment",
@ -90,6 +90,209 @@
"description": "Tools for validating callback signatures",
"time": "2017-04-03T15:22:41+00:00"
},
{
"name": "fgrosse/phpasn1",
"version": "v2.1.1",
"source": {
"type": "git",
"url": "https://github.com/fgrosse/PHPASN1.git",
"reference": "7ebf2a09084a7bbdb7b879c66fdf7ad80461bbe8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/fgrosse/PHPASN1/zipball/7ebf2a09084a7bbdb7b879c66fdf7ad80461bbe8",
"reference": "7ebf2a09084a7bbdb7b879c66fdf7ad80461bbe8",
"shasum": ""
},
"require": {
"php": ">=7.0.0"
},
"require-dev": {
"phpunit/phpunit": "~6.3",
"satooshi/php-coveralls": "~2.0"
},
"suggest": {
"ext-gmp": "GMP is the preferred extension for big integer calculations",
"php-curl": "For loading OID information from the web if they have not bee defined statically"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
}
},
"autoload": {
"psr-4": {
"FG\\": "lib/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Friedrich Große",
"email": "friedrich.grosse@gmail.com",
"homepage": "https://github.com/FGrosse",
"role": "Author"
},
{
"name": "All contributors",
"homepage": "https://github.com/FGrosse/PHPASN1/contributors"
}
],
"description": "A PHP Framework that allows you to encode and decode arbitrary ASN.1 structures using the ITU-T X.690 Encoding Rules.",
"homepage": "https://github.com/FGrosse/PHPASN1",
"keywords": [
"DER",
"asn.1",
"asn1",
"ber",
"binary",
"decoding",
"encoding",
"x.509",
"x.690",
"x509",
"x690"
],
"time": "2018-12-02T01:34:34+00:00"
},
{
"name": "mdanter/ecc",
"version": "v0.5.2",
"source": {
"type": "git",
"url": "https://github.com/phpecc/phpecc.git",
"reference": "b95f25cc1bacc83a9f0ccd375900b7cfd343029e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpecc/phpecc/zipball/b95f25cc1bacc83a9f0ccd375900b7cfd343029e",
"reference": "b95f25cc1bacc83a9f0ccd375900b7cfd343029e",
"shasum": ""
},
"require": {
"ext-gmp": "*",
"fgrosse/phpasn1": "^2.0",
"php": "^7.0"
},
"require-dev": {
"phpunit/phpunit": "^6.0",
"squizlabs/php_codesniffer": "^2.0",
"symfony/yaml": "^2.6|^3.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Mdanter\\Ecc\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Matyas Danter",
"homepage": "http://matejdanter.com/",
"role": "Author"
},
{
"name": "Thibaud Fabre",
"email": "thibaud@aztech.io",
"homepage": "http://aztech.io",
"role": "Maintainer"
},
{
"name": "Thomas Kerin",
"email": "afk11@users.noreply.github.com",
"role": "Maintainer"
}
],
"description": "PHP Elliptic Curve Cryptography library",
"homepage": "https://github.com/phpecc/phpecc",
"keywords": [
"Diffie",
"ECDSA",
"Hellman",
"curve",
"ecdh",
"elliptic",
"nistp192",
"nistp224",
"nistp256",
"nistp384",
"nistp521",
"phpecc",
"secp256k1",
"secp256r1"
],
"time": "2018-12-03T18:17:01+00:00"
},
{
"name": "particle/validator",
"version": "v2.3.4",
"source": {
"type": "git",
"url": "https://github.com/particle-php/Validator.git",
"reference": "657c7543e51938dd9d114750e49d695129527a7a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/particle-php/Validator/zipball/657c7543e51938dd9d114750e49d695129527a7a",
"reference": "657c7543e51938dd9d114750e49d695129527a7a",
"shasum": ""
},
"require": {
"php": ">=5.4"
},
"require-dev": {
"byrokrat/checkdigit": "^1.0",
"giggsey/libphonenumber-for-php": "^7.2",
"phpunit/phpunit": "~4.0",
"squizlabs/php_codesniffer": "2.*"
},
"suggest": {
"byrokrat/checkdigit": "If you want to use CreditCard validation rule, this library must be installed.",
"giggsey/libphonenumber-for-php": "If you want to use Phone validation rule, this library must be installed."
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.0-dev"
}
},
"autoload": {
"psr-4": {
"Particle\\Validator\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Berry Langerak",
"email": "berry@berryllium.nl",
"role": "Developer"
},
{
"name": "Rick van der Staaij",
"homepage": "http://rickvanderstaaij.nl",
"role": "Developer"
}
],
"description": "Flexible and highly usable validation library with no dependencies.",
"homepage": "http://github.com/particle-php/validator",
"keywords": [
"validation",
"validator"
],
"time": "2019-01-07T13:39:13+00:00"
},
{
"name": "pocketmine/binaryutils",
"version": "0.1.9",
@ -126,16 +329,16 @@
},
{
"name": "pocketmine/math",
"version": "0.2.2",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/pmmp/Math.git",
"reference": "b755d3fb7025c4ddb7d9d6df0ba7e0b65125e51c"
"reference": "d436a98b85edd18d7b1542fab66827b1e6fc8d68"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/pmmp/Math/zipball/b755d3fb7025c4ddb7d9d6df0ba7e0b65125e51c",
"reference": "b755d3fb7025c4ddb7d9d6df0ba7e0b65125e51c",
"url": "https://api.github.com/repos/pmmp/Math/zipball/d436a98b85edd18d7b1542fab66827b1e6fc8d68",
"reference": "d436a98b85edd18d7b1542fab66827b1e6fc8d68",
"shasum": ""
},
"require": {
@ -148,28 +351,33 @@
"pocketmine\\math\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"pocketmine\\math\\": "tests/phpunit/"
}
},
"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.2",
"source": "https://github.com/pmmp/Math/tree/master",
"issues": "https://github.com/pmmp/Math/issues"
},
"time": "2019-01-04T15:42:36+00:00"
"time": "2019-07-29T16:46:11+00:00"
},
{
"name": "pocketmine/nbt",
"version": "0.2.10",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/pmmp/NBT.git",
"reference": "2db27aebe7dc89772aaa8df53361eef801f60063"
"reference": "0976fcea814978c4ca7e53f5c19e459ae8e341e5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/pmmp/NBT/zipball/2db27aebe7dc89772aaa8df53361eef801f60063",
"reference": "2db27aebe7dc89772aaa8df53361eef801f60063",
"url": "https://api.github.com/repos/pmmp/NBT/zipball/0976fcea814978c4ca7e53f5c19e459ae8e341e5",
"reference": "0976fcea814978c4ca7e53f5c19e459ae8e341e5",
"shasum": ""
},
"require": {
@ -194,23 +402,23 @@
],
"description": "PHP library for working with Named Binary Tags",
"support": {
"source": "https://github.com/pmmp/NBT/tree/0.2.10",
"source": "https://github.com/pmmp/NBT/tree/master",
"issues": "https://github.com/pmmp/NBT/issues"
},
"time": "2019-07-22T15:22:23+00:00"
"time": "2019-07-22T15:30:11+00:00"
},
{
"name": "pocketmine/raklib",
"version": "0.12.5",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/pmmp/RakLib.git",
"reference": "874db2d3c24117db2221c1e4550380478aeea852"
"reference": "df98f7e1a67629ee743939318810d3d2bafc5ba3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/pmmp/RakLib/zipball/874db2d3c24117db2221c1e4550380478aeea852",
"reference": "874db2d3c24117db2221c1e4550380478aeea852",
"url": "https://api.github.com/repos/pmmp/RakLib/zipball/df98f7e1a67629ee743939318810d3d2bafc5ba3",
"reference": "df98f7e1a67629ee743939318810d3d2bafc5ba3",
"shasum": ""
},
"require": {
@ -222,7 +430,7 @@
"php-ipv6": "*",
"pocketmine/binaryutils": "^0.1.9",
"pocketmine/snooze": "^0.1.0",
"pocketmine/spl": "^0.3.0"
"pocketmine/spl": "dev-master"
},
"type": "library",
"autoload": {
@ -235,10 +443,10 @@
],
"description": "A RakNet server implementation written in PHP",
"support": {
"source": "https://github.com/pmmp/RakLib/tree/0.12",
"source": "https://github.com/pmmp/RakLib/tree/master",
"issues": "https://github.com/pmmp/RakLib/issues"
},
"time": "2019-07-22T14:38:20+00:00"
"time": "2019-07-22T15:27:51+00:00"
},
{
"name": "pocketmine/snooze",
@ -276,23 +484,20 @@
},
{
"name": "pocketmine/spl",
"version": "0.3.2",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/pmmp/SPL.git",
"reference": "7fd53857cd000491ba69e8db865792a024dd2c49"
"reference": "49a4b0187f2aa9daa1a9457aefa1f4cbcc5ead92"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/pmmp/SPL/zipball/7fd53857cd000491ba69e8db865792a024dd2c49",
"reference": "7fd53857cd000491ba69e8db865792a024dd2c49",
"url": "https://api.github.com/repos/pmmp/SPL/zipball/49a4b0187f2aa9daa1a9457aefa1f4cbcc5ead92",
"reference": "49a4b0187f2aa9daa1a9457aefa1f4cbcc5ead92",
"shasum": ""
},
"type": "library",
"autoload": {
"exclude-from-classmap": [
"stubs"
],
"classmap": [
"./"
]
@ -304,13 +509,17 @@
"support": {
"source": "https://github.com/pmmp/SPL/tree/master"
},
"time": "2018-08-12T15:17:39+00:00"
"time": "2019-07-20T14:32:24+00:00"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": {
"pocketmine/raklib": 20,
"pocketmine/spl": 20,
"pocketmine/nbt": 20,
"pocketmine/math": 20,
"daverandom/callback-validator": 20
},
"prefer-stable": false,
@ -319,11 +528,16 @@
"php": ">=7.2.0",
"php-64bit": "*",
"ext-bcmath": "*",
"ext-chunkutils2": "^0.1.0",
"ext-curl": "*",
"ext-crypto": "^0.3.1",
"ext-ctype": "*",
"ext-date": "*",
"ext-ds": "^1.2.7",
"ext-gmp": "*",
"ext-hash": "*",
"ext-json": "*",
"ext-leveldb": "^0.2.1",
"ext-mbstring": "*",
"ext-openssl": "*",
"ext-pcre": "*",

1
resources/locale Submodule

Submodule resources/locale added at 8718542e62

View File

@ -0,0 +1,8 @@
#This configuration file allows you to control which plugins are loaded on your server.
#List behaviour
# - blacklist: Only plugins which ARE NOT listed will load.
# - whitelist: Only plugins which ARE listed will load.
mode: blacklist
#List names of plugins here.
plugins: []

View File

@ -94,6 +94,9 @@ network:
#Maximum size in bytes of packets sent over the network (default 1492 bytes). Packets larger than this will be
#fragmented or split into smaller parts. Clients can request MTU sizes up to but not more than this number.
max-mtu-size: 1492
#Enable encryption of Minecraft network traffic. This has an impact on performance, but prevents hackers from stealing sessions and pretending to be other players.
#DO NOT DISABLE THIS unless you understand the risks involved.
enable-encryption: true
debug:
#If > 1, it will show debug messages in the console
@ -102,13 +105,10 @@ debug:
player:
#Choose whether to enable player data saving.
save-player-data: true
anti-cheat:
#If false, will try to prevent speed and noclip cheats. May cause movement issues.
allow-movement-cheats: true
level-settings:
#The default format that levels will use when created
default-format: pmanvil
default-format: leveldb
chunk-sending:
#To change server normal render distance, change view-distance in server.properties.
@ -122,8 +122,6 @@ chunk-ticking:
per-tick: 40
#Radius of chunks around a player to tick
tick-radius: 3
light-updates: false
clear-tick-list: true
#IDs of blocks not to perform random ticking on.
disable-block-ticking:
#- 2 # grass

View File

@ -1,150 +0,0 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine;
use pocketmine\lang\TranslationContainer;
use pocketmine\utils\TextFormat;
/**
* Handles the achievement list and a bit more
*/
abstract class Achievement{
/**
* @var array[]
*/
public static $list = [
/*"openInventory" => array(
"name" => "Taking Inventory",
"requires" => [],
),*/
"mineWood" => [
"name" => "Getting Wood",
"requires" => [ //"openInventory",
]
],
"buildWorkBench" => [
"name" => "Benchmarking",
"requires" => [
"mineWood"
]
],
"buildPickaxe" => [
"name" => "Time to Mine!",
"requires" => [
"buildWorkBench"
]
],
"buildFurnace" => [
"name" => "Hot Topic",
"requires" => [
"buildPickaxe"
]
],
"acquireIron" => [
"name" => "Acquire hardware",
"requires" => [
"buildFurnace"
]
],
"buildHoe" => [
"name" => "Time to Farm!",
"requires" => [
"buildWorkBench"
]
],
"makeBread" => [
"name" => "Bake Bread",
"requires" => [
"buildHoe"
]
],
"bakeCake" => [
"name" => "The Lie",
"requires" => [
"buildHoe"
]
],
"buildBetterPickaxe" => [
"name" => "Getting an Upgrade",
"requires" => [
"buildPickaxe"
]
],
"buildSword" => [
"name" => "Time to Strike!",
"requires" => [
"buildWorkBench"
]
],
"diamonds" => [
"name" => "DIAMONDS!",
"requires" => [
"acquireIron"
]
]
];
/**
* @param Player $player
* @param string $achievementId
*
* @return bool
*/
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()->getConfigBool("announce-player-achievements", true)){
Server::getInstance()->broadcastMessage($translation);
}else{
$player->sendMessage($translation);
}
return true;
}
return false;
}
/**
* @param string $achievementId
* @param string $achievementName
* @param array $requires
*
* @return bool
*/
public static function add(string $achievementId, string $achievementName, array $requires = []) : bool{
if(!isset(Achievement::$list[$achievementId])){
Achievement::$list[$achievementId] = [
"name" => $achievementName,
"requires" => $requires
];
return true;
}
return false;
}
}

View File

@ -25,7 +25,6 @@ namespace pocketmine;
use pocketmine\network\mcpe\protocol\ProtocolInfo;
use pocketmine\plugin\PluginBase;
use pocketmine\plugin\PluginLoadOrder;
use pocketmine\plugin\PluginManager;
use pocketmine\utils\Utils;
use pocketmine\utils\VersionString;
@ -56,25 +55,11 @@ use function phpversion;
use function preg_replace;
use function str_split;
use function strpos;
use function strtoupper;
use function substr;
use function time;
use function zend_version;
use function zlib_encode;
use const E_COMPILE_ERROR;
use const E_COMPILE_WARNING;
use const E_CORE_ERROR;
use const E_CORE_WARNING;
use const E_DEPRECATED;
use const E_ERROR;
use const E_NOTICE;
use const E_PARSE;
use const E_RECOVERABLE_ERROR;
use const E_STRICT;
use const E_USER_DEPRECATED;
use const E_USER_ERROR;
use const E_USER_NOTICE;
use const E_USER_WARNING;
use const E_WARNING;
use const FILE_IGNORE_NEW_LINES;
use const JSON_UNESCAPED_SLASHES;
use const PHP_EOL;
@ -134,7 +119,7 @@ class CrashDump{
return $this->path;
}
public function getEncodedData(){
public function getEncodedData() : string{
return $this->encodedData;
}
@ -142,7 +127,7 @@ class CrashDump{
return $this->data;
}
private function encodeData(){
private function encodeData() : void{
$this->addLine();
$this->addLine("----------------------REPORT THE DATA BELOW THIS LINE-----------------------");
$this->addLine();
@ -158,7 +143,7 @@ class CrashDump{
$this->addLine("===END CRASH DUMP===");
}
private function pluginsData(){
private function pluginsData() : void{
if($this->server->getPluginManager() instanceof PluginManager){
$this->addLine();
$this->addLine("Loaded plugins:");
@ -174,7 +159,7 @@ class CrashDump{
"depends" => $d->getDepend(),
"softDepends" => $d->getSoftDepend(),
"main" => $d->getMain(),
"load" => $d->getOrder() === PluginLoadOrder::POSTWORLD ? "POSTWORLD" : "STARTUP",
"load" => strtoupper($d->getOrder()->name()),
"website" => $d->getWebsite()
];
$this->addLine($d->getName() . " " . $d->getVersion() . " by " . implode(", ", $d->getAuthors()) . " for API(s) " . implode(", ", $d->getCompatibleApis()));
@ -182,7 +167,7 @@ class CrashDump{
}
}
private function extraData(){
private function extraData() : void{
global $argv;
if($this->server->getProperty("auto-report.send-settings", true) !== false){
@ -209,7 +194,7 @@ class CrashDump{
}
}
private function baseCrash(){
private function baseCrash() : void{
global $lastExceptionError, $lastError;
if(isset($lastExceptionError)){
@ -217,26 +202,13 @@ class CrashDump{
}else{
$error = (array) error_get_last();
$error["trace"] = Utils::currentTrace(3); //Skipping CrashDump->baseCrash, CrashDump->construct, Server->crashDump
$errorConversion = [
E_ERROR => "E_ERROR",
E_WARNING => "E_WARNING",
E_PARSE => "E_PARSE",
E_NOTICE => "E_NOTICE",
E_CORE_ERROR => "E_CORE_ERROR",
E_CORE_WARNING => "E_CORE_WARNING",
E_COMPILE_ERROR => "E_COMPILE_ERROR",
E_COMPILE_WARNING => "E_COMPILE_WARNING",
E_USER_ERROR => "E_USER_ERROR",
E_USER_WARNING => "E_USER_WARNING",
E_USER_NOTICE => "E_USER_NOTICE",
E_STRICT => "E_STRICT",
E_RECOVERABLE_ERROR => "E_RECOVERABLE_ERROR",
E_DEPRECATED => "E_DEPRECATED",
E_USER_DEPRECATED => "E_USER_DEPRECATED"
];
$error["fullFile"] = $error["file"];
$error["file"] = Utils::cleanPath($error["file"]);
$error["type"] = $errorConversion[$error["type"]] ?? $error["type"];
try{
$error["type"] = \ErrorUtils::errorTypeToString($error["type"]);
}catch(\InvalidArgumentException $e){
//pass
}
if(($pos = strpos($error["message"], "\n")) !== false){
$error["message"] = substr($error["message"], 0, $pos);
}
@ -317,7 +289,7 @@ class CrashDump{
return false;
}
private function generalData(){
private function generalData() : void{
$version = new VersionString(\pocketmine\BASE_VERSION, \pocketmine\IS_DEVELOPMENT_BUILD, \pocketmine\BUILD_NUMBER);
$this->data["general"] = [];
$this->data["general"]["name"] = $this->server->getName();
@ -340,11 +312,11 @@ class CrashDump{
$this->addLine("OS : " . PHP_OS . ", " . Utils::getOS());
}
public function addLine($line = ""){
public function addLine($line = "") : void{
fwrite($this->fp, $line . PHP_EOL);
}
public function add($str){
public function add($str) : void{
fwrite($this->fp, $str);
}
}

View File

@ -27,6 +27,7 @@ use pocketmine\event\server\LowMemoryEvent;
use pocketmine\scheduler\DumpWorkerMemoryTask;
use pocketmine\scheduler\GarbageCollectionTask;
use pocketmine\timings\Timings;
use pocketmine\utils\Process;
use pocketmine\utils\Utils;
use function arsort;
use function count;
@ -109,13 +110,17 @@ class MemoryManager{
/** @var bool */
private $dumpWorkers = true;
/** @var \Logger */
private $logger;
public function __construct(Server $server){
$this->server = $server;
$this->logger = new \PrefixedLogger($server->getLogger(), "Memory Manager");
$this->init();
}
private function init(){
private function init() : void{
$this->memoryLimit = ((int) $this->server->getProperty("memory.main-limit", 0)) * 1024 * 1024;
$defaultMemory = 1024;
@ -176,6 +181,13 @@ class MemoryManager{
return $this->lowMemory;
}
/**
* @return int
*/
public function getGlobalMemoryLimit() : int{
return $this->globalMemoryLimit;
}
/**
* @return bool
*/
@ -202,18 +214,18 @@ class MemoryManager{
* @param bool $global
* @param int $triggerCount
*/
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",
public function trigger(int $memory, int $limit, bool $global = false, int $triggerCount = 0) : void{
$this->logger->debug(sprintf("%sLow memory triggered, limit %gMB, using %gMB",
$global ? "Global " : "", round(($limit / 1024) / 1024, 2), round(($memory / 1024) / 1024, 2)));
if($this->lowMemClearWorldCache){
foreach($this->server->getLevels() as $level){
$level->clearCache(true);
foreach($this->server->getWorldManager()->getWorlds() as $world){
$world->clearCache(true);
}
}
if($this->lowMemChunkGC){
foreach($this->server->getLevels() as $level){
$level->doChunkGarbageCollection();
foreach($this->server->getWorldManager()->getWorlds() as $world){
$world->doChunkGarbageCollection();
}
}
@ -225,18 +237,18 @@ class MemoryManager{
$cycles = $this->triggerGarbageCollector();
}
$this->server->getLogger()->debug(sprintf("[Memory Manager] Freed %gMB, $cycles cycles", round(($ev->getMemoryFreed() / 1024) / 1024, 2)));
$this->logger->debug(sprintf("Freed %gMB, $cycles cycles", round(($ev->getMemoryFreed() / 1024) / 1024, 2)));
}
/**
* Called every tick to update the memory manager state.
*/
public function check(){
public function check() : void{
Timings::$memoryManagerTimer->startTiming();
if(($this->memoryLimit > 0 or $this->globalMemoryLimit > 0) and ++$this->checkTicker >= $this->checkRate){
$this->checkTicker = 0;
$memory = Utils::getMemoryUsage(true);
$memory = Process::getMemoryUsage(true);
$trigger = false;
if($this->memoryLimit > 0 and $memory[0] > $this->memoryLimit){
$trigger = 0;
@ -277,7 +289,7 @@ class MemoryManager{
if($this->garbageCollectionAsync){
$pool = $this->server->getAsyncPool();
if(($w = $pool->shutdownUnusedWorkers()) > 0){
$this->server->getLogger()->debug("Shut down $w idle async pool workers");
$this->logger->debug("Shut down $w idle async pool workers");
}
foreach($pool->getRunningWorkers() as $i){
$pool->submitTaskToWorker(new GarbageCollectionTask(), $i);
@ -298,9 +310,10 @@ class MemoryManager{
* @param int $maxNesting
* @param int $maxStringSize
*/
public function dumpServerMemory(string $outputFolder, int $maxNesting, int $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());
public function dumpServerMemory(string $outputFolder, int $maxNesting, int $maxStringSize) : void{
$logger = new \PrefixedLogger($this->server->getLogger(), "Memory Dump");
$logger->notice("After the memory dump is done, the server might crash");
self::dumpMemory($this->server, $outputFolder, $maxNesting, $maxStringSize, $logger);
if($this->dumpWorkers){
$pool = $this->server->getAsyncPool();
@ -321,7 +334,7 @@ class MemoryManager{
*
* @throws \ReflectionException
*/
public static function dumpMemory($startingObject, string $outputFolder, int $maxNesting, int $maxStringSize, \Logger $logger){
public static function dumpMemory($startingObject, string $outputFolder, int $maxNesting, int $maxStringSize, \Logger $logger) : void{
$hardLimit = ini_get('memory_limit');
ini_set('memory_limit', '-1');
gc_disable();
@ -365,7 +378,7 @@ class MemoryManager{
}
file_put_contents($outputFolder . "/staticProperties.js", json_encode($staticProperties, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
$logger->info("[Dump] Wrote $staticCount static properties");
$logger->info("Wrote $staticCount static properties");
if(isset($GLOBALS)){ //This might be null if we're on a different thread
$globalVariables = [];
@ -393,7 +406,7 @@ class MemoryManager{
}
file_put_contents($outputFolder . "/globalVariables.js", json_encode($globalVariables, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
$logger->info("[Dump] Wrote $globalCount global variables");
$logger->info("Wrote $globalCount global variables");
}
self::continueDump($startingObject, $data, $objects, $refCounts, 0, $maxNesting, $maxStringSize);
@ -454,7 +467,7 @@ class MemoryManager{
}while($continue);
$logger->info("[Dump] Wrote " . count($objects) . " objects");
$logger->info("Wrote " . count($objects) . " objects");
fclose($obData);
@ -464,7 +477,7 @@ class MemoryManager{
arsort($instanceCounts, SORT_NUMERIC);
file_put_contents($outputFolder . "/instanceCounts.js", json_encode($instanceCounts, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
$logger->info("[Dump] Finished!");
$logger->info("Finished!");
ini_set('memory_limit', $hardLimit);
gc_enable();
@ -479,7 +492,7 @@ class MemoryManager{
* @param int $maxNesting
* @param int $maxStringSize
*/
private static function continueDump($from, &$data, array &$objects, array &$refCounts, int $recursion, int $maxNesting, int $maxStringSize){
private static function continueDump($from, &$data, array &$objects, array &$refCounts, int $recursion, int $maxNesting, int $maxStringSize) : void{
if($maxNesting <= 0){
$data = "(error) NESTING LIMIT REACHED";
return;

File diff suppressed because it is too large Load Diff

View File

@ -28,11 +28,12 @@ namespace {
namespace pocketmine {
use pocketmine\thread\ThreadManager;
use pocketmine\utils\MainLogger;
use pocketmine\utils\Process;
use pocketmine\utils\ServerKiller;
use pocketmine\utils\Terminal;
use pocketmine\utils\Timezone;
use pocketmine\utils\Utils;
use pocketmine\utils\VersionString;
use pocketmine\wizard\SetupWizard;
@ -73,11 +74,16 @@ namespace pocketmine {
$extensions = [
"bcmath" => "BC Math",
"chunkutils2" => "PocketMine ChunkUtils v2",
"curl" => "cURL",
"crypto" => "php-crypto",
"ctype" => "ctype",
"date" => "Date",
"ds" => "Data Structures",
"gmp" => "GMP",
"hash" => "Hash",
"json" => "JSON",
"leveldb" => "LevelDB",
"mbstring" => "Multibyte String",
"openssl" => "OpenSSL",
"pcre" => "PCRE",
@ -153,13 +159,16 @@ namespace pocketmine {
if(\pocketmine\COMPOSER_AUTOLOADER_PATH !== false and is_file(\pocketmine\COMPOSER_AUTOLOADER_PATH)){
require_once(\pocketmine\COMPOSER_AUTOLOADER_PATH);
if(extension_loaded('parallel')){
\parallel\bootstrap(\pocketmine\COMPOSER_AUTOLOADER_PATH);
}
}else{
critical_error("Composer autoloader not found at " . $bootstrap);
critical_error("Please install/update Composer dependencies or use provided builds.");
exit(1);
}
set_error_handler([Utils::class, 'errorExceptionHandler']);
\ErrorUtils::setErrorExceptionHandler();
/*
* We now use the Composer autoloader, but this autoloader is still for loading plugins.
@ -176,7 +185,7 @@ namespace pocketmine {
ini_set("memory_limit", '-1');
define('pocketmine\RESOURCE_PATH', \pocketmine\PATH . 'src' . DIRECTORY_SEPARATOR . 'pocketmine' . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR);
define('pocketmine\RESOURCE_PATH', \pocketmine\PATH . 'resources' . DIRECTORY_SEPARATOR);
$opts = getopt("", ["data:", "plugins:", "no-wizard", "enable-ansi", "disable-ansi"]);
@ -204,7 +213,7 @@ namespace pocketmine {
flock(\pocketmine\LOCK_FILE, LOCK_SH); //prevent acquiring an exclusive lock from another process, but allow reading
//Logger has a dependency on timezone
$tzError = Timezone::init();
Timezone::init();
if(isset($opts["enable-ansi"])){
Terminal::init(true);
@ -215,19 +224,11 @@ namespace pocketmine {
}
$logger = new MainLogger(\pocketmine\DATA . "server.log");
$logger->registerStatic();
foreach($tzError as $e){
$logger->warning($e);
}
unset($tzError);
\GlobalLogger::set($logger);
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(!extension_loaded("pocketmine_chunkutils")){
$logger->warning("ChunkUtils extension is missing. Anvil-format worlds will experience degraded performance.");
}
if(\Phar::running(true) === ""){
$logger->warning("Non-packaged " . \pocketmine\NAME . " installation detected. Consider using a phar in production for better performance.");
@ -239,9 +240,9 @@ namespace pocketmine {
$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){
if(Process::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
if(Process::execute("git diff --quiet") === 1 or Process::execute("git diff --cached --quiet") === 1){ //Locally-modified
$gitHash .= "-dirty";
}
}
@ -284,7 +285,7 @@ namespace pocketmine {
if(\pocketmine\DEBUG > 1){
echo "Some threads could not be stopped, performing a force-kill" . PHP_EOL . PHP_EOL;
}
Utils::kill(getmypid());
Process::kill(getmypid());
}
}while(false);

File diff suppressed because it is too large Load Diff

View File

@ -22,6 +22,6 @@
namespace pocketmine;
const NAME = "PocketMine-MP";
const BASE_VERSION = "3.9.4";
const BASE_VERSION = "4.0.0";
const IS_DEVELOPMENT_BUILD = true;
const BUILD_NUMBER = 0;

View File

@ -25,11 +25,5 @@ namespace pocketmine\block;
class ActivatorRail extends RedstoneRail{
protected $id = self::ACTIVATOR_RAIL;
public function getName() : string{
return "Activator Rail";
}
//TODO
}

View File

@ -23,31 +23,15 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\math\AxisAlignedBB;
/**
* Air block
*/
class Air extends Transparent{
protected $id = self::AIR;
public function __construct(int $meta = 0){
$this->meta = $meta;
}
public function getName() : string{
return "Air";
}
public function canPassThrough() : bool{
return true;
}
public function isBreakable(Item $item) : bool{
return false;
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? BlockBreakInfo::indestructible(0.0));
}
public function canBeFlowedInto() : bool{
@ -73,12 +57,4 @@ class Air extends Transparent{
public function getCollisionBoxes() : array{
return [];
}
public function getHardness() : float{
return -1;
}
public function getBlastResistance() : float{
return 0;
}
}

View File

@ -23,93 +23,60 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\block\utils\BlockDataSerializer;
use pocketmine\block\utils\Fallable;
use pocketmine\block\utils\FallableTrait;
use pocketmine\inventory\AnvilInventory;
use pocketmine\item\Item;
use pocketmine\item\TieredTool;
use pocketmine\item\ToolTier;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\Player;
use pocketmine\player\Player;
use pocketmine\world\BlockTransaction;
class Anvil extends Fallable{
class Anvil extends Transparent implements Fallable{
use FallableTrait;
public const TYPE_NORMAL = 0;
public const TYPE_SLIGHTLY_DAMAGED = 4;
public const TYPE_VERY_DAMAGED = 8;
/** @var int */
protected $facing = Facing::NORTH;
protected $id = self::ANVIL;
public function __construct(int $meta = 0){
$this->meta = $meta;
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(5.0, BlockToolType::PICKAXE, ToolTier::WOOD()->getHarvestLevel(), 6000.0));
}
public function isTransparent() : bool{
return true;
protected function writeStateToMeta() : int{
return BlockDataSerializer::writeLegacyHorizontalFacing($this->facing);
}
public function getHardness() : float{
return 5;
public function readStateFromData(int $id, int $stateMeta) : void{
$this->facing = BlockDataSerializer::readLegacyHorizontalFacing($stateMeta);
}
public function getBlastResistance() : float{
return 6000;
public function getStateBitmask() : int{
return 0b11;
}
public function getVariantBitmask() : int{
return 0x0c;
protected function recalculateBoundingBox() : ?AxisAlignedBB{
return AxisAlignedBB::one()->squash(Facing::axis(Facing::rotateY($this->facing, false)), 1 / 8);
}
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->getVariant()] ?? "Anvil";
}
public function getToolType() : int{
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{
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($player instanceof Player){
$player->addWindow(new AnvilInventory($this));
$player->setCurrentWindow(new AnvilInventory($this));
}
return true;
}
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->getVariant() | $direction;
return $this->getLevel()->setBlock($blockReplace, $this, true, true);
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($player !== null){
$this->facing = Facing::rotateY($player->getHorizontalFacing(), true);
}
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
}
public function tickFalling() : ?Block{
return null;
}
}

View File

@ -0,0 +1,194 @@
<?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 Ds\Deque;
use pocketmine\block\tile\Banner as TileBanner;
use pocketmine\block\utils\BannerPattern;
use pocketmine\block\utils\BlockDataSerializer;
use pocketmine\block\utils\DyeColor;
use pocketmine\item\Banner as ItemBanner;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\ItemIds;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\player\Player;
use pocketmine\utils\Utils;
use pocketmine\world\BlockTransaction;
use function assert;
use function floor;
class Banner extends Transparent{
/** @var BlockIdentifierFlattened */
protected $idInfo;
//TODO: conditionally useless properties, find a way to fix
/** @var int */
protected $rotation = 0;
/** @var int */
protected $facing = Facing::UP;
/** @var DyeColor */
protected $baseColor;
/** @var Deque|BannerPattern[] */
protected $patterns;
public function __construct(BlockIdentifierFlattened $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(1.0, BlockToolType::AXE));
$this->baseColor = DyeColor::BLACK();
$this->patterns = new Deque();
}
public function __clone(){
$this->patterns = $this->patterns->map(Utils::cloneCallback());
}
public function getId() : int{
return $this->facing === Facing::UP ? parent::getId() : $this->idInfo->getSecondId();
}
protected function writeStateToMeta() : int{
if($this->facing === Facing::UP){
return $this->rotation;
}
return BlockDataSerializer::writeHorizontalFacing($this->facing);
}
public function readStateFromData(int $id, int $stateMeta) : void{
if($id === $this->idInfo->getSecondId()){
$this->facing = BlockDataSerializer::readHorizontalFacing($stateMeta);
}else{
$this->facing = Facing::UP;
$this->rotation = $stateMeta;
}
}
public function getStateBitmask() : int{
return 0b1111;
}
public function readStateFromWorld() : void{
parent::readStateFromWorld();
$tile = $this->world->getTile($this);
if($tile instanceof TileBanner){
$this->baseColor = $tile->getBaseColor();
$this->setPatterns($tile->getPatterns());
}
}
public function writeStateToWorld() : void{
parent::writeStateToWorld();
$tile = $this->world->getTile($this);
assert($tile instanceof TileBanner);
$tile->setBaseColor($this->baseColor);
$tile->setPatterns($this->patterns);
}
public function isSolid() : bool{
return false;
}
/**
* TODO: interface method? this is only the BASE colour...
* @return DyeColor
*/
public function getColor() : DyeColor{
return $this->baseColor;
}
/**
* @return Deque|BannerPattern[]
*/
public function getPatterns() : Deque{
return $this->patterns;
}
/**
* @param Deque|BannerPattern[] $patterns
*/
public function setPatterns(Deque $patterns) : void{
$checked = $patterns->filter(function($v){ return $v instanceof BannerPattern; });
if($checked->count() !== $patterns->count()){
throw new \TypeError("Deque must only contain " . BannerPattern::class . " objects");
}
$this->patterns = $checked;
}
protected function recalculateBoundingBox() : ?AxisAlignedBB{
return null;
}
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($item instanceof ItemBanner){
$this->baseColor = $item->getColor();
$this->setPatterns($item->getPatterns());
}
if($face !== Facing::DOWN){
$this->facing = $face;
if($face === Facing::UP){
$this->rotation = $player !== null ? ((int) floor((($player->yaw + 180) * 16 / 360) + 0.5)) & 0x0f : 0;
}
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
}
return false;
}
public function onNearbyBlockChange() : void{
if($this->getSide(Facing::opposite($this->facing))->getId() === BlockLegacyIds::AIR){
$this->getWorld()->useBreakOn($this);
}
}
public function asItem() : Item{
return ItemFactory::get(ItemIds::BANNER, $this->baseColor->getInvertedMagicNumber());
}
public function getDropsForCompatibleTool(Item $item) : array{
$drop = $this->asItem();
if($drop instanceof ItemBanner and !$this->patterns->isEmpty()){
$drop->setPatterns($this->patterns);
}
return [$drop];
}
public function getPickedItem(bool $addUserData = false) : Item{
$result = $this->asItem();
if($addUserData and $result instanceof ItemBanner and !$this->patterns->isEmpty()){
$result->setPatterns($this->patterns);
}
return $result;
}
public function isAffectedBySilkTouch() : bool{
return false;
}
}

View File

@ -23,9 +23,12 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\block\utils\InvalidBlockStateException;
use pocketmine\item\Item;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\Player;
use pocketmine\player\Player;
use pocketmine\world\BlockTransaction;
use function array_map;
use function array_reverse;
use function array_search;
@ -36,69 +39,76 @@ use function in_array;
abstract class BaseRail extends Flowable{
public const STRAIGHT_NORTH_SOUTH = 0;
public const STRAIGHT_EAST_WEST = 1;
public const ASCENDING_EAST = 2;
public const ASCENDING_WEST = 3;
public const ASCENDING_NORTH = 4;
public const ASCENDING_SOUTH = 5;
private const ASCENDING_SIDES = [
self::ASCENDING_NORTH => Vector3::SIDE_NORTH,
self::ASCENDING_EAST => Vector3::SIDE_EAST,
self::ASCENDING_SOUTH => Vector3::SIDE_SOUTH,
self::ASCENDING_WEST => Vector3::SIDE_WEST
];
protected const FLAG_ASCEND = 1 << 24; //used to indicate direction-up
protected const CONNECTIONS = [
//straights
self::STRAIGHT_NORTH_SOUTH => [
Vector3::SIDE_NORTH,
Vector3::SIDE_SOUTH
BlockLegacyMetadata::RAIL_STRAIGHT_NORTH_SOUTH => [
Facing::NORTH,
Facing::SOUTH
],
self::STRAIGHT_EAST_WEST => [
Vector3::SIDE_EAST,
Vector3::SIDE_WEST
BlockLegacyMetadata::RAIL_STRAIGHT_EAST_WEST => [
Facing::EAST,
Facing::WEST
],
//ascending
self::ASCENDING_EAST => [
Vector3::SIDE_WEST,
Vector3::SIDE_EAST | self::FLAG_ASCEND
BlockLegacyMetadata::RAIL_ASCENDING_EAST => [
Facing::WEST,
Facing::EAST | self::FLAG_ASCEND
],
self::ASCENDING_WEST => [
Vector3::SIDE_EAST,
Vector3::SIDE_WEST | self::FLAG_ASCEND
BlockLegacyMetadata::RAIL_ASCENDING_WEST => [
Facing::EAST,
Facing::WEST | self::FLAG_ASCEND
],
self::ASCENDING_NORTH => [
Vector3::SIDE_SOUTH,
Vector3::SIDE_NORTH | self::FLAG_ASCEND
BlockLegacyMetadata::RAIL_ASCENDING_NORTH => [
Facing::SOUTH,
Facing::NORTH | self::FLAG_ASCEND
],
self::ASCENDING_SOUTH => [
Vector3::SIDE_NORTH,
Vector3::SIDE_SOUTH | self::FLAG_ASCEND
BlockLegacyMetadata::RAIL_ASCENDING_SOUTH => [
Facing::NORTH,
Facing::SOUTH | self::FLAG_ASCEND
]
];
public function __construct(int $meta = 0){
$this->meta = $meta;
/** @var int[] */
protected $connections = [];
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(0.7));
}
public function getHardness() : float{
return 0.7;
protected function writeStateToMeta() : int{
if(empty($this->connections)){
return BlockLegacyMetadata::RAIL_STRAIGHT_NORTH_SOUTH;
}
return $this->getMetaForState($this->connections);
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
if(!$blockReplace->getSide(Vector3::SIDE_DOWN)->isTransparent() and $this->getLevel()->setBlock($blockReplace, $this, true, true)){
$this->tryReconnect();
return true;
public function readStateFromData(int $id, int $stateMeta) : void{
$connections = $this->getConnectionsFromMeta($stateMeta);
if($connections === null){
throw new InvalidBlockStateException("Invalid rail type meta $stateMeta");
}
$this->connections = $connections;
}
public function getStateBitmask() : int{
return 0b1111;
}
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if(!$blockReplace->getSide(Facing::DOWN)->isTransparent()){
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
}
return false;
}
public function onPostPlace() : void{
$this->tryReconnect();
}
protected static function searchState(array $connections, array $lookup) : int{
$meta = array_search($connections, $lookup, true);
if($meta === false){
@ -127,9 +137,11 @@ abstract class BaseRail extends Flowable{
/**
* Returns the connection directions of this rail (depending on the current block state)
*
* @param int $meta
*
* @return int[]
*/
abstract protected function getConnectionsForState() : array;
abstract protected function getConnectionsFromMeta(int $meta) : ?array;
/**
* Returns all the directions this rail is already connected in.
@ -141,21 +153,21 @@ abstract class BaseRail extends Flowable{
$connections = [];
/** @var int $connection */
foreach($this->getConnectionsForState() as $connection){
foreach($this->connections as $connection){
$other = $this->getSide($connection & ~self::FLAG_ASCEND);
$otherConnection = Vector3::getOppositeSide($connection & ~self::FLAG_ASCEND);
$otherConnection = Facing::opposite($connection & ~self::FLAG_ASCEND);
if(($connection & self::FLAG_ASCEND) !== 0){
$other = $other->getSide(Vector3::SIDE_UP);
$other = $other->getSide(Facing::UP);
}elseif(!($other instanceof BaseRail)){ //check for rail sloping up to meet this one
$other = $other->getSide(Vector3::SIDE_DOWN);
$other = $other->getSide(Facing::DOWN);
$otherConnection |= self::FLAG_ASCEND;
}
if(
$other instanceof BaseRail and
in_array($otherConnection, $other->getConnectionsForState(), true)
in_array($otherConnection, $other->connections, true)
){
$connections[] = $connection;
}
@ -169,10 +181,10 @@ abstract class BaseRail extends Flowable{
case 0:
//No constraints, can connect in any direction
$possible = [
Vector3::SIDE_NORTH => true,
Vector3::SIDE_SOUTH => true,
Vector3::SIDE_WEST => true,
Vector3::SIDE_EAST => true
Facing::NORTH => true,
Facing::SOUTH => true,
Facing::WEST => true,
Facing::EAST => true
];
foreach($possible as $p => $_){
$possible[$p | self::FLAG_ASCEND] = true;
@ -189,7 +201,7 @@ abstract class BaseRail extends Flowable{
}
protected function getPossibleConnectionDirectionsOneConstraint(int $constraint) : array{
$opposite = Vector3::getOppositeSide($constraint & ~self::FLAG_ASCEND);
$opposite = Facing::opposite($constraint & ~self::FLAG_ASCEND);
$possible = [$opposite => true];
@ -210,15 +222,15 @@ abstract class BaseRail extends Flowable{
$continue = false;
foreach($possible as $thisSide => $_){
$otherSide = Vector3::getOppositeSide($thisSide & ~self::FLAG_ASCEND);
$otherSide = Facing::opposite($thisSide & ~self::FLAG_ASCEND);
$other = $this->getSide($thisSide & ~self::FLAG_ASCEND);
if(($thisSide & self::FLAG_ASCEND) !== 0){
$other = $other->getSide(Vector3::SIDE_UP);
$other = $other->getSide(Facing::UP);
}elseif(!($other instanceof BaseRail)){ //check if other rails can slope up to meet this one
$other = $other->getSide(Vector3::SIDE_DOWN);
$other = $other->getSide(Facing::DOWN);
$otherSide |= self::FLAG_ASCEND;
}
@ -231,7 +243,8 @@ abstract class BaseRail extends Flowable{
if(isset($otherPossible[$otherSide])){
$otherConnections[] = $otherSide;
$other->updateState($otherConnections);
$other->setConnections($otherConnections);
$other->world->setBlock($other, $other);
$changed = true;
$thisConnections[] = $thisSide;
@ -243,31 +256,31 @@ abstract class BaseRail extends Flowable{
}while($continue);
if($changed){
$this->updateState($thisConnections);
$this->setConnections($thisConnections);
$this->world->setBlock($this, $this);
}
}
private function updateState(array $connections) : void{
private function setConnections(array $connections) : void{
if(count($connections) === 1){
$connections[] = Vector3::getOppositeSide($connections[0] & ~self::FLAG_ASCEND);
$connections[] = Facing::opposite($connections[0] & ~self::FLAG_ASCEND);
}elseif(count($connections) !== 2){
throw new \InvalidArgumentException("Expected exactly 2 connections, got " . count($connections));
}
$this->meta = $this->getMetaForState($connections);
$this->level->setBlock($this, $this, false, false); //avoid recursion
$this->connections = $connections;
}
public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_DOWN)->isTransparent() or (
isset(self::ASCENDING_SIDES[$this->meta & 0x07]) and
$this->getSide(self::ASCENDING_SIDES[$this->meta & 0x07])->isTransparent()
)){
$this->getLevel()->useBreakOn($this);
if($this->getSide(Facing::DOWN)->isTransparent()){
$this->world->useBreakOn($this);
}else{
foreach($this->connections as $connection){
if(($connection & self::FLAG_ASCEND) !== 0 and $this->getSide($connection & ~self::FLAG_ASCEND)->isTransparent()){
$this->world->useBreakOn($this);
break;
}
}
}
}
public function getVariantBitmask() : int{
return 0;
}
}

View File

@ -23,118 +23,116 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\block\tile\Bed as TileBed;
use pocketmine\block\utils\BlockDataSerializer;
use pocketmine\block\utils\DyeColor;
use pocketmine\item\Bed as ItemBed;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\lang\TranslationContainer;
use pocketmine\level\Level;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\Player;
use pocketmine\tile\Bed as TileBed;
use pocketmine\tile\Tile;
use pocketmine\player\Player;
use pocketmine\utils\TextFormat;
use pocketmine\world\BlockTransaction;
use pocketmine\world\World;
class Bed extends Transparent{
public const BITFLAG_OCCUPIED = 0x04;
public const BITFLAG_HEAD = 0x08;
protected $id = self::BED_BLOCK;
/** @var int */
protected $facing = Facing::NORTH;
/** @var bool */
protected $occupied = false;
/** @var bool */
protected $head = false;
/** @var DyeColor */
protected $color;
protected $itemId = Item::BED;
public function __construct(int $meta = 0){
$this->meta = $meta;
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(0.2));
$this->color = DyeColor::RED();
}
public function getHardness() : float{
return 0.2;
protected function writeStateToMeta() : int{
return BlockDataSerializer::writeLegacyHorizontalFacing($this->facing) |
($this->occupied ? BlockLegacyMetadata::BED_FLAG_OCCUPIED : 0) |
($this->head ? BlockLegacyMetadata::BED_FLAG_HEAD : 0);
}
public function getName() : string{
return "Bed Block";
public function readStateFromData(int $id, int $stateMeta) : void{
$this->facing = BlockDataSerializer::readLegacyHorizontalFacing($stateMeta & 0x03);
$this->occupied = ($stateMeta & BlockLegacyMetadata::BED_FLAG_OCCUPIED) !== 0;
$this->head = ($stateMeta & BlockLegacyMetadata::BED_FLAG_HEAD) !== 0;
}
public function getStateBitmask() : int{
return 0b1111;
}
public function readStateFromWorld() : void{
parent::readStateFromWorld();
//read extra state information from the tile - this is an ugly hack
$tile = $this->world->getTile($this);
if($tile instanceof TileBed){
$this->color = $tile->getColor();
}
}
public function writeStateToWorld() : void{
parent::writeStateToWorld();
//extra block properties storage hack
$tile = $this->world->getTile($this);
if($tile instanceof TileBed){
$tile->setColor($this->color);
}
}
protected function recalculateBoundingBox() : ?AxisAlignedBB{
return new AxisAlignedBB(
$this->x,
$this->y,
$this->z,
$this->x + 1,
$this->y + 0.5625,
$this->z + 1
);
return AxisAlignedBB::one()->trim(Facing::UP, 7 / 16);
}
public function isHeadPart() : bool{
return ($this->meta & self::BITFLAG_HEAD) !== 0;
return $this->head;
}
/**
* @return bool
*/
public function isOccupied() : bool{
return ($this->meta & self::BITFLAG_OCCUPIED) !== 0;
return $this->occupied;
}
public function setOccupied(bool $occupied = true){
if($occupied){
$this->meta |= self::BITFLAG_OCCUPIED;
}else{
$this->meta &= ~self::BITFLAG_OCCUPIED;
}
public function setOccupied(bool $occupied = true) : void{
$this->occupied = $occupied;
$this->world->setBlock($this, $this, false);
$this->getLevel()->setBlock($this, $this, false, false);
if(($other = $this->getOtherHalf()) !== null and $other->isOccupied() !== $occupied){
$other->setOccupied($occupied);
if(($other = $this->getOtherHalf()) !== null){
$other->occupied = $occupied;
$this->world->setBlock($other, $other, false);
}
}
/**
* @param int $meta
* @param bool $isHead
*
* @return int
*/
public static function getOtherHalfSide(int $meta, bool $isHead = false) : int{
$rotation = $meta & 0x03;
$side = -1;
switch($rotation){
case 0x00: //South
$side = Vector3::SIDE_SOUTH;
break;
case 0x01: //West
$side = Vector3::SIDE_WEST;
break;
case 0x02: //North
$side = Vector3::SIDE_NORTH;
break;
case 0x03: //East
$side = Vector3::SIDE_EAST;
break;
}
if($isHead){
$side = Vector3::getOppositeSide($side);
}
return $side;
private function getOtherHalfSide() : int{
return $this->head ? Facing::opposite($this->facing) : $this->facing;
}
/**
* @return Bed|null
*/
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))){
$other = $this->getSide($this->getOtherHalfSide());
if($other instanceof Bed and $other->head !== $this->head and $other->facing === $this->facing){
return $other;
}
return null;
}
public function onActivate(Item $item, Player $player = null) : bool{
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($player !== null){
$other = $this->getOtherHalf();
if($other === null){
@ -146,9 +144,9 @@ class Bed extends Transparent{
return true;
}
$time = $this->getLevel()->getTime() % Level::TIME_FULL;
$time = $this->getWorld()->getTimeOfDay();
$isNight = ($time >= Level::TIME_NIGHT and $time < Level::TIME_SUNRISE);
$isNight = ($time >= World::TIME_NIGHT and $time < World::TIME_SUNRISE);
if(!$isNight){
$player->sendMessage(new TranslationContainer(TextFormat::GRAY . "%tile.bed.noSleep"));
@ -171,18 +169,19 @@ class Bed extends Transparent{
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$down = $this->getSide(Vector3::SIDE_DOWN);
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($item instanceof ItemBed){ //TODO: the item should do this
$this->color = $item->getColor();
}
$down = $this->getSide(Facing::DOWN);
if(!$down->isTransparent()){
$meta = (($player instanceof Player ? $player->getDirection() : 0) - 1) & 0x03;
$next = $this->getSide(self::getOtherHalfSide($meta));
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);
Tile::createTile(Tile::BED, $this->getLevel(), TileBed::createNBT($this, $face, $item, $player));
Tile::createTile(Tile::BED, $this->getLevel(), TileBed::createNBT($next, $face, $item, $player));
$this->facing = $player !== null ? $player->getHorizontalFacing() : Facing::NORTH;
$next = $this->getSide($this->getOtherHalfSide());
if($next->canBeReplaced() and !$next->getSide(Facing::DOWN)->isTransparent()){
$nextState = clone $this;
$nextState->head = true;
$tx->addBlock($blockReplace, $this)->addBlock($next, $nextState);
return true;
}
}
@ -190,29 +189,16 @@ class Bed extends Transparent{
return false;
}
public function getDropsForCompatibleTool(Item $item) : array{
if($this->isHeadPart()){
return [$this->getItem()];
public function getDrops(Item $item) : array{
if($this->head){
return parent::getDrops($item);
}
return [];
}
public function getPickedItem() : Item{
return $this->getItem();
}
private function getItem() : Item{
$tile = $this->getLevel()->getTile($this);
if($tile instanceof TileBed){
return ItemFactory::get($this->getItemId(), $tile->getColor());
}
return ItemFactory::get($this->getItemId(), 14); //Red
}
public function isAffectedBySilkTouch() : bool{
return false;
public function asItem() : Item{
return ItemFactory::get($this->idInfo->getItemId(), $this->color->getMagicNumber());
}
public function getAffectedBlocks() : array{

View File

@ -23,29 +23,28 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Item;
class Bedrock extends Opaque{
class Bedrock extends Solid{
/** @var bool */
private $burnsForever = false;
protected $id = self::BEDROCK;
public function __construct(int $meta = 0){
$this->meta = $meta;
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? BlockBreakInfo::indestructible());
}
public function getName() : string{
return "Bedrock";
public function readStateFromData(int $id, int $stateMeta) : void{
$this->burnsForever = ($stateMeta & BlockLegacyMetadata::BEDROCK_FLAG_INFINIBURN) !== 0;
}
public function getHardness() : float{
return -1;
protected function writeStateToMeta() : int{
return $this->burnsForever ? BlockLegacyMetadata::BEDROCK_FLAG_INFINIBURN : 0;
}
public function getBlastResistance() : float{
return 18000000;
public function getStateBitmask() : int{
return 0b1;
}
public function isBreakable(Item $item) : bool{
return false;
public function burnsForever() : bool{
return $this->burnsForever;
}
}

View File

@ -24,35 +24,25 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\VanillaItems;
use function mt_rand;
class Beetroot extends Crops{
protected $id = self::BEETROOT_BLOCK;
public function __construct(int $meta = 0){
$this->meta = $meta;
}
public function getName() : string{
return "Beetroot Block";
}
public function getDropsForCompatibleTool(Item $item) : array{
if($this->meta >= 0x07){
if($this->age >= 7){
return [
ItemFactory::get(Item::BEETROOT),
ItemFactory::get(Item::BEETROOT_SEEDS, 0, mt_rand(0, 3))
VanillaItems::BEETROOT(),
VanillaItems::BEETROOT_SEEDS()->setCount(mt_rand(0, 3))
];
}
return [
ItemFactory::get(Item::BEETROOT_SEEDS)
VanillaItems::BEETROOT_SEEDS()
];
}
public function getPickedItem() : Item{
return ItemFactory::get(Item::BEETROOT_SEEDS);
public function getPickedItem(bool $addUserData = false) : Item{
return VanillaItems::BEETROOT_SEEDS();
}
}

View File

@ -26,91 +26,88 @@ declare(strict_types=1);
*/
namespace pocketmine\block;
use pocketmine\block\tile\Spawnable;
use pocketmine\block\tile\Tile;
use pocketmine\block\tile\TileFactory;
use pocketmine\block\utils\InvalidBlockStateException;
use pocketmine\entity\Entity;
use pocketmine\item\enchantment\Enchantment;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\level\Position;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
use pocketmine\math\RayTraceResult;
use pocketmine\math\Vector3;
use pocketmine\metadata\Metadatable;
use pocketmine\metadata\MetadataValue;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\network\mcpe\protocol\types\RuntimeBlockMapping;
use pocketmine\Player;
use pocketmine\plugin\Plugin;
use pocketmine\player\Player;
use pocketmine\world\BlockTransaction;
use pocketmine\world\Position;
use pocketmine\world\World;
use function array_merge;
use function get_class;
use function assert;
use function dechex;
use const PHP_INT_MAX;
class Block extends Position implements BlockIds, Metadatable{
class Block extends Position{
/**
* Returns a new Block instance with the specified ID, meta and position.
*
* This function redirects to {@link BlockFactory#get}.
*
* @param int $id
* @param int $meta
* @param Position|null $pos
*
* @return Block
*/
public static function get(int $id, int $meta = 0, Position $pos = null) : Block{
return BlockFactory::get($id, $meta, $pos);
}
/** @var BlockIdentifier */
protected $idInfo;
/** @var int */
protected $id;
/** @var int */
protected $meta = 0;
/** @var string|null */
/** @var string */
protected $fallbackName;
/** @var int|null */
protected $itemId;
/** @var BlockBreakInfo */
protected $breakInfo;
/** @var AxisAlignedBB */
protected $boundingBox = null;
/** @var AxisAlignedBB[]|null */
protected $collisionBoxes = null;
/**
* @param int $id The block type's ID, 0-255
* @param int $meta Meta value of the block type
* @param string|null $name English name of the block type (TODO: implement translations)
* @param int $itemId The item ID of the block type, used for block picking and dropping items.
* @param BlockIdentifier $idInfo
* @param string $name English name of the block type (TODO: implement translations)
* @param BlockBreakInfo $breakInfo
*/
public function __construct(int $id, int $meta = 0, string $name = null, int $itemId = null){
$this->id = $id;
$this->meta = $meta;
public function __construct(BlockIdentifier $idInfo, string $name, BlockBreakInfo $breakInfo){
if(($idInfo->getVariant() & $this->getStateBitmask()) !== 0){
throw new \InvalidArgumentException("Variant 0x" . dechex($idInfo->getVariant()) . " collides with state bitmask 0x" . dechex($this->getStateBitmask()));
}
$this->idInfo = $idInfo;
$this->fallbackName = $name;
$this->itemId = $itemId;
$this->breakInfo = $breakInfo;
}
public function getIdInfo() : BlockIdentifier{
return $this->idInfo;
}
/**
* @return string
*/
public function getName() : string{
return $this->fallbackName ?? "Unknown";
return $this->fallbackName;
}
/**
* @return int
*/
final public function getId() : int{
return $this->id;
public function getId() : int{
return $this->idInfo->getBlockId();
}
/**
* Returns the ID of the item form of the block.
* Used for drops for blocks (some blocks such as doors have a different item ID).
*
* @internal
* @return int
*/
public function getItemId() : int{
return $this->itemId ?? $this->getId();
public function getFullId() : int{
return ($this->getId() << 4) | $this->getMeta();
}
public function asItem() : Item{
return ItemFactory::get($this->idInfo->getItemId(), $this->idInfo->getVariant());
}
/**
@ -118,48 +115,97 @@ class Block extends Position implements BlockIds, Metadatable{
* @return int
*/
public function getRuntimeId() : int{
return RuntimeBlockMapping::toStaticRuntimeId($this->getId(), $this->getDamage());
return RuntimeBlockMapping::toStaticRuntimeId($this->getId(), $this->getMeta());
}
/**
* @return int
*/
final public function getDamage() : int{
return $this->meta;
public function getMeta() : int{
$stateMeta = $this->writeStateToMeta();
assert(($stateMeta & ~$this->getStateBitmask()) === 0);
return $this->idInfo->getVariant() | $stateMeta;
}
/**
* Returns a bitmask used to extract state bits from block metadata.
*
* @return int
*/
public function getStateBitmask() : int{
return 0;
}
protected function writeStateToMeta() : int{
return 0;
}
/**
* @param int $meta
* @param int $id
* @param int $stateMeta
*
* @throws InvalidBlockStateException
*/
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");
public function readStateFromData(int $id, int $stateMeta) : void{
//NOOP
}
/**
* Called when this block is created, set, or has a neighbouring block update, to re-detect dynamic properties which
* are not saved on the world.
*
* Clears any cached precomputed objects, such as bounding boxes. Remove any outdated precomputed things such as
* AABBs and force recalculation.
*/
public function readStateFromWorld() : void{
$this->boundingBox = null;
$this->collisionBoxes = null;
}
public function writeStateToWorld() : void{
$this->world->getChunkAtPosition($this)->setFullBlock($this->x & 0xf, $this->y, $this->z & 0xf, $this->getFullId());
$tileType = $this->idInfo->getTileClass();
$oldTile = $this->world->getTile($this);
if($oldTile !== null){
if($tileType === null or !($oldTile instanceof $tileType)){
$oldTile->close();
$oldTile = null;
}elseif($oldTile instanceof Spawnable){
$oldTile->setDirty(); //destroy old network cache
}
}
if($oldTile === null and $tileType !== null){
$this->world->addTile(TileFactory::create($tileType, $this->world, $this->asVector3()));
}
$this->meta = $meta;
}
/**
* Bitmask to use to remove superfluous information from block meta when getting its item form or name.
* This defaults to -1 (don't remove any data). Used to remove rotation data and bitflags from block drops.
* Returns whether the given block has an equivalent type to this one. This compares base legacy ID and variant.
*
* If your block should not have any meta value when it's dropped as an item, override this to return 0 in
* descendent classes.
* Note: This ignores additional IDs used to represent additional states. This means that, for example, a lit
* furnace and unlit furnace are considered the same type.
*
* @return int
* @param Block $other
*
* @return bool
*/
public function getVariantBitmask() : int{
return -1;
public function isSameType(Block $other) : bool{
return $this->idInfo->getBlockId() === $other->idInfo->getBlockId() and $this->idInfo->getVariant() === $other->idInfo->getVariant();
}
/**
* Returns the block meta, stripped of non-variant flags.
* @return int
* Returns whether the given block has the same type and properties as this block.
*
* @param Block $other
*
* @return bool
*/
public function getVariant() : int{
return $this->meta & $this->getVariantBitmask();
public function isSameState(Block $other) : bool{
return $this->isSameType($other) and $this->writeStateToMeta() === $other->writeStateToMeta();
}
/**
* AKA: Block->isPlaceable
* @return bool
@ -182,73 +228,32 @@ class Block extends Position implements BlockIds, Metadatable{
/**
* Places the Block, using block space and block target, and side. Returns if the block has been placed.
*
* @param Item $item
* @param Block $blockReplace
* @param Block $blockClicked
* @param int $face
* @param Vector3 $clickVector
* @param Player|null $player
* @param BlockTransaction $tx
* @param Item $item
* @param Block $blockReplace
* @param Block $blockClicked
* @param int $face
* @param Vector3 $clickVector
* @param Player|null $player
*
* @return 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);
}
/**
* Returns if the block can be broken with an specific Item
*
* @param Item $item
*
* @return bool
*/
public function isBreakable(Item $item) : bool{
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
$tx->addBlock($blockReplace, $this);
return true;
}
/**
* @return int
*/
public function getToolType() : int{
return BlockToolType::TYPE_NONE;
public function onPostPlace() : void{
}
/**
* 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.
* Returns an object containing information about the destruction requirements of this 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
* @return BlockBreakInfo
*/
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);
public function getBreakInfo() : BlockBreakInfo{
return $this->breakInfo;
}
/**
@ -259,35 +264,12 @@ class Block extends Position implements BlockIds, Metadatable{
*
* @return bool
*/
public function onBreak(Item $item, Player $player = null) : bool{
return $this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), true, true);
}
/**
* Returns the seconds that this block takes to be broken using an specific Item
*
* @param Item $item
*
* @return float
* @throws \InvalidArgumentException if the item efficiency is not a positive number
*/
public function getBreakTime(Item $item) : float{
$base = $this->getHardness();
if($this->isCompatibleWithTool($item)){
$base *= 1.5;
}else{
$base *= 5;
public function onBreak(Item $item, ?Player $player = null) : bool{
if(($t = $this->world->getTile($this)) !== null){
$t->onBlockDestroyed();
}
$efficiency = $item->getMiningEfficiency($this);
if($efficiency <= 0){
throw new \InvalidArgumentException(get_class($item) . " has invalid mining efficiency: expected >= 0, got $efficiency");
}
$base /= $efficiency;
return $base;
$this->getWorld()->setBlock($this, VanillaBlocks::AIR());
return true;
}
/**
@ -315,38 +297,38 @@ class Block extends Position implements BlockIds, Metadatable{
}
/**
* Called when this block is updated by the delayed blockupdate scheduler in the level.
* Called when this block is updated by the delayed blockupdate scheduler in the world.
*/
public function onScheduledUpdate() : void{
}
/**
* Do actions when activated by Item. Returns if it has done anything
* Do actions when interacted by Item. Returns if it has done anything
*
* @param Item $item
* @param int $face
* @param Vector3 $clickVector
* @param Player|null $player
*
* @return bool
*/
public function onActivate(Item $item, Player $player = null) : bool{
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
return false;
}
/**
* Returns a base value used to compute block break times.
* @return float
* Called when this block is attacked (left-clicked). This is called when a player left-clicks the block to try and
* start to break it in survival mode.
*
* @param Item $item
* @param int $face
* @param Player|null $player
*
* @return bool if an action took place, prevents starting to break the block if true.
*/
public function getHardness() : float{
return 10;
}
/**
* Returns the block's resistance to explosions. Usually 5x hardness.
* @return float
*/
public function getBlastResistance() : float{
return $this->getHardness() * 5;
public function onAttack(Item $item, int $face, ?Player $player = null) : bool{
return false;
}
/**
@ -370,7 +352,7 @@ class Block extends Position implements BlockIds, Metadatable{
* @return int 0-15
*/
public function getLightFilter() : int{
return 15;
return $this->isTransparent() ? 0 : 15;
}
/**
@ -409,10 +391,6 @@ class Block extends Position implements BlockIds, Metadatable{
return false;
}
public function canPassThrough() : bool{
return false;
}
/**
* Returns whether entities can climb up this block.
* @return bool
@ -427,16 +405,18 @@ class Block extends Position implements BlockIds, Metadatable{
}
/**
* Sets the block position to a new Position object
* @internal
*
* @param Position $v
* @param World $world
* @param int $x
* @param int $y
* @param int $z
*/
final public function position(Position $v) : void{
$this->x = (int) $v->x;
$this->y = (int) $v->y;
$this->z = (int) $v->z;
$this->level = $v->level;
$this->boundingBox = null;
final public function position(World $world, int $x, int $y, int $z) : void{
$this->x = $x;
$this->y = $y;
$this->z = $z;
$this->world = $world;
}
/**
@ -447,8 +427,8 @@ 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)){
if($this->breakInfo->isToolCompatible($item)){
if($this->isAffectedBySilkTouch() and $item->hasEnchantment(Enchantment::SILK_TOUCH())){
return $this->getSilkTouchDrops($item);
}
@ -466,9 +446,7 @@ class Block extends Position implements BlockIds, Metadatable{
* @return Item[]
*/
public function getDropsForCompatibleTool(Item $item) : array{
return [
ItemFactory::get($this->getItemId(), $this->getVariant())
];
return [$this->asItem()];
}
/**
@ -479,9 +457,7 @@ class Block extends Position implements BlockIds, Metadatable{
* @return Item[]
*/
public function getSilkTouchDrops(Item $item) : array{
return [
ItemFactory::get($this->getItemId(), $this->getVariant())
];
return [$this->asItem()];
}
/**
@ -492,7 +468,7 @@ class Block extends Position implements BlockIds, Metadatable{
* @return int
*/
public function getXpDropForTool(Item $item) : int{
if($item->hasEnchantment(Enchantment::SILK_TOUCH) or !$this->isCompatibleWithTool($item)){
if($item->hasEnchantment(Enchantment::SILK_TOUCH()) or !$this->breakInfo->isToolCompatible($item)){
return 0;
}
@ -520,10 +496,24 @@ class Block extends Position implements BlockIds, Metadatable{
/**
* Returns the item that players will equip when middle-clicking on this block.
*
* @param bool $addUserData
*
* @return Item
*/
public function getPickedItem() : Item{
return ItemFactory::get($this->getItemId(), $this->getVariant());
public function getPickedItem(bool $addUserData = false) : Item{
$item = $this->asItem();
if($addUserData){
$tile = $this->world->getTile($this);
if($tile instanceof Tile){
$nbt = $tile->getCleanedNBT();
if($nbt instanceof CompoundTag){
$item->setCustomBlockData($nbt);
$item->setLore(["+(DATA)"]);
}
}
}
return $item;
}
/**
@ -588,10 +578,10 @@ class Block extends Position implements BlockIds, Metadatable{
*/
public function getSide(int $side, int $step = 1){
if($this->isValid()){
return $this->getLevel()->getBlock(Vector3::getSide($side, $step));
return $this->getWorld()->getBlock(Vector3::getSide($side, $step));
}
return BlockFactory::get(Block::AIR, 0, Position::fromObject(Vector3::getSide($side, $step)));
throw new \InvalidStateException("Block does not have a valid world");
}
/**
@ -601,10 +591,10 @@ class Block extends Position implements BlockIds, Metadatable{
*/
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)
$this->getSide(Facing::NORTH),
$this->getSide(Facing::SOUTH),
$this->getSide(Facing::WEST),
$this->getSide(Facing::EAST)
];
}
@ -616,8 +606,8 @@ class Block extends Position implements BlockIds, Metadatable{
public function getAllSides() : array{
return array_merge(
[
$this->getSide(Vector3::SIDE_DOWN),
$this->getSide(Vector3::SIDE_UP)
$this->getSide(Facing::DOWN),
$this->getSide(Facing::UP)
],
$this->getHorizontalSides()
);
@ -637,7 +627,7 @@ class Block extends Position implements BlockIds, Metadatable{
* @return string
*/
public function __toString(){
return "Block[" . $this->getName() . "] (" . $this->getId() . ":" . $this->getDamage() . ")";
return "Block[" . $this->getName() . "] (" . $this->getId() . ":" . $this->getMeta() . ")";
}
/**
@ -658,9 +648,12 @@ class Block extends Position implements BlockIds, Metadatable{
}
/**
* Called when an entity's bounding box clips inside this block's cell. Note that the entity may not be intersecting
* with the collision box or bounding box.
*
* @param Entity $entity
*/
public function onEntityCollide(Entity $entity) : void{
public function onEntityInside(Entity $entity) : void{
}
@ -670,6 +663,9 @@ class Block extends Position implements BlockIds, Metadatable{
public function getCollisionBoxes() : array{
if($this->collisionBoxes === null){
$this->collisionBoxes = $this->recalculateCollisionBoxes();
foreach($this->collisionBoxes as $bb){
$bb->offset($this->x, $this->y, $this->z);
}
}
return $this->collisionBoxes;
@ -692,6 +688,9 @@ class Block extends Position implements BlockIds, Metadatable{
public function getBoundingBox() : ?AxisAlignedBB{
if($this->boundingBox === null){
$this->boundingBox = $this->recalculateBoundingBox();
if($this->boundingBox !== null){
$this->boundingBox->offset($this->x, $this->y, $this->z);
}
}
return $this->boundingBox;
}
@ -700,23 +699,7 @@ class Block extends Position implements BlockIds, Metadatable{
* @return AxisAlignedBB|null
*/
protected function recalculateBoundingBox() : ?AxisAlignedBB{
return new AxisAlignedBB(
$this->x,
$this->y,
$this->z,
$this->x + 1,
$this->y + 1,
$this->z + 1
);
}
/**
* 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;
return AxisAlignedBB::one();
}
/**
@ -752,31 +735,15 @@ class Block extends Position implements BlockIds, Metadatable{
return $currentHit;
}
public function setMetadata(string $metadataKey, MetadataValue $newMetadataValue){
if($this->isValid()){
$this->level->getBlockMetadata()->setMetadata($this, $metadataKey, $newMetadataValue);
}
}
public function getMetadata(string $metadataKey){
if($this->isValid()){
return $this->level->getBlockMetadata()->getMetadata($this, $metadataKey);
}
return null;
}
public function hasMetadata(string $metadataKey) : bool{
if($this->isValid()){
return $this->level->getBlockMetadata()->hasMetadata($this, $metadataKey);
}
return false;
}
public function removeMetadata(string $metadataKey, Plugin $owningPlugin){
if($this->isValid()){
$this->level->getBlockMetadata()->removeMetadata($this, $metadataKey, $owningPlugin);
/**
* @param self $self
*
* @return static
*/
public static function cast(self $self){
if(!($self instanceof static)){
throw new \TypeError("Cannot cast from " . self::class . " to " . static::class);
}
return $self;
}
}

View File

@ -0,0 +1,165 @@
<?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 function get_class;
class BlockBreakInfo{
/** @var float */
private $hardness;
/** @var float */
private $blastResistance;
/** @var int */
private $toolType;
/** @var int */
private $toolHarvestLevel;
/**
* @param float $hardness
* @param int $toolType
* @param int $toolHarvestLevel
* @param float|null $blastResistance default 5x hardness
*/
public function __construct(float $hardness, int $toolType = BlockToolType::NONE, int $toolHarvestLevel = 0, ?float $blastResistance = null){
$this->hardness = $hardness;
$this->toolType = $toolType;
$this->toolHarvestLevel = $toolHarvestLevel;
$this->blastResistance = $blastResistance ?? $hardness * 5;
}
public static function instant(int $toolType = BlockToolType::NONE, int $toolHarvestLevel = 0) : self{
return new self(0.0, $toolType, $toolHarvestLevel, 0.0);
}
public static function indestructible(float $blastResistance = 18000000.0) : self{
return new self(-1.0, BlockToolType::NONE, 0, $blastResistance);
}
/**
* Returns a base value used to compute block break times.
*
* @return float
*/
public function getHardness() : float{
return $this->hardness;
}
/**
* Returns whether the block can be broken at all.
*
* @return bool
*/
public function isBreakable() : bool{
return $this->hardness >= 0;
}
/**
* Returns whether this block can be instantly broken.
*
* @return bool
*/
public function breaksInstantly() : bool{
return $this->hardness == 0.0;
}
/**
* Returns the block's resistance to explosions. Usually 5x hardness.
*
* @return float
*/
public function getBlastResistance() : float{
return $this->blastResistance;
}
/**
* @return int
*/
public function getToolType() : int{
return $this->toolType;
}
/**
* Returns the level of tool required to harvest the 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 $this->toolHarvestLevel;
}
/**
* 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 isToolCompatible(Item $tool) : bool{
if($this->hardness < 0){
return false;
}
return $this->toolType === BlockToolType::NONE or $this->toolHarvestLevel === 0 or (
($this->toolType & $tool->getBlockToolType()) !== 0 and $tool->getBlockToolHarvestLevel() >= $this->toolHarvestLevel);
}
/**
* Returns the seconds that this block takes to be broken using an specific Item
*
* @param Item $item
*
* @return float
* @throws \InvalidArgumentException if the item efficiency is not a positive number
*/
public function getBreakTime(Item $item) : float{
$base = $this->hardness;
if($this->isToolCompatible($item)){
$base *= 1.5;
}else{
$base *= 5;
}
$efficiency = $item->getMiningEfficiency(($this->toolType & $item->getBlockToolType()) !== 0);
if($efficiency <= 0){
throw new \InvalidArgumentException(get_class($item) . " has invalid mining efficiency: expected >= 0, got $efficiency");
}
$base /= $efficiency;
return $base;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,78 @@
<?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 BlockIdentifier{
/** @var int */
private $blockId;
/** @var int */
private $variant;
/** @var int|null */
private $itemId;
/** @var string|null */
private $tileClass;
public function __construct(int $blockId, int $variant = 0, ?int $itemId = null, ?string $tileClass = null){
$this->blockId = $blockId;
$this->variant = $variant;
$this->itemId = $itemId;
$this->tileClass = $tileClass;
}
/**
* @return int
*/
public function getBlockId() : int{
return $this->blockId;
}
/**
* @return int[]
*/
public function getAllBlockIds() : array{
return [$this->blockId];
}
/**
* @return int
*/
public function getVariant() : int{
return $this->variant;
}
/**
* @return int
*/
public function getItemId() : int{
return $this->itemId ?? ($this->blockId > 255 ? 255 - $this->blockId : $this->blockId);
}
/**
* @return string|null
*/
public function getTileClass() : ?string{
return $this->tileClass;
}
}

View File

@ -21,31 +21,26 @@
declare(strict_types=1);
namespace pocketmine\event\player;
namespace pocketmine\block;
use pocketmine\event\Cancellable;
use pocketmine\Player;
class BlockIdentifierFlattened extends BlockIdentifier{
/**
* Called when a player does an animation
*/
class PlayerAnimationEvent extends PlayerEvent implements Cancellable{
/** @var int */
private $animationType;
private $secondId;
/**
* @param Player $player
* @param int $animation
*/
public function __construct(Player $player, int $animation){
$this->player = $player;
$this->animationType = $animation;
public function __construct(int $blockId, int $secondId, int $variant = 0, ?int $itemId = null, ?string $tileClass = null){
parent::__construct($blockId, $variant, $itemId, $tileClass);
$this->secondId = $secondId;
}
/**
* @return int
*/
public function getAnimationType() : int{
return $this->animationType;
public function getSecondId() : int{
return $this->secondId;
}
public function getAllBlockIds() : array{
return [$this->getBlockId(), $this->getSecondId()];
}
}

View File

@ -23,7 +23,7 @@ declare(strict_types=1);
namespace pocketmine\block;
interface BlockIds{
interface BlockLegacyIds{
public const AIR = 0;
public const STONE = 1;
@ -42,7 +42,7 @@ interface BlockIds{
public const GOLD_ORE = 14;
public const IRON_ORE = 15;
public const COAL_ORE = 16;
public const LOG = 17, WOOD = 17;
public const LOG = 17;
public const LEAVES = 18;
public const SPONGE = 19;
public const GLASS = 20;
@ -61,7 +61,7 @@ interface BlockIds{
public const PISTON = 33;
public const PISTONARMCOLLISION = 34, PISTON_ARM_COLLISION = 34;
public const WOOL = 35;
public const ELEMENT_0 = 36;
public const DANDELION = 37, YELLOW_FLOWER = 37;
public const POPPY = 38, RED_FLOWER = 38;
public const BROWN_MUSHROOM = 39;
@ -187,11 +187,11 @@ interface BlockIds{
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 LOG2 = 162;
public const ACACIA_STAIRS = 163;
public const DARK_OAK_STAIRS = 164;
public const SLIME = 165, SLIME_BLOCK = 165;
public const GLOW_STICK = 166;
public const IRON_TRAPDOOR = 167;
public const PRISMARINE = 168;
public const SEALANTERN = 169, SEA_LANTERN = 169;
@ -215,7 +215,9 @@ interface BlockIds{
public const ACACIA_FENCE_GATE = 187;
public const REPEATING_COMMAND_BLOCK = 188;
public const CHAIN_COMMAND_BLOCK = 189;
public const HARD_GLASS_PANE = 190;
public const HARD_STAINED_GLASS_PANE = 191;
public const CHEMICAL_HEAT = 192;
public const SPRUCE_DOOR_BLOCK = 193;
public const BIRCH_DOOR_BLOCK = 194;
public const JUNGLE_DOOR_BLOCK = 195;
@ -225,9 +227,9 @@ interface BlockIds{
public const FRAME_BLOCK = 199, ITEM_FRAME_BLOCK = 199;
public const CHORUS_FLOWER = 200;
public const PURPUR_BLOCK = 201;
public const COLORED_TORCH_RG = 202;
public const PURPUR_STAIRS = 203;
public const COLORED_TORCH_BP = 204;
public const UNDYED_SHULKER_BOX = 205;
public const END_BRICKS = 206;
public const FROSTED_ICE = 207;
@ -259,7 +261,8 @@ interface BlockIds{
public const BLACK_GLAZED_TERRACOTTA = 235;
public const CONCRETE = 236;
public const CONCRETEPOWDER = 237, CONCRETE_POWDER = 237;
public const CHEMISTRY_TABLE = 238;
public const UNDERWATER_TORCH = 239;
public const CHORUS_PLANT = 240;
public const STAINED_GLASS = 241;
@ -273,7 +276,222 @@ interface BlockIds{
public const MOVINGBLOCK = 250, MOVING_BLOCK = 250;
public const OBSERVER = 251;
public const STRUCTURE_BLOCK = 252;
public const HARD_GLASS = 253;
public const HARD_STAINED_GLASS = 254;
public const RESERVED6 = 255;
public const PRISMARINE_STAIRS = 257;
public const DARK_PRISMARINE_STAIRS = 258;
public const PRISMARINE_BRICKS_STAIRS = 259;
public const STRIPPED_SPRUCE_LOG = 260;
public const STRIPPED_BIRCH_LOG = 261;
public const STRIPPED_JUNGLE_LOG = 262;
public const STRIPPED_ACACIA_LOG = 263;
public const STRIPPED_DARK_OAK_LOG = 264;
public const STRIPPED_OAK_LOG = 265;
public const BLUE_ICE = 266;
public const ELEMENT_1 = 267;
public const ELEMENT_2 = 268;
public const ELEMENT_3 = 269;
public const ELEMENT_4 = 270;
public const ELEMENT_5 = 271;
public const ELEMENT_6 = 272;
public const ELEMENT_7 = 273;
public const ELEMENT_8 = 274;
public const ELEMENT_9 = 275;
public const ELEMENT_10 = 276;
public const ELEMENT_11 = 277;
public const ELEMENT_12 = 278;
public const ELEMENT_13 = 279;
public const ELEMENT_14 = 280;
public const ELEMENT_15 = 281;
public const ELEMENT_16 = 282;
public const ELEMENT_17 = 283;
public const ELEMENT_18 = 284;
public const ELEMENT_19 = 285;
public const ELEMENT_20 = 286;
public const ELEMENT_21 = 287;
public const ELEMENT_22 = 288;
public const ELEMENT_23 = 289;
public const ELEMENT_24 = 290;
public const ELEMENT_25 = 291;
public const ELEMENT_26 = 292;
public const ELEMENT_27 = 293;
public const ELEMENT_28 = 294;
public const ELEMENT_29 = 295;
public const ELEMENT_30 = 296;
public const ELEMENT_31 = 297;
public const ELEMENT_32 = 298;
public const ELEMENT_33 = 299;
public const ELEMENT_34 = 300;
public const ELEMENT_35 = 301;
public const ELEMENT_36 = 302;
public const ELEMENT_37 = 303;
public const ELEMENT_38 = 304;
public const ELEMENT_39 = 305;
public const ELEMENT_40 = 306;
public const ELEMENT_41 = 307;
public const ELEMENT_42 = 308;
public const ELEMENT_43 = 309;
public const ELEMENT_44 = 310;
public const ELEMENT_45 = 311;
public const ELEMENT_46 = 312;
public const ELEMENT_47 = 313;
public const ELEMENT_48 = 314;
public const ELEMENT_49 = 315;
public const ELEMENT_50 = 316;
public const ELEMENT_51 = 317;
public const ELEMENT_52 = 318;
public const ELEMENT_53 = 319;
public const ELEMENT_54 = 320;
public const ELEMENT_55 = 321;
public const ELEMENT_56 = 322;
public const ELEMENT_57 = 323;
public const ELEMENT_58 = 324;
public const ELEMENT_59 = 325;
public const ELEMENT_60 = 326;
public const ELEMENT_61 = 327;
public const ELEMENT_62 = 328;
public const ELEMENT_63 = 329;
public const ELEMENT_64 = 330;
public const ELEMENT_65 = 331;
public const ELEMENT_66 = 332;
public const ELEMENT_67 = 333;
public const ELEMENT_68 = 334;
public const ELEMENT_69 = 335;
public const ELEMENT_70 = 336;
public const ELEMENT_71 = 337;
public const ELEMENT_72 = 338;
public const ELEMENT_73 = 339;
public const ELEMENT_74 = 340;
public const ELEMENT_75 = 341;
public const ELEMENT_76 = 342;
public const ELEMENT_77 = 343;
public const ELEMENT_78 = 344;
public const ELEMENT_79 = 345;
public const ELEMENT_80 = 346;
public const ELEMENT_81 = 347;
public const ELEMENT_82 = 348;
public const ELEMENT_83 = 349;
public const ELEMENT_84 = 350;
public const ELEMENT_85 = 351;
public const ELEMENT_86 = 352;
public const ELEMENT_87 = 353;
public const ELEMENT_88 = 354;
public const ELEMENT_89 = 355;
public const ELEMENT_90 = 356;
public const ELEMENT_91 = 357;
public const ELEMENT_92 = 358;
public const ELEMENT_93 = 359;
public const ELEMENT_94 = 360;
public const ELEMENT_95 = 361;
public const ELEMENT_96 = 362;
public const ELEMENT_97 = 363;
public const ELEMENT_98 = 364;
public const ELEMENT_99 = 365;
public const ELEMENT_100 = 366;
public const ELEMENT_101 = 367;
public const ELEMENT_102 = 368;
public const ELEMENT_103 = 369;
public const ELEMENT_104 = 370;
public const ELEMENT_105 = 371;
public const ELEMENT_106 = 372;
public const ELEMENT_107 = 373;
public const ELEMENT_108 = 374;
public const ELEMENT_109 = 375;
public const ELEMENT_110 = 376;
public const ELEMENT_111 = 377;
public const ELEMENT_112 = 378;
public const ELEMENT_113 = 379;
public const ELEMENT_114 = 380;
public const ELEMENT_115 = 381;
public const ELEMENT_116 = 382;
public const ELEMENT_117 = 383;
public const ELEMENT_118 = 384;
public const SEAGRASS = 385;
public const CORAL = 386;
public const CORAL_BLOCK = 387;
public const CORAL_FAN = 388;
public const CORAL_FAN_DEAD = 389;
public const CORAL_FAN_HANG = 390;
public const CORAL_FAN_HANG2 = 391;
public const CORAL_FAN_HANG3 = 392;
public const KELP = 393;
public const DRIED_KELP_BLOCK = 394;
public const ACACIA_BUTTON = 395;
public const BIRCH_BUTTON = 396;
public const DARK_OAK_BUTTON = 397;
public const JUNGLE_BUTTON = 398;
public const SPRUCE_BUTTON = 399;
public const ACACIA_TRAPDOOR = 400;
public const BIRCH_TRAPDOOR = 401;
public const DARK_OAK_TRAPDOOR = 402;
public const JUNGLE_TRAPDOOR = 403;
public const SPRUCE_TRAPDOOR = 404;
public const ACACIA_PRESSURE_PLATE = 405;
public const BIRCH_PRESSURE_PLATE = 406;
public const DARK_OAK_PRESSURE_PLATE = 407;
public const JUNGLE_PRESSURE_PLATE = 408;
public const SPRUCE_PRESSURE_PLATE = 409;
public const CARVED_PUMPKIN = 410;
public const SEA_PICKLE = 411;
public const CONDUIT = 412;
public const TURTLE_EGG = 414;
public const BUBBLE_COLUMN = 415;
public const BARRIER = 416;
public const STONE_SLAB3 = 417;
public const BAMBOO = 418;
public const BAMBOO_SAPLING = 419;
public const SCAFFOLDING = 420;
public const STONE_SLAB4 = 421;
public const DOUBLE_STONE_SLAB3 = 422;
public const DOUBLE_STONE_SLAB4 = 423;
public const GRANITE_STAIRS = 424;
public const DIORITE_STAIRS = 425;
public const ANDESITE_STAIRS = 426;
public const POLISHED_GRANITE_STAIRS = 427;
public const POLISHED_DIORITE_STAIRS = 428;
public const POLISHED_ANDESITE_STAIRS = 429;
public const MOSSY_STONE_BRICK_STAIRS = 430;
public const SMOOTH_RED_SANDSTONE_STAIRS = 431;
public const SMOOTH_SANDSTONE_STAIRS = 432;
public const END_BRICK_STAIRS = 433;
public const MOSSY_COBBLESTONE_STAIRS = 434;
public const NORMAL_STONE_STAIRS = 435;
public const SPRUCE_STANDING_SIGN = 436;
public const SPRUCE_WALL_SIGN = 437;
public const SMOOTH_STONE = 438;
public const RED_NETHER_BRICK_STAIRS = 439;
public const SMOOTH_QUARTZ_STAIRS = 440;
public const BIRCH_STANDING_SIGN = 441;
public const BIRCH_WALL_SIGN = 442;
public const JUNGLE_STANDING_SIGN = 443;
public const JUNGLE_WALL_SIGN = 444;
public const ACACIA_STANDING_SIGN = 445;
public const ACACIA_WALL_SIGN = 446;
public const DARKOAK_STANDING_SIGN = 447;
public const DARKOAK_WALL_SIGN = 448;
public const LECTERN = 449;
public const GRINDSTONE = 450;
public const BLAST_FURNACE = 451;
public const STONECUTTER_BLOCK = 452;
public const SMOKER = 453;
public const LIT_SMOKER = 454;
public const CARTOGRAPHY_TABLE = 455;
public const FLETCHING_TABLE = 456;
public const SMITHING_TABLE = 457;
public const BARREL = 458;
public const LOOM = 459;
public const BELL = 461;
public const SWEET_BERRY_BUSH = 462;
public const LANTERN = 463;
public const CAMPFIRE = 464;
public const LAVA_CAULDRON = 465;
public const JIGSAW = 466;
public const WOOD = 467;
public const COMPOSTER = 468;
public const LIT_BLAST_FURNACE = 469;
}

View File

@ -0,0 +1,240 @@
<?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;
/**
* Constants for legacy metadata for various blocks.
*/
interface BlockLegacyMetadata{
public const ANVIL_NORMAL = 0;
public const ANVIL_SLIGHTLY_DAMAGED = 4;
public const ANVIL_VERY_DAMAGED = 8;
public const BED_FLAG_HEAD = 0x08;
public const BED_FLAG_OCCUPIED = 0x04;
public const BEDROCK_FLAG_INFINIBURN = 0x01;
public const BREWING_STAND_FLAG_EAST = 0x01;
public const BREWING_STAND_FLAG_SOUTHWEST = 0x02;
public const BREWING_STAND_FLAG_NORTHWEST = 0x04;
public const BUTTON_FLAG_POWERED = 0x08;
public const COLORED_TORCH_BP_BLUE = 0;
public const COLORED_TORCH_BP_PURPLE = 8;
public const COLORED_TORCH_RG_RED = 0;
public const COLORED_TORCH_RG_GREEN = 8;
public const DIRT_NORMAL = 0;
public const DIRT_COARSE = 1;
public const DOOR_FLAG_TOP = 0x08;
public const DOOR_BOTTOM_FLAG_OPEN = 0x04;
public const DOOR_TOP_FLAG_RIGHT = 0x01;
public const DOOR_TOP_FLAG_POWERED = 0x02;
public const DOUBLE_PLANT_SUNFLOWER = 0;
public const DOUBLE_PLANT_LILAC = 1;
public const DOUBLE_PLANT_TALLGRASS = 2;
public const DOUBLE_PLANT_LARGE_FERN = 3;
public const DOUBLE_PLANT_ROSE_BUSH = 4;
public const DOUBLE_PLANT_PEONY = 5;
public const DOUBLE_PLANT_FLAG_TOP = 0x08;
public const END_PORTAL_FRAME_FLAG_EYE = 0x04;
public const FENCE_GATE_FLAG_OPEN = 0x04;
public const FENCE_GATE_FLAG_IN_WALL = 0x08;
public const FLOWER_POPPY = 0;
public const FLOWER_BLUE_ORCHID = 1;
public const FLOWER_ALLIUM = 2;
public const FLOWER_AZURE_BLUET = 3;
public const FLOWER_RED_TULIP = 4;
public const FLOWER_ORANGE_TULIP = 5;
public const FLOWER_WHITE_TULIP = 6;
public const FLOWER_PINK_TULIP = 7;
public const FLOWER_OXEYE_DAISY = 8;
public const FLOWER_CORNFLOWER = 9;
public const FLOWER_LILY_OF_THE_VALLEY = 10;
public const FLOWER_POT_FLAG_OCCUPIED = 0x01;
public const HOPPER_FLAG_POWERED = 0x08;
public const INFESTED_STONE = 0;
public const INFESTED_COBBLESTONE = 1;
public const INFESTED_STONE_BRICK = 2;
public const INFESTED_STONE_BRICK_MOSSY = 3;
public const INFESTED_STONE_BRICK_CRACKED = 4;
public const INFESTED_STONE_BRICK_CHISELED = 5;
public const ITEM_FRAME_FLAG_HAS_MAP = 0x04;
public const LANTERN_FLAG_HANGING = 0x01;
public const LEAVES_FLAG_NO_DECAY = 0x04;
public const LEAVES_FLAG_CHECK_DECAY = 0x08;
public const LEVER_FLAG_POWERED = 0x08;
public const LIQUID_FLAG_FALLING = 0x08;
public const NETHER_PORTAL_AXIS_X = 1;
public const NETHER_PORTAL_AXIS_Z = 2;
public const NETHER_REACTOR_INACTIVE = 0;
public const NETHER_REACTOR_ACTIVE = 1;
public const NETHER_REACTOR_USED = 2;
public const PRESSURE_PLATE_FLAG_POWERED = 0x01;
public const PRISMARINE_NORMAL = 0;
public const PRISMARINE_DARK = 1;
public const PRISMARINE_BRICKS = 2;
public const PURPUR_NORMAL = 0;
public const PURPUR_PILLAR = 2;
public const QUARTZ_NORMAL = 0;
public const QUARTZ_CHISELED = 1;
public const QUARTZ_PILLAR = 2;
public const QUARTZ_SMOOTH = 3;
public const RAIL_STRAIGHT_NORTH_SOUTH = 0;
public const RAIL_STRAIGHT_EAST_WEST = 1;
public const RAIL_ASCENDING_EAST = 2;
public const RAIL_ASCENDING_WEST = 3;
public const RAIL_ASCENDING_NORTH = 4;
public const RAIL_ASCENDING_SOUTH = 5;
public const RAIL_CURVE_SOUTHEAST = 6;
public const RAIL_CURVE_SOUTHWEST = 7;
public const RAIL_CURVE_NORTHWEST = 8;
public const RAIL_CURVE_NORTHEAST = 9;
public const REDSTONE_COMPARATOR_FLAG_SUBTRACT = 0x04;
public const REDSTONE_COMPARATOR_FLAG_POWERED = 0x08;
public const REDSTONE_RAIL_FLAG_POWERED = 0x08;
public const SANDSTONE_NORMAL = 0;
public const SANDSTONE_CHISELED = 1;
public const SANDSTONE_CUT = 2;
public const SANDSTONE_SMOOTH = 3;
public const SAPLING_FLAG_READY = 0x08;
public const SEA_PICKLE_FLAG_NOT_UNDERWATER = 0x04;
public const SLAB_FLAG_UPPER = 0x08;
public const SPONGE_FLAG_WET = 0x01;
public const STAIR_FLAG_UPSIDE_DOWN = 0x04;
public const STONE_NORMAL = 0;
public const STONE_GRANITE = 1;
public const STONE_POLISHED_GRANITE = 2;
public const STONE_DIORITE = 3;
public const STONE_POLISHED_DIORITE = 4;
public const STONE_ANDESITE = 5;
public const STONE_POLISHED_ANDESITE = 6;
public const STONE_BRICK_NORMAL = 0;
public const STONE_BRICK_MOSSY = 1;
public const STONE_BRICK_CRACKED = 2;
public const STONE_BRICK_CHISELED = 3;
public const STONE_SLAB_SMOOTH_STONE = 0;
public const STONE_SLAB_SANDSTONE = 1;
public const STONE_SLAB_FAKE_WOODEN = 2;
public const STONE_SLAB_COBBLESTONE = 3;
public const STONE_SLAB_BRICK = 4;
public const STONE_SLAB_STONE_BRICK = 5;
public const STONE_SLAB_QUARTZ = 6;
public const STONE_SLAB_NETHER_BRICK = 7;
public const STONE_SLAB2_RED_SANDSTONE = 0;
public const STONE_SLAB2_PURPUR = 1;
public const STONE_SLAB2_PRISMARINE = 2;
public const STONE_SLAB2_DARK_PRISMARINE = 3;
public const STONE_SLAB2_PRISMARINE_BRICKS = 4;
public const STONE_SLAB2_MOSSY_COBBLESTONE = 5;
public const STONE_SLAB2_SMOOTH_SANDSTONE = 6;
public const STONE_SLAB2_RED_NETHER_BRICK = 7;
public const STONE_SLAB3_END_STONE_BRICK = 0;
public const STONE_SLAB3_SMOOTH_RED_SANDSTONE = 1;
public const STONE_SLAB3_POLISHED_ANDESITE = 2;
public const STONE_SLAB3_ANDESITE = 3;
public const STONE_SLAB3_DIORITE = 4;
public const STONE_SLAB3_POLISHED_DIORITE = 5;
public const STONE_SLAB3_GRANITE = 6;
public const STONE_SLAB3_POLISHED_GRANITE = 7;
public const STONE_SLAB4_MOSSY_STONE_BRICK = 0;
public const STONE_SLAB4_SMOOTH_QUARTZ = 1;
public const STONE_SLAB4_STONE = 2;
public const STONE_SLAB4_CUT_SANDSTONE = 3;
public const STONE_SLAB4_CUT_RED_SANDSTONE = 4;
public const TALLGRASS_NORMAL = 1;
public const TALLGRASS_FERN = 2;
public const TNT_NORMAL = 0;
public const TNT_UNDERWATER = 2;
public const TNT_FLAG_UNSTABLE = 0x01;
public const TRAPDOOR_FLAG_UPPER = 0x04;
public const TRAPDOOR_FLAG_OPEN = 0x08;
public const TRIPWIRE_FLAG_TRIGGERED = 0x01;
public const TRIPWIRE_FLAG_SUSPENDED = 0x02;
public const TRIPWIRE_FLAG_CONNECTED = 0x04;
public const TRIPWIRE_FLAG_DISARMED = 0x08;
public const TRIPWIRE_HOOK_FLAG_CONNECTED = 0x04;
public const TRIPWIRE_HOOK_FLAG_POWERED = 0x08;
public const VINE_FLAG_SOUTH = 0x01;
public const VINE_FLAG_WEST = 0x02;
public const VINE_FLAG_NORTH = 0x04;
public const VINE_FLAG_EAST = 0x08;
public const WALL_COBBLESTONE = 0;
public const WALL_MOSSY_COBBLESTONE = 1;
public const WALL_GRANITE = 2;
public const WALL_DIORITE = 3;
public const WALL_ANDESITE = 4;
public const WALL_SANDSTONE = 5;
public const WALL_BRICK = 6;
public const WALL_STONE_BRICK = 7;
public const WALL_MOSSY_STONE_BRICK = 8;
public const WALL_NETHER_BRICK = 9;
public const WALL_END_STONE_BRICK = 10;
public const WALL_PRISMARINE = 11;
public const WALL_RED_SANDSTONE = 12;
public const WALL_RED_NETHER_BRICK = 13;
}

View File

@ -29,11 +29,11 @@ namespace pocketmine\block;
*/
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;
public const NONE = 0;
public const SWORD = 1 << 0;
public const SHOVEL = 1 << 1;
public const PICKAXE = 1 << 2;
public const AXE = 1 << 3;
public const SHEARS = 1 << 4;
}

View File

@ -0,0 +1,45 @@
<?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;
class BlueIce extends Opaque{
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(2.8, BlockToolType::PICKAXE));
}
public function getLightLevel() : int{
return 1;
}
public function getFrictionFactor() : float{
return 0.99;
}
public function getDropsForCompatibleTool(Item $item) : array{
return [];
}
}

View File

@ -23,42 +23,13 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\block\utils\PillarRotationHelper;
use pocketmine\item\Item;
use pocketmine\item\TieredTool;
use pocketmine\math\Vector3;
use pocketmine\Player;
use pocketmine\block\utils\PillarRotationTrait;
use pocketmine\item\ToolTier;
class BoneBlock extends Solid{
class BoneBlock extends Opaque{
use PillarRotationTrait;
protected $id = Block::BONE_BLOCK;
public function __construct(int $meta = 0){
$this->meta = $meta;
}
public function getName() : string{
return "Bone Block";
}
public function getHardness() : float{
return 2;
}
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{
$this->meta = PillarRotationHelper::getMetaFromFace($this->meta, $face);
return $this->getLevel()->setBlock($blockReplace, $this, true, true);
}
public function getVariantBitmask() : int{
return 0x03;
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(2.0, BlockToolType::PICKAXE, ToolTier::WOOD()->getHarvestLevel()));
}
}

View File

@ -24,31 +24,17 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\VanillaItems;
class Bookshelf extends Solid{
class Bookshelf extends Opaque{
protected $id = self::BOOKSHELF;
public function __construct(int $meta = 0){
$this->meta = $meta;
}
public function getName() : string{
return "Bookshelf";
}
public function getHardness() : float{
return 1.5;
}
public function getToolType() : int{
return BlockToolType::TYPE_AXE;
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(1.5, BlockToolType::AXE));
}
public function getDropsForCompatibleTool(Item $item) : array{
return [
ItemFactory::get(Item::BOOK, 0, 3)
VanillaItems::BOOK()->setCount(3)
];
}

View File

@ -23,38 +23,53 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\block\tile\BrewingStand as TileBrewingStand;
use pocketmine\item\Item;
use pocketmine\item\TieredTool;
use pocketmine\item\ToolTier;
use pocketmine\math\Vector3;
use pocketmine\player\Player;
class BrewingStand extends Transparent{
protected $id = self::BREWING_STAND_BLOCK;
/** @var bool */
protected $eastSlot = false;
/** @var bool */
protected $northwestSlot = false;
/** @var bool */
protected $southwestSlot = false;
protected $itemId = Item::BREWING_STAND;
public function __construct(int $meta = 0){
$this->meta = $meta;
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(0.5, BlockToolType::PICKAXE, ToolTier::WOOD()->getHarvestLevel()));
}
public function getName() : string{
return "Brewing Stand";
protected function writeStateToMeta() : int{
return ($this->eastSlot ? BlockLegacyMetadata::BREWING_STAND_FLAG_EAST : 0) |
($this->southwestSlot ? BlockLegacyMetadata::BREWING_STAND_FLAG_SOUTHWEST : 0) |
($this->northwestSlot ? BlockLegacyMetadata::BREWING_STAND_FLAG_NORTHWEST : 0);
}
public function getHardness() : float{
return 0.5;
public function readStateFromData(int $id, int $stateMeta) : void{
$this->eastSlot = ($stateMeta & BlockLegacyMetadata::BREWING_STAND_FLAG_EAST) !== 0;
$this->southwestSlot = ($stateMeta & BlockLegacyMetadata::BREWING_STAND_FLAG_SOUTHWEST) !== 0;
$this->northwestSlot = ($stateMeta & BlockLegacyMetadata::BREWING_STAND_FLAG_NORTHWEST) !== 0;
}
public function getToolType() : int{
return BlockToolType::TYPE_PICKAXE;
public function getStateBitmask() : int{
return 0b111;
}
public function getToolHarvestLevel() : int{
return TieredTool::TIER_WOODEN;
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($player instanceof Player){
$stand = $this->getWorld()->getTile($this);
if($stand instanceof TileBrewingStand and $stand->canOpenWith($item->getCustomName())){
$player->setCurrentWindow($stand->getInventory());
}
}
return true;
}
public function getVariantBitmask() : int{
return 0;
public function onScheduledUpdate() : void{
//TODO
}
//TODO
}

View File

@ -25,12 +25,6 @@ namespace pocketmine\block;
class BrownMushroom extends RedMushroom{
protected $id = self::BROWN_MUSHROOM;
public function getName() : string{
return "Brown Mushroom";
}
public function getLightLevel() : int{
return 1;
}

View File

@ -28,15 +28,9 @@ use function mt_rand;
class BrownMushroomBlock extends RedMushroomBlock{
protected $id = Block::BROWN_MUSHROOM_BLOCK;
public function getName() : string{
return "Brown Mushroom Block";
}
public function getDropsForCompatibleTool(Item $item) : array{
return [
Item::get(Item::BROWN_MUSHROOM, 0, mt_rand(0, 2))
VanillaBlocks::BROWN_MUSHROOM()->asItem()->setCount(mt_rand(0, 2))
];
}
}

View File

@ -1,98 +0,0 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\TieredTool;
use pocketmine\math\Vector3;
use pocketmine\Player;
use pocketmine\tile\Furnace as TileFurnace;
use pocketmine\tile\Tile;
class BurningFurnace extends Solid{
protected $id = self::BURNING_FURNACE;
protected $itemId = self::FURNACE;
public function __construct(int $meta = 0){
$this->meta = $meta;
}
public function getName() : string{
return "Burning Furnace";
}
public function getHardness() : float{
return 3.5;
}
public function getToolType() : int{
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 $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::FURNACE, $this->getLevel(), TileFurnace::createNBT($this, $face, $item, $player));
return true;
}
public function onActivate(Item $item, Player $player = null) : bool{
if($player instanceof Player){
$furnace = $this->getLevel()->getTile($this);
if(!($furnace instanceof TileFurnace)){
$furnace = Tile::createTile(Tile::FURNACE, $this->getLevel(), TileFurnace::createNBT($this));
}
if(!$furnace->canOpenWith($item->getCustomName())){
return true;
}
$player->addWindow($furnace->getInventory());
}
return true;
}
public function getVariantBitmask() : int{
return 0;
}
}

View File

@ -23,29 +23,60 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\block\utils\BlockDataSerializer;
use pocketmine\item\Item;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\Player;
use pocketmine\player\Player;
use pocketmine\world\BlockTransaction;
use pocketmine\world\sound\RedstonePowerOffSound;
use pocketmine\world\sound\RedstonePowerOnSound;
abstract class Button extends Flowable{
public function __construct(int $meta = 0){
$this->meta = $meta;
/** @var int */
protected $facing = Facing::DOWN;
/** @var bool */
protected $powered = false;
protected function writeStateToMeta() : int{
return BlockDataSerializer::writeFacing($this->facing) | ($this->powered ? BlockLegacyMetadata::BUTTON_FLAG_POWERED : 0);
}
public function getVariantBitmask() : int{
return 0;
public function readStateFromData(int $id, int $stateMeta) : void{
//TODO: in PC it's (6 - facing) for every meta except 0 (down)
$this->facing = BlockDataSerializer::readFacing($stateMeta & 0x07);
$this->powered = ($stateMeta & BlockLegacyMetadata::BUTTON_FLAG_POWERED) !== 0;
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
public function getStateBitmask() : int{
return 0b1111;
}
public function place(BlockTransaction $tx, 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);
$this->facing = $face;
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
}
public function onActivate(Item $item, Player $player = null) : bool{
//TODO
abstract protected function getActivationTime() : int;
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if(!$this->powered){
$this->powered = true;
$this->world->setBlock($this, $this);
$this->world->scheduleDelayedBlockUpdate($this, $this->getActivationTime());
$this->world->addSound($this->add(0.5, 0.5, 0.5), new RedstonePowerOnSound());
}
return true;
}
public function onScheduledUpdate() : void{
if($this->powered){
$this->powered = false;
$this->world->setBlock($this, $this);
$this->world->addSound($this->add(0.5, 0.5, 0.5), new RedstonePowerOffSound());
}
}
}

View File

@ -23,61 +23,62 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\block\utils\BlockDataSerializer;
use pocketmine\entity\Entity;
use pocketmine\event\block\BlockGrowEvent;
use pocketmine\event\entity\EntityDamageByBlockEvent;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\item\Item;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\Player;
use pocketmine\player\Player;
use pocketmine\world\BlockTransaction;
class Cactus extends Transparent{
protected $id = self::CACTUS;
/** @var int */
protected $age = 0;
public function __construct(int $meta = 0){
$this->meta = $meta;
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(0.4));
}
public function getHardness() : float{
return 0.4;
protected function writeStateToMeta() : int{
return $this->age;
}
public function readStateFromData(int $id, int $stateMeta) : void{
$this->age = BlockDataSerializer::readBoundedInt("age", $stateMeta, 0, 15);
}
public function getStateBitmask() : int{
return 0b1111;
}
public function hasEntityCollision() : bool{
return true;
}
public function getName() : string{
return "Cactus";
}
protected function recalculateBoundingBox() : ?AxisAlignedBB{
return new AxisAlignedBB(
$this->x + 0.0625,
$this->y + 0.0625,
$this->z + 0.0625,
$this->x + 0.9375,
$this->y + 0.9375,
$this->z + 0.9375
);
static $shrinkSize = 1 / 16;
return AxisAlignedBB::one()->contract($shrinkSize, 0, $shrinkSize)->trim(Facing::UP, $shrinkSize);
}
public function onEntityCollide(Entity $entity) : void{
public function onEntityInside(Entity $entity) : void{
$ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_CONTACT, 1);
$entity->attack($ev);
}
public function onNearbyBlockChange() : void{
$down = $this->getSide(Vector3::SIDE_DOWN);
if($down->getId() !== self::SAND and $down->getId() !== self::CACTUS){
$this->getLevel()->useBreakOn($this);
$down = $this->getSide(Facing::DOWN);
if($down->getId() !== BlockLegacyIds::SAND and !$down->isSameType($this)){
$this->getWorld()->useBreakOn($this);
}else{
for($side = 2; $side <= 5; ++$side){
foreach(Facing::HORIZONTAL as $side){
$b = $this->getSide($side);
if($b->isSolid()){
$this->getLevel()->useBreakOn($this);
$this->getWorld()->useBreakOn($this);
break;
}
}
@ -89,48 +90,42 @@ class Cactus extends Transparent{
}
public function onRandomTick() : void{
if($this->getSide(Vector3::SIDE_DOWN)->getId() !== self::CACTUS){
if($this->meta === 0x0f){
if(!$this->getSide(Facing::DOWN)->isSameType($this)){
if($this->age === 15){
for($y = 1; $y < 3; ++$y){
$b = $this->getLevel()->getBlockAt($this->x, $this->y + $y, $this->z);
if($b->getId() === self::AIR){
$ev = new BlockGrowEvent($b, BlockFactory::get(Block::CACTUS));
$b = $this->getWorld()->getBlockAt($this->x, $this->y + $y, $this->z);
if($b->getId() === BlockLegacyIds::AIR){
$ev = new BlockGrowEvent($b, VanillaBlocks::CACTUS());
$ev->call();
if($ev->isCancelled()){
break;
}
$this->getLevel()->setBlock($b, $ev->getNewState(), true);
$this->getWorld()->setBlock($b, $ev->getNewState());
}else{
break;
}
}
$this->meta = 0;
$this->getLevel()->setBlock($this, $this);
$this->age = 0;
$this->getWorld()->setBlock($this, $this);
}else{
++$this->meta;
$this->getLevel()->setBlock($this, $this);
++$this->age;
$this->getWorld()->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->isSolid() and !$block1->isSolid() and !$block2->isSolid() and !$block3->isSolid()){
$this->getLevel()->setBlock($this, $this, true);
return true;
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
$down = $this->getSide(Facing::DOWN);
if($down->getId() === BlockLegacyIds::SAND or $down->isSameType($this)){
foreach(Facing::HORIZONTAL as $side){
if($this->getSide($side)->isSolid()){
return false;
}
}
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
}
return false;
}
public function getVariantBitmask() : int{
return 0;
}
}

View File

@ -23,60 +23,57 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\entity\EffectInstance;
use pocketmine\block\utils\BlockDataSerializer;
use pocketmine\entity\effect\EffectInstance;
use pocketmine\entity\Living;
use pocketmine\item\FoodSource;
use pocketmine\item\Item;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\Player;
use pocketmine\player\Player;
use pocketmine\world\BlockTransaction;
class Cake extends Transparent implements FoodSource{
protected $id = self::CAKE_BLOCK;
/** @var int */
protected $bites = 0;
protected $itemId = Item::CAKE;
public function __construct(int $meta = 0){
$this->meta = $meta;
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(0.5));
}
public function getHardness() : float{
return 0.5;
protected function writeStateToMeta() : int{
return $this->bites;
}
public function getName() : string{
return "Cake";
public function readStateFromData(int $id, int $stateMeta) : void{
$this->bites = BlockDataSerializer::readBoundedInt("bites", $stateMeta, 0, 6);
}
public function getStateBitmask() : int{
return 0b111;
}
protected function recalculateBoundingBox() : ?AxisAlignedBB{
$f = $this->getDamage() * 0.125; //1 slice width
return new AxisAlignedBB(
$this->x + 0.0625 + $f,
$this->y,
$this->z + 0.0625,
$this->x + 1 - 0.0625,
$this->y + 0.5,
$this->z + 1 - 0.0625
);
return AxisAlignedBB::one()
->contract(1 / 16, 0, 1 / 16)
->trim(Facing::UP, 0.5)
->trim(Facing::WEST, $this->bites / 8);
}
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);
return true;
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
$down = $this->getSide(Facing::DOWN);
if($down->getId() !== BlockLegacyIds::AIR){
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
}
return false;
}
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);
if($this->getSide(Facing::DOWN)->getId() === BlockLegacyIds::AIR){ //Replace with common break method
$this->getWorld()->setBlock($this, VanillaBlocks::AIR());
}
}
@ -88,7 +85,7 @@ class Cake extends Transparent implements FoodSource{
return false;
}
public function onActivate(Item $item, Player $player = null) : bool{
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($player !== null){
$player->consumeObject($this);
return true;
@ -114,9 +111,9 @@ class Cake extends Transparent implements FoodSource{
*/
public function getResidue(){
$clone = clone $this;
$clone->meta++;
if($clone->meta > 0x06){
$clone = BlockFactory::get(Block::AIR);
$clone->bites++;
if($clone->bites > 6){
$clone = VanillaBlocks::AIR();
}
return $clone;
}
@ -129,6 +126,6 @@ class Cake extends Transparent implements FoodSource{
}
public function onConsume(Living $consumer) : void{
$this->level->setBlock($this, $this->getResidue());
$this->world->setBlock($this, $this->getResidue());
}
}

View File

@ -23,58 +23,39 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\block\utils\ColorBlockMetaHelper;
use pocketmine\item\Item;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\Player;
use pocketmine\player\Player;
use pocketmine\world\BlockTransaction;
class Carpet extends Flowable{
protected $id = self::CARPET;
public function __construct(int $meta = 0){
$this->meta = $meta;
}
public function getHardness() : float{
return 0.1;
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(0.1));
}
public function isSolid() : bool{
return true;
}
public function getName() : string{
return ColorBlockMetaHelper::getColorFromMeta($this->getVariant()) . " Carpet";
}
protected function recalculateBoundingBox() : ?AxisAlignedBB{
return new AxisAlignedBB(
$this->x,
$this->y,
$this->z,
$this->x + 1,
$this->y + 0.0625,
$this->z + 1
);
return AxisAlignedBB::one()->trim(Facing::UP, 15 / 16);
}
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);
return true;
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
$down = $this->getSide(Facing::DOWN);
if($down->getId() !== BlockLegacyIds::AIR){
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
}
return false;
}
public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_DOWN)->getId() === self::AIR){
$this->getLevel()->useBreakOn($this);
if($this->getSide(Facing::DOWN)->getId() === BlockLegacyIds::AIR){
$this->getWorld()->useBreakOn($this);
}
}

View File

@ -24,28 +24,18 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\VanillaItems;
use function mt_rand;
class Carrot extends Crops{
protected $id = self::CARROT_BLOCK;
public function __construct(int $meta = 0){
$this->meta = $meta;
}
public function getName() : string{
return "Carrot Block";
}
public function getDropsForCompatibleTool(Item $item) : array{
return [
ItemFactory::get(Item::CARROT, 0, $this->meta >= 0x07 ? mt_rand(1, 4) : 1)
VanillaItems::CARROT()->setCount($this->age >= 7 ? mt_rand(1, 4) : 1)
];
}
public function getPickedItem() : Item{
return ItemFactory::get(Item::CARROT);
public function getPickedItem(bool $addUserData = false) : Item{
return VanillaItems::CARROT();
}
}

View File

@ -0,0 +1,56 @@
<?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\BlockDataSerializer;
use pocketmine\item\Item;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\player\Player;
use pocketmine\world\BlockTransaction;
class CarvedPumpkin extends Opaque{
/** @var int */
protected $facing = Facing::NORTH;
public function readStateFromData(int $id, int $stateMeta) : void{
$this->facing = BlockDataSerializer::readLegacyHorizontalFacing($stateMeta & 0x03);
}
protected function writeStateToMeta() : int{
return BlockDataSerializer::writeLegacyHorizontalFacing($this->facing);
}
public function getStateBitmask() : int{
return 0b11;
}
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($player !== null){
$this->facing = Facing::opposite($player->getHorizontalFacing());
}
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
}
}

View File

@ -23,112 +23,89 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\block\tile\Chest as TileChest;
use pocketmine\block\utils\BlockDataSerializer;
use pocketmine\item\Item;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\Player;
use pocketmine\tile\Chest as TileChest;
use pocketmine\tile\Tile;
use pocketmine\player\Player;
use pocketmine\world\BlockTransaction;
class Chest extends Transparent{
protected $id = self::CHEST;
/** @var int */
protected $facing = Facing::NORTH;
public function __construct(int $meta = 0){
$this->meta = $meta;
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(2.5, BlockToolType::AXE));
}
public function getHardness() : float{
return 2.5;
protected function writeStateToMeta() : int{
return BlockDataSerializer::writeHorizontalFacing($this->facing);
}
public function getName() : string{
return "Chest";
public function readStateFromData(int $id, int $stateMeta) : void{
$this->facing = BlockDataSerializer::readHorizontalFacing($stateMeta);
}
public function getToolType() : int{
return BlockToolType::TYPE_AXE;
public function getStateBitmask() : int{
return 0b111;
}
protected function recalculateBoundingBox() : ?AxisAlignedBB{
//these are slightly bigger than in PC
return new AxisAlignedBB(
$this->x + 0.025,
$this->y,
$this->z + 0.025,
$this->x + 0.975,
$this->y + 0.95,
$this->z + 0.975
);
return AxisAlignedBB::one()->contract(0.025, 0, 0.025)->trim(Facing::UP, 0.05);
}
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
];
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($player !== null){
$this->facing = Facing::opposite($player->getHorizontalFacing());
}
$chest = null;
$this->meta = $faces[$player instanceof Player ? $player->getDirection() : 0];
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
}
for($side = 2; $side <= 5; ++$side){
if(($this->meta === 4 or $this->meta === 5) and ($side === 4 or $side === 5)){
continue;
}elseif(($this->meta === 3 or $this->meta === 2) and ($side === 2 or $side === 3)){
continue;
}
$c = $this->getSide($side);
if($c->getId() === $this->id and $c->getDamage() === $this->meta){
$tile = $this->getLevel()->getTile($c);
if($tile instanceof TileChest and !$tile->isPaired()){
$chest = $tile;
break;
public function onPostPlace() : void{
$tile = $this->world->getTile($this);
if($tile instanceof TileChest){
foreach([
Facing::rotateY($this->facing, true),
Facing::rotateY($this->facing, false)
] as $side){
$c = $this->getSide($side);
if($c instanceof Chest and $c->isSameType($this) and $c->facing === $this->facing){
$pair = $this->world->getTile($c);
if($pair instanceof TileChest and !$pair->isPaired()){
$pair->pairWith($tile);
$tile->pairWith($pair);
break;
}
}
}
}
$this->getLevel()->setBlock($blockReplace, $this, true, true);
$tile = Tile::createTile(Tile::CHEST, $this->getLevel(), TileChest::createNBT($this, $face, $item, $player));
if($chest instanceof TileChest and $tile instanceof TileChest){
$chest->pairWith($tile);
$tile->pairWith($chest);
}
return true;
}
public function onActivate(Item $item, Player $player = null) : bool{
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($player instanceof Player){
$t = $this->getLevel()->getTile($this);
$chest = null;
if($t instanceof TileChest){
$chest = $t;
}else{
$chest = Tile::createTile(Tile::CHEST, $this->getLevel(), TileChest::createNBT($this));
}
$chest = $this->getWorld()->getTile($this);
if($chest instanceof TileChest){
if(
!$this->getSide(Facing::UP)->isTransparent() or
($chest->isPaired() and !$chest->getPair()->getBlock()->getSide(Facing::UP)->isTransparent()) or
!$chest->canOpenWith($item->getCustomName())
){
return true;
}
if(
!$this->getSide(Vector3::SIDE_UP)->isTransparent() or
($chest->isPaired() and !$chest->getPair()->getBlock()->getSide(Vector3::SIDE_UP)->isTransparent()) or
!$chest->canOpenWith($item->getCustomName())
){
return true;
$player->setCurrentWindow($chest->getInventory());
}
$player->addWindow($chest->getInventory());
}
return true;
}
public function getVariantBitmask() : int{
return 0;
}
public function getFuelTime() : int{
return 300;
}

View File

@ -24,31 +24,17 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\VanillaItems;
class Clay extends Solid{
class Clay extends Opaque{
protected $id = self::CLAY_BLOCK;
public function __construct(int $meta = 0){
$this->meta = $meta;
}
public function getHardness() : float{
return 0.6;
}
public function getToolType() : int{
return BlockToolType::TYPE_SHOVEL;
}
public function getName() : string{
return "Clay Block";
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(0.6, BlockToolType::SHOVEL));
}
public function getDropsForCompatibleTool(Item $item) : array{
return [
ItemFactory::get(Item::CLAY_BALL, 0, 4)
VanillaItems::CLAY()->setCount(4)
];
}
}

View File

@ -23,30 +23,12 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\TieredTool;
use pocketmine\item\ToolTier;
class Coal extends Solid{
class Coal extends Opaque{
protected $id = self::COAL_BLOCK;
public function __construct(int $meta = 0){
$this->meta = $meta;
}
public function getHardness() : float{
return 5;
}
public function getToolType() : int{
return BlockToolType::TYPE_PICKAXE;
}
public function getToolHarvestLevel() : int{
return TieredTool::TIER_WOODEN;
}
public function getName() : string{
return "Coal Block";
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(5.0, BlockToolType::PICKAXE, ToolTier::WOOD()->getHarvestLevel(), 30.0));
}
public function getFuelTime() : int{

View File

@ -24,37 +24,19 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\TieredTool;
use pocketmine\item\ToolTier;
use pocketmine\item\VanillaItems;
use function mt_rand;
class CoalOre extends Solid{
class CoalOre extends Opaque{
protected $id = self::COAL_ORE;
public function __construct(int $meta = 0){
$this->meta = $meta;
}
public function getHardness() : float{
return 3;
}
public function getToolType() : int{
return BlockToolType::TYPE_PICKAXE;
}
public function getToolHarvestLevel() : int{
return TieredTool::TIER_WOODEN;
}
public function getName() : string{
return "Coal Ore";
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(3.0, BlockToolType::PICKAXE, ToolTier::WOOD()->getHarvestLevel()));
}
public function getDropsForCompatibleTool(Item $item) : array{
return [
ItemFactory::get(Item::COAL)
VanillaItems::COAL()
];
}

View File

@ -23,29 +23,21 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Hoe;
use pocketmine\item\Item;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\player\Player;
class InvisibleBedrock extends Transparent{
class CoarseDirt extends Dirt{
protected $id = self::INVISIBLE_BEDROCK;
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($face === Facing::UP and $item instanceof Hoe){
$item->applyDamage(1);
$this->getWorld()->setBlock($this, VanillaBlocks::DIRT());
return true;
}
public function __construct(){
}
public function getName() : string{
return "Invisible Bedrock";
}
public function getHardness() : float{
return -1;
}
public function getBlastResistance() : float{
return 18000000;
}
public function isBreakable(Item $item) : bool{
return false;
}
}

View File

@ -1,117 +0,0 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\TieredTool;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Vector3;
class CobblestoneWall extends Transparent{
public const NONE_MOSSY_WALL = 0;
public const MOSSY_WALL = 1;
public const GRANITE_WALL = 2;
public const DIORITE_WALL = 3;
public const ANDESITE_WALL = 4;
public const SANDSTONE_WALL = 5;
public const BRICK_WALL = 6;
public const STONE_BRICK_WALL = 7;
public const MOSSY_STONE_BRICK_WALL = 8;
public const NETHER_BRICK_WALL = 9;
public const END_STONE_BRICK_WALL = 10;
public const PRISMARINE_WALL = 11;
public const RED_SANDSTONE_WALL = 12;
public const RED_NETHER_BRICK_WALL = 13;
protected $id = self::COBBLESTONE_WALL;
public function __construct(int $meta = 0){
$this->meta = $meta;
}
public function getToolType() : int{
return BlockToolType::TYPE_PICKAXE;
}
public function getToolHarvestLevel() : int{
return TieredTool::TIER_WOODEN;
}
public function getHardness() : float{
return 2;
}
public function getName() : string{
static $names = [
self::NONE_MOSSY_WALL => "Cobblestone",
self::MOSSY_WALL => "Mossy Cobblestone",
self::GRANITE_WALL => "Granite",
self::DIORITE_WALL => "Diorite",
self::ANDESITE_WALL => "Andesite",
self::SANDSTONE_WALL => "Sandstone",
self::BRICK_WALL => "Brick",
self::STONE_BRICK_WALL => "Stone Brick",
self::MOSSY_STONE_BRICK_WALL => "Mossy Stone Brick",
self::NETHER_BRICK_WALL => "Nether Brick",
self::END_STONE_BRICK_WALL => "End Stone Brick",
self::PRISMARINE_WALL => "Prismarine",
self::RED_SANDSTONE_WALL => "Red Sandstone",
self::RED_NETHER_BRICK_WALL => "Red Nether Brick"
];
return ($names[$this->getVariant()] ?? "Unknown") . " Wall";
}
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));
$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 + ($west ? 0 : $inset),
$this->y,
$this->z + ($north ? 0 : $inset),
$this->x + 1 - ($east ? 0 : $inset),
$this->y + 1.5,
$this->z + 1 - ($south ? 0 : $inset)
);
}
public function canConnect(Block $block){
return $block instanceof static or $block instanceof FenceGate or ($block->isSolid() and !$block->isTransparent());
}
}

View File

@ -25,43 +25,25 @@ namespace pocketmine\block;
use pocketmine\entity\Entity;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\VanillaItems;
class Cobweb extends Flowable{
protected $id = self::COBWEB;
public function __construct(int $meta = 0){
$this->meta = $meta;
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(4.0, BlockToolType::SWORD | BlockToolType::SHEARS, 1));
}
public function hasEntityCollision() : bool{
return true;
}
public function getName() : string{
return "Cobweb";
}
public function getHardness() : float{
return 4;
}
public function getToolType() : int{
return BlockToolType::TYPE_SWORD | BlockToolType::TYPE_SHEARS;
}
public function getToolHarvestLevel() : int{
return 1;
}
public function onEntityCollide(Entity $entity) : void{
public function onEntityInside(Entity $entity) : void{
$entity->resetFallDistance();
}
public function getDropsForCompatibleTool(Item $item) : array{
return [
ItemFactory::get(Item::STRING)
VanillaItems::STRING()
];
}

View File

@ -23,29 +23,102 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\block\utils\BlockDataSerializer;
use pocketmine\block\utils\TreeType;
use pocketmine\item\Fertilizer;
use pocketmine\item\Item;
use pocketmine\item\VanillaItems;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\player\Player;
use pocketmine\world\BlockTransaction;
use function mt_rand;
class CocoaBlock extends Transparent{
protected $id = self::COCOA_BLOCK;
/** @var int */
protected $facing = Facing::NORTH;
/** @var int */
protected $age = 0;
public function __construct(int $meta = 0){
$this->meta = $meta;
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(0.2, BlockToolType::AXE, 0, 15.0));
}
public function getName() : string{
return "Cocoa Block";
protected function writeStateToMeta() : int{
return BlockDataSerializer::writeLegacyHorizontalFacing(Facing::opposite($this->facing)) | ($this->age << 2);
}
public function getHardness() : float{
return 0.2;
public function readStateFromData(int $id, int $stateMeta) : void{
$this->facing = Facing::opposite(BlockDataSerializer::readLegacyHorizontalFacing($stateMeta & 0x03));
$this->age = BlockDataSerializer::readBoundedInt("age", $stateMeta >> 2, 0, 2);
}
public function getToolType() : int{
return BlockToolType::TYPE_AXE;
public function getStateBitmask() : int{
return 0b1111;
}
//TODO
public function isAffectedBySilkTouch() : bool{
return false;
}
protected function recalculateBoundingBox() : ?AxisAlignedBB{
return AxisAlignedBB::one()
->squash(Facing::axis(Facing::rotateY($this->facing, true)), (6 - $this->age) / 16) //sides
->trim(Facing::DOWN, (7 - $this->age * 2) / 16)
->trim(Facing::UP, 0.25)
->trim(Facing::opposite($this->facing), 1 / 16) //gap between log and pod
->trim($this->facing, (11 - $this->age * 2) / 16); //outward face
}
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if(Facing::axis($face) !== Facing::AXIS_Y and $blockClicked instanceof Wood and $blockClicked->getTreeType()->equals(TreeType::JUNGLE())){
$this->facing = $face;
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
}
return false;
}
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($this->age < 2 and $item instanceof Fertilizer){
$this->age++;
$this->world->setBlock($this, $this);
$item->pop();
return true;
}
return false;
}
public function onNearbyBlockChange() : void{
$side = $this->getSide(Facing::opposite($this->facing));
if(!($side instanceof Wood) or !$side->getTreeType()->equals(TreeType::JUNGLE())){
$this->world->useBreakOn($this);
}
}
public function ticksRandomly() : bool{
return true;
}
public function onRandomTick() : void{
if($this->age < 2 and mt_rand(1, 5) === 1){
$this->age++;
$this->world->setBlock($this, $this);
}
}
public function getDropsForCompatibleTool(Item $item) : array{
return [
VanillaItems::COCOA_BEANS()->setCount($this->age === 2 ? mt_rand(2, 3) : 1)
];
}
public function getPickedItem(bool $addUserData = false) : Item{
return VanillaItems::COCOA_BEANS();
}
}

View File

@ -23,30 +23,11 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\block\utils\ColorBlockMetaHelper;
use pocketmine\item\TieredTool;
use pocketmine\item\ToolTier;
class Concrete extends Solid{
class Concrete extends Opaque{
protected $id = Block::CONCRETE;
public function __construct(int $meta = 0){
$this->meta = $meta;
}
public function getName() : string{
return ColorBlockMetaHelper::getColorFromMeta($this->getVariant()) . " Concrete";
}
public function getHardness() : float{
return 1.8;
}
public function getToolType() : int{
return BlockToolType::TYPE_PICKAXE;
}
public function getToolHarvestLevel() : int{
return TieredTool::TIER_WOODEN;
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(1.8, BlockToolType::PICKAXE, ToolTier::WOOD()->getHarvestLevel()));
}
}

View File

@ -23,33 +23,24 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\block\utils\ColorBlockMetaHelper;
use pocketmine\block\utils\Fallable;
use pocketmine\block\utils\FallableTrait;
use pocketmine\math\Facing;
class ConcretePowder extends Fallable{
protected $id = self::CONCRETE_POWDER;
public function __construct(int $meta = 0){
$this->meta = $meta;
class ConcretePowder extends Opaque implements Fallable{
use FallableTrait {
onNearbyBlockChange as protected startFalling;
}
public function getName() : string{
return ColorBlockMetaHelper::getColorFromMeta($this->getVariant()) . " Concrete Powder";
}
public function getHardness() : float{
return 0.5;
}
public function getToolType() : int{
return BlockToolType::TYPE_SHOVEL;
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(0.5, BlockToolType::SHOVEL));
}
public function onNearbyBlockChange() : void{
if(($block = $this->checkAdjacentWater()) !== null){
$this->level->setBlock($this, $block);
$this->world->setBlock($this, $block);
}else{
parent::onNearbyBlockChange();
$this->startFalling();
}
}
@ -64,9 +55,12 @@ class ConcretePowder extends Fallable{
* @return null|Block
*/
private function checkAdjacentWater() : ?Block{
for($i = 1; $i < 6; ++$i){ //Do not check underneath
foreach(Facing::ALL as $i){
if($i === Facing::DOWN){
continue;
}
if($this->getSide($i) instanceof Water){
return BlockFactory::get(Block::CONCRETE, $this->meta);
return BlockFactory::get(BlockLegacyIds::CONCRETE, $this->idInfo->getVariant());
}
}

View File

@ -23,31 +23,18 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\inventory\CraftingGrid;
use pocketmine\crafting\CraftingGrid;
use pocketmine\item\Item;
use pocketmine\Player;
use pocketmine\math\Vector3;
use pocketmine\player\Player;
class CraftingTable extends Solid{
class CraftingTable extends Opaque{
protected $id = self::CRAFTING_TABLE;
public function __construct(int $meta = 0){
$this->meta = $meta;
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(2.5, BlockToolType::AXE));
}
public function getHardness() : float{
return 2.5;
}
public function getName() : string{
return "Crafting Table";
}
public function getToolType() : int{
return BlockToolType::TYPE_AXE;
}
public function onActivate(Item $item, Player $player = null) : bool{
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($player instanceof Player){
$player->setCraftingGrid(new CraftingGrid($player, CraftingGrid::SIZE_BIG));
}

View File

@ -23,40 +23,60 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\block\utils\BlockDataSerializer;
use pocketmine\event\block\BlockGrowEvent;
use pocketmine\item\Fertilizer;
use pocketmine\item\Item;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\Player;
use pocketmine\player\Player;
use pocketmine\world\BlockTransaction;
use function mt_rand;
abstract class Crops extends Flowable{
/** @var int */
protected $age = 0;
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);
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? BlockBreakInfo::instant());
}
return true;
protected function writeStateToMeta() : int{
return $this->age;
}
public function readStateFromData(int $id, int $stateMeta) : void{
$this->age = BlockDataSerializer::readBoundedInt("age", $stateMeta, 0, 7);
}
public function getStateBitmask() : int{
return 0b111;
}
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($blockReplace->getSide(Facing::DOWN)->getId() === BlockLegacyIds::FARMLAND){
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
}
return false;
}
public function onActivate(Item $item, Player $player = null) : bool{
if($this->meta < 7 and $item->getId() === Item::DYE and $item->getDamage() === 0x0F){ //Bonemeal
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($this->age < 7 and $item instanceof Fertilizer){
$block = clone $this;
$block->meta += mt_rand(2, 5);
if($block->meta > 7){
$block->meta = 7;
$block->age += mt_rand(2, 5);
if($block->age > 7){
$block->age = 7;
}
$ev = new BlockGrowEvent($this, $block);
$ev->call();
if(!$ev->isCancelled()){
$this->getLevel()->setBlock($this, $ev->getNewState(), true, true);
$this->getWorld()->setBlock($this, $ev->getNewState());
}
$item->count--;
$item->pop();
return true;
}
@ -65,8 +85,8 @@ abstract class Crops extends Flowable{
}
public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_DOWN)->getId() !== Block::FARMLAND){
$this->getLevel()->useBreakOn($this);
if($this->getSide(Facing::DOWN)->getId() !== BlockLegacyIds::FARMLAND){
$this->getWorld()->useBreakOn($this);
}
}
@ -75,15 +95,13 @@ abstract class Crops extends Flowable{
}
public function onRandomTick() : void{
if(mt_rand(0, 2) === 1){
if($this->meta < 0x07){
$block = clone $this;
++$block->meta;
$ev = new BlockGrowEvent($this, $block);
$ev->call();
if(!$ev->isCancelled()){
$this->getLevel()->setBlock($this, $ev->getNewState(), true, true);
}
if($this->age < 7 and mt_rand(0, 2) === 1){
$block = clone $this;
++$block->age;
$ev = new BlockGrowEvent($this, $block);
$ev->call();
if(!$ev->isCancelled()){
$this->getWorld()->setBlock($this, $ev->getNewState());
}
}
}

View File

@ -1,67 +0,0 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\math\Vector3;
use pocketmine\Player;
class Dandelion extends Flowable{
protected $id = self::DANDELION;
public function __construct(int $meta = 0){
$this->meta = $meta;
}
public function getName() : string{
return "Dandelion";
}
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);
return true;
}
return false;
}
public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_DOWN)->isTransparent()){
$this->getLevel()->useBreakOn($this);
}
}
public function getFlameEncouragement() : int{
return 60;
}
public function getFlammability() : int{
return 100;
}
}

View File

@ -23,28 +23,91 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\block\utils\BlockDataSerializer;
use pocketmine\item\Item;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\player\Player;
use function cos;
use function max;
use function round;
use const M_PI;
class DaylightSensor extends Transparent{
/** @var BlockIdentifierFlattened */
protected $idInfo;
protected $id = self::DAYLIGHT_SENSOR;
/** @var int */
protected $power = 0;
public function __construct(int $meta = 0){
$this->meta = $meta;
/** @var bool */
protected $inverted = false;
public function __construct(BlockIdentifierFlattened $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(0.2, BlockToolType::AXE));
}
public function getName() : string{
return "Daylight Sensor";
public function getId() : int{
return $this->inverted ? $this->idInfo->getSecondId() : parent::getId();
}
public function getHardness() : float{
return 0.2;
protected function writeStateToMeta() : int{
return $this->power;
}
public function readStateFromData(int $id, int $stateMeta) : void{
$this->power = BlockDataSerializer::readBoundedInt("power", $stateMeta, 0, 15);
$this->inverted = $id === $this->idInfo->getSecondId();
}
public function getStateBitmask() : int{
return 0b1111;
}
public function isInverted() : bool{
return $this->inverted;
}
/**
* @param bool $inverted
*
* @return $this
*/
public function setInverted(bool $inverted = true) : self{
$this->inverted = $inverted;
return $this;
}
public function getFuelTime() : int{
return 300;
}
public function getToolType() : int{
return BlockToolType::TYPE_AXE;
protected function recalculateBoundingBox() : ?AxisAlignedBB{
return AxisAlignedBB::one()->trim(Facing::UP, 0.5);
}
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
$this->inverted = !$this->inverted;
$this->power = $this->recalculatePower();
$this->world->setBlock($this, $this);
return true;
}
public function onScheduledUpdate() : void{
$this->power = $this->recalculatePower();
$this->world->setBlock($this, $this);
$this->world->scheduleDelayedBlockUpdate($this, 20);
}
private function recalculatePower() : int{
$lightLevel = $this->world->getRealBlockSkyLightAt($this->x, $this->y, $this->z);
if($this->inverted){
return 15 - $lightLevel;
}
$sunAngle = $this->world->getSunAnglePercentage();
return max(0, (int) round(15 * cos(($sunAngle + ((($sunAngle < 0.5 ? 0 : 1) - $sunAngle) / 5)) * 2 * M_PI)));
}
//TODO

View File

@ -24,49 +24,37 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\VanillaItems;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\Player;
use pocketmine\player\Player;
use pocketmine\world\BlockTransaction;
use function mt_rand;
class DeadBush extends Flowable{
protected $id = self::DEAD_BUSH;
public function __construct(int $meta = 0){
$this->meta = $meta;
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? BlockBreakInfo::instant(BlockToolType::SHEARS, 1));
}
public function getName() : string{
return "Dead Bush";
}
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);
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if(!$this->getSide(Facing::DOWN)->isTransparent()){
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
}
return false;
}
public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_DOWN)->isTransparent()){
$this->getLevel()->useBreakOn($this);
if($this->getSide(Facing::DOWN)->isTransparent()){
$this->getWorld()->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)){
if(!$this->breakInfo->isToolCompatible($item)){
return [
ItemFactory::get(Item::STICK, 0, mt_rand(0, 2))
VanillaItems::STICK()->setCount(mt_rand(0, 2))
];
}

View File

@ -25,11 +25,5 @@ namespace pocketmine\block;
class DetectorRail extends RedstoneRail{
protected $id = self::DETECTOR_RAIL;
public function getName() : string{
return "Detector Rail";
}
//TODO
}

View File

@ -24,37 +24,19 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\TieredTool;
use pocketmine\item\ToolTier;
use pocketmine\item\VanillaItems;
use function mt_rand;
class DiamondOre extends Solid{
class DiamondOre extends Opaque{
protected $id = self::DIAMOND_ORE;
public function __construct(int $meta = 0){
$this->meta = $meta;
}
public function getHardness() : float{
return 3;
}
public function getName() : string{
return "Diamond Ore";
}
public function getToolType() : int{
return BlockToolType::TYPE_PICKAXE;
}
public function getToolHarvestLevel() : int{
return TieredTool::TIER_IRON;
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(3.0, BlockToolType::PICKAXE, ToolTier::IRON()->getHarvestLevel()));
}
public function getDropsForCompatibleTool(Item $item) : array{
return [
ItemFactory::get(Item::DIAMOND)
VanillaItems::DIAMOND()
];
}

View File

@ -25,39 +25,20 @@ namespace pocketmine\block;
use pocketmine\item\Hoe;
use pocketmine\item\Item;
use pocketmine\Player;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\player\Player;
class Dirt extends Solid{
class Dirt extends Opaque{
protected $id = self::DIRT;
public function __construct(int $meta = 0){
$this->meta = $meta;
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(0.5, BlockToolType::SHOVEL));
}
public function getHardness() : float{
return 0.5;
}
public function getToolType() : int{
return BlockToolType::TYPE_SHOVEL;
}
public function getName() : string{
if($this->meta === 1){
return "Coarse Dirt";
}
return "Dirt";
}
public function onActivate(Item $item, Player $player = null) : bool{
if($item instanceof Hoe){
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($face === Facing::UP and $item instanceof Hoe){
$item->applyDamage(1);
if($this->meta === 1){
$this->getLevel()->setBlock($this, BlockFactory::get(Block::DIRT), true);
}else{
$this->getLevel()->setBlock($this, BlockFactory::get(Block::FARMLAND), true);
}
$this->getWorld()->setBlock($this, VanillaBlocks::FARMLAND());
return true;
}

View File

@ -23,271 +23,144 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\block\utils\BlockDataSerializer;
use pocketmine\item\Item;
use pocketmine\level\sound\DoorSound;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\Player;
use pocketmine\player\Player;
use pocketmine\world\BlockTransaction;
use pocketmine\world\sound\DoorSound;
abstract class Door extends Transparent{
class Door extends Transparent{
/** @var int */
protected $facing = Facing::NORTH;
/** @var bool */
protected $top = false;
/** @var bool */
protected $hingeRight = false;
/** @var bool */
protected $open = false;
/** @var bool */
protected $powered = false;
protected function writeStateToMeta() : int{
if($this->top){
return BlockLegacyMetadata::DOOR_FLAG_TOP |
($this->hingeRight ? BlockLegacyMetadata::DOOR_TOP_FLAG_RIGHT : 0) |
($this->powered ? BlockLegacyMetadata::DOOR_TOP_FLAG_POWERED : 0);
}
return BlockDataSerializer::writeLegacyHorizontalFacing(Facing::rotateY($this->facing, true)) | ($this->open ? BlockLegacyMetadata::DOOR_BOTTOM_FLAG_OPEN : 0);
}
public function readStateFromData(int $id, int $stateMeta) : void{
$this->top = $stateMeta & BlockLegacyMetadata::DOOR_FLAG_TOP;
if($this->top){
$this->hingeRight = ($stateMeta & BlockLegacyMetadata::DOOR_TOP_FLAG_RIGHT) !== 0;
$this->powered = ($stateMeta & BlockLegacyMetadata::DOOR_TOP_FLAG_POWERED) !== 0;
}else{
$this->facing = Facing::rotateY(BlockDataSerializer::readLegacyHorizontalFacing($stateMeta & 0x03), false);
$this->open = ($stateMeta & BlockLegacyMetadata::DOOR_BOTTOM_FLAG_OPEN) !== 0;
}
}
public function getStateBitmask() : int{
return 0b1111;
}
public function readStateFromWorld() : void{
parent::readStateFromWorld();
//copy door properties from other half
$other = $this->getSide($this->top ? Facing::DOWN : Facing::UP);
if($other instanceof Door and $other->isSameType($this)){
if($this->top){
$this->facing = $other->facing;
$this->open = $other->open;
}else{
$this->hingeRight = $other->hingeRight;
$this->powered = $other->powered;
}
}
}
public function isSolid() : bool{
return false;
}
private function getFullDamage(){
$damage = $this->getDamage();
$isUp = ($damage & 0x08) > 0;
if($isUp){
$down = $this->getSide(Vector3::SIDE_DOWN)->getDamage();
$up = $damage;
}else{
$down = $damage;
$up = $this->getSide(Vector3::SIDE_UP)->getDamage();
}
$isRight = ($up & 0x01) > 0;
return $down & 0x07 | ($isUp ? 8 : 0) | ($isRight ? 0x10 : 0);
}
protected function recalculateBoundingBox() : ?AxisAlignedBB{
$f = 0.1875;
$damage = $this->getFullDamage();
$bb = new AxisAlignedBB(
$this->x,
$this->y,
$this->z,
$this->x + 1,
$this->y + 2,
$this->z + 1
);
$j = $damage & 0x03;
$isOpen = (($damage & 0x04) > 0);
$isRight = (($damage & 0x10) > 0);
if($j === 0){
if($isOpen){
if(!$isRight){
$bb->setBounds(
$this->x,
$this->y,
$this->z,
$this->x + 1,
$this->y + 1,
$this->z + $f
);
}else{
$bb->setBounds(
$this->x,
$this->y,
$this->z + 1 - $f,
$this->x + 1,
$this->y + 1,
$this->z + 1
);
}
}else{
$bb->setBounds(
$this->x,
$this->y,
$this->z,
$this->x + $f,
$this->y + 1,
$this->z + 1
);
}
}elseif($j === 1){
if($isOpen){
if(!$isRight){
$bb->setBounds(
$this->x + 1 - $f,
$this->y,
$this->z,
$this->x + 1,
$this->y + 1,
$this->z + 1
);
}else{
$bb->setBounds(
$this->x,
$this->y,
$this->z,
$this->x + $f,
$this->y + 1,
$this->z + 1
);
}
}else{
$bb->setBounds(
$this->x,
$this->y,
$this->z,
$this->x + 1,
$this->y + 1,
$this->z + $f
);
}
}elseif($j === 2){
if($isOpen){
if(!$isRight){
$bb->setBounds(
$this->x,
$this->y,
$this->z + 1 - $f,
$this->x + 1,
$this->y + 1,
$this->z + 1
);
}else{
$bb->setBounds(
$this->x,
$this->y,
$this->z,
$this->x + 1,
$this->y + 1,
$this->z + $f
);
}
}else{
$bb->setBounds(
$this->x + 1 - $f,
$this->y,
$this->z,
$this->x + 1,
$this->y + 1,
$this->z + 1
);
}
}elseif($j === 3){
if($isOpen){
if(!$isRight){
$bb->setBounds(
$this->x,
$this->y,
$this->z,
$this->x + $f,
$this->y + 1,
$this->z + 1
);
}else{
$bb->setBounds(
$this->x + 1 - $f,
$this->y,
$this->z,
$this->x + 1,
$this->y + 1,
$this->z + 1
);
}
}else{
$bb->setBounds(
$this->x,
$this->y,
$this->z + 1 - $f,
$this->x + 1,
$this->y + 1,
$this->z + 1
);
}
}
return $bb;
return AxisAlignedBB::one()
->extend(Facing::UP, 1)
->trim($this->open ? Facing::rotateY($this->facing, !$this->hingeRight) : $this->facing, 13 / 16);
}
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);
}
if($this->getSide(Facing::DOWN)->getId() === BlockLegacyIds::AIR){ //Replace with common break method
$this->getWorld()->useBreakOn($this); //this will delete both halves if they exist
}
}
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);
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($face === Facing::UP){
$blockUp = $this->getSide(Facing::UP);
$blockDown = $this->getSide(Facing::DOWN);
if(!$blockUp->canBeReplaced() or $blockDown->isTransparent()){
return false;
}
$direction = $player instanceof Player ? $player->getDirection() : 0;
$faces = [
0 => 3,
1 => 4,
2 => 2,
3 => 5
];
$next = $this->getSide($faces[($direction + 2) % 4]);
$next2 = $this->getSide($faces[$direction]);
$metaUp = 0x08;
if($next->getId() === $this->getId() or (!$next2->isTransparent() and $next->isTransparent())){ //Door hinge
$metaUp |= 0x01;
if($player !== null){
$this->facing = $player->getHorizontalFacing();
}
$this->setDamage($player->getDirection() & 0x03);
$this->getLevel()->setBlock($blockReplace, $this, true, true); //Bottom
$this->getLevel()->setBlock($blockUp, BlockFactory::get($this->getId(), $metaUp), true); //Top
$next = $this->getSide(Facing::rotateY($this->facing, false));
$next2 = $this->getSide(Facing::rotateY($this->facing, true));
if($next->isSameType($this) or (!$next2->isTransparent() and $next->isTransparent())){ //Door hinge
$this->hingeRight = true;
}
$topHalf = clone $this;
$topHalf->top = true;
$tx->addBlock($blockReplace, $this)->addBlock($blockUp, $topHalf);
return true;
}
return false;
}
public function onActivate(Item $item, Player $player = null) : bool{
if(($this->getDamage() & 0x08) === 0x08){ //Top
$down = $this->getSide(Vector3::SIDE_DOWN);
if($down->getId() === $this->getId()){
$meta = $down->getDamage() ^ 0x04;
$this->level->setBlock($down, BlockFactory::get($this->getId(), $meta), true);
$this->level->addSound(new DoorSound($this));
return true;
}
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
$this->open = !$this->open;
return false;
}else{
$this->meta ^= 0x04;
$this->level->setBlock($this, $this, true);
$this->level->addSound(new DoorSound($this));
$other = $this->getSide($this->top ? Facing::DOWN : Facing::UP);
if($other instanceof Door and $other->isSameType($this)){
$other->open = $this->open;
$this->world->setBlock($other, $other);
}
$this->world->setBlock($this, $this);
$this->world->addSound($this, new DoorSound());
return true;
}
public function getVariantBitmask() : int{
return 0;
}
public function getDropsForCompatibleTool(Item $item) : array{
if(($this->meta & 0x08) === 0){ //bottom half only
return parent::getDropsForCompatibleTool($item);
public function getDrops(Item $item) : array{
if(!$this->top){
return parent::getDrops($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];
}
$other = $this->getSide($this->top ? Facing::DOWN : Facing::UP);
if($other->isSameType($this)){
return [$this, $other];
}
return parent::getAffectedBlocks();
}
}

View File

@ -24,42 +24,38 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\Player;
use function mt_rand;
use pocketmine\player\Player;
use pocketmine\world\BlockTransaction;
class DoublePlant extends Flowable{
public const BITFLAG_TOP = 0x08;
protected $id = self::DOUBLE_PLANT;
/** @var bool */
protected $top = false;
public function __construct(int $meta = 0){
$this->meta = $meta;
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? BlockBreakInfo::instant());
}
public function canBeReplaced() : bool{
return $this->getVariant() === 2 or $this->getVariant() === 3; //grass or fern
protected function writeStateToMeta() : int{
return ($this->top ? BlockLegacyMetadata::DOUBLE_PLANT_FLAG_TOP : 0);
}
public function getName() : string{
static $names = [
0 => "Sunflower",
1 => "Lilac",
2 => "Double Tallgrass",
3 => "Large Fern",
4 => "Rose Bush",
5 => "Peony"
];
return $names[$this->getVariant()] ?? "";
public function readStateFromData(int $id, int $stateMeta) : void{
$this->top = ($stateMeta & BlockLegacyMetadata::DOUBLE_PLANT_FLAG_TOP) !== 0;
}
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);
$this->getLevel()->setBlock($blockReplace->getSide(Vector3::SIDE_UP), BlockFactory::get($this->id, $this->meta | self::BITFLAG_TOP), false, false);
public function getStateBitmask() : int{
return 0b1000;
}
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
$id = $blockReplace->getSide(Facing::DOWN)->getId();
if(($id === BlockLegacyIds::GRASS or $id === BlockLegacyIds::DIRT) and $blockReplace->getSide(Facing::UP)->canBeReplaced()){
$top = clone $this;
$top->top = true;
$tx->addBlock($blockReplace, $this)->addBlock($blockReplace->getSide(Facing::UP), $top);
return true;
}
@ -71,56 +67,28 @@ class DoublePlant extends Flowable{
* @return bool
*/
public function isValidHalfPlant() : bool{
if($this->meta & self::BITFLAG_TOP){
$other = $this->getSide(Vector3::SIDE_DOWN);
}else{
$other = $this->getSide(Vector3::SIDE_UP);
}
$other = $this->getSide($this->top ? Facing::DOWN : Facing::UP);
return (
$other->getId() === $this->getId() and
$other->getVariant() === $this->getVariant() and
($other->getDamage() & self::BITFLAG_TOP) !== ($this->getDamage() & self::BITFLAG_TOP)
$other instanceof DoublePlant and
$other->isSameType($this) and
$other->top !== $this->top
);
}
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);
if(!$this->isValidHalfPlant() or (!$this->top and $this->getSide(Facing::DOWN)->isTransparent())){
$this->getWorld()->useBreakOn($this);
}
}
public function getVariantBitmask() : int{
return 0x07;
}
public function getToolType() : int{
return ($this->getVariant() === 2 or $this->getVariant() === 3) ? BlockToolType::TYPE_SHEARS : BlockToolType::TYPE_NONE;
}
public function getToolHarvestLevel() : int{
return ($this->getVariant() === 2 or $this->getVariant() === 3) ? 1 : 0; //only grass or fern require shears
}
public function getDrops(Item $item) : array{
if($this->meta & self::BITFLAG_TOP){
if($this->isCompatibleWithTool($item)){
return parent::getDrops($item);
}
if(mt_rand(0, 24) === 0){
return [
ItemFactory::get(Item::SEEDS)
];
}
}
return [];
return $this->top ? parent::getDrops($item) : [];
}
public function getAffectedBlocks() : array{
if($this->isValidHalfPlant()){
return [$this, $this->getSide(($this->meta & self::BITFLAG_TOP) !== 0 ? Vector3::SIDE_DOWN : Vector3::SIDE_UP)];
return [$this, $this->getSide($this->top ? Facing::DOWN : Facing::UP)];
}
return parent::getAffectedBlocks();

View File

@ -24,31 +24,25 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\TieredTool;
use pocketmine\item\VanillaItems;
use function mt_rand;
class IronDoor extends Door{
class DoubleTallGrass extends DoublePlant{
protected $id = self::IRON_DOOR_BLOCK;
protected $itemId = Item::IRON_DOOR;
public function __construct(int $meta = 0){
$this->meta = $meta;
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? BlockBreakInfo::instant(BlockToolType::SHEARS, 1));
}
public function getName() : string{
return "Iron Door";
public function canBeReplaced() : bool{
return true;
}
public function getToolType() : int{
return BlockToolType::TYPE_PICKAXE;
}
public function getToolHarvestLevel() : int{
return TieredTool::TIER_WOODEN;
}
public function getHardness() : float{
return 5;
public function getDrops(Item $item) : array{
if($this->top and !$this->breakInfo->isToolCompatible($item) and mt_rand(0, 7) === 0){
return [
VanillaItems::WHEAT_SEEDS()
];
}
return parent::getDrops($item);
}
}

View File

@ -0,0 +1,86 @@
<?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\Fallable;
use pocketmine\block\utils\FallableTrait;
use pocketmine\event\block\BlockTeleportEvent;
use pocketmine\item\Item;
use pocketmine\item\ToolTier;
use pocketmine\math\Vector3;
use pocketmine\player\Player;
use pocketmine\world\particle\DragonEggTeleportParticle;
use pocketmine\world\World;
use function max;
use function min;
use function mt_rand;
class DragonEgg extends Transparent implements Fallable{
use FallableTrait;
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(3.0, BlockToolType::PICKAXE, ToolTier::WOOD()->getHarvestLevel()));
}
public function getLightLevel() : int{
return 1;
}
public function tickFalling() : ?Block{
return null;
}
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
$this->teleport();
return true;
}
public function onAttack(Item $item, int $face, ?Player $player = null) : bool{
$this->teleport();
return true;
}
public function teleport() : void{
for($tries = 0; $tries < 16; ++$tries){
$block = $this->world->getBlockAt(
$this->x + mt_rand(-16, 16),
max(0, min(World::Y_MAX - 1, $this->y + mt_rand(-8, 8))),
$this->z + mt_rand(-16, 16)
);
if($block instanceof Air){
$ev = new BlockTeleportEvent($this, $block);
$ev->call();
if($ev->isCancelled()){
break;
}else{
$block = $ev->getTo();
}
$this->world->addParticle($this, new DragonEggTeleportParticle($this->x - $block->x, $this->y - $block->y, $this->z - $block->z));
$this->world->setBlock($this, VanillaBlocks::AIR());
$this->world->setBlock($block, $this);
break;
}
}
}
}

View File

@ -23,15 +23,17 @@ declare(strict_types=1);
namespace pocketmine\block;
class LitRedstoneLamp extends RedstoneLamp{
class DriedKelp extends Opaque{
protected $id = self::LIT_REDSTONE_LAMP;
public function getName() : string{
return "Lit Redstone Lamp";
public function getFlameEncouragement() : int{
return 30;
}
public function getLightLevel() : int{
return 15;
public function getFlammability() : int{
return 60;
}
public function getFuelTime() : int{
return 4000;
}
}

View File

@ -0,0 +1,62 @@
<?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 Element extends Opaque{
/** @var int */
private $atomicWeight;
/** @var int */
private $group;
/** @var string */
private $symbol;
public function __construct(BlockIdentifier $idInfo, string $name, BlockBreakInfo $breakInfo, string $symbol, int $atomicWeight, int $group){
parent::__construct($idInfo, $name, $breakInfo);
$this->atomicWeight = $atomicWeight;
$this->group = $group;
$this->symbol = $symbol;
}
/**
* @return int
*/
public function getAtomicWeight() : int{
return $this->atomicWeight;
}
/**
* @return int
*/
public function getGroup() : int{
return $this->group;
}
/**
* @return string
*/
public function getSymbol() : string{
return $this->symbol;
}
}

View File

@ -1,51 +0,0 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\TieredTool;
class Emerald extends Solid{
protected $id = self::EMERALD_BLOCK;
public function __construct(int $meta = 0){
$this->meta = $meta;
}
public function getHardness() : float{
return 5;
}
public function getToolType() : int{
return BlockToolType::TYPE_PICKAXE;
}
public function getToolHarvestLevel() : int{
return TieredTool::TIER_IRON;
}
public function getName() : string{
return "Emerald Block";
}
}

View File

@ -24,37 +24,19 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\TieredTool;
use pocketmine\item\ToolTier;
use pocketmine\item\VanillaItems;
use function mt_rand;
class EmeraldOre extends Solid{
class EmeraldOre extends Opaque{
protected $id = self::EMERALD_ORE;
public function __construct(int $meta = 0){
$this->meta = $meta;
}
public function getName() : string{
return "Emerald Ore";
}
public function getToolType() : int{
return BlockToolType::TYPE_PICKAXE;
}
public function getToolHarvestLevel() : int{
return TieredTool::TIER_IRON;
}
public function getHardness() : float{
return 3;
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(3.0, BlockToolType::PICKAXE, ToolTier::IRON()->getHarvestLevel()));
}
public function getDropsForCompatibleTool(Item $item) : array{
return [
ItemFactory::get(Item::EMERALD)
VanillaItems::EMERALD()
];
}

View File

@ -25,53 +25,27 @@ namespace pocketmine\block;
use pocketmine\inventory\EnchantInventory;
use pocketmine\item\Item;
use pocketmine\item\TieredTool;
use pocketmine\item\ToolTier;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\Player;
use pocketmine\tile\EnchantTable as TileEnchantTable;
use pocketmine\tile\Tile;
use pocketmine\player\Player;
class EnchantingTable extends Transparent{
protected $id = self::ENCHANTING_TABLE;
public function __construct(int $meta = 0){
$this->meta = $meta;
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(5.0, BlockToolType::PICKAXE, ToolTier::WOOD()->getHarvestLevel(), 6000.0));
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$this->getLevel()->setBlock($blockReplace, $this, true, true);
Tile::createTile(Tile::ENCHANT_TABLE, $this->getLevel(), TileEnchantTable::createNBT($this, $face, $item, $player));
return true;
protected function recalculateBoundingBox() : ?AxisAlignedBB{
return AxisAlignedBB::one()->trim(Facing::UP, 0.25);
}
public function getHardness() : float{
return 5;
}
public function getBlastResistance() : float{
return 6000;
}
public function getName() : string{
return "Enchanting Table";
}
public function getToolType() : int{
return BlockToolType::TYPE_PICKAXE;
}
public function getToolHarvestLevel() : int{
return TieredTool::TIER_WOODEN;
}
public function onActivate(Item $item, Player $player = null) : bool{
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($player instanceof Player){
//TODO lock
$player->addWindow(new EnchantInventory($this));
$player->setCurrentWindow(new EnchantInventory($this));
}
return true;

View File

@ -23,46 +23,50 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\block\utils\BlockDataSerializer;
use pocketmine\item\Item;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\player\Player;
use pocketmine\world\BlockTransaction;
class EndPortalFrame extends Solid{
class EndPortalFrame extends Opaque{
protected $id = self::END_PORTAL_FRAME;
/** @var int */
protected $facing = Facing::NORTH;
/** @var bool */
protected $eye = false;
public function __construct(int $meta = 0){
$this->meta = $meta;
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? BlockBreakInfo::indestructible());
}
protected function writeStateToMeta() : int{
return BlockDataSerializer::writeLegacyHorizontalFacing($this->facing) | ($this->eye ? BlockLegacyMetadata::END_PORTAL_FRAME_FLAG_EYE : 0);
}
public function readStateFromData(int $id, int $stateMeta) : void{
$this->facing = BlockDataSerializer::readLegacyHorizontalFacing($stateMeta & 0x03);
$this->eye = ($stateMeta & BlockLegacyMetadata::END_PORTAL_FRAME_FLAG_EYE) !== 0;
}
public function getStateBitmask() : int{
return 0b111;
}
public function getLightLevel() : int{
return 1;
}
public function getName() : string{
return "End Portal Frame";
}
public function getHardness() : float{
return -1;
}
public function getBlastResistance() : float{
return 18000000;
}
public function isBreakable(Item $item) : bool{
return false;
}
protected function recalculateBoundingBox() : ?AxisAlignedBB{
return AxisAlignedBB::one()->trim(Facing::UP, 3 / 16);
}
return new AxisAlignedBB(
$this->x,
$this->y,
$this->z,
$this->x + 1,
$this->y + (($this->getDamage() & 0x04) > 0 ? 1 : 0.8125),
$this->z + 1
);
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($player !== null){
$this->facing = Facing::opposite($player->getHorizontalFacing());
}
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
}
}

View File

@ -23,34 +23,51 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\block\utils\BlockDataSerializer;
use pocketmine\item\Item;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\Player;
use pocketmine\player\Player;
use pocketmine\world\BlockTransaction;
class EndRod extends Flowable{
protected $id = Block::END_ROD;
/** @var int */
protected $facing = Facing::DOWN;
public function __construct(int $meta = 0){
$this->meta = $meta;
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? BlockBreakInfo::instant());
}
public function getName() : string{
return "End Rod";
protected function writeStateToMeta() : int{
$result = BlockDataSerializer::writeFacing($this->facing);
if(Facing::axis($this->facing) !== Facing::AXIS_Y){
$result ^= 1; //TODO: in PC this is always the same as facing, just PE is stupid
}
return $result;
}
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{
$this->meta = $face ^ 0x01;
}
if($blockClicked instanceof EndRod and $blockClicked->getDamage() === $this->meta){
$this->meta ^= 0x01;
public function readStateFromData(int $id, int $stateMeta) : void{
if($stateMeta !== 0 and $stateMeta !== 1){
$stateMeta ^= 1;
}
return $this->level->setBlock($blockReplace, $this, true, true);
$this->facing = BlockDataSerializer::readFacing($stateMeta);
}
public function getStateBitmask() : int{
return 0b111;
}
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
$this->facing = $face;
if($blockClicked instanceof EndRod and $blockClicked->facing === $this->facing){
$this->facing = Facing::opposite($face);
}
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
}
public function isSolid() : bool{
@ -62,43 +79,15 @@ class EndRod extends Flowable{
}
protected function recalculateBoundingBox() : ?AxisAlignedBB{
$m = $this->meta & ~0x01;
$width = 0.375;
$myAxis = Facing::axis($this->facing);
switch($m){
case 0x00: //up/down
return new AxisAlignedBB(
$this->x + $width,
$this->y,
$this->z + $width,
$this->x + 1 - $width,
$this->y + 1,
$this->z + 1 - $width
);
case 0x02: //north/south
return new AxisAlignedBB(
$this->x,
$this->y + $width,
$this->z + $width,
$this->x + 1,
$this->y + 1 - $width,
$this->z + 1 - $width
);
case 0x04: //east/west
return new AxisAlignedBB(
$this->x + $width,
$this->y + $width,
$this->z,
$this->x + 1 - $width,
$this->y + 1 - $width,
$this->z + 1
);
$bb = AxisAlignedBB::one();
foreach([Facing::AXIS_Y, Facing::AXIS_Z, Facing::AXIS_X] as $axis){
if($axis === $myAxis){
continue;
}
$bb->squash($axis, 6 / 16);
}
return null;
}
public function getVariantBitmask() : int{
return 0;
return $bb;
}
}

View File

@ -1,51 +0,0 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\TieredTool;
class EndStone extends Solid{
protected $id = self::END_STONE;
public function __construct(int $meta = 0){
$this->meta = $meta;
}
public function getName() : string{
return "End Stone";
}
public function getToolType() : int{
return BlockToolType::TYPE_PICKAXE;
}
public function getToolHarvestLevel() : int{
return TieredTool::TIER_WOODEN;
}
public function getHardness() : float{
return 3;
}
}

View File

@ -23,75 +23,60 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\block\tile\EnderChest as TileEnderChest;
use pocketmine\block\utils\BlockDataSerializer;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\TieredTool;
use pocketmine\item\ToolTier;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\Player;
use pocketmine\tile\EnderChest as TileEnderChest;
use pocketmine\tile\Tile;
use pocketmine\player\Player;
use pocketmine\world\BlockTransaction;
class EnderChest extends Chest{
class EnderChest extends Transparent{
protected $id = self::ENDER_CHEST;
/** @var int */
protected $facing = Facing::NORTH;
public function getHardness() : float{
return 22.5;
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(22.5, BlockToolType::PICKAXE, ToolTier::WOOD()->getHarvestLevel(), 3000.0));
}
public function getBlastResistance() : float{
return 3000;
protected function writeStateToMeta() : int{
return BlockDataSerializer::writeHorizontalFacing($this->facing);
}
public function readStateFromData(int $id, int $stateMeta) : void{
$this->facing = BlockDataSerializer::readHorizontalFacing($stateMeta);
}
public function getStateBitmask() : int{
return 0b111;
}
public function getLightLevel() : int{
return 7;
}
public function getName() : string{
return "Ender Chest";
protected function recalculateBoundingBox() : ?AxisAlignedBB{
//these are slightly bigger than in PC
return AxisAlignedBB::one()->contract(0.025, 0, 0.025)->trim(Facing::UP, 0.05);
}
public function getToolType() : int{
return BlockToolType::TYPE_PICKAXE;
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($player !== null){
$this->facing = Facing::opposite($player->getHorizontalFacing());
}
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
}
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{
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?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));
$enderChest = $this->getWorld()->getTile($this);
if($enderChest instanceof TileEnderChest and $this->getSide(Facing::UP)->isTransparent()){
$player->getEnderChestInventory()->setHolderPosition($enderChest);
$player->setCurrentWindow($player->getEnderChestInventory());
}
if(!$this->getSide(Vector3::SIDE_UP)->isTransparent()){
return true;
}
$player->getEnderChestInventory()->setHolderPosition($enderChest);
$player->addWindow($player->getEnderChestInventory());
}
return true;
@ -99,11 +84,7 @@ class EnderChest extends Chest{
public function getDropsForCompatibleTool(Item $item) : array{
return [
ItemFactory::get(Item::OBSIDIAN, 0, 8)
VanillaBlocks::OBSIDIAN()->asItem()->setCount(8)
];
}
public function getFuelTime() : int{
return 0;
}
}

View File

@ -23,46 +23,39 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\block\utils\BlockDataSerializer;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Vector3;
use pocketmine\math\Facing;
class Farmland extends Transparent{
protected $id = self::FARMLAND;
/** @var int */
protected $wetness = 0; //"moisture" blockstate property in PC
public function __construct(int $meta = 0){
$this->meta = $meta;
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(0.6, BlockToolType::SHOVEL));
}
public function getName() : string{
return "Farmland";
protected function writeStateToMeta() : int{
return $this->wetness;
}
public function getHardness() : float{
return 0.6;
public function readStateFromData(int $id, int $stateMeta) : void{
$this->wetness = BlockDataSerializer::readBoundedInt("wetness", $stateMeta, 0, 7);
}
public function getToolType() : int{
return BlockToolType::TYPE_SHOVEL;
public function getStateBitmask() : int{
return 0b111;
}
protected function recalculateBoundingBox() : ?AxisAlignedBB{
return new AxisAlignedBB(
$this->x,
$this->y,
$this->z,
$this->x + 1,
$this->y + 1, //TODO: this should be 0.9375, but MCPE currently treats them as a full block (https://bugs.mojang.com/browse/MCPE-12109)
$this->z + 1
);
return AxisAlignedBB::one(); //TODO: this should be trimmed at the top by 1/16, but MCPE currently treats them as a full block (https://bugs.mojang.com/browse/MCPE-12109)
}
public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_UP)->isSolid()){
$this->level->setBlock($this, BlockFactory::get(Block::DIRT), true);
if($this->getSide(Facing::UP)->isSolid()){
$this->world->setBlock($this, VanillaBlocks::DIRT());
}
}
@ -72,15 +65,15 @@ class Farmland extends Transparent{
public function onRandomTick() : void{
if(!$this->canHydrate()){
if($this->meta > 0){
$this->meta--;
$this->level->setBlock($this, $this, false, false);
if($this->wetness > 0){
$this->wetness--;
$this->world->setBlock($this, $this, false);
}else{
$this->level->setBlock($this, BlockFactory::get(Block::DIRT), false, true);
$this->world->setBlock($this, VanillaBlocks::DIRT());
}
}elseif($this->meta < 7){
$this->meta = 7;
$this->level->setBlock($this, $this, false, false);
}elseif($this->wetness < 7){
$this->wetness = 7;
$this->world->setBlock($this, $this, false);
}
}
@ -91,8 +84,7 @@ class Farmland extends Transparent{
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){
if($this->world->getBlockAt($x, $y, $z) instanceof Water){
return true;
}
}
@ -104,7 +96,7 @@ class Farmland extends Transparent{
public function getDropsForCompatibleTool(Item $item) : array{
return [
ItemFactory::get(Item::DIRT)
VanillaBlocks::DIRT()->asItem()
];
}
@ -112,7 +104,7 @@ class Farmland extends Transparent{
return false;
}
public function getPickedItem() : Item{
return ItemFactory::get(Item::DIRT);
public function getPickedItem(bool $addUserData = false) : Item{
return VanillaBlocks::DIRT()->asItem();
}
}

View File

@ -24,29 +24,40 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Vector3;
use pocketmine\math\Facing;
abstract class Fence extends Transparent{
public function __construct(int $meta = 0){
$this->meta = $meta;
}
class Fence extends Transparent{
/** @var bool[] facing => dummy */
protected $connections = [];
public function getThickness() : float{
return 0.25;
}
public function readStateFromWorld() : void{
parent::readStateFromWorld();
foreach(Facing::HORIZONTAL as $facing){
$block = $this->getSide($facing);
if($block instanceof static or $block instanceof FenceGate or ($block->isSolid() and !$block->isTransparent())){
$this->connections[$facing] = true;
}else{
unset($this->connections[$facing]);
}
}
}
protected function recalculateBoundingBox() : ?AxisAlignedBB{
$width = 0.5 - $this->getThickness() / 2;
return new AxisAlignedBB(
$this->x + ($this->canConnect($this->getSide(Vector3::SIDE_WEST)) ? 0 : $width),
$this->y,
$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 + 1 - ($this->canConnect($this->getSide(Vector3::SIDE_SOUTH)) ? 0 : $width)
);
$bb = AxisAlignedBB::one()
->extend(Facing::UP, 0.5);
foreach(Facing::HORIZONTAL as $facing){
if(!isset($this->connections[$facing])){
$bb->trim($facing, $width);
}
}
return $bb;
}
protected function recalculateCollisionBoxes() : array{
@ -55,54 +66,39 @@ abstract class Fence extends Transparent{
/** @var AxisAlignedBB[] $bbs */
$bbs = [];
$connectWest = $this->canConnect($this->getSide(Vector3::SIDE_WEST));
$connectEast = $this->canConnect($this->getSide(Vector3::SIDE_EAST));
$connectWest = isset($this->connections[Facing::WEST]);
$connectEast = isset($this->connections[Facing::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
);
$bbs[] = AxisAlignedBB::one()
->squash(Facing::AXIS_Z, $inset)
->extend(Facing::UP, 0.5)
->trim(Facing::WEST, $connectWest ? 0 : $inset)
->trim(Facing::EAST, $connectEast ? 0 : $inset);
}
$connectNorth = $this->canConnect($this->getSide(Vector3::SIDE_NORTH));
$connectSouth = $this->canConnect($this->getSide(Vector3::SIDE_SOUTH));
$connectNorth = isset($this->connections[Facing::NORTH]);
$connectSouth = isset($this->connections[Facing::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)
);
$bbs[] = AxisAlignedBB::one()
->squash(Facing::AXIS_X, $inset)
->extend(Facing::UP, 0.5)
->trim(Facing::NORTH, $connectNorth ? 0 : $inset)
->trim(Facing::SOUTH, $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
)
AxisAlignedBB::one()
->extend(Facing::UP, 0.5)
->contract($inset, 0, $inset)
];
}
return $bbs;
}
public function canConnect(Block $block){
return $block instanceof static or $block instanceof FenceGate or ($block->isSolid() and !$block->isTransparent());
}
}

View File

@ -23,71 +23,87 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\block\utils\BlockDataSerializer;
use pocketmine\item\Item;
use pocketmine\level\sound\DoorSound;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\Player;
use pocketmine\player\Player;
use pocketmine\world\BlockTransaction;
use pocketmine\world\sound\DoorSound;
class FenceGate extends Transparent{
/** @var bool */
protected $open = false;
/** @var int */
protected $facing = Facing::NORTH;
/** @var bool */
protected $inWall = false;
public function getHardness() : float{
return 2;
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(2.0, BlockToolType::AXE));
}
public function getToolType() : int{
return BlockToolType::TYPE_AXE;
protected function writeStateToMeta() : int{
return BlockDataSerializer::writeLegacyHorizontalFacing($this->facing) |
($this->open ? BlockLegacyMetadata::FENCE_GATE_FLAG_OPEN : 0) |
($this->inWall ? BlockLegacyMetadata::FENCE_GATE_FLAG_IN_WALL : 0);
}
public function readStateFromData(int $id, int $stateMeta) : void{
$this->facing = BlockDataSerializer::readLegacyHorizontalFacing($stateMeta & 0x03);
$this->open = ($stateMeta & BlockLegacyMetadata::FENCE_GATE_FLAG_OPEN) !== 0;
$this->inWall = ($stateMeta & BlockLegacyMetadata::FENCE_GATE_FLAG_IN_WALL) !== 0;
}
public function getStateBitmask() : int{
return 0b1111;
}
protected function recalculateBoundingBox() : ?AxisAlignedBB{
if(($this->getDamage() & 0x04) > 0){
if($this->open){
return null;
}
$i = ($this->getDamage() & 0x03);
if($i === 2 or $i === 0){
return new AxisAlignedBB(
$this->x,
$this->y,
$this->z + 0.375,
$this->x + 1,
$this->y + 1.5,
$this->z + 0.625
);
}else{
return new AxisAlignedBB(
$this->x + 0.375,
$this->y,
$this->z,
$this->x + 0.625,
$this->y + 1.5,
$this->z + 1
);
}
return AxisAlignedBB::one()->extend(Facing::UP, 0.5)->squash(Facing::axis($this->facing), 6 / 16);
}
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);
return true;
private function checkInWall() : bool{
return (
$this->getSide(Facing::rotateY($this->facing, false)) instanceof Wall or
$this->getSide(Facing::rotateY($this->facing, true)) instanceof Wall
);
}
public function getVariantBitmask() : int{
return 0;
}
public function onActivate(Item $item, Player $player = null) : bool{
$this->meta = (($this->meta ^ 0x04) & ~0x02);
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($player !== null){
$this->meta |= (($player->getDirection() - 1) & 0x02);
$this->facing = $player->getHorizontalFacing();
}
$this->getLevel()->setBlock($this, $this, true);
$this->level->addSound(new DoorSound($this));
$this->inWall = $this->checkInWall();
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
}
public function onNearbyBlockChange() : void{
$inWall = $this->checkInWall();
if($inWall !== $this->inWall){
$this->inWall = $inWall;
$this->world->setBlock($this, $this);
}
}
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
$this->open = !$this->open;
if($this->open and $player !== null){
$playerFacing = $player->getHorizontalFacing();
if($playerFacing === Facing::opposite($this->facing)){
$this->facing = $playerFacing;
}
}
$this->getWorld()->setBlock($this, $this);
$this->world->addSound($this, new DoorSound());
return true;
}

View File

@ -23,6 +23,7 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\block\utils\BlockDataSerializer;
use pocketmine\entity\Entity;
use pocketmine\entity\projectile\Arrow;
use pocketmine\event\block\BlockBurnEvent;
@ -30,39 +31,44 @@ use pocketmine\event\entity\EntityCombustByBlockEvent;
use pocketmine\event\entity\EntityDamageByBlockEvent;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\item\Item;
use pocketmine\math\Vector3;
use pocketmine\math\Facing;
use function min;
use function mt_rand;
class Fire extends Flowable{
protected $id = self::FIRE;
/** @var int */
protected $age = 0;
public function __construct(int $meta = 0){
$this->meta = $meta;
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? BlockBreakInfo::instant());
}
protected function writeStateToMeta() : int{
return $this->age;
}
public function readStateFromData(int $id, int $stateMeta) : void{
$this->age = BlockDataSerializer::readBoundedInt("age", $stateMeta, 0, 15);
}
public function getStateBitmask() : int{
return 0b1111;
}
public function hasEntityCollision() : bool{
return true;
}
public function getName() : string{
return "Fire Block";
}
public function getLightLevel() : int{
return 15;
}
public function isBreakable(Item $item) : bool{
return false;
}
public function canBeReplaced() : bool{
return true;
}
public function onEntityCollide(Entity $entity) : void{
public function onEntityInside(Entity $entity) : void{
$ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_FIRE, 1);
$entity->attack($ev);
@ -81,10 +87,10 @@ class Fire extends Flowable{
}
public function onNearbyBlockChange() : void{
if(!$this->getSide(Vector3::SIDE_DOWN)->isSolid() and !$this->hasAdjacentFlammableBlocks()){
$this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), true);
if(!$this->getSide(Facing::DOWN)->isSolid() and !$this->hasAdjacentFlammableBlocks()){
$this->getWorld()->setBlock($this, VanillaBlocks::AIR());
}else{
$this->level->scheduleDelayedBlockUpdate($this, mt_rand(30, 40));
$this->world->scheduleDelayedBlockUpdate($this, mt_rand(30, 40));
}
}
@ -93,35 +99,35 @@ class Fire extends Flowable{
}
public function onRandomTick() : void{
$down = $this->getSide(Vector3::SIDE_DOWN);
$down = $this->getSide(Facing::DOWN);
$result = null;
if($this->meta < 15 and mt_rand(0, 2) === 0){
$this->meta++;
if($this->age < 15 and mt_rand(0, 2) === 0){
$this->age++;
$result = $this;
}
$canSpread = true;
if(!$down->burnsForever()){
//TODO: check rain
if($this->meta === 15){
if($this->age === 15){
if(!$down->isFlammable() and mt_rand(0, 3) === 3){ //1/4 chance to extinguish
$canSpread = false;
$result = BlockFactory::get(Block::AIR);
$result = VanillaBlocks::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(!$down->isSolid() or $this->age > 3){
$result = VanillaBlocks::AIR();
}
}
}
if($result !== null){
$this->level->setBlock($this, $result);
$this->world->setBlock($this, $result);
}
$this->level->scheduleDelayedBlockUpdate($this, mt_rand(30, 40));
$this->world->scheduleDelayedBlockUpdate($this, mt_rand(30, 40));
if($canSpread){
//TODO: raise upper bound for chance in humid biomes
@ -131,8 +137,8 @@ class Fire extends Flowable{
}
//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);
$this->burnBlock($this->getSide(Facing::UP), 350);
$this->burnBlock($this->getSide(Facing::DOWN), 350);
//TODO: fire spread
}
@ -143,8 +149,8 @@ class Fire extends Flowable{
}
private function hasAdjacentFlammableBlocks() : bool{
for($i = 0; $i <= 5; ++$i){
if($this->getSide($i)->isFlammable()){
foreach(Facing::ALL as $face){
if($this->getSide($face)->isFlammable()){
return true;
}
}
@ -159,10 +165,12 @@ class Fire extends Flowable{
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))));
if(mt_rand(0, $this->age + 9) < 5){ //TODO: check rain
$fire = clone $this;
$fire->age = min(15, $fire->age + (mt_rand(0, 4) >> 2));
$this->world->setBlock($block, $fire);
}else{
$this->level->setBlock($block, BlockFactory::get(Block::AIR));
$this->world->setBlock($block, VanillaBlocks::AIR());
}
}
}

View File

@ -31,10 +31,6 @@ abstract class Flowable extends Transparent{
return true;
}
public function getHardness() : float{
return 0;
}
public function isSolid() : bool{
return false;
}

View File

@ -24,55 +24,29 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\Player;
use pocketmine\player\Player;
use pocketmine\world\BlockTransaction;
class Flower extends Flowable{
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;
public function __construct(int $meta = 0){
$this->meta = $meta;
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? BlockBreakInfo::instant());
}
public function getName() : string{
static $names = [
self::TYPE_POPPY => "Poppy",
self::TYPE_BLUE_ORCHID => "Blue Orchid",
self::TYPE_ALLIUM => "Allium",
self::TYPE_AZURE_BLUET => "Azure Bluet",
self::TYPE_RED_TULIP => "Red Tulip",
self::TYPE_ORANGE_TULIP => "Orange Tulip",
self::TYPE_WHITE_TULIP => "White Tulip",
self::TYPE_PINK_TULIP => "Pink Tulip",
self::TYPE_OXEYE_DAISY => "Oxeye Daisy"
];
return $names[$this->getVariant()] ?? "Unknown";
}
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);
return true;
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
$down = $this->getSide(Facing::DOWN);
if($down->getId() === BlockLegacyIds::GRASS or $down->getId() === BlockLegacyIds::DIRT or $down->getId() === BlockLegacyIds::FARMLAND){
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
}
return false;
}
public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_DOWN)->isTransparent()){
$this->getLevel()->useBreakOn($this);
if($this->getSide(Facing::DOWN)->isTransparent()){
$this->getWorld()->useBreakOn($this);
}
}

View File

@ -23,90 +23,138 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\block\tile\FlowerPot as TileFlowerPot;
use pocketmine\item\Item;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\Player;
use pocketmine\tile\FlowerPot as TileFlowerPot;
use pocketmine\tile\Tile;
use pocketmine\player\Player;
use pocketmine\world\BlockTransaction;
use function assert;
class FlowerPot extends Flowable{
public const STATE_EMPTY = 0;
public const STATE_FULL = 1;
/**
* TODO: get rid of this hack (it's currently needed to deal with blockfactory state handling)
* @var bool
*/
protected $occupied = false;
protected $id = self::FLOWER_POT_BLOCK;
protected $itemId = Item::FLOWER_POT;
/** @var Block|null */
protected $plant = null;
public function __construct(int $meta = 0){
$this->meta = $meta;
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? BlockBreakInfo::instant());
}
public function getName() : string{
return "Flower Pot";
protected function writeStateToMeta() : int{
return $this->occupied ? BlockLegacyMetadata::FLOWER_POT_FLAG_OCCUPIED : 0;
}
public function readStateFromData(int $id, int $stateMeta) : void{
$this->occupied = ($stateMeta & BlockLegacyMetadata::FLOWER_POT_FLAG_OCCUPIED) !== 0;
}
public function getStateBitmask() : int{
return 0b1111; //vanilla uses various values, we only care about 1 and 0 for PE
}
public function readStateFromWorld() : void{
parent::readStateFromWorld();
$tile = $this->world->getTile($this);
if($tile instanceof TileFlowerPot){
$this->setPlant($tile->getPlant());
}else{
$this->occupied = false;
}
}
public function writeStateToWorld() : void{
parent::writeStateToWorld();
$tile = $this->world->getTile($this);
assert($tile instanceof TileFlowerPot);
$tile->setPlant($this->plant);
}
/**
* @return Block|null
*/
public function getPlant() : ?Block{
return $this->plant;
}
/**
* @param Block|null $plant
*/
public function setPlant(?Block $plant) : void{
if($plant === null or $plant instanceof Air){
$this->plant = null;
}else{
$this->plant = clone $plant;
}
$this->occupied = $this->plant !== null;
}
public function canAddPlant(Block $block) : bool{
if($this->plant !== null){
return false;
}
return
$block instanceof Cactus or
$block instanceof DeadBush or
$block instanceof Flower or
$block instanceof RedMushroom or
$block instanceof Sapling or
($block instanceof TallGrass and $block->getIdInfo()->getVariant() === BlockLegacyMetadata::TALLGRASS_FERN); //TODO: clean up
//TODO: bamboo
}
protected function recalculateBoundingBox() : ?AxisAlignedBB{
return new AxisAlignedBB(
$this->x + 0.3125,
$this->y,
$this->z + 0.3125,
$this->x + 0.6875,
$this->y + 0.375,
$this->z + 0.6875
);
return AxisAlignedBB::one()->contract(3 / 16, 0, 3 / 16)->trim(Facing::UP, 5 / 8);
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
if($this->getSide(Vector3::SIDE_DOWN)->isTransparent()){
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($this->getSide(Facing::DOWN)->isTransparent()){
return false;
}
$this->getLevel()->setBlock($blockReplace, $this, true, true);
Tile::createTile(Tile::FLOWER_POT, $this->getLevel(), TileFlowerPot::createNBT($this, $face, $item, $player));
return true;
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
}
public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_DOWN)->isTransparent()){
$this->getLevel()->useBreakOn($this);
if($this->getSide(Facing::DOWN)->isTransparent()){
$this->getWorld()->useBreakOn($this);
}
}
public function onActivate(Item $item, Player $player = null) : bool{
$pot = $this->getLevel()->getTile($this);
if(!($pot instanceof TileFlowerPot)){
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
$plant = $item->getBlock();
if(!$this->canAddPlant($plant)){
return false;
}
if(!$pot->canAddItem($item)){
return true;
}
$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->pop());
$this->setPlant($plant);
$item->pop();
$this->world->setBlock($this, $this);
return true;
}
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){
$item = $tile->getItem();
if($item->getId() !== Item::AIR){
$items[] = $item;
}
if($this->plant !== null){
$items[] = $this->plant->asItem();
}
return $items;
}
public function getPickedItem(bool $addUserData = false) : Item{
return $this->plant !== null ? $this->plant->asItem() : parent::getPickedItem($addUserData);
}
public function isAffectedBySilkTouch() : bool{
return false;
}

View File

@ -0,0 +1,115 @@
<?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\BlockDataSerializer;
use function max;
use function mt_rand;
class FrostedIce extends Ice{
/** @var int */
protected $age = 0;
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(2.5, BlockToolType::PICKAXE));
}
public function readStateFromData(int $id, int $stateMeta) : void{
$this->age = BlockDataSerializer::readBoundedInt("age", $stateMeta, 0, 3);
}
protected function writeStateToMeta() : int{
return $this->age;
}
public function getStateBitmask() : int{
return 0b11;
}
public function onNearbyBlockChange() : void{
if(!$this->checkAdjacentBlocks(2)){
$this->world->useBreakOn($this);
}else{
$this->world->scheduleDelayedBlockUpdate($this, mt_rand(20, 40));
}
}
public function onRandomTick() : void{
if((!$this->checkAdjacentBlocks(4) or mt_rand(0, 2) === 0) and
max( //TODO: move this to World
$this->world->getHighestAdjacentBlockLight($this->x, $this->y, $this->z),
$this->world->getHighestAdjacentBlockSkyLight($this->x, $this->y, $this->z) - $this->world->getSkyLightReduction()
) >= 12 - $this->age){
if($this->tryMelt()){
foreach($this->getAllSides() as $block){
if($block instanceof FrostedIce){
$block->tryMelt();
}
}
}
}else{
$this->world->scheduleDelayedBlockUpdate($this, mt_rand(20, 40));
}
}
public function onScheduledUpdate() : void{
$this->onRandomTick();
}
private function checkAdjacentBlocks(int $requirement) : bool{
$found = 0;
for($x = -1; $x <= 1; ++$x){
for($z = -1; $z <= 1; ++$z){
if($x === 0 and $z === 0){
continue;
}
if(
$this->world->getBlockAt($this->x + $x, $this->y, $this->z + $z) instanceof FrostedIce and
++$found >= $requirement
){
return true;
}
}
}
return false;
}
/**
* Updates the age of the ice, destroying it if appropriate.
*
* @return bool Whether the ice was destroyed.
*/
private function tryMelt() : bool{
if($this->age >= 3){
$this->world->useBreakOn($this);
return true;
}
$this->age++;
$this->world->setBlock($this, $this);
$this->world->scheduleDelayedBlockUpdate($this, mt_rand(20, 40));
return false;
}
}

View File

@ -23,16 +23,86 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\block\tile\Furnace as TileFurnace;
use pocketmine\block\utils\BlockDataSerializer;
use pocketmine\item\Item;
use pocketmine\item\ToolTier;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\player\Player;
use pocketmine\world\BlockTransaction;
class Furnace extends BurningFurnace{
class Furnace extends Opaque{
/** @var BlockIdentifierFlattened */
protected $idInfo;
protected $id = self::FURNACE;
/** @var int */
protected $facing = Facing::NORTH;
/** @var bool */
protected $lit = false; //this is set based on the blockID
public function getName() : string{
return "Furnace";
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(3.5, BlockToolType::PICKAXE, ToolTier::WOOD()->getHarvestLevel()));
}
public function getId() : int{
return $this->lit ? $this->idInfo->getSecondId() : parent::getId();
}
protected function writeStateToMeta() : int{
return BlockDataSerializer::writeHorizontalFacing($this->facing);
}
public function readStateFromData(int $id, int $stateMeta) : void{
$this->facing = BlockDataSerializer::readHorizontalFacing($stateMeta);
$this->lit = $id === $this->idInfo->getSecondId();
}
public function getStateBitmask() : int{
return 0b111;
}
public function getLightLevel() : int{
return 0;
return $this->lit ? 13 : 0;
}
public function isLit() : bool{
return $this->lit;
}
/**
* @param bool $lit
*
* @return $this
*/
public function setLit(bool $lit = true) : self{
$this->lit = $lit;
return $this;
}
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($player !== null){
$this->facing = Facing::opposite($player->getHorizontalFacing());
}
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
}
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($player instanceof Player){
$furnace = $this->getWorld()->getTile($this);
if($furnace instanceof TileFurnace and $furnace->canOpenWith($item->getCustomName())){
$player->setCurrentWindow($furnace->getInventory());
}
}
return true;
}
public function onScheduledUpdate() : void{
$furnace = $this->getWorld()->getTile($this);
if($furnace instanceof TileFurnace and $furnace->onUpdate()){
$this->world->scheduleDelayedBlockUpdate($this, 1); //TODO: check this
}
}
}

View File

@ -27,18 +27,8 @@ use pocketmine\item\Item;
class Glass extends Transparent{
protected $id = self::GLASS;
public function __construct(int $meta = 0){
$this->meta = $meta;
}
public function getName() : string{
return "Glass";
}
public function getHardness() : float{
return 0.3;
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(0.3));
}
public function getDropsForCompatibleTool(Item $item) : array{

View File

@ -27,18 +27,8 @@ use pocketmine\item\Item;
class GlassPane extends Thin{
protected $id = self::GLASS_PANE;
public function __construct(int $meta = 0){
$this->meta = $meta;
}
public function getName() : string{
return "Glass Pane";
}
public function getHardness() : float{
return 0.3;
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(0.3));
}
public function getDropsForCompatibleTool(Item $item) : array{

View File

@ -24,40 +24,40 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\block\utils\BlockDataSerializer;
use pocketmine\item\Item;
use pocketmine\item\TieredTool;
use pocketmine\item\ToolTier;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\Player;
use pocketmine\player\Player;
use pocketmine\world\BlockTransaction;
class GlazedTerracotta extends Solid{
class GlazedTerracotta extends Opaque{
public function getHardness() : float{
return 1.4;
/** @var int */
protected $facing = Facing::NORTH;
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(1.4, BlockToolType::PICKAXE, ToolTier::WOOD()->getHarvestLevel()));
}
public function getToolType() : int{
return BlockToolType::TYPE_PICKAXE;
protected function writeStateToMeta() : int{
return BlockDataSerializer::writeHorizontalFacing($this->facing);
}
public function getToolHarvestLevel() : int{
return TieredTool::TIER_WOODEN;
public function readStateFromData(int $id, int $stateMeta) : void{
$this->facing = BlockDataSerializer::readHorizontalFacing($stateMeta);
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
public function getStateBitmask() : int{
return 0b111;
}
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($player !== null){
$faces = [
0 => 4,
1 => 3,
2 => 5,
3 => 2
];
$this->meta = $faces[(~($player->getDirection() - 1)) & 0x03];
$this->facing = Facing::opposite($player->getHorizontalFacing());
}
return $this->getLevel()->setBlock($blockReplace, $this, true, true);
}
public function getVariantBitmask() : int{
return 0;
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
}
}

View File

@ -24,37 +24,15 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\TieredTool;
use pocketmine\item\ToolTier;
class GlowingObsidian extends Solid{
class GlowingObsidian extends Opaque{
protected $id = self::GLOWING_OBSIDIAN;
public function __construct(int $meta = 0){
$this->meta = $meta;
}
public function getName() : string{
return "Glowing Obsidian";
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(10.0, BlockToolType::PICKAXE, ToolTier::DIAMOND()->getHarvestLevel(), 50.0));
}
public function getLightLevel() : int{
return 12;
}
public function getHardness() : float{
return 10;
}
public function getBlastResistance() : float{
return 50;
}
public function getToolType() : int{
return BlockToolType::TYPE_PICKAXE;
}
public function getToolHarvestLevel() : int{
return TieredTool::TIER_DIAMOND;
}
}

View File

@ -1,58 +0,0 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\block;
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";
}
public function getLightLevel() : int{
return 9;
}
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

@ -24,27 +24,13 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\VanillaItems;
use function mt_rand;
class Glowstone extends Transparent{
protected $id = self::GLOWSTONE;
public function __construct(int $meta = 0){
$this->meta = $meta;
}
public function getName() : string{
return "Glowstone";
}
public function getHardness() : float{
return 0.3;
}
public function getToolType() : int{
return BlockToolType::TYPE_PICKAXE;
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(0.3, BlockToolType::PICKAXE));
}
public function getLightLevel() : int{
@ -53,7 +39,7 @@ class Glowstone extends Transparent{
public function getDropsForCompatibleTool(Item $item) : array{
return [
ItemFactory::get(Item::GLOWSTONE_DUST, 0, mt_rand(2, 4))
VanillaItems::GLOWSTONE_DUST()->setCount(mt_rand(2, 4))
];
}
}

View File

@ -1,51 +0,0 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\TieredTool;
class Gold extends Solid{
protected $id = self::GOLD_BLOCK;
public function __construct(int $meta = 0){
$this->meta = $meta;
}
public function getName() : string{
return "Gold Block";
}
public function getHardness() : float{
return 3;
}
public function getToolType() : int{
return BlockToolType::TYPE_PICKAXE;
}
public function getToolHarvestLevel() : int{
return TieredTool::TIER_IRON;
}
}

View File

@ -1,51 +0,0 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\TieredTool;
class GoldOre extends Solid{
protected $id = self::GOLD_ORE;
public function __construct(int $meta = 0){
$this->meta = $meta;
}
public function getName() : string{
return "Gold Ore";
}
public function getHardness() : float{
return 3;
}
public function getToolType() : int{
return BlockToolType::TYPE_PICKAXE;
}
public function getToolHarvestLevel() : int{
return TieredTool::TIER_IRON;
}
}

View File

@ -24,39 +24,26 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\event\block\BlockSpreadEvent;
use pocketmine\item\Fertilizer;
use pocketmine\item\Hoe;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\Shovel;
use pocketmine\level\generator\object\TallGrass as TallGrassObject;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\Player;
use pocketmine\player\Player;
use pocketmine\utils\Random;
use pocketmine\world\generator\object\TallGrass as TallGrassObject;
use function mt_rand;
class Grass extends Solid{
class Grass extends Opaque{
protected $id = self::GRASS;
public function __construct(int $meta = 0){
$this->meta = $meta;
}
public function getName() : string{
return "Grass";
}
public function getHardness() : float{
return 0.6;
}
public function getToolType() : int{
return BlockToolType::TYPE_SHOVEL;
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(0.6, BlockToolType::SHOVEL));
}
public function getDropsForCompatibleTool(Item $item) : array{
return [
ItemFactory::get(Item::DIRT)
VanillaBlocks::DIRT()->asItem()
];
}
@ -65,13 +52,13 @@ class Grass extends Solid{
}
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
$lightAbove = $this->world->getFullLightAt($this->x, $this->y + 1, $this->z);
if($lightAbove < 4 and $this->world->getBlockAt($this->x, $this->y + 1, $this->z)->getLightFilter() >= 2){
//grass dies
$ev = new BlockSpreadEvent($this, $this, BlockFactory::get(Block::DIRT));
$ev = new BlockSpreadEvent($this, $this, VanillaBlocks::DIRT());
$ev->call();
if(!$ev->isCancelled()){
$this->level->setBlock($this, $ev->getNewState(), false, false);
$this->world->setBlock($this, $ev->getNewState(), false);
}
}elseif($lightAbove >= 9){
//try grass spread
@ -79,38 +66,43 @@ class Grass extends Solid{
$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);
$b = $this->world->getBlockAt($x, $y, $z);
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
!($b instanceof Dirt) or
$b instanceof CoarseDirt or
$this->world->getFullLightAt($x, $y + 1, $z) < 4 or
$this->world->getBlockAt($x, $y + 1, $z)->getLightFilter() >= 2
){
continue;
}
$ev = new BlockSpreadEvent($b = $this->level->getBlockAt($x, $y, $z), $this, BlockFactory::get(Block::GRASS));
$ev = new BlockSpreadEvent($b, $this, VanillaBlocks::GRASS());
$ev->call();
if(!$ev->isCancelled()){
$this->level->setBlock($b, $ev->getNewState(), false, false);
$this->world->setBlock($b, $ev->getNewState(), false);
}
}
}
}
public function onActivate(Item $item, Player $player = null) : bool{
if($item->getId() === Item::DYE and $item->getDamage() === 0x0F){
$item->count--;
TallGrassObject::growGrass($this->getLevel(), $this, new Random(mt_rand()), 8, 2);
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($face !== Facing::UP){
return false;
}
if($item instanceof Fertilizer){
$item->pop();
TallGrassObject::growGrass($this->getWorld(), $this, new Random(mt_rand()), 8, 2);
return true;
}elseif($item instanceof Hoe){
$item->applyDamage(1);
$this->getLevel()->setBlock($this, BlockFactory::get(Block::FARMLAND));
$this->getWorld()->setBlock($this, VanillaBlocks::FARMLAND());
return true;
}elseif($item instanceof Shovel and $this->getSide(Vector3::SIDE_UP)->getId() === Block::AIR){
}elseif($item instanceof Shovel and $this->getSide(Facing::UP)->getId() === BlockLegacyIds::AIR){
$item->applyDamage(1);
$this->getLevel()->setBlock($this, BlockFactory::get(Block::GRASS_PATH));
$this->getWorld()->setBlock($this, VanillaBlocks::GRASS_PATH());
return true;
}

View File

@ -24,50 +24,28 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Vector3;
use pocketmine\math\Facing;
class GrassPath extends Transparent{
protected $id = self::GRASS_PATH;
public function __construct(int $meta = 0){
$this->meta = $meta;
}
public function getName() : string{
return "Grass Path";
}
public function getToolType() : int{
return BlockToolType::TYPE_SHOVEL;
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(0.6, BlockToolType::SHOVEL));
}
protected function recalculateBoundingBox() : ?AxisAlignedBB{
return new AxisAlignedBB(
$this->x,
$this->y,
$this->z,
$this->x + 1,
$this->y + 1, //TODO: this should be 0.9375, but MCPE currently treats them as a full block (https://bugs.mojang.com/browse/MCPE-12109)
$this->z + 1
);
}
public function getHardness() : float{
return 0.6;
return AxisAlignedBB::one(); //TODO: this should be trimmed at the top by 1/16, but MCPE currently treats them as a full block (https://bugs.mojang.com/browse/MCPE-12109)
}
public function onNearbyBlockChange() : void{
if($this->getSide(Vector3::SIDE_UP)->isSolid()){
$this->level->setBlock($this, BlockFactory::get(Block::DIRT), true);
if($this->getSide(Facing::UP)->isSolid()){
$this->world->setBlock($this, VanillaBlocks::DIRT());
}
}
public function getDropsForCompatibleTool(Item $item) : array{
return [
ItemFactory::get(Item::DIRT)
VanillaBlocks::DIRT()->asItem()
];
}
}

View File

@ -23,37 +23,30 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\block\utils\Fallable;
use pocketmine\block\utils\FallableTrait;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\VanillaItems;
use function mt_rand;
class Gravel extends Fallable{
class Gravel extends Opaque implements Fallable{
use FallableTrait;
protected $id = self::GRAVEL;
public function __construct(int $meta = 0){
$this->meta = $meta;
}
public function getName() : string{
return "Gravel";
}
public function getHardness() : float{
return 0.6;
}
public function getToolType() : int{
return BlockToolType::TYPE_SHOVEL;
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(0.6, BlockToolType::SHOVEL));
}
public function getDropsForCompatibleTool(Item $item) : array{
if(mt_rand(1, 10) === 1){
return [
ItemFactory::get(Item::FLINT)
VanillaItems::FLINT()
];
}
return parent::getDropsForCompatibleTool($item);
}
public function tickFalling() : ?Block{
return null;
}
}

View File

@ -23,29 +23,11 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\TieredTool;
use pocketmine\item\ToolTier;
class HardenedClay extends Solid{
class HardenedClay extends Opaque{
protected $id = self::HARDENED_CLAY;
public function __construct(int $meta = 0){
$this->meta = $meta;
}
public function getName() : string{
return "Hardened Clay";
}
public function getToolType() : int{
return BlockToolType::TYPE_PICKAXE;
}
public function getToolHarvestLevel() : int{
return TieredTool::TIER_WOODEN;
}
public function getHardness() : float{
return 1.25;
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(1.25, BlockToolType::PICKAXE, ToolTier::WOOD()->getHarvestLevel(), 21.0));
}
}

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