diff --git a/src/generated/resources/data/nmt/recipe/obsidian_tipped_arrow.json b/src/generated/resources/data/nmt/recipe/obsidian_tipped_arrow.json new file mode 100644 index 0000000..255b094 --- /dev/null +++ b/src/generated/resources/data/nmt/recipe/obsidian_tipped_arrow.json @@ -0,0 +1,4 @@ +{ + "type": "nmt:crafting_special_obsidiantippedarrow", + "category": "misc" +} \ No newline at end of file diff --git a/src/main/java/net/nova/nmt/NoMoreThings.java b/src/main/java/net/nova/nmt/NoMoreThings.java index 4a26a57..08ff66e 100644 --- a/src/main/java/net/nova/nmt/NoMoreThings.java +++ b/src/main/java/net/nova/nmt/NoMoreThings.java @@ -33,6 +33,7 @@ public NoMoreThings(IEventBus bus) { NMTMenuType.MENUS.register(bus); NMTFeature.FEATURES.register(bus); NMTEntityType.ENTITY_TYPES.register(bus); + NMTRecipeSerializers.RECIPE_SERIALIZERS.register(bus); bus.addListener(DataGenerators::gatherData); bus.addListener(this::onRegisterComplete); diff --git a/src/main/java/net/nova/nmt/client/renderer/entity/ObsidianTippableArrowRenderer.java b/src/main/java/net/nova/nmt/client/renderer/entity/ObsidianTippableArrowRenderer.java deleted file mode 100644 index 9b6cb1c..0000000 --- a/src/main/java/net/nova/nmt/client/renderer/entity/ObsidianTippableArrowRenderer.java +++ /dev/null @@ -1,22 +0,0 @@ -package net.nova.nmt.client.renderer.entity; - -import net.minecraft.client.renderer.entity.ArrowRenderer; -import net.minecraft.client.renderer.entity.EntityRendererProvider; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.entity.projectile.Arrow; -import net.neoforged.api.distmarker.Dist; -import net.neoforged.api.distmarker.OnlyIn; - -@OnlyIn(Dist.CLIENT) -public class ObsidianTippableArrowRenderer extends ArrowRenderer { - public static final ResourceLocation NORMAL_ARROW_LOCATION = ResourceLocation.withDefaultNamespace("textures/entity/projectiles/arrow.png"); - public static final ResourceLocation TIPPED_ARROW_LOCATION = ResourceLocation.withDefaultNamespace("textures/entity/projectiles/tipped_arrow.png"); - - public ObsidianTippableArrowRenderer(EntityRendererProvider.Context context) { - super(context); - } - - public ResourceLocation getTextureLocation(Arrow entity) { - return entity.getColor() > 0 ? TIPPED_ARROW_LOCATION : NORMAL_ARROW_LOCATION; - } -} \ No newline at end of file diff --git a/src/main/java/net/nova/nmt/data/recipe/CraftingRecipes.java b/src/main/java/net/nova/nmt/data/recipe/CraftingRecipes.java index 90975b2..f59b14a 100644 --- a/src/main/java/net/nova/nmt/data/recipe/CraftingRecipes.java +++ b/src/main/java/net/nova/nmt/data/recipe/CraftingRecipes.java @@ -5,12 +5,16 @@ import net.minecraft.data.recipes.RecipeCategory; import net.minecraft.data.recipes.RecipeOutput; import net.minecraft.data.recipes.ShapedRecipeBuilder; +import net.minecraft.data.recipes.SpecialRecipeBuilder; import net.minecraft.tags.ItemTags; import net.minecraft.world.item.Items; +import net.minecraft.world.item.crafting.TippedArrowRecipe; import net.minecraft.world.level.block.Blocks; import net.neoforged.neoforge.common.Tags; +import net.nova.nmt.NoMoreThings; import net.nova.nmt.init.NMTBlocks; import net.nova.nmt.init.NMTItems; +import net.nova.nmt.recipe.ObsidianTippedArrowRecipe; import java.util.concurrent.CompletableFuture; @@ -23,6 +27,20 @@ public CraftingRecipes(PackOutput output, CompletableFuture entityType, Level level) { - super(entityType, level); - } -} diff --git a/src/main/java/net/nova/nmt/entity/projectile/ThrownObsidianPotion.java b/src/main/java/net/nova/nmt/entity/projectile/ThrownObsidianPotion.java index 5eb8407..79f6b93 100644 --- a/src/main/java/net/nova/nmt/entity/projectile/ThrownObsidianPotion.java +++ b/src/main/java/net/nova/nmt/entity/projectile/ThrownObsidianPotion.java @@ -93,6 +93,15 @@ protected void onHit(HitResult result) { this.level().levelEvent(i, this.blockPosition(), potioncontents.getColor()); this.discard(); } + + if (potioncontents.is(NMTPotions.AWFULLY)) { + this.applySplash( + potioncontents.getAllEffects(), result.getType() == HitResult.Type.ENTITY ? ((EntityHitResult) result).getEntity() : null + ); + int i = potioncontents.potion().isPresent() && potioncontents.potion().get().value().hasInstantEffects() ? 2007 : 2002; + this.level().levelEvent(i, this.blockPosition(), potioncontents.getColor()); + this.discard(); + } } } diff --git a/src/main/java/net/nova/nmt/init/NMTItems.java b/src/main/java/net/nova/nmt/init/NMTItems.java index 2b5147c..b84cd54 100644 --- a/src/main/java/net/nova/nmt/init/NMTItems.java +++ b/src/main/java/net/nova/nmt/init/NMTItems.java @@ -3,6 +3,7 @@ import net.minecraft.core.component.DataComponents; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemNameBlockItem; +import net.minecraft.world.item.TippedArrowItem; import net.minecraft.world.item.alchemy.PotionContents; import net.neoforged.neoforge.registries.DeferredItem; import net.neoforged.neoforge.registries.DeferredRegister; @@ -22,6 +23,5 @@ public class NMTItems { public static final DeferredItem OBSIDIAN_POTION = ITEMS.register("obsidian_potion", () -> new ObsidianPotionItem(new Item.Properties().stacksTo(1).component(DataComponents.POTION_CONTENTS, new PotionContents(NMTPotions.LAVA)).fireResistant())); public static final DeferredItem SPLASH_OBSIDIAN_POTION = ITEMS.register("splash_obsidian_potion", () -> new SplashObsidianPotionItem(new Item.Properties().stacksTo(1).component(DataComponents.POTION_CONTENTS, new PotionContents(NMTPotions.LAVA)).fireResistant())); public static final DeferredItem LINGERING_OBSIDIAN_POTION = ITEMS.register("lingering_obsidian_potion", () -> new LingeringObsidianPotionItem(new Item.Properties().stacksTo(1).component(DataComponents.POTION_CONTENTS, new PotionContents(NMTPotions.LAVA)).fireResistant())); - public static final DeferredItem OBSIDIAN_TIPPED_ARROW = ITEMS.register("obsidian_tipped_arrow", () -> new ObsidianTippedArrowItem(new Item.Properties().component(DataComponents.POTION_CONTENTS, new PotionContents(NMTPotions.LAVA)))); - + public static final DeferredItem OBSIDIAN_TIPPED_ARROW = ITEMS.register("obsidian_tipped_arrow", () -> new TippedArrowItem(new Item.Properties().component(DataComponents.POTION_CONTENTS, new PotionContents(NMTPotions.LAVA)))); } diff --git a/src/main/java/net/nova/nmt/init/NMTRecipeSerializers.java b/src/main/java/net/nova/nmt/init/NMTRecipeSerializers.java new file mode 100644 index 0000000..1bf48d8 --- /dev/null +++ b/src/main/java/net/nova/nmt/init/NMTRecipeSerializers.java @@ -0,0 +1,18 @@ +package net.nova.nmt.init; + +import net.minecraft.core.registries.Registries; +import net.minecraft.world.item.crafting.RecipeSerializer; +import net.minecraft.world.item.crafting.SimpleCraftingRecipeSerializer; +import net.minecraft.world.item.crafting.TippedArrowRecipe; +import net.neoforged.neoforge.registries.DeferredRegister; +import net.nova.nmt.recipe.ObsidianTippedArrowRecipe; + +import java.util.function.Supplier; + +import static net.nova.nmt.NoMoreThings.MODID; + +public class NMTRecipeSerializers { + public static final DeferredRegister> RECIPE_SERIALIZERS = DeferredRegister.create(Registries.RECIPE_SERIALIZER, MODID); + + public static final Supplier> OBSIDIAN_TIPPED_ARROW = RECIPE_SERIALIZERS.register("crafting_special_obsidiantippedarrow", () -> new SimpleCraftingRecipeSerializer<>(ObsidianTippedArrowRecipe::new)); +} diff --git a/src/main/java/net/nova/nmt/item/ObsidianTippedArrowItem.java b/src/main/java/net/nova/nmt/item/ObsidianTippedArrowItem.java deleted file mode 100644 index cfc661b..0000000 --- a/src/main/java/net/nova/nmt/item/ObsidianTippedArrowItem.java +++ /dev/null @@ -1,39 +0,0 @@ -package net.nova.nmt.item; - -import net.minecraft.core.component.DataComponents; -import net.minecraft.network.chat.Component; -import net.minecraft.world.item.ArrowItem; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.TooltipFlag; -import net.minecraft.world.item.alchemy.Potion; -import net.minecraft.world.item.alchemy.PotionContents; -import net.nova.nmt.init.NMTPotions; - -import java.util.List; - -public class ObsidianTippedArrowItem extends ArrowItem { - public ObsidianTippedArrowItem(Properties properties) { - super(properties); - } - - @Override - public ItemStack getDefaultInstance() { - ItemStack itemstack = super.getDefaultInstance(); - itemstack.set(DataComponents.POTION_CONTENTS, new PotionContents(NMTPotions.LAVA)); - return itemstack; - } - - @Override - public void appendHoverText(ItemStack stack, Item.TooltipContext context, List tooltipComponents, TooltipFlag tooltipFlag) { - PotionContents potioncontents = stack.get(DataComponents.POTION_CONTENTS); - if (potioncontents != null) { - potioncontents.addPotionTooltip(tooltipComponents::add, 0.125F, context.tickRate()); - } - } - - @Override - public String getDescriptionId(ItemStack stack) { - return Potion.getName(stack.getOrDefault(DataComponents.POTION_CONTENTS, PotionContents.EMPTY).potion(), this.getDescriptionId() + ".effect."); - } -} diff --git a/src/main/java/net/nova/nmt/recipe/ObsidianTippedArrowRecipe.java b/src/main/java/net/nova/nmt/recipe/ObsidianTippedArrowRecipe.java new file mode 100644 index 0000000..ad6cc90 --- /dev/null +++ b/src/main/java/net/nova/nmt/recipe/ObsidianTippedArrowRecipe.java @@ -0,0 +1,65 @@ +package net.nova.nmt.recipe; + +import net.minecraft.core.HolderLookup; +import net.minecraft.core.component.DataComponents; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.item.crafting.CraftingBookCategory; +import net.minecraft.world.item.crafting.CraftingInput; +import net.minecraft.world.item.crafting.CustomRecipe; +import net.minecraft.world.item.crafting.RecipeSerializer; +import net.minecraft.world.level.Level; +import net.nova.nmt.init.NMTItems; +import net.nova.nmt.init.NMTRecipeSerializers; + +public class ObsidianTippedArrowRecipe extends CustomRecipe { + public ObsidianTippedArrowRecipe(CraftingBookCategory category) { + super(category); + } + + public boolean matches(CraftingInput input, Level level) { + if (input.width() == 3 && input.height() == 3) { + for (int i = 0; i < input.height(); i++) { + for (int j = 0; j < input.width(); j++) { + ItemStack itemstack = input.getItem(j, i); + if (itemstack.isEmpty()) { + return false; + } + + if (j == 1 && i == 1) { + if (!itemstack.is(NMTItems.LINGERING_OBSIDIAN_POTION)) { + return false; + } + } else if (!itemstack.is(Items.ARROW)) { + return false; + } + } + } + + return true; + } else { + return false; + } + } + + public ItemStack assemble(CraftingInput input, HolderLookup.Provider registries) { + ItemStack itemstack = input.getItem(1, 1); + if (!itemstack.is(NMTItems.LINGERING_OBSIDIAN_POTION)) { + return ItemStack.EMPTY; + } else { + ItemStack itemstack1 = new ItemStack(NMTItems.OBSIDIAN_TIPPED_ARROW.get(), 8); + itemstack1.set(DataComponents.POTION_CONTENTS, itemstack.get(DataComponents.POTION_CONTENTS)); + return itemstack1; + } + } + + @Override + public boolean canCraftInDimensions(int width, int height) { + return width >= 3 && height >= 3; + } + + @Override + public RecipeSerializer getSerializer() { + return NMTRecipeSerializers.OBSIDIAN_TIPPED_ARROW.get(); + } +}