ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/items/CanolaSeed.java

49 lines
1.8 KiB
Java
Raw Normal View History

2022-01-09 18:58:55 +01:00
package de.ellpeck.actuallyadditions.mod.items;
import de.ellpeck.actuallyadditions.mod.fluids.InitFluids;
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
2024-03-02 21:23:08 +01:00
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.LiquidBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Fluid;
2022-01-09 18:58:55 +01:00
public class CanolaSeed extends ItemBase {
public boolean empowered;
public CanolaSeed(boolean empowered) {
this.empowered = empowered;
}
@Override
public boolean isFoil(ItemStack p_77636_1_) {
return empowered;
}
@Override
public boolean onEntityItemUpdate(ItemStack stack, ItemEntity entity) {
2024-03-03 01:20:53 +01:00
if (!entity.level().isClientSide) {
2022-01-09 18:58:55 +01:00
if (stack != null) {
BlockPos pos = entity.blockPosition();
2024-03-03 01:20:53 +01:00
BlockState state = entity.level().getBlockState(pos);
2022-01-09 18:58:55 +01:00
Block block = state.getBlock();
2024-03-02 21:23:08 +01:00
if (block instanceof LiquidBlock && state.getFluidState().isSource()) {
Fluid fluid = ((LiquidBlock) block).getFluid();
2022-01-09 18:58:55 +01:00
if (fluid != null && fluid == (empowered
? InitFluids.CRYSTALLIZED_OIL.get()
2022-01-09 18:58:55 +01:00
: InitFluids.REFINED_CANOLA_OIL.get())) {
entity.kill();
2024-03-03 01:20:53 +01:00
entity.level().setBlockAndUpdate(pos, (empowered
2022-01-09 18:58:55 +01:00
? InitFluids.EMPOWERED_OIL.getBlock()
: InitFluids.CRYSTALLIZED_OIL.getBlock()).defaultBlockState());
2022-01-09 18:58:55 +01:00
}
}
}
}
return super.onEntityItemUpdate(stack, entity);
}
}