Skip to content

Commit 51ef8a8

Browse files
committed
Move relevant mod logic to common
1 parent 664f839 commit 51ef8a8

16 files changed

Lines changed: 140 additions & 115 deletions
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.cyclops.structuredcrafting;
2+
3+
import org.cyclops.cyclopscore.datastructure.Wrapper;
4+
import org.cyclops.cyclopscore.init.IModBase;
5+
6+
/**
7+
* @author rubensworks
8+
*/
9+
public interface IStructuredCraftingMod extends IModBase {
10+
11+
public static Wrapper<IStructuredCraftingMod> MOD = new Wrapper<>();
12+
13+
}

loader-common/src/main/java/org/cyclops/structuredcrafting/RegistryEntriesCommon.java renamed to loader-common/src/main/java/org/cyclops/structuredcrafting/RegistryEntries.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,20 @@
44
import net.minecraft.resources.ResourceLocation;
55
import net.minecraft.world.item.Item;
66
import net.minecraft.world.level.block.Block;
7+
import net.minecraft.world.level.block.entity.BlockEntityType;
78
import org.cyclops.cyclopscore.config.DeferredHolderCommon;
9+
import org.cyclops.structuredcrafting.blockentity.BlockEntityStructuredCrafter;
810

911
/**
1012
* Referenced registry entries.
1113
* @author rubensworks
1214
*/
13-
public class RegistryEntriesCommon {
15+
public class RegistryEntries {
1416

1517
public static final DeferredHolderCommon<Item, Item> ITEM_STRUCTURED_CRAFTER = DeferredHolderCommon.create(Registries.ITEM, ResourceLocation.parse("structuredcrafting:structured_crafter"));
1618

1719
public static final DeferredHolderCommon<Block, Block> BLOCK_STRUCTURED_CRAFTER = DeferredHolderCommon.create(Registries.BLOCK, ResourceLocation.parse("structuredcrafting:structured_crafter"));
1820

19-
// TODO: when when move the following, rename this file
20-
// public static final DeferredHolderCommon<BlockEntityType<?>, BlockEntityType<?>> BLOCK_ENTITY_STRUCTURED_CRAFTER = DeferredHolderCommon.create(Registries.BLOCK_ENTITY_TYPE, ResourceLocation.parse("structuredcrafting:structured_crafter"));
21+
public static final DeferredHolderCommon<BlockEntityType<?>, BlockEntityType<BlockEntityStructuredCrafter>> BLOCK_ENTITY_STRUCTURED_CRAFTER = DeferredHolderCommon.create(Registries.BLOCK_ENTITY_TYPE, ResourceLocation.parse("structuredcrafting:structured_crafter"));
2122

2223
}

loader-neoforge/src/main/java/org/cyclops/structuredcrafting/block/BlockStructuredCrafter.java renamed to loader-common/src/main/java/org/cyclops/structuredcrafting/block/BlockStructuredCrafter.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515
import net.minecraft.world.level.block.entity.BlockEntity;
1616
import net.minecraft.world.level.block.entity.BlockEntityTicker;
1717
import net.minecraft.world.level.block.entity.BlockEntityType;
18+
import net.minecraft.world.level.block.state.BlockBehaviour;
1819
import net.minecraft.world.level.block.state.BlockState;
1920
import net.minecraft.world.level.block.state.StateDefinition;
2021
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
2122
import net.minecraft.world.level.block.state.properties.DirectionProperty;
2223
import net.minecraft.world.phys.BlockHitResult;
23-
import org.cyclops.cyclopscore.block.BlockWithEntity;
24+
import org.cyclops.cyclopscore.block.BlockWithEntityCommon;
2425
import org.cyclops.structuredcrafting.RegistryEntries;
2526
import org.cyclops.structuredcrafting.blockentity.BlockEntityStructuredCrafter;
2627

@@ -30,9 +31,9 @@
3031
* This block will detect neighbour block updates and will try to craft a new block/item from them.
3132
* @author rubensworks
3233
*/
33-
public class BlockStructuredCrafter extends BlockWithEntity {
34+
public class BlockStructuredCrafter extends BlockWithEntityCommon {
3435

35-
public static final MapCodec<BlockStructuredCrafter> CODEC = simpleCodec(BlockStructuredCrafter::new);
36+
public static final MapCodec<BlockStructuredCrafter> CODEC = BlockBehaviour.simpleCodec(BlockStructuredCrafter::new);
3637

3738
public static final DirectionProperty FACING = BlockStateProperties.FACING;
3839

@@ -51,7 +52,7 @@ protected MapCodec<? extends BaseEntityBlock> codec() {
5152
@Override
5253
@Nullable
5354
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState blockState, BlockEntityType<T> blockEntityType) {
54-
return level.isClientSide ? null : createTickerHelper(blockEntityType, RegistryEntries.BLOCK_ENTITY_STRUCTURED_CRAFTER.value(), new BlockEntityStructuredCrafter.Ticker());
55+
return level.isClientSide ? null : BaseEntityBlock.createTickerHelper(blockEntityType, RegistryEntries.BLOCK_ENTITY_STRUCTURED_CRAFTER.value(), new BlockEntityStructuredCrafter.Ticker());
5556
}
5657

5758
@Override

loader-neoforge/src/main/java/org/cyclops/structuredcrafting/block/BlockStructuredCrafterConfig.java renamed to loader-common/src/main/java/org/cyclops/structuredcrafting/block/BlockStructuredCrafterConfig.java

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,52 @@
22

33
import net.minecraft.world.level.block.Block;
44
import net.minecraft.world.level.block.SoundType;
5-
import net.neoforged.fml.config.ModConfig;
6-
import org.cyclops.cyclopscore.config.ConfigurableProperty;
7-
import org.cyclops.cyclopscore.config.extendedconfig.BlockConfig;
8-
import org.cyclops.structuredcrafting.StructuredCrafting;
5+
import org.cyclops.cyclopscore.config.ConfigurablePropertyCommon;
6+
import org.cyclops.cyclopscore.config.ModConfigLocation;
7+
import org.cyclops.cyclopscore.config.extendedconfig.BlockConfigCommon;
8+
import org.cyclops.cyclopscore.init.IModBase;
99

1010
/**
1111
* Config for {@link BlockStructuredCrafter}.
1212
* @author rubensworks
1313
*/
14-
public class BlockStructuredCrafterConfig extends BlockConfig {
15-
16-
/**
17-
* The unique instance.
18-
*/
19-
public static BlockStructuredCrafterConfig _instance;
14+
public class BlockStructuredCrafterConfig<M extends IModBase> extends BlockConfigCommon<M> {
2015

2116
/**
2217
* If crafting inputs can be taken from the world.
2318
*/
24-
@ConfigurableProperty(category = "general", comment = "If crafting inputs can be taken from the world.", configLocation = ModConfig.Type.SERVER)
19+
@ConfigurablePropertyCommon(category = "general", comment = "If crafting inputs can be taken from the world.", configLocation = ModConfigLocation.SERVER)
2520
public static boolean canTakeInputsFromWorld = true;
2621

2722
/**
2823
* If crafting inputs can be taken from inventories.
2924
*/
30-
@ConfigurableProperty(category = "general", comment = "If crafting inputs can be taken from inventories.", configLocation = ModConfig.Type.SERVER)
25+
@ConfigurablePropertyCommon(category = "general", comment = "If crafting inputs can be taken from inventories.", configLocation = ModConfigLocation.SERVER)
3126
public static boolean canTakeInputsFromInventory = true;
3227

3328
/**
3429
* If crafting outputs can placed into the world.
3530
*/
36-
@ConfigurableProperty(category = "general", comment = "If crafting outputs can placed into the world.", configLocation = ModConfig.Type.SERVER)
31+
@ConfigurablePropertyCommon(category = "general", comment = "If crafting outputs can placed into the world.", configLocation = ModConfigLocation.SERVER)
3732
public static boolean canPlaceOutputsIntoWorld = true;
3833

3934
/**
4035
* If crafting outputs can placed into inventories.
4136
*/
42-
@ConfigurableProperty(category = "general", comment = "If crafting outputs can placed into inventories.", configLocation = ModConfig.Type.SERVER)
37+
@ConfigurablePropertyCommon(category = "general", comment = "If crafting outputs can placed into inventories.", configLocation = ModConfigLocation.SERVER)
4338
public static boolean canPlaceOutputsIntoInventory = true;
4439

4540
/**
4641
* Make a new instance.
4742
*/
48-
public BlockStructuredCrafterConfig() {
43+
public BlockStructuredCrafterConfig(M mod) {
4944
super(
50-
StructuredCrafting._instance,
45+
mod,
5146
"structured_crafter",
5247
(eConfig) -> new BlockStructuredCrafter(Block.Properties.of()
5348
.sound(SoundType.WOOD)
5449
.strength(2.0f)),
55-
getDefaultItemConstructor(StructuredCrafting._instance)
50+
BlockConfigCommon.getDefaultItemConstructor(mod)
5651
);
5752
}
5853

loader-neoforge/src/main/java/org/cyclops/structuredcrafting/blockentity/BlockEntityStructuredCrafter.java renamed to loader-common/src/main/java/org/cyclops/structuredcrafting/blockentity/BlockEntityStructuredCrafter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
import net.minecraft.world.level.Level;
55
import net.minecraft.world.level.block.state.BlockState;
66
import org.cyclops.cyclopscore.blockentity.BlockEntityTickerDelayed;
7-
import org.cyclops.cyclopscore.blockentity.CyclopsBlockEntity;
7+
import org.cyclops.cyclopscore.blockentity.CyclopsBlockEntityCommon;
88
import org.cyclops.structuredcrafting.RegistryEntries;
99
import org.cyclops.structuredcrafting.craft.WorldCraftingMatrix;
1010

1111
/**
1212
* A ticking block entity for the structured crafter.
1313
* @author rubensworks
1414
*/
15-
public class BlockEntityStructuredCrafter extends CyclopsBlockEntity {
15+
public class BlockEntityStructuredCrafter extends CyclopsBlockEntityCommon {
1616

1717
private static final int SPEED = 20;
1818

@@ -21,7 +21,7 @@ public class BlockEntityStructuredCrafter extends CyclopsBlockEntity {
2121
private int tickOffset;
2222

2323
public BlockEntityStructuredCrafter(BlockPos blockPos, BlockState blockState) {
24-
super(RegistryEntries.BLOCK_ENTITY_STRUCTURED_CRAFTER.get(), blockPos, blockState);
24+
super(RegistryEntries.BLOCK_ENTITY_STRUCTURED_CRAFTER.value(), blockPos, blockState);
2525
tickOffset = (int) (Math.random() * (float) SPEED);
2626
}
2727

loader-neoforge/src/main/java/org/cyclops/structuredcrafting/blockentity/BlockEntityStructuredCrafterConfig.java renamed to loader-common/src/main/java/org/cyclops/structuredcrafting/blockentity/BlockEntityStructuredCrafterConfig.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22

33
import com.google.common.collect.Sets;
44
import net.minecraft.world.level.block.entity.BlockEntityType;
5-
import org.cyclops.cyclopscore.config.extendedconfig.BlockEntityConfig;
6-
import org.cyclops.structuredcrafting.RegistryEntriesCommon;
7-
import org.cyclops.structuredcrafting.StructuredCrafting;
5+
import org.cyclops.cyclopscore.config.extendedconfig.BlockEntityConfigCommon;
6+
import org.cyclops.cyclopscore.init.IModBase;
7+
import org.cyclops.structuredcrafting.RegistryEntries;
88

99
/**
1010
* Config for the {@link BlockEntityStructuredCrafter}.
1111
* @author rubensworks
1212
*
1313
*/
14-
public class BlockEntityStructuredCrafterConfig extends BlockEntityConfig<BlockEntityStructuredCrafter> {
14+
public class BlockEntityStructuredCrafterConfig<M extends IModBase> extends BlockEntityConfigCommon<BlockEntityStructuredCrafter, M> {
1515

16-
public BlockEntityStructuredCrafterConfig() {
16+
public BlockEntityStructuredCrafterConfig(M mod) {
1717
super(
18-
StructuredCrafting._instance,
18+
mod,
1919
"structured_crafter",
2020
(eConfig) -> new BlockEntityType<>(BlockEntityStructuredCrafter::new,
21-
Sets.newHashSet(RegistryEntriesCommon.BLOCK_STRUCTURED_CRAFTER.value()), null)
21+
Sets.newHashSet(RegistryEntries.BLOCK_STRUCTURED_CRAFTER.value()), null)
2222
);
2323
}
2424

loader-neoforge/src/main/java/org/cyclops/structuredcrafting/craft/WorldCraftingMatrix.java renamed to loader-common/src/main/java/org/cyclops/structuredcrafting/craft/WorldCraftingMatrix.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.google.common.collect.Lists;
44
import com.google.common.collect.Maps;
5-
import lombok.ToString;
65
import net.minecraft.core.BlockPos;
76
import net.minecraft.core.Direction;
87
import net.minecraft.core.NonNullList;
@@ -12,13 +11,14 @@
1211
import net.minecraft.world.item.crafting.RecipeHolder;
1312
import net.minecraft.world.item.crafting.RecipeType;
1413
import net.minecraft.world.level.Level;
15-
import org.cyclops.cyclopscore.helper.CraftingHelpers;
16-
import org.cyclops.structuredcrafting.StructuredCrafting;
14+
import org.cyclops.cyclopscore.helper.IModHelpers;
15+
import org.cyclops.structuredcrafting.IStructuredCraftingMod;
1716
import org.cyclops.structuredcrafting.block.BlockStructuredCrafter;
1817
import org.cyclops.structuredcrafting.craft.provider.IItemStackProvider;
1918
import org.cyclops.structuredcrafting.craft.provider.IItemStackProviderRegistry;
2019

2120
import javax.annotation.Nullable;
21+
import java.util.Arrays;
2222
import java.util.List;
2323
import java.util.Map;
2424

@@ -56,7 +56,7 @@ protected BlockPos addInAxis(BlockPos pos, Direction.Axis axis, int i, int j) {
5656
}
5757

5858
protected List<IItemStackProvider> getItemStackProviders() {
59-
return StructuredCrafting._instance.getRegistryManager().
59+
return IStructuredCraftingMod.MOD.get().getRegistryManager().
6060
getRegistry(IItemStackProviderRegistry.class).getProviders();
6161
}
6262

@@ -163,7 +163,6 @@ public static WorldCraftingMatrix deriveMatrix(Level level, BlockPos centerPos)
163163
centerPos.relative(side.getOpposite()), side.getOpposite());
164164
}
165165

166-
@ToString
167166
public static class CraftingPossibility {
168167
private final WorldInventoryCrafting inventoryCrafting = new WorldInventoryCrafting();
169168
private final BlockPos[] positions = new BlockPos[9];
@@ -196,7 +195,7 @@ public void setPosition(int i, int j, int rotation, BlockPos pos, IItemStackProv
196195

197196
@Nullable
198197
protected Recipe getRecipe(Level level) {
199-
return CraftingHelpers.findRecipeCached(RecipeType.CRAFTING, inventoryCrafting.asCraftInput(), level, true)
198+
return IModHelpers.get().getCraftingHelpers().findRecipeCached(RecipeType.CRAFTING, inventoryCrafting.asCraftInput(), level, true)
200199
.map(RecipeHolder::value)
201200
.orElse(null);
202201
}
@@ -250,7 +249,7 @@ public boolean handleRemainingItems(Level level, Direction inputSide, boolean si
250249
providers[i].addItemStack(level, positions[i], inputSide, remainingStack, simulate);
251250
}
252251
} else {
253-
StructuredCrafting.clog(org.apache.logging.log4j.Level.WARN, "The structured crafting provider for position "
252+
IStructuredCraftingMod.MOD.get().getLoggerHelper().log(org.apache.logging.log4j.Level.WARN, "The structured crafting provider for position "
254253
+ i + " did not exist for stack " + originalStack);
255254
}
256255
}
@@ -268,6 +267,15 @@ public CraftingPossibility clone() {
268267
System.arraycopy(this.providers, 0, craftingPossibility.providers, 0, this.providers.length);
269268
return craftingPossibility;
270269
}
270+
271+
@Override
272+
public String toString() {
273+
return "CraftingPossibility{" +
274+
"inventoryCrafting=" + inventoryCrafting +
275+
", positions=" + Arrays.toString(positions) +
276+
", providers=" + Arrays.toString(providers) +
277+
'}';
278+
}
271279
}
272280

273281
}

loader-neoforge/src/main/java/org/cyclops/structuredcrafting/craft/WorldInventoryCrafting.java renamed to loader-common/src/main/java/org/cyclops/structuredcrafting/craft/WorldInventoryCrafting.java

File renamed without changes.

loader-neoforge/src/main/java/org/cyclops/structuredcrafting/craft/provider/IItemStackProvider.java renamed to loader-common/src/main/java/org/cyclops/structuredcrafting/craft/provider/IItemStackProvider.java

File renamed without changes.

loader-neoforge/src/main/java/org/cyclops/structuredcrafting/craft/provider/IItemStackProviderRegistry.java renamed to loader-common/src/main/java/org/cyclops/structuredcrafting/craft/provider/IItemStackProviderRegistry.java

File renamed without changes.

0 commit comments

Comments
 (0)