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
Cleaned up API module
All the classes of API does not import other BC modules now.
  • Loading branch information
CalenXwX committed Apr 27, 2024
commit bae7c3c46305d3cf2ba418d1fa37d63f78d3837a
76 changes: 76 additions & 0 deletions api/buildcraft/api/BCBlocks.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package buildcraft.api;

import net.minecraft.world.level.block.Block;
import net.minecraftforge.registries.ObjectHolder;

public class BCBlocks {

@ObjectHolder("buildcraftcore")
public static class Core {
public static final Block SPRING_WATER = null;
public static final Block SPRING_OIL = null;
public static final Block DECORATED_DESTROY = null;
public static final Block DECORATED_BLUEPRINT = null;
public static final Block DECORATED_TEMPLATE = null;
public static final Block DECORATED_PAPER = null;
public static final Block DECORATED_LEATHER = null;
public static final Block DECORATED_LASER_BACK = null;
public static final Block ENGINE_WOOD = null;
public static final Block ENGINE_STONE = null;
public static final Block ENGINE_IRON = null;
public static final Block ENGINE_CREATIVE = null;
public static final Block MARKER_VOLUME = null;
public static final Block MARKER_PATH = null;
}

@ObjectHolder("buildcraftbuilders")
public static class Builders {
public static final Block ARCHITECT = null;
public static final Block BUILDER = null;
public static final Block FILLER = null;
public static final Block LIBRARY = null;
public static final Block REPLACER = null;
public static final Block QUARRY = null;
public static final Block FRAME = null;
}

@ObjectHolder("buildcraftenergy")
public static class Energy {
// Fluid blocks can be accessed ~somewhere else~
}

@ObjectHolder("buildcraftfactory")
public static class Factory {
public static final Block AUTOWORKBENCH_ITEM = null;
public static final Block MINING_WELL = null;
public static final Block PUMP = null;
public static final Block TUBE = null;
public static final Block FLOOD_GATE = null;
public static final Block TANK = null;
public static final Block CHUTE = null;
public static final Block WATER_GEL = null;
public static final Block DISTILLER = null;
public static final Block HEAT_EXCHANGE = null;
}

@ObjectHolder("buildcrafttransport")
public static class Transport {
public static final Block FILTERED_BUFFER = null;
public static final Block PIPE_HOLDER = null;
}

@ObjectHolder("buildcraftsilicon")
public static class Silicon {
public static final Block LASER = null;
public static final Block ASSEMBLY_TABLE = null;
public static final Block ADVANCED_CRAFTING_TABLE = null;
public static final Block INTEGRATION_TABLE = null;
public static final Block CHARGING_TABLE = null;
public static final Block PROGRAMMING_TABLE = null;
}

@ObjectHolder("buildcraftrobotics")
public static class Robotics {

}
}
81 changes: 81 additions & 0 deletions api/buildcraft/api/BCItems.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package buildcraft.api;

import buildcraft.api.items.FluidItemDrops;
import net.minecraft.world.item.Item;
import net.minecraftforge.registries.ObjectHolder;

public class BCItems {

@ObjectHolder("buildcraftlib")
public static class Lib {
public static final Item GUIDE = null;
public static final Item GUIDE_NOTE = null;
public static final Item DEBUGGER = null;
}

@ObjectHolder("buildcraftcore")
public static class Core {
public static final Item GEAR_WOOD = null;
public static final Item GEAR_STONE = null;
public static final Item GEAR_IRON = null;
public static final Item GEAR_GOLD = null;
public static final Item GEAR_DIAMOND = null;
public static final Item WRENCH = null;
public static final Item PAINTBRUSH_CLEAN = null;
public static final Item LIST = null;
public static final Item MAP_LOCATION = null;
public static final Item MARKER_CONNECTOR = null;
public static final Item VOLUME_BOX = null;
public static final Item GOGGLES = null;

/** It is recommended that you refer to {@link FluidItemDrops#item} when creating fluid drops rather than
* this. */
public static final Item FRAGILE_FLUID_SHARD = null;
}

@ObjectHolder("buildcraftbuilders")
public static class Builders {

}

@ObjectHolder("buildcraftenergy")
public static class Energy {
public static final Item GLOB_OIL = null;
}

@ObjectHolder("buildcraftfactory")
public static class Factory {
public static final Item PLASTIC_SHEET = null;
public static final Item WATER_GEL_SPAWN = null;
public static final Item GEL = null;
}

@ObjectHolder("buildcrafttransport")
public static class Transport {
public static final Item PLUG_BLOCKER = null;
public static final Item PLUG_POWER_ADAPTOR = null;

public static final Item PIPE_STRUCTURE_COBBLESTONE_COLORLESS = null;
public static final Item PIPE_ITEMS_WOOD_COLORLESS = null;
public static final Item PIPE_ITEMS_EMZULI_COLORLESS = null;
public static final Item PIPE_ITEMS_DIAMOND_WOOD_COLORLESS = null;
public static final Item PIPE_FLUIDS_WOOD_COLORLESS = null;
public static final Item PIPE_FLUIDS_DIAMOND_WOOD_COLORLESS = null;
}

@ObjectHolder("buildcraftsilicon")
public static class Silicon {
public static final Item CHIPSET_REDSTONE = null;
public static final Item CHIPSET_IRON = null;
public static final Item CHIPSET_GOLD = null;
public static final Item CHIPSET_QUARTZ = null;
public static final Item CHIPSET_DIAMOND = null;

public static final Item PLUG_PULSAR = null;
}

@ObjectHolder("buildcraftrobotics")
public static class Robotics {

}
}
19 changes: 8 additions & 11 deletions api/buildcraft/api/BCModules.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.fml.ModList;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.ModLoadingStage;

