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 @@ -36,14 +36,15 @@ public boolean onDestroyedByPlayer(BlockState state, Level level, BlockPos pos,
return placeRope(level, pos);
}

@Override
public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean movedByPiston) {
super.onRemove(state, level, pos, newState, movedByPiston);
if (Configuration.ENABLE_TOMATO_ROPE_PERMANENCE.get() && !movedByPiston && !state.is(newState.getBlock())) {
placeRope(level, pos);
}
}

public static boolean placeRope(Level level, BlockPos pos) {
public boolean placeRope(Level level, BlockPos pos) {
Block configuredRopeBlock = BuiltInRegistries.BLOCK.get(ResourceLocation.parse(Configuration.DEFAULT_TOMATO_VINE_ROPE.get()));
if (configuredRopeBlock == null) {
configuredRopeBlock = ModBlocks.ROPE.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,24 @@ public boolean canClimbBlock(BlockState stateAbove) {
return Configuration.ENABLE_TOMATO_VINE_CLIMBING_TAGGED_ROPES.get() ? stateAbove.is(ModTags.Blocks.ROPES) : stateAbove.is(ModBlocks.ROPE.get());
}

@Nullable
public BlockState getClimbingState(BlockState stateAbove) {
if (this.canClimbBlock(stateAbove)){
return ModBlocks.TOMATO_CROP_ON_ROPE.get().defaultBlockState();
}
return null;
}

public void climbRopeAbove(ServerLevel level, BlockPos pos) {
BlockPos posAbove = pos.above();
BlockState stateAbove = level.getBlockState(posAbove);
if (canClimbBlock(stateAbove)) {
BlockState climbingState = getClimbingState(stateAbove);
if (climbingState != null) {
int vineHeight;
for (vineHeight = 1; level.getBlockState(pos.below(vineHeight)).is(this); ++vineHeight) {
}
if (vineHeight < 3) {
level.setBlockAndUpdate(posAbove, ModBlocks.TOMATO_CROP_ON_ROPE.get().defaultBlockState());
level.setBlockAndUpdate(posAbove, climbingState);
}
}
}
Expand All @@ -179,7 +188,7 @@ public boolean isValidBonemealTarget(LevelReader level, BlockPos pos, BlockState
if (canClimbBlock(nextState)) {
return true;
}
if (nextState.is(ModBlocks.TOMATO_CROP_ON_ROPE.get())) {
if (nextState.getBlock() instanceof HangingTomatoBlock) {
if (!isMaxAge(nextState)) {
return true;
}
Expand Down Expand Up @@ -218,7 +227,7 @@ public boolean canSurvive(BlockState state, LevelReader level, BlockPos pos) {
BlockPos belowPos = pos.below();
BlockState belowState = level.getBlockState(belowPos);

if (belowState.is(ModBlocks.TOMATO_CROP.get()) || belowState.is(ModBlocks.TOMATO_CROP_ON_ROPE.get())) {
if (belowState.getBlock() instanceof TomatoBlock) {
return hasGoodCropConditions(level, pos);
}

Expand All @@ -238,6 +247,7 @@ public BlockState updateShape(BlockState state, Direction facing, BlockState fac
return state;
}

@Deprecated(forRemoval = true)
@Override
public void playerDestroy(Level level, Player player, BlockPos pos, BlockState state, @Nullable BlockEntity blockEntity, ItemStack stack) {
boolean isRopelogged = state.getValue(TomatoBlock.ROPELOGGED);
Expand All @@ -251,7 +261,7 @@ public void playerDestroy(Level level, Player player, BlockPos pos, BlockState s
/**
* Deprecated - This block will no longer use its ropelogged state. Refer to HangingTomatoBlock instead.
*/
@Deprecated
@Deprecated(forRemoval = true)
public static void destroyAndPlaceRope(Level level, BlockPos pos) {
Block configuredRopeBlock = BuiltInRegistries.BLOCK.get(ResourceLocation.parse(Configuration.DEFAULT_TOMATO_VINE_ROPE.get()));
Block finalRopeBlock = configuredRopeBlock != null ? configuredRopeBlock : ModBlocks.ROPE.get();
Expand Down