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

Cleanup of enchantments #1593

Merged

Conversation

parlough
Copy link
Contributor

@parlough parlough commented Nov 12, 2017

SpongeAPI | SpongeCommon | SpongeVanilla | SpongeForge

Read API PR for more information.

public String enchantment$getName() {
return shadow$getName();
return I18n.translateToLocal(shadow$getName());
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this change intended?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah as the getName method previously returned the translation key of "enchantment." + name. For example "enchantment.waterWalker" or similar.

@@ -436,7 +436,7 @@ public void registerDefaults() {

this.fieldMap.put("last_date_played", makeSingleKey(TypeTokens.INSTANT_TOKEN, TypeTokens.INSTANT_VALUE_TOKEN, of("LastTimePlayed"), "sponge:last_time_played", "Last Time Played"));

this.fieldMap.put("hide_enchantments", makeSingleKey(TypeTokens.BOOLEAN_TOKEN, TypeTokens.BOOLEAN_VALUE_TOKEN, of("HideEnchantments"), "sponge:hide_enchantments", "Hide Enchantments"));
this.fieldMap.put("hide_enchantments", makeSingleKey(TypeTokens.BOOLEAN_TOKEN, TypeTokens.BOOLEAN_VALUE_TOKEN, of("HideEnchantments"), "sponge:hide_enchantments", "Hide EnchantmentTypes"));
Copy link
Contributor

Choose a reason for hiding this comment

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

This one is not that much...

@@ -412,7 +412,7 @@ public void registerDefaults() {

this.fieldMap.put("persists", makeSingleKey(TypeTokens.BOOLEAN_TOKEN, TypeTokens.BOOLEAN_VALUE_TOKEN, of("Persists"), "sponge:persists", "Persists"));

this.fieldMap.put("stored_enchantments", makeListKey(TypeTokens.LIST_ITEM_ENCHANTMENT_TOKEN, TypeTokens.LIST_ITEM_ENCHANTMENT_VALUE_TOKEN, of("StoredEnchantments"), "sponge:stored_enchantments", "Stored Enchantments"));
this.fieldMap.put("stored_enchantments", makeListKey(TypeTokens.LIST_ITEM_ENCHANTMENT_TOKEN, TypeTokens.LIST_ITEM_ENCHANTMENT_VALUE_TOKEN, of("StoredEnchantments"), "sponge:stored_enchantments", "Stored EnchantmentTypes"));
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you should change these names.

this.modifierTypeMap.put("offensive_potion_effect", new SpongeDamageModifierType("Offensive PotionEffect", "offensive_potion_effect"));
this.modifierTypeMap.put("defensive_potion_effect", new SpongeDamageModifierType("Defensive PotionEffect", "defensive_potion_effect"));
this.modifierTypeMap.put("negative_potion_effect", new SpongeDamageModifierType("Negative PotionEffect", "negative_potion_effect"));
this.modifierTypeMap.put("hard_hat", new SpongeDamageModifierType("Hard Hat", "hard_hat"));
this.modifierTypeMap.put("shield", new SpongeDamageModifierType("Shield", "shield"));
this.modifierTypeMap.put("blocking", this.modifierTypeMap.get("shield"));
this.modifierTypeMap.put("armor", new SpongeDamageModifierType("Armor", "armor"));
this.modifierTypeMap.put("armor_enchantment", new SpongeDamageModifierType("Armor Enchantment", "armor_enchantment"));
this.modifierTypeMap.put("armor_enchantment", new SpongeDamageModifierType("Armor EnchantmentType", "armor_enchantment"));
Copy link
Contributor

Choose a reason for hiding this comment

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

Not these two

@@ -67,6 +69,20 @@
public class CustomInventoryTest {

@Listener
public void onBlockInteract(InteractBlockEvent event, @Root Player player) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was for some testing, will remove this later.

@parlough parlough changed the title [WIP] Cleanup of enchantments Cleanup of enchantments Nov 16, 2017
@parlough
Copy link
Contributor Author

One second, will fix the issue...

Copy link
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.

Small ages.

@@ -64,8 +64,8 @@
public static final DataQuery VELOCITY_Y = of("Y");
public static final DataQuery VELOCITY_Z = of("Z");

// Enchantments
public static final DataQuery ENCHANTMENT_ID = of("Enchantment");
Copy link
Member

Choose a reason for hiding this comment

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

This may need to be deprecated legacy versioned


@Override
public Enchantment.Builder from(final Enchantment value) {
this.enchantmentType = value.getType();
Copy link
Member

Choose a reason for hiding this comment

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

Needs a null check.

@Override
protected Optional<Enchantment> buildContent(DataView container) throws InvalidDataException {
checkNotNull(container, "The data view cannot be null!");
if (container.contains(Queries.ENCHANTMENT_ID, Queries.LEVEL)) {
Copy link
Member

Choose a reason for hiding this comment

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

Invert the if block, style change, I know, just preference. Fail fast.

if (container.contains(Queries.ENCHANTMENT_ID, Queries.LEVEL)) {
final String id = DataUtil.getData(container, Queries.ENCHANTMENT_ID, String.class);
final int level = DataUtil.getData(container, Queries.LEVEL, Integer.class);
final Optional<EnchantmentType> enchantmentType = SpongeImpl.getRegistry().getType(EnchantmentType.class, id);
Copy link
Member

Choose a reason for hiding this comment

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

SpongeImpl vs Sponge?

@Implements(@Interface(iface = Enchantment.class, prefix = "enchantment$"))
public abstract class MixinEnchantment implements Enchantment, IMixinEnchantment {
@Implements(@Interface(iface = EnchantmentType.class, prefix = "enchantment$"))
public abstract class MixinEnchantment implements IMixinEnchantment {
Copy link
Member

Choose a reason for hiding this comment

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

Why remove it? It'll still perfectly implement just fine normally.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMixinEnchantment extends Enchantment so I didn't think it was needed.

Copy link
Member

Choose a reason for hiding this comment

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

Thinking about it further, the IMixin interfaces shouldn't extend the API interfaces for the basic understanding that they are only from implementation, The only reason why there's IMixinEntity and a few others doing this is because of Java compiler requirements with potentially ambiguous methods.

@@ -20,7 +20,7 @@ public net.minecraft.command.EntitySelector func_82381_h(Ljava/lang/String;)Ljav
public net.minecraft.crash.CrashReport field_71511_b # cause
public net.minecraft.crash.CrashReportCategory field_85078_a # crashReport

public net.minecraft.enchantment.Enchantment field_180311_a # enchantmentsList
public net.minecraft.enchantmentType.Enchantment field_180311_a # enchantmentsList
Copy link
Member

Choose a reason for hiding this comment

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

typo?

@Implements(@Interface(iface = Enchantment.class, prefix = "enchantment$"))
public abstract class MixinEnchantment implements Enchantment, IMixinEnchantment {
@Implements(@Interface(iface = EnchantmentType.class, prefix = "enchantment$"))
public abstract class MixinEnchantment implements IMixinEnchantment {
Copy link
Member

Choose a reason for hiding this comment

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

Thinking about it further, the IMixin interfaces shouldn't extend the API interfaces for the basic understanding that they are only from implementation, The only reason why there's IMixinEntity and a few others doing this is because of Java compiler requirements with potentially ambiguous methods.

@ryantheleach ryantheleach added system: data type: enhancement An improvement version: 1.12 (u) API: 7 (unsupported since May 21st 2021) labels Nov 27, 2017
@ryantheleach ryantheleach added this to the API 7.0 milestone Nov 27, 2017
@parlough parlough merged commit f085786 into SpongePowered:bleeding Dec 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
system: data type: enhancement An improvement version: 1.12 (u) API: 7 (unsupported since May 21st 2021)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants