Commit Graph

59 Commits

Author SHA1 Message Date
fac2bd3379 Liquid: mark getSmallestFlowDecay() as impure
this fixes two bogus PHPStan warnings.
2021-02-25 22:41:07 +00:00
c4793241f5 Mass removal of useless @param/@return PHPDoc annotations, pass 1 2020-01-21 15:10:18 +00:00
ccbcc14600 Block: populate missing return type info 2020-01-19 17:02:03 +00:00
07cb603231 Liquid: add missing return type to getFluidHeightPercent() 2020-01-17 13:58:54 +00:00
1eedac87b2 added missing @var property types (reported by phpstan) 2020-01-09 14:13:54 +00:00
11fc16617a Liquid: fix max cost calculation for flow direction search, closes #2995 2019-07-07 14:32:52 +01:00
4b9a142a5d Import global functions and constants for enhanced performance
This is better for performance because these then don't need to be reevaluated every time they are called.

When encountering an unqualified function or constant reference, PHP will first try to locate a symbol in the current namespace by that name, and then fall back to the global namespace.
This short-circuits the check, which has substantial performance effects in some cases - in particular, ord(), chr() and strlen() show ~1500x faster calls when they are fully qualified.

However, this doesn't mean that PM is getting a massive amount faster. In real world terms, this translates to about 10-15% performance improvement.
But before anyone gets excited, you should know that the CodeOptimizer in the PreProcessor repo has been applying fully-qualified symbol optimizations to Jenkins builds for years, which is one of the reasons why Jenkins builds have better performance than home-built or source installations.
We're choosing to do this for the sake of future SafePHP integration and also to be able to get rid of the buggy CodeOptimizer, so that phar and source are more consistent.
2019-01-04 20:43:15 +00:00
d34b94302f fixed lava fizz sound 2018-12-12 18:00:43 +00:00
30f5a8fac6 Protocol changes for 1.8.0 release 2018-12-11 21:05:03 +00:00
e3f46987f5 Liquid: Add events to allow controlling flow and fusion (#2547) 2018-12-04 13:14:22 +00:00
1d5978df98 Fixed falling blocks getting moved by currents, closes #2080 2018-03-30 12:20:59 +01: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
5f48433c95 Bucket: Added sounds for bucket fill/empty 2018-01-03 14:27:41 +00:00
33352638a9 Bucket: Fixed appearing empty when picking up still liquids
Buckets already affected by this bug will still appear empty until used. After that they'll work fine.
2018-01-03 14:22:53 +00:00
4f8e4f0522 Add EOF newlines where missing (bulk) (#1836)
This should solve issues with people making GitHub PRs and having the web editor messing things up. GitHub Web Editor sucks :(
2017-12-20 11:56:36 +00:00
56f1a6ba37 Block: Migrated all trivial drops code to getDropsForCompatibleTool()
getDrops() should now be overridden only for special cases. There are some non-trivial overrides left that are going to need some extra work to clean up.
2017-12-13 12:49:58 +00:00
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
1f5f67e087 Liquid: Removed a bad hack-fix, fixed mobs not moving when water flows around them
this breaks more than it appears to fix, and I can't reproduce any CPU
leaks when block updates are enabled, so I'm going to assume this is OK.
2017-11-24 17:23:12 +00:00
74967eed87 Liquid: Stop abusing getLevel() in performance-sensitive situations
Most of these methods are called from onUpdate(). It's unreasonable to
assume that the level might be null during a tick (unless a plugin
messes with a block update event or something, but that's undefined
behaviour anyway). Using getLevel() simply wastes processing time by
constantly checking if the level is closed.
2017-11-24 16:58:03 +00:00
18e4e5364f Fixed getBlock() performance degradation caused by 781de3efab, added Level->getBlockAt() to avoid creating vectors everywhere 2017-10-20 13:22:49 +01:00
d8b1757ebc added some nullable and void typehints to Block API 2017-10-11 18:45:40 +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
ea5bd0348a Fixed liquid flow attempting to set negative block damage values
This should only execute if the current liquid block is actually still existent. When decay is negative, it means the water block doesn't exist anymore.
2017-08-29 14:22:12 +01:00
02f42eba48 Move block registration to its own class 2017-08-20 18:05:01 +01:00
f2ff0198cc Fixed slab placement, close #145 2017-08-20 10:52:07 +01:00
e51106e64c Fixed bad overrides of getBoundingBox() 2017-08-19 17:16:22 +01:00
0e24596aed Changed block construction calls to Block::get() 2017-08-19 13:46:17 +01:00
d8f0dd6db8 Changed Block->getDrops() to return Item[] 2017-08-18 11:21:33 +01:00
83af4dcd59 Block API typehints 2017-08-17 13:50:19 +01:00
06083d6dc4 s/Item/Block 2017-08-07 16:26:27 +01:00
210bdc2436 Fixed liquid CPU leaks and some flow issues
Liquid still needs a total rewrite, but at least it won't constantly waste CPU anymore.
2017-07-31 07:24:22 +01:00
a95d173989 Fixed a couple of repeated Level->getBlock() calls in Liquid 2017-07-30 17:57:40 +01:00
51b0673b4b Bite the bullet and enable strict types on everything 2017-06-07 12:53:16 +01:00
f3ab45e7d5 Merged in 1.0.6 changes, added autogenerated data for 1.1.0.3 (doesn't work yet) and deliberately made the same merge error as Mojang 2017-04-14 13:00:43 +01:00
9004417456 Fixed file headers (#255) 2017-01-13 16:57:05 +00:00
6fc435da0e Imports rearrangement 2016-10-03 00:43:46 +08:00
26c9eed82e Added all block hardness 2015-07-27 20:31:55 +02:00
74917923b6 Improved checks, area collision checks, etc 2015-05-29 15:13:19 +02:00
7201372b0d oops 2015-05-23 12:02:20 +02:00
744ea6af8f Fixed #3023 2015-05-23 11:47:07 +02:00
4c30b6b8a1 Optimized Liquid spreading, optimized light updates, improved side block get/update, fixed raw set not cleaning Block cache (TNT explosions) 2014-12-10 00:37:04 +01:00
747f7685e7 Fix formatting issues due to bad IDE settings 2014-12-07 16:30:04 +01:00
a98da3bab1 Renamed old getID() calls to getId() 2014-12-07 15:21:32 +01:00
af82d616c1 Block creating and property handling rewrite, part2 2014-12-07 02:20:26 +01:00
a0d4bff385 Block creating and property handling rewrite, part1 2014-12-07 01:53:27 +01:00
f866efb622 Removed unused Block->isLiquid property 2014-11-27 17:26:43 +01:00
8601405a88 Fixed CPU leak 2014-10-31 21:07:00 +01:00
7abf52e615 Implemented Vector3 List and AxisAlignedBB Pool to decrease object allocation 2014-10-27 15:39:20 +01:00
1eec333501 Save block bounding boxes, improves block cache 2014-10-13 18:38:00 +02:00
da23cf685d Added PlayerBucketEvent and children, improved Bucket usage and Liquid placing 2014-10-13 18:04:40 +02:00