Skip to content

Commit 9741d5b

Browse files
committed
Update to Minecraft 1.18
1 parent 4325468 commit 9741d5b

19 files changed

Lines changed: 228 additions & 205 deletions

build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ group = "org.cyclops.structuredcrafting"
3737
archivesBaseName = "StructuredCrafting"
3838

3939
// Set Java details
40-
sourceCompatibility = 1.8
41-
targetCompatibility = 1.8
40+
java.toolchain.languageVersion = JavaLanguageVersion.of(17)
41+
compileJava.options.compilerArgs << "-Xmaxerrs" << "9999"
42+
println('Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + '(' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch'))
4243

4344
// Load secrets
4445
def getSecrets() {

gradle.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
mod_version=0.2.2
2-
minecraft_version=1.16.5
3-
forge_version=36.0.14
4-
cyclopscore_version=1.11.6-64
2+
minecraft_version=1.18.1
3+
forge_version=39.0.0
4+
cyclopscore_version=1.12.1-100
55
release_type=release
66
fingerprint=bd0353b3e8a2810d60dd584e256e364bc3bedd44
77

Submodule api updated 36 files
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package org.cyclops.structuredcrafting;
22

33
import net.minecraftforge.common.capabilities.Capability;
4-
import net.minecraftforge.common.capabilities.CapabilityInject;
4+
import net.minecraftforge.common.capabilities.CapabilityManager;
5+
import net.minecraftforge.common.capabilities.CapabilityToken;
56
import org.cyclops.commoncapabilities.api.capability.work.IWorker;
67

78
/**
89
* Used capabilities for this mod.
910
* @author rubensworks
1011
*/
1112
public class Capabilities {
12-
@CapabilityInject(IWorker.class)
13-
public static Capability<IWorker> WORKER = null;
13+
public static Capability<IWorker> WORKER = CapabilityManager.get(new CapabilityToken<>(){});
1414
}

src/main/java/org/cyclops/structuredcrafting/RegistryEntries.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package org.cyclops.structuredcrafting;
22

3-
import net.minecraft.block.Block;
4-
import net.minecraft.item.Item;
5-
import net.minecraft.tileentity.TileEntityType;
3+
import net.minecraft.world.item.Item;
4+
import net.minecraft.world.level.block.Block;
5+
import net.minecraft.world.level.block.entity.BlockEntityType;
66
import net.minecraftforge.registries.ObjectHolder;
7-
import org.cyclops.structuredcrafting.tileentity.TileStructuredCrafter;
7+
import org.cyclops.structuredcrafting.blockentity.BlockEntityStructuredCrafter;
88

99
/**
1010
* Referenced registry entries.
@@ -19,6 +19,6 @@ public class RegistryEntries {
1919
public static final Block BLOCK_STRUCTURED_CRAFTER = null;
2020

2121
@ObjectHolder("structuredcrafting:structured_crafter")
22-
public static final TileEntityType<TileStructuredCrafter> TILE_STRUCTURED_CRAFTER = null;
22+
public static final BlockEntityType<BlockEntityStructuredCrafter> BLOCK_ENTITY_STRUCTURED_CRAFTER = null;
2323

2424
}

src/main/java/org/cyclops/structuredcrafting/StructuredCrafting.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.cyclops.structuredcrafting;
22

3-
import net.minecraft.item.ItemGroup;
3+
import net.minecraft.world.item.CreativeModeTab;
44
import net.minecraftforge.fml.common.Mod;
55
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
66
import org.apache.logging.log4j.Level;
@@ -11,13 +11,13 @@
1111
import org.cyclops.cyclopscore.proxy.IClientProxy;
1212
import org.cyclops.cyclopscore.proxy.ICommonProxy;
1313
import org.cyclops.structuredcrafting.block.BlockStructuredCrafterConfig;
14+
import org.cyclops.structuredcrafting.blockentity.BlockEntityStructuredCrafter;
15+
import org.cyclops.structuredcrafting.blockentity.TileStructuredCrafterConfig;
1416
import org.cyclops.structuredcrafting.craft.provider.IItemStackProviderRegistry;
1517
import org.cyclops.structuredcrafting.craft.provider.InventoryItemStackProvider;
1618
import org.cyclops.structuredcrafting.craft.provider.ItemStackProviderRegistry;
1719
import org.cyclops.structuredcrafting.craft.provider.WorldItemStackProvider;
1820
import org.cyclops.structuredcrafting.modcompat.capabilities.WorkerStructuredCrafterTileCompat;
19-
import org.cyclops.structuredcrafting.tileentity.TileStructuredCrafter;
20-
import org.cyclops.structuredcrafting.tileentity.TileStructuredCrafterConfig;
2121

2222
/**
2323
* The main mod class of StructuredCrafting.
@@ -41,7 +41,7 @@ protected void loadModCompats(ModCompatLoader modCompatLoader) {
4141
super.loadModCompats(modCompatLoader);
4242

4343
// Capabilities
44-
getCapabilityConstructorRegistry().registerTile(TileStructuredCrafter.class, new WorkerStructuredCrafterTileCompat());
44+
getCapabilityConstructorRegistry().registerTile(BlockEntityStructuredCrafter.class, new WorkerStructuredCrafterTileCompat());
4545
}
4646

4747
@Override
@@ -66,7 +66,7 @@ protected ICommonProxy constructCommonProxy() {
6666
}
6767

6868
@Override
69-
protected ItemGroup constructDefaultItemGroup() {
69+
protected CreativeModeTab constructDefaultCreativeModeTab() {
7070
return new ItemGroupMod(this, () -> RegistryEntries.ITEM_STRUCTURED_CRAFTER);
7171
}
7272

src/main/java/org/cyclops/structuredcrafting/block/BlockStructuredCrafter.java

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,69 @@
11
package org.cyclops.structuredcrafting.block;
22

3-
import net.minecraft.block.Block;
4-
import net.minecraft.block.BlockState;
5-
import net.minecraft.entity.player.PlayerEntity;
6-
import net.minecraft.item.BlockItemUseContext;
7-
import net.minecraft.item.ItemStack;
8-
import net.minecraft.item.Items;
9-
import net.minecraft.state.DirectionProperty;
10-
import net.minecraft.state.StateContainer;
11-
import net.minecraft.state.properties.BlockStateProperties;
12-
import net.minecraft.util.ActionResultType;
13-
import net.minecraft.util.Direction;
14-
import net.minecraft.util.Hand;
15-
import net.minecraft.util.math.BlockPos;
16-
import net.minecraft.util.math.BlockRayTraceResult;
17-
import net.minecraft.world.World;
18-
import org.cyclops.cyclopscore.block.BlockTile;
19-
import org.cyclops.structuredcrafting.tileentity.TileStructuredCrafter;
3+
import net.minecraft.core.BlockPos;
4+
import net.minecraft.core.Direction;
5+
import net.minecraft.world.InteractionHand;
6+
import net.minecraft.world.InteractionResult;
7+
import net.minecraft.world.entity.player.Player;
8+
import net.minecraft.world.item.ItemStack;
9+
import net.minecraft.world.item.Items;
10+
import net.minecraft.world.item.context.BlockPlaceContext;
11+
import net.minecraft.world.level.Level;
12+
import net.minecraft.world.level.block.Block;
13+
import net.minecraft.world.level.block.entity.BlockEntity;
14+
import net.minecraft.world.level.block.entity.BlockEntityTicker;
15+
import net.minecraft.world.level.block.entity.BlockEntityType;
16+
import net.minecraft.world.level.block.state.BlockState;
17+
import net.minecraft.world.level.block.state.StateDefinition;
18+
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
19+
import net.minecraft.world.level.block.state.properties.DirectionProperty;
20+
import net.minecraft.world.phys.BlockHitResult;
21+
import org.cyclops.cyclopscore.block.BlockWithEntity;
22+
import org.cyclops.structuredcrafting.RegistryEntries;
23+
import org.cyclops.structuredcrafting.blockentity.BlockEntityStructuredCrafter;
2024

2125
import javax.annotation.Nullable;
2226

2327
/**
2428
* This block will detect neighbour block updates and will try to craft a new block/item from them.
2529
* @author rubensworks
2630
*/
27-
public class BlockStructuredCrafter extends BlockTile {
31+
public class BlockStructuredCrafter extends BlockWithEntity {
2832

2933
public static final DirectionProperty FACING = BlockStateProperties.FACING;
3034

3135
public BlockStructuredCrafter(Block.Properties properties) {
32-
super(properties, TileStructuredCrafter::new);
36+
super(properties, BlockEntityStructuredCrafter::new);
3337

3438
this.registerDefaultState(this.stateDefinition.any()
3539
.setValue(FACING, Direction.DOWN));
3640
}
3741

3842
@Override
39-
protected void createBlockStateDefinition(StateContainer.Builder<Block, BlockState> builder) {
43+
@Nullable
44+
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState blockState, BlockEntityType<T> blockEntityType) {
45+
return level.isClientSide ? null : createTickerHelper(blockEntityType, RegistryEntries.BLOCK_ENTITY_STRUCTURED_CRAFTER, new BlockEntityStructuredCrafter.Ticker());
46+
}
47+
48+
@Override
49+
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
4050
builder.add(FACING);
4151
}
4252

4353
@Nullable
4454
@Override
45-
public BlockState getStateForPlacement(BlockItemUseContext context) {
55+
public BlockState getStateForPlacement(BlockPlaceContext context) {
4656
return this.defaultBlockState()
4757
.setValue(FACING, context.getClickedFace().getOpposite());
4858
}
4959

5060
@Override
51-
public ActionResultType use(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand hand,
52-
BlockRayTraceResult hit) {
61+
public InteractionResult use(BlockState state, Level worldIn, BlockPos pos, Player player, InteractionHand hand,
62+
BlockHitResult hit) {
5363
ItemStack heldItem = player.getItemInHand(hand);
5464
if(player != null && !heldItem.isEmpty() && heldItem.getItem() == Items.STICK) {
5565
worldIn.setBlockAndUpdate(pos, state.setValue(FACING, hit.getDirection().getOpposite()));
56-
return ActionResultType.SUCCESS;
66+
return InteractionResult.SUCCESS;
5767
}
5868
return super.use(state, worldIn, pos, player, hand, hit);
5969
}

src/main/java/org/cyclops/structuredcrafting/block/BlockStructuredCrafterConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.cyclops.structuredcrafting.block;
22

3-
import net.minecraft.block.Block;
4-
import net.minecraft.block.material.Material;
3+
import net.minecraft.world.level.block.Block;
4+
import net.minecraft.world.level.material.Material;
55
import net.minecraftforge.fml.config.ModConfig;
66
import org.cyclops.cyclopscore.config.ConfigurableProperty;
77
import org.cyclops.cyclopscore.config.extendedconfig.BlockConfig;
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package org.cyclops.structuredcrafting.blockentity;
2+
3+
import net.minecraft.core.BlockPos;
4+
import net.minecraft.world.level.Level;
5+
import net.minecraft.world.level.block.state.BlockState;
6+
import org.cyclops.cyclopscore.blockentity.BlockEntityTickerDelayed;
7+
import org.cyclops.cyclopscore.blockentity.CyclopsBlockEntity;
8+
import org.cyclops.structuredcrafting.RegistryEntries;
9+
import org.cyclops.structuredcrafting.craft.WorldCraftingMatrix;
10+
11+
/**
12+
* A ticking block entity for the structured crafter.
13+
* @author rubensworks
14+
*/
15+
public class BlockEntityStructuredCrafter extends CyclopsBlockEntity {
16+
17+
private static final int SPEED = 20;
18+
19+
protected WorldCraftingMatrix matrix = null;
20+
21+
private int tickOffset;
22+
23+
public BlockEntityStructuredCrafter(BlockPos blockPos, BlockState blockState) {
24+
super(RegistryEntries.BLOCK_ENTITY_STRUCTURED_CRAFTER, blockPos, blockState);
25+
tickOffset = (int) (Math.random() * (float) SPEED);
26+
}
27+
28+
public WorldCraftingMatrix getMatrix() {
29+
if(matrix == null) {
30+
matrix = WorldCraftingMatrix.deriveMatrix(level, worldPosition);
31+
}
32+
return matrix;
33+
}
34+
35+
public void setMatrix(WorldCraftingMatrix matrix) {
36+
this.matrix = matrix;
37+
}
38+
39+
public int getTickOffset() {
40+
return tickOffset;
41+
}
42+
43+
public void setTickOffset(int tickOffset) {
44+
this.tickOffset = tickOffset;
45+
}
46+
47+
public static class Ticker extends BlockEntityTickerDelayed<BlockEntityStructuredCrafter> {
48+
@Override
49+
protected void update(Level level, BlockPos pos, BlockState blockState, BlockEntityStructuredCrafter blockEntity) {
50+
super.update(level, pos, blockState, blockEntity);
51+
52+
blockEntity.setTickOffset((blockEntity.getTickOffset() + 1) % SPEED);
53+
if(!level.isClientSide && blockEntity.getTickOffset() == 0) {
54+
if(level.hasNeighborSignal(pos)) {
55+
blockEntity.getMatrix().craft(false);
56+
} else {
57+
blockEntity.setMatrix(null);
58+
}
59+
}
60+
}
61+
}
62+
63+
}

src/main/java/org/cyclops/structuredcrafting/tileentity/TileStructuredCrafterConfig.java renamed to src/main/java/org/cyclops/structuredcrafting/blockentity/TileStructuredCrafterConfig.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
package org.cyclops.structuredcrafting.tileentity;
1+
package org.cyclops.structuredcrafting.blockentity;
22

33
import com.google.common.collect.Sets;
4-
import net.minecraft.tileentity.TileEntityType;
5-
import org.cyclops.cyclopscore.config.extendedconfig.TileEntityConfig;
4+
import net.minecraft.world.level.block.entity.BlockEntityType;
5+
import org.cyclops.cyclopscore.config.extendedconfig.BlockEntityConfig;
66
import org.cyclops.structuredcrafting.RegistryEntries;
77
import org.cyclops.structuredcrafting.StructuredCrafting;
88

99
/**
10-
* Config for the {@link TileStructuredCrafter}.
10+
* Config for the {@link BlockEntityStructuredCrafter}.
1111
* @author rubensworks
1212
*
1313
*/
14-
public class TileStructuredCrafterConfig extends TileEntityConfig<TileStructuredCrafter> {
14+
public class TileStructuredCrafterConfig extends BlockEntityConfig<BlockEntityStructuredCrafter> {
1515

1616
public TileStructuredCrafterConfig() {
1717
super(
1818
StructuredCrafting._instance,
1919
"structured_crafter",
20-
(eConfig) -> new TileEntityType<>(TileStructuredCrafter::new,
20+
(eConfig) -> new BlockEntityType<>(BlockEntityStructuredCrafter::new,
2121
Sets.newHashSet(RegistryEntries.BLOCK_STRUCTURED_CRAFTER), null)
2222
);
2323
}

0 commit comments

Comments
 (0)