CryptoMorin / XSeries

Library for cross-version Minecraft Bukkit support and various efficient API methods.
https://www.spigotmc.org/threads/378136/
MIT License
403 stars 126 forks source link

XMaterial - Incorrect Materials #166

Closed GavvyDizzle closed 2 years ago

GavvyDizzle commented 2 years ago

Description This is somewhat of a continuation if issue #160 XMaterial.matchXMaterial("Hard_Clay") does now return the right value

Currently I'm using the following code to get the type of block broken: if (XMaterial.matchXMaterial(e.getBlock().getType().name() + ":" + e.getBlock().getData()).isPresent()) String blockName = XMaterial.matchXMaterial(e.getBlock().getType().name() + ":" + e.getBlock().getData()).get().name().toLowerCase();

This code will always pass a string of the format "Material:data" to the matchXMaterial method. In most cases, this works fine. The only inconsistency I've found is with the parameter "HARD_CLAY:0" still returning CLAY.

I found a some errors with other blocks too. https://cdn.discordapp.com/attachments/830236883979993168/949071921457279107/unknown.png

Version My server is running Paper 1.12.2 and the plugin is running XSeries v8.6.2

CryptoMorin commented 2 years ago

XMaterial is not designed to work with blocks correctly. It's mainly for items.

But anyways, It's impossible for HARD_CLAY:0 to return anything other than HARD_CLAY or TERRACOTTA if you check their legacy material list in the enum. Are you sure you're using the latest version?

GavvyDizzle commented 2 years ago

I think something might be problematic because I have multiple plugins running using different versions. Just running a simple test plugin, I can see that terracotta does give the correct item (when checking the block how I showed above or by checking the item in my hand).

I looked a little deeper and found why these errors are happening.

Most GLAZED_TERRACOTTAs have nothing after them except LIGHT_GRAY_GLAZED_TERRACOTTA(8, "STAINED_CLAY", "SILVER_GLAZED_TERRACOTTA") WHITE_GLAZED_TERRACOTTA("STAINED_CLAY") YELLOW_GLAZED_TERRACOTTA(4, "STAINED_CLAY", "YELLOW_TERRACOTTA") These entries having the "STAINED_CLAY" returns the glazed varient for light gray, white, and yellow terracotta.

I'm not exactly sure how the cross compatibility works but I assume you try as best as you can to link new blocks to an old block of similar type. For example, MOSSY_STONE_BRICK_SLAB should be seen as STONE_BRICK_SLAB in 1.12 While this is nice, it breaks certain items in the following way...

END_STONE_BRICK_STAIRS("SMOOTH_STAIRS") MOSSY_STONE_BRICK_STAIRS("SMOOTH_STAIRS") STONE_BRICK_STAIRS("SMOOTH_STAIRS") In 1.12 STONE_BRICK_STAIRS is SMOOTH_STAIRS and because END_STONE_BRICK_STAIRS is defined first, it gets returned.

Similarly, END_STONE_BRICK_SLAB(6, "STEP") NETHER_BRICK_SLAB(6, "STEP") Gives END_STONE_BRICK_SLAB for NETHER_BRICK_SLABs

MOSSY_STONE_BRICK_SLAB(5, "STEP") STONE_BRICK_SLAB(4, "DOUBLE_STEP", "STEP", "STONE_SLAB") STONE_BRICK_SLAB Should have a data value of 5, but it would still return MOSSY_STONE_BRICK_SLAB

STONE_SLABs dont return the right value because many entries before it define ("STEP")

WOODEN_PRESSURE_PLATEs don't return the right value because all wooden pressure plate variants define ("WOOD_PLATE")

CryptoMorin commented 2 years ago

Wait we were talking about HARD_CLAY giving CLAY, what happened to that? Also, multiple plugins running with XMaterial is fine as long as they shade it correctly.

GavvyDizzle commented 2 years ago

Wait we were talking about HARD_CLAY giving CLAY, what happened to that? Also, multiple plugins running with XMaterial is fine as long as they shade it correctly.

Something weird was happening during my test. HARD_CLAY giving CLAY has been fixed. I found more issues in trying to understand why HARD_CLAY giving CLAY wasn't working so I made a commant instead of a new issue

CryptoMorin commented 2 years ago

you try as best as you can to link new blocks to an old block of similar type.

In the old version there was a bad decision made that added something called suggestions system to XMaterial which attempted to return similar materials if they didn't exist in older versions, however this was completely removed, but some materials are still lurking in the corner.

So no, my intention is to link the exact same counterpart of that material in older versions or null if they don't exist.

YELLOW_GLAZED_TERRACOTTA(4, "STAINED_CLAY", "YELLOW_TERRACOTTA"),
YELLOW_TERRACOTTA(4, "STAINED_CLAY"),

For example since you mentioned terracotta, I noticed this which is wrong.

But

LIGHT_GRAY_GLAZED_TERRACOTTA(8, "STAINED_CLAY", "SILVER_GLAZED_TERRACOTTA")

Is correct, except STAINED_CLAY.

I'm guessing that STAINED_CLAY was the old name for TERRACOTTA (not glazed one) and the glazed ones never had an old name (except the light gray one)

I'm just explaining again just to make sure. As for the steps, I'm kinda confused what needs to be removed/changed. If you had the time could you make a list of them with their solution or a PR would be even better. If you couldn't, I'll just check it myself in a few days.

CryptoMorin commented 2 years ago

Fixed in v8.7.0