Skip to content

Commit

Permalink
Spotless & Checkstyle
Browse files Browse the repository at this point in the history
Maybe we should get a Checkstyle rule to allow comments after blocks? It's making me do stuff like this:

// :::1
if (condition) {
    // code...
}

// :::1

...which is IMO kinda ugly
  • Loading branch information
natri0 committed Dec 30, 2024
1 parent 522985f commit 4dbf9a9
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.example.docs.block;

import com.example.docs.block.custom.DuplicatorBlock;

import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.PillarBlock;
Expand All @@ -16,6 +14,7 @@

import com.example.docs.FabricDocsReference;
import com.example.docs.block.custom.CounterBlock;
import com.example.docs.block.custom.DuplicatorBlock;
import com.example.docs.block.custom.EngineBlock;
import com.example.docs.block.custom.PrismarineLampBlock;
import com.example.docs.item.ModItems;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.example.docs.block.custom;

import com.example.docs.block.entity.ModBlockEntities;
import com.example.docs.block.entity.custom.DuplicatorBlockEntity;

import com.mojang.serialization.MapCodec;
import org.jetbrains.annotations.Nullable;

import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockState;
Expand All @@ -17,10 +15,10 @@
import net.minecraft.util.ItemActionResult;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;

import net.minecraft.world.World;

import org.jetbrains.annotations.Nullable;
import com.example.docs.block.entity.ModBlockEntities;
import com.example.docs.block.entity.custom.DuplicatorBlockEntity;

// :::1
public class DuplicatorBlock extends BlockWithEntity {
Expand Down Expand Up @@ -55,12 +53,14 @@ protected ItemActionResult onUseWithItem(ItemStack stack, BlockState state, Worl
if (!(world.getBlockEntity(pos) instanceof DuplicatorBlockEntity duplicatorBlockEntity)) {
return ItemActionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
}

// :::2

// :::3
if (!duplicatorBlockEntity.canInsert(0, stack, hit.getSide())) {
return ItemActionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
}

// :::3

// :::2
Expand All @@ -71,6 +71,7 @@ protected ItemActionResult onUseWithItem(ItemStack stack, BlockState state, Worl

return ItemActionResult.SUCCESS;
}

// :::2

@Nullable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.example.docs.block.entity;

import com.example.docs.block.entity.custom.DuplicatorBlockEntity;

import net.minecraft.block.Block;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType;
Expand All @@ -12,6 +10,7 @@
import com.example.docs.FabricDocsReference;
import com.example.docs.block.ModBlocks;
import com.example.docs.block.entity.custom.CounterBlockEntity;
import com.example.docs.block.entity.custom.DuplicatorBlockEntity;
import com.example.docs.block.entity.custom.EngineBlockEntity;

public class ModBlockEntities {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.example.docs.block.entity.custom;

import com.example.docs.block.entity.ModBlockEntities;

import com.example.docs.inventory.ImplementedInventory;
import org.jetbrains.annotations.Nullable;

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
Expand All @@ -17,7 +15,8 @@
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;

import org.jetbrains.annotations.Nullable;
import com.example.docs.block.entity.ModBlockEntities;
import com.example.docs.inventory.ImplementedInventory;

/*
The following is a dummy piece of code to not have `implements SidedInventory` in the first code block where we implement `ImplementedInventory`.
Expand All @@ -40,6 +39,7 @@ public DuplicatorBlockEntity(BlockPos pos, BlockState state) {
public DefaultedList<ItemStack> getItems() {
return items;
}

// :::1

// :::2
Expand All @@ -54,6 +54,7 @@ protected void writeNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup registryL
Inventories.writeNbt(nbt, items, registryLookup);
super.writeNbt(nbt, registryLookup);
}

// :::2

// :::3
Expand All @@ -66,6 +67,7 @@ public static void tick(World world, BlockPos blockPos, BlockState blockState, D
Block.dropStack(world, blockPos, stack);
}
}

// :::3

// :::4
Expand All @@ -83,6 +85,7 @@ public boolean canInsert(int slot, ItemStack stack, @Nullable Direction dir) {
public boolean canExtract(int slot, ItemStack stack, Direction dir) {
return true;
}

// :::4

// :::1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
* @author Juuz
*/
public interface ImplementedInventory extends Inventory {

/**
* Retrieves the item list of this inventory.
* Must return the same instance every time it's called.
Expand Down Expand Up @@ -49,10 +48,12 @@ default int size() {
default boolean isEmpty() {
for (int i = 0; i < size(); i++) {
ItemStack stack = getStack(i);

if (!stack.isEmpty()) {
return false;
}
}

return true;
}

Expand All @@ -73,9 +74,11 @@ default ItemStack getStack(int slot) {
@Override
default ItemStack removeStack(int slot, int count) {
ItemStack result = Inventories.splitStack(getItems(), slot, count);

if (!result.isEmpty()) {
markDirty();
}

return result;
}

Expand All @@ -98,6 +101,7 @@ default ItemStack removeStack(int slot) {
@Override
default void setStack(int slot, ItemStack stack) {
getItems().set(slot, stack);

if (stack.getCount() > stack.getMaxCount()) {
stack.setCount(stack.getMaxCount());
}
Expand Down Expand Up @@ -129,4 +133,3 @@ default boolean canPlayerUse(PlayerEntity player) {
return true;
}
}

0 comments on commit 4dbf9a9

Please sign in to comment.