Skip to content

Commit

Permalink
Material Block Cleanup + Block Registration Cleanup + annotations (#1715
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Tictim authored May 11, 2023
1 parent 78c4d1d commit 14bf3ed
Show file tree
Hide file tree
Showing 24 changed files with 401 additions and 496 deletions.
2 changes: 2 additions & 0 deletions src/main/java/gregtech/api/block/DelayedStateBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
* This class allows lazy initialization of block state of block
* Useful when you need some parameters from constructor to construct a BlockStateContainer
* All child classes must call initBlockState() in their constructors
* @deprecated No usage
*/
@Deprecated
public abstract class DelayedStateBlock extends Block {

public DelayedStateBlock(Material materialIn) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@

public abstract class MultiblockControllerBase extends MetaTileEntity implements IMultiblockController {

@Nullable
public BlockPattern structurePattern;

private final Map<MultiblockAbility<Object>, List<Object>> multiblockAbilities = new HashMap<>();
Expand Down Expand Up @@ -143,8 +144,8 @@ public static TraceabilityPredicate metaTileEntities(MetaTileEntity... metaTileE
return tilePredicate((state, tile) -> ArrayUtils.contains(ids, tile.metaTileEntityId), getCandidates(metaTileEntities));
}

private static Supplier<BlockInfo[]> getCandidates(MetaTileEntity... metaTileEntities){
return ()->Arrays.stream(metaTileEntities).filter(Objects::nonNull).map(tile -> {
private static Supplier<BlockInfo[]> getCandidates(MetaTileEntity... metaTileEntities) {
return () -> Arrays.stream(metaTileEntities).filter(Objects::nonNull).map(tile -> {
// TODO
MetaTileEntityHolder holder = new MetaTileEntityHolder();
holder.setMetaTileEntity(tile);
Expand Down Expand Up @@ -174,7 +175,9 @@ public static TraceabilityPredicate states(IBlockState... allowedStates) {
}, getCandidates(allowedStates));
}

/** Use this predicate for Frames in your Multiblock. Allows for Framed Pipes as well as normal Frame blocks. */
/**
* Use this predicate for Frames in your Multiblock. Allows for Framed Pipes as well as normal Frame blocks.
*/
public static TraceabilityPredicate frames(Material... frameMaterials) {
return states(Arrays.stream(frameMaterials).map(m -> MetaBlocks.FRAMES.get(m).getBlock(m)).toArray(IBlockState[]::new))
.or(new TraceabilityPredicate(blockWorldState -> {
Expand Down Expand Up @@ -249,6 +252,7 @@ public void checkStructurePattern() {
Map<MultiblockAbility<Object>, List<Object>> abilities = new HashMap<>();
for (IMultiblockPart multiblockPart : parts) {
if (multiblockPart instanceof IMultiblockAbilityPart) {
@SuppressWarnings("unchecked")
IMultiblockAbilityPart<Object> abilityPart = (IMultiblockAbilityPart<Object>) multiblockPart;
List<Object> abilityInstancesList = abilities.computeIfAbsent(abilityPart.getAbility(), k -> new ArrayList<>());
abilityPart.registerAbilities(abilityInstancesList);
Expand Down Expand Up @@ -391,7 +395,7 @@ private List<MultiblockShapeInfo> repetitionDFS(List<MultiblockShapeInfo> pages,
for (int i = 0; i < repetitionStack.size(); i++) {
repetition[i] = repetitionStack.get(i);
}
pages.add(new MultiblockShapeInfo(this.structurePattern.getPreview(repetition)));
pages.add(new MultiblockShapeInfo(Objects.requireNonNull(this.structurePattern).getPreview(repetition)));
} else {
for (int i = aisleRepetitions[repetitionStack.size()][0]; i <= aisleRepetitions[repetitionStack.size()][1]; i++) {
repetitionStack.push(i);
Expand Down
23 changes: 12 additions & 11 deletions src/main/java/gregtech/api/pipenet/block/BlockPipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@
import gregtech.api.pipenet.WorldPipeNet;
import gregtech.api.pipenet.tile.IPipeTile;
import gregtech.api.pipenet.tile.TileEntityPipeBase;
import gregtech.api.unification.material.Material;
import gregtech.api.util.GTUtility;
import gregtech.common.ConfigHolder;
import gregtech.common.blocks.BlockFrame;
import gregtech.common.blocks.FrameItemBlock;
import gregtech.common.blocks.MetaBlocks;
import gregtech.common.items.MetaItems;
import gregtech.integration.ctm.IFacadeWrapper;
Expand Down Expand Up @@ -295,16 +293,19 @@ public boolean onBlockActivated(@Nonnull World worldIn, @Nonnull BlockPos pos, @
public boolean onPipeActivated(World world, IBlockState state, BlockPos pos, EntityPlayer entityPlayer, EnumHand hand, EnumFacing side, CuboidRayTraceResult hit, IPipeTile<PipeType, NodeDataType> pipeTile) {
ItemStack itemStack = entityPlayer.getHeldItem(hand);

if (pipeTile.getFrameMaterial() == null && pipeTile instanceof TileEntityPipeBase && itemStack.getItem() instanceof FrameItemBlock && pipeTile.getPipeType().getThickness() < 1) {
BlockFrame frameBlock = (BlockFrame) ((FrameItemBlock) itemStack.getItem()).getBlock();
Material material = frameBlock.getGtMaterial(itemStack.getMetadata());
((TileEntityPipeBase<PipeType, NodeDataType>) pipeTile).setFrameMaterial(material);
SoundType type = frameBlock.getSoundType(itemStack);
world.playSound(entityPlayer, pos, type.getPlaceSound(), SoundCategory.BLOCKS, (type.getVolume() + 1.0F) / 2.0F, type.getPitch() * 0.8F);
if (!entityPlayer.capabilities.isCreativeMode) {
itemStack.shrink(1);
if (pipeTile.getFrameMaterial() == null &&
pipeTile instanceof TileEntityPipeBase &&
pipeTile.getPipeType().getThickness() < 1) {
BlockFrame frameBlock = BlockFrame.getFrameBlockFromItem(itemStack);
if (frameBlock != null) {
((TileEntityPipeBase<PipeType, NodeDataType>) pipeTile).setFrameMaterial(frameBlock.getGtMaterial(itemStack));
SoundType type = frameBlock.getSoundType(itemStack);
world.playSound(entityPlayer, pos, type.getPlaceSound(), SoundCategory.BLOCKS, (type.getVolume() + 1.0F) / 2.0F, type.getPitch() * 0.8F);
if (!entityPlayer.capabilities.isCreativeMode) {
itemStack.shrink(1);
}
return true;
}
return true;
}

if (itemStack.getItem() instanceof ItemBlockPipe) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public MetaItemBracketHandler() {
this.method = CraftTweakerAPI.getJavaMethod(MetaItemBracketHandler.class, "getCtMetaItem", String.class);
}

@SuppressWarnings("ConstantConditions")
public static void rebuildComponentRegistry() {
metaItemNames.clear();
for (MetaItem<?> item : MetaItem.getMetaItems()) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/gregtech/api/util/CTRecipeHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ public static String getMetaItemId(ItemStack item) {
}
}
if (block instanceof BlockCompressed) {
return "block" + ((BlockCompressed) block).getGtMaterial(item.getMetadata()).toCamelCaseString();
return "block" + ((BlockCompressed) block).getGtMaterial(item).toCamelCaseString();
}
if (block instanceof BlockFrame) {
return "frame" + ((BlockFrame) block).getGtMaterial(item.getMetadata()).toCamelCaseString();
return "frame" + ((BlockFrame) block).getGtMaterial(item).toCamelCaseString();
}
if (block instanceof BlockMaterialPipe) {
return ((BlockMaterialPipe<?, ?, ?>) block).getPrefix().name + BlockMaterialPipe.getItemMaterial(item).toCamelCaseString();
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/gregtech/api/util/GTStringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ public static String prettyPrintItemStack(@Nonnull ItemStack stack) {
Block block = Block.getBlockFromItem(stack.getItem());
String id = null;
if (block instanceof BlockCompressed) {
id = "block" + ((BlockCompressed) block).getGtMaterial(stack.getMetadata()).toCamelCaseString();
id = "block" + ((BlockCompressed) block).getGtMaterial(stack).toCamelCaseString();
} else if (block instanceof BlockFrame) {
id = "frame" + ((BlockFrame) block).getGtMaterial(stack.getMetadata()).toCamelCaseString();
id = "frame" + ((BlockFrame) block).getGtMaterial(stack).toCamelCaseString();
} else if (block instanceof BlockMaterialPipe) {
id = ((BlockMaterialPipe<?, ?, ?>) block).getPrefix().name + BlockMaterialPipe.getItemMaterial(stack).toCamelCaseString();
}
Expand Down Expand Up @@ -87,7 +87,7 @@ public static String ticksToElapsedTime(int ticks) {
*
* @param stringToDraw The String to draw
* @param fontRenderer An instance of the MC FontRenderer
* @param maxLength The maximum width of the String
* @param maxLength The maximum width of the String
*/
public static void drawCenteredStringWithCutoff(String stringToDraw, FontRenderer fontRenderer, int maxLength) {

Expand Down
41 changes: 0 additions & 41 deletions src/main/java/gregtech/client/ClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,47 +70,6 @@
@Mod.EventBusSubscriber(Side.CLIENT)
public class ClientProxy extends CommonProxy {

public static final IBlockColor COMPRESSED_BLOCK_COLOR = (IBlockState state, IBlockAccess worldIn, BlockPos pos, int tintIndex) ->
state.getValue(((BlockCompressed) state.getBlock()).variantProperty).getMaterialRGB();

public static final IItemColor COMPRESSED_ITEM_COLOR = (stack, tintIndex) -> {
BlockCompressed block = (BlockCompressed) ((ItemBlock) stack.getItem()).getBlock();
IBlockState state = block.getStateFromMeta(stack.getItemDamage());
return state.getValue(block.variantProperty).getMaterialRGB();
};

public static final IBlockColor FRAME_BLOCK_COLOR = (IBlockState state, IBlockAccess worldIn, BlockPos pos, int tintIndex) ->
state.getValue(((BlockFrame) state.getBlock()).variantProperty).getMaterialRGB();

public static final IItemColor FRAME_ITEM_COLOR = (stack, tintIndex) -> {
BlockFrame block = (BlockFrame) ((ItemBlock) stack.getItem()).getBlock();
IBlockState state = block.getStateFromMeta(stack.getItemDamage());
return state.getValue(block.variantProperty).getMaterialRGB();
};

public static final IBlockColor ORE_BLOCK_COLOR = (IBlockState state, IBlockAccess worldIn, BlockPos pos, int tintIndex) ->
tintIndex == 1 ? ((BlockOre) state.getBlock()).material.getMaterialRGB() : 0xFFFFFF;

public static final IItemColor ORE_ITEM_COLOR = (stack, tintIndex) ->
tintIndex == 1 ? ((BlockOre) ((ItemBlock) stack.getItem()).getBlock()).material.getMaterialRGB() : 0xFFFFFF;

public static final IBlockColor FOAM_BLOCK_COLOR = (IBlockState state, IBlockAccess worldIn, BlockPos pos, int tintIndex) ->
state.getValue(BlockColored.COLOR).colorValue;

public static final IBlockColor SURFACE_ROCK_BLOCK_COLOR = (IBlockState state, IBlockAccess worldIn, BlockPos pos, int tintIndex) ->
tintIndex == 1 ? state.getValue(((BlockSurfaceRock) state.getBlock()).variantProperty).getMaterialRGB() : -1;

public static final IBlockColor RUBBER_LEAVES_BLOCK_COLOR = (IBlockState state, IBlockAccess worldIn, BlockPos pos, int tintIndex) ->
0x98de4b;

public static final IItemColor RUBBER_LEAVES_ITEM_COLOR = (stack, tintIndex) -> 0x98de4b;

public static final IBlockColor MACHINE_CASING_BLOCK_COLOR = (state, world, pos, tintIndex) ->
state.getBlock() instanceof BlockMachineCasing && MetaBlocks.MACHINE_CASING.getMetaFromState(state) == 0 ? 0xFFFFFF : ConfigHolder.client.defaultPaintingColor;

public static final IItemColor MACHINE_CASING_ITEM_COLOR = (stack, tintIndex) ->
stack.getItemDamage() == 0 && ((ItemBlock) stack.getItem()).getBlock() instanceof BlockMachineCasing ? 0xFFFFFF : ConfigHolder.client.defaultPaintingColor;

public void onPreLoad() {
super.onPreLoad();

Expand Down
36 changes: 16 additions & 20 deletions src/main/java/gregtech/common/CommonProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ public static void registerBlocks(RegistryEvent.Register<Block> event) {
for (BlockLamp block : LAMPS.values()) registry.register(block);
for (BlockLamp block : BORDERLESS_LAMPS.values()) registry.register(block);

COMPRESSED.values().stream().distinct().forEach(registry::register);
FRAMES.values().stream().distinct().forEach(registry::register);
SURFACE_ROCK.values().stream().distinct().forEach(registry::register);
ORES.forEach(registry::register);
for (BlockCompressed block : COMPRESSED_BLOCKS) registry.register(block);
for (BlockFrame block : FRAME_BLOCKS) registry.register(block);
for (BlockSurfaceRock block : SURFACE_ROCK_BLOCKS) registry.register(block);
for (BlockOre block : ORES) registry.register(block);
}

private static void createOreBlock(Material material) {
Expand Down Expand Up @@ -254,17 +254,15 @@ public static void registerItems(RegistryEvent.Register<Item> event) {
registry.register(createItemBlock(RUBBER_LEAVES, ItemBlock::new));
registry.register(createItemBlock(RUBBER_SAPLING, ItemBlock::new));

COMPRESSED.values()
.stream().distinct()
.map(block -> createItemBlock(block, CompressedItemBlock::new))
.forEach(registry::register);
FRAMES.values()
.stream().distinct()
.map(block -> createItemBlock(block, FrameItemBlock::new))
.forEach(registry::register);
ORES.stream()
.map(block -> createItemBlock(block, OreItemBlock::new))
.forEach(registry::register);
for (BlockCompressed block : COMPRESSED_BLOCKS) {
registry.register(createItemBlock(block, b -> new MaterialItemBlock(b, OrePrefix.block)));
}
for (BlockFrame block : FRAME_BLOCKS) {
registry.register(createItemBlock(block, b -> new MaterialItemBlock(b, OrePrefix.frameGt)));
}
for (BlockOre block : ORES) {
registry.register(createItemBlock(block, OreItemBlock::new));
}
}

@SubscribeEvent(priority = EventPriority.HIGHEST)
Expand Down Expand Up @@ -339,13 +337,11 @@ public static void modifyFuelBurnTime(FurnaceFuelBurnTimeEvent event) {
event.setBurnTime(100);
} else if (block == WOOD_SLAB) {
event.setBurnTime(150);
} else if (stack.getItem() instanceof CompressedItemBlock) {
} else if (block instanceof BlockCompressed) {
//handle material blocks burn value
CompressedItemBlock itemBlock = (CompressedItemBlock) stack.getItem();
Material material = itemBlock.getBlockState(stack).getValue(itemBlock.compressedBlock.variantProperty);
Material material = ((BlockCompressed) block).getGtMaterial(stack);
DustProperty property = material.getProperty(PropertyKey.DUST);
if (property != null &&
property.getBurnTime() > 0) {
if (property != null && property.getBurnTime() > 0) {
//compute burn value for block prefix, taking amount of material in block into account
double materialUnitsInBlock = OrePrefix.block.getMaterialAmount(material) / (GTValues.M * 1.0);
event.setBurnTime((int) (materialUnitsInBlock * property.getBurnTime()));
Expand Down
Loading

0 comments on commit 14bf3ed

Please sign in to comment.