Skip to content

Commit

Permalink
1.21 Port
Browse files Browse the repository at this point in the history
  • Loading branch information
ExDrill committed Jun 20, 2024
1 parent 3f070ce commit 41cb3ce
Show file tree
Hide file tree
Showing 47 changed files with 549 additions and 235 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
matrix:
# Use these Java versions
java: [
17, # Current Java LTS & minimum supported by Minecraft
21, # Current Java LTS & minimum supported by Minecraft
]
# and run on both Linux and Windows
os: [ubuntu-22.04, windows-2022]
Expand All @@ -33,7 +33,7 @@ jobs:
- name: build
run: ./gradlew build
- name: capture build artifacts
if: ${{ runner.os == 'Linux' && matrix.java == '17' }} # Only upload artifacts built from latest java on one OS
if: ${{ runner.os == 'Linux' && matrix.java == '21' }} # Only upload artifacts built from latest java on one OS
uses: actions/upload-artifact@v3
with:
name: Artifacts
Expand Down
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
### Gameplay Changes
* Netherite Shield enchantability has been reduced. `20 -> 15`
* Barbed durability damage has been reduced. `2 -> 1`
* Barbed success chance has been increased. `20% -> 33%`

### Config Changes
* The enchantability of the Shield and Netherite Shield have been made configurable.
* Configurations for Pummeling and Barbed and projectile deflection strength have been removed.

### Technical Changes
Guarding now uses 1.21's data driven enchantments, for this reason, several configurations were removed in favor of this new system.

Added 3 new enchantment effect components:

`guarding:shield_blocked`: Effects applying after an attack is blocked.
* Condition Context: Damage Parameters
* Effect: Entity Effect
* Additional fields:
- `cancel_on_parry`: When true, stops the effects from being applied when a parry is landed
- `affected`: A specifier for whom the effect is applied to. Possible values are `attacker`, `damaging_entity`, and `victim`

`guarding:shield_parried`: Effects applying after an attack is parried.
* Condition Context: Damage Parameters
* Effect: Entity Effect
* Additional fields:
- `affected`: A specifier for whom the effect is applied to. Possible values are `attacker`, `damaging_entity`, and `victim`

`guarding:shield_knockback`: Effects for the amount of knockback to deal when an attack is blocked.
* Condition Context: Damage Parameters
* Effect: Value Effect
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx1G
org.gradle.parallel=true

# Fabric Properties
minecraft_version=1.20.6
minecraft_version=1.21
loader_version=0.15.11

# Mod Properties
Expand All @@ -11,5 +11,5 @@ org.gradle.parallel=true
archives_base_name = guarding

# Dependencies
fabric_version=0.97.8+1.20.6
sketch_version=1.20.6-1.1.0
fabric_version=0.100.3+1.21
sketch_version=1.21-1.2.0
16 changes: 7 additions & 9 deletions src/main/java/com/teamabode/guarding/Guarding.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
package com.teamabode.guarding;

import com.teamabode.guarding.core.init.*;
import com.teamabode.guarding.core.registry.*;
import com.teamabode.guarding.core.util.ShieldUtils;
import com.teamabode.sketch.core.api.config.ConfigManager;
import com.teamabode.sketch.core.api.event.ShieldEvents;
import net.fabricmc.api.ModInitializer;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Guarding implements ModInitializer {
public static final String MOD_ID = "guarding";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);

public static final TagKey<Item> SHIELD_ENCHANTABLE = TagKey.create(Registries.ITEM, id("enchantable/shield"));

public void onInitialize() {
GuardingItems.init();
GuardingEnchantments.init();
GuardingEnchantmentEffects.init();
GuardingSounds.init();
GuardingParticles.init();
GuardingCallbacks.init();
GuardingCritieriaTriggers.init();
GuardingRecipeSerializers.init();

ShieldEvents.BLOCKED.register(ShieldUtils::onBlocked);
ConfigManager.INSTANCE.register(GuardingConfig.INSTANCE);
}

public static ResourceLocation id(String name) {
return new ResourceLocation(MOD_ID, name);
return ResourceLocation.fromNamespaceAndPath(MOD_ID, name);
}
}
19 changes: 8 additions & 11 deletions src/main/java/com/teamabode/guarding/GuardingConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,25 @@

