Commit Graph

188 Commits

Author SHA1 Message Date
f22ad14c67 Block: added isFlammable() 2018-04-10 09:58:35 +01:00
64540f36be Block: added burnsForever() 2018-04-10 09:58:21 +01:00
e66b1953de Block: added flame encouragement and flammability properties 2018-04-10 09:58:08 +01:00
a4c50d3204 Remove unused imports 2018-03-24 11:59:15 +00:00
1648fff916 Replaced Position->getLevel() null checks with isValid() 2018-03-20 11:10:36 +00:00
3d89bf5693 Updated PocketMine Math dependency 2018-03-18 18:08:24 +00:00
bf97eab98f Block: remove redundant local variable from collidesWithBB() 2018-03-15 09:38:14 +00:00
86eee429bb Block: Split onUpdate() into several functions, removed Level::BLOCK_UPDATE_* constants
This allows the removal of lots of ugly code, and also exposes lots of similarities with how this update type was handled. This can be further improved in the future to more generically handle cases.

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

RedstoneOre: use onActivate() to trigger glowing
this is not technically correct behaviour, but this preserves the current behaviour.
2018-03-13 17:29:46 +00:00
f0535df96d Remove deprecated things 2018-02-27 11:59:16 +00:00
8d7c65585c Enchantment: Implement Silk Touch (#1912) 2018-01-14 13:37:27 +00:00
45b02d92d4 Math: Added RayTraceResult, removed dependence on MovingObjectPosition
MOP doesn't make any sense anyway.

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

This would allow modularisation of the pocketmine\\math namespace.
2018-01-12 14:28:41 +00:00
3a0cbd1cd4 Block: Cleaned up double-block break handling, close #1862, close #1525
This now removes the need for recursing around for structures comprised of multiple blocks. Instead, override getAffectedBlocks() to return all blocks that need to be deleted when the current block is deleted, and make sure that only one half of the block drops something. When a player breaks one of the blocks, all the blocks affected by that block will also be destroyed, creating particles and sounds where appropriate.

This fixes creative drops for double plants and beds.
2018-01-03 13:01:05 +00:00
6abf880e44 Block: Drop unnecessary parameters for ItemFactory::get() 2017-12-13 18:37:04 +00:00
8c47a338df Block: Remove unused imports 2017-12-13 12:44:21 +00:00
b9b50dd5dc Added Block->getDropsForCompatibleTool(), removed lots of boilerplate code from subclasses
The function name is a little long-winded, but that can always be refactored later if needed. This provides a way for blocks requiring specific tools to override drops with non-standard stuff without needing to worry about what tool type was used.

It's also possible that passing the Item used here is actually entirely redundant, but again that can be fixed later.
2017-12-12 20:02:50 +00:00
da3640357c Rename Block->canBeBrokenWith() to isCompatibleWithTool() and add documentation
This name better describes it. "can be broken with" implies that items which this returns false for cannot destroy the block at all, which is incorrect. What this actually returns is whether the item is the best tool to use to break the block.
2017-12-12 19:51:31 +00:00
0004e7429f Added some documentation on harvest level properties 2017-12-12 16:55:00 +00:00
b903161a5d Refactored tool efficiency handling
This fixes lots of bugs with things like wool, cobwebs, swords.
2017-12-12 13:55:36 +00:00
99fe63b2a3 Added harvest level properties to applicable blocks
this fixes block-breaking animations with wrong tools, and also finally resolves the long-standing hierarchy problem in Stair.
2017-12-12 13:54:17 +00:00
dbc180315e Declare tool harvest level as a property 2017-12-12 13:54:16 +00:00
45983acc0d Fixed too-fast break times with wrong tool types 2017-12-12 13:54:16 +00:00
7de88b9040 Tool tier efficiency should still apply if the block can't be harvested
If you use an iron pickaxe on obsidian, it still mines faster because the tool types are compatible, even though the tool is not high enough.
2017-12-12 13:54:06 +00:00
58327d0514 Change block tool types to bitflags
This allows specification of multiple tool types for a block, such as cobwebs.
2017-12-12 13:51:33 +00:00
55d0684565 Move block-breaking tool-type constants to a BlockToolType interface 2017-12-12 13:45:52 +00:00
2088a43c56 Refactored tool hierarchy 2017-12-12 13:45:51 +00:00
a94c669730 Fixed sword efficiency on anything that's not cobwebs 2017-12-11 12:57:18 +00:00
d03fdd5f72 Liquids refactor, bug fixes and performance improvements (#1753)
* Added Liquid->getLiquidLevelDecreasePerBlock()

* Fixed lava turning into cobblestone when flowing over water

* Cache liquid flow vectors for faster entity movement

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

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

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

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

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

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

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

* Lava should only search 2 blocks for a slope

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

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

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

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

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

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

* Move liquid collide to its own method

* add sound for lava/water mix
2017-12-04 10:09:35 +00:00
b88ffa3bdf Fixed a mistake in Block->getSide() documentation
side() -> getSide()
2017-11-24 15:09:55 +00:00
754e088ee8 Change visibility of Block->boundingBox 2017-11-03 12:19:51 +00:00
451f5d0cd7 Fixed block-pick on crops giving the crop block itself 2017-11-03 12:17:38 +00:00
d1db27016e s/facePos/clickVector/
clickVector better describes this
2017-10-27 19:05:26 +01:00
716c1f29b4 Fixed slabs again 2017-10-24 10:23:07 +01:00
fd8a562e02 Fixed collision bugs caused by not clearing pre-computed outdated AABBs for blocks
take fences as an example: say you have fence1 and fence2 next to each other, like this:
|==|
and they are joined together
then delete the fence on the right
the left fence will then look like this
|
but the server would still think its collision boxes were like this:
|=
so you wouldn't be able to shoot arrows through that space.

This commit clears pre-computed bounding boxes when a block is set using Level->setBlock() (in case the block was previously already set and has pre-calculated outdated AABB). However, because of weird blocks like fences, glass and walls, they must also be cleared on neighbour block update (since connection state isn't shown in the block data).
2017-10-14 10:07:17 +01:00
15d6fd86e2 Added basic support for blocks with multiple AABBs, fixed stairs (#1303) 2017-10-12 16:29:24 +01:00
b9501ef415 Remove unnecessary duplicated ray-trace code from Block
this isn't actually used anywhere, but "backwards compatibility"
2017-10-12 13:40:12 +01:00
d8b1757ebc added some nullable and void typehints to Block API 2017-10-11 18:45:40 +01:00
fc9c264e77 Resend blocks around targeted blocks when interactions & block-break are cancelled, fixes #906
this solution is dumber but more effective (also solves the beds & doors placement problem)
2017-10-03 19:28:01 +01:00
c09d782503 Fix #145, take 2 (slab placement in half gaps doesn't work) (#1411) 2017-10-01 16:19:59 +01:00
90cb018de2 Re-organise some Block code 2017-09-26 19:39:05 +01:00
992c4ce6a0 Added API method Block->getVariant() 2017-09-26 19:35:04 +01:00
0e2e9aab2e Fixed crash when block classes override the constructor but don't specify a fallback name 2017-09-21 16:43:33 +01:00
1b5fed983b Revert "Fixed slab placement, close #145", reopen #145, close #1314
This reverts commit f2ff0198cc.
2017-09-21 14:41:18 +01:00
6d5620606e Block->place() parameter refactor to make things clearer 2017-08-26 14:41:49 +01:00
9e142655ea Removed redundant count parameter from item constructors, added some documentation and tightened safety checks
the count parameter is useless since Item ctor should now only be used for constructing item _types_, not actual items. All item creations for inventories etc, should go through the ItemFactory.
2017-08-25 19:06:23 +01:00
8ce833bf74 Stripped redundant trailing commas 2017-08-25 12:41:49 +01:00
ebda6ec19b Cleaned up random-block-ticking registration 2017-08-25 11:47:38 +01:00
8a35b9da29 Added some documentation 2017-08-22 10:28:43 +01:00
b8ade18888 Fixed double plants and beds sometimes dropping in creative 2017-08-21 19:25:04 +01:00
876659cc73 Item factory refactor and added capability to register custom items 2017-08-21 17:49:26 +01:00
02f42eba48 Move block registration to its own class 2017-08-20 18:05:01 +01:00