Bad impression

- Mechanical Press can no longer create sheets in bulk, unless configured to
- Fixed Mechanical Press missing items passing on a belt while retracting
This commit is contained in:
simibubi 2021-04-11 15:24:58 +02:00
parent d249318b80
commit e92e9a7139
3 changed files with 70 additions and 22 deletions

View File

@ -7,18 +7,25 @@ import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import com.simibubi.create.Create;
import com.simibubi.create.content.contraptions.components.press.MechanicalPressTileEntity.Mode;
import com.simibubi.create.content.contraptions.relays.belt.BeltHelper;
import com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack;
import com.simibubi.create.content.logistics.InWorldProcessing;
import com.simibubi.create.foundation.tileEntity.behaviour.belt.BeltProcessingBehaviour.ProcessingResult;
import com.simibubi.create.foundation.tileEntity.behaviour.belt.TransportedItemStackHandlerBehaviour;
import com.simibubi.create.foundation.tileEntity.behaviour.belt.TransportedItemStackHandlerBehaviour.TransportedResult;
import net.minecraftforge.items.ItemHandlerHelper;
public class BeltPressingCallbacks {
static ProcessingResult onItemReceived(TransportedItemStack transported,
TransportedItemStackHandlerBehaviour handler, MechanicalPressTileEntity press) {
if (press.getSpeed() == 0 || press.running)
if (press.getSpeed() == 0)
return PASS;
if (press.running)
return HOLD;
if (!press.getRecipe(transported.stack)
.isPresent())
return PASS;
@ -44,25 +51,38 @@ public class BeltPressingCallbacks {
if (!recipe.isPresent())
return PASS;
List<TransportedItemStack> collect = InWorldProcessing.applyRecipeOn(transported.stack, recipe.get())
.stream()
.map(stack -> {
TransportedItemStack copy = transported.copy();
copy.stack = stack;
return copy;
}).collect(Collectors.toList());
boolean bulk = MechanicalPressTileEntity.canProcessInBulk() || transported.stack.getCount() == 1;
List<TransportedItemStack> collect = InWorldProcessing
.applyRecipeOn(bulk ? transported.stack : ItemHandlerHelper.copyStackWithSize(transported.stack, 1),
recipe.get())
.stream()
.map(stack -> {
TransportedItemStack copy = transported.copy();
boolean centered = BeltHelper.isItemUpright(stack);
copy.stack = stack;
copy.locked = true;
copy.angle = centered ? 180 : Create.random.nextInt(360);
return copy;
})
.collect(Collectors.toList());
if (bulk) {
if (collect.isEmpty())
handler.handleProcessingOnItem(transported, TransportedResult.removeItem());
else
handler.handleProcessingOnItem(transported, TransportedResult.convertTo(collect));
} else {
TransportedItemStack left = transported.copy();
left.stack.shrink(1);
if (collect.isEmpty())
handler.handleProcessingOnItem(transported, TransportedResult.convertTo(left));
else
handler.handleProcessingOnItem(transported, TransportedResult.convertToAndLeaveHeld(collect, left));
}
if (collect.isEmpty())
handler.handleProcessingOnItem(transported, TransportedItemStackHandlerBehaviour.TransportedResult.removeItem());
else
handler.handleProcessingOnItem(transported, TransportedItemStackHandlerBehaviour.TransportedResult.convertTo(collect));
/*ItemStack out = recipe.get()
.getRecipeOutput()
.copy();
List<ItemStack> multipliedOutput = ItemHelper.multipliedOutput(transported.stack, out);
if (multipliedOutput.isEmpty())
transported.stack = ItemStack.EMPTY;
transported.stack = multipliedOutput.get(0);*/
pressTe.sendData();
return HOLD;
}

View File

@ -7,6 +7,7 @@ import java.util.Optional;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllRecipeTypes;
import com.simibubi.create.AllSoundEvents;
import com.simibubi.create.Create;
import com.simibubi.create.content.contraptions.processing.BasinOperatingTileEntity;
import com.simibubi.create.content.contraptions.processing.BasinTileEntity;
import com.simibubi.create.content.logistics.InWorldProcessing;
@ -39,6 +40,7 @@ import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraftforge.common.util.Constants.NBT;
import net.minecraftforge.items.ItemHandlerHelper;
import net.minecraftforge.items.ItemStackHandler;
import net.minecraftforge.items.wrapper.RecipeWrapper;
@ -231,6 +233,7 @@ public class MechanicalPressTileEntity extends BasinOperatingTileEntity {
protected void applyPressingInWorld() {
AxisAlignedBB bb = new AxisAlignedBB(pos.down(1));
boolean bulk = canProcessInBulk();
pressedItems.clear();
if (world.isRemote)
return;
@ -240,16 +243,39 @@ public class MechanicalPressTileEntity extends BasinOperatingTileEntity {
if (!entity.isAlive() || !entity.isOnGround())
continue;
ItemEntity itemEntity = (ItemEntity) entity;
pressedItems.add(itemEntity.getItem());
ItemStack item = itemEntity.getItem();
pressedItems.add(item);
sendData();
Optional<PressingRecipe> recipe = getRecipe(itemEntity.getItem());
Optional<PressingRecipe> recipe = getRecipe(item);
if (!recipe.isPresent())
continue;
InWorldProcessing.applyRecipeOn(itemEntity, recipe.get());
if (bulk || item.getCount() == 1) {
InWorldProcessing.applyRecipeOn(itemEntity, recipe.get());
} else {
for (ItemStack result : InWorldProcessing.applyRecipeOn(ItemHandlerHelper.copyStackWithSize(item, 1),
recipe.get())) {
ItemEntity created =
new ItemEntity(world, itemEntity.getX(), itemEntity.getY(), itemEntity.getZ(), result);
created.setDefaultPickupDelay();
created.setMotion(VecHelper.offsetRandomly(Vector3d.ZERO, Create.random, .05f));
world.addEntity(created);
}
item.shrink(1);
}
AllTriggers.triggerForNearbyPlayers(AllTriggers.BONK, world, pos, 4);
entityScanCooldown = 0;
if (!bulk)
break;
}
}
public static boolean canProcessInBulk() {
return AllConfigs.SERVER.recipes.bulkPressing.get();
}
public int getRunningTickSpeed() {
if (getSpeed() == 0)
return 0;

View File

@ -2,6 +2,7 @@ package com.simibubi.create.foundation.config;
public class CRecipes extends ConfigBase {
public ConfigBool bulkPressing = b(false, "bulkPressing", Comments.bulkPressing);
public ConfigBool allowShapelessInMixer = b(true, "allowShapelessInMixer", Comments.allowShapelessInMixer);
public ConfigBool allowShapedSquareInPress = b(true, "allowShapedSquareInPress", Comments.allowShapedSquareInPress);
public ConfigBool allowRegularCraftingInCrafter =
@ -20,6 +21,7 @@ public class CRecipes extends ConfigBase {
}
private static class Comments {
static String bulkPressing = "When true, allows the Mechanical Press to process entire stacks at a time.";
static String allowShapelessInMixer =
"When true, allows any shapeless crafting recipes to be processed by a Mechanical Mixer + Basin.";
static String allowShapedSquareInPress =