• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

CyclopsMC / IntegratedDynamics / 20210191346

14 Dec 2025 03:32PM UTC coverage: 19.514% (-33.5%) from 53.061%
20210191346

push

github

rubensworks
Remove deprecations

663 of 8728 branches covered (7.6%)

Branch coverage included in aggregate %.

6786 of 29445 relevant lines covered (23.05%)

1.09 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

25.19
/src/main/java/org/cyclops/integrateddynamics/block/BlockSqueezer.java
1
package org.cyclops.integrateddynamics.block;
2

3
import com.mojang.serialization.MapCodec;
4
import net.minecraft.core.BlockPos;
5
import net.minecraft.core.Direction;
6
import net.minecraft.server.level.ServerLevel;
7
import net.minecraft.util.Mth;
8
import net.minecraft.world.Containers;
9
import net.minecraft.world.InteractionResult;
10
import net.minecraft.world.entity.Entity;
11
import net.minecraft.world.entity.LivingEntity;
12
import net.minecraft.world.entity.player.Player;
13
import net.minecraft.world.item.ItemStack;
14
import net.minecraft.world.item.context.BlockPlaceContext;
15
import net.minecraft.world.level.BlockGetter;
16
import net.minecraft.world.level.Level;
17
import net.minecraft.world.level.block.BaseEntityBlock;
18
import net.minecraft.world.level.block.Block;
19
import net.minecraft.world.level.block.entity.BlockEntity;
20
import net.minecraft.world.level.block.entity.BlockEntityTicker;
21
import net.minecraft.world.level.block.entity.BlockEntityType;
22
import net.minecraft.world.level.block.state.BlockState;
23
import net.minecraft.world.level.block.state.StateDefinition;
24
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
25
import net.minecraft.world.level.block.state.properties.EnumProperty;
26
import net.minecraft.world.level.block.state.properties.IntegerProperty;
27
import net.minecraft.world.level.redstone.Orientation;
28
import net.minecraft.world.phys.AABB;
29
import net.minecraft.world.phys.BlockHitResult;
30
import net.minecraft.world.phys.Vec3;
31
import net.minecraft.world.phys.shapes.CollisionContext;
32
import net.minecraft.world.phys.shapes.Shapes;
33
import net.minecraft.world.phys.shapes.VoxelShape;
34
import org.cyclops.cyclopscore.block.BlockWithEntity;
35
import org.cyclops.cyclopscore.helper.IModHelpers;
36
import org.cyclops.integrateddynamics.RegistryEntries;
37
import org.cyclops.integrateddynamics.blockentity.BlockEntitySqueezer;
38

39
import javax.annotation.Nullable;
40

41
/**
42
 * A block for squeezing stuff.
43
 * @author rubensworks
44
 */
