Skip to content

Commit

Permalink
update to 1.20.6
Browse files Browse the repository at this point in the history
- added delay when using
- make main hand work as well
  • Loading branch information
ferriarnus committed May 19, 2024
1 parent bb0dbd0 commit 45baae3
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public boolean isFluidValid(int tank, FluidStack stack) {
@Override
public int fill(FluidStack resource, FluidAction doFill) {
if (!getFluid().isEmpty() && fluidPredicate.test(resource.getFluid())) {
resource = new FluidStack(getFluid(), resource.getAmount());
resource = new FluidStack(getFluid().getFluid(), resource.getAmount());
}
return super.fill(resource, doFill);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
"conditions": {
"items": [
{
"items": [
"enderio:empty_soul_vial"
]
"items": "enderio:empty_soul_vial"
}
]
},
Expand Down
5 changes: 3 additions & 2 deletions src/generated/resources/data/enderio/recipes/void_seed.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
"item": "enderio:grains_of_infinity"
},
{
"tag": "forge:seeds"
"tag": "c:seeds"
}
],
"result": {
"item": "enderio:void_seed"
"count": 1,
"id": "enderio:void_seed"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"enderio:silent_heavy_weighted_pressure_plate",
"enderio:silent_light_weighted_pressure_plate",
"enderio:painted_redstone_block",
"enderio:conduit",
"enderio:fluid_tank",
"enderio:pressurized_fluid_tank",
"enderio:enchanter",
Expand All @@ -61,7 +62,6 @@
"enderio:crafter",
"enderio:soul_engine",
"enderio:drain",
"enderio:xp_obelisk",
"enderio:conduit"
"enderio:xp_obelisk"
]
}
49 changes: 28 additions & 21 deletions src/main/java/com/enderio/base/common/item/tool/VoidSeedItem.java
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
package com.enderio.base.common.item.tool;

import com.enderio.base.common.init.EIOAttachments;
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.attachment.IStrictItemFluidHandlerConfig;
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.level.Level;
import net.minecraft.world.level.material.Fluid;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.Mod;
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 org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.function.Predicate;

@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE)
public class VoidSeedItem extends Item implements IStrictItemFluidHandlerConfig {
@EventBusSubscriber(bus = EventBusSubscriber.Bus.GAME)
public class VoidSeedItem extends Item {

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

public VoidSeedItem(Properties pProperties) {
super(pProperties);
Expand All @@ -49,6 +48,16 @@ public InteractionResultHolder<ItemStack> use(Level pLevel, Player pPlayer, Inte
return InteractionResultHolder.fail(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 boolean isBarVisible(ItemStack stack) {
return stack.getCapability(Capabilities.FluidHandler.ITEM) != null;
Expand All @@ -69,31 +78,29 @@ public int getBarWidth(ItemStack stack) {
return 0;
}

@Override //TODO config
public int getFluidCapacity() {
return 3400; //0-10 levels
}

@Override
public Predicate<Fluid> getFluidFilter() {
return f -> f.is(EIOTags.Fluids.EXPERIENCE);
}

@Override
public void appendHoverText(ItemStack stack, @Nullable Level level, List<Component> components, TooltipFlag flag) {
super.appendHoverText(stack, level, components, flag);
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).getDisplayName();
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) {
return (int) 1.6F * 20; //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);
}
IFluidHandler cap = stack.getCapability(Capabilities.FluidHandler.ITEM);
if (stack.getItem() instanceof VoidSeedItem && cap != null && event.getOrb().getValue() > 0) {
if (cap.getFluidInTank(0).getAmount() < cap.getTankCapacity(0)) {
Expand Down

0 comments on commit 45baae3

Please sign in to comment.