Skip to content

Commit 7d9ba67

Browse files
committed
Make crafting directional
This simplifies the usage a lot, otherwise you had to take into account all six sides at all times.
1 parent 32d3b98 commit 7d9ba67

8 files changed

Lines changed: 37 additions & 25 deletions

File tree

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

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

3-
import net.minecraft.block.Block;
3+
import com.google.common.collect.Lists;
4+
import com.google.common.collect.Sets;
45
import net.minecraft.block.material.Material;
6+
import net.minecraft.block.properties.PropertyDirection;
57
import net.minecraft.block.state.IBlockState;
8+
import net.minecraft.entity.EntityLivingBase;
69
import net.minecraft.util.BlockPos;
10+
import net.minecraft.util.EnumFacing;
11+
import net.minecraft.util.MathHelper;
712
import net.minecraft.world.World;
8-
import org.cyclops.cyclopscore.config.configurable.ConfigurableBlock;
13+
import org.cyclops.cyclopscore.block.property.BlockProperty;
914
import org.cyclops.cyclopscore.config.configurable.ConfigurableBlockContainer;
1015
import org.cyclops.cyclopscore.config.extendedconfig.ExtendedConfig;
11-
import org.cyclops.structurecrafting.craft.WorldCraftingMatrix;
1216
import org.cyclops.structurecrafting.tileentity.TileStructuredCrafter;
1317

1418
/**
@@ -17,6 +21,9 @@
1721
*/
1822
public class BlockStructuredCrafter extends ConfigurableBlockContainer {
1923

24+
@BlockProperty
25+
public static final PropertyDirection FACING = PropertyDirection.create("facing", Lists.newArrayList(EnumFacing.VALUES));
26+
2027
private static BlockStructuredCrafter _instance = null;
2128

2229
/**
@@ -38,4 +45,10 @@ public BlockStructuredCrafter(ExtendedConfig eConfig) {
3845
setStepSound(soundTypeStone);
3946
}
4047

48+
@Override
49+
public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ,
50+
int meta, EntityLivingBase placer) {
51+
return this.getDefaultState().withProperty(FACING, facing.getOpposite());
52+
}
53+
4154
}

src/main/java/org/cyclops/structurecrafting/craft/WorldCraftingMatrix.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import net.minecraft.world.World;
1010
import org.apache.commons.lang3.tuple.Pair;
1111
import org.cyclops.structurecrafting.StructuredCrafting;
12+
import org.cyclops.structurecrafting.block.BlockStructuredCrafter;
1213
import org.cyclops.structurecrafting.craft.provider.IItemStackProvider;
1314
import org.cyclops.structurecrafting.craft.provider.IItemStackProviderRegistry;
1415

@@ -40,7 +41,7 @@ public WorldCraftingMatrix(World world, BlockPos centerPos, EnumFacing.Axis axis
4041

4142
protected BlockPos addInAxis(BlockPos pos, EnumFacing.Axis axis, int i, int j) {
4243
if(axis == EnumFacing.Axis.X) {
43-
return pos.add(0, i, j);
44+
return pos.add(0, j, i);
4445
} else if(axis == EnumFacing.Axis.Y) {
4546
return pos.add(i, 0, j);
4647
} else if(axis == EnumFacing.Axis.Z) {
@@ -86,7 +87,6 @@ public boolean craft() {
8687

8788
BlockPos[] positions = new BlockPos[9];
8889
IItemStackProvider[] providers = new IItemStackProvider[9];
89-
9090
// Set crafting grid
9191
for(int i = -1; i < 2; i++) {
9292
for(int j = -1; j < 2; j++) {
@@ -123,14 +123,10 @@ public boolean craft() {
123123
return false;
124124
}
125125

126-
public static WorldCraftingMatrix[] deriveMatrices(World world, BlockPos centerPos) {
127-
final WorldCraftingMatrix[] matrices = new WorldCraftingMatrix[6]; // Test for all faces of the center position.
128-
for(int i = 0; i < EnumFacing.values().length; i++) {
129-
EnumFacing side = EnumFacing.values()[i];
130-
matrices[i] = new WorldCraftingMatrix(world, centerPos.offset(side), side.getAxis(),
131-
centerPos.offset(side.getOpposite()), side.getOpposite());
132-
}
133-
return matrices;
126+
public static WorldCraftingMatrix deriveMatrix(World world, BlockPos centerPos) {
127+
EnumFacing side = ((EnumFacing) world.getBlockState(centerPos).getValue(BlockStructuredCrafter.FACING)).getOpposite();
128+
return new WorldCraftingMatrix(world, centerPos.offset(side), side.getAxis(),
129+
centerPos.offset(side.getOpposite()), side.getOpposite());
134130
}
135131

136132
}

src/main/java/org/cyclops/structurecrafting/tileentity/TileStructuredCrafter.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ public TileStructuredCrafter() {
2121
protected void updateTileEntity() {
2222
tickOffset = (tickOffset + 1) % SPEED;
2323
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-
}
24+
WorldCraftingMatrix matrix = WorldCraftingMatrix.deriveMatrix(worldObj, pos);
25+
matrix.craft();
2826
}
2927
}
3028

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
{
22
"variants": {
3-
"normal": { "model": "structuredcrafting:structured_crafter" },
4-
"inventory": { "model": "structuredcrafting:structured_crafter" }
3+
"facing=south": { "model": "structuredcrafting:structured_crafter", "x": 90 },
4+
"facing=west" : { "model": "structuredcrafting:structured_crafter", "x": 90, "y": 90 },
5+
"facing=north": { "model": "structuredcrafting:structured_crafter", "x": 90, "y": 180 },
6+
"facing=east" : { "model": "structuredcrafting:structured_crafter", "x": 90, "y": 270 },
7+
"facing=up" : { "model": "structuredcrafting:structured_crafter", "x": 180 },
8+
"facing=down" : { "model": "structuredcrafting:structured_crafter" },
9+
"inventory" : { "model": "structuredcrafting:structured_crafter" }
510
}
611
}

src/main/resources/assets/structuredcrafting/models/block/structured_crafter.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
"parent": "block/cube_all",
33
"textures": {
44
"particle": "structuredcrafting:blocks/structuredCrafter_front",
5-
"down": "blocks/cobblestone",
6-
"up": "structuredcrafting:blocks/structuredCrafter_top",
7-
"north": "structuredcrafting:blocks/structuredCrafter_front",
8-
"east": "structuredcrafting:blocks/structuredCrafter_side",
9-
"south": "structuredcrafting:blocks/structuredCrafter_side",
10-
"west": "structuredcrafting:blocks/structuredCrafter_front"
5+
"down" : "structuredcrafting:blocks/structuredCrafter_down",
6+
"up" : "structuredcrafting:blocks/structuredCrafter_top",
7+
"north" : "structuredcrafting:blocks/structuredCrafter_front",
8+
"east" : "structuredcrafting:blocks/structuredCrafter_side",
9+
"south" : "structuredcrafting:blocks/structuredCrafter_side",
10+
"west" : "structuredcrafting:blocks/structuredCrafter_front"
1111
}
1212
}
3.49 KB
Loading
16 Bytes
Loading
19 Bytes
Loading

0 commit comments

Comments
 (0)