Skip to content

Commit

Permalink
feat: merge armor trim implementation
Browse files Browse the repository at this point in the history
Merges #4143

Signed-off-by: Gabriel Harris-Rouquette <[email protected]>
  • Loading branch information
gabizou committed Nov 3, 2024
2 parents b26d6db + 033ca7e commit 33daf3d
Show file tree
Hide file tree
Showing 11 changed files with 789 additions and 563 deletions.
5 changes: 3 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
root = true

[*mixins*.json]
indent_size = 4

[*]
charset = utf-8
end_of_line = lf
Expand All @@ -9,8 +12,6 @@ insert_final_newline = false
max_line_length = 120
tab_width = 4

[*mixins*.json]
indent_size = 4

[*.yaml]
indent_size = 2
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,24 @@ private static List<Generator> generators(final Context context) {
$ -> true,
RegistryScope.GAME
),
new RegistryEntriesGenerator<>(
"item.recipe.smithing",
"TrimMaterials",
"TRIM_MATERIAL",
context.relativeClass("item.recipe.smithing", "TrimMaterial"),
Registries.TRIM_MATERIAL,
$ ->true,
RegistryScope.SERVER
),
new RegistryEntriesGenerator<>(
"item.recipe.smithing",
"TrimPatterns",
"TRIM_PATTERN",
context.relativeClass("item.recipe.smithing", "TrimPattern"),
Registries.TRIM_PATTERN,
$ -> true,
RegistryScope.SERVER
),
new RegistryEntriesGenerator<>(
"data.type",
"VillagerTypes",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@
*/
package org.spongepowered.common.data.provider.item.stack;

import net.minecraft.core.component.DataComponents;
import net.minecraft.world.item.ArmorItem;
import net.minecraft.world.item.ItemStack;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.spongepowered.api.data.Keys;
import org.spongepowered.api.data.type.ArmorMaterial;
import org.spongepowered.api.item.inventory.equipment.EquipmentTypes;
import org.spongepowered.api.item.recipe.smithing.ArmorTrim;
import org.spongepowered.common.data.provider.DataProviderRegistrator;

public final class ArmorItemStackData {
Expand All @@ -48,6 +51,23 @@ public static void register(final DataProviderRegistrator registrator) {
return null;
})
.supports(h -> h.getItem() instanceof ArmorItem)
.create(Keys.ARMOR_TRIM)
.get(h -> {
final net.minecraft.world.item.armortrim.@Nullable ArmorTrim trim = h.get(DataComponents.TRIM);
if (trim != null) {
return (ArmorTrim) (Object) trim;
}
return null;
})
.set((h, v) -> {
if (v == null) {
h.remove(DataComponents.TRIM);
return;
}
h.set(DataComponents.TRIM, (net.minecraft.world.item.armortrim.ArmorTrim) v);
})
.delete(h -> h.remove(DataComponents.TRIM))
.supports(h -> h.getItem() instanceof ArmorItem)
.create(Keys.DAMAGE_ABSORPTION)
.get(h -> {
if (h.getItem() instanceof ArmorItem armorItem) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ public static void register(final DataProviderRegistrator registrator) {
.get(h -> h.has(DataComponents.CAN_BREAK) && !h.get(DataComponents.CAN_BREAK).showInTooltip())
.set((h, v) -> h.set(DataComponents.CAN_BREAK, HideFlagsItemStackData.newAdventureModePredicate(h, !v)))
.create(Keys.HIDE_CAN_PLACE)
.get(h -> h.has(DataComponents.CAN_PLACE_ON) && !h.get(DataComponents.CAN_BREAK).showInTooltip())
.get(h -> {
final var predicate = h.get(DataComponents.CAN_BREAK);
if (predicate == null) {
return false;
}
return !predicate.showInTooltip();
})
.set((h, v) -> h.set(DataComponents.CAN_PLACE_ON, HideFlagsItemStackData.newAdventureModePredicate(h, !v)))
.create(Keys.HIDE_ENCHANTMENTS)
.get(h -> ((ItemEnchantmentsAccessor)h.getOrDefault(DataComponents.ENCHANTMENTS, ItemEnchantments.EMPTY)).accessor$showInTooltip())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* This file is part of Sponge, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.common.item.recipe.smithing;

import net.minecraft.core.Registry;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.item.recipe.smithing.ArmorTrim;
import org.spongepowered.api.item.recipe.smithing.TrimMaterial;
import org.spongepowered.api.item.recipe.smithing.TrimPattern;
import org.spongepowered.api.registry.RegistryTypes;

public class SpongeArmorTrimFactory implements ArmorTrim.Factory {

@Override
public ArmorTrim create(TrimMaterial material, TrimPattern pattern) {

final var trimRegistry = Sponge.server().registry(RegistryTypes.TRIM_MATERIAL);
final var patternRegistry = Sponge.server().registry(RegistryTypes.TRIM_PATTERN);

final var materialHolder = ((Registry<net.minecraft.world.item.armortrim.TrimMaterial>) trimRegistry).wrapAsHolder((net.minecraft.world.item.armortrim.TrimMaterial) (Object) material);
final var patternHolder = ((Registry<net.minecraft.world.item.armortrim.TrimPattern>) patternRegistry).wrapAsHolder((net.minecraft.world.item.armortrim.TrimPattern) (Object) pattern);
return (ArmorTrim) new net.minecraft.world.item.armortrim.ArmorTrim(materialHolder, patternHolder);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.spongepowered.api.item.inventory.ItemStackComparators;
import org.spongepowered.api.item.inventory.ItemStackSnapshot;
import org.spongepowered.api.item.recipe.crafting.RecipeInput;
import org.spongepowered.api.item.recipe.smithing.ArmorTrim;
import org.spongepowered.api.network.channel.ChannelExceptionHandler;
import org.spongepowered.api.network.status.Favicon;
import org.spongepowered.api.profile.GameProfile;
Expand Down Expand Up @@ -130,6 +131,7 @@
import org.spongepowered.common.item.SpongeItemStackSnapshot;
import org.spongepowered.common.item.SpongeToolRuleFactory;
import org.spongepowered.common.item.recipe.SpongeRecipeInputFactory;
import org.spongepowered.common.item.recipe.smithing.SpongeArmorTrimFactory;
import org.spongepowered.common.item.util.SpongeItemStackComparatorFactory;
import org.spongepowered.common.network.channel.SpongeChannelExceptionHandlerFactory;
import org.spongepowered.common.network.status.SpongeFavicon;
Expand Down Expand Up @@ -290,6 +292,7 @@ public void registerDefaultFactories() {
.registerFactory(ToolRule.Factory.class, new SpongeToolRuleFactory())
.registerFactory(PortalLogic.Factory.class, new SpongePortalLogicFactory())
.registerFactory(RecipeInput.Factory.class, new SpongeRecipeInputFactory())
.registerFactory(ArmorTrim.Factory.class, new SpongeArmorTrimFactory())
;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* This file is part of Sponge, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.common.mixin.api.minecraft.world.item.armortrim;

import net.minecraft.core.Holder;
import net.minecraft.world.item.armortrim.ArmorTrim;
import org.spongepowered.api.item.recipe.smithing.TrimMaterial;
import org.spongepowered.api.item.recipe.smithing.TrimPattern;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

@Mixin(ArmorTrim.class)
public abstract class ArmorTrimMixin_API implements org.spongepowered.api.item.recipe.smithing.ArmorTrim {

// @formatter:off
@Shadow public abstract Holder<net.minecraft.world.item.armortrim.TrimMaterial> shadow$material();
@Shadow public abstract Holder<net.minecraft.world.item.armortrim.TrimPattern> shadow$pattern();
// @formatter:on

@Override
public TrimMaterial material() {
return (TrimMaterial) this.shadow$material();
}

@Override
public TrimPattern pattern() {
return (TrimPattern) this.shadow$pattern();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* This file is part of Sponge, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.common.mixin.api.minecraft.world.item.armortrim;

import net.minecraft.world.item.armortrim.TrimMaterial;
import org.spongepowered.asm.mixin.Mixin;

@Mixin(TrimMaterial.class)
public class TrimMaterialMixin_API implements org.spongepowered.api.item.recipe.smithing.TrimMaterial {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* This file is part of Sponge, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.common.mixin.api.minecraft.world.item.armortrim;

import net.minecraft.world.item.armortrim.TrimPattern;
import org.spongepowered.asm.mixin.Mixin;

@Mixin(TrimPattern.class)
public class TrimPatternMixin_API implements org.spongepowered.api.item.recipe.smithing.TrimPattern {
}
Loading

0 comments on commit 33daf3d

Please sign in to comment.