Skip to content

Commit e20f621

Browse files
committed
Recipes package now at 90 percent, only missing main recipe class
1 parent 1bbe52a commit e20f621

33 files changed

+605
-502
lines changed

build.gradle

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,12 @@ repositories {
200200
}
201201

202202
maven {
203-
name 'MCUnitTests'
204-
url 'https://jitpack.io'
203+
name "MCJUnitLib - CM Github"
204+
url = uri("https://maven.pkg.github.com/CompactMods/mcjunitlib")
205+
credentials {
206+
username = project.findProperty("gpr.user") ?: System.getenv("GITHUB_ACTOR")
207+
password = project.findProperty("gpr.key") ?: System.getenv("GITHUB_TOKEN")
208+
}
205209
}
206210
}
207211

@@ -213,7 +217,7 @@ dependencies {
213217
// The userdev artifact is a special name and will get all sorts of transformations applied to it.
214218
minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"
215219

216-
testImplementation fg.deobf("com.github.CompactMods:mcjunitlib:${mcunittest_version}")
220+
testImplementation fg.deobf("com.github.alcatrazEscapee:mcjunitlib:${mcunittest_version}")
217221

218222
// Deobfuscate each dev mod for runtime
219223
dev_mods.each {

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ mod_version=1.0.0-beta.5
1212
# Dependencies and Libs
1313
jei_version=7.7.1.110
1414
top_version=1.16-3.1.4-22
15-
mcunittest_version=1.4.4-1.16.5
15+
mcunittest_version=1.4.6-1.16.5
1616

1717
# Curseforge
1818
cf_project=429735

src/api/java/dev/compactmods/crafting/api/field/MiniaturizationFieldSize.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,8 @@ public AxisAlignedBB getBoundsAtPosition(BlockPos center) {
139139
public String getSerializedName() {
140140
return name;
141141
}
142+
143+
public BlockPos getCenterOffset() {
144+
return new BlockPos(getBoundsAtOrigin().getCenter());
145+
}
142146
}

src/api/java/dev/compactmods/crafting/api/recipe/layers/IRecipeLayerBlocks.java renamed to src/api/java/dev/compactmods/crafting/api/recipe/layers/IRecipeBlocks.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
import net.minecraft.block.BlockState;
77
import net.minecraft.util.math.AxisAlignedBB;
88
import net.minecraft.util.math.BlockPos;
9+
import net.minecraft.util.math.vector.Vector3i;
910

10-
public interface IRecipeLayerBlocks {
11+
public interface IRecipeBlocks {
1112

1213
Optional<String> getComponentAtPosition(BlockPos relative);
1314

@@ -33,11 +34,31 @@ public interface IRecipeLayerBlocks {
3334

3435
Map<String, Integer> getKnownComponentTotals();
3536

36-
AxisAlignedBB getBounds();
37+
AxisAlignedBB getSourceBounds();
3738

3839
boolean allIdentified();
3940

4041
Stream<BlockPos> getUnmappedPositions();
4142

4243
Stream<BlockPos> getPositionsForComponent(String component);
44+
45+
AxisAlignedBB getFilledBounds();
46+
47+
IRecipeBlocks slice(AxisAlignedBB bounds);
48+
49+
IRecipeBlocks offset(Vector3i amount);
50+
51+
default IRecipeBlocks below(int offset) {
52+
return offset(new Vector3i(0, -offset, 0));
53+
}
54+
55+
default IRecipeBlocks above(int offset) {
56+
return offset(new Vector3i(0, offset, 0));
57+
}
58+
59+
default IRecipeBlocks normalize() {
60+
AxisAlignedBB sb = getSourceBounds();
61+
BlockPos offset = new BlockPos(-sb.minX, -sb.minY, -sb.minZ);
62+
return offset(offset);
63+
}
4364
}

src/api/java/dev/compactmods/crafting/api/recipe/layers/IRecipeLayer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ default boolean requiresAllBlocksIdentified() {
2727
return true;
2828
}
2929

30-
default boolean matches(IRecipeComponents components, IRecipeLayerBlocks blocks) {
30+
default boolean matches(IRecipeComponents components, IRecipeBlocks blocks) {
3131
return !requiresAllBlocksIdentified() || blocks.allIdentified();
3232
}
3333

src/main/java/dev/compactmods/crafting/field/MiniaturizationField.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import dev.compactmods.crafting.network.NetworkHandler;
1212
import dev.compactmods.crafting.projector.block.FieldProjectorBlock;
1313
import dev.compactmods.crafting.recipes.MiniaturizationRecipe;
14+
import dev.compactmods.crafting.recipes.blocks.RecipeBlocks;
1415
import dev.compactmods.crafting.server.ServerConfig;
1516
import dev.compactmods.crafting.util.BlockSpaceUtil;
1617
import dev.compactmods.crafting.api.EnumCraftingState;
@@ -113,7 +114,7 @@ private void getRecipeFromId() {
113114

114115
r.ifPresent(rec -> {
115116
this.currentRecipe = (MiniaturizationRecipe) rec;
116-
if(craftingState == EnumCraftingState.NOT_MATCHED)
117+
if (craftingState == EnumCraftingState.NOT_MATCHED)
117118
setCraftingState(EnumCraftingState.MATCHED);
118119

119120
this.listeners.forEach(li -> li.ifPresent(l -> {
@@ -301,7 +302,8 @@ public void doRecipeScan() {
301302
// Begin recipe dry run - loop, check bottom layer for matches
302303
MiniaturizationRecipe matchedRecipe = null;
303304
for (MiniaturizationRecipe recipe : recipes) {
304-
boolean recipeMatches = recipe.matches(level, this);
305+
RecipeBlocks blocks = RecipeBlocks.create(level, recipe.getComponents(), getFilledBounds());
306+
boolean recipeMatches = recipe.matches(blocks);
305307
if (!recipeMatches)
306308
continue;
307309

@@ -320,7 +322,7 @@ private void setRecipe(MiniaturizationRecipe recipe) {
320322
setCraftingState(recipe != null ? EnumCraftingState.MATCHED : EnumCraftingState.NOT_MATCHED);
321323

322324
// Send tracking client updates
323-
if(!level.isClientSide) {
325+
if (!level.isClientSide) {
324326
NetworkHandler.MAIN_CHANNEL.send(
325327
PacketDistributor.TRACKING_CHUNK.with(() -> level.getChunkAt(center)),
326328
new FieldRecipeChangedPacket(this)
@@ -331,7 +333,7 @@ private void setRecipe(MiniaturizationRecipe recipe) {
331333
listeners.forEach(l -> l.ifPresent(fl -> {
332334
fl.onRecipeChanged(this, recipe);
333335

334-
if(craftingState == EnumCraftingState.MATCHED)
336+
if (craftingState == EnumCraftingState.MATCHED)
335337
fl.onRecipeMatched(this, recipe);
336338
}));
337339
}

src/main/java/dev/compactmods/crafting/recipes/MiniaturizationRecipe.java

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@
1111
import dev.compactmods.crafting.api.components.IRecipeComponents;
1212
import dev.compactmods.crafting.api.field.MiniaturizationFieldSize;
1313
import dev.compactmods.crafting.api.recipe.IMiniaturizationRecipe;
14+
import dev.compactmods.crafting.api.recipe.layers.IRecipeBlocks;
1415
import dev.compactmods.crafting.api.recipe.layers.IRecipeLayer;
15-
import dev.compactmods.crafting.api.recipe.layers.IRecipeLayerBlocks;
1616
import dev.compactmods.crafting.api.recipe.layers.dim.IDynamicSizedRecipeLayer;
1717
import dev.compactmods.crafting.api.recipe.layers.dim.IFixedSizedRecipeLayer;
18-
import dev.compactmods.crafting.field.MiniaturizationField;
19-
import dev.compactmods.crafting.recipes.blocks.RecipeLayerBlocks;
2018
import dev.compactmods.crafting.recipes.components.EmptyBlockComponent;
2119
import dev.compactmods.crafting.recipes.components.MiniaturizationRecipeComponents;
2220
import dev.compactmods.crafting.recipes.exceptions.MiniaturizationRecipeException;
@@ -32,7 +30,6 @@
3230
import net.minecraft.util.math.AxisAlignedBB;
3331
import net.minecraft.util.math.BlockPos;
3432
import net.minecraft.util.math.vector.Vector3d;
35-
import net.minecraft.world.IBlockReader;
3633

3734
public class MiniaturizationRecipe extends RecipeBase implements IMiniaturizationRecipe {
3835

@@ -163,10 +160,11 @@ void recalculateDimensions() {
163160

164161
private void updateFluidLayerDimensions() {
165162
// Update all the dynamic recipe layers
163+
final AxisAlignedBB footprint = BlockSpaceUtil.getLayerBounds(dimensions, 0);
166164
this.layers.values()
167165
.stream()
168166
.filter(l -> l instanceof IDynamicSizedRecipeLayer)
169-
.forEach(dl -> ((IDynamicSizedRecipeLayer) dl).setRecipeDimensions(dimensions));
167+
.forEach(dl -> ((IDynamicSizedRecipeLayer) dl).setRecipeDimensions(footprint));
170168
}
171169

172170
/**
@@ -183,15 +181,15 @@ public boolean fitsInFieldSize(MiniaturizationFieldSize fieldSize) {
183181
return fits;
184182
}
185183

186-
public boolean matches(IBlockReader world, MiniaturizationField field) {
187-
if (!fitsInFieldSize(field.getFieldSize())) {
184+
public boolean matches(IRecipeBlocks blocks) {
185+
if (!BlockSpaceUtil.boundsFitsInside(blocks.getFilledBounds(), dimensions)) {
188186
if (ServerConfig.RECIPE_MATCHING.get())
189187
CompactCrafting.LOGGER.debug("Failing recipe {} for being too large to fit in field.", this.id);
190188
return false;
191189
}
192190

193191
// We know that the recipe will at least fit inside the current projection field
194-
AxisAlignedBB filledBounds = field.getFilledBounds();
192+
AxisAlignedBB filledBounds = blocks.getFilledBounds();
195193

196194
Rotation[] validRotations = new Rotation[]{
197195
Rotation.NONE,
@@ -201,7 +199,7 @@ public boolean matches(IBlockReader world, MiniaturizationField field) {
201199
};
202200

203201
for (Rotation rot : validRotations) {
204-
boolean matchesRot = checkRotation(world, rot, filledBounds);
202+
boolean matchesRot = checkRotation(blocks, rot);
205203
if (matchesRot)
206204
return true;
207205
}
@@ -211,7 +209,7 @@ public boolean matches(IBlockReader world, MiniaturizationField field) {
211209
return false;
212210
}
213211

214-
private boolean checkRotation(IBlockReader world, Rotation rot, AxisAlignedBB filledBounds) {
212+
private boolean checkRotation(IRecipeBlocks blocks, Rotation rot) {
215213
// Check the recipe layer by layer
216214

217215
int maxY = (int) dimensions.getYsize();
@@ -223,19 +221,18 @@ private boolean checkRotation(IBlockReader world, Rotation rot, AxisAlignedBB fi
223221
return false;
224222
}
225223

226-
AxisAlignedBB bounds = BlockSpaceUtil.getLayerBounds(filledBounds, offset);
227-
IRecipeLayerBlocks blocks = RecipeLayerBlocks.create(world, this.components, bounds);
224+
IRecipeBlocks layerBlocks = blocks.slice(BlockSpaceUtil.getLayerBounds(blocks.getFilledBounds(), offset)).below(offset);
228225

229226
if (rot != Rotation.NONE)
230-
blocks = RecipeLayerUtil.rotate(blocks, rot);
227+
layerBlocks = RecipeLayerUtil.rotate(layerBlocks, rot);
231228

232229
IRecipeLayer targetLayer = layer.get();
233230

234231
// If the layer spec requires all components to be known (by default) then check early
235-
if (targetLayer.requiresAllBlocksIdentified() && !blocks.allIdentified())
232+
if (targetLayer.requiresAllBlocksIdentified() && !layerBlocks.allIdentified())
236233
return false;
237234

238-
boolean layerMatched = targetLayer.matches(components, blocks);
235+
boolean layerMatched = targetLayer.matches(components, layerBlocks);
239236

240237
if (!layerMatched) {
241238
if (ServerConfig.RECIPE_MATCHING.get())

0 commit comments

Comments
 (0)