Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.cyclops.commoncapabilities.api.capability.recipehandler.IRecipeDefinition;
import org.cyclops.commoncapabilities.api.ingredient.IPrototypedIngredient;
import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent;
import net.minecraft.world.item.ItemStack;
import org.cyclops.commoncapabilities.api.ingredient.storage.IIngredientComponentStorage;
import org.cyclops.integratedcrafting.api.network.ICraftingNetwork;
import org.cyclops.integrateddynamics.api.part.PrioritizedPartPos;
Expand Down Expand Up @@ -101,6 +102,14 @@ public interface ICraftingInterface {
*/
public PrioritizedPartPos getPosition();

/**
* @return An item representation of the machine that this interface is targeting,
* or an empty stack if the machine is unknown or its position is not loaded.
*/
public default ItemStack getTargetMachineItem() {
return ItemStack.EMPTY;
}

public static Comparator<ICraftingInterface> createComparator() {
return Comparator.comparing(ICraftingInterface::getPosition);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import org.cyclops.commoncapabilities.api.capability.recipehandler.IRecipeDefinition;
import org.cyclops.cyclopscore.datastructure.DimPos;
import org.cyclops.commoncapabilities.api.ingredient.IPrototypedIngredient;
import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent;
import org.cyclops.commoncapabilities.api.ingredient.IngredientInstanceWrapper;
Expand Down Expand Up @@ -394,6 +396,20 @@ public PrioritizedPartPos getPosition() {
return PrioritizedPartPos.of(getTarget().getCenter(), getPriority());
}

@Override
public ItemStack getTargetMachineItem() {
PartTarget target = getTarget();
if (target == null) {
return ItemStack.EMPTY;
}
DimPos dimPos = target.getTarget().getPos();
if (!dimPos.isLoaded()) {
return ItemStack.EMPTY;
}
Level level = dimPos.getLevel(false);
return new ItemStack(level.getBlockState(dimPos.getBlockPos()).getBlock());
}

public CraftingJobHandler getCraftingJobHandler() {
return craftingJobHandler;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package org.cyclops.integratedcrafting.gametest;

import net.minecraft.core.BlockPos;
import net.minecraft.gametest.framework.GameTest;
import net.minecraft.gametest.framework.GameTestHelper;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.neoforged.neoforge.gametest.GameTestHolder;
import net.neoforged.neoforge.gametest.PrefixGameTestTemplate;
import org.cyclops.integratedcrafting.Reference;
import org.cyclops.integratedcrafting.core.part.PartTypeInterfaceCraftingBase;

import static org.cyclops.integratedcrafting.gametest.GameTestHelpersIntegratedCrafting.*;

/**
* Game tests for the machine that crafting interfaces are targeting.
* @author rubensworks
*/
@GameTestHolder(Reference.MOD_ID)
@PrefixGameTestTemplate(false)
public class GameTestsCraftingInterfaceTargetMachine {

public static final String TEMPLATE_EMPTY = "empty10";
public static final int TIMEOUT = 2000;
public static final BlockPos POS = BlockPos.ZERO.offset(2, 0, 2);

protected void testTargetMachineItem(GameTestHelper helper, boolean attuned, Block crafter, Item expectedItem) {
INetworkPositions<PartTypeInterfaceCraftingBase.State<?, ?>> positions = createBasicNetwork(helper, POS, attuned, crafter);

helper.succeedWhen(() -> {
ItemStack machineItem = positions.interfaceStates().get(0).getTargetMachineItem();
helper.assertValueEqual(machineItem.getItem(), expectedItem, "Target machine item is incorrect");
});
}

@GameTest(template = TEMPLATE_EMPTY, timeoutTicks = TIMEOUT)
public void testTargetMachineItemCraftingTable(GameTestHelper helper) {
testTargetMachineItem(helper, false, Blocks.CRAFTING_TABLE, Items.CRAFTING_TABLE);
}

@GameTest(template = TEMPLATE_EMPTY, timeoutTicks = TIMEOUT)
public void testTargetMachineItemFurnace(GameTestHelper helper) {
testTargetMachineItem(helper, false, Blocks.FURNACE, Items.FURNACE);
}

@GameTest(template = TEMPLATE_EMPTY, timeoutTicks = TIMEOUT)
public void testTargetMachineItemAttunedCraftingTable(GameTestHelper helper) {
testTargetMachineItem(helper, true, Blocks.CRAFTING_TABLE, Items.CRAFTING_TABLE);
}

@GameTest(template = TEMPLATE_EMPTY, timeoutTicks = TIMEOUT)
public void testTargetMachineItemAttunedFurnace(GameTestHelper helper) {
testTargetMachineItem(helper, true, Blocks.FURNACE, Items.FURNACE);
}

}
Loading