Skip to content

Commit e5c526b

Browse files
committed
feat: ✨ Added linked storage support
1 parent 45b9564 commit e5c526b

57 files changed

Lines changed: 2438 additions & 11 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ mod_id=sophisticatedcore
77
mod_name=Sophisticated Core
88
mod_license=All Rights Reserved
99
mod_group_id=net.p3pp3rf1y
10-
mod_version=1.3.84
10+
mod_version=1.5.0
1111
sonar_project_key=sophisticatedcore:SophisticatedCore
1212
github_package_url=https://maven.pkg.github.com/P3pp3rF1y/SophisticatedCore
1313

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"forge:conditions": [
3+
{
4+
"type": "sophisticatedcore:item_enabled",
5+
"itemRegistryName": "sophisticatedcore:ender_linker"
6+
},
7+
{
8+
"type": "forge:or",
9+
"values": [
10+
{
11+
"type": "forge:mod_loaded",
12+
"modid": "sophisticatedbackpacks"
13+
},
14+
{
15+
"type": "forge:mod_loaded",
16+
"modid": "sophisticatedstorage"
17+
}
18+
]
19+
}
20+
],
21+
"parent": "minecraft:recipes/root",
22+
"criteria": {
23+
"has_ender_pearl": {
24+
"conditions": {
25+
"items": [
26+
{
27+
"items": [
28+
"minecraft:ender_pearl"
29+
]
30+
}
31+
]
32+
},
33+
"trigger": "minecraft:inventory_changed"
34+
},
35+
"has_the_recipe": {
36+
"conditions": {
37+
"recipe": "sophisticatedcore:ender_linker"
38+
},
39+
"trigger": "minecraft:recipe_unlocked"
40+
}
41+
},
42+
"requirements": [
43+
[
44+
"has_the_recipe",
45+
"has_ender_pearl"
46+
]
47+
],
48+
"rewards": {
49+
"recipes": [
50+
"sophisticatedcore:ender_linker"
51+
]
52+
}
53+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"forge:conditions": [
3+
{
4+
"type": "sophisticatedcore:item_enabled",
5+
"itemRegistryName": "sophisticatedcore:ender_linker"
6+
},
7+
{
8+
"type": "forge:or",
9+
"values": [
10+
{
11+
"type": "forge:mod_loaded",
12+
"modid": "sophisticatedbackpacks"
13+
},
14+
{
15+
"type": "forge:mod_loaded",
16+
"modid": "sophisticatedstorage"
17+
}
18+
]
19+
}
20+
],
21+
"type": "minecraft:crafting_shaped",
22+
"category": "misc",
23+
"key": {
24+
"B": {
25+
"item": "minecraft:blaze_rod"
26+
},
27+
"E": {
28+
"item": "minecraft:ender_pearl"
29+
},
30+
"O": {
31+
"item": "minecraft:obsidian"
32+
}
33+
},
34+
"pattern": [
35+
"OEO",
36+
"BOB",
37+
"OEO"
38+
],
39+
"result": {
40+
"item": "sophisticatedcore:ender_linker"
41+
}
42+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"forge:conditions": [
3+
{
4+
"type": "forge:or",
5+
"values": [
6+
{
7+
"type": "forge:mod_loaded",
8+
"modid": "sophisticatedbackpacks"
9+
},
10+
{
11+
"type": "forge:mod_loaded",
12+
"modid": "sophisticatedstorage"
13+
}
14+
]
15+
}
16+
],
17+
"type": "sophisticatedcore:ender_linker_clear"
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"forge:conditions": [
3+
{
4+
"type": "forge:or",
5+
"values": [
6+
{
7+
"type": "forge:mod_loaded",
8+
"modid": "sophisticatedbackpacks"
9+
},
10+
{
11+
"type": "forge:mod_loaded",
12+
"modid": "sophisticatedstorage"
13+
}
14+
]
15+
}
16+
],
17+
"type": "sophisticatedcore:ender_linker_endpoint"
18+
}