45
public class BlockSqueezer extends BlockWithEntity {
46

47
    public static final MapCodec<BlockSqueezer> CODEC = simpleCodec(BlockSqueezer::new);
3✔
48
    public static final EnumProperty<Direction.Axis> AXIS = BlockStateProperties.HORIZONTAL_AXIS;
2✔
49
    public static final IntegerProperty HEIGHT = IntegerProperty.create("height", 1, 7); // 1 is heighest, 7 is lowest
5✔
50

51
    private static final VoxelShape[] SHAPES_BLOCK = {
14✔
52
            null,
53
            box(0.0F, 0.0F, 0.0F, 16.0F, 16F, 16.0F),
10✔
54
            box(0.0F, 0.0F, 0.0F, 16.0F, 14F, 16.0F),
10✔
55
            box(0.0F, 0.0F, 0.0F, 16.0F, 12F, 16.0F),
10✔
56
            box(0.0F, 0.0F, 0.0F, 16.0F, 10F, 16.0F),
10✔
57
            box(0.0F, 0.0F, 0.0F, 16.0F, 8F, 16.0F),
10✔
58
            box(0.0F, 0.0F, 0.0F, 16.0F, 6F, 16.0F),
10✔
59
            box(0.0F, 0.0F, 0.0F, 16.0F, 4F, 16.0F),
3✔
60
    };
61
    private static final VoxelShape[] SHAPES_STICKS = {
10✔
62
            box(0.0F, 0.0F, 0.0F, 2F, 16.0F, 2F),
10✔
63
            box(14.0F, 0.0F, 0.0F, 16F, 16.0F, 2F),
10✔
64
            box(0.0F, 0.0F, 14.0F, 2F, 16.0F, 16F),
10✔
65
            box(14.0F, 0.0F, 14.0F, 16F, 16.0F, 16F),
3✔
66
    };
67
    private static final VoxelShape[] SHAPES = {
13✔
68
            null,
69
            Shapes.or(SHAPES_BLOCK[1], SHAPES_STICKS),
8✔
70
            Shapes.or(SHAPES_BLOCK[2], SHAPES_STICKS),
8✔
71
            Shapes.or(SHAPES_BLOCK[3], SHAPES_STICKS),
8✔
72
            Shapes.or(SHAPES_BLOCK[4], SHAPES_STICKS),
8✔
73
            Shapes.or(SHAPES_BLOCK[5], SHAPES_STICKS),
8✔
74
            Shapes.or(SHAPES_BLOCK[6], SHAPES_STICKS),
8✔
75
            Shapes.or(SHAPES_BLOCK[7], SHAPES_STICKS),
3✔
76
    };
77

78
    public BlockSqueezer(Properties properties) {
79
        super(properties, BlockEntitySqueezer::new);
4✔
80

81
        this.registerDefaultState(this.stateDefinition.any()
8✔
82
                .setValue(AXIS, Direction.Axis.X)
4✔
83
                .setValue(HEIGHT, 1));
3✔
84
    }
1✔
85

86
    @Override
87
    protected MapCodec<? extends BaseEntityBlock> codec() {
88
        return CODEC;
×
89
    }
90

91
    @Override
92
    @Nullable
93
    public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState blockState, BlockEntityType<T> blockEntityType) {
94
        return level.isClientSide() ? null : createTickerHelper(blockEntityType, RegistryEntries.BLOCK_ENTITY_SQUEEZER.get(), new BlockEntitySqueezer.Ticker());
×
95
    }
96

97
    @Override
98
    protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
99
        builder.add(AXIS, HEIGHT);
13✔
100
    }
1✔
101

102
    public BlockState getStateForPlacement(BlockPlaceContext context) {
103
        return this.defaultBlockState().setValue(AXIS, context.getHorizontalDirection().getAxis());
×
104
    }
105

106
    @Override
107
    public InteractionResult useWithoutItem(BlockState blockState, Level world, BlockPos blockPos, Player player, BlockHitResult blockRayTraceResult) {
108
        if (world.isClientSide()) {
×
109
            return InteractionResult.SUCCESS;
×
110
        } else if(world.getBlockState(blockPos).getValue(BlockSqueezer.HEIGHT) == 1) {
×
111
            return IModHelpers.get().getBlockEntityHelpers().get(world, blockPos, BlockEntitySqueezer.class)
×
112
                    .map(tile -> {
×
113
                        ItemStack itemStack = player.getInventory().getSelectedItem();
×
114
                        ItemStack tileStack = tile.getInventory().getItem(0);
×
115

116
                        if (itemStack.isEmpty() && !tileStack.isEmpty()) {
×
117
                            player.getInventory().setItem(player.getInventory().getSelectedSlot(), tileStack);
×
118
                            tile.getInventory().setItem(0, ItemStack.EMPTY);
×
119
                            tile.sendUpdate();
×
120
                            return InteractionResult.SUCCESS;
×
121
                        } else if(player.getInventory().add(tileStack)){
×
122
                            tile.getInventory().setItem(0, ItemStack.EMPTY);
×
123
                            tile.sendUpdate();
×
124
                            return InteractionResult.SUCCESS;
×
125
                        } else if (!itemStack.isEmpty() && tile.getInventory().getItem(0).isEmpty()) {
×
126
                            tile.getInventory().setItem(0, itemStack.split(1));
×
127
                            if (itemStack.getCount() <= 0)
×
128
                                player.getInventory().setItem(player.getInventory().getSelectedSlot(), ItemStack.EMPTY);
×
129
                            tile.sendUpdate();
×
130
                            return InteractionResult.SUCCESS;
×
131
                        }
132
                        return InteractionResult.PASS;
×
133
                    })
134
                    .orElse(InteractionResult.PASS);
×
135
        }
136
        return InteractionResult.PASS;
×
137
    }
138

139
    @Override
140
    public void updateEntityMovementAfterFallOn(BlockGetter worldIn, Entity entityIn) {
141
        double motionY = entityIn.getDeltaMovement().y;
×
142
        super.updateEntityMovementAfterFallOn(worldIn, entityIn);
×
143
        if(!entityIn.level().isClientSide() && motionY <= -0.37D && entityIn instanceof LivingEntity) {
×
144
            // Same way of deriving blockPos as is done in Entity#moveEntity
145
            int i = Mth.floor(entityIn.getX());
×
146
            int j = Mth.floor(entityIn.getY() - 0.2D);
×
147
            int k = Mth.floor(entityIn.getZ());
×
148
            BlockPos blockPos = new BlockPos(i, j, k);
×
149
            BlockState blockState = worldIn.getBlockState(blockPos);
×
150

151
            // The faster the entity is falling, the more steps to advance by
152
            int steps = 1 + Mth.floor((-motionY - 0.37D) * 5);
×
153

154
            if (blockState.getBlock() == this) { // Just to be sure...
×
155
                if((entityIn.getY() - blockPos.getY()) - getRelativeTopPositionTop(worldIn, blockPos, blockState) <= 0.1F) {
×
156
                    int newHeight = Math.min(7, blockState.getValue(HEIGHT) + steps);
×
157
                    entityIn.level().setBlockAndUpdate(blockPos, blockState.setValue(HEIGHT, newHeight));
×
158
                    IModHelpers.get().getBlockEntityHelpers().get(worldIn, blockPos, BlockEntitySqueezer.class)
×
159
                            .ifPresent(tile -> tile.setItemHeight(Math.max(newHeight, tile.getItemHeight())));
×
160
                }
161
            }
162
        }
163
    }
×
164

165
    @Override
166
    protected void neighborChanged(BlockState state, Level level, BlockPos pos, Block neighborBlock, @org.jetbrains.annotations.Nullable Orientation orientation, boolean movedByPiston) {
167
        super.neighborChanged(state, level, pos, neighborBlock, orientation, movedByPiston);
×
168
        if (!level.isClientSide()) {
×
169
            for (Direction enumfacing : Direction.values()) {
×
170
                if (level.hasSignal(pos.relative(enumfacing), enumfacing)) {
×
171
                    level.setBlockAndUpdate(pos, state.setValue(HEIGHT, 1));
×
172
                    for(Entity entity : level.getEntitiesOfClass(Entity.class, new AABB(Vec3.atLowerCornerOf(pos), Vec3.atLowerCornerOf(pos.offset(1, 1, 1))))) {
×
173
                        entity.getDeltaMovement().add(0, 0.25F, 0);
×
174
                        entity.setDeltaMovement(0, 1, 0);
×
175
                    }
×
176
                    return;
×
177
                }
178
            }
179
        }
180
    }
×
181

182
    public float getRelativeTopPositionTop(BlockGetter world, BlockPos blockPos, BlockState blockState) {
183
        return (9 - blockState.getValue(HEIGHT)) * 0.125F;
×
184
    }
185

186
    @Override
187
    public VoxelShape getShape(BlockState blockState, BlockGetter world, BlockPos blockPos, CollisionContext selectionContext) {
188
        return SHAPES[blockState.getValue(HEIGHT)];
8✔
189
    }
190

191
    @Override
192
    public VoxelShape getInteractionShape(BlockState blockState, BlockGetter world, BlockPos blockPos) {
193
        return SHAPES_BLOCK[blockState.getValue(HEIGHT)];
×
194
    }
195

196
    @Override
197
    public VoxelShape getCollisionShape(BlockState blockState, BlockGetter world, BlockPos blockPos, CollisionContext selectionContext) {
198
        return SHAPES_BLOCK[blockState.getValue(HEIGHT)];
8✔
199
    }
200

201
    @SuppressWarnings("deprecation")
202
    @Override
203
    public boolean hasAnalogOutputSignal(BlockState blockState) {
204
        return true;
×
205
    }
206

207
    @Override
208
    protected int getAnalogOutputSignal(BlockState blockState, Level level, BlockPos pos, Direction direction) {
209
        return (int) (((double) blockState.getValue(HEIGHT) - 1) / 6D * 15D);
×
210
    }
211

212
    @Override
213
    protected void affectNeighborsAfterRemoval(BlockState state, ServerLevel level, BlockPos pos, boolean movedByPiston) {
214
        super.affectNeighborsAfterRemoval(state, level, pos, movedByPiston);
×
215
        Containers.updateNeighboursAfterDestroy(state, level, pos);
×
216
    }
×
217
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc