Skip to content

Commit f755d94

Browse files
committed
feat: ✨ Added linked storage support
1 parent 108a412 commit f755d94

67 files changed

Lines changed: 3804 additions & 32 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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ loader_version_range=[4,)
1515
mod_id=sophisticatedcore
1616
mod_name=Sophisticated Core
1717
mod_license=All Rights Reserved
18-
mod_version=1.4.82
18+
mod_version=1.5.0
1919
mod_group_id=net.p3pp3rf1y
2020
mod_authors=P3pp3rF1y
2121
mod_description=A library / shared functionality mod for Sophisticated Storage and Backpacks
@@ -47,6 +47,7 @@ trashslot_version=21.5.1+1.21.5
4747
reliquary_version=[1.21.5-2.0.76,1.21.6)
4848
ftb_chunks_version=2101.1.11
4949
ftb_library_version=2101.1.21
50+
accessories_version=1.1.0-beta.52+1.21.1
5051
openpartiesandclaims_cf_file_id=6999204
5152
#quark_cf_file_id=3919164
5253
#autoreglib_cf_file_id=3857246
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"neoforge:conditions": [
3+
{
4+
"type": "sophisticatedcore:item_enabled",
5+
"itemRegistryName": "sophisticatedcore:ender_linker"
6+
},
7+
{
8+
"type": "neoforge:or",
9+
"values": [
10+
{
11+
"type": "neoforge:mod_loaded",
12+
"modid": "sophisticatedbackpacks"
13+
},
14+
{
15+
"type": "neoforge: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": "minecraft:ender_pearl"
28+
}
29+
]
30+
},
31+
"trigger": "minecraft:inventory_changed"
32+
},
33+
"has_the_recipe": {
34+
"conditions": {
35+
"recipe": "sophisticatedcore:ender_linker"
36+
},
37+
"trigger": "minecraft:recipe_unlocked"
38+
}
39+
},
40+
"requirements": [
41+
[
42+
"has_the_recipe",
43+
"has_ender_pearl"
44+
]
45+
],
46+
"rewards": {
47+
"recipes": [
48+
"sophisticatedcore:ender_linker"
49+
]
50+
}
51+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"neoforge:conditions": [
3+
{
4+
"type": "sophisticatedcore:item_enabled",
5+
"itemRegistryName": "sophisticatedcore:ender_linker"
6+
},
7+
{
8+
"type": "neoforge:or",
9+
"values": [
10+
{
11+
"type": "neoforge:mod_loaded",
12+
"modid": "sophisticatedbackpacks"
13+
},
14+
{
15+
"type": "neoforge:mod_loaded",
16+
"modid": "sophisticatedstorage"
17+
}
18+
]
19+
}
20+
],
21+
"type": "minecraft:crafting_shaped",
22+
"category": "misc",
23+
"key": {
24+
"B": "minecraft:blaze_rod",
25+
"E": "minecraft:ender_pearl",
26+
"O": "minecraft:obsidian"
27+
},
28+
"pattern": [
29+
"OEO",
30+
"BOB",
31+
"OEO"
32+
],
33+
"result": {
34+
"count": 1,
35+
"id": "sophisticatedcore:ender_linker"
36+
}
37+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"neoforge:conditions": [
3+
{
4+
"type": "neoforge:or",
5+
"values": [
6+
{
7+
"type": "neoforge:mod_loaded",
8+
"modid": "sophisticatedbackpacks"
9+
},
10+
{
11+
"type": "neoforge:mod_loaded",
12+
"modid": "sophisticatedstorage"
13+
}
14+
]
15+
}
16+
],
17+
"type": "sophisticatedcore:ender_linker_clear",
18+
"category": "misc"
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"neoforge:conditions": [
3+
{
4+
"type": "neoforge:or",
5+
"values": [
6+
{
7+
"type": "neoforge:mod_loaded",
8+
"modid": "sophisticatedbackpacks"
9+
},
10+
{
11+
"type": "neoforge:mod_loaded",
12+
"modid": "sophisticatedstorage"
13+
}
14+
]
15+
}
16+
],
17+
"type": "sophisticatedcore:ender_linker_endpoint",
18+
"category": "misc"
19+
}

