re-added curios compat

This commit is contained in:
Ell 2020-09-22 16:16:25 +02:00
parent af05de4708
commit 572a63fe20
8 changed files with 67 additions and 48 deletions

View file

@ -0,0 +1,7 @@
{
"replace": false,
"values": [
"naturesaura:aura_cache",
"naturesaura:aura_trove"
]
}

View file

@ -0,0 +1,7 @@
{
"replace": false,
"values": [
"naturesaura:eye",
"naturesaura:eye_improved"
]
}

View file

@ -0,0 +1,6 @@
{
"replace": false,
"values": [
"naturesaura:shockwave_creator"
]
}

View file

@ -0,0 +1,6 @@
{
"replace": false,
"values": [
"naturesaura:death_ring"
]
}

View file

@ -46,6 +46,7 @@ import net.minecraftforge.registries.IForgeRegistry;
import net.minecraftforge.registries.IForgeRegistryEntry; import net.minecraftforge.registries.IForgeRegistryEntry;
import org.apache.commons.lang3.tuple.ImmutableTriple; import org.apache.commons.lang3.tuple.ImmutableTriple;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import top.theillusivec4.curios.api.CuriosApi;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -331,10 +332,9 @@ public final class Helper {
public static ItemStack getEquippedItem(Predicate<ItemStack> predicate, PlayerEntity player) { public static ItemStack getEquippedItem(Predicate<ItemStack> predicate, PlayerEntity player) {
if (Compat.hasCompat("curios")) { if (Compat.hasCompat("curios")) {
// TODO curios Optional<ItemStack> stack = CuriosApi.getCuriosHelper().findEquippedCurio(predicate, player).map(ImmutableTriple::getRight);
/* Optional<ItemStack> stack = CuriosAPI.getCurioEquipped(predicate, player).map(ImmutableTriple::getRight);
if (stack.isPresent()) if (stack.isPresent())
return stack.get();*/ return stack.get();
} }
for (int i = 0; i < player.inventory.getSizeInventory(); i++) { for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
ItemStack slot = player.inventory.getStackInSlot(i); ItemStack slot = player.inventory.getStackInSlot(i);

View file

@ -7,6 +7,8 @@ import de.ellpeck.naturesaura.items.ModItems;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.tags.ITag;
import net.minecraft.tags.ItemTags;
import net.minecraft.tags.Tag; import net.minecraft.tags.Tag;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
@ -20,41 +22,29 @@ import net.minecraftforge.fml.InterModComms;
import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent; import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import top.theillusivec4.curios.api.CuriosCapability; import top.theillusivec4.curios.api.CuriosCapability;
import top.theillusivec4.curios.api.SlotTypeMessage;
import top.theillusivec4.curios.api.SlotTypePreset;
import top.theillusivec4.curios.api.type.capability.ICurio;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Map; import java.util.Map;
// TODO curios
public class CuriosCompat implements ICompat { public class CuriosCompat implements ICompat {
@Override
public void setup() {
} private static final Map<Item, String> TYPES = ImmutableMap.<Item, String>builder()
.put(ModItems.EYE, "charm")
@Override .put(ModItems.EYE_IMPROVED, "charm")
public void setupClient() { .put(ModItems.AURA_CACHE, "belt")
.put(ModItems.AURA_TROVE, "belt")
} .put(ModItems.SHOCKWAVE_CREATOR, "necklace")
.put(ModItems.DEATH_RING, "ring")
@Override
public void addItemTags(ItemTagProvider provider) {
}
/*private static final Map<Item, Tag<Item>> TYPES = ImmutableMap.<Item, Tag<Item>>builder()
.put(ModItems.EYE, CurioTags.CHARM)
.put(ModItems.EYE_IMPROVED, CurioTags.CHARM)
.put(ModItems.AURA_CACHE, CurioTags.BELT)
.put(ModItems.AURA_TROVE, CurioTags.BELT)
.put(ModItems.SHOCKWAVE_CREATOR, CurioTags.NECKLACE)
.put(ModItems.DEATH_RING, CurioTags.RING)
.build(); .build();
@Override @Override
public void setup() { public void setup() {
FMLJavaModLoadingContext.get().getModEventBus().register(this); // inter mod comms FMLJavaModLoadingContext.get().getModEventBus().addListener(this::sendImc);
MinecraftForge.EVENT_BUS.register(this); // capabilities MinecraftForge.EVENT_BUS.addGenericListener(ItemStack.class, this::onCapabilitiesAttach);
} }
@Override @Override
@ -62,16 +52,11 @@ public class CuriosCompat implements ICompat {
} }
@SubscribeEvent private void sendImc(InterModEnqueueEvent event) {
public void sendImc(InterModEnqueueEvent event) { TYPES.values().stream().distinct().forEach(t -> InterModComms.sendTo("curios", SlotTypeMessage.REGISTER_TYPE, () -> new SlotTypeMessage.Builder(t).build()));
TYPES.values().stream().distinct().forEach(t -> {
String path = t.getId().getPath();
InterModComms.sendTo("curios", CuriosAPI.IMC.REGISTER_TYPE, () -> new CurioIMCMessage(path));
});
} }
@SubscribeEvent private void onCapabilitiesAttach(AttachCapabilitiesEvent<ItemStack> event) {
public void onCapabilitiesAttach(AttachCapabilitiesEvent<ItemStack> event) {
ItemStack stack = event.getObject(); ItemStack stack = event.getObject();
if (TYPES.containsKey(stack.getItem())) { if (TYPES.containsKey(stack.getItem())) {
event.addCapability(new ResourceLocation(NaturesAura.MOD_ID, "curios"), new ICapabilityProvider() { event.addCapability(new ResourceLocation(NaturesAura.MOD_ID, "curios"), new ICapabilityProvider() {
@ -82,8 +67,9 @@ public class CuriosCompat implements ICompat {
return LazyOptional.empty(); return LazyOptional.empty();
return LazyOptional.of(() -> (T) new ICurio() { return LazyOptional.of(() -> (T) new ICurio() {
@Override @Override
public void onCurioTick(String identifier, int index, LivingEntity livingEntity) { public void curioTick(String identifier, int index, LivingEntity livingEntity) {
stack.getItem().inventoryTick(stack, livingEntity.world, livingEntity, -1, false); stack.getItem().inventoryTick(stack, livingEntity.world, livingEntity, -1, false);
} }
@Override @Override
@ -92,7 +78,7 @@ public class CuriosCompat implements ICompat {
} }
@Override @Override
public boolean shouldSyncToTracking(String identifier, LivingEntity livingEntity) { public boolean canSync(String identifier, int index, LivingEntity livingEntity) {
return true; return true;
} }
}); });
@ -103,7 +89,9 @@ public class CuriosCompat implements ICompat {
@Override @Override
public void addItemTags(ItemTagProvider provider) { public void addItemTags(ItemTagProvider provider) {
for (Map.Entry<Item, Tag<Item>> entry : TYPES.entrySet()) for (Map.Entry<Item, String> entry : TYPES.entrySet()) {
provider.getBuilder(entry.getValue()).add(entry.getKey()); ITag.INamedTag<Item> tag = ItemTags.createOptional(new ResourceLocation("curios", entry.getValue()));
}*/ provider.getOrCreateBuilder(tag).add(entry.getKey());
}
}
} }

View file

@ -7,6 +7,7 @@ import net.minecraft.data.DataGenerator;
import net.minecraft.data.ItemTagsProvider; import net.minecraft.data.ItemTagsProvider;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.tags.BlockTags; import net.minecraft.tags.BlockTags;
import net.minecraft.tags.ITag;
import net.minecraft.tags.ItemTags; import net.minecraft.tags.ItemTags;
import net.minecraft.tags.Tag; import net.minecraft.tags.Tag;
import net.minecraftforge.common.Tags; import net.minecraftforge.common.Tags;
@ -30,4 +31,9 @@ public class ItemTagProvider extends ItemTagsProvider {
Compat.addItemTags(this); Compat.addItemTags(this);
} }
@Override
public Builder<Item> getOrCreateBuilder(ITag.INamedTag<Item> tag) {
return super.getOrCreateBuilder(tag);
}
} }

View file

@ -19,6 +19,9 @@ import net.minecraft.util.math.vector.Vector3f;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandler;
import top.theillusivec4.curios.api.CuriosApi;
import top.theillusivec4.curios.api.type.capability.ICuriosItemHandler;
import top.theillusivec4.curios.api.type.inventory.ICurioStacksHandler;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
@ -60,15 +63,11 @@ public class PlayerLayerTrinkets extends LayerRenderer<AbstractClientPlayerEntit
} }
if (Compat.hasCompat("curios")) { if (Compat.hasCompat("curios")) {
// TODO curios IItemHandler handler = CuriosApi.getCuriosHelper().getEquippedCurios(player).orElse(null);
/*ICurioItemHandler handler = CuriosAPI.getCuriosHandler(player).orElse(null);
if (handler != null) { if (handler != null) {
for (IItemHandler items : handler.getCurioMap().values()) { for (int i = 0; i < handler.getSlots(); i++)
for (int i = 0; i < items.getSlots(); i++) { this.renderStack(handler.getStackInSlot(i), player, type, main, second, matrices, buffer, packedLight);
this.renderStack(items.getStackInSlot(i), player, type, main, second, matrices, buffer, packedLight); }
}
}
}*/
} }
} }