src/main/java/net/p3pp3rf1y/sophisticatedcore/client/ClientEventHandler.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import net.minecraft.client.gui.screens.Screen;
1111
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
1212
import net.minecraft.client.gui.screens.inventory.CreativeModeInventoryScreen;
13+
import net.minecraft.client.renderer.item.ItemProperties;
1314
import net.minecraft.network.chat.Component;
1415
import net.minecraft.world.inventory.AbstractContainerMenu;
1516
import net.minecraft.world.inventory.Slot;
@@ -23,16 +24,21 @@
2324
import net.minecraftforge.client.settings.KeyModifier;
2425
import net.minecraftforge.common.MinecraftForge;
2526
import net.minecraftforge.event.TickEvent;
27+
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
2628
import net.minecraftforge.eventbus.api.IEventBus;
29+
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
2730
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
31+
import net.p3pp3rf1y.sophisticatedcore.SophisticatedCore;
2832
import net.p3pp3rf1y.sophisticatedcore.api.IStashStorageItem;
2933
import net.p3pp3rf1y.sophisticatedcore.client.gui.StorageScreenBase;
3034
import net.p3pp3rf1y.sophisticatedcore.client.gui.utils.GuiSoundHelper;
3135
import net.p3pp3rf1y.sophisticatedcore.client.gui.utils.TranslationHelper;
3236
import net.p3pp3rf1y.sophisticatedcore.client.init.ModParticles;
3337
import net.p3pp3rf1y.sophisticatedcore.client.render.BlockHighlightRenderer;
3438
import net.p3pp3rf1y.sophisticatedcore.common.gui.StorageContainerMenuBase;
39+
import net.p3pp3rf1y.sophisticatedcore.init.ModItems;
3540
import net.p3pp3rf1y.sophisticatedcore.inventory.ItemStackKey;
41+
import net.p3pp3rf1y.sophisticatedcore.linkedstorage.EnderLinkerItem;
3642
import net.p3pp3rf1y.sophisticatedcore.upgrades.jukebox.StorageSoundHandler;
3743
import org.lwjgl.glfw.GLFW;
3844

@@ -59,17 +65,24 @@ public static void registerHandlers() {
5965
IEventBus modBus = FMLJavaModLoadingContext.get().getModEventBus();
6066
modBus.addListener(ModParticles::registerFactories);
6167
modBus.addListener(ClientEventHandler::registerKeyMappings);
68+
modBus.addListener(ClientEventHandler::registerItemProperties);
6269
IEventBus eventBus = MinecraftForge.EVENT_BUS;
6370
eventBus.addListener(StorageSoundHandler::tick);
6471
eventBus.addListener(StorageSoundHandler::onWorldUnload);
6572
eventBus.addListener(ClientEventHandler::onDrawScreen);
6673
eventBus.addListener(ClientEventHandler::onContainerScreenForeground);
74+
eventBus.addListener(ClientEventHandler::onItemTooltip);
6775
eventBus.addListener(ClientEventHandler::handleGuiKeyPress);
6876
eventBus.addListener(ClientEventHandler::handleGuiMouseKeyPress);
6977
eventBus.addListener(ClientEventHandler::renderLevelStage);
7078
eventBus.addListener(ClientEventHandler::onTickEnd);
7179
}
7280

