Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Void Seed to replace Experience Rod early game #638

Open
wants to merge 4 commits into
base: dev/1.21.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,13 @@ public boolean canFillFluidType(FluidStack fluid) {
public boolean isFluidValid(int tank, FluidStack stack) {
return fluidPredicate.test(stack.getFluid());
}

//Convert to present fluid if needed
@Override
public int fill(FluidStack resource, FluidAction doFill) {
if (!getFluid().isEmpty() && fluidPredicate.test(resource.getFluid())) {
resource = new FluidStack(getFluid().getFluid(), resource.getAmount());
}
return super.fill(resource, doFill);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@
"item.enderio.vibrant_crystal": "Vibrant Crystal",
"item.enderio.vibrant_gear": "Vibrant Bimetal Gear",
"item.enderio.vibrant_powder": "Grains of Vibrancy",
"item.enderio.void_seed": "Void Seed",
"item.enderio.weather_crystal": "Weather Crystal",
"item.enderio.withering_powder": "Withering Powder",
"item.enderio.wood_gear": "Wooden Gear",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "enderio:item/void_seed"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"parent": "minecraft:recipes/root",
"criteria": {
"has_ingredient": {
"conditions": {
"items": [
{
"items": "enderio:empty_soul_vial"
}
]
},
"trigger": "minecraft:inventory_changed"
},
"has_the_recipe": {
"conditions": {
"recipe": "enderio:void_seed"
},
"trigger": "minecraft:recipe_unlocked"
}
},
"requirements": [
[
"has_the_recipe",
"has_ingredient"
]
],
"rewards": {
"recipes": [
"enderio:void_seed"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"type": "minecraft:crafting_shapeless",
"category": "equipment",
"ingredients": [
{
"item": "enderio:empty_soul_vial"
},
{
"item": "enderio:grains_of_infinity"
},
{
"tag": "c:seeds"
}
],
"result": {
"count": 1,
"id": "enderio:void_seed"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.enderio.base.common.item.misc.HangGliderItem;
import com.enderio.base.common.item.misc.LocationPrintoutItem;
import com.enderio.base.common.item.misc.MaterialItem;
import com.enderio.base.common.item.tool.VoidSeedItem;
import com.enderio.base.common.item.tool.ColdFireIgniter;
import com.enderio.base.common.item.tool.CoordinateSelectorItem;
import com.enderio.base.common.item.tool.ElectromagnetItem;
Expand Down Expand Up @@ -409,6 +410,11 @@ private static RegiliteItem<MaterialItem> materialItemGlinted(String name) {
modifier -> EIOItems.COLD_FIRE_IGNITER.get().addAllVariants(modifier)) // TODO: Might PR this to ITEM_REGISTRY so its nicer, but I like the footprint.
.addCapability(Capabilities.FluidHandler.ITEM, ColdFireIgniter.FLUID_HANDLER_PROVIDER);

public static final RegiliteItem<VoidSeedItem> VOID_SEED = ITEM_REGISTRY
.register("void_seed", () -> new VoidSeedItem(new Item.Properties().stacksTo(1).craftRemainder(EIOItems.EMPTY_SOUL_VIAL.get())))
.setTab(EIOCreativeTabs.MAIN)
.addCapability(Capabilities.FluidHandler.ITEM, VoidSeedItem.FLUID_HANDLER_PROVIDER);

// endregion

// region filter
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
package com.enderio.base.common.item.tool;

import com.enderio.base.common.init.EIODataComponents;
import com.enderio.base.common.init.EIOFluids;
import com.enderio.base.common.tag.EIOTags;
import com.enderio.base.common.util.ExperienceUtil;
import com.enderio.core.common.capability.StrictFluidHandlerItemStack;
import net.minecraft.network.chat.Component;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.item.UseAnim;
import net.minecraft.world.level.Level;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.capabilities.Capabilities;
import net.neoforged.neoforge.capabilities.ICapabilityProvider;
import net.neoforged.neoforge.event.entity.player.PlayerXpEvent;
import net.neoforged.neoforge.fluids.FluidStack;
import net.neoforged.neoforge.fluids.capability.IFluidHandler;
import net.neoforged.neoforge.fluids.capability.IFluidHandlerItem;

import java.util.List;

@EventBusSubscriber(bus = EventBusSubscriber.Bus.GAME)
public class VoidSeedItem extends Item {

public static ICapabilityProvider<ItemStack, Void, IFluidHandlerItem> FLUID_HANDLER_PROVIDER =
(stack, v) -> new StrictFluidHandlerItemStack(EIODataComponents.ITEM_FLUID_CONTENT, stack, 3400, EIOTags.Fluids.EXPERIENCE); //0-10 levels

public VoidSeedItem(Properties pProperties) {
super(pProperties);
}

@Override
public InteractionResultHolder<ItemStack> use(Level pLevel, Player pPlayer, InteractionHand pUsedHand) {
ItemStack stack = pPlayer.getItemInHand(pUsedHand);
IFluidHandlerItem capability = stack.getCapability(Capabilities.FluidHandler.ITEM);
if (capability != null && capability.getFluidInTank(0).getAmount() < ExperienceUtil.EXP_TO_FLUID) {
return InteractionResultHolder.fail(stack);
}
pPlayer.startUsingItem(pUsedHand);
return InteractionResultHolder.consume(stack);
}

@Override
public ItemStack finishUsingItem(ItemStack pStack, Level pLevel, LivingEntity pLivingEntity) {
IFluidHandlerItem capability = pStack.getCapability(Capabilities.FluidHandler.ITEM);
if (pLivingEntity instanceof Player player && capability != null && capability.getFluidInTank(0).getAmount() > ExperienceUtil.EXP_TO_FLUID) {
FluidStack result = capability.drain((capability.getFluidInTank(0).getAmount() / ExperienceUtil.EXP_TO_FLUID) * ExperienceUtil.EXP_TO_FLUID, IFluidHandler.FluidAction.EXECUTE);
player.giveExperiencePoints(result.getAmount() / ExperienceUtil.EXP_TO_FLUID);
}
return pStack;
}

@Override
public UseAnim getUseAnimation(ItemStack pStack) {
return UseAnim.DRINK;
}

@Override
public boolean isBarVisible(ItemStack stack) {
return stack.getCapability(Capabilities.FluidHandler.ITEM) != null;
}

@Override //TODO nice color?
public int getBarColor(ItemStack stack) {
return 0xcfff18;
}

@Override
public int getBarWidth(ItemStack stack) {
var fluidHandler = stack.getCapability(Capabilities.FluidHandler.ITEM);
if (fluidHandler != null) {
return Math.round(fluidHandler.getFluidInTank(0).getAmount() * 13f / fluidHandler.getTankCapacity(0));
}

return 0;
}

@Override
public boolean isFoil(ItemStack pStack) {
var fluidHandler = pStack.getCapability(Capabilities.FluidHandler.ITEM);
if (fluidHandler != null) {
return fluidHandler.getFluidInTank(0).getAmount() == fluidHandler.getTankCapacity(0);
}
return super.isFoil(pStack);
}

@Override
public void appendHoverText(ItemStack stack, TooltipContext context, List<Component> components, TooltipFlag flag) {
super.appendHoverText(stack, context, components, flag);

var tankCap = stack.getCapability(Capabilities.FluidHandler.ITEM);
if (tankCap != null) {
Component postFix = tankCap.getFluidInTank(0).isEmpty() ? EIOFluids.XP_JUICE.get().getDescription() : tankCap.getFluidInTank(0).getHoverName();
components.add(Component.literal(tankCap.getFluidInTank(0).getAmount() + " / " + tankCap.getTankCapacity(0) + " ").append(postFix));
}
}

@Override
public int getUseDuration(ItemStack pStack, LivingEntity p_344979_) {
return (int) (1.6F * 20.0F); //default food time
}

@SubscribeEvent
static void collectEXP(PlayerXpEvent.PickupXp event) {
Player player = event.getEntity();
ItemStack stack = player.getItemInHand(InteractionHand.OFF_HAND);
if (!(stack.getItem() instanceof VoidSeedItem)) {
stack = player.getItemInHand(InteractionHand.MAIN_HAND);
}

if (stack.getItem() instanceof VoidSeedItem) {
IFluidHandler cap = stack.getCapability(Capabilities.FluidHandler.ITEM);
if (cap != null && event.getOrb().getValue() > 0 && cap.getFluidInTank(0).getAmount() < cap.getTankCapacity(0)) {
int exp = event.getOrb().getValue() * ExperienceUtil.EXP_TO_FLUID;
int amount = cap.fill(new FluidStack(EIOFluids.XP_JUICE.getSource(), exp), IFluidHandler.FluidAction.EXECUTE);
event.getOrb().value = exp - amount;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraft.data.recipes.RecipeProvider;
import net.minecraft.data.recipes.ShapedRecipeBuilder;
import net.minecraft.data.recipes.ShapelessRecipeBuilder;
import net.minecraft.tags.ItemTags;
import net.minecraft.world.item.Items;
import net.neoforged.neoforge.common.Tags;

Expand Down Expand Up @@ -125,6 +126,14 @@ private void addTools(RecipeOutput recipeOutput) {
.pattern("I ")
.unlockedBy("has_ingredient", InventoryChangeTrigger.TriggerInstance.hasItems(EIOItems.ENDER_CRYSTAL.get()))
.save(recipeOutput);

ShapelessRecipeBuilder
.shapeless(RecipeCategory.TOOLS, EIOItems.VOID_SEED.get())
.requires(EIOItems.EMPTY_SOUL_VIAL)
.requires(EIOItems.GRAINS_OF_INFINITY)
.requires(Tags.Items.SEEDS)
.unlockedBy("has_ingredient", InventoryChangeTrigger.TriggerInstance.hasItems(EIOItems.EMPTY_SOUL_VIAL))
.save(recipeOutput);
}

private void eraseFilterRecipes(RecipeOutput recipeOutput) {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
"P": {
"tag": "c:gems/pulsating_crystal"
},
"R": {
"item": "enderio:experience_rod"
"S": {
"item": "enderio:void_seed"
}
},
"pattern": [
"III",
"IRI",
"ISI",
"IPI"
],
"result": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,10 @@ protected void buildRecipes(RecipeOutput recipeOutput) {
ShapedRecipeBuilder
.shaped(RecipeCategory.MISC, MachineBlocks.XP_VACUUM)
.pattern("III")
.pattern("IRI")
.pattern("ISI")
.pattern("IPI")
.define('I', Tags.Items.INGOTS_IRON)
.define('R', EIOItems.EXPERIENCE_ROD)
.define('S', EIOItems.VOID_SEED)
.define('P', EIOTags.Items.GEMS_PULSATING_CRYSTAL)
.unlockedBy("has_ingredient", InventoryChangeTrigger.TriggerInstance.hasItems(EIOItems.PULSATING_CRYSTAL.get()))
.save(recipeOutput);
Expand Down