-
Notifications
You must be signed in to change notification settings - Fork 308
Expand file tree
/
Copy pathItemSigilLava.java
More file actions
105 lines (92 loc) · 3.72 KB
/
ItemSigilLava.java
File metadata and controls
105 lines (92 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package wayoftime.bloodmagic.common.item.sigil;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.core.Direction;
import net.minecraft.world.InteractionHand;
import net.minecraft.core.BlockPos;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.level.Level;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.capability.IFluidHandler;
import wayoftime.bloodmagic.common.item.IAlchemyItem;
import wayoftime.bloodmagic.core.data.SoulTicket;
import wayoftime.bloodmagic.util.helper.NetworkHelper;
import wayoftime.bloodmagic.util.helper.PlayerHelper;
import wayoftime.bloodmagic.ConfigManager;
public class ItemSigilLava extends ItemSigilFluidBase implements IAlchemyItem
{
public ItemSigilLava()
{
super("lava", 1000, new FluidStack(Fluids.LAVA, 10000));
}
@Override
public int getLpUsed()
{
return ConfigManager.COMMON.sigilLavaCost.get();
}
@Override
public InteractionResultHolder<ItemStack> use(Level world, Player player, InteractionHand hand)
{
ItemStack stack = player.getItemInHand(hand);
if (stack.getItem() instanceof ISigil.Holding)
stack = ((Holding) stack.getItem()).getHeldItem(stack, player);
if (PlayerHelper.isFakePlayer(player))
return InteractionResultHolder.fail(stack);
if (!world.isClientSide && !isUnusable(stack))
{
HitResult rayTrace = getPlayerPOVHitResult(world, player, ClipContext.Fluid.NONE);
if (rayTrace == null || rayTrace.getType() != HitResult.Type.BLOCK)
{
return InteractionResultHolder.fail(stack);
}
BlockHitResult blockRayTrace = (BlockHitResult) rayTrace;
BlockPos blockPos = blockRayTrace.getBlockPos();
Direction sideHit = blockRayTrace.getDirection();
BlockPos blockpos1 = blockPos.relative(sideHit);
if (world.mayInteract(player, blockPos) && player.mayUseItemAt(blockpos1, sideHit, stack))
{
// Case for if block at blockPos is a fluid handler like a tank
// Try to put fluid into tank
IFluidHandler destination = getFluidHandler(world, blockPos, null);
if (destination != null && tryInsertSigilFluid(destination, false) && NetworkHelper.getSoulNetwork(getBinding(stack)).syphonAndDamage(player, SoulTicket.item(stack, world, player, getLpUsed())).isSuccess())
{
boolean result = tryInsertSigilFluid(destination, true);
if (result)
return InteractionResultHolder.success(stack);
}
// Do the same as above, but use sidedness to interact with the fluid handler.
IFluidHandler destinationSide = getFluidHandler(world, blockPos, sideHit);
if (destinationSide != null && tryInsertSigilFluid(destinationSide, false) && NetworkHelper.getSoulNetwork(getBinding(stack)).syphonAndDamage(player, SoulTicket.item(stack, world, player, getLpUsed())).isSuccess())
{
boolean result = tryInsertSigilFluid(destinationSide, true);
if (result)
return InteractionResultHolder.success(stack);
}
// Case for if block at blockPos is not a tank
// Place fluid in world
if (destination == null && destinationSide == null)
{
if (tryPlaceSigilFluid(player, world, blockpos1) && NetworkHelper.getSoulNetwork(getBinding(stack)).syphonAndDamage(player, SoulTicket.item(stack, world, player, getLpUsed())).isSuccess())
{
return InteractionResultHolder.success(stack);
}
}
}
}
return super.use(world, player, hand);
}
@Override
public ItemStack onConsumeInput(ItemStack stack)
{
return stack;
}
@Override
public boolean isStackChangedOnUse(ItemStack stack)
{
return false;
}
}