import com.teamabode.sketch.core.api.config.Config;
import com.teamabode.sketch.core.api.config.FloatProperty;
import com.teamabode.sketch.core.api.config.IntProperty;

// TODO: Item to int map property which allows custom shields to be given enchantibility.
public class GuardingConfig extends Config {
public static final GuardingConfig INSTANCE = new GuardingConfig();

public final FloatProperty exhaustionCost;
public final FloatProperty knockbackStrength;
public final FloatProperty projectileReflectStrength;
public final FloatProperty damageAmount;
public final FloatProperty damageChance;
public final FloatProperty additionalKnockbackStrengthPerLevel;
public final IntProperty shieldEnchantibility;
public final IntProperty netheriteShieldEnchantibility;

public GuardingConfig() {
super("guarding");
this.exhaustionCost = new FloatProperty("exhaustion_cost", 2.0f);
this.knockbackStrength = new FloatProperty("knockback_strength", 0.5f);
this.projectileReflectStrength = new FloatProperty("projectile_reflect_strength", 1.25f);
this.damageAmount = new FloatProperty("damage_amount", 2.0f);
this.damageChance = new FloatProperty("damage_chance", 0.2f);
this.additionalKnockbackStrengthPerLevel = new FloatProperty("additional_knockback_strength_per_level", 0.15f);
this.shieldEnchantibility = new IntProperty("minecraft:shield", 9);
this.netheriteShieldEnchantibility = new IntProperty("guarding:netherite_shield", 15);

this.defineCategory("parry", this.exhaustionCost, this.knockbackStrength, this.projectileReflectStrength);
this.defineCategory("barbed", this.damageAmount, this.damageChance);
this.defineCategory("pummeling", this.additionalKnockbackStrengthPerLevel);
this.defineCategory("parry", this.exhaustionCost, this.knockbackStrength);
this.defineCategory("enchantability", this.shieldEnchantibility, this.netheriteShieldEnchantibility);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import com.teamabode.guarding.client.model.NetheriteShieldModel;
import com.teamabode.guarding.client.particle.ParryParticle;
import com.teamabode.guarding.client.render.NetheriteShieldRenderer;
import com.teamabode.guarding.core.init.GuardingItems;
import com.teamabode.guarding.core.init.GuardingParticles;
import com.teamabode.guarding.core.registry.GuardingItems;
import com.teamabode.guarding.core.registry.GuardingParticles;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.particle.v1.ParticleFactoryRegistry;
import net.fabricmc.fabric.api.client.rendering.v1.BuiltinItemRendererRegistry;
Expand All @@ -29,7 +29,7 @@ private static void netheriteShield() {
NetheriteShieldRenderer renderer = new NetheriteShieldRenderer();
BuiltinItemRendererRegistry.INSTANCE.register(GuardingItems.NETHERITE_SHIELD, renderer);
ResourceManagerHelper.get(PackType.CLIENT_RESOURCES).registerReloadListener(renderer);
ItemProperties.register(GuardingItems.NETHERITE_SHIELD, new ResourceLocation(Guarding.MOD_ID,"blocking"), GuardingClient::blockingPredicate);
ItemProperties.register(GuardingItems.NETHERITE_SHIELD, Guarding.id("blocking"), GuardingClient::blockingPredicate);
}

private static float blockingPredicate(ItemStack stack, ClientLevel level, LivingEntity user, int i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import net.minecraft.world.item.armortrim.ArmorTrim;

public class NetheriteShieldModel extends ShieldModel {
public static final ModelLayerLocation LAYER = new ModelLayerLocation(new ResourceLocation(Guarding.MOD_ID, "netherite_shield"), "main");
public static final ResourceLocation TEXTURE = new ResourceLocation(Guarding.MOD_ID, "textures/entity/netherite_shield.png");
public static final ModelLayerLocation LAYER = new ModelLayerLocation(Guarding.id("netherite_shield"), "main");
public static final ResourceLocation TEXTURE = Guarding.id("textures/entity/netherite_shield.png");

private final TextureAtlas atlas;

Expand All @@ -31,11 +31,11 @@ public void renderTrim(PoseStack poseStack, MultiBufferSource bufferSource, int
TextureAtlasSprite sprite = atlas.getSprite(trimTexture(trim));

VertexConsumer vertex = sprite.wrap(bufferSource.getBuffer(RenderType.entityCutout(Sheets.ARMOR_TRIMS_SHEET)));
this.renderToBuffer(poseStack, vertex, light, OverlayTexture.NO_OVERLAY, 1.0f, 1.0f, 1.0f, 1.0f);
this.renderToBuffer(poseStack, vertex, light, OverlayTexture.NO_OVERLAY);
}

public void renderGlint(PoseStack poseStack, MultiBufferSource bufferSource, int light) {
this.renderToBuffer(poseStack, ItemRenderer.getFoilBuffer(bufferSource, RenderType.armorGlint(), false, true), light, OverlayTexture.NO_OVERLAY, 1.0f, 1.0f, 1.0f, 1.0f);
this.renderToBuffer(poseStack, ItemRenderer.getFoilBuffer(bufferSource, RenderType.armorEntityGlint(), false, true), light, OverlayTexture.NO_OVERLAY);
}

private static ResourceLocation trimTexture(ArmorTrim trim) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ public class NetheriteShieldRenderer implements BuiltinItemRendererRegistry.Dyna
private NetheriteShieldModel model;

public ResourceLocation getFabricId() {
return new ResourceLocation(Guarding.MOD_ID, "netherite_shield_renderer");
return Guarding.id("netherite_shield_renderer");
}

public void render(ItemStack stack, ItemDisplayContext displayContext, PoseStack poseStack, MultiBufferSource bufferSource, int light, int overlay) {
poseStack.pushPose();
poseStack.scale(1.0f, -1.0f, -1.0f);

VertexConsumer buffer = bufferSource.getBuffer(model.renderType(NetheriteShieldModel.TEXTURE));
model.renderToBuffer(poseStack, buffer, light, overlay, 1.0f, 1.0f, 1.0f, 1.0f);
model.renderToBuffer(poseStack, buffer, light, overlay);

ClientLevel level = Minecraft.getInstance().level;
if (level != null && stack.has(DataComponents.TRIM)) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.teamabode.guarding.common.enchantment;

import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.world.item.enchantment.ConditionalEffect;
import net.minecraft.world.item.enchantment.EnchantmentTarget;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSet;
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;

import java.util.Optional;

public record BlockedConditionalEffect<T>(EnchantmentTarget affected, T effect, boolean cancelOnParry, Optional<LootItemCondition> requirements) {

public static <S> Codec<BlockedConditionalEffect<S>> parriedCodec(Codec<S> codec, LootContextParamSet contextSet) {
return RecordCodecBuilder.create(instance -> instance.group(
EnchantmentTarget.CODEC.fieldOf("affected").forGetter(BlockedConditionalEffect::affected),
codec.fieldOf("effect").forGetter(BlockedConditionalEffect::effect),
ConditionalEffect.conditionCodec(contextSet).optionalFieldOf("requirements").forGetter(BlockedConditionalEffect::requirements)
).apply(instance, (affected, effect, requirements) -> new BlockedConditionalEffect<>(affected, effect, false, requirements)));
}

public static <S> Codec<BlockedConditionalEffect<S>> codec(Codec<S> codec, LootContextParamSet contextSet) {
return RecordCodecBuilder.create(instance -> instance.group(
EnchantmentTarget.CODEC.fieldOf("affected").forGetter(BlockedConditionalEffect::affected),
codec.fieldOf("effect").forGetter(BlockedConditionalEffect::effect),
Codec.BOOL.fieldOf("cancel_on_parry").forGetter(BlockedConditionalEffect::cancelOnParry),
ConditionalEffect.conditionCodec(contextSet).optionalFieldOf("requirements").forGetter(BlockedConditionalEffect::requirements)
).apply(instance, BlockedConditionalEffect::new));
}

public boolean matches(LootContext lootContext) {
return this.requirements.map(lootItemCondition -> lootItemCondition.test(lootContext)).orElse(true);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.teamabode.guarding.common.enchantment;

import net.minecraft.core.Holder;
import net.minecraft.world.item.enchantment.Enchantment;

@FunctionalInterface
public interface EnchantmentConsumer {
void accept(Holder<Enchantment> holder, int level);
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.teamabode.guarding.common.item;

import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Multimap;
import com.teamabode.guarding.core.init.GuardingSounds;
import com.teamabode.guarding.Guarding;
import com.teamabode.guarding.GuardingConfig;
import com.teamabode.guarding.core.registry.GuardingSounds;
import net.minecraft.core.Holder;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.EquipmentSlotGroup;
import net.minecraft.world.entity.ai.attributes.Attribute;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.item.ItemStack;
Expand All @@ -20,6 +19,8 @@
import java.util.function.Supplier;

public class NetheriteShieldItem extends ShieldItem {
private static final ResourceLocation KNOCKBACK_RESISTANCE = Guarding.id("knockback_resistance");

private static final UUID MODIIFER_UUID = UUID.fromString("8b128327-f878-4e94-ada2-707cd81b13af");
private final Supplier<ItemAttributeModifiers> defaultModifiers;

Expand All @@ -28,7 +29,7 @@ public NetheriteShieldItem(Properties properties) {

this.defaultModifiers = Suppliers.memoize(() -> {
ItemAttributeModifiers.Builder builder = ItemAttributeModifiers.builder();
builder.add(Attributes.KNOCKBACK_RESISTANCE, new AttributeModifier(MODIIFER_UUID, "Shield modifier", 0.1d, AttributeModifier.Operation.ADD_VALUE), EquipmentSlotGroup.OFFHAND);
builder.add(Attributes.KNOCKBACK_RESISTANCE, new AttributeModifier(KNOCKBACK_RESISTANCE, 0.1d, AttributeModifier.Operation.ADD_VALUE), EquipmentSlotGroup.OFFHAND);
return builder.build();
});
}
Expand All @@ -39,7 +40,7 @@ public ItemAttributeModifiers getDefaultAttributeModifiers() {
}

public int getEnchantmentValue() {
return 15;
return GuardingConfig.INSTANCE.netheriteShieldEnchantibility.get();
}

public Holder<SoundEvent> getEquipSound() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
package com.teamabode.guarding.common.recipe;

import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import com.teamabode.guarding.Guarding;
import com.teamabode.guarding.core.init.GuardingRecipeSerializers;
import com.teamabode.guarding.core.registry.GuardingRecipeSerializers;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.RegistryAccess;
import net.minecraft.core.component.DataComponents;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.Container;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.item.crafting.SmithingRecipe;
import net.minecraft.world.item.crafting.SmithingRecipeInput;
import net.minecraft.world.level.Level;

import java.util.stream.Stream;
Expand All @@ -32,30 +26,23 @@ public record SmithingTransformShieldRecipe(Ingredient template, Ingredient base

public static final StreamCodec<RegistryFriendlyByteBuf, SmithingTransformShieldRecipe> STREAM_CODEC = StreamCodec.of(Serializer::toNetwork, Serializer::fromNetwork);

public SmithingTransformShieldRecipe(Ingredient template, Ingredient base, Ingredient addition, ItemStack result) {
this.template = template;
this.base = base;
this.addition = addition;
this.result = result;
}

@Override
public boolean matches(Container container, Level level) {
return this.template.test(container.getItem(0)) && this.base.test(container.getItem(1)) && this.addition.test(container.getItem(2));
public boolean matches(SmithingRecipeInput input, Level level) {
return this.template.test(input.template()) && this.base.test(input.base()) && this.addition.test(input.addition());
}

@Override
public ItemStack assemble(Container container, HolderLookup.Provider provider) {
ItemStack itemStack = container.getItem(1).transmuteCopy(this.result.getItem(), this.result.getCount());
public ItemStack assemble(SmithingRecipeInput input, HolderLookup.Provider provider) {
ItemStack stack = input.base().transmuteCopy(this.result.getItem(), this.result.getCount());

if (itemStack.has(DataComponents.BASE_COLOR)) {
itemStack.remove(DataComponents.BASE_COLOR);
if (stack.has(DataComponents.BASE_COLOR)) {
stack.remove(DataComponents.BASE_COLOR);
}
if (itemStack.has(DataComponents.BANNER_PATTERNS)) {
itemStack.remove(DataComponents.BANNER_PATTERNS);
if (stack.has(DataComponents.BANNER_PATTERNS)) {
stack.remove(DataComponents.BANNER_PATTERNS);
}
itemStack.applyComponents(this.result.getComponentsPatch());
return itemStack;
stack.applyComponents(this.result.getComponentsPatch());
return stack;
}

@Override
Expand Down
Loading

0 comments on commit 41cb3ce

Please sign in to comment.