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 1e8fcd9 commit 869de1b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ public void onRemove(@NotNull BlockState state, @NotNull Level level, @NotNull B
&& !hasChuteFacing(level, pos.relative(state.getValue(FACING)))) {
BlockState newBlockState = ModBlocks.CHUTE.getDefaultState();
newBlockState = newBlockState
.setValue(FACING, state.getValue(SimpleChuteBlock.FACING))
.setValue(ENABLED, state.getValue(SimpleChuteBlock.ENABLED));
.setValue(FACING, facingState.getValue(SimpleChuteBlock.FACING))
.setValue(ENABLED, facingState.getValue(SimpleChuteBlock.ENABLED));
level.setBlockAndUpdate(pos.relative(state.getValue(FACING)), newBlockState);
}
BlockState downState = level.getBlockState(pos.relative(Direction.DOWN));
Expand All @@ -202,7 +202,9 @@ public void onPlace(BlockState state, Level level, BlockPos pos, BlockState oldS
newState = newState
.setValue(SimpleChuteBlock.FACING, facingState.getValue(FACING))
.setValue(SimpleChuteBlock.ENABLED, facingState.getValue(ENABLED));
if (state.getValue(FACING) == Direction.DOWN) {
BlockState facingUpState = level.getBlockState(pos.relative(state.getValue(FACING)).relative(Direction.UP));
if (state.getValue(FACING) == Direction.DOWN
|| ((facingUpState.is(ModBlocks.SIMPLE_CHUTE.get()) || facingUpState.is(ModBlocks.CHUTE.get())) && facingUpState.getValue(FACING) == Direction.DOWN)) {
newState = newState.setValue(SimpleChuteBlock.TALL, true);
} else {
newState = newState.setValue(SimpleChuteBlock.TALL, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ public void onRemove(@NotNull BlockState state, @NotNull Level level, @NotNull B
level.setBlockAndUpdate(pos.relative(state.getValue(FACING)), newBlockState);
}
BlockState downState = level.getBlockState(pos.relative(Direction.DOWN));
if (state.getValue(FACING) == Direction.DOWN && downState.is(ModBlocks.SIMPLE_CHUTE.get())) {
if (state.getValue(FACING) == Direction.DOWN
&& downState.is(ModBlocks.SIMPLE_CHUTE.get())
&& !newState.is(ModBlocks.SIMPLE_CHUTE.get())
&& !newState.is(ModBlocks.CHUTE.get())) {
BlockState newBlockState = ModBlocks.SIMPLE_CHUTE.getDefaultState();
newBlockState = newBlockState
.setValue(FACING, downState.getValue(FACING))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.item.ItemStack;
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 org.jetbrains.annotations.NotNull;

@Getter
Expand Down Expand Up @@ -53,14 +56,28 @@ public void load(@NotNull CompoundTag tag) {
depository.deserializeNBT(tag.getCompound("Inventory"));
}

@SuppressWarnings("UnreachableCode")
@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;
}
}
}
}
cooldown = AnvilCraft.config.chuteMaxCooldown;
} else {
Expand Down

0 comments on commit 869de1b

Please sign in to comment.