Added support for not checking recipes downwards in the compacting drawer
This commit is contained in:
parent
d8ad7a702c
commit
750eacea31
|
@ -87,4 +87,5 @@ ff234dac4f0b0b4f83ffa92f2d2fb1074c68df43 data/functionalstorage/recipes/spruce_4
|
|||
bcb281904eac23183c45786e3d703d24bba92be6 data/functionalstorage/recipes/warped_1.json
|
||||
8fc3f76a2c57eb4d80ce86947fabebe48fa6f692 data/functionalstorage/recipes/warped_2.json
|
||||
7510a8ca1f1e3bb63f4c4f4add0bb6b713feaa0b data/functionalstorage/recipes/warped_4.json
|
||||
f37e620a26ceb158507c607cee6ba3b51f14c6d6 data/functionalstorage/tags/items/drawer.json
|
||||
db0122948639b122cb0c1df7530996e9784356b0 data/functionalstorage/tags/items/drawer.json
|
||||
12ec935226bf5a6a1493d353ef6dc6c224c256dd data/functionalstorage/tags/items/ignore_crafting_check.json
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
{
|
||||
"replace": false,
|
||||
"values": [
|
||||
"functionalstorage:oak_2",
|
||||
"functionalstorage:spruce_2",
|
||||
"functionalstorage:birch_2",
|
||||
"functionalstorage:jungle_2",
|
||||
"functionalstorage:acacia_2",
|
||||
"functionalstorage:dark_oak_2",
|
||||
"functionalstorage:crimson_2",
|
||||
"functionalstorage:warped_2",
|
||||
"functionalstorage:oak_1",
|
||||
"functionalstorage:spruce_1",
|
||||
"functionalstorage:birch_1",
|
||||
"functionalstorage:jungle_1",
|
||||
"functionalstorage:acacia_1",
|
||||
"functionalstorage:dark_oak_1",
|
||||
"functionalstorage:crimson_1",
|
||||
"functionalstorage:warped_1",
|
||||
"functionalstorage:oak_4",
|
||||
"functionalstorage:spruce_4",
|
||||
"functionalstorage:birch_4",
|
||||
|
@ -17,13 +17,13 @@
|
|||
"functionalstorage:dark_oak_4",
|
||||
"functionalstorage:crimson_4",
|
||||
"functionalstorage:warped_4",
|
||||
"functionalstorage:oak_1",
|
||||
"functionalstorage:spruce_1",
|
||||
"functionalstorage:birch_1",
|
||||
"functionalstorage:jungle_1",
|
||||
"functionalstorage:acacia_1",
|
||||
"functionalstorage:dark_oak_1",
|
||||
"functionalstorage:crimson_1",
|
||||
"functionalstorage:warped_1"
|
||||
"functionalstorage:oak_2",
|
||||
"functionalstorage:spruce_2",
|
||||
"functionalstorage:birch_2",
|
||||
"functionalstorage:jungle_2",
|
||||
"functionalstorage:acacia_2",
|
||||
"functionalstorage:dark_oak_2",
|
||||
"functionalstorage:crimson_2",
|
||||
"functionalstorage:warped_2"
|
||||
]
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"replace": false,
|
||||
"values": [
|
||||
"minecraft:clay",
|
||||
"minecraft:clay_ball",
|
||||
"minecraft:glowstone",
|
||||
"minecraft:glowstone_dust"
|
||||
]
|
||||
}
|
|
@ -15,6 +15,7 @@ import net.minecraft.world.InteractionHand;
|
|||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
|
@ -36,6 +37,7 @@ public class CompactingDrawerTile extends ControllableDrawerTile<CompactingDrawe
|
|||
@Save
|
||||
public CompactingInventoryHandler handler;
|
||||
private final LazyOptional<IItemHandler> lazyStorage;
|
||||
private boolean hasCheckedRecipes;
|
||||
|
||||
public CompactingDrawerTile(BasicTileBlock<CompactingDrawerTile> base, BlockPos pos, BlockState state) {
|
||||
super(base, pos, state);
|
||||
|
@ -61,7 +63,20 @@ public class CompactingDrawerTile extends ControllableDrawerTile<CompactingDrawe
|
|||
}
|
||||
};
|
||||
lazyStorage = LazyOptional.of(() -> this.handler);
|
||||
//TODO Check for the recipe on load
|
||||
this.hasCheckedRecipes = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serverTick(Level level, BlockPos pos, BlockState state, CompactingDrawerTile blockEntity) {
|
||||
super.serverTick(level, pos, state, blockEntity);
|
||||
if (!hasCheckedRecipes){
|
||||
if (!handler.getParent().isEmpty()){
|
||||
CompactingUtil compactingUtil = new CompactingUtil(this.level);
|
||||
compactingUtil.setup(handler.getParent());
|
||||
handler.setup(compactingUtil);
|
||||
}
|
||||
hasCheckedRecipes = true;
|
||||
}
|
||||
}
|
||||
|
||||
public InteractionResult onSlotActivated(Player playerIn, InteractionHand hand, Direction facing, double hitX, double hitY, double hitZ, int slot) {
|
||||
|
|
|
@ -54,27 +54,7 @@ public class CompactingDrawerRenderer implements BlockEntityRenderer<CompactingD
|
|||
}
|
||||
matrixStack.translate(0,0,-0.5/16D);
|
||||
combinedLightIn = LevelRenderer.getLightColor(tile.getLevel(), tile.getBlockPos().relative(facing));
|
||||
matrixStack.pushPose();
|
||||
matrixStack.translate(0.031,0.031f,0.469/16D);
|
||||
float scale = 0.0625f;
|
||||
for (int i = 0; i < tile.getStorageUpgrades().getSlots(); i++) {
|
||||
ItemStack stack = tile.getStorageUpgrades().getStackInSlot(i);
|
||||
if (!stack.isEmpty()){
|
||||
matrixStack.pushPose();
|
||||
matrixStack.scale(scale, scale, scale);
|
||||
Minecraft.getInstance().getItemRenderer().renderStatic(stack, ItemTransforms.TransformType.NONE, combinedLightIn, combinedOverlayIn, matrixStack, bufferIn, 0);
|
||||
matrixStack.popPose();
|
||||
matrixStack.translate(scale,0,0);
|
||||
}
|
||||
}
|
||||
matrixStack.popPose();
|
||||
if (tile.isVoid()){
|
||||
matrixStack.pushPose();
|
||||
matrixStack.translate(0.969,0.031f,0.469/16D);
|
||||
matrixStack.scale(scale, scale, scale);
|
||||
Minecraft.getInstance().getItemRenderer().renderStatic(new ItemStack(FunctionalStorage.VOID_UPGRADE.get()), ItemTransforms.TransformType.NONE, combinedLightIn, combinedOverlayIn, matrixStack, bufferIn, 0);
|
||||
matrixStack.popPose();
|
||||
}
|
||||
DrawerRenderer.renderUpgrades(matrixStack, bufferIn, combinedLightIn, combinedOverlayIn, tile);
|
||||
ItemStack stack = tile.getHandler().getResultList().get(0).getResult();
|
||||
if (!stack.isEmpty()){
|
||||
matrixStack.pushPose();
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.buuz135.functionalstorage.client;
|
||||
|
||||
import com.buuz135.functionalstorage.FunctionalStorage;
|
||||
import com.buuz135.functionalstorage.block.tile.ControllableDrawerTile;
|
||||
import com.buuz135.functionalstorage.block.tile.DrawerTile;
|
||||
import com.buuz135.functionalstorage.inventory.BigInventoryHandler;
|
||||
import com.buuz135.functionalstorage.util.NumberUtils;
|
||||
|
@ -57,6 +58,14 @@ public class DrawerRenderer implements BlockEntityRenderer<DrawerTile> {
|
|||
}
|
||||
matrixStack.translate(0,0,-0.5/16D);
|
||||
combinedLightIn = LevelRenderer.getLightColor(tile.getLevel(), tile.getBlockPos().relative(facing));
|
||||
renderUpgrades(matrixStack, bufferIn, combinedLightIn, combinedOverlayIn, tile);
|
||||
if (tile.getDrawerType() == FunctionalStorage.DrawerType.X_1) render1Slot(matrixStack, bufferIn, combinedLightIn, combinedOverlayIn, tile);
|
||||
if (tile.getDrawerType() == FunctionalStorage.DrawerType.X_2) render2Slot(matrixStack, bufferIn, combinedLightIn, combinedOverlayIn, tile);
|
||||
if (tile.getDrawerType() == FunctionalStorage.DrawerType.X_4) render4Slot(matrixStack, bufferIn, combinedLightIn, combinedOverlayIn, tile);
|
||||
matrixStack.popPose();
|
||||
}
|
||||
|
||||
public static void renderUpgrades(PoseStack matrixStack, MultiBufferSource bufferIn, int combinedLightIn, int combinedOverlayIn, ControllableDrawerTile<?> tile){
|
||||
matrixStack.pushPose();
|
||||
matrixStack.translate(0.031,0.031f,0.469/16D);
|
||||
float scale = 0.0625f;
|
||||
|
@ -78,10 +87,6 @@ public class DrawerRenderer implements BlockEntityRenderer<DrawerTile> {
|
|||
Minecraft.getInstance().getItemRenderer().renderStatic(new ItemStack(FunctionalStorage.VOID_UPGRADE.get()), ItemTransforms.TransformType.NONE, combinedLightIn, combinedOverlayIn, matrixStack, bufferIn, 0);
|
||||
matrixStack.popPose();
|
||||
}
|
||||
if (tile.getDrawerType() == FunctionalStorage.DrawerType.X_1) render1Slot(matrixStack, bufferIn, combinedLightIn, combinedOverlayIn, tile);
|
||||
if (tile.getDrawerType() == FunctionalStorage.DrawerType.X_2) render2Slot(matrixStack, bufferIn, combinedLightIn, combinedOverlayIn, tile);
|
||||
if (tile.getDrawerType() == FunctionalStorage.DrawerType.X_4) render4Slot(matrixStack, bufferIn, combinedLightIn, combinedOverlayIn, tile);
|
||||
matrixStack.popPose();
|
||||
}
|
||||
|
||||
private void render1Slot(PoseStack matrixStack, MultiBufferSource bufferIn, int combinedLightIn, int combinedOverlayIn, DrawerTile tile){
|
||||
|
|
|
@ -8,6 +8,7 @@ import net.minecraft.data.tags.ItemTagsProvider;
|
|||
import net.minecraft.data.tags.TagsProvider;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
|
@ -29,5 +30,6 @@ public class FunctionalStorageTagsProvider extends ItemTagsProvider {
|
|||
tTagAppender.add(blockRegistryObject.get().asItem());
|
||||
}
|
||||
}
|
||||
this.tag(StorageTags.IGNORE_CRAFTING_CHECK).add(Items.CLAY).add(Items.CLAY_BALL).add(Items.GLOWSTONE).add(Items.GLOWSTONE_DUST);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import java.util.List;
|
|||
|
||||
public abstract class CompactingInventoryHandler implements IItemHandler, INBTSerializable<CompoundTag> {
|
||||
|
||||
public static String VOID = "Void";
|
||||
public static String PARENT = "Parent";
|
||||
public static String BIG_ITEMS = "BigItems";
|
||||
public static String STACK = "Stack";
|
||||
public static String AMOUNT = "Amount";
|
||||
|
@ -21,6 +21,7 @@ public abstract class CompactingInventoryHandler implements IItemHandler, INBTSe
|
|||
public static final int TOTAL_AMOUNT = 512 * 9 * 9;
|
||||
|
||||
private int amount;
|
||||
private ItemStack parent;
|
||||
private List<CompactingUtil.Result> resultList;
|
||||
|
||||
public CompactingInventoryHandler(){
|
||||
|
@ -28,6 +29,7 @@ public abstract class CompactingInventoryHandler implements IItemHandler, INBTSe
|
|||
for (int i = 0; i < 3; i++) {
|
||||
this.resultList.add(i, new CompactingUtil.Result(ItemStack.EMPTY, 1));
|
||||
}
|
||||
this.parent = ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -69,6 +71,7 @@ public abstract class CompactingInventoryHandler implements IItemHandler, INBTSe
|
|||
|
||||
public void setup(CompactingUtil compactingUtil){
|
||||
this.resultList = compactingUtil.getResults();
|
||||
this.parent = compactingUtil.getResults().get(2).getResult();
|
||||
onChange();
|
||||
}
|
||||
|
||||
|
@ -133,6 +136,7 @@ public abstract class CompactingInventoryHandler implements IItemHandler, INBTSe
|
|||
@Override
|
||||
public CompoundTag serializeNBT() {
|
||||
CompoundTag compoundTag = new CompoundTag();
|
||||
compoundTag.put(PARENT, this.getParent().serializeNBT());
|
||||
compoundTag.putInt(AMOUNT, this.amount);
|
||||
CompoundTag items = new CompoundTag();
|
||||
for (int i = 0; i < this.resultList.size(); i++) {
|
||||
|
@ -147,6 +151,7 @@ public abstract class CompactingInventoryHandler implements IItemHandler, INBTSe
|
|||
|
||||
@Override
|
||||
public void deserializeNBT(CompoundTag nbt) {
|
||||
this.parent = ItemStack.of(nbt.getCompound(PARENT));
|
||||
this.amount = nbt.getInt(AMOUNT);
|
||||
for (String allKey : nbt.getCompound(BIG_ITEMS).getAllKeys()) {
|
||||
this.resultList.get(Integer.parseInt(allKey)).setResult(ItemStack.of(nbt.getCompound(BIG_ITEMS).getCompound(allKey).getCompound(STACK)));
|
||||
|
@ -165,4 +170,8 @@ public abstract class CompactingInventoryHandler implements IItemHandler, INBTSe
|
|||
public List<CompactingUtil.Result> getResultList() {
|
||||
return resultList;
|
||||
}
|
||||
|
||||
public ItemStack getParent() {
|
||||
return parent;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,7 +76,9 @@ public class CompactingUtil {
|
|||
container = createContainerAndFill(2, stack);
|
||||
outputs = findAllMatchingRecipes(container);
|
||||
}
|
||||
if (outputs.size() > 0){
|
||||
if (stack.is(StorageTags.IGNORE_CRAFTING_CHECK)){
|
||||
realOutputs = outputs;
|
||||
}else if (outputs.size() > 0){
|
||||
for (ItemStack output : outputs) {
|
||||
container = createContainerAndFill(1, output);
|
||||
List<ItemStack> reversed = findAllMatchingRecipes(container);
|
||||
|
@ -107,13 +109,18 @@ public class CompactingUtil {
|
|||
if (!ItemStack.isSame(stack, output)) continue;
|
||||
ItemStack match = tryMatch(stack, craftingRecipe.getIngredients());
|
||||
if (!match.isEmpty()){
|
||||
int recipeSize = craftingRecipe.getIngredients().size();
|
||||
if (stack.is(StorageTags.IGNORE_CRAFTING_CHECK)){
|
||||
candidates.add(match);
|
||||
candidatesRate.put(match, recipeSize);
|
||||
}
|
||||
CraftingContainer container = createContainerAndFill(1, output);
|
||||
List<ItemStack> matchStacks = findAllMatchingRecipes(container);
|
||||
for (ItemStack matchStack : matchStacks) {
|
||||
int recipeSize = craftingRecipe.getIngredients().size();
|
||||
if (ItemStack.isSame(match, matchStack) && matchStack.getCount() == recipeSize){
|
||||
candidates.add(match);
|
||||
candidatesRate.put(match, recipeSize);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,5 +9,6 @@ import net.minecraftforge.common.Tags;
|
|||
public class StorageTags {
|
||||
|
||||
public static Tags.IOptionalNamedTag<Item> DRAWER = ItemTags.createOptional(new ResourceLocation(FunctionalStorage.MOD_ID, "drawer"));
|
||||
public static Tags.IOptionalNamedTag<Item> IGNORE_CRAFTING_CHECK = ItemTags.createOptional(new ResourceLocation(FunctionalStorage.MOD_ID, "ignore_crafting_check"));
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user