use of pl.asie.charset.module.crafting.cauldron.api.ICauldron in project Charset by CharsetMC.
the class BlockCauldronCharset method onEntityCollidedWithBlock.
@Override
public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn) {
if (!worldIn.isRemote) {
TileEntity tile = worldIn.getTileEntity(pos);
if (tile instanceof TileCauldronCharset) {
FluidStack stack = ((TileCauldronCharset) tile).getContents();
float height = (float) pos.getY() + ((TileCauldronCharset) tile).getFluidHeight() / 16.0F;
if (stack != null && stack.amount > 0 && entityIn.getEntityBoundingBox().minY <= height) {
if (stack.getFluid() == FluidRegistry.LAVA) {
if (!entityIn.isBurning() && stack.amount >= 100 && !entityIn.isImmuneToFire()) {
entityIn.setFire(stack.amount / 100);
return;
}
} else if (stack.getFluid() == FluidRegistry.WATER) {
if (entityIn.isBurning() && stack.amount >= 250) {
entityIn.extinguish();
((TileCauldronCharset) tile).drain(250, true);
return;
}
}
if (entityIn instanceof EntityItem) {
EntityItem entityItem = (EntityItem) entityIn;
ItemStack heldItem = entityItem.getItem();
if (!heldItem.isEmpty()) {
ItemStack heldItemOne = heldItem.copy();
heldItemOne.setCount(1);
Optional<CauldronContents> contentsNew = Optional.empty();
Optional<ItemStack> fluidResult = FluidUtils.handleTank((IFluidHandler) tile, stack, worldIn, pos, heldItemOne, false, true, false);
if (fluidResult.isPresent()) {
contentsNew = Optional.of(new CauldronContents(((TileCauldronCharset) tile).getContents(), fluidResult.get()));
}
if (!contentsNew.isPresent()) {
contentsNew = CharsetCraftingCauldron.craft((ICauldron) tile, new CauldronContents(CauldronContents.Source.ENTITY, stack, heldItemOne));
}
if (contentsNew.isPresent()) {
CauldronContents cc = contentsNew.get();
if (cc.hasResponse()) {
new Notice(tile, cc.getResponse()).sendToAll();
} else {
if (cc.getHeldItem().isEmpty()) {
heldItem.shrink(1);
} else if (cc.getHeldItem().getCount() == 1 && ItemUtils.canMerge(cc.getHeldItem(), heldItem)) {
// pass
} else {
heldItem.shrink(1);
ItemUtils.spawnItemEntity(worldIn, entityItem.getPositionVector(), cc.getHeldItem(), 0, 0, 0, 0);
}
((TileCauldronCharset) tile).setContents(cc.getFluidStack());
}
}
}
}
}
}
}
}
Aggregations