Skip to content
Merged
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 @@ -15,7 +15,7 @@
" A "
],
"result": {
"count": 1,
"count": 4,
"id": "anvilcraft_pigsplus:cauldron_output"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,24 @@

import dev.anvilcraft.pigsplus.block.CauldronOutputBlock;
import dev.anvilcraft.pigsplus.init.AddonBlocks;
import dev.dubhe.anvilcraft.api.itemhandler.ItemHandlerUtil;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.tags.BlockTags;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.AbstractCauldronBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import net.neoforged.neoforge.items.IItemHandler;
import net.neoforged.neoforge.items.ItemStackHandler;

public class CauldronOutputBlockEntity extends BlockEntity {
public CauldronOutputBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState blockState) {
Expand All @@ -19,21 +28,32 @@ public CauldronOutputBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockSta

public void tick() {
if (level == null) return;
if (level.hasNeighborSignal(getBlockPos())) return;

BlockState state = getBlockState();
if (!state.is(AddonBlocks.CAULDRON_OUTPUT.get())) return;

Direction facing = state.getValue(CauldronOutputBlock.FACING);
BlockPos cauldronPos = getBlockPos().relative(facing.getOpposite());
BlockState cauldronState = level.getBlockState(cauldronPos);
if (!cauldronState.is(BlockTags.CAULDRONS)) return;
if (cauldronState.is(BlockTags.CAULDRONS)) {
extractItemFromCauldron(cauldronPos, facing, level);
extractFluidFromCauldron(cauldronPos, level);
} else {
IItemHandler source = ItemHandlerUtil.getSourceItemHandler(cauldronPos, facing, level);
if (source == null) return;

extractItemFromSource(facing, level, source);
}
}

private void extractItemFromCauldron(BlockPos cauldronPos, Direction facing, Level level) {
AABB searchBox = new AABB(cauldronPos);
level.getEntities(EntityType.ITEM, searchBox, (e)->!e.anvilcraft$isAdsorbable())
level.getEntities(EntityType.ITEM, searchBox, (e) -> !e.anvilcraft$isAdsorbable())
.forEach(entity -> {
Vec3 targetPos = getBlockPos().getCenter().add(
-facing.getStepX() * 0.2,
0,
-0.3,
-facing.getStepZ() * 0.2
);
entity.teleportTo(targetPos.x, targetPos.y, targetPos.z);
Expand All @@ -42,4 +62,31 @@ public void tick() {
entity.setDeltaMovement(Vec3.ZERO);
});
}

private void extractFluidFromCauldron(BlockPos cauldronPos, Level level) {
BlockPos outputPos = getBlockPos().below();
BlockState inputState = level.getBlockState(cauldronPos);
BlockState outputState = level.getBlockState(outputPos);

if (outputState.is(Blocks.CAULDRON) &&
inputState.getBlock() instanceof AbstractCauldronBlock cauldron &&
cauldron.isFull(inputState)) {
level.setBlock(outputPos, inputState, Block.UPDATE_ALL);
level.setBlock(cauldronPos, outputState, Block.UPDATE_ALL);
}
}

private void extractItemFromSource(Direction facing, Level level, IItemHandler source) {
ItemStackHandler itemHandler = new ItemStackHandler();
ItemHandlerUtil.importFromTarget(itemHandler, 64, stack -> true, source);
// 将itemHandler的物品输出到世界中
for (int i = 0; i < itemHandler.getSlots(); i++) {
ItemStack stack = itemHandler.getStackInSlot(i);
if (stack.isEmpty()) continue;
Vec3 targetPos = getBlockPos().getCenter()
.add(-facing.getStepX() * 0.2, -0.3, -facing.getStepZ() * 0.2);
ItemEntity itemEntity = new ItemEntity(level, targetPos.x, targetPos.y, targetPos.z, stack.copy(), 0, 0, 0);
level.addFreshEntity(itemEntity);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,14 @@ public void tick() {
return true;
} else if (
state.is(AddonBlocks.ECHO_CLUSTER)) {
level.setBlockAndUpdate(blockPos, Blocks.AIR.defaultBlockState());
sculkValue.getAndAdd(50);
return true;
} else if (state.is(AddonBlocks.BUDDING_ECHO_SHARD)) {
} else if (state.is(AddonBlocks.BUDDING_ECHO_SHARD) ||
state.is(AddonBlocks.SCULK_EXTRACTOR)) {
return true;
} else {
return state.is(AddonBlocks.SCULK_EXTRACTOR);
return false;
}
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class AddonBlocks {
.blockstate(DataGenUtil::noExtraModelOrState)
.simpleItem()
.tag(BlockTags.MINEABLE_WITH_PICKAXE)
.recipe((ctx, provider) -> ShapedRecipeBuilder.shaped(RecipeCategory.MISC, ctx.get())
.recipe((ctx, provider) -> ShapedRecipeBuilder.shaped(RecipeCategory.MISC, ctx.get(), 4)
.pattern(" A ")
.pattern("ABA")
.pattern(" A ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"sortnum": 14101,
"entry_color": "DD6666",
"pages": [
"贴在$(item)炼药锅$()上以使用,可以直接输出制作完成的物品",
"贴在$(item)炼药锅$()上以使用 $(li)输出制作完成的物品 $(li)如果炼药锅装满了流体,输出流体至下方的空锅 $(li)如果贴在容器上,可以输出物品 $(li)可以被红石信号关闭",
{
"type": "patchouli:crafting",
"recipe": "anvilcraft_pigsplus:cauldron_output"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"format_version": "1.21.6",
"credit": "Made with Blockbench",
"parent": "minecraft:block/cube",
"render_type": "minecraft:cutout",
Expand Down Expand Up @@ -36,7 +37,8 @@
"translation": [0, 1, 7]
},
"gui": {
"translation": [0, 2.5, 0]
"rotation": [30, -135, 0],
"translation": [-6.25, 3.75, 0]
},
"fixed": {
"translation": [0, 0, 6.5]
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.