import javax.annotation.Nullable;
import java.util.ArrayList;
Expand Down Expand Up @@ -33,7 +35,7 @@ public enum BCModules implements IBuildCraftMod {
public final String lowerCaseName = name().toLowerCase(Locale.ROOT);
// Bit hacky, but it works as this is all english
public final String camelCaseName = name().charAt(0) + lowerCaseName.substring(1);
// private final String modId = "buildcraft" + lowerCaseName;
// private final String modId = "buildcraft" + lowerCaseName;
private final String modId = BUILDCRAFT + lowerCaseName;
private boolean loaded;

Expand All @@ -44,27 +46,22 @@ private static void checkLoadStatus() {
load0();
}

/**
* Performs the actual loading of {@link #checkLoadStatus()}, except this is thread safe.
*/
/** Performs the actual loading of {@link #checkLoadStatus()}, except this is thread safe. */
private static synchronized void load0() {
if (hasChecked) {
return;
}
// Calen: loading events order is changed from 1.12.2 to 1.18.2...
// if (!Loader.instance().hasReachedState(LoaderState.PREINITIALIZATION))
// if (ModLoadingContext.get().getActiveContainer().getCurrentState().ordinal() >= ModLoadingStage.CONSTRUCT.ordinal())
// {
// throw new RuntimeException("You can only use BCModules.isLoaded from pre-init onwards!");
// }
if (ModLoadingContext.get().getActiveContainer().getCurrentState().ordinal() < ModLoadingStage.CONSTRUCT.ordinal()) {
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) {
module.loaded = ModList.get().isLoaded(module.modId);

if (module.loaded) {
found.add(module);
}
else {
} else {
missing.add(module);
}
}
Expand Down
60 changes: 37 additions & 23 deletions api/buildcraft/api/blocks/CustomPaintHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

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;
import net.minecraft.core.BlockPos;
Expand All @@ -12,17 +11,16 @@
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.registries.ForgeRegistries;

import javax.annotation.Nullable;
import java.util.List;
import java.util.Map;

/**
* Provides a simple way to paint a single core, iterating through all {@link ICustomPaintHandler}'s that are
* registered for the core.
*/
/** Provides a simple way to paint a single block, iterating through all {@link ICustomPaintHandler}'s that are
* registered for the block. */
public enum CustomPaintHelper {
INSTANCE;

Expand All @@ -33,20 +31,16 @@ public enum CustomPaintHelper {
private final Map<Block, List<ICustomPaintHandler>> handlers = Maps.newIdentityHashMap();
private final List<ICustomPaintHandler> allHandlers = Lists.newArrayList();

/**
* 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.
*/
/** 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 block. */
public void registerHandlerForAll(ICustomPaintHandler handler) {
if (DEBUG) {
BCLog.logger.info("[api.painting] Adding a paint handler for ALL blocks (" + handler.getClass() + ")");
}
allHandlers.add(handler);
}

/**
* Register's a paint handler for every class of a given core.
*/
/** Register's a paint handler for every class of a given block. */
public void registerHandlerForAll(Class<? extends Block> blockClass, ICustomPaintHandler handler) {
// for (Block block : Block.REGISTRY)
for (Block block : ForgeRegistries.BLOCKS.getValues()) {
Expand All @@ -65,8 +59,7 @@ public void registerHandler(Block block, ICustomPaintHandler handler) {
if (DEBUG) {
BCLog.logger.info("[api.painting] Setting a paint handler for block " + block.getRegistryName() + "(" + handler.getClass() + ")");
}
}
else if (DEBUG) {
} else if (DEBUG) {
BCLog.logger.info("[api.painting] Adding another paint handler for block " + block.getRegistryName() + "(" + handler.getClass() + ")");
}
}
Expand All @@ -77,16 +70,13 @@ private boolean registerHandlerInternal(Block block, ICustomPaintHandler handler
forBlock.add(handler);
handlers.put(block, forBlock);
return true;
}
else {
} else {
handlers.get(block).add(handler);
return false;
}
}

/**
* Attempts to paint a core at the given position. Basically iterates through all registered paint handlers.
*/
/** Attempts to paint a block 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) {
Block block = state.getBlock();
if (block instanceof ICustomPaintHandler) {
Expand Down Expand Up @@ -115,13 +105,37 @@ private InteractionResult defaultAttemptPaint(Level world, BlockPos pos, BlockSt
if (paint == null) {
return InteractionResult.FAIL;
}
Block b = state.getBlock();
// Block b = state.getBlock();
// if (b.recolorBlock(world, pos, hitSide, paint))
if (BlockUtil.recolorBlock(world, pos, hitSide, paint)) {
if (recolorBlock(world, pos, hitSide, paint)) {
return InteractionResult.SUCCESS;
}
else {
} else {
return InteractionResult.FAIL;
}
}

/**
* From 1.12.2 Block
* Common way to recolor a block with an external tool
*
* @param world The world
* @param pos Block position in world
* @param side The side hit with the coloring tool
* @param color The color to change to
* @return If the recoloring was successful
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public static boolean recolorBlock(Level world, BlockPos pos, Direction side, DyeColor color) {
BlockState state = world.getBlockState(pos);
for (Property prop : state.getProperties()) {
if (prop.getName().equals("color") && prop.getValueClass() == DyeColor.class) {
DyeColor current = (DyeColor) state.getValue(prop);
if (current != color && prop.getPossibleValues().contains(color)) {
world.setBlock(pos, state.setValue(prop, color), Block.UPDATE_ALL);
return true;
}
}
}
return false;
}
}
13 changes: 5 additions & 8 deletions api/buildcraft/api/blocks/CustomRotationHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ public enum CustomRotationHelper {

public void registerHandlerForAll(Class<? extends Block> blockClass, ICustomRotationHandler handler) {
for (Block block : ForgeRegistries.BLOCKS) {

Class<? extends Block> foundClass = block.getClass();
if (blockClass.isAssignableFrom(foundClass)) {
if (DEBUG) {
BCLog.logger.info("[api.rotation] Found an assignable core " + block.getRegistryName() + " (" + foundClass + ") for " + blockClass);
BCLog.logger.info("[api.rotation] Found an assignable block " + block.getRegistryName() + " (" + foundClass + ") for " + blockClass);
}
registerHandlerInternal(block, handler);
}
Expand All @@ -40,11 +39,10 @@ public void registerHandlerForAll(Class<? extends Block> blockClass, ICustomRota
public void registerHandler(Block block, ICustomRotationHandler handler) {
if (registerHandlerInternal(block, handler)) {
if (DEBUG) {
BCLog.logger.info("[api.rotation] Setting a rotation handler for core " + block.getRegistryName());
BCLog.logger.info("[api.rotation] Setting a rotation handler for block " + block.getRegistryName());
}
}
else if (DEBUG) {
BCLog.logger.info("[api.rotation] Adding another rotation handler for core " + block.getRegistryName());
} else if (DEBUG) {
BCLog.logger.info("[api.rotation] Adding another rotation handler for block " + block.getRegistryName());
}
}

Expand All @@ -54,8 +52,7 @@ 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
Loading