Skip to content

Commit 32d3b98

Browse files
committed
Tick using a tile entity
1 parent 9be8d21 commit 32d3b98

3 files changed

Lines changed: 39 additions & 16 deletions

File tree

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

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@
66
import net.minecraft.util.BlockPos;
77
import net.minecraft.world.World;
88
import org.cyclops.cyclopscore.config.configurable.ConfigurableBlock;
9+
import org.cyclops.cyclopscore.config.configurable.ConfigurableBlockContainer;
910
import org.cyclops.cyclopscore.config.extendedconfig.ExtendedConfig;
1011
import org.cyclops.structurecrafting.craft.WorldCraftingMatrix;
12+
import org.cyclops.structurecrafting.tileentity.TileStructuredCrafter;
1113

1214
/**
1315
* This block will detect neighbour block updates and will try to craft a new block/item from them.
1416
* @author rubensworks
1517
*/
16-
public class BlockStructuredCrafter extends ConfigurableBlock {
18+
public class BlockStructuredCrafter extends ConfigurableBlockContainer {
1719

1820
private static BlockStructuredCrafter _instance = null;
1921

@@ -30,20 +32,10 @@ public static BlockStructuredCrafter getInstance() {
3032
* @param eConfig Config for this block.
3133
*/
3234
public BlockStructuredCrafter(ExtendedConfig eConfig) {
33-
super(eConfig, Material.iron);
35+
super(eConfig, Material.ground, TileStructuredCrafter.class);
3436

35-
setHardness(3.0F);
36-
setStepSound(soundTypeMetal);
37-
}
38-
39-
@Override
40-
public void onNeighborBlockChange(World world, BlockPos pos, IBlockState state, Block neighborBlock) {
41-
if(!world.isRemote && !world.isBlockPowered(pos)) {
42-
WorldCraftingMatrix[] matrices = WorldCraftingMatrix.deriveMatrices(world, pos);
43-
for (WorldCraftingMatrix matrix : matrices) {
44-
if (matrix.craft()) break;
45-
}
46-
}
37+
setHardness(2.0F);
38+
setStepSound(soundTypeStone);
4739
}
4840

4941
}

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

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

3-
import org.cyclops.cyclopscore.config.extendedconfig.BlockConfig;
3+
import org.cyclops.cyclopscore.config.extendedconfig.BlockContainerConfig;
44
import org.cyclops.structurecrafting.StructuredCrafting;
55

66
/**
77
* Config for {@link BlockStructuredCrafter}.
88
* @author rubensworks
99
*/
10-
public class BlockStructuredCrafterConfig extends BlockConfig {
10+
public class BlockStructuredCrafterConfig extends BlockContainerConfig {
1111

1212
/**
1313
* The unique instance.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.cyclops.structurecrafting.tileentity;
2+
3+
import org.cyclops.cyclopscore.tileentity.TickingCyclopsTileEntity;
4+
import org.cyclops.structurecrafting.craft.WorldCraftingMatrix;
5+
6+
/**
7+
* A ticking tile entity for the structured crafter.
8+
* @author rubensworks
9+
*/
10+
public class TileStructuredCrafter extends TickingCyclopsTileEntity {
11+
12+
private static final int SPEED = 20;
13+
14+
private int tickOffset;
15+
16+
public TileStructuredCrafter() {
17+
tickOffset = (int) (Math.random() * (float) SPEED);
18+
}
19+
20+
@Override
21+
protected void updateTileEntity() {
22+
tickOffset = (tickOffset + 1) % SPEED;
23+
if(!worldObj.isRemote && tickOffset == 0 && worldObj.isBlockPowered(getPos())) {
24+
WorldCraftingMatrix[] matrices = WorldCraftingMatrix.deriveMatrices(worldObj, pos);
25+
for (WorldCraftingMatrix matrix : matrices) {
26+
if (matrix.craft()) break;
27+
}
28+
}
29+
}
30+
31+
}

0 commit comments

Comments
 (0)