Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Massive block's hardness & blast resistance update #6378

Open
wants to merge 1 commit into
base: minor-next
Choose a base branch
from

Conversation

IvanCraft623
Copy link
Member

Introduction

It is important to keep these values up to date, not only for vanilla-parity, anti-cheats may also depend on them.

Follow-up

Add a file to bedrock-data that contains block's hardness & blast resistance values, to be able to make a PHPUnit test.

Tests

I tested this PR by doing the following (tick all that apply):

  • Writing a test plugin (provide the code and sample output)

Vanilla hardness & blast resistance values(need to be droped in plugin_data) file: blocks_hardness.json
(File was provided by @TwistedAsylumMC)

Code:

public function onEnable() : void {
	$ignoredStates = [
		"minecraft:air" => true,
		"minecraft:barrier" => true,
		"minecraft:flowing_lava" => true, //destructible in vanilla???
		"minecraft:flowing_water" => true, //destructible in vanilla???
		"minecraft:light_block" => true,
	];

	$blocksData = json_decode(file_get_contents($this->getDataFolder() . "blocks_hardness.json"), true);
	$serializer = GlobalBlockStateHandlers::getSerializer();
	foreach (VanillaBlocks::getAll() as $block) {
		$stateName = $serializer->serialize($block->getStateId())->getName();
		if (isset($ignoredStates[$stateName])) {
			continue;
		}
		foreach ($blocksData as $blockData) {
			if ($blockData["id"] !== $stateName) {
				continue;
			}
			$breakInfo = $block->getBreakInfo();
			$hardness = round($blockData["base_hardness"], 5);
			$blastResistance = round($blockData["blast_resistance"], 5) * 5;
			if ($hardness != $breakInfo->getHardness() ||
				$blastResistance != $breakInfo->getBlastResistance()
			) {
				$this->getLogger()->warning(
					"\n\nBlock(" . $block->getName() . ", class: " . basename(str_replace('\\', '/', $block::class)) . ", stateName: $stateName) has a mismatch hardness:\n" .
					"PM hardness: " . $breakInfo->getHardness() . "\n" .
					"PM blast_resistance: " . $breakInfo->getBlastResistance() . "\n" .
					"Vanilla hardness: " . $hardness . "\n" .
					"Vanilla blast_resistance: " . $blastResistance
				);
			}
			continue 2;
		}
		$this->getLogger()->error("Block with state id $stateName not found");
	}
	$this->getLogger()->info("Finished hardness test!");
}

Sample output:

[18:48:36.004] [Server thread/ERROR]: [Test] Block with state id minecraft:tube_coral_block not found
[18:48:36.004] [Server thread/ERROR]: [Test] Block with state id minecraft:sunflower not found
[18:48:36.004] [Server thread/ERROR]: [Test] Block with state id minecraft:lilac not found
[18:48:36.005] [Server thread/ERROR]: [Test] Block with state id minecraft:rose_bush not found
[18:48:36.005] [Server thread/ERROR]: [Test] Block with state id minecraft:peony not found
[18:48:36.005] [Server thread/ERROR]: [Test] Block with state id minecraft:tall_grass not found
[18:48:36.005] [Server thread/ERROR]: [Test] Block with state id minecraft:large_fern not found
[18:48:36.009] [Server thread/ERROR]: [Test] Block with state id minecraft:brick_slab not found
[18:48:36.009] [Server thread/ERROR]: [Test] Block with state id minecraft:cobblestone_slab not found
[18:48:36.009] [Server thread/ERROR]: [Test] Block with state id minecraft:petrified_oak_slab not found
[18:48:36.009] [Server thread/ERROR]: [Test] Block with state id minecraft:nether_brick_slab not found
[18:48:36.010] [Server thread/ERROR]: [Test] Block with state id minecraft:quartz_slab not found
[18:48:36.010] [Server thread/ERROR]: [Test] Block with state id minecraft:sandstone_slab not found
[18:48:36.010] [Server thread/ERROR]: [Test] Block with state id minecraft:smooth_stone_slab not found
[18:48:36.010] [Server thread/ERROR]: [Test] Block with state id minecraft:stone_brick_slab not found
[18:48:36.023] [Server thread/INFO]: [Test] Finished hardness test!

Currently it seems that doesn't have some blocks mapped

@IvanCraft623 IvanCraft623 added Category: Core Related to internal functionality Type: Enhancement Contributes features or other improvements to PocketMine-MP labels Jun 26, 2024
@ShockedPlot7560
Copy link
Member

What is the source of the file? Do we know what it was generated from?

@IvanCraft623
Copy link
Member Author

What is the source of the file? Do we know what it was generated from?

It was provided to me by @TwistedAsylumMC, was generated through a mod

Copy link
Member

@ShockedPlot7560 ShockedPlot7560 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds fine to me if all the values are correct and the source is reliable.

@IvanCraft623 IvanCraft623 mentioned this pull request Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Core Related to internal functionality Type: Enhancement Contributes features or other improvements to PocketMine-MP
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants