Skip to content

Commit

Permalink
Switch to palantir-java-format over Eclipse formatting XML
Browse files Browse the repository at this point in the history
  • Loading branch information
62832 committed Aug 3, 2023
1 parent 41698bc commit 1a95fa9
Show file tree
Hide file tree
Showing 42 changed files with 1,061 additions and 888 deletions.
7 changes: 3 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,9 @@ subprojects {
java {
target("src/**/java/**/*.java")
endWithNewline()
indentWithSpaces()
indentWithSpaces(4)
removeUnusedImports()
toggleOffOn()
eclipse().configFile(rootProject.file("codeformat/codeformat.xml"))
palantirJavaFormat()
importOrderFile(rootProject.file("codeformat/mega.importorder"))

// courtesy of diffplug/spotless#240
Expand Down Expand Up @@ -234,4 +233,4 @@ for (platform in property("enabledPlatforms").toString().split(',')) {
skip()
}
}
}
}
365 changes: 0 additions & 365 deletions codeformat/codeformat.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@
import gripe._90.megacells.definition.MEGATranslations;

public class MEGAPatternProviderBlock extends AEBaseEntityBlock<MEGAPatternProviderBlockEntity> {
public static final EnumProperty<PushDirection> PUSH_DIRECTION = EnumProperty.create("push_direction",
PushDirection.class);
public static final EnumProperty<PushDirection> PUSH_DIRECTION =
EnumProperty.create("push_direction", PushDirection.class);

public static final MenuType<Menu> MENU = MenuTypeBuilder
.create(Menu::new, PatternProviderLogicHost.class)
.build("mega_pattern_provider");
public static final MenuType<Menu> MENU =
MenuTypeBuilder.create(Menu::new, PatternProviderLogicHost.class).build("mega_pattern_provider");

public MEGAPatternProviderBlock(Properties props) {
super(props);
Expand All @@ -67,18 +66,22 @@ protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockSt
}

@Override
public void neighborChanged(BlockState state, Level level, BlockPos pos, Block block, BlockPos fromPos,
boolean isMoving) {
public void neighborChanged(
BlockState state, Level level, BlockPos pos, Block block, BlockPos fromPos, boolean isMoving) {
var be = this.getBlockEntity(level, pos);
if (be != null) {
be.getLogic().updateRedstoneState();
}
}

@Override
public InteractionResult onActivated(Level level, BlockPos pos, Player p,
public InteractionResult onActivated(
Level level,
BlockPos pos,
Player p,
InteractionHand hand,
@Nullable ItemStack heldItem, BlockHitResult hit) {
@Nullable ItemStack heldItem,
BlockHitResult hit) {
if (InteractionUtil.isInAlternateUseMode(p)) {
return InteractionResult.PASS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,17 @@ public BakedModel getBakedModel(Function<Material, TextureAtlasSprite> spriteGet
TextureAtlasSprite ringSideVer = spriteGetter.apply(RING_SIDE_VER);

return switch (this.type) {
case UNIT -> new UnitBakedModel(ringCorner, ringSideHor, ringSideVer,
spriteGetter.apply(UNIT_BASE));
case UNIT -> new UnitBakedModel(ringCorner, ringSideHor, ringSideVer, spriteGetter.apply(UNIT_BASE));
case ACCELERATOR, STORAGE_1M, STORAGE_4M, STORAGE_16M, STORAGE_64M, STORAGE_256M -> new LightBakedModel(
ringCorner, ringSideHor, ringSideVer, spriteGetter.apply(LIGHT_BASE),
ringCorner,
ringSideHor,
ringSideVer,
spriteGetter.apply(LIGHT_BASE),
this.getLightMaterial(spriteGetter));
case MONITOR -> new MonitorBakedModel(ringCorner, ringSideHor, ringSideVer,
case MONITOR -> new MonitorBakedModel(
ringCorner,
ringSideHor,
ringSideVer,
spriteGetter.apply(UNIT_BASE),
spriteGetter.apply(MONITOR_BASE),
spriteGetter.apply(MONITOR_LIGHT_DARK),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
public class DecompressionPatternDecoder implements IPatternDetailsDecoder {
public static final DecompressionPatternDecoder INSTANCE = new DecompressionPatternDecoder();

private DecompressionPatternDecoder() {
}
private DecompressionPatternDecoder() {}

@Override
public boolean isEncodedPattern(ItemStack stack) {
Expand All @@ -21,7 +20,9 @@ public boolean isEncodedPattern(ItemStack stack) {

@Override
public MEGADecompressionPattern decodePattern(AEItemKey what, Level level) {
if (level == null || what == null || !(what.getItem() instanceof MEGADecompressionPattern.Item)
if (level == null
|| what == null
|| !(what.getItem() instanceof MEGADecompressionPattern.Item)
|| !(what.hasTag())) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ public static int getFactor(CompoundTag nbt) {
return nbt.getInt(NBT_FACTOR);
}

public static void encode(CompoundTag tag, AEItemKey compressed, AEItemKey decompressed,
int factor) {
public static void encode(CompoundTag tag, AEItemKey compressed, AEItemKey decompressed, int factor) {
tag.put(NBT_COMPRESSED, compressed.toTag());
tag.put(NBT_DECOMPRESSED, decompressed.toTag());
tag.putInt(NBT_FACTOR, factor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public MEGADecompressionPattern(AEItemKey definition) {
var factor = DecompressionPatternEncoding.getFactor(tag);
var output = decompressed.toStack(factor);

this.inputs = new IInput[] { new Input() };
this.outputs = new GenericStack[] { GenericStack.fromItemStack(output) };
this.inputs = new IInput[] {new Input()};
this.outputs = new GenericStack[] {GenericStack.fromItemStack(output)};
}

@Override
Expand All @@ -47,7 +47,8 @@ public GenericStack[] getOutputs() {

@Override
public boolean equals(Object obj) {
return obj != null && obj.getClass() == getClass()
return obj != null
&& obj.getClass() == getClass()
&& ((MEGADecompressionPattern) obj).definition.equals(definition);
}

Expand All @@ -59,7 +60,7 @@ public int hashCode() {
private class Input implements IInput {
@Override
public GenericStack[] getPossibleInputs() {
return new GenericStack[] { new GenericStack(input, 1) };
return new GenericStack[] {new GenericStack(input, 1)};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import gripe._90.megacells.block.entity.MEGAPatternProviderBlockEntity;
import gripe._90.megacells.util.Utils;

@SuppressWarnings({ "unused", "unchecked" })
@SuppressWarnings({"unused", "unchecked"})
public final class MEGABlockEntities {
public static void init() {
// controls static load order
Expand All @@ -36,37 +36,57 @@ public static Map<ResourceLocation, BlockEntityType<?>> getBlockEntityTypes() {
return ImmutableMap.copyOf(BLOCK_ENTITY_TYPES);
}

// spotless:off
public static final BlockEntityType<EnergyCellBlockEntity> MEGA_ENERGY_CELL = create("mega_energy_cell", EnergyCellBlockEntity.class, EnergyCellBlockEntity::new, MEGABlocks.MEGA_ENERGY_CELL);

public static final BlockEntityType<CraftingBlockEntity> MEGA_CRAFTING_UNIT = create("mega_crafting_unit", CraftingBlockEntity.class, CraftingBlockEntity::new, MEGABlocks.MEGA_CRAFTING_UNIT, MEGABlocks.CRAFTING_ACCELERATOR);
public static final BlockEntityType<CraftingBlockEntity> MEGA_CRAFTING_STORAGE = create("mega_crafting_storage", CraftingBlockEntity.class, CraftingBlockEntity::new, MEGABlocks.CRAFTING_STORAGE_1M, MEGABlocks.CRAFTING_STORAGE_4M, MEGABlocks.CRAFTING_STORAGE_16M, MEGABlocks.CRAFTING_STORAGE_64M, MEGABlocks.CRAFTING_STORAGE_256M);
public static final BlockEntityType<CraftingMonitorBlockEntity> MEGA_CRAFTING_MONITOR = create("mega_crafting_monitor", CraftingMonitorBlockEntity.class, CraftingMonitorBlockEntity::new, MEGABlocks.CRAFTING_MONITOR);

public static final BlockEntityType<MEGAPatternProviderBlockEntity> MEGA_PATTERN_PROVIDER = create("mega_pattern_provider", MEGAPatternProviderBlockEntity.class, MEGAPatternProviderBlockEntity::new, MEGABlocks.MEGA_PATTERN_PROVIDER);
// spotless:on
public static final BlockEntityType<EnergyCellBlockEntity> MEGA_ENERGY_CELL = create(
"mega_energy_cell", EnergyCellBlockEntity.class, EnergyCellBlockEntity::new, MEGABlocks.MEGA_ENERGY_CELL);

public static final BlockEntityType<CraftingBlockEntity> MEGA_CRAFTING_UNIT = create(
"mega_crafting_unit",
CraftingBlockEntity.class,
CraftingBlockEntity::new,
MEGABlocks.MEGA_CRAFTING_UNIT,
MEGABlocks.CRAFTING_ACCELERATOR);
public static final BlockEntityType<CraftingBlockEntity> MEGA_CRAFTING_STORAGE = create(
"mega_crafting_storage",
CraftingBlockEntity.class,
CraftingBlockEntity::new,
MEGABlocks.CRAFTING_STORAGE_1M,
MEGABlocks.CRAFTING_STORAGE_4M,
MEGABlocks.CRAFTING_STORAGE_16M,
MEGABlocks.CRAFTING_STORAGE_64M,
MEGABlocks.CRAFTING_STORAGE_256M);
public static final BlockEntityType<CraftingMonitorBlockEntity> MEGA_CRAFTING_MONITOR = create(
"mega_crafting_monitor",
CraftingMonitorBlockEntity.class,
CraftingMonitorBlockEntity::new,
MEGABlocks.CRAFTING_MONITOR);

public static final BlockEntityType<MEGAPatternProviderBlockEntity> MEGA_PATTERN_PROVIDER = create(
"mega_pattern_provider",
MEGAPatternProviderBlockEntity.class,
MEGAPatternProviderBlockEntity::new,
MEGABlocks.MEGA_PATTERN_PROVIDER);

@SafeVarargs
private static <T extends AEBaseBlockEntity> BlockEntityType<T> create(String id, Class<T> entityClass,
private static <T extends AEBaseBlockEntity> BlockEntityType<T> create(
String id,
Class<T> entityClass,
BlockEntityFactory<T> factory,
BlockDefinition<? extends AEBaseEntityBlock<?>>... blockDefinitions) {
Preconditions.checkArgument(blockDefinitions.length > 0);

var blocks = Arrays.stream(blockDefinitions)
.map(BlockDefinition::block)
.toArray(AEBaseEntityBlock[]::new);
var blocks = Arrays.stream(blockDefinitions).map(BlockDefinition::block).toArray(AEBaseEntityBlock[]::new);

AtomicReference<BlockEntityType<T>> typeHolder = new AtomicReference<>();
BlockEntityType.BlockEntitySupplier<T> supplier = (blockPos, blockState) -> factory.create(typeHolder.get(),
blockPos, blockState);
var type = BlockEntityType.Builder.of(supplier, blocks).build(null);
var typeHolder = new AtomicReference<BlockEntityType<T>>();
var type = BlockEntityType.Builder.of(
(blockPos, blockState) -> factory.create(typeHolder.get(), blockPos, blockState), blocks)
.build(null);
typeHolder.set(type); // Makes it available to the supplier used above
BLOCK_ENTITY_TYPES.put(Utils.makeId(id), type);

AEBaseBlockEntity.registerBlockEntityItem(type, blockDefinitions[0].asItem());

for (var block : blocks) {
AEBaseEntityBlock<T> baseBlock = (AEBaseEntityBlock<T>) block;
var baseBlock = (AEBaseEntityBlock<T>) block;
baseBlock.setBlockEntity(entityClass, type, null, null);
}

Expand All @@ -77,5 +97,4 @@ private static <T extends AEBaseBlockEntity> BlockEntityType<T> create(String id
interface BlockEntityFactory<T extends AEBaseBlockEntity> {
T create(BlockEntityType<T> type, BlockPos pos, BlockState state);
}

}
102 changes: 73 additions & 29 deletions common/src/main/java/gripe/_90/megacells/definition/MEGABlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,41 +48,85 @@ public static List<BlockDefinition<?>> getBlocks() {
.sound(SoundType.METAL)
.forceSolidOn();

// spotless:off
public static final BlockDefinition<AEDecorativeBlock> SKY_STEEL_BLOCK = block("Sky Steel Block", "sky_steel_block", () -> new AEDecorativeBlock(BlockBehaviour.Properties.of().strength(5.0f, 12.0f).requiresCorrectToolForDrops().mapColor(MapColor.METAL).sound(SoundType.METAL)));

public static final BlockDefinition<EnergyCellBlock> MEGA_ENERGY_CELL = block("Superdense Energy Cell", "mega_energy_cell", () -> new EnergyCellBlock(12800000, 3200, 12800), EnergyCellBlockItem::new);

public static final BlockDefinition<CraftingUnitBlock> MEGA_CRAFTING_UNIT = block("MEGA Crafting Unit", "mega_crafting_unit", () -> new CraftingUnitBlock(MEGACraftingUnitType.UNIT));
public static final BlockDefinition<CraftingUnitBlock> CRAFTING_ACCELERATOR = craftingBlock("MEGA Crafting Co-Processing Unit", "mega_crafting_accelerator", () -> new CraftingUnitBlock(MEGACraftingUnitType.ACCELERATOR), () -> AEItems.ENGINEERING_PROCESSOR);
public static final BlockDefinition<CraftingUnitBlock> CRAFTING_STORAGE_1M = craftingBlock("1M MEGA Crafting Storage", "1m_crafting_storage", () -> new CraftingUnitBlock(MEGACraftingUnitType.STORAGE_1M), () -> MEGAItems.CELL_COMPONENT_1M);
public static final BlockDefinition<CraftingUnitBlock> CRAFTING_STORAGE_4M = craftingBlock("4M MEGA Crafting Storage", "4m_crafting_storage", () -> new CraftingUnitBlock(MEGACraftingUnitType.STORAGE_4M), () -> MEGAItems.CELL_COMPONENT_4M);
public static final BlockDefinition<CraftingUnitBlock> CRAFTING_STORAGE_16M = craftingBlock("16M MEGA Crafting Storage", "16m_crafting_storage", () -> new CraftingUnitBlock(MEGACraftingUnitType.STORAGE_16M), () -> MEGAItems.CELL_COMPONENT_16M);
public static final BlockDefinition<CraftingUnitBlock> CRAFTING_STORAGE_64M = craftingBlock("64M MEGA Crafting Storage", "64m_crafting_storage", () -> new CraftingUnitBlock(MEGACraftingUnitType.STORAGE_64M), () -> MEGAItems.CELL_COMPONENT_64M);
public static final BlockDefinition<CraftingUnitBlock> CRAFTING_STORAGE_256M = craftingBlock("256M MEGA Crafting Storage", "256m_crafting_storage", () -> new CraftingUnitBlock(MEGACraftingUnitType.STORAGE_256M), () -> MEGAItems.CELL_COMPONENT_256M);
public static final BlockDefinition<CraftingMonitorBlock> CRAFTING_MONITOR = craftingBlock("MEGA Crafting Monitor", "mega_crafting_monitor", () -> new CraftingMonitorBlock(MEGACraftingUnitType.MONITOR), () -> AEParts.STORAGE_MONITOR);

public static final BlockDefinition<MEGAPatternProviderBlock> MEGA_PATTERN_PROVIDER = block("MEGA Pattern Provider", "mega_pattern_provider", () -> new MEGAPatternProviderBlock(props), MEGAPatternProviderBlock.Item::new);
// spotless:on

private static <T extends Block> BlockDefinition<T> craftingBlock(String englishName, String id,
Supplier<T> blockSupplier,
Supplier<ItemLike> disassemblyExtra) {
return block(englishName, id, blockSupplier,
public static final BlockDefinition<AEDecorativeBlock> SKY_STEEL_BLOCK = block(
"Sky Steel Block",
"sky_steel_block",
() -> new AEDecorativeBlock(BlockBehaviour.Properties.of()
.strength(5.0f, 12.0f)
.requiresCorrectToolForDrops()
.mapColor(MapColor.METAL)
.sound(SoundType.METAL)));

public static final BlockDefinition<EnergyCellBlock> MEGA_ENERGY_CELL = block(
"Superdense Energy Cell",
"mega_energy_cell",
() -> new EnergyCellBlock(12800000, 3200, 12800),
EnergyCellBlockItem::new);

public static final BlockDefinition<CraftingUnitBlock> MEGA_CRAFTING_UNIT =
block("MEGA Crafting Unit", "mega_crafting_unit", () -> new CraftingUnitBlock(MEGACraftingUnitType.UNIT));
public static final BlockDefinition<CraftingUnitBlock> CRAFTING_ACCELERATOR = craftingBlock(
"MEGA Crafting Co-Processing Unit",
"mega_crafting_accelerator",
() -> new CraftingUnitBlock(MEGACraftingUnitType.ACCELERATOR),
() -> AEItems.ENGINEERING_PROCESSOR);
public static final BlockDefinition<CraftingUnitBlock> CRAFTING_STORAGE_1M = craftingBlock(
"1M MEGA Crafting Storage",
"1m_crafting_storage",
() -> new CraftingUnitBlock(MEGACraftingUnitType.STORAGE_1M),
() -> MEGAItems.CELL_COMPONENT_1M);
public static final BlockDefinition<CraftingUnitBlock> CRAFTING_STORAGE_4M = craftingBlock(
"4M MEGA Crafting Storage",
"4m_crafting_storage",
() -> new CraftingUnitBlock(MEGACraftingUnitType.STORAGE_4M),
() -> MEGAItems.CELL_COMPONENT_4M);
public static final BlockDefinition<CraftingUnitBlock> CRAFTING_STORAGE_16M = craftingBlock(
"16M MEGA Crafting Storage",
"16m_crafting_storage",
() -> new CraftingUnitBlock(MEGACraftingUnitType.STORAGE_16M),
() -> MEGAItems.CELL_COMPONENT_16M);
public static final BlockDefinition<CraftingUnitBlock> CRAFTING_STORAGE_64M = craftingBlock(
"64M MEGA Crafting Storage",
"64m_crafting_storage",
() -> new CraftingUnitBlock(MEGACraftingUnitType.STORAGE_64M),
() -> MEGAItems.CELL_COMPONENT_64M);
public static final BlockDefinition<CraftingUnitBlock> CRAFTING_STORAGE_256M = craftingBlock(
"256M MEGA Crafting Storage",
"256m_crafting_storage",
() -> new CraftingUnitBlock(MEGACraftingUnitType.STORAGE_256M),
() -> MEGAItems.CELL_COMPONENT_256M);
public static final BlockDefinition<CraftingMonitorBlock> CRAFTING_MONITOR = craftingBlock(
"MEGA Crafting Monitor",
"mega_crafting_monitor",
() -> new CraftingMonitorBlock(MEGACraftingUnitType.MONITOR),
() -> AEParts.STORAGE_MONITOR);

public static final BlockDefinition<MEGAPatternProviderBlock> MEGA_PATTERN_PROVIDER = block(
"MEGA Pattern Provider",
"mega_pattern_provider",
() -> new MEGAPatternProviderBlock(props),
MEGAPatternProviderBlock.Item::new);

private static <T extends Block> BlockDefinition<T> craftingBlock(
String englishName, String id, Supplier<T> blockSupplier, Supplier<ItemLike> disassemblyExtra) {
return block(
englishName,
id,
blockSupplier,
(block, props) -> new MEGACraftingBlockItem(block, props, disassemblyExtra));
}

private static <T extends Block> BlockDefinition<T> block(String englishName, String id,
Supplier<T> blockSupplier) {
private static <T extends Block> BlockDefinition<T> block(
String englishName, String id, Supplier<T> blockSupplier) {
return block(englishName, id, blockSupplier, null);
}

private static <T extends Block> BlockDefinition<T> block(String englishName, String id, Supplier<T> blockSupplier,
private static <T extends Block> BlockDefinition<T> block(
String englishName,
String id,
Supplier<T> blockSupplier,
BiFunction<Block, Item.Properties, BlockItem> itemFactory) {

// Create block and matching item
T block = blockSupplier.get();

var block = blockSupplier.get();
var itemProperties = new Item.Properties();

BlockItem item;
Expand All @@ -97,7 +141,7 @@ private static <T extends Block> BlockDefinition<T> block(String englishName, St
item = new BlockItem(block, itemProperties);
}

BlockDefinition<T> definition = new BlockDefinition<>(englishName, Utils.makeId(id), block, item);
var definition = new BlockDefinition<>(englishName, Utils.makeId(id), block, item);
BLOCKS.add(definition);
return definition;
}
Expand Down
Loading

0 comments on commit 1a95fa9

Please sign in to comment.