From b31282ea6280f2c46507c2ede702be1d6717704b Mon Sep 17 00:00:00 2001 From: Uraneptus <50745606+Uraneptus@users.noreply.github.com> Date: Thu, 29 Aug 2024 00:31:38 +0200 Subject: [PATCH] artifact weapons --- build.gradle | 3 +- .../sullysmod/models/item/broken_bottle.json | 72 ++++++++++++++++++- .../resources/assets/sullysmod/sounds.json | 17 +++++ .../sullysmod/tags/blocks/melts_amber.json | 2 +- .../common/items/ArtifactWeaponItem.java | 51 +++++++++++++ ...ientEvents.java => SMClientModEvents.java} | 9 ++- .../sullysmod/core/events/SMPlayerEvents.java | 8 ++- .../sullysmod/core/registry/SMItems.java | 5 +- .../sullysmod/core/registry/SMSounds.java | 1 + .../data/client/SMItemModelProvider.java | 36 +++++++--- .../client/SMSoundDefinitionsProvider.java | 5 ++ 11 files changed, 189 insertions(+), 20 deletions(-) create mode 100644 src/main/java/com/uraneptus/sullysmod/common/items/ArtifactWeaponItem.java rename src/main/java/com/uraneptus/sullysmod/core/events/{SMClientEvents.java => SMClientModEvents.java} (96%) diff --git a/build.gradle b/build.gradle index 8450f382..7bdda2f5 100644 --- a/build.gradle +++ b/build.gradle @@ -101,8 +101,7 @@ dependencies { //runtimeOnly fg.deobf("curse.maven:configured-457570:4011355") runtimeOnly fg.deobf("curse.maven:config-menus-forge-544048:4672356") runtimeOnly fg.deobf("curse.maven:neat-238372:4580940") - runtimeOnly fg.deobf("curse.maven:advanced-xray-256256:4840340") - + //runtimeOnly fg.deobf("curse.maven:advanced-xray-256256:4840340") Use this for worldgen tests } mixin { diff --git a/src/generated/resources/assets/sullysmod/models/item/broken_bottle.json b/src/generated/resources/assets/sullysmod/models/item/broken_bottle.json index 68098db7..342e20b9 100644 --- a/src/generated/resources/assets/sullysmod/models/item/broken_bottle.json +++ b/src/generated/resources/assets/sullysmod/models/item/broken_bottle.json @@ -1,5 +1,75 @@ { - "parent": "minecraft:item/generated", + "parent": "minecraft:item/handheld", + "display": { + "firstperson_lefthand": { + "rotation": [ + -180, + 90, + 0 + ], + "scale": [ + 0.68, + 0.68, + 0.68 + ], + "translation": [ + 1.13, + 3.2, + 1.13 + ] + }, + "firstperson_righthand": { + "rotation": [ + 180, + -90, + 0 + ], + "scale": [ + 0.68, + 0.68, + 0.68 + ], + "translation": [ + 1.13, + 3.2, + 1.13 + ] + }, + "thirdperson_lefthand": { + "rotation": [ + -180, + 90, + 0 + ], + "scale": [ + 0.85, + 0.85, + 0.85 + ], + "translation": [ + 0, + 4, + 0.5 + ] + }, + "thirdperson_righthand": { + "rotation": [ + 180, + -90, + 0 + ], + "scale": [ + 0.85, + 0.85, + 0.85 + ], + "translation": [ + 0, + 4, + 0.5 + ] + } + }, "textures": { "layer0": "sullysmod:item/broken_bottle" } diff --git a/src/generated/resources/assets/sullysmod/sounds.json b/src/generated/resources/assets/sullysmod/sounds.json index 68409054..3ad7a0f7 100644 --- a/src/generated/resources/assets/sullysmod/sounds.json +++ b/src/generated/resources/assets/sullysmod/sounds.json @@ -408,6 +408,23 @@ ], "subtitle": "subtitles.entity.tortoise_shell.place" }, + "item.broken_bottle.shatter": { + "sounds": [ + { + "name": "random/glass1", + "pitch": 1.3 + }, + { + "name": "random/glass2", + "pitch": 1.3 + }, + { + "name": "random/glass3", + "pitch": 1.3 + } + ], + "subtitle": "subtitles.item.broken_bottle.shatter" + }, "item.throwing_knife.hit": { "sounds": [ "sullysmod:item/throwing_knife/hit1", diff --git a/src/generated/resources/data/sullysmod/tags/blocks/melts_amber.json b/src/generated/resources/data/sullysmod/tags/blocks/melts_amber.json index 2c38690d..7106f1a7 100644 --- a/src/generated/resources/data/sullysmod/tags/blocks/melts_amber.json +++ b/src/generated/resources/data/sullysmod/tags/blocks/melts_amber.json @@ -8,6 +8,6 @@ "minecraft:campfire", "minecraft:soul_campfire", "minecraft:lava", - "sullysmod:amber_lantern" + "sullysmod:molten_amber_block" ] } \ No newline at end of file diff --git a/src/main/java/com/uraneptus/sullysmod/common/items/ArtifactWeaponItem.java b/src/main/java/com/uraneptus/sullysmod/common/items/ArtifactWeaponItem.java new file mode 100644 index 00000000..dd6224f6 --- /dev/null +++ b/src/main/java/com/uraneptus/sullysmod/common/items/ArtifactWeaponItem.java @@ -0,0 +1,51 @@ +package com.uraneptus.sullysmod.common.items; + +import com.google.common.collect.ImmutableMultimap; +import com.google.common.collect.Multimap; +import com.uraneptus.sullysmod.core.registry.SMSounds; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.sounds.SoundSource; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.entity.LivingEntity; +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.Item; +import net.minecraft.world.item.ItemStack; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.function.Supplier; + +public class ArtifactWeaponItem extends Item { + @Nullable + private final Supplier customBreakSound; + private final Multimap defaultModifiers; + + public ArtifactWeaponItem(int damage, float speed, @Nullable Supplier customBreakSound, Properties pProperties) { + super(pProperties); + this.customBreakSound = customBreakSound; + ImmutableMultimap.Builder builder = ImmutableMultimap.builder(); + builder.put(Attributes.ATTACK_DAMAGE, new AttributeModifier(BASE_ATTACK_DAMAGE_UUID, "Weapon modifier", damage, AttributeModifier.Operation.ADDITION)); + builder.put(Attributes.ATTACK_SPEED, new AttributeModifier(BASE_ATTACK_SPEED_UUID, "Weapon modifier", speed, AttributeModifier.Operation.ADDITION)); + this.defaultModifiers = builder.build(); + } + + @Override + public boolean hurtEnemy(ItemStack pStack, LivingEntity pTarget, LivingEntity pAttacker) { + pStack.hurtAndBreak(1, pAttacker, (entity) -> { + if (customBreakSound == null) { + entity.broadcastBreakEvent(EquipmentSlot.MAINHAND); + } else { + pAttacker.level().playSound(null, pAttacker.getOnPos(), customBreakSound.get(), SoundSource.NEUTRAL, 1.0F, 1.0F); + } + }); + return true; + } + + @NotNull + @Override + public Multimap getAttributeModifiers(EquipmentSlot slot, ItemStack stack) { + return slot == EquipmentSlot.MAINHAND ? this.defaultModifiers : super.getAttributeModifiers(slot, stack); + } +} diff --git a/src/main/java/com/uraneptus/sullysmod/core/events/SMClientEvents.java b/src/main/java/com/uraneptus/sullysmod/core/events/SMClientModEvents.java similarity index 96% rename from src/main/java/com/uraneptus/sullysmod/core/events/SMClientEvents.java rename to src/main/java/com/uraneptus/sullysmod/core/events/SMClientModEvents.java index 2d65e2b4..9bc4b17c 100644 --- a/src/main/java/com/uraneptus/sullysmod/core/events/SMClientEvents.java +++ b/src/main/java/com/uraneptus/sullysmod/core/events/SMClientModEvents.java @@ -2,6 +2,8 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.Maps; +import com.mojang.blaze3d.platform.Window; +import com.mojang.blaze3d.systems.RenderSystem; import com.uraneptus.sullysmod.SullysMod; import com.uraneptus.sullysmod.client.model.*; import com.uraneptus.sullysmod.client.model.ancient_skulls.*; @@ -13,13 +15,15 @@ import com.uraneptus.sullysmod.client.renderer.entities.*; import com.uraneptus.sullysmod.client.renderer.entities.layer.StuckInAmberLayer; import com.uraneptus.sullysmod.common.blocks.AncientSkullBlock; +import com.uraneptus.sullysmod.common.caps.SMEntityCap; import com.uraneptus.sullysmod.common.items.VenomVialItem; import com.uraneptus.sullysmod.core.registry.SMBlockEntityTypes; import com.uraneptus.sullysmod.core.registry.SMEntityTypes; import com.uraneptus.sullysmod.core.registry.SMItems; import com.uraneptus.sullysmod.core.registry.SMParticleTypes; import net.minecraft.Util; -import net.minecraft.client.particle.DripParticle; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.renderer.blockentity.SkullBlockRenderer; import net.minecraft.client.renderer.entity.LivingEntityRenderer; import net.minecraft.client.renderer.item.ItemProperties; @@ -31,6 +35,7 @@ import net.minecraftforge.client.event.EntityRenderersEvent; import net.minecraftforge.client.event.RegisterColorHandlersEvent; import net.minecraftforge.client.event.RegisterParticleProvidersEvent; +import net.minecraftforge.client.event.RenderGuiEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; @@ -41,7 +46,7 @@ @Mod.EventBusSubscriber(modid = SullysMod.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT) @SuppressWarnings("unused") -public class SMClientEvents { +public class SMClientModEvents { @SubscribeEvent public static void registerEntityRenderer(EntityRenderersEvent.RegisterRenderers event) { diff --git a/src/main/java/com/uraneptus/sullysmod/core/events/SMPlayerEvents.java b/src/main/java/com/uraneptus/sullysmod/core/events/SMPlayerEvents.java index a1ae590c..8006e454 100644 --- a/src/main/java/com/uraneptus/sullysmod/core/events/SMPlayerEvents.java +++ b/src/main/java/com/uraneptus/sullysmod/core/events/SMPlayerEvents.java @@ -13,6 +13,7 @@ import com.uraneptus.sullysmod.core.registry.SMParticleTypes; import com.uraneptus.sullysmod.core.registry.SMSounds; import net.minecraft.ChatFormatting; +import net.minecraft.client.Minecraft; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.particles.ItemParticleOption; @@ -46,6 +47,7 @@ import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.loading.FMLEnvironment; import java.util.ArrayList; import java.util.List; @@ -165,8 +167,10 @@ public static void onItemTooltip(ItemTooltipEvent event) { } }); - if (itemstack.is(SMItems.JADE_SHIELD.get()) || itemstack.is(SMItemTags.ARTIFACTS)) { - itemstack.hideTooltipPart(ItemStack.TooltipPart.MODIFIERS); + if (itemstack.is(SMItems.JADE_SHIELD.get()) || (itemstack.is(SMItemTags.ARTIFACTS) && !itemstack.is(SMItems.BROKEN_BOTTLE.get()) && !itemstack.is(SMItems.PRIMITIVE_KNIFE.get()))) { //This also hides damage values of artifacts + if (FMLEnvironment.production) { + itemstack.hideTooltipPart(ItemStack.TooltipPart.MODIFIERS); + } } if (player != null) { diff --git a/src/main/java/com/uraneptus/sullysmod/core/registry/SMItems.java b/src/main/java/com/uraneptus/sullysmod/core/registry/SMItems.java index 7ed1c508..0f1d1182 100644 --- a/src/main/java/com/uraneptus/sullysmod/core/registry/SMItems.java +++ b/src/main/java/com/uraneptus/sullysmod/core/registry/SMItems.java @@ -21,7 +21,6 @@ import net.minecraftforge.registries.RegistryObject; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.function.Supplier; @@ -69,7 +68,7 @@ public class SMItems { public static Map, Integer> TRADES = new HashMap<>(); public static final RegistryObject BROKEN_VASE = registerArtifact("broken_vase", "A large piece of the side is missing", 10); - public static final RegistryObject PRIMITIVE_KNIFE = registerArtifact("primitive_knife", "A small knife made from obsidian", 15); + public static final RegistryObject PRIMITIVE_KNIFE = registerArtifact("primitive_knife", "A small knife made from obsidian", () -> new ArtifactWeaponItem(5, -2.5F, null, SMProperties.Items.artifacts().durability(20)), 15); public static final RegistryObject MINERS_HELMET = registerArtifact("miners_helmet", "Looks like it’s previous owner couldn’t get the candle lit anymore", () -> new ArtifactHelmetItem(SMArmorMaterials.MINERS_HELMET, SMProperties.Items.artifacts(), MinersHelmetModel.INSTANCE), 15); public static final RegistryObject SMALL_DENTED_HELMET = registerArtifact("small_dented_helmet", "A small rusty helmet. Barely fits", @@ -109,7 +108,7 @@ public class SMItems { public static final RegistryObject TORN_CLOTH = registerArtifact("torn_cloth", "A dirty torn off piece of clothing", 6); public static final RegistryObject GOLDEN_GOBLET = registerArtifact("golden_goblet", "An old but beautiful chalice made by a skilled goldsmith", 29); public static final RegistryObject EMERALD_EARRING = registerArtifact("emerald_earring", "Besides the beautiful emerald, it looks sloppily put together", 17); - public static final RegistryObject BROKEN_BOTTLE = registerArtifact("broken_bottle", "The top half of a bottle", 5); + public static final RegistryObject BROKEN_BOTTLE = registerArtifact("broken_bottle", "The top half of a bottle", () -> new ArtifactWeaponItem(4, -1.2F, SMSounds.BROKEN_BOTTLE_SHATTERS, SMProperties.Items.artifacts().durability(1)), 5); public static final RegistryObject FROG_IDOL = registerArtifact("frog_idol", "Everybody likes frogs", 29); public static RegistryObject registerArtifact(String name, String description, int price) { diff --git a/src/main/java/com/uraneptus/sullysmod/core/registry/SMSounds.java b/src/main/java/com/uraneptus/sullysmod/core/registry/SMSounds.java index 1f9f32d2..44d956b5 100644 --- a/src/main/java/com/uraneptus/sullysmod/core/registry/SMSounds.java +++ b/src/main/java/com/uraneptus/sullysmod/core/registry/SMSounds.java @@ -23,6 +23,7 @@ public class SMSounds { public static final RegistryObject THROWING_KNIFE_HIT = HELPER.createSoundEvent("item.throwing_knife.hit"); public static final RegistryObject THROWING_KNIFE_HIT_GROUND = HELPER.createSoundEvent("item.throwing_knife.hit_ground"); public static final RegistryObject THROWING_KNIFE_THROW = HELPER.createSoundEvent("item.throwing_knife.throw"); + public static final RegistryObject BROKEN_BOTTLE_SHATTERS = HELPER.createSoundEvent("item.broken_bottle.shatter"); //Block Sounds public static final RegistryObject JADE_RICOCHET = HELPER.createSoundEvent("block.jade.ricochet"); diff --git a/src/main/java/com/uraneptus/sullysmod/data/client/SMItemModelProvider.java b/src/main/java/com/uraneptus/sullysmod/data/client/SMItemModelProvider.java index 894e5f9e..f3536433 100644 --- a/src/main/java/com/uraneptus/sullysmod/data/client/SMItemModelProvider.java +++ b/src/main/java/com/uraneptus/sullysmod/data/client/SMItemModelProvider.java @@ -8,6 +8,7 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemDisplayContext; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraftforge.client.model.generators.ItemModelProvider; @@ -66,12 +67,10 @@ protected void registerModels() { basicBlockItem(SMBlocks.ROUGH_JADE_BRICK_SLAB); basicItem(SMItems.MUSIC_DISC_SCOUR); basicItem(SMItems.MUSIC_DISC_SUNKEN_PAST); - jadeShieldItem(SMItems.JADE_SHIELD); basicItem(SMItems.TORTOISE_SCUTE); basicItem(SMItems.TORTOISE_SHELL); basicItem(SMItems.JADE_UPGRADE_SMITHING_TEMPLATE); basicItem(SMItems.GLASS_VIAL); - venomVialItem(SMItems.VENOM_VIAL); basicItem(SMItems.JADE_HORSE_ARMOR); basicItemHandheld(SMItems.THROWING_KNIFE); basicBlockItem(SMBlocks.AMBER); @@ -141,7 +140,7 @@ protected void registerModels() { basicItem(SMItems.TORN_CLOTH); basicItem(SMItems.GOLDEN_GOBLET); basicItem(SMItems.EMERALD_EARRING); - basicItem(SMItems.BROKEN_BOTTLE); + basicItemHandheld(SMItems.BROKEN_BOTTLE); basicItem(SMItems.FROG_IDOL); ancientSkull(SMBlocks.CRACKED_ANCIENT_SKULL.getFirst()); ancientSkull(SMBlocks.CRESTED_ANCIENT_SKULL.getFirst()); @@ -151,6 +150,10 @@ protected void registerModels() { ancientSkull(SMBlocks.LONG_ANCIENT_SKULL.getFirst()); ancientSkull(SMBlocks.TINY_ANCIENT_SKULL.getFirst()); ancientSkull(SMBlocks.WIDE_ANCIENT_SKULL.getFirst()); + //Single use methods + brokenBottle(); + venomVialItem(); + jadeShieldItem(); } private void basicBlockItem(Supplier blockForItem) { @@ -201,8 +204,9 @@ private void basicSpawnEggItem(Supplier item) { withExistingParent(name(item.get()), SPAWN_EGG); } - private void jadeShieldItem(Supplier item) { - getBuilder(name(item.get()) + "_blocking") + private void jadeShieldItem() { + Item item = SMItems.JADE_SHIELD.get(); + getBuilder(name(item) + "_blocking") .parent(new ModelFile.UncheckedModelFile(ENTITY)) .guiLight(BlockModel.GuiLight.FRONT) .texture("particle", vanillaBlockLocation(name(Blocks.DARK_OAK_PLANKS))) @@ -214,7 +218,7 @@ private void jadeShieldItem(Supplier item) { .transform(ItemDisplayContext.GUI).rotation(15, -25, -5).translation(2, 2.5F, 0).scale(0.65F, 0.65F, 0.65F).end() .end(); - getBuilder(name(item.get())) + getBuilder(name(item)) .parent(new ModelFile.UncheckedModelFile(ENTITY)) .guiLight(BlockModel.GuiLight.FRONT) .texture("particle", vanillaBlockLocation(name(Blocks.DARK_OAK_PLANKS))) @@ -227,11 +231,12 @@ private void jadeShieldItem(Supplier item) { .transform(ItemDisplayContext.FIXED).rotation(0, 180, 0).translation(-4.5F, 4.5F, -5).scale(0.55F, 0.55F, 0.55F).end() .transform(ItemDisplayContext.GROUND).rotation(0, 0, 0).translation(2, 4, 2).scale(0.25F, 0.25F, 0.25F).end() .end() - .override().predicate(new ResourceLocation("blocking"), 1).model(new ModelFile.UncheckedModelFile(modItemLocation(name(item.get()) + "_blocking"))); + .override().predicate(new ResourceLocation("blocking"), 1).model(new ModelFile.UncheckedModelFile(modItemLocation(name(item) + "_blocking"))); } - private void venomVialItem(Supplier item) { - withExistingParent(name(item.get()), GENERATED) + private void venomVialItem() { + Item vial = SMItems.VENOM_VIAL.get(); + withExistingParent(name(vial), GENERATED) .texture("layer0", modItemLocation("glass_vial")) .texture("layer1", modItemLocation("venom_vial_1")) .texture("layer2", modItemLocation("venom_vial_2")); @@ -249,4 +254,17 @@ private void ancientSkull(Supplier skull) { .end(); } + + private void brokenBottle() { + Item bottle = SMItems.BROKEN_BOTTLE.get(); + getBuilder(name(bottle)) + .parent(getExistingFile(HANDHELD)) + .texture("layer0", modItemLocation(name(bottle))) + .transforms() + .transform(ItemDisplayContext.THIRD_PERSON_RIGHT_HAND).rotation(180, -90, 0).translation(0, 4, 0.5F).scale(0.85F, 0.85F, 0.85F).end() + .transform(ItemDisplayContext.THIRD_PERSON_LEFT_HAND).rotation(-180, 90, 0).translation(0, 4, 0.5F).scale(0.85F, 0.85F, 0.85F).end() + .transform(ItemDisplayContext.FIRST_PERSON_RIGHT_HAND).rotation(180, -90, 0).translation(1.13F, 3.2F, 1.13F).scale(0.68F, 0.68F, 0.68F).end() + .transform(ItemDisplayContext.FIRST_PERSON_LEFT_HAND).rotation(-180, 90, 0).translation(1.13F, 3.2F, 1.13F).scale(0.68F, 0.68F, 0.68F).end() + .end(); + } } diff --git a/src/main/java/com/uraneptus/sullysmod/data/client/SMSoundDefinitionsProvider.java b/src/main/java/com/uraneptus/sullysmod/data/client/SMSoundDefinitionsProvider.java index 7db21b3b..52a5140a 100644 --- a/src/main/java/com/uraneptus/sullysmod/data/client/SMSoundDefinitionsProvider.java +++ b/src/main/java/com/uraneptus/sullysmod/data/client/SMSoundDefinitionsProvider.java @@ -52,6 +52,11 @@ public void registerSounds() { sound(SullysMod.modPrefix("item/throwing_knife/throw1")), sound(SullysMod.modPrefix("item/throwing_knife/throw2")) ); + this.addBasicSound(SMSounds.BROKEN_BOTTLE_SHATTERS, + sound("random/glass1").pitch(1.3F), + sound("random/glass2").pitch(1.3F), + sound("random/glass3").pitch(1.3F) + ); //Block Sounds this.addBasicSound(SMSounds.POLISH_JADE,