Skip to content

Commit

Permalink
finished blueprint slot and fixed slots not being interactable
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinsdar committed Feb 5, 2025
1 parent 57e0ca4 commit fc75f50
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public BlockEntityWorkbench(MaterialMachine type, BlockPos pos, BlockState state
@Override
protected TrackedItemHandler<BlockEntityWorkbench> createTrackedHandler(SlotType<?> type, BlockEntityWorkbench tile) {
int count = tile.getMachineType().getCount(tile.getMachineTier(), type);
return type != SlotType.DISPLAY_SETTABLE && type != SlotType.DISPLAY && type != SlotType.FLUID_DISPLAY_SETTABLE ? new TrackedItemHandler<>(tile, type, count, type == SlotTypes.EXPORT, false, type.tester) : new FakeTrackedItemHandler<>(tile, type, count, type.output, type.input, type.tester);
return type != SlotType.DISPLAY_SETTABLE && type != SlotType.DISPLAY && type != SlotType.FLUID_DISPLAY_SETTABLE ? new TrackedItemHandler<>(tile, type, count, type == SlotTypes.EXPORT, type.input, type.tester) : new FakeTrackedItemHandler<>(tile, type, count, type.output, type.input, type.tester);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public static void init() {
initTFC();
}
AntimatterAPI.register(BlockEntityType.class, "sap_bag", GTCore.ID, SAP_BAG_BLOCK_ENTITY);
createWorkbench(AntimatterMaterials.Iron, false);
}

public static void initItemBarrels(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public class SlotTypes {
return true;
}, true, true, new ResourceLocation(GTCore.ID, "electric_tool"));
public static SlotType<SlotCrafting> CRAFTING = new SlotType<>("crafting", (type, gui, item, i, d) -> new SlotCrafting(type, gui, item.getOrDefault(type, new EmptyContainer()), i, d.getX(), d.getY()), (t, i) -> true, false, true);
public static SlotType<AbstractSlot<?>> PARK = new SlotType<>("park", (type, gui, item, i, d) -> new AbstractSlot<>(type, gui, item.getOrDefault(type, new EmptyContainer()), i, d.getX(), d.getY()), (t, i) -> true, false, false, new ResourceLocation(GTCore.ID, "park"));
public static SlotType<SlotBlueprint> BLUEPRINT = new SlotType<>("blueprint", (type, gui, item, i, d) -> new SlotBlueprint(type, gui, item.getOrDefault(type, new EmptyContainer()), i, d.getX(), d.getY()), (t, i) -> i.getItem() == GTCoreItems.Blueprint || i.getItem() == GTCoreItems.EmptyBlueprint, false, false, new ResourceLocation(GTCore.ID, "blueprint"));
public static SlotType<AbstractSlot<?>> PARK = new SlotType<>("park", (type, gui, item, i, d) -> new AbstractSlot<>(type, gui, item.getOrDefault(type, new EmptyContainer()), i, d.getX(), d.getY()), (t, i) -> true, true, false, new ResourceLocation(GTCore.ID, "park"));
public static SlotType<SlotBlueprint> BLUEPRINT = new SlotType<>("blueprint", (type, gui, item, i, d) -> new SlotBlueprint(type, gui, item.getOrDefault(type, new EmptyContainer()), i, d.getX(), d.getY()), (t, i) -> i.getItem() == GTCoreItems.Blueprint || i.getItem() == GTCoreItems.EmptyBlueprint, true, false, new ResourceLocation(GTCore.ID, "blueprint"));
public static SlotType<AbstractSlot<?>> EXPORT = new SlotType<>("export", (type, gui, item, i, d) -> new AbstractSlot<>(type, gui, item.getOrDefault(type, new EmptyContainer()), i, d.getX(), d.getY()), (t, i) -> true, true, true, new ResourceLocation(GTCore.ID, "export"));

public static SlotType<SlotUnlimited> UNLIMITED = new SlotType<>("unlimited", (type, gui, item, i, d) -> new SlotUnlimited(type, gui, item.getOrDefault(type, new EmptyContainer()), i, d.getX(), d.getY()), (t, i) -> true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,26 @@
import muramasa.antimatter.gui.SlotType;
import muramasa.antimatter.gui.slot.AbstractSlot;
import muramasa.antimatter.gui.slot.IClickableSlot;
import muramasa.antimatter.util.Utils;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.StringTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.ClickType;
import net.minecraft.world.inventory.CraftingContainer;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.CraftingRecipe;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.Level;
import org.gtreimagined.gtcore.data.GTCoreItems;
import org.gtreimagined.gtcore.gui.ContainerWorkbench;
import tesseract.api.item.ExtendedItemContainer;

import java.util.Optional;

public class SlotBlueprint extends AbstractSlot<SlotBlueprint> implements IClickableSlot {
public SlotBlueprint(SlotType<SlotBlueprint> type, IGuiHandler tile, ExtendedItemContainer stackHandler, int index, int x, int y) {
super(type, tile, stackHandler, index, x, y);
Expand All @@ -18,10 +32,32 @@ public SlotBlueprint(SlotType<SlotBlueprint> type, IGuiHandler tile, ExtendedIte

@Override
public ItemStack clickSlot(int i, ClickType clickType, Player player, AbstractContainerMenu abstractContainerMenu) {
if (player.isShiftKeyDown()) {

if (!(abstractContainerMenu instanceof ContainerWorkbench<?> workbench)) return this.getItem();
ItemStack item = this.getItem();
if (clickType == ClickType.QUICK_MOVE && i == 0 && item.getItem() == GTCoreItems.EmptyBlueprint) {
Level level = player.getCommandSenderWorld();
if (!level.isClientSide()){
ServerPlayer serverPlayer = (ServerPlayer) player;
CraftingContainer craftingGrid = workbench.getCraftingGrid();
Optional<CraftingRecipe> optional = level.getServer().getRecipeManager().getRecipeFor(RecipeType.CRAFTING, craftingGrid, level);
if (optional.isPresent()) {
CraftingRecipe recipe = optional.get();
ItemStack result = recipe.assemble(craftingGrid);
if (!result.isEmpty()) {
ItemStack blueprint = new ItemStack(GTCoreItems.Blueprint, item.getCount());
StringTag name = StringTag.valueOf(Component.Serializer.toJson(result.getHoverName()));
CompoundTag display = new CompoundTag();
display.put("Name", name);
blueprint.getOrCreateTag().put("display", display);
blueprint.getOrCreateTag().putString("recipeId", recipe.getId().toString());
this.set(blueprint);
serverPlayer.connection.send(new ClientboundContainerSetSlotPacket(abstractContainerMenu.containerId, abstractContainerMenu.getStateId(), 31, blueprint));
}
}
}
return this.getItem();
}
abstractContainerMenu.doClick(this.index, i, clickType, player);
abstractContainerMenu.doClick(31, i, clickType, player);
return this.getItem();
}
}

0 comments on commit fc75f50

Please sign in to comment.