Skip to content
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 @@ -19,17 +19,21 @@
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.Nullable;
import vectorwing.farmersdelight.common.block.SkilletBlock;
import vectorwing.farmersdelight.common.registry.ModSounds;

public class CuisineSkilletBlock extends SkilletBlock {

protected static final VoxelShape SHAPE_WITH_ABOVE = Block.box(1.0, 0.0, 1.0, 15.0, 8, 15.0);

public CuisineSkilletBlock(Properties properties) {
super(properties);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,26 @@
import dev.xkmc.cuisinedelight.content.item.CuisineSkilletItem;
import dev.xkmc.cuisinedelight.content.item.SpatulaItem;
import dev.xkmc.cuisinedelight.content.logic.CookingData;
import dev.xkmc.cuisinedelight.content.logic.IngredientConfig;
import dev.xkmc.cuisinedelight.init.data.CDConfig;
import dev.xkmc.cuisinedelight.init.registrate.CDItems;
import dev.xkmc.l2library.base.tile.BaseBlockEntity;
import dev.xkmc.l2serial.serialization.SerialClass;
import net.minecraft.core.BlockPos;
import net.minecraft.core.NonNullList;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.entity.EntitySelector;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import vectorwing.farmersdelight.common.block.entity.HeatableBlockEntity;
import vectorwing.farmersdelight.common.registry.ModSounds;

import javax.annotation.Nonnull;
import java.util.List;

@SerialClass
public class CuisineSkilletBlockEntity extends BaseBlockEntity implements HeatableBlockEntity {
Expand All @@ -38,6 +45,42 @@ public void tick(Level pLevel, BlockPos pPos, BlockState pState) {
if (stirTimer > 0) {
stirTimer--;
}
if (!pLevel.isClientSide) {
for (ItemEntity itemEntity : getItemsAtAndAbove(pLevel, pPos)) {
ItemStack heldStack = itemEntity.getItem();
IngredientConfig.IngredientEntry config = IngredientConfig.get().getEntry(heldStack);
if (config != null) {
if (!this.canCook()) {
return;
}

if (this.cookingData.contents.size() >= CDConfig.COMMON.maxIngredient.get()) {
return;
}

int count = 1 + this.baseItem.getEnchantmentLevel(Enchantments.BLOCK_EFFICIENCY);
if (this.slowCook()) {
this.cookingData.setSpeed(0.5F);
}
ItemStack add = heldStack.split(count);
this.cookingData.addItem(add, pLevel.getGameTime());
ItemStack remain = add.getCraftingRemainingItem();
remain.setCount(add.getCount());
itemEntity.setItem(remain);
if (remain.isEmpty()) {
itemEntity.discard();
}
pLevel.playSound(null, pPos.getX(), pPos.getY(), pPos.getZ(), ModSounds.BLOCK_SKILLET_ADD_FOOD.get(),
SoundSource.BLOCKS, 0.4F, pLevel.random.nextFloat() * 0.2F + 0.9F);
this.sync();
}
}
}
}

public static List<ItemEntity> getItemsAtAndAbove(Level level, BlockPos pos) {
return CuisineSkilletBlock.SHAPE_WITH_ABOVE.toAabbs().stream().flatMap((aabb) ->
level.getEntitiesOfClass(ItemEntity.class, aabb.move(pos.getX(), pos.getY(), pos.getZ()), EntitySelector.ENTITY_STILL_ALIVE).stream()).toList();
}

public boolean isCooking() {
Expand Down