Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BuildCraft API for 1.16.5 Forge #49

Open
wants to merge 2 commits into
base: 8.0.x-1.12.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 13 additions & 5 deletions api/buildcraft/api/BCBlocks.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
package buildcraft.api;

import net.minecraft.block.Block;

import net.minecraftforge.fml.common.registry.GameRegistry.ObjectHolder;
import net.minecraftforge.registries.ObjectHolder;

public class BCBlocks {

@ObjectHolder("buildcraftcore")
public static class Core {
public static final Block SPRING = null;
public static final Block DECORATED = null;
public static final Block ENGINE = null;
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;
}
Expand Down
33 changes: 18 additions & 15 deletions api/buildcraft/api/BCItems.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package buildcraft.api;

import net.minecraft.item.Item;

import net.minecraftforge.fml.common.registry.GameRegistry.ObjectHolder;

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

public class BCItems {

Expand All @@ -23,7 +21,7 @@ public static class Core {
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 = 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;
Expand All @@ -42,34 +40,39 @@ public static class Builders {

@ObjectHolder("buildcraftenergy")
public static class Energy {
public static final Item GLOB_OF_OIL = null;
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 = null;
public static final Item GELLED_WATER = 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 = null;
public static final Item PIPE_WOOD_ITEM = null;
public static final Item PIPE_EMZULI_ITEM = null;
public static final Item PIPE_DIAMOND_WOOD_ITEM = null;
public static final Item PIPE_WOOD_FLUID = null;
public static final Item PIPE_DIAMOND_WOOD_FLUID = 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 REDSTONE_CHIPSET = null;
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;
public static final Item PLUG_FACADE = null;
}

@ObjectHolder("buildcraftrobotics")
Expand Down
27 changes: 16 additions & 11 deletions api/buildcraft/api/BCModules.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package buildcraft.api;

import net.minecraft.client.renderer.model.ModelResourceLocation;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.ModList;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.ModLoadingStage;

import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import javax.annotation.Nullable;

import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.util.ResourceLocation;

import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.LoaderState;

public enum BCModules implements IBuildCraftMod {
LIB,
// Base module for all BC.
Expand All @@ -30,10 +29,14 @@ public enum BCModules implements IBuildCraftMod {
private static boolean hasChecked = false;
private static BCModules[] loadedModules, missingModules;

// Calen
public static final String BUILDCRAFT = "buildcraft";

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;

private static void checkLoadStatus() {
Expand All @@ -48,12 +51,14 @@ private static synchronized void load0() {
if (hasChecked) {
return;
}
if (!Loader.instance().hasReachedState(LoaderState.PREINITIALIZATION)) {
// 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!");
}
List<BCModules> found = new ArrayList<>(), missing = new ArrayList<>();
for (BCModules module : VALUES) {
module.loaded = Loader.isModLoaded(module.modId);
module.loaded = ModList.get().isLoaded(module.modId);

if (module.loaded) {
found.add(module);
} else {
Expand Down
15 changes: 15 additions & 0 deletions api/buildcraft/api/blocks/BlockConstants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package buildcraft.api.blocks;

public class BlockConstants {
public static final int UPDATE_NEIGHBORS = 1;
public static final int UPDATE_CLIENTS = 2;
public static final int UPDATE_INVISIBLE = 4;
public static final int UPDATE_IMMEDIATE = 8;
public static final int UPDATE_KNOWN_SHAPE = 16;
public static final int UPDATE_SUPPRESS_DROPS = 32;
public static final int UPDATE_MOVE_BY_PISTON = 64;
public static final int UPDATE_SUPPRESS_LIGHT = 128;
public static final int UPDATE_NONE = 4;
public static final int UPDATE_ALL = 3;
public static final int UPDATE_ALL_IMMEDIATE = 11;
}
76 changes: 51 additions & 25 deletions api/buildcraft/api/blocks/CustomPaintHelper.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
package buildcraft.api.blocks;

import java.util.List;
import java.util.Map;

import javax.annotation.Nullable;

import buildcraft.api.core.BCDebugging;
import buildcraft.api.core.BCLog;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.block.BlockState;
import net.minecraft.item.DyeColor;
import net.minecraft.state.Property;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.world.World;
import net.minecraftforge.registries.ForgeRegistries;

import buildcraft.api.core.BCDebugging;
import buildcraft.api.core.BCLog;
import javax.annotation.Nullable;
import java.util.List;
import java.util.Map;

/** Provides a simple way to paint a single block, iterating through all {@link ICustomPaintHandler}'s that are
* registered for the block. */
Expand All @@ -43,7 +42,8 @@ public void registerHandlerForAll(ICustomPaintHandler handler) {

/** 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 : Block.REGISTRY)
for (Block block : ForgeRegistries.BLOCKS.getValues()) {
Class<? extends Block> foundClass = block.getClass();
if (blockClass.isAssignableFrom(foundClass)) {
if (DEBUG) {
Expand Down Expand Up @@ -77,7 +77,7 @@ private boolean registerHandlerInternal(Block block, ICustomPaintHandler handler
}

/** Attempts to paint a block at the given position. Basically iterates through all registered paint handlers. */
public EnumActionResult attemptPaintBlock(World world, BlockPos pos, IBlockState state, Vec3d hitPos, @Nullable EnumFacing hitSide, @Nullable EnumDyeColor paint) {
public ActionResultType attemptPaintBlock(World world, BlockPos pos, BlockState state, Vector3d hitPos, @Nullable Direction hitSide, @Nullable DyeColor paint) {
Block block = state.getBlock();
if (block instanceof ICustomPaintHandler) {
return ((ICustomPaintHandler) block).attemptPaint(world, pos, state, hitPos, hitSide, paint);
Expand All @@ -87,29 +87,55 @@ public EnumActionResult attemptPaintBlock(World world, BlockPos pos, IBlockState
return defaultAttemptPaint(world, pos, state, hitPos, hitSide, paint);
}
for (ICustomPaintHandler handler : custom) {
EnumActionResult result = handler.attemptPaint(world, pos, state, hitPos, hitSide, paint);
if (result != EnumActionResult.PASS) {
ActionResultType result = handler.attemptPaint(world, pos, state, hitPos, hitSide, paint);
if (result != ActionResultType.PASS) {
return result;
}
}
return defaultAttemptPaint(world, pos, state, hitPos, hitSide, paint);
}

private EnumActionResult defaultAttemptPaint(World world, BlockPos pos, IBlockState state, Vec3d hitPos, EnumFacing hitSide, @Nullable EnumDyeColor paint) {
private ActionResultType defaultAttemptPaint(World world, BlockPos pos, BlockState state, Vector3d hitPos, Direction hitSide, @Nullable DyeColor paint) {
for (ICustomPaintHandler handler : allHandlers) {
EnumActionResult result = handler.attemptPaint(world, pos, state, hitPos, hitSide, paint);
if (result != EnumActionResult.PASS) {
ActionResultType result = handler.attemptPaint(world, pos, state, hitPos, hitSide, paint);
if (result != ActionResultType.PASS) {
return result;
}
}
if (paint == null) {
return EnumActionResult.FAIL;
return ActionResultType.FAIL;
}
Block b = state.getBlock();
if (b.recolorBlock(world, pos, hitSide, paint)) {
return EnumActionResult.SUCCESS;
// Block b = state.getBlock();
// if (b.recolorBlock(world, pos, hitSide, paint))
if (recolorBlock(world, pos, hitSide, paint)) {
return ActionResultType.SUCCESS;
} else {
return EnumActionResult.FAIL;
return ActionResultType.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(World 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), BlockConstants.UPDATE_ALL);
return true;
}
}
}
return false;
}
}
29 changes: 14 additions & 15 deletions api/buildcraft/api/blocks/CustomRotationHelper.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package buildcraft.api.blocks;

import java.util.List;
import java.util.Map;

import buildcraft.api.core.BCDebugging;
import buildcraft.api.core.BCLog;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.block.BlockState;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.registries.ForgeRegistries;

import buildcraft.api.core.BCDebugging;
import buildcraft.api.core.BCLog;
import java.util.List;
import java.util.Map;

public enum CustomRotationHelper {
INSTANCE;
Expand All @@ -26,7 +25,7 @@ public enum CustomRotationHelper {
private final Map<Block, List<ICustomRotationHandler>> handlers = Maps.newIdentityHashMap();

public void registerHandlerForAll(Class<? extends Block> blockClass, ICustomRotationHandler handler) {
for (Block block : Block.REGISTRY) {
for (Block block : ForgeRegistries.BLOCKS) {
Class<? extends Block> foundClass = block.getClass();
if (blockClass.isAssignableFrom(foundClass)) {
if (DEBUG) {
Expand Down Expand Up @@ -59,18 +58,18 @@ private boolean registerHandlerInternal(Block block, ICustomRotationHandler hand
}
}

public EnumActionResult attemptRotateBlock(World world, BlockPos pos, IBlockState state, EnumFacing sideWrenched) {
public ActionResultType attemptRotateBlock(World world, BlockPos pos, BlockState state, Direction sideWrenched) {
Block block = state.getBlock();
if (block instanceof ICustomRotationHandler) {
return ((ICustomRotationHandler) block).attemptRotation(world, pos, state, sideWrenched);
}
if (!handlers.containsKey(block)) return EnumActionResult.PASS;
if (!handlers.containsKey(block)) return ActionResultType.PASS;
for (ICustomRotationHandler handler : handlers.get(block)) {
EnumActionResult result = handler.attemptRotation(world, pos, state, sideWrenched);
if (result != EnumActionResult.PASS) {
ActionResultType result = handler.attemptRotation(world, pos, state, sideWrenched);
if (result != ActionResultType.PASS) {
return result;
}
}
return EnumActionResult.PASS;
return ActionResultType.PASS;
}
}
18 changes: 9 additions & 9 deletions api/buildcraft/api/blocks/ICustomPaintHandler.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package buildcraft.api.blocks;

import javax.annotation.Nullable;

import net.minecraft.block.state.IBlockState;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.block.BlockState;
import net.minecraft.item.DyeColor;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.world.World;

import javax.annotation.Nullable;

/** Provides a way to paint blocks from any position. You can either implement this on a block, or register an instance
* for a block with {@link CustomPaintHelper} */
public interface ICustomPaintHandler {
/** Attempts to paint the given block. This can also only paint a specific part of the block (as the hit position is
* given).
*
*
* @param world The world that the block is contained within.
* @param pos The position of the block.
* @param state The current state of the block.
Expand All @@ -27,5 +27,5 @@ public interface ICustomPaintHandler {
* @return The result of attempting to paint. SUCCESS means that you changed the block from before to a new value,
* FAIL means you COULD have handled the block, but it was already painted to that colour, or PASS if you
* have no idea how to handle the block in question. */
EnumActionResult attemptPaint(World world, BlockPos pos, IBlockState state, Vec3d hitPos, @Nullable EnumFacing hitSide, @Nullable EnumDyeColor paintColour);
ActionResultType attemptPaint(World world, BlockPos pos, BlockState state, Vector3d hitPos, @Nullable Direction hitSide, @Nullable DyeColor paintColour);
}
Loading