Skip to content

Fix CatalogTypes#1792

Closed
ImMorpheus wants to merge 7 commits into
SpongePowered:1.13from
ImMorpheus:fix/catalogtypes
Closed

Fix CatalogTypes#1792
ImMorpheus wants to merge 7 commits into
SpongePowered:1.13from
ImMorpheus:fix/catalogtypes

Conversation

@ImMorpheus
Copy link
Copy Markdown
Contributor

@ImMorpheus ImMorpheus commented Feb 10, 2018

SpongeAPI | SpongeCommon

Missing translations:

  • EntityTypes: (Missing entries in the lang file)
    entity.MinecartSpawner.name
    entity.MinecartTNT.name
    entity.ThrownEnderpearl.name
    entity.EyeOfEnderSignal.name
    entity.FireworksRocketEntity.name
    entity.MinecartCommandBlock.name
    entity.MinecartFurnace.name
    entity.LlamaSpit.name
    entity.ThrownExpBottle.name
    entity.ItemFrame.name
    entity.SpectralArrow.name
    entity.EvocationFangs.name
    entity.ShulkerBullet.name
    entity.MinecartRideable.name
    entity.AreaEffectCloud.name
    entity.LeashKnot.name
    entity.WitherSkull.name
    entity.EnderCrystal.name

@ImMorpheus
Copy link
Copy Markdown
Contributor Author

ImMorpheus commented Feb 10, 2018

~wip

@limbo-app limbo-app added the status: wip Work in progress label Feb 10, 2018
@gabizou
Copy link
Copy Markdown
Member

gabizou commented Jul 1, 2018

Does this fix the spam from the catalog type tests?

@ImMorpheus
Copy link
Copy Markdown
Contributor Author

ImMorpheus commented Jul 1, 2018

All inconsistencies with mojang's translations should be fixed.

There are still a few things I don't like, I'll see if I can come up with something better. Suggestions are welcomed.

EDIT:

Does this fix the spam from the catalog type tests?

Yes.

After this PR:

See edit

This also adds a test to make sure name and id are not the same and another one to find inconsistencies with mojang's translation

@ImMorpheus
Copy link
Copy Markdown
Contributor Author

ImMorpheus commented Jul 1, 2018

Also, the old test had a few problems. If the translation was equal to the id, then it'd be classified as a missing translation. However minecraft is using the id as a fallback for a missing translation, thus that's not something we should fix.

Here's the situation before this PR with the new test:

See edit