src/main/java/net/p3pp3rf1y/sophisticatedcore/SophisticatedCore.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import net.p3pp3rf1y.sophisticatedcore.data.DataGenerators;
2525
import net.p3pp3rf1y.sophisticatedcore.init.ModCompat;
2626
import net.p3pp3rf1y.sophisticatedcore.init.ModCoreDataComponents;
27+
import net.p3pp3rf1y.sophisticatedcore.init.ModItems;
2728
import net.p3pp3rf1y.sophisticatedcore.inventory.StorageWrapperRepository;
2829
import net.p3pp3rf1y.sophisticatedcore.settings.DatapackSettingsTemplateManager;
2930
import net.p3pp3rf1y.sophisticatedcore.util.RecipeHelper;
@@ -52,6 +53,7 @@ public SophisticatedCore(IEventBus modBus, Dist dist, ModContainer container) {
5253
}
5354
Config.COMMON.initListeners(modBus);
5455
ModCoreDataComponents.register(modBus);
56+
ModItems.register(modBus);
5557
modBus.addListener((FMLConstructModEvent event) -> construct(event, modBus));
5658
modBus.addListener(SophisticatedCore::setup);
5759
modBus.addListener(DataGenerators::gatherData);

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

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,25 @@
1717
import net.minecraft.world.inventory.tooltip.TooltipComponent;
1818
import net.minecraft.world.item.ItemStack;
1919
import net.neoforged.bus.api.IEventBus;
20-
import net.neoforged.neoforge.client.event.*;
20+
import net.neoforged.neoforge.client.event.ClientTickEvent;
21+
import net.neoforged.neoforge.client.event.ContainerScreenEvent;
22+
import net.neoforged.neoforge.client.event.RecipesReceivedEvent;
23+
import net.neoforged.neoforge.client.event.RegisterConditionalItemModelPropertyEvent;
24+
import net.neoforged.neoforge.client.event.RegisterKeyMappingsEvent;
25+
import net.neoforged.neoforge.client.event.RenderLevelStageEvent;
26+
import net.neoforged.neoforge.client.event.ScreenEvent;
2127
import net.neoforged.neoforge.client.extensions.common.IClientFluidTypeExtensions;
2228
import net.neoforged.neoforge.client.extensions.common.RegisterClientExtensionsEvent;
2329
import net.neoforged.neoforge.client.settings.IKeyConflictContext;
2430
import net.neoforged.neoforge.client.settings.KeyModifier;
2531
import net.neoforged.neoforge.common.NeoForge;
32+
import net.neoforged.neoforge.event.entity.player.ItemTooltipEvent;
2633
import net.p3pp3rf1y.sophisticatedcore.SophisticatedCore;
2734
import net.p3pp3rf1y.sophisticatedcore.api.IStashStorageItem;
2835
import net.p3pp3rf1y.sophisticatedcore.client.gui.StorageScreenBase;
2936
import net.p3pp3rf1y.sophisticatedcore.client.gui.utils.GuiSoundHelper;
3037
import net.p3pp3rf1y.sophisticatedcore.client.gui.utils.TranslationHelper;
3138
import net.p3pp3rf1y.sophisticatedcore.client.init.ModParticles;
32-
import net.p3pp3rf1y.sophisticatedcore.client.render.BlockHighlightRenderHelper;
3339
import net.p3pp3rf1y.sophisticatedcore.client.render.BlockHighlightRenderer;
3440
import net.p3pp3rf1y.sophisticatedcore.common.gui.StorageContainerMenuBase;
3541
import net.p3pp3rf1y.sophisticatedcore.init.ModFluids;
@@ -59,21 +65,30 @@ private ClientEventHandler() {
5965

6066
public static void registerHandlers(IEventBus modBus) {
6167
modBus.addListener(ModParticles::registerFactories);
68+
modBus.addListener(ClientEventHandler::registerConditionalItemModelProperties);
6269
modBus.addListener(ClientEventHandler::registerFluidClientExtension);
6370
modBus.addListener(ClientEventHandler::registerKeyMappings);
64-
modBus.addListener(ClientEventHandler::registerRenderPipelines);
6571
IEventBus eventBus = NeoForge.EVENT_BUS;
6672
eventBus.addListener(StorageSoundHandler::tick);
6773
eventBus.addListener(StorageSoundHandler::onWorldUnload);
6874
eventBus.addListener(ClientEventHandler::onDrawScreen);
6975
eventBus.addListener(ClientEventHandler::onContainerScreenForeground);
7076
eventBus.addListener(ClientEventHandler::recipesReceived);
77+
eventBus.addListener(ClientEventHandler::onItemTooltip);
7178
eventBus.addListener(ClientEventHandler::handleGuiKeyPress);
7279
eventBus.addListener(ClientEventHandler::handleGuiMouseKeyPress);
7380
eventBus.addListener(ClientEventHandler::renderLevelStage);
7481
eventBus.addListener(ClientEventHandler::onTickEnd);
7582
}
7683

84+
private static void registerConditionalItemModelProperties(RegisterConditionalItemModelPropertyEvent event) {
85+
event.register(SophisticatedCore.getRL("ender_linker_bound"), EnderLinkerBound.MAP_CODEC);
86+
}
87+
88+
private static void recipesReceived(RecipesReceivedEvent event) {
89+
RecipeHelper.setRecipes(event.getRecipeMap());
90+
}
91+
7792
private static void onTickEnd(ClientTickEvent.Post event) {
7893
ItemStackKey.clearCache();
7994
}
@@ -86,10 +101,6 @@ private static void renderLevelStage(RenderLevelStageEvent event) {
86101
BlockHighlightRenderer.render(event.getPoseStack(), partialTick, event.getCamera().getPosition());
87102
}
88103

89-
private static void registerRenderPipelines(RegisterRenderPipelinesEvent event) {
90-
event.registerPipeline(BlockHighlightRenderHelper.THICK_HIGHLIGHT_PIPELINE);
91-
}
92-
93104
private static void registerKeyMappings(RegisterKeyMappingsEvent event) {
94105
event.register(SORT_KEYBIND);
95106
event.register(TRANSFER_TO_STORAGE_KEYBIND);
@@ -154,7 +165,7 @@ private static boolean tryCallSort(Screen gui) {
154165
MouseHandler mh = mc.mouseHandler;
155166
double mouseX = mh.xpos() * mc.getWindow().getGuiScaledWidth() / mc.getWindow().getScreenWidth();
156167
double mouseY = mh.ypos() * mc.getWindow().getGuiScaledHeight() / mc.getWindow().getScreenHeight();
157-
Slot selectedSlot = screen.getHoveredSlot(mouseX, mouseY);
168+
Slot selectedSlot = screen.findSlot(mouseX, mouseY);
158169
if (selectedSlot == null || container.isNotPlayersInventorySlot(selectedSlot.index)) {
159170
container.sort();
160171
return true;
@@ -163,10 +174,6 @@ private static boolean tryCallSort(Screen gui) {
163174
return false;
164175
}
165176

166-
private static void recipesReceived(RecipesReceivedEvent event) {
167-
RecipeHelper.setRecipes(event.getRecipeMap());
168-
}
169-
170177
private static void onDrawScreen(ScreenEvent.Render.Post event) {
171178
Minecraft mc = Minecraft.getInstance();
172179
Screen gui = mc.screen;
@@ -188,6 +195,8 @@ private static void onContainerScreenForeground(ContainerScreenEvent.Render.Fore
188195
return;
189196
}
190197
AbstractContainerMenu menu = containerGui.getMenu();
198+
LinkerCraftingDiagnostics.requestIfChanged(menu);
199+
renderLinkerCraftingDiagnostics(event.getGuiGraphics(), menu);
191200
ItemStack held = menu.getCarried();
192201
if (held.isEmpty()) {
193202
return;
@@ -204,6 +213,35 @@ private static void onContainerScreenForeground(ContainerScreenEvent.Render.Fore
204213
}
205214
}
206215

216+
private static void renderLinkerCraftingDiagnostics(GuiGraphics guiGraphics, AbstractContainerMenu menu) {
217+
for (Slot slot : menu.slots) {
218+
renderLinkerCraftingDiagnostic(guiGraphics, slot);
219+
}
220+
if (menu instanceof StorageContainerMenuBase<?> storageContainer) {
221+
storageContainer.upgradeSlots.forEach(slot -> renderLinkerCraftingDiagnostic(guiGraphics, slot));
222+
}
223+
}
224+
225+
private static void renderLinkerCraftingDiagnostic(GuiGraphics guiGraphics, Slot slot) {
226+
if (LinkerCraftingDiagnostics.getStatusMessage(slot.index) != null) {
227+
guiGraphics.fill(slot.x, slot.y, slot.x + 16, slot.y + 16, 0x80FF0000);
228+
}
229+
}
230+
231+
private static void onItemTooltip(ItemTooltipEvent event) {
232+
if (!(Minecraft.getInstance().screen instanceof AbstractContainerScreen<?> screen)) {
233+
return;
234+
}
235+
Slot slot = screen.getSlotUnderMouse();
236+
if (slot == null || slot.getItem() != event.getItemStack()) {
237+
return;
238+
}
239+
String statusMessage = LinkerCraftingDiagnostics.getStatusMessage(slot.index);
240+
if (statusMessage != null) {
241+
event.getToolTip().add(TranslationHelper.INSTANCE.translStatusMessage(statusMessage).withStyle(ChatFormatting.RED));
242+
}
243+
}
244+
207245
private static void renderStashSign(Minecraft mc, GuiGraphics guiGraphics, Slot s, ItemStack stack, IStashStorageItem.StashResult stashResult) {
208246
int x = s.x;
209247
int y = s.y;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package net.p3pp3rf1y.sophisticatedcore.client;
2+
3+
import com.mojang.serialization.MapCodec;
4+
import net.minecraft.client.multiplayer.ClientLevel;
5+
import net.minecraft.client.renderer.item.properties.conditional.ConditionalItemModelProperty;
6+
import net.minecraft.world.entity.LivingEntity;
7+
import net.minecraft.world.item.ItemDisplayContext;
8+
import net.minecraft.world.item.ItemStack;
9+
import net.p3pp3rf1y.sophisticatedcore.linkedstorage.EnderLinkerItem;
10+
11+
import javax.annotation.Nullable;
12+
13+
public record EnderLinkerBound() implements ConditionalItemModelProperty {
14+
public static final MapCodec<EnderLinkerBound> MAP_CODEC = MapCodec.unit(new EnderLinkerBound());
15+
16+
@Override
17+
public boolean get(ItemStack itemStack, @Nullable ClientLevel clientLevel, @Nullable LivingEntity livingEntity, int seed,
18+
ItemDisplayContext itemDisplayContext) {
19+
return EnderLinkerItem.hasBoundPresentation(itemStack);
20+
}
21+
22+
@Override
23+
public MapCodec<? extends ConditionalItemModelProperty> type() {
24+
return MAP_CODEC;
25+
}
26+
}

0 commit comments

Comments
 (0)