移植药水弹

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.item.*;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component;
import net.minecraft.world.flag.FeatureFlagSet;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.CreativeModeTabs;
import net.minecraft.world.item.Item;
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.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.event.BuildCreativeModeTabContentsEvent;
@ -52,9 +57,10 @@ public class ModTabs {
}
});
// TODO potion mortar shell
// param.holders().lookup(Registries.POTION)
// .ifPresent(potion -> generatePotionEffectTypes(output, potion, ModItems.POTION_MORTAR_SHELL.get()));
param.holders().lookup(Registries.POTION)
.ifPresent(potion -> generatePotionEffectTypes(output, potion, ModItems.POTION_MORTAR_SHELL.get(),
CreativeModeTab.TabVisibility.PARENT_AND_SEARCH_TABS,
param.enabledFeatures()));
})
.build());
@ -97,10 +103,12 @@ public class ModTabs {
}
}
// TODO potion shell
// private static void generatePotionEffectTypes(CreativeModeTab.Output output, HolderLookup<Potion> potions, Item potionItem) {
// potions.listElements().filter(potion -> !potion.is(Potions.EMPTY_ID))
// .map(potion -> PotionUtils.setPotion(new ItemStack(potionItem), potion.value()))
// .forEach(output::accept);
// }
private static void generatePotionEffectTypes(
CreativeModeTab.Output output, HolderLookup<Potion> potions, Item item, CreativeModeTab.TabVisibility visibility, FeatureFlagSet requiredFeatures
) {
potions.listElements()
.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;
//@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 PotionMortarShell() {
super();
}
// TODO default instance
// @Override
// public ItemStack getDefaultInstance() {
// return PotionUtils.setPotion(super.getDefaultInstance(), Potions.POISON);
// }
@Override
public ItemStack getDefaultInstance() {
ItemStack itemstack = super.getDefaultInstance();
itemstack.set(DataComponents.POTION_CONTENTS, new PotionContents(Potions.POISON));
return itemstack;
}
// @Override
// public void appendHoverText(ItemStack pStack, @Nullable Level pLevel, List<Component> pTooltip, TooltipFlag pFlag) {
// PotionUtils.addPotionTooltip(pStack, pTooltip, 0.125F);
// }
@Override
public void appendHoverText(ItemStack stack, Item.TooltipContext context, List<Component> tooltipComponents, TooltipFlag tooltipFlag) {
PotionContents potioncontents = stack.get(DataComponents.POTION_CONTENTS);
if (potioncontents != null) {
potioncontents.addPotionTooltip(tooltipComponents::add, 0.125F, context.tickRate());
}
}
// @SubscribeEvent
// public static void onRegisterColorHandlers(final RegisterColorHandlersEvent.Item event) {
// event.register((stack, layer) -> layer == 1 ? PotionUtils.getColor(stack) : -1, ModItems.POTION_MORTAR_SHELL.get());
// }
@SubscribeEvent
public static void onRegisterColorHandlers(final RegisterColorHandlersEvent.Item event) {
event.register((stack, layer) -> layer == 1 ? FastColor.ARGB32.opaque(stack.getOrDefault(DataComponents.POTION_CONTENTS, PotionContents.EMPTY).getColor()) : -1,
ModItems.POTION_MORTAR_SHELL.get());
}
}