Skip to content

Commit

Permalink
Merge pull request #182 from rikka0w0/main
Browse files Browse the repository at this point in the history
Port to 1.21.3 and optimize the implementation
  • Loading branch information
CringeStar authored Dec 31, 2024
2 parents 7cbf764 + b70049a commit ef8c6fd
Show file tree
Hide file tree
Showing 21 changed files with 243 additions and 483 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: validate gradle wrapper
uses: gradle/wrapper-validation-action@v1
- name: setup jdk ${{ matrix.java }}
Expand All @@ -33,7 +33,7 @@ jobs:
run: ./gradlew build
- name: capture build artifacts
if: ${{ runner.os == 'Linux' && matrix.java == '21' }} # Only upload artifacts built from the latest java on one OS
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: Artifacts
path: build/libs/
5 changes: 4 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.6-SNAPSHOT'
id 'fabric-loom' version '1.9-SNAPSHOT'
id 'maven-publish'
}

Expand Down Expand Up @@ -37,6 +37,9 @@ 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
14 changes: 7 additions & 7 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ org.gradle.jvmargs=-Xmx1G

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

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

# Dependencies
fabric_version=0.102.1+1.21.1
mod_menu_version=11.0.1
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
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
import net.minecraft.item.ItemGroups;
import net.minecraft.item.Items;
import net.minecraft.recipe.RecipeType;
import net.minecraft.recipe.SpecialRecipeSerializer;
import net.minecraft.recipe.ShieldDecorationRecipe;
import net.minecraft.recipe.SpecialCraftingRecipe;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
Expand All @@ -30,6 +31,9 @@
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;

Expand Down Expand Up @@ -58,13 +62,13 @@ public class FabricShieldLib implements ModInitializer {
* Test shield item that does not support banners.
*/
public static FabricShieldItem fabric_shield;


/**
* Recipe type and serializer for banner decoration recipe.
*/

public static final SpecialRecipeSerializer<FabricShieldDecoratorRecipe> FABRIC_SHIELD_DECORATION_SERIALIZER;
public static final SpecialCraftingRecipe.SpecialRecipeSerializer<ShieldDecorationRecipe> FABRIC_SHIELD_DECORATION_SERIALIZER;
public static final RecipeType<FabricShieldDecoratorRecipe> FABRIC_SHIELD_DECORATION;

static {
Expand All @@ -73,7 +77,7 @@ public class FabricShieldLib implements ModInitializer {
@Override
public String toString() {return "fabric_shield_decoration";}
});
FABRIC_SHIELD_DECORATION_SERIALIZER = Registry.register(Registries.RECIPE_SERIALIZER, Identifier.of(MOD_ID, "fabric_shield_decoration"), new SpecialRecipeSerializer<>(FabricShieldDecoratorRecipe::new));
FABRIC_SHIELD_DECORATION_SERIALIZER = Registry.register(Registries.RECIPE_SERIALIZER, Identifier.of(MOD_ID, "fabric_shield_decoration"), new SpecialCraftingRecipe.SpecialRecipeSerializer<>(FabricShieldDecoratorRecipe::new));
}


Expand All @@ -90,9 +94,9 @@ public void onInitialize() {
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 = Registry.register(Registries.ITEM, Identifier.of(MOD_ID, "fabric_banner_shield"), new FabricBannerShieldItem(new Item.Settings().maxDamage(336), 85, 9, Items.OAK_PLANKS, Items.SPRUCE_PLANKS));
fabric_banner_shield = registerItem("fabric_banner_shield", (props) -> new FabricBannerShieldItem(props.maxDamage(336), 85, 9, Items.OAK_PLANKS, Items.SPRUCE_PLANKS));

fabric_shield = Registry.register(Registries.ITEM, Identifier.of(MOD_ID, "fabric_shield"), new FabricShieldItem(new Item.Settings().maxDamage(336), 100, 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));

ItemGroupEvents.modifyEntriesEvent(ItemGroups.COMBAT).register(entries -> {
entries.addAfter(Items.SHIELD,fabric_banner_shield);
Expand All @@ -103,7 +107,7 @@ public void onInitialize() {
ShieldBlockCallback.EVENT.register((defender, source, amount, hand, shield) -> {

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

if(reflectNumber > 0) {
Expand All @@ -115,9 +119,9 @@ public void onInitialize() {
if(defender.blockedByShield(source)){
World world = attacker.getWorld();
if(defender instanceof PlayerEntity) { //Defender should always be a player, but check anyway
attacker.damage(world.getDamageSources().playerAttack((PlayerEntity) defender), Math.round(amount * 0.33F));
attacker.sidedDamage(world.getDamageSources().playerAttack((PlayerEntity) defender), Math.round(amount * 0.33F));
} else {
attacker.damage(world.getDamageSources().mobAttack(defender), Math.round(amount * 0.33F));
attacker.sidedDamage(world.getDamageSources().mobAttack(defender), Math.round(amount * 0.33F));
}
}
}
Expand All @@ -134,4 +138,12 @@ public void onInitialize() {
//Announce having finished starting up
logger.info("Fabric Shield Lib Initialized!");
}

private static <T extends Item> T registerItem(String name, Function<Item.Settings, T> constructor) {
RegistryKey<Item> key = RegistryKey.of(RegistryKeys.ITEM, Identifier.of(MOD_ID, name));
Item.Settings settings = new Item.Settings();
settings = settings.registryKey(key);
T item = constructor.apply(settings);
return Registry.register(Registries.ITEM, key, item);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class FabricShieldLibClient implements ClientModInitializer {
public static final SpriteIdentifier FABRIC_BANNER_SHIELD_BASE = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE, Identifier.of(FabricShieldLib.MOD_ID, "entity/fabric_banner_shield_base"));
@SuppressWarnings("deprecation")
public static final SpriteIdentifier FABRIC_BANNER_SHIELD_BASE_NO_PATTERN = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE, Identifier.of(FabricShieldLib.MOD_ID, "entity/fabric_banner_shield_base_nopattern"));

@Override
public void onInitializeClient() {

Expand All @@ -55,7 +55,7 @@ public void onInitializeClient() {
ItemTooltipCallback.EVENT.register((stack, context, type, tooltip) -> {

if(FabricShieldLibConfig.enable_tooltips) {

if(stack.getItem() instanceof FabricShield) {

FabricShield shield = (FabricShield) stack.getItem();
Expand Down Expand Up @@ -109,10 +109,10 @@ public static void renderBanner(ItemStack stack, MatrixStack matrices, VertexCon
matrices.push();
matrices.scale(1.0F, -1.0F, -1.0F);
SpriteIdentifier spriteIdentifier = bl ? base : base_nopattern;
VertexConsumer vertexConsumer = spriteIdentifier.getSprite().getTextureSpecificVertexConsumer(ItemRenderer.getDirectItemGlintConsumer(vertexConsumers, model.getLayer(spriteIdentifier.getAtlasId()), true, stack.hasGlint()));
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());
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);
}
Expand Down
Loading

0 comments on commit ef8c6fd

Please sign in to comment.