@Override
public Translation getTranslation() {
return translation;
Copy link
Copy Markdown
Member

@ST-DDT ST-DDT Jul 1, 2018

Choose a reason for hiding this comment

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

Add this here.


@Override
public Translation getTranslation() {
EnumDyeColor enumdyecolor = ItemBanner.getBaseColor(new ItemStack((Item) (IMixinItem) this));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Cache the translation?


@Override
public Translation getTranslation() {
return new SpongeTranslation(PotionUtils.getPotionFromItem(new ItemStack((Item) (IMixinItem) this)).getNamePrefixed("lingering_potion.effect."));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Cache the translation?


@Override
public Translation getTranslation() {
return new SpongeTranslation(PotionUtils.getPotionFromItem(new ItemStack((Item) (IMixinItem) this)).getNamePrefixed("potion.effect."));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same here

public SpongeItemStatistic(String statId, String itemName, ITextComponent statName, Item item) {
super(statId, itemName, statName, item);
String args = new ItemStack(item).getDisplayName();
translation = new SpongeTranslation(statId.substring(0, statId.length() - 1), args);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this

public abstract class MixinItemTippedArrow extends MixinItem implements ItemType {

@Override
public Translation getTranslation() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Cache this.


public Translation itemstack$getTranslation() {
return new SpongeTranslation(shadow$getItem().getUnlocalizedName((net.minecraft.item.ItemStack) (Object) this) + ".name");
String id;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Cache this.

public abstract class MixinItemSplashPotion extends MixinItem implements ItemType {

@Override
public Translation getTranslation() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Cache this.

public abstract class MixinItemSkull extends MixinItem implements ItemType {

@Override
public Translation getTranslation() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Cache this.


@Override
public Translation getTranslation() {
return translation;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this

@ST-DDT
Copy link
Copy Markdown
Member

ST-DDT commented Jul 1, 2018

Nice improvements.

@ImMorpheus
Copy link
Copy Markdown
Contributor Author

    [Test worker/INFO]: FML platform manager could not load class cpw.mods.fml.relauncher.CoreModManager. Proceeding without FML support.
    [Test worker/ERROR]: MixinBootstrap.doInit() called during a tweak constructor!
    [Test worker/INFO]: Compatibility level set to JAVA_8
    [Test worker/INFO]: Loading tweak class name org.spongepowered.asm.mixin.EnvironmentStateTweaker
    [Test worker/INFO]: Calling tweak class org.spongepowered.asm.mixin.EnvironmentStateTweaker
    [Test worker/ERROR]: Classloader restrictions [PACKAGE_CLASSLOADER_EXCLUSION] encountered loading mixins.common.test.json:MixinBlock, name: org.spongepowered.common.launch.mixin.MixinBlock
    [Test worker/ERROR]: Classloader restrictions [PACKAGE_CLASSLOADER_EXCLUSION] encountered loading mixins.common.test.json:MixinEnumDifficulty, name: org.spongepowered.common.launch.mixin.MixinEnumDifficulty
    [Test worker/ERROR]: Classloader restrictions [PACKAGE_CLASSLOADER_EXCLUSION] encountered loading mixins.common.test.json:MixinGameType, name: org.spongepowered.common.launch.mixin.MixinGameType
    [Test worker/ERROR]: Classloader restrictions [PACKAGE_CLASSLOADER_EXCLUSION] encountered loading mixins.common.test.json:MixinItem, name: org.spongepowered.common.launch.mixin.MixinItem
    [Test worker/ERROR]: Classloader restrictions [PACKAGE_CLASSLOADER_EXCLUSION] encountered loading mixins.common.test.json:MixinSpongeItemStackSnapshot, name: org.spongepowered.common.launch.mixin.MixinSpongeItemStackSnapshot
    [Test worker/ERROR]: Classloader restrictions [PACKAGE_CLASSLOADER_EXCLUSION] encountered loading mixins.common.test.json:MixinStatBase, name: org.spongepowered.common.launch.mixin.MixinStatBase
    [Test worker/INFO]: Launching wrapped minecraft {org.spongepowered.common.test.TestMain}

I don't know what's going on here.

Everything else works as expected.

@ImMorpheus
Copy link
Copy Markdown
Contributor Author

~qa

@limbo-app limbo-app added status: needs review a code review is needed status: needs testing does this run, does it solve the issue etc and removed status: wip Work in progress labels Jul 2, 2018
Copy link
Copy Markdown
Member

@gabizou gabizou left a comment

Choose a reason for hiding this comment

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

Some changes, clarifications.

Comment thread src/main/java/org/spongepowered/common/mixin/core/item/MixinItemSplashPotion.java Outdated
Comment thread src/main/java/org/spongepowered/common/mixin/core/item/MixinItemSkull.java Outdated
Comment thread src/main/java/org/spongepowered/common/mixin/core/item/MixinItemPotion.java Outdated
Comment thread src/main/java/org/spongepowered/common/mixin/core/item/MixinItemBanner.java Outdated
Comment thread src/test/java/org/spongepowered/common/launch/mixin/MixinBlock.java
LOG.warn("Catalog Type: {} Id : {} has broken Method: {} ({}): {}", this.name, this.catalogId, this.methodName,
this.implementationClass, t);
return;
testResult(checkNotNull(this.method.invoke(this.catalogType), "return value"));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How is this changing how it used to work previously?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Previously, everything inside ignoredFailureswould be ignored (it would just log "x has broken method: etc.") but it was a workaround (see the TODO above). I've just removed the if and unwrapped the exception.


if (object instanceof IStringSerializable || object instanceof Fish || object instanceof CookedFish) {
if (verbose) {
LOG.info("This is probably a blockstate. Mojang doesn't directly provide translations for blockstates. Ignoring {}", translation.getId());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is fish considered untranslatable but you're saying it's probably a block state?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

AFAICT there are translations for fish!?

item.fish.cod.raw.name=Raw Fish
item.fish.salmon.raw.name=Raw Salmon
item.fish.pufferfish.raw.name=Pufferfish
item.fish.clownfish.raw.name=Clownfish
item.fish.cod.cooked.name=Cooked Fish
item.fish.salmon.cooked.name=Cooked Salmon

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Indeed. However that's net.minecraft.item.ItemFishFood.

This check should avoid net.minecraft.item.ItemFishFood.FishType

@Shadow private String unlocalizedName;

@Shadow public abstract int getItemStackLimit();
@Shadow public abstract String getUnlocalizedName();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

AFAICT this is no longer used.

ItemStack is = ItemStackUtil.fromNative(new net.minecraft.item.ItemStack((Item) (IMixinItem) this));
Optional<GameProfile> owner = is.get(Keys.REPRESENTED_PLAYER);

if (owner.isPresent()) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This cannot be present, since you just created the item or am I missing something?

@Override
public Translation getTranslation() {
return new SpongeTranslation(this.statId);
return this.translation;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Instead of statId.equals("stat.mineBlock.") you could use StatBase#statId.startsWith("stat.mineBlock.").

and instead of item you could use StatCrafting#Item

*/
package org.spongepowered.common.interfaces;

public interface MojangTranslatable {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Need javadocs that explain the purpose of this interface.


if (object instanceof IStringSerializable || object instanceof Fish || object instanceof CookedFish) {
if (verbose) {
LOG.info("This is probably a blockstate. Mojang doesn't directly provide translations for blockstates. Ignoring {}", translation.getId());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

AFAICT there are translations for fish!?

item.fish.cod.raw.name=Raw Fish
item.fish.salmon.raw.name=Raw Salmon
item.fish.pufferfish.raw.name=Pufferfish
item.fish.clownfish.raw.name=Clownfish
item.fish.cod.cooked.name=Cooked Fish
item.fish.salmon.cooked.name=Cooked Salmon

@gabizou
Copy link
Copy Markdown
Member

gabizou commented Jul 15, 2018

Sounds like it's almost ready, so with these changes the warnings are pretty much gone from all the catalog type tests? (I know I may have introduced one or two printouts with the recent PhaseTracker changes, but that I'll get to once I figure out how to beat a testing environment check without making those checks fail in production).

@ImMorpheus
Copy link
Copy Markdown
Contributor Author

so with these changes the warnings are pretty much gone from all the catalog type tests?

Correct, but as you can see from the travis log https://travis-ci.org/SpongePowered/SpongeCommon/jobs/403996687, it's still complaining about NotePitch having the same id and name. I think it's safe to ignore them (unless someone comes up with different names).

@Cybermaxke
Copy link
Copy Markdown
Contributor

Cybermaxke commented Jul 17, 2018

Ids shouldn't be uppercase, I noticed C_SHARP1 for one of the NotePitches in the log. With the CatalogKey PR, all catalog types should also get a plugin id in the future, so maybe this is the time?
minecraft:id

@ImMorpheus
Copy link
Copy Markdown
Contributor Author

That's probably a breaking change. Is it something I can do in this PR ? Input wanted

@gabizou
Copy link
Copy Markdown
Member

gabizou commented Jul 17, 2018

That's probably a breaking change. Is it something I can do in this PR ? Input wanted

I'd say it's a fix, but best to check with some plugin developers for input. @clienthax for your note block music plugin, do the catalog id's changing from previously unprefixed to correctly prefixed note pitches change anything for you? (first example I could think of at this moment).

@ST-DDT
Copy link
Copy Markdown
Member

ST-DDT commented Jul 17, 2018

There is a solution to it though. The associated registry could still return the right entries for old ids, so after the entries get loaded and saved once, you have completed the note pitch migration. Or does the config loader only use the ids for the mapping. IIRC they use GameRegistry#get(type, id).

@ImMorpheus
Copy link
Copy Markdown
Contributor Author

The thing is, NotePitch is not the only one having unprefixed ids.
Prefix everything and things like #1286 would arise. I could fix NotePitch and leave everything else to the catalogue key PR. Probably adding other tests to ensure we wont miss anything

@ImMorpheus
Copy link
Copy Markdown
Contributor Author

ImMorpheus commented Jul 18, 2018

org.spongepowered.common.registry.CatalogTypeMethodTest > testCatalogMethodImpl[87755 Catalog Type: Fish | Id : minecraft:raw.cod | Method: Fish#getCookedFish() | (net.minecraft.item.ItemFishFood$FishType)] STANDARD_OUT
    [Test worker/WARN]: id is not lowercase. Catalog Type: Fish | Id : cooked.COD | (net.minecraft.item.ItemFishFood$FishType)

org.spongepowered.common.registry.CatalogTypeMethodTest > testCatalogMethodImpl[87763 Catalog Type: Fish | Id : minecraft:raw.salmon | Method: Fish#getCookedFish() | (net.minecraft.item.ItemFishFood$FishType)] STANDARD_OUT
    [Test worker/WARN]: id is not lowercase. Catalog Type: Fish | Id : cooked.SALMON | (net.minecraft.item.ItemFishFood$FishType)

Something is not right.

EDIT: Ok, something is horribly wrong. Looks like the catalogtest was not testing every catalog type.
Thanks to @SimonFlash for making me realise that with his FireworkShape PR.

@ImMorpheus ImMorpheus force-pushed the fix/catalogtypes branch 4 times, most recently from 87beb6d to bbe521d Compare August 22, 2018 19:59
@limbo-app limbo-app added status: needs review a code review is needed status: needs testing does this run, does it solve the issue etc and removed status: wip Work in progress labels Aug 22, 2018
@ImMorpheus
Copy link
Copy Markdown
Contributor Author

ImMorpheus commented Aug 22, 2018

Updated to reflect the CatalogKey PR.

@ImMorpheus ImMorpheus added the type: bug Something isn't working label Aug 29, 2018
@ImMorpheus ImMorpheus force-pushed the fix/catalogtypes branch 3 times, most recently from 165b6f4 to 2d2b3eb Compare September 19, 2018 16:50
@ImMorpheus ImMorpheus changed the base branch from bleeding to 1.13 February 2, 2019 16:01
@ImMorpheus ImMorpheus force-pushed the fix/catalogtypes branch 4 times, most recently from 2ba45aa to 3828654 Compare February 2, 2019 16:56
@ImMorpheus ImMorpheus requested a review from Cybermaxke February 2, 2019 17:09
@Zidane Zidane closed this Dec 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: needs review a code review is needed status: needs testing does this run, does it solve the issue etc type: bug Something isn't working version: 1.16 (u) API: 8

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants