Skip to content

Commit

Permalink
feat: re-enable curios integration
Browse files Browse the repository at this point in the history
Supports Adorned and Curios API Continuation
  • Loading branch information
klikli-dev committed Aug 1, 2024
1 parent 91efa3b commit 45836e8
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 121 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build_and_publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ jobs:
emi(optional)
almost-unified(optional)
perviaminvenire(optional)
# TODO: Enable once curios is updated
# curios(required)
curios-continuation(optional)
adorned(optional)
# Publish at the end because it creates a non reobfed jarjar which otherwise would be distributed
- name: Publish
run: ./gradlew publish
Expand Down
17 changes: 12 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ sourceSets {
exclude '**/AlmostUnifiedIntegrationImpl.java'
// exclude '**/emi/**/*.java'
// exclude '**/jei/impl/**/*.java'
exclude 'com/klikli_dev/occultism/common/item/tool/FamiliarRingItem.java'
// exclude 'com/klikli_dev/occultism/common/item/tool/FamiliarRingItem.java'
}
}
}
Expand Down Expand Up @@ -83,9 +83,16 @@ repositories {
includeGroup "com.almostreliable.mods"
}
}
// maven { //used to be curios
// name = "Curios Maven"
// url = "https://maven.theillusivec4.top/"
// content {
// includeGroup "top.theillusivec4.curios"
// }
// }
maven {
name = "Curios Maven"
url = "https://maven.theillusivec4.top/"
name = "OctoStudios (Curios Api Contiunation)"
url = uri("https://maven.octo-studios.com/releases")
content {
includeGroup "top.theillusivec4.curios"
}
Expand Down Expand Up @@ -145,8 +152,8 @@ dependencies {
runtimeOnly "mezz.jei:jei-${minecraft_version}-neoforge:${jei_version}"

//curios
// compileOnly "top.theillusivec4.curios:curios-neoforge:${curios_version}+${minecraft_version}:api"
// runtimeOnly "top.theillusivec4.curios:curios-neoforge:${curios_version}+${minecraft_version}"
compileOnly "top.theillusivec4.curios:curios-neoforge:${curios_version}+${minecraft_version}:api"
runtimeOnly "top.theillusivec4.curios:curios-neoforge:${curios_version}+${minecraft_version}"

//geckolib
implementation "software.bernie.geckolib:geckolib-neoforge-${geckolib_minecraft_version}:${geckolib_version}"
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ mod_description=A magic mod inspired by the world of Jonathan Stroud's Bartimaeu
## Dependency Properties
jei_version=19.3.1.25
jei_version_range=[19.3.1.0,)
curios_version=8.0.0-beta.4
curios_version_range=[8.0.0-beta.4,)
curios_version=9.0.5
curios_version_range=[9.0.5,)
geckolib_minecraft_version=1.21
geckolib_version=4.5.7
geckolib_version_range=[4.5.5,)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ private boolean captureFamiliar(Level level, IFamiliar familiar) {
return false;

//otherwise is added to world is serialized
familiar.getFamiliarEntity().onRemovedFromWorld();
familiar.getFamiliarEntity().onRemovedFromLevel();
this.setFamiliar(familiar, level.registryAccess());
this.getFamiliar(level).getFamiliarEntity().stopRiding();
this.getFamiliar(level).getFamiliarEntity().ejectPassengers();
Expand All @@ -193,8 +193,12 @@ private boolean captureFamiliar(Level level, IFamiliar familiar) {

private boolean releaseFamiliar(Player player, Level level) {
if (this.getFamiliar(level) != null
&& !this.getFamiliar(level).getFamiliarEntity().isAddedToWorld()) {
EntityType.loadEntityRecursive(this.getFamiliar(level).getFamiliarEntity().serializeNBT(level.registryAccess()), level, e -> {
&& !this.getFamiliar(level).getFamiliarEntity().isAddedToLevel()) {

var familiarTag = new CompoundTag();
this.getFamiliar(level).getFamiliarEntity().saveAsPassenger(familiarTag);

EntityType.loadEntityRecursive(familiarTag, level, e -> {
e.setPos(player.getX(), player.getY(), player.getZ());
//on release overwrite owner -> familiar rings can be used to trade familiars.
((IFamiliar) e).setFamiliarOwner(player);
Expand Down Expand Up @@ -224,7 +228,7 @@ public void curioTick(SlotContext slotContext) {
if (familiar != null) {
// after portal use the level is still the pre-teleport level, the familiar owner is not found on the next check
// hence, we update the level, if the familiar is in a ring
if (!familiar.getFamiliarEntity().isAddedToWorld())
if (!familiar.getFamiliarEntity().isAddedToLevel())
familiar.getFamiliarEntity().setLevel(level);

if (familiar.getFamiliarOwner() != slotContext.entity())
Expand All @@ -243,9 +247,11 @@ public void curioTick(SlotContext slotContext) {
public CompoundTag serializeNBT(HolderLookup.Provider provider) {
CompoundTag compound = new CompoundTag();
compound.putBoolean("hasFamiliar", this.familiar != null || this.cachedNbt != null);
if (this.familiar != null)
compound.put("familiar", this.familiar.getFamiliarEntity().serializeNBT(provider));
else if (this.cachedNbt != null)
if (this.familiar != null) {
var familiarTag = new CompoundTag();
this.familiar.getFamiliarEntity().saveAsPassenger(familiarTag);
compound.put("familiar", familiarTag);
} else if (this.cachedNbt != null)
compound.put("familiar", this.cachedNbt);

return compound;
Expand All @@ -264,7 +270,7 @@ private IFamiliar getFamiliar(Level level) {
return this.familiar;

var data = this.stack.get(OccultismDataComponents.FAMILIAR_DATA);
var tag = data == null ? null : data.getUnsafe();
var tag = data == null ? null : data.getUnsafe();
if (tag != null && (this.cachedNbt == null || !this.cachedNbt.equals(tag))) {
this.deserializeNBT(level.registryAccess(), tag);
}
Expand All @@ -280,7 +286,13 @@ private IFamiliar getFamiliar(Level level) {
private void setFamiliar(IFamiliar familiar, HolderLookup.Provider provider) {
this.familiar = familiar;

this.cachedNbt = this.familiar != null ? this.familiar.getFamiliarEntity().serializeNBT(provider) : null;
CompoundTag compound = new CompoundTag();
if (this.familiar != null) {
this.cachedNbt = this.familiar.getFamiliarEntity().saveAsPassenger(compound) ? compound : null;
} else {
this.cachedNbt = null;
}

this.stack.set(OccultismDataComponents.FAMILIAR_DATA, CustomData.of(this.serializeNBT(provider)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import net.neoforged.neoforge.common.Tags;
import net.neoforged.neoforge.common.data.ExistingFileHelper;
import org.jetbrains.annotations.Nullable;
import top.theillusivec4.curios.api.CuriosApi;

import java.util.concurrent.CompletableFuture;

Expand Down Expand Up @@ -66,11 +67,10 @@ private void addOptionalOreTagsForMinerCompat(HolderLookup.Provider provider) {
}

private void addCuriosTags(HolderLookup.Provider provider) {
//TODO: enable if we have curios again
// this.tag(OccultismTags.makeItemTag(ResourceLocation.fromNamespaceAndPath(CuriosApi.MODID, "belt"))).add(OccultismItems.SATCHEL.get()).replace(false);
// this.tag(OccultismTags.makeItemTag(ResourceLocation.fromNamespaceAndPath(CuriosApi.MODID, "hands"))).add(OccultismItems.STORAGE_REMOTE.get()).replace(false);
// this.tag(OccultismTags.makeItemTag(ResourceLocation.fromNamespaceAndPath(CuriosApi.MODID, "head"))).add(OccultismItems.OTHERWORLD_GOGGLES.get()).replace(false);
// this.tag(OccultismTags.makeItemTag(ResourceLocation.fromNamespaceAndPath(CuriosApi.MODID, "ring"))).add(OccultismItems.FAMILIAR_RING.get()).replace(false);
this.tag(OccultismTags.makeItemTag(ResourceLocation.fromNamespaceAndPath(CuriosApi.MODID, "belt"))).add(OccultismItems.SATCHEL.get()).replace(false);
this.tag(OccultismTags.makeItemTag(ResourceLocation.fromNamespaceAndPath(CuriosApi.MODID, "hands"))).add(OccultismItems.STORAGE_REMOTE.get()).replace(false);
this.tag(OccultismTags.makeItemTag(ResourceLocation.fromNamespaceAndPath(CuriosApi.MODID, "head"))).add(OccultismItems.OTHERWORLD_GOGGLES.get()).replace(false);
this.tag(OccultismTags.makeItemTag(ResourceLocation.fromNamespaceAndPath(CuriosApi.MODID, "ring"))).add(OccultismItems.FAMILIAR_RING.get()).replace(false);
}

private void addOccultismTags(HolderLookup.Provider provider) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,24 @@
package com.klikli_dev.occultism.registry;

import com.klikli_dev.occultism.common.blockentity.StorageControllerBlockEntity;
import com.klikli_dev.occultism.common.item.tool.FamiliarRingItem;
import net.minecraft.core.Direction;
import net.neoforged.neoforge.capabilities.Capabilities;
import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent;
import top.theillusivec4.curios.api.CuriosCapability;

public class OccultismCapabilities {

public static void onRegisterCapabilities(RegisterCapabilitiesEvent event) {

//TODO: Re-enable once curios is available again
// event.registerItem(
// CuriosCapability.ITEM, // capability to register for
// (itemStack, context) -> {
// return new FamiliarRingItem.Curio(itemStack);
// },
// // items to register for
// OccultismItems.FAMILIAR_RING.get()
// );
event.registerItem(
CuriosCapability.ITEM, // capability to register for
(itemStack, context) -> {
return new FamiliarRingItem.Curio(itemStack);
},
// items to register for
OccultismItems.FAMILIAR_RING.get()
);

event.registerBlockEntity(
Capabilities.ItemHandler.BLOCK,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,8 @@ public class OccultismItems {
.component(OccultismDataComponents.SPIRIT_NAME, "(Not yet known)")
));

//TODO: Re-enable familiar ring once we have curios
public static final DeferredItem<Item> FAMILIAR_RING = ITEMS.register("familiar_ring",
// () -> new FamiliarRingItem(defaultProperties().stacksTo(1)));
() -> new Item(defaultProperties().stacksTo(1).component(OccultismDataComponents.SPIRIT_NAME, "(Not yet known)")));
() -> new FamiliarRingItem(defaultProperties().stacksTo(1).component(OccultismDataComponents.SPIRIT_NAME, "(Not yet known)")));

public static final DeferredItem<Item> PURIFIED_INK = ITEMS.register("purified_ink",
() -> new Item(defaultProperties()));
Expand Down Expand Up @@ -512,7 +510,7 @@ public static boolean shouldSkipCreativeModTab(Item item) {
|| item == JEI_DUMMY_NONE.get()
|| item == JEI_DUMMY_REQUIRE_SACRIFICE.get()
|| item == JEI_DUMMY_REQUIRE_ITEM_USE.get()
|| item == FAMILIAR_RING.get() //TODO: Re-enable familiar ring once we have curios
// || item == FAMILIAR_RING.get()
)
return true;

Expand Down
126 changes: 63 additions & 63 deletions src/main/java/com/klikli_dev/occultism/util/CuriosUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,65 +28,66 @@
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import top.theillusivec4.curios.api.CuriosCapability;
import top.theillusivec4.curios.api.type.capability.ICuriosItemHandler;
import top.theillusivec4.curios.api.type.inventory.ICurioStacksHandler;
import top.theillusivec4.curios.api.type.inventory.IDynamicStackHandler;

public class CuriosUtil {
public static boolean hasGoggles(Player player) {
ItemStack helmet = player.getItemBySlot(EquipmentSlot.HEAD);
if (OtherworldGogglesItem.isGogglesItem(helmet))
return true;

return false;
//TODO: Enable once curios is available again
// var curiosHandler = player.getCapability(CuriosCapability.INVENTORY);
// if (curiosHandler == null)
// return false;
//
// var slotsHandler = curiosHandler.getCurios().values();
// return slotsHandler.stream().map(ICurioStacksHandler::getStacks).anyMatch(
// stackHandler -> {
// for (int i = 0; i < stackHandler.getSlots(); i++) {
// ItemStack stack = stackHandler.getStackInSlot(i);
// if (OtherworldGogglesItem.isGogglesItem(stack)) {
// return true;
//
// }
// }
// return false;
// }
// );
var curiosHandler = player.getCapability(CuriosCapability.INVENTORY);
if (curiosHandler == null)
return false;

var slotsHandler = curiosHandler.getCurios().values();
return slotsHandler.stream().map(ICurioStacksHandler::getStacks).anyMatch(
stackHandler -> {
for (int i = 0; i < stackHandler.getSlots(); i++) {
ItemStack stack = stackHandler.getStackInSlot(i);
if (OtherworldGogglesItem.isGogglesItem(stack)) {
return true;

}
}
return false;
}
);
}

public static ItemStack getBackpack(Player player) {
var curiosHandler = player.getCapability(CuriosCapability.INVENTORY);
if (curiosHandler == null)
return ItemStack.EMPTY;

for (var curio : curiosHandler.getCurios().keySet()) {
var stack = getSatchelItemFromSlot(curiosHandler, curio);
if (!stack.isEmpty()) {
return stack;
}
}
return ItemStack.EMPTY;
// var curiosHandler = player.getCapability(CuriosCapability.INVENTORY);
// if (curiosHandler == null)
// return ItemStack.EMPTY;
//
// for (var curio : curiosHandler.getCurios().keySet()) {
// var stack = getSatchelItemFromSlot(curiosHandler, curio);
// if (!stack.isEmpty()) {
// return stack;
// }
// }
// return ItemStack.EMPTY;
}

// protected static ItemStack getSatchelItemFromSlot(ICuriosItemHandler curiosHandler, String identifier) {
// ICurioStacksHandler slotHandler = curiosHandler.getStacksHandler(identifier).orElse(null);
// if (slotHandler == null) {
// return ItemStack.EMPTY;
// }
//
// IDynamicStackHandler stackHandler = slotHandler.getStacks();
// for (int i = 0; i < stackHandler.getSlots(); i++) {
// ItemStack stack = stackHandler.getStackInSlot(i);
// if (stack.getItem() instanceof SatchelItem) {
// return stack;
// }
// }
//
// return ItemStack.EMPTY;
// }
protected static ItemStack getSatchelItemFromSlot(ICuriosItemHandler curiosHandler, String identifier) {
ICurioStacksHandler slotHandler = curiosHandler.getStacksHandler(identifier).orElse(null);
if (slotHandler == null) {
return ItemStack.EMPTY;
}

IDynamicStackHandler stackHandler = slotHandler.getStacks();
for (int i = 0; i < stackHandler.getSlots(); i++) {
ItemStack stack = stackHandler.getStackInSlot(i);
if (stack.getItem() instanceof SatchelItem) {
return stack;
}
}

return ItemStack.EMPTY;
}


public static SelectedCurio getStorageRemote(Player player) {
Expand All @@ -113,23 +114,22 @@ public static SelectedCurio getStorageRemote(Player player) {
}

public static ItemStack getStorageRemoteCurio(Player player) {
return ItemStack.EMPTY;
// ICuriosItemHandler curiosHandler = player.getCapability(CuriosCapability.INVENTORY);
// ItemStack hasStorageRemote = ItemStack.EMPTY;
// for (ICurioStacksHandler curiosStackshandler : curiosHandler.getCurios().values()) {
// IDynamicStackHandler stackHandler = curiosStackshandler.getStacks();
// for (int i = 0; i < stackHandler.getSlots(); i++) {
// ItemStack stack = stackHandler.getStackInSlot(i);
// if (stack.getItem() instanceof StorageRemoteItem) {
// hasStorageRemote = stack;
// break;
// }
// }
// if (!hasStorageRemote.isEmpty()) {
// break;
// }
// }
// return hasStorageRemote;
ICuriosItemHandler curiosHandler = player.getCapability(CuriosCapability.INVENTORY);
ItemStack hasStorageRemote = ItemStack.EMPTY;
for (ICurioStacksHandler curiosStackshandler : curiosHandler.getCurios().values()) {
IDynamicStackHandler stackHandler = curiosStackshandler.getStacks();
for (int i = 0; i < stackHandler.getSlots(); i++) {
ItemStack stack = stackHandler.getStackInSlot(i);
if (stack.getItem() instanceof StorageRemoteItem) {
hasStorageRemote = stack;
break;
}
}
if (!hasStorageRemote.isEmpty()) {
break;
}
}
return hasStorageRemote;
}

public static int getFirstBackpackSlot(Player player) {
Expand Down
Loading

0 comments on commit 45836e8

Please sign in to comment.