Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Revert the code style for file history
  • Loading branch information
CalenXwX committed Apr 13, 2024
commit 8f4b6f56f1c61e33601ef2c3563147d3048175f6
57 changes: 19 additions & 38 deletions api/buildcraft/api/BCModules.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
import java.util.List;
import java.util.Locale;

public enum BCModules implements IBuildCraftMod
{
public enum BCModules implements IBuildCraftMod {
LIB,
// Base module for all BC.
CORE,
Expand Down Expand Up @@ -38,10 +37,8 @@ public enum BCModules implements IBuildCraftMod
private final String modId = BUILDCRAFT + lowerCaseName;
private boolean loaded;

private static void checkLoadStatus()
{
if (hasChecked)
{
private static void checkLoadStatus() {
if (hasChecked) {
return;
}
load0();
Expand All @@ -50,10 +47,8 @@ private static void checkLoadStatus()
/**
* Performs the actual loading of {@link #checkLoadStatus()}, except this is thread safe.
*/
private static synchronized void load0()
{
if (hasChecked)
{
private static synchronized void load0() {
if (hasChecked) {
return;
}
// Calen: loading events order is changed from 1.12.2 to 1.18.2...
Expand All @@ -63,16 +58,13 @@ private static synchronized void load0()
// throw new RuntimeException("You can only use BCModules.isLoaded from pre-init onwards!");
// }
List<BCModules> found = new ArrayList<>(), missing = new ArrayList<>();
for (BCModules module : VALUES)
{
for (BCModules module : VALUES) {
module.loaded = ModList.get().isLoaded(module.modId);

if (module.loaded)
{
if (module.loaded) {
found.add(module);
}
else
{
else {
missing.add(module);
}
}
Expand All @@ -82,59 +74,48 @@ private static synchronized void load0()
}

@Nullable
public static BCModules getBcMod(String testModId)
{
for (BCModules mod : VALUES)
{
if (mod.modId.equals(testModId))
{
public static BCModules getBcMod(String testModId) {
for (BCModules mod : VALUES) {
if (mod.modId.equals(testModId)) {
return mod;
}
}
return null;
}

public static boolean isBcMod(String testModId)
{
public static boolean isBcMod(String testModId) {
return getBcMod(testModId) != null;
}

public static BCModules[] getLoadedModules()
{
public static BCModules[] getLoadedModules() {
checkLoadStatus();
return loadedModules;
}

public static BCModules[] getMissingModules()
{
public static BCModules[] getMissingModules() {
checkLoadStatus();
return missingModules;
}

@Override
public String getModId()
{
public String getModId() {
return modId;
}

public boolean isLoaded()
{
public boolean isLoaded() {
checkLoadStatus();
return loaded;
}

public ResourceLocation createLocation(String path)
{
public ResourceLocation createLocation(String path) {
return new ResourceLocation(getModId(), path);
}

public ModelResourceLocation createModelLocation(String path, String variant)
{
public ModelResourceLocation createModelLocation(String path, String variant) {
return new ModelResourceLocation(getModId() + ":" + path + "#" + variant);
}

public ModelResourceLocation createModelLocation(String pathAndVariant)
{
public ModelResourceLocation createModelLocation(String pathAndVariant) {
return new ModelResourceLocation(getModId() + ":" + pathAndVariant);
}
}
3 changes: 1 addition & 2 deletions api/buildcraft/api/IBuildCraftMod.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package buildcraft.api;

/** Allows a mod (or addon) to register networking packets in the message manager. */
public interface IBuildCraftMod
{
public interface IBuildCraftMod {
/** @return The modid to use when registering this as a channel. */
String getModId();
}
77 changes: 26 additions & 51 deletions api/buildcraft/api/blocks/CustomPaintHelper.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package buildcraft.api.blocks;

import buildcraft.api.core.BCLog;
import buildcraft.api.core.BCDebugging;
import buildcraft.api.core.BCLog;
import buildcraft.lib.misc.BlockUtil;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
Expand All @@ -23,8 +23,7 @@
* Provides a simple way to paint a single core, iterating through all {@link ICustomPaintHandler}'s that are
* registered for the core.
*/
public enum CustomPaintHelper
{
public enum CustomPaintHelper {
INSTANCE;

/* If you want to test your class-based rotation registration then add the system property
Expand All @@ -38,10 +37,8 @@ public enum CustomPaintHelper
* Registers a handler that will be called LAST for ALL blocks, if all other paint handlers have returned PASS or
* none are registered for that core.
*/
public void registerHandlerForAll(ICustomPaintHandler handler)
{
if (DEBUG)
{
public void registerHandlerForAll(ICustomPaintHandler handler) {
if (DEBUG) {
BCLog.logger.info("[api.painting] Adding a paint handler for ALL blocks (" + handler.getClass() + ")");
}
allHandlers.add(handler);
Expand All @@ -50,49 +47,38 @@ public void registerHandlerForAll(ICustomPaintHandler handler)
/**
* Register's a paint handler for every class of a given core.
*/
public void registerHandlerForAll(Class<? extends Block> blockClass, ICustomPaintHandler handler)
{
public void registerHandlerForAll(Class<? extends Block> blockClass, ICustomPaintHandler handler) {
// for (Block block : Block.REGISTRY)
for (Block block : ForgeRegistries.BLOCKS.getValues())
{
for (Block block : ForgeRegistries.BLOCKS.getValues()) {
Class<? extends Block> foundClass = block.getClass();
if (blockClass.isAssignableFrom(foundClass))
{
if (DEBUG)
{
if (blockClass.isAssignableFrom(foundClass)) {
if (DEBUG) {
BCLog.logger.info("[api.painting] Found an assignable core " + block.getRegistryName() + " (" + foundClass + ") for " + blockClass);
}
registerHandlerInternal(block, handler);
}
}
}

public void registerHandler(Block block, ICustomPaintHandler handler)
{
if (registerHandlerInternal(block, handler))
{
if (DEBUG)
{
public void registerHandler(Block block, ICustomPaintHandler handler) {
if (registerHandlerInternal(block, handler)) {
if (DEBUG) {
BCLog.logger.info("[api.painting] Setting a paint handler for core " + block.getRegistryName() + "(" + handler.getClass() + ")");
}
}
else if (DEBUG)
{
else if (DEBUG) {
BCLog.logger.info("[api.painting] Adding another paint handler for core " + block.getRegistryName() + "(" + handler.getClass() + ")");
}
}

private boolean registerHandlerInternal(Block block, ICustomPaintHandler handler)
{
if (!handlers.containsKey(block))
{
private boolean registerHandlerInternal(Block block, ICustomPaintHandler handler) {
if (!handlers.containsKey(block)) {
List<ICustomPaintHandler> forBlock = Lists.newArrayList();
forBlock.add(handler);
handlers.put(block, forBlock);
return true;
}
else
{
else {
handlers.get(block).add(handler);
return false;
}
Expand All @@ -101,51 +87,40 @@ private boolean registerHandlerInternal(Block block, ICustomPaintHandler handler
/**
* Attempts to paint a core at the given position. Basically iterates through all registered paint handlers.
*/
public InteractionResult attemptPaintBlock(Level world, BlockPos pos, BlockState state, Vec3 hitPos, @Nullable Direction hitSide, @Nullable DyeColor paint)
{
public InteractionResult attemptPaintBlock(Level world, BlockPos pos, BlockState state, Vec3 hitPos, @Nullable Direction hitSide, @Nullable DyeColor paint) {
Block block = state.getBlock();
if (block instanceof ICustomPaintHandler)
{
if (block instanceof ICustomPaintHandler) {
return ((ICustomPaintHandler) block).attemptPaint(world, pos, state, hitPos, hitSide, paint);
}
List<ICustomPaintHandler> custom = handlers.get(block);
if (custom == null || custom.isEmpty())
{
if (custom == null || custom.isEmpty()) {
return defaultAttemptPaint(world, pos, state, hitPos, hitSide, paint);
}
for (ICustomPaintHandler handler : custom)
{
for (ICustomPaintHandler handler : custom) {
InteractionResult result = handler.attemptPaint(world, pos, state, hitPos, hitSide, paint);
if (result != InteractionResult.PASS)
{
if (result != InteractionResult.PASS) {
return result;
}
}
return defaultAttemptPaint(world, pos, state, hitPos, hitSide, paint);
}

private InteractionResult defaultAttemptPaint(Level world, BlockPos pos, BlockState state, Vec3 hitPos, Direction hitSide, @Nullable DyeColor paint)
{
for (ICustomPaintHandler handler : allHandlers)
{
private InteractionResult defaultAttemptPaint(Level world, BlockPos pos, BlockState state, Vec3 hitPos, Direction hitSide, @Nullable DyeColor paint) {
for (ICustomPaintHandler handler : allHandlers) {
InteractionResult result = handler.attemptPaint(world, pos, state, hitPos, hitSide, paint);
if (result != InteractionResult.PASS)
{
if (result != InteractionResult.PASS) {
return result;
}
}
if (paint == null)
{
if (paint == null) {
return InteractionResult.FAIL;
}
Block b = state.getBlock();
// if (b.recolorBlock(world, pos, hitSide, paint))
if (BlockUtil.recolorBlock(world, pos, hitSide, paint))
{
if (BlockUtil.recolorBlock(world, pos, hitSide, paint)) {
return InteractionResult.SUCCESS;
}
else
{
else {
return InteractionResult.FAIL;
}
}
Expand Down
10 changes: 5 additions & 5 deletions api/buildcraft/api/blocks/CustomRotationHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.google.common.collect.Maps;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Registry;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
Expand All @@ -16,8 +15,7 @@
import java.util.List;
import java.util.Map;

public enum CustomRotationHelper
{
public enum CustomRotationHelper {
INSTANCE;

/* If you want to test your class-based rotation registration then add the system property
Expand All @@ -44,7 +42,8 @@ public void registerHandler(Block block, ICustomRotationHandler handler) {
if (DEBUG) {
BCLog.logger.info("[api.rotation] Setting a rotation handler for core " + block.getRegistryName());
}
} else if (DEBUG) {
}
else if (DEBUG) {
BCLog.logger.info("[api.rotation] Adding another rotation handler for core " + block.getRegistryName());
}
}
Expand All @@ -55,7 +54,8 @@ private boolean registerHandlerInternal(Block block, ICustomRotationHandler hand
forBlock.add(handler);
handlers.put(block, forBlock);
return true;
} else {
}
else {
handlers.get(block).add(handler);
return false;
}
Expand Down
5 changes: 2 additions & 3 deletions api/buildcraft/api/blocks/ICustomPaintHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@

/** Provides a way to paint blocks from any position. You can either implement this on a core, or register an instance
* for a core with {@link CustomPaintHelper} */
public interface ICustomPaintHandler
{
public interface ICustomPaintHandler {
/** Attempts to paint the given core. This can also only paint a specific part of the core (as the hit position is
* given).
*
*
* @param world The world that the core is contained within.
* @param pos The position of the core.
* @param state The current state of the core.
Expand Down
3 changes: 1 addition & 2 deletions api/buildcraft/api/blocks/ICustomRotationHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;

public interface ICustomRotationHandler
{
public interface ICustomRotationHandler {
InteractionResult attemptRotation(Level world, BlockPos pos, BlockState state, Direction sideWrenched);
}
3 changes: 2 additions & 1 deletion api/buildcraft/api/boards/RedstoneBoardNBT.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public void createBoard(CompoundTag nbt) {
public int getParameterNumber(CompoundTag nbt) {
if (!nbt.contains("parameters")) {
return 0;
} else {
}
else {
return nbt.getList("parameters", Tag.TAG_COMPOUND).size();
}
}
Expand Down
2 changes: 1 addition & 1 deletion api/buildcraft/api/boards/RedstoneBoardRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public abstract class RedstoneBoardRegistry {
public static RedstoneBoardRegistry instance;

/** Register a redstone board type.
*
*
* @param redstoneBoardNBT The RedstoneBoardNBT instance containing the board information.
* @param microJoules MJ price of the board, in micro MJ. */
public abstract void registerBoardType(RedstoneBoardNBT<?> redstoneBoardNBT, long microJoules);
Expand Down
Loading