Skip to content

Commit

Permalink
Merge pull request #283 from Gu-ZT/Chute
Browse files Browse the repository at this point in the history
修复在特定摆放方式下,溜槽出现卡物品的问题
  • Loading branch information
Gu-ZT authored Apr 14, 2024
2 parents 1e79d47 + 8172c37 commit 2ea64dd
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 29 deletions.
27 changes: 15 additions & 12 deletions common/src/main/java/dev/dubhe/anvilcraft/block/ChuteBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,21 @@ public void neighborChanged(
if (!bl) level.scheduleTick(pos, this, 4);
else level.setBlock(pos, state.cycle(ENABLED), 2);
}
if (!neighborPos.equals(pos.relative(state.getValue(FACING)))) return;
BlockState blockState = level.getBlockState(neighborPos);
if (blockState.is(ModBlocks.CHUTE.get())) return;
if (hasChuteFacing(level, neighborPos)) {
BlockState newState = ModBlocks.SIMPLE_CHUTE.getDefaultState();
newState = newState.setValue(SimpleChuteBlock.FACING, blockState.getValue(FACING))
.setValue(SimpleChuteBlock.ENABLED, blockState.getValue(ENABLED));
BlockState upState = level.getBlockState(neighborPos.relative(Direction.UP));
if (upState.is(ModBlocks.SIMPLE_CHUTE.get()) || upState.is(ModBlocks.CHUTE.get())) {
if (upState.getValue(FACING) == Direction.DOWN) {
newState = newState.setValue(SimpleChuteBlock.TALL, true);
}
}
level.setBlockAndUpdate(neighborPos, newState);
}
}

@SuppressWarnings("deprecation")
Expand Down Expand Up @@ -278,18 +293,6 @@ public void onPlace(
}
level.setBlockAndUpdate(pos.relative(state.getValue(FACING)), newState);
}
if (hasChuteFacing(level, pos)) {
BlockState newState = ModBlocks.SIMPLE_CHUTE.getDefaultState();
newState = newState.setValue(SimpleChuteBlock.FACING, state.getValue(FACING))
.setValue(SimpleChuteBlock.ENABLED, state.getValue(ENABLED));
BlockState upState = level.getBlockState(pos.relative(Direction.UP));
if (upState.is(ModBlocks.SIMPLE_CHUTE.get()) || upState.is(ModBlocks.CHUTE.get())) {
if (upState.getValue(FACING) == Direction.DOWN) {
newState = newState.setValue(SimpleChuteBlock.TALL, true);
}
}
level.setBlockAndUpdate(pos, newState);
}
super.onPlace(state, level, pos, oldState, movedByPiston);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@

import javax.annotation.Nonnull;

import static dev.dubhe.anvilcraft.block.ChuteBlock.hasChuteFacing;

public class SimpleChuteBlock extends BaseEntityBlock implements
SimpleWaterloggedBlock, IHammerChangeable, IHammerRemovable {
public static final DirectionProperty FACING = BlockStateProperties.FACING_HOPPER;
Expand Down Expand Up @@ -68,10 +70,10 @@ public class SimpleChuteBlock extends BaseEntityBlock implements
public SimpleChuteBlock(Properties properties) {
super(properties);
this.registerDefaultState(this.stateDefinition.any()
.setValue(FACING, Direction.DOWN)
.setValue(WATERLOGGED, false)
.setValue(ENABLED, true)
.setValue(TALL, false));
.setValue(FACING, Direction.DOWN)
.setValue(WATERLOGGED, false)
.setValue(ENABLED, true)
.setValue(TALL, false));
}

@Nullable
Expand All @@ -81,7 +83,7 @@ public BlockEntity newBlockEntity(@NotNull BlockPos pos, @NotNull BlockState sta
}

@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
protected void createBlockStateDefinition(@NotNull StateDefinition.Builder<Block, BlockState> builder) {
builder.add(FACING, WATERLOGGED, ENABLED, TALL);
}

Expand All @@ -98,6 +100,21 @@ public void neighborChanged(
if (!bl) level.scheduleTick(pos, this, 4);
else level.setBlock(pos, state.cycle(ENABLED), 2);
}
if (!neighborPos.equals(pos.relative(state.getValue(FACING)))) return;
BlockState blockState = level.getBlockState(neighborPos);
if (blockState.is(ModBlocks.CHUTE.get())) return;
if (ChuteBlock.hasChuteFacing(level, neighborPos)) {
BlockState newState = ModBlocks.SIMPLE_CHUTE.getDefaultState();
newState = newState.setValue(SimpleChuteBlock.FACING, blockState.getValue(FACING))
.setValue(SimpleChuteBlock.ENABLED, blockState.getValue(ENABLED));
BlockState upState = level.getBlockState(neighborPos.relative(Direction.UP));
if (upState.is(ModBlocks.SIMPLE_CHUTE.get()) || upState.is(ModBlocks.CHUTE.get())) {
if (upState.getValue(FACING) == Direction.DOWN) {
newState = newState.setValue(SimpleChuteBlock.TALL, true);
}
}
level.setBlockAndUpdate(neighborPos, newState);
}
}

@SuppressWarnings("deprecation")
Expand Down Expand Up @@ -133,24 +150,24 @@ public void onRemove(
}
BlockState facingState = level.getBlockState(pos.relative(state.getValue(FACING)));
if (facingState.is(ModBlocks.SIMPLE_CHUTE.get())
&& !newState.is(ModBlocks.CHUTE.get())
&& !ChuteBlock.hasChuteFacing(level, pos.relative(state.getValue(FACING)))) {
&& !newState.is(ModBlocks.CHUTE.get())
&& !hasChuteFacing(level, pos.relative(state.getValue(FACING)))) {
BlockState newBlockState = ModBlocks.CHUTE.getDefaultState();
newBlockState = newBlockState
.setValue(FACING, facingState.getValue(SimpleChuteBlock.FACING))
.setValue(ENABLED, facingState.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));
if (state.getValue(FACING) == Direction.DOWN
&& downState.is(ModBlocks.SIMPLE_CHUTE.get())
&& !newState.is(ModBlocks.SIMPLE_CHUTE.get())
&& !newState.is(ModBlocks.CHUTE.get())) {
&& 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))
.setValue(ENABLED, downState.getValue(ENABLED))
.setValue(TALL, false);
.setValue(FACING, downState.getValue(FACING))
.setValue(ENABLED, downState.getValue(ENABLED))
.setValue(TALL, false);
level.setBlockAndUpdate(pos.relative(Direction.DOWN), newBlockState);
}
super.onRemove(state, level, pos, newState, movedByPiston);
Expand All @@ -159,11 +176,11 @@ public void onRemove(
@Nullable
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(
Level level, @NotNull BlockState state, @NotNull BlockEntityType<T> blockEntityType
@NotNull Level level, @NotNull BlockState state, @NotNull BlockEntityType<T> blockEntityType
) {
if (level.isClientSide) return null;
return createTickerHelper(blockEntityType, ModBlockEntities.SIMPLE_CHUTE.get(),
((level1, blockPos, blockState, blockEntity) -> blockEntity.tick()));
((level1, blockPos, blockState, blockEntity) -> blockEntity.tick()));
}

@SuppressWarnings("deprecation")
Expand Down

0 comments on commit 2ea64dd

Please sign in to comment.