移植药水弹

This commit is contained in:
17146 2025-04-02 21:05:25 +08:00
parent 9f9af0617c
commit cb9a97e97a
2 changed files with 52 additions and 23 deletions

View file

@ -2,11 +2,16 @@ package com.atsuishio.superbwarfare.init;
import com.atsuishio.superbwarfare.Mod; import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.item.*; import com.atsuishio.superbwarfare.item.*;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.registries.Registries; import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.world.flag.FeatureFlagSet;
import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.CreativeModeTabs; import net.minecraft.world.item.CreativeModeTabs;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.alchemy.Potion;
import net.minecraft.world.item.alchemy.PotionContents;
import net.neoforged.bus.api.SubscribeEvent; import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber; import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.event.BuildCreativeModeTabContentsEvent; import net.neoforged.neoforge.event.BuildCreativeModeTabContentsEvent;
@ -52,9 +57,10 @@ public class ModTabs {
} }
}); });
// TODO potion mortar shell param.holders().lookup(Registries.POTION)
// param.holders().lookup(Registries.POTION) .ifPresent(potion -> generatePotionEffectTypes(output, potion, ModItems.POTION_MORTAR_SHELL.get(),
// .ifPresent(potion -> generatePotionEffectTypes(output, potion, ModItems.POTION_MORTAR_SHELL.get())); CreativeModeTab.TabVisibility.PARENT_AND_SEARCH_TABS,
param.enabledFeatures()));
}) })
.build()); .build());
@ -97,10 +103,12 @@ public class ModTabs {
} }
} }
// TODO potion shell private static void generatePotionEffectTypes(
// private static void generatePotionEffectTypes(CreativeModeTab.Output output, HolderLookup<Potion> potions, Item potionItem) { CreativeModeTab.Output output, HolderLookup<Potion> potions, Item item, CreativeModeTab.TabVisibility visibility, FeatureFlagSet requiredFeatures
// potions.listElements().filter(potion -> !potion.is(Potions.EMPTY_ID)) ) {
// .map(potion -> PotionUtils.setPotion(new ItemStack(potionItem), potion.value())) potions.listElements()
// .forEach(output::accept); .filter(potion -> potion.value().isEnabled(requiredFeatures))
// } .map(potion -> PotionContents.createItemStack(item, potion))
.forEach(itemStack -> output.accept(itemStack, visibility));
}
} }

View file

@ -1,25 +1,46 @@
package com.atsuishio.superbwarfare.item.common.ammo; package com.atsuishio.superbwarfare.item.common.ammo;
//@EventBusSubscriber(bus = EventBusSubscriber.Bus.MOD, value = Dist.CLIENT) import com.atsuishio.superbwarfare.init.ModItems;
import net.minecraft.core.component.DataComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.util.FastColor;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.item.alchemy.PotionContents;
import net.minecraft.world.item.alchemy.Potions;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.client.event.RegisterColorHandlersEvent;
import java.util.List;
@EventBusSubscriber(bus = EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
public class PotionMortarShell extends MortarShell { public class PotionMortarShell extends MortarShell {
public PotionMortarShell() { public PotionMortarShell() {
super(); super();
} }
// TODO default instance @Override
// @Override public ItemStack getDefaultInstance() {
// public ItemStack getDefaultInstance() { ItemStack itemstack = super.getDefaultInstance();
// return PotionUtils.setPotion(super.getDefaultInstance(), Potions.POISON); itemstack.set(DataComponents.POTION_CONTENTS, new PotionContents(Potions.POISON));
// } return itemstack;
}
// @Override @Override
// public void appendHoverText(ItemStack pStack, @Nullable Level pLevel, List<Component> pTooltip, TooltipFlag pFlag) { public void appendHoverText(ItemStack stack, Item.TooltipContext context, List<Component> tooltipComponents, TooltipFlag tooltipFlag) {
// PotionUtils.addPotionTooltip(pStack, pTooltip, 0.125F); PotionContents potioncontents = stack.get(DataComponents.POTION_CONTENTS);
// } if (potioncontents != null) {
potioncontents.addPotionTooltip(tooltipComponents::add, 0.125F, context.tickRate());
}
}
// @SubscribeEvent @SubscribeEvent
// public static void onRegisterColorHandlers(final RegisterColorHandlersEvent.Item event) { public static void onRegisterColorHandlers(final RegisterColorHandlersEvent.Item event) {
// event.register((stack, layer) -> layer == 1 ? PotionUtils.getColor(stack) : -1, ModItems.POTION_MORTAR_SHELL.get()); event.register((stack, layer) -> layer == 1 ? FastColor.ARGB32.opaque(stack.getOrDefault(DataComponents.POTION_CONTENTS, PotionContents.EMPTY).getColor()) : -1,
// } ModItems.POTION_MORTAR_SHELL.get());
}
} }