Skip to content

Commit

Permalink
实现傻溜槽的中键选取
Browse files Browse the repository at this point in the history
  • Loading branch information
DancingSnow0517 committed Apr 11, 2024
1 parent 869de1b commit 8b46152
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,24 @@ public void load(@NotNull CompoundTag tag) {
@SuppressWarnings({"UnreachableCode", "DuplicatedCode"})
public void tick() {
if (cooldown <= 0) {
if (ItemDepositoryHelper.getItemDepository(getLevel(), getBlockPos().relative(getDirection()), getDirection().getOpposite()) != null) {
// 尝试向朝向容器输出
if (!depository.isEmpty()) {
ItemDepositoryHelper.exportToTarget(depository, 64, stack -> true, getLevel(), getBlockPos().relative(getDirection()), getDirection().getOpposite());
}
} else {
Vec3 center = getBlockPos().relative(getDirection()).getCenter();
AABB aabb = new AABB(center.add(-0.125, -0.125, -0.125), center.add(0.125, 0.125, 0.125));
if (getLevel().noCollision(aabb)) {
for (int i = 0; i < depository.getSlots(); i++) {
ItemStack stack = depository.getStack(i);
if (!stack.isEmpty()) {
ItemEntity itemEntity = new ItemEntity(getLevel(), center.x, center.y, center.z, stack, 0, 0, 0);
getLevel().addFreshEntity(itemEntity);
depository.setStack(i, ItemStack.EMPTY);
break;
if (getBlockState().getValue(SimpleChuteBlock.ENABLED)) {
if (ItemDepositoryHelper.getItemDepository(getLevel(), getBlockPos().relative(getDirection()), getDirection().getOpposite()) != null) {
// 尝试向朝向容器输出
if (!depository.isEmpty()) {
ItemDepositoryHelper.exportToTarget(depository, 64, stack -> true, getLevel(), getBlockPos().relative(getDirection()), getDirection().getOpposite());
}
} else {
Vec3 center = getBlockPos().relative(getDirection()).getCenter();
AABB aabb = new AABB(center.add(-0.125, -0.125, -0.125), center.add(0.125, 0.125, 0.125));
if (getLevel().noCollision(aabb)) {
for (int i = 0; i < depository.getSlots(); i++) {
ItemStack stack = depository.getStack(i);
if (!stack.isEmpty()) {
ItemEntity itemEntity = new ItemEntity(getLevel(), center.x, center.y, center.z, stack, 0, 0, 0);
getLevel().addFreshEntity(itemEntity);
depository.setStack(i, ItemStack.EMPTY);
break;
}
}
}
}
Expand Down
15 changes: 10 additions & 5 deletions common/src/main/java/dev/dubhe/anvilcraft/init/ModBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import net.minecraft.data.recipes.RecipeCategory;
import net.minecraft.data.recipes.ShapedRecipeBuilder;
import net.minecraft.tags.BlockTags;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
Expand Down Expand Up @@ -120,7 +122,9 @@ public class ModBlocks {
.properties(BlockBehaviour.Properties::noOcclusion)
.blockstate((ctx, provider) -> {
})
.simpleItem()
.item(BlockItem::new)
.onRegister(blockItem -> Item.BY_BLOCK.put(ModBlocks.SIMPLE_CHUTE.get(), blockItem))
.build()
.defaultLoot()
.tag(BlockTags.MINEABLE_WITH_PICKAXE, BlockTags.MINEABLE_WITH_AXE)
.recipe((ctx, provider) -> ShapedRecipeBuilder.shaped(RecipeCategory.TOOLS, ModBlocks.CHUTE)
Expand All @@ -138,7 +142,8 @@ public class ModBlocks {
.block("simple_chute", SimpleChuteBlock::new)
.initialProperties(() -> Blocks.IRON_BLOCK)
.properties(BlockBehaviour.Properties::noOcclusion)
.blockstate((ctx, provider) -> {})
.blockstate((ctx, provider) -> {
})
.loot((tables, block) -> tables.dropOther(block, ModBlocks.CHUTE))
.tag(BlockTags.MINEABLE_WITH_PICKAXE, BlockTags.MINEABLE_WITH_AXE)
.register();
Expand Down Expand Up @@ -316,9 +321,9 @@ public class ModBlocks {
.initialProperties(() -> Blocks.SLIME_BLOCK)
.blockstate((ctx, provider) -> {
provider.simpleBlock(ctx.get());
provider.models().cubeAll(ctx.getName(), provider.modLoc( "block/" + ctx.getName())).renderType("translucent");
provider.models().cubeAll(ctx.getName(), provider.modLoc("block/" + ctx.getName())).renderType("translucent");
})
.properties(properties->properties.sound(SoundType.HONEY_BLOCK))
.properties(properties -> properties.sound(SoundType.HONEY_BLOCK))
.simpleItem()
.defaultLoot()
.tag(BlockTags.MINEABLE_WITH_PICKAXE)
Expand All @@ -335,7 +340,7 @@ public class ModBlocks {
.initialProperties(() -> Blocks.EMERALD_BLOCK)
.blockstate((ctx, provider) -> {
provider.simpleBlock(ctx.get());
provider.models().cubeAll(ctx.getName(), provider.modLoc( "block/" + ctx.getName())).renderType("translucent");
provider.models().cubeAll(ctx.getName(), provider.modLoc("block/" + ctx.getName())).renderType("translucent");
})
.properties(BlockBehaviour.Properties::noOcclusion)
.simpleItem()
Expand Down

0 comments on commit 8b46152

Please sign in to comment.