Skip to content

Commit

Permalink
Merge pull request #192 from CringeStar/1.21.4
Browse files Browse the repository at this point in the history
Update to 1.21.4
  • Loading branch information
StellarWind22 authored Jan 20, 2025
2 parents ef8c6fd + 5011969 commit cbe22e8
Show file tree
Hide file tree
Showing 27 changed files with 336 additions and 266 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ library is distributed via [jitpack.io](https://jitpack.io/#CrimsonDawn45/Fabric

#### put this in gradle.properties
```properties
fabric_shield_lib_version=1.7.2-1.21.1
fabric_shield_lib_version=1.8.0-1.21.4
```

#### build.gradle under repositories just above dependencies
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ dependencies {
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"



//Mod Menu
modCompileOnly modRuntimeOnly ("com.terraformersmc:modmenu:${project.mod_menu_version}"), {
exclude(group: "net.fabricmc.fabric-api")
}

//Fabric ASM
modImplementation("com.github.Chocohead:Fabric-ASM:v2.3") {
exclude (group: "net.fabricmc.fabric-api")
Expand All @@ -38,8 +40,6 @@ dependencies {
modImplementation "maven.modrinth:midnightlib:${project.midnightlib_version}"
include "maven.modrinth:midnightlib:${project.midnightlib_version}"

// Mixin Extras
include(implementation(annotationProcessor("io.github.llamalad7:mixinextras-fabric:${mixinextras_version}")))
}

processResources {
Expand Down
13 changes: 6 additions & 7 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/develop/
minecraft_version=1.21.3
yarn_mappings=1.21.3+build.2
minecraft_version=1.21.4
yarn_mappings=1.21.4+build.4
loader_version=0.16.9

# Mod Properties
mod_version=1.8.0-1.21.3
mod_version=1.8.0-1.21.4
maven_group=com.github.crimsondawn45
archives_base_name=FabricShieldLib

# Dependencies
fabric_version=0.106.1+1.21.3
mod_menu_version=12.0.0-beta.1
midnightlib_version=1.5.8-fabric
mixinextras_version=0.4.1
fabric_version=0.114.3+1.21.4
mod_menu_version=13.0.0
midnightlib_version=1.6.6-fabric
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.21 2024-08-17T22:36:15.9204123 Fabric Shield Lib/FabricShieldLibEnchantmentGenerator
// 1.21.3 2024-12-31T11:01:40.5595807 Fabric Shield Lib/FabricShieldLibEnchantmentGenerator
a315763c245701a58241df5b075f5208c35d3829 data\fabricshieldlib\enchantment\reflect.json
20 changes: 0 additions & 20 deletions src/main/generated/data/fabricshieldlib/enchantment/reflect.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
package com.github.crimsondawn45.fabricshieldlib.initializers;

import com.github.crimsondawn45.fabricshieldlib.lib.config.FabricShieldLibConfig;
import com.github.crimsondawn45.fabricshieldlib.lib.event.ShieldBlockCallback;
import com.github.crimsondawn45.fabricshieldlib.lib.event.ShieldDisabledCallback;
import com.github.crimsondawn45.fabricshieldlib.lib.object.FabricBannerShieldItem;
import com.github.crimsondawn45.fabricshieldlib.lib.object.FabricShieldDecoratorRecipe;
import com.github.crimsondawn45.fabricshieldlib.lib.object.FabricShieldItem;
import com.github.crimsondawn45.fabricshieldlib.lib.object.FabricShieldLibDataGenerator;
//import com.github.crimsondawn45.fabricshieldlib.lib.object.FabricShieldLibDataGenerator;
import com.github.crimsondawn45.fabricshieldlib.lib.object.FabricShieldModelComponent;
import eu.midnightdust.lib.config.MidnightConfig;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.component.ComponentType;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroups;
import net.minecraft.item.Items;
Expand All @@ -27,16 +21,12 @@
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Identifier;
import net.minecraft.world.World;

import java.util.function.Function;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.function.Function;

/**
* Main class for Fabric Shield Lib.
*/
Expand All @@ -63,6 +53,9 @@ public class FabricShieldLib implements ModInitializer {
*/
public static FabricShieldItem fabric_shield;

public static ComponentType<FabricShieldModelComponent> MODEL_COMPONENT;



/**
* Recipe type and serializer for banner decoration recipe.
Expand All @@ -87,14 +80,16 @@ public void onInitialize() {
//Register Config
MidnightConfig.init(MOD_ID, FabricShieldLibConfig.class);

MODEL_COMPONENT = Registry.register(Registries.DATA_COMPONENT_TYPE, Identifier.of(MOD_ID, "shieldlibmodelcomponent"), ComponentType.<FabricShieldModelComponent>builder().codec(FabricShieldModelComponent.CODEC).build());

//Dev environment code.
if(FabricLoader.getInstance().isDevelopmentEnvironment()) {

//Warn about dev code
logger.warn("FABRIC SHIELD LIB DEVELOPMENT CODE RAN!!!, if you are not in a development environment this is very bad! Test items and test enchantments will be ingame!");

//Register Custom Shield
fabric_banner_shield = registerItem("fabric_banner_shield", (props) -> new FabricBannerShieldItem(props.maxDamage(336), 85, 9, Items.OAK_PLANKS, Items.SPRUCE_PLANKS));
fabric_banner_shield = registerItem("fabric_banner_shield", (props) -> new FabricBannerShieldItem(props.maxDamage(336).component(MODEL_COMPONENT, new FabricShieldModelComponent(FabricShieldLibClient.FABRIC_BANNER_SHIELD_BASE.getTextureId(), FabricShieldLibClient.FABRIC_BANNER_SHIELD_BASE_NO_PATTERN.getTextureId(), FabricShieldLibClient.fabric_banner_shield_model_layer.toString())), 85, 9, Items.OAK_PLANKS, Items.SPRUCE_PLANKS));

fabric_shield = registerItem("fabric_shield", (props) -> new FabricShieldItem(props.maxDamage(336), 100, 9, Items.OAK_PLANKS, Items.SPRUCE_PLANKS));

Expand All @@ -103,37 +98,40 @@ public void onInitialize() {
entries.addAfter(fabric_banner_shield,fabric_shield);
});




//Test event: makes any shield with new enchantment reflect a 1/3rd of damage back to attacker
ShieldBlockCallback.EVENT.register((defender, source, amount, hand, shield) -> {

RegistryKey<Enchantment> key = FabricShieldLibDataGenerator.EnchantmentGenerator.REFLECTION;
RegistryEntry<Enchantment> entry = defender.getWorld().getRegistryManager().getOrThrow(RegistryKeys.ENCHANTMENT).getEntry(key.getValue()).get();
int reflectNumber = EnchantmentHelper.getLevel(entry, shield);

if(reflectNumber > 0) {
Entity attacker = source.getAttacker();

if(attacker.equals(null)) {
return ActionResult.CONSUME;
}
if(defender.blockedByShield(source)){
World world = attacker.getWorld();
if(defender instanceof PlayerEntity) { //Defender should always be a player, but check anyway
attacker.sidedDamage(world.getDamageSources().playerAttack((PlayerEntity) defender), Math.round(amount * 0.33F));
} else {
attacker.sidedDamage(world.getDamageSources().mobAttack(defender), Math.round(amount * 0.33F));
}
}
}

return ActionResult.PASS;
});
// ShieldBlockCallback.EVENT.register((defender, source, amount, hand, shield) -> {
//
// RegistryKey<Enchantment> key = FabricShieldLibDataGenerator.EnchantmentGenerator.REFLECTION;
// RegistryEntry<Enchantment> entry = defender.getWorld().getRegistryManager().getOrThrow(RegistryKeys.ENCHANTMENT).getEntry(key.getValue()).get();
// int reflectNumber = EnchantmentHelper.getLevel(entry, shield);
//
// if(reflectNumber > 0) {
// Entity attacker = source.getAttacker();
//
// if(attacker.equals(null)) {
// return ActionResult.CONSUME;
// }
// if(defender.blockedByShield(source)){
// World world = attacker.getWorld();
// if(defender instanceof PlayerEntity) { //Defender should always be a player, but check anyway
// attacker.sidedDamage(world.getDamageSources().playerAttack((PlayerEntity) defender), Math.round(amount * 0.33F));
// } else {
// attacker.sidedDamage(world.getDamageSources().mobAttack(defender), Math.round(amount * 0.33F));
// }
// }
// }
//
// return ActionResult.PASS;
// });

//Test Event: if your shield gets disabled, give player speed
ShieldDisabledCallback.EVENT.register((defender, hand, shield) -> {
defender.addStatusEffect(new StatusEffectInstance(StatusEffects.SPEED, 10, 1, true, false));
return ActionResult.PASS;
});
// ShieldDisabledCallback.EVENT.register((defender, hand, shield) -> {
// defender.addStatusEffect(new StatusEffectInstance(StatusEffects.SPEED, 10, 1, true, false));
// return ActionResult.PASS;
// });
}
//Announce having finished starting up
logger.info("Fabric Shield Lib Initialized!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,26 @@
import com.github.crimsondawn45.fabricshieldlib.lib.config.FabricShieldLibConfig;
import com.github.crimsondawn45.fabricshieldlib.lib.event.ShieldSetModelCallback;
import com.github.crimsondawn45.fabricshieldlib.lib.object.FabricShield;
import com.github.crimsondawn45.fabricshieldlib.lib.object.FabricShieldModelRenderer;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.item.v1.ItemTooltipCallback;
import net.fabricmc.fabric.api.client.rendering.v1.BuiltinItemRendererRegistry;
import net.fabricmc.fabric.api.client.rendering.v1.EntityModelLayerRegistry;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.block.entity.BannerBlockEntityRenderer;
import net.minecraft.client.render.entity.model.EntityModelLayer;
import net.minecraft.client.render.entity.model.ShieldEntityModel;
import net.minecraft.client.render.item.ItemRenderer;
import net.minecraft.client.render.item.model.special.SpecialModelTypes;
import net.minecraft.client.texture.SpriteAtlasTexture;
import net.minecraft.client.util.SpriteIdentifier;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.BannerPatternsComponent;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.item.tooltip.TooltipType;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.util.DyeColor;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;


public class FabricShieldLibClient implements ClientModInitializer {
Expand All @@ -48,6 +40,8 @@ public class FabricShieldLibClient implements ClientModInitializer {
@Override
public void onInitializeClient() {

SpecialModelTypes.ID_MAPPER.put(Identifier.of("fabricshieldlib", "fabric_banner_shield"), FabricShieldModelRenderer.Unbaked.CODEC);

/*
* Register tooltip callback this is the same as mixing into the end of:
* ItemStack.getTooltip()
Expand All @@ -65,7 +59,7 @@ public void onInitializeClient() {

//Add cooldown tooltip
if(shield.displayTooltip()) {
getCooldownTooltip(stack, type ,tooltip, shield.getCoolDownTicks());
getCooldownTooltip(stack, type ,tooltip, shield.getCoolDownTicks(stack));
}
}

Expand All @@ -90,34 +84,7 @@ public void onInitializeClient() {
return ActionResult.PASS;
});

//Register renderer
BuiltinItemRendererRegistry.INSTANCE.register(FabricShieldLib.fabric_banner_shield, (stack, mode, matrices, vertexConsumers, light, overlay) -> {
renderBanner(stack, matrices, vertexConsumers, light, overlay, modelFabricShield, FABRIC_BANNER_SHIELD_BASE, FABRIC_BANNER_SHIELD_BASE_NO_PATTERN);
});
}
}

/**
* Used to simplify the mixin on the user end to make their shield render banner.
*
* Uses params from the mixin method, and the model and sprite identifiers made by the player.
*/
public static void renderBanner(ItemStack stack, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay, ShieldEntityModel model, SpriteIdentifier base, SpriteIdentifier base_nopattern){
BannerPatternsComponent bannerPatternsComponent = (BannerPatternsComponent)stack.getOrDefault(DataComponentTypes.BANNER_PATTERNS, BannerPatternsComponent.DEFAULT);
DyeColor dyeColor2 = (DyeColor)stack.get(DataComponentTypes.BASE_COLOR);
boolean bl = !bannerPatternsComponent.layers().isEmpty() || dyeColor2 != null;
matrices.push();
matrices.scale(1.0F, -1.0F, -1.0F);
SpriteIdentifier spriteIdentifier = bl ? base : base_nopattern;
VertexConsumer vertexConsumer = spriteIdentifier.getSprite().getTextureSpecificVertexConsumer(ItemRenderer.getItemGlintConsumer(vertexConsumers, model.getLayer(spriteIdentifier.getAtlasId()), true, stack.hasGlint()));
model.getHandle().render(matrices, vertexConsumer, light, overlay);
if (bl) {
BannerBlockEntityRenderer.renderCanvas(matrices, vertexConsumers, light, overlay, model.getPlate(), spriteIdentifier, false, (DyeColor) Objects.requireNonNullElse(dyeColor2, DyeColor.WHITE), bannerPatternsComponent, stack.hasGlint(), true);
} else {
model.getPlate().render(matrices, vertexConsumer, light, overlay);
}

matrices.pop();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.client.render.entity.model.EntityModelLoader;
import net.minecraft.client.render.entity.model.LoadedEntityModels;
import net.minecraft.util.ActionResult;

public interface ShieldSetModelCallback {
Expand All @@ -23,5 +23,5 @@ public interface ShieldSetModelCallback {
return ActionResult.PASS;
});

ActionResult setModel(EntityModelLoader loader);
ActionResult setModel(LoadedEntityModels loader);
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.github.crimsondawn45.fabricshieldlib.lib.object;

import net.minecraft.component.DataComponentTypes;
import net.minecraft.item.*;
import net.minecraft.item.BannerItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ToolMaterial;
import net.minecraft.item.tooltip.TooltipType;
import net.minecraft.registry.tag.TagKey;
import net.minecraft.text.Text;
import net.minecraft.util.*;
import net.minecraft.util.DyeColor;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.minecraft.item.ItemStack;
import net.minecraft.item.tooltip.TooltipType;
import net.minecraft.text.Text;
import org.jetbrains.annotations.Nullable;

import java.util.List;

Expand All @@ -17,7 +18,7 @@ public interface FabricShield {
*
* @return how many ticks shield will be disabled for when it with axe.
*/
default int getCoolDownTicks() {
default int getCoolDownTicks(@Nullable ItemStack itemStack) {
return 100;
}

Expand Down
Loading

0 comments on commit cbe22e8

Please sign in to comment.