81+
private static void registerItemProperties(FMLClientSetupEvent event) {
82+
event.enqueueWork(() -> ItemProperties.register(ModItems.ENDER_LINKER.get(), SophisticatedCore.getRL("bound"),
83+
(stack, level, entity, seed) -> EnderLinkerItem.hasBoundPresentation(stack) ? 1.0F : 0.0F));
84+
}
85+
7386
private static void onTickEnd(TickEvent.ClientTickEvent event) {
7487
if (event.phase != TickEvent.Phase.END) {
7588
return;
@@ -179,6 +192,8 @@ private static void onContainerScreenForeground(ContainerScreenEvent.Render.Fore
179192
return;
180193
}
181194
AbstractContainerMenu menu = containerGui.getMenu();
195+
LinkerCraftingDiagnostics.requestIfChanged(menu);
196+
renderLinkerCraftingDiagnostics(event.getGuiGraphics(), menu);
182197
ItemStack held = menu.getCarried();
183198
if (held.isEmpty()) {
184199
return;
@@ -195,6 +210,28 @@ private static void onContainerScreenForeground(ContainerScreenEvent.Render.Fore
195210
}
196211
}
197212

213+
private static void renderLinkerCraftingDiagnostics(GuiGraphics guiGraphics, AbstractContainerMenu menu) {
214+
for (Slot slot : menu.slots) {
215+
if (LinkerCraftingDiagnostics.getStatusMessage(slot.index) != null) {
216+
guiGraphics.fill(slot.x, slot.y, slot.x + 16, slot.y + 16, 0x80FF0000);
217+
}
218+
}
219+
}
220+
221+
private static void onItemTooltip(ItemTooltipEvent event) {
222+
if (!(Minecraft.getInstance().screen instanceof AbstractContainerScreen<?> screen)) {
223+
return;
224+
}
225+
Slot slot = screen.getSlotUnderMouse();
226+
if (slot == null || slot.getItem() != event.getItemStack()) {
227+
return;
228+
}
229+
String statusMessage = LinkerCraftingDiagnostics.getStatusMessage(slot.index);
230+
if (statusMessage != null) {
231+
event.getToolTip().add(TranslationHelper.INSTANCE.translStatusMessage(statusMessage).withStyle(ChatFormatting.RED));
232+
}
233+
}
234+
198235
private static void renderStashSign(Minecraft mc, GuiGraphics guiGraphics, Slot s, ItemStack stack, IStashStorageItem.StashResult stashResult) {
199236
int x = s.x;
200237
int y = s.y;
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package net.p3pp3rf1y.sophisticatedcore.client;
2+
3+
import net.minecraft.client.Minecraft;
4+
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
5+
import net.minecraft.world.inventory.AbstractContainerMenu;
6+
import net.minecraft.world.inventory.CraftingContainer;
7+
import net.minecraft.world.inventory.Slot;
8+
import net.p3pp3rf1y.sophisticatedcore.network.PacketHandler;
9+
import net.p3pp3rf1y.sophisticatedcore.network.RequestLinkerCraftingDiagnosticsMessage;
10+
11+
import javax.annotation.Nullable;
12+
13+
import java.util.HashMap;
14+
import java.util.Map;
15+
16+
public final class LinkerCraftingDiagnostics {
17+
private static int lastRequestedContainerId = -1;
18+
private static int lastRequestedSignature;
19+
@Nullable
20+
private static AbstractContainerMenu lastRequestedMenu;
21+
private static final Map<Integer, String> DIAGNOSTICS = new HashMap<>();
22+
23+
private LinkerCraftingDiagnostics() {
24+
}
25+
26+
public static void requestIfChanged(AbstractContainerMenu menu) {
27+
if (menu != lastRequestedMenu) {
28+
lastRequestedMenu = menu;
29+
lastRequestedContainerId = -1;
30+
DIAGNOSTICS.clear();
31+
}
32+
int signature = 1;
33+
boolean hasCraftingGrid = false;
34+
for (Slot slot : menu.slots) {
35+
if (slot.container instanceof CraftingContainer) {
36+
signature = 31 * signature + 31 * slot.index + slot.getItem().hashCode();
37+
hasCraftingGrid = true;
38+
}
39+
}
40+
if (!hasCraftingGrid) {
41+
DIAGNOSTICS.clear();
42+
return;
43+
}
44+
if (menu.containerId == lastRequestedContainerId && signature == lastRequestedSignature) {
45+
return;
46+
}
47+
lastRequestedContainerId = menu.containerId;
48+
lastRequestedSignature = signature;
49+
DIAGNOSTICS.clear();
50+
PacketHandler.INSTANCE.sendToServer(new RequestLinkerCraftingDiagnosticsMessage(menu.containerId));
51+
}
52+
53+
public static void update(int containerId, Map<Integer, String> updatedDiagnostics) {
54+
if (!(Minecraft.getInstance().screen instanceof AbstractContainerScreen<?> screen) || screen.getMenu().containerId != containerId) {
55+
return;
56+
}
57+
DIAGNOSTICS.clear();
58+
DIAGNOSTICS.putAll(updatedDiagnostics);
59+
}
60+
61+
@Nullable
62+
public static String getStatusMessage(int slot) {
63+
return DIAGNOSTICS.get(slot);
64+
}
65+
}

0 commit comments

Comments
 (0)