Skip to content

Commit

Permalink
feat: apply micro-optimizations to Maw Hopper
Browse files Browse the repository at this point in the history
  • Loading branch information
Elenterius committed Jun 16, 2023
1 parent 4ec3d0d commit 64a00ee
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, Block

@Override
public void entityInside(BlockState state, Level level, BlockPos pos, Entity entity) {
if (getVertexType(state) != VertexType.SOURCE) return;

BlockEntity blockentity = level.getBlockEntity(pos);
if (blockentity instanceof MawHopperBlockEntity blockEntity) {
MawHopperBlockEntity.entityInside(level, pos, state, blockEntity, entity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ private void serverTick(ServerLevel level, BlockPos pos, BlockState state) {
}
}

if (ticks % (DURATION + DELAY) == 0 && !inventory.isFull()) {
if (ticks % (DURATION + DELAY) == 0 && !inventory.isFull() && isMawHead()) {
BlockPos pullPos = pos.relative(MawHopperBlock.getConnection(state).ingoing);
if (level.isLoaded(pullPos)) {
LazyOptional<IItemHandler> itemHandler = getItemHandler(level, pullPos, Direction.DOWN);
Expand All @@ -157,6 +157,10 @@ private void serverTick(ServerLevel level, BlockPos pos, BlockState state) {
}
}

private boolean isMawHead() {
return MawHopperBlock.getVertexType(getBlockState()) == VertexType.SOURCE;
}

private boolean tryToInsertItems(IItemHandler itemHandler) {
ItemStack stack = inventory.extractItem(ITEM_TRANSFER_AMOUNT, false);
if (stack.isEmpty()) return false;
Expand Down

0 comments on commit 64a00ee

Please sign in to comment.