diff --git a/src/main/java/tobinio/realarrowtip/RealArrowTip.java b/src/main/java/tobinio/realarrowtip/RealArrowTip.java index b1e5e50..4f5a561 100644 --- a/src/main/java/tobinio/realarrowtip/RealArrowTip.java +++ b/src/main/java/tobinio/realarrowtip/RealArrowTip.java @@ -2,7 +2,9 @@ package tobinio.realarrowtip; import net.fabricmc.api.ModInitializer; import net.minecraft.client.item.ModelPredicateProviderRegistry; -import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.client.world.ClientWorld; +import net.minecraft.entity.LivingEntity; +import net.minecraft.item.CrossbowItem; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; @@ -15,31 +17,35 @@ public class RealArrowTip implements ModInitializer { public static final Logger LOGGER = LoggerFactory.getLogger("Real Arrow Tip"); - /** - * Runs the mod initializer. - */ @Override public void onInitialize() { + ModelPredicateProviderRegistry.register(Items.BOW, new Identifier("arrow_type"), RealArrowTip::arrowTypeBow); + ModelPredicateProviderRegistry.register(Items.CROSSBOW, new Identifier("arrow_type"), RealArrowTip::arrowTypeCrossbow); + } + + // 0 = default arrow + // 0.1 = tipped arrow + // 0.2 = spectral arrow + private static float arrowTypeBow(ItemStack stack, ClientWorld world, LivingEntity entity, int seed) { + if (entity == null) return 0; - // 0 = default arrow - // 0.1 = tipped arrow - // 0.2 = spectral arrow + Item item = entity.getProjectileType(stack).getItem(); - ModelPredicateProviderRegistry.register(Items.BOW, new Identifier("arrow_type"), (stack, world, entity, seed) -> { - if (entity == null) - return 0; + if (item == Items.TIPPED_ARROW) return 0.1f; - Item item = entity.getProjectileType(stack).getItem(); + if (item == Items.SPECTRAL_ARROW) return 0.2f; + + return 0; + } - if (item == Items.TIPPED_ARROW) - return 0.1f; + private static float arrowTypeCrossbow(ItemStack stack, ClientWorld world, LivingEntity entity, int seed) { - if (item == Items.SPECTRAL_ARROW) - return 0.2f; + if (!CrossbowItem.isCharged(stack)) return 0; - return 0; - }); + if (CrossbowItem.hasProjectile(stack, Items.TIPPED_ARROW)) return 0.1f; + if (CrossbowItem.hasProjectile(stack, Items.SPECTRAL_ARROW)) return 0.2f; + return 0; } } diff --git a/src/main/java/tobinio/realarrowtip/mixin/CrossbowItemInvoker.java b/src/main/java/tobinio/realarrowtip/mixin/CrossbowItemInvoker.java new file mode 100644 index 0000000..e5fc425 --- /dev/null +++ b/src/main/java/tobinio/realarrowtip/mixin/CrossbowItemInvoker.java @@ -0,0 +1,21 @@ +package tobinio.realarrowtip.mixin; + +import net.minecraft.item.CrossbowItem; +import net.minecraft.item.ItemStack; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; + +import java.util.List; + +/** + * Created: 04/10/2023 + * @author Tobias Frischmann + */ + +@Mixin (CrossbowItem.class) +public interface CrossbowItemInvoker { + @Invoker ("getProjectiles") + public static List invokerGetProjectiles(ItemStack crossbow) { + throw new AssertionError(); + } +} diff --git a/src/main/java/tobinio/realarrowtip/mixin/ItemColorsMixin.java b/src/main/java/tobinio/realarrowtip/mixin/ItemColorsMixin.java index b92bb05..4efa68f 100644 --- a/src/main/java/tobinio/realarrowtip/mixin/ItemColorsMixin.java +++ b/src/main/java/tobinio/realarrowtip/mixin/ItemColorsMixin.java @@ -5,16 +5,14 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.color.block.BlockColors; import net.minecraft.client.color.item.ItemColors; import net.minecraft.client.network.ClientPlayerEntity; -import net.minecraft.item.BowItem; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.item.TippedArrowItem; +import net.minecraft.item.*; import net.minecraft.potion.PotionUtil; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import tobinio.realarrowtip.RealArrowTip; + +import java.util.Optional; /** * Created: 03/10/2023 @@ -30,15 +28,26 @@ public abstract class ItemColorsMixin { itemColors.register((stack, tintIndex) -> { ClientPlayerEntity player = MinecraftClient.getInstance().player; - if (player == null || tintIndex != 1) - return -1; + if (player == null || tintIndex != 1) return -1; ItemStack projectileType = player.getProjectileType(stack); - if (!(projectileType.getItem() instanceof TippedArrowItem)) - return -1; + if (!(projectileType.getItem() instanceof TippedArrowItem)) return -1; return PotionUtil.getColor(projectileType); }, Items.BOW); + + itemColors.register((stack, tintIndex) -> { + ClientPlayerEntity player = MinecraftClient.getInstance().player; + + if (player == null || tintIndex != 1) return -1; + + Optional tippedArrow = CrossbowItemInvoker.invokerGetProjectiles(stack) + .stream() + .filter(itemStack -> itemStack.isOf(Items.TIPPED_ARROW)) + .findFirst(); + + return tippedArrow.map(PotionUtil::getColor).orElse(-1); + }, Items.CROSSBOW); } } diff --git a/src/main/resources/assets/minecraft/models/item/crossbow.json b/src/main/resources/assets/minecraft/models/item/crossbow.json new file mode 100644 index 0000000..9d5077c --- /dev/null +++ b/src/main/resources/assets/minecraft/models/item/crossbow.json @@ -0,0 +1,125 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "item/crossbow_standby" + }, + "display": { + "thirdperson_righthand": { + "rotation": [ + -90, + 0, + -60 + ], + "translation": [ + 2, + 0.1, + -3 + ], + "scale": [ + 0.9, + 0.9, + 0.9 + ] + }, + "thirdperson_lefthand": { + "rotation": [ + -90, + 0, + 30 + ], + "translation": [ + 2, + 0.1, + -3 + ], + "scale": [ + 0.9, + 0.9, + 0.9 + ] + }, + "firstperson_righthand": { + "rotation": [ + -90, + 0, + -55 + ], + "translation": [ + 1.13, + 3.2, + 1.13 + ], + "scale": [ + 0.68, + 0.68, + 0.68 + ] + }, + "firstperson_lefthand": { + "rotation": [ + -90, + 0, + 35 + ], + "translation": [ + 1.13, + 3.2, + 1.13 + ], + "scale": [ + 0.68, + 0.68, + 0.68 + ] + } + }, + "overrides": [ + { + "predicate": { + "pulling": 1 + }, + "model": "item/crossbow_pulling_0" + }, + { + "predicate": { + "pulling": 1, + "pull": 0.58 + }, + "model": "item/crossbow_pulling_1" + }, + { + "predicate": { + "pulling": 1, + "pull": 1.0 + }, + "model": "item/crossbow_pulling_2" + }, + { + "predicate": { + "charged": 1 + }, + "model": "item/crossbow_arrow" + }, + { + "predicate": { + "charged": 1, + "firework": 1 + }, + "model": "item/crossbow_firework" + }, + { + "predicate": { + "charged": 1, + "arrow_type": 0.1 + }, + "model": "real_arrow_tip:item/crossbow_tipped" + }, + { + "predicate": { + "charged": 1, + "arrow_type": 0.2 + }, + "model": "real_arrow_tip:item/crossbow_spectral" + } + ] +} diff --git a/src/main/resources/assets/real_arrow_tip/models/item/crossbow_spectral.json b/src/main/resources/assets/real_arrow_tip/models/item/crossbow_spectral.json new file mode 100644 index 0000000..fdb225b --- /dev/null +++ b/src/main/resources/assets/real_arrow_tip/models/item/crossbow_spectral.json @@ -0,0 +1,6 @@ +{ + "parent": "item/crossbow", + "textures": { + "layer0": "real_arrow_tip:item/crossbow_spectral" + } +} diff --git a/src/main/resources/assets/real_arrow_tip/models/item/crossbow_tipped.json b/src/main/resources/assets/real_arrow_tip/models/item/crossbow_tipped.json new file mode 100644 index 0000000..2cca1d7 --- /dev/null +++ b/src/main/resources/assets/real_arrow_tip/models/item/crossbow_tipped.json @@ -0,0 +1,7 @@ +{ + "parent": "item/crossbow", + "textures": { + "layer0": "real_arrow_tip:item/crossbow_tipped_base", + "layer1": "real_arrow_tip:item/crossbow_tipped_head" + } +} diff --git a/src/main/resources/assets/real_arrow_tip/textures/item/crossbow_spectral.png b/src/main/resources/assets/real_arrow_tip/textures/item/crossbow_spectral.png new file mode 100644 index 0000000000000000000000000000000000000000..7fe4fcd232bd62e890cc6b8c9c95236bc04418d3 GIT binary patch literal 198 zcmeAS@N?(olHy`uVBq!ia0y~yU=RRd4mJh`2Kmqb6B!s77>k44ofy`glX=O&z`&C3 z=s@R_1TkWI0k4wV)Xd@Q?B&WUZ%}6m7EhAa`F|JCroE+R}A^c xr<0&*#4#=Ggc-}U6B=eMk3K9=N=RT}NHU0XTFI$t#K6G7;OXk;vd$@?2>?y$J@5bk literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/real_arrow_tip/textures/item/crossbow_tipped_base.png b/src/main/resources/assets/real_arrow_tip/textures/item/crossbow_tipped_base.png new file mode 100644 index 0000000000000000000000000000000000000000..18098dfa27f9d35806ead580adde745bcaf34be9 GIT binary patch literal 313 zcmeAS@N?(olHy`uVBq!ia0y~yU=RRd4rT@h1`S>QUAmAwqs@vA(qmuZxRIXS#Z>zl6LHTZpYt zZf>rJw!pM$(_D>s%@nv97#Mi&cztDHU=S<`@(cct1{hS=&P-xpVBjq9h%9Dc;5!V$ zjK}j=q%bfr6nVNhhG+zbo{Qu=Y{0>C;bVZlMd{(c{?Qy^m-_4l&T}yS_B1hP(D;(a z?BemLF?{XTi0<_nzZ=~4CVr_rIg#Puo5_08Kd$L=PDncCEq7y+&QU+|Nq?F+#5G;Oq({%#l?kzf#DZdw>AR<16xUuU+{kr zVA#BW$$ka~2F?PH$YKTtzQZ8Qcszea3IhX!zNd?0h(>U7f-Cb476}Q7g)#yRoCb!Q x9V#6dL=sZkHXUS0VVh**!obQC#26OF(7TA`A=}i>ECvP!22WQ%mvv4FO#mb`IZyxq literal 0 HcmV?d00001 diff --git a/src/main/resources/real-arrow-tip.mixins.json b/src/main/resources/real-arrow-tip.mixins.json index 671ec47..4d072d0 100644 --- a/src/main/resources/real-arrow-tip.mixins.json +++ b/src/main/resources/real-arrow-tip.mixins.json @@ -4,6 +4,7 @@ "package": "tobinio.realarrowtip.mixin", "compatibilityLevel": "JAVA_17", "mixins": [ + "CrossbowItemInvoker" ], "client": [ "ArrowEntityRendererMixin",