Skip to content

Commit

Permalink
AH
Browse files Browse the repository at this point in the history
  • Loading branch information
SammySemicolon committed Dec 7, 2024
1 parent f544530 commit 63fd7d8
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import com.sammy.malum.client.screen.codex.pages.recipe.*;
import com.sammy.malum.client.screen.codex.pages.recipe.vanilla.*;
import com.sammy.malum.client.screen.codex.pages.text.*;
import com.sammy.malum.common.events.*;
import com.sammy.malum.common.item.codex.*;
import com.sammy.malum.core.systems.events.*;
import com.sammy.malum.registry.common.*;
import net.minecraft.client.*;
import net.minecraft.resources.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import com.sammy.malum.client.screen.codex.pages.text.HeadlineTextPage;
import com.sammy.malum.client.screen.codex.pages.text.TextPage;
import com.sammy.malum.client.screen.codex.pages.text.WeepingWellTextPage;
import com.sammy.malum.common.events.SetupMalumCodexEntriesEvent;
import com.sammy.malum.core.systems.events.SetupMalumCodexEntriesEvent;
import com.sammy.malum.common.item.codex.EncyclopediaEsotericaItem;
import com.sammy.malum.registry.common.SoundRegistry;
import net.minecraft.client.Minecraft;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,43 +26,31 @@ public class MalumItemDataCapability {

public static final Codec<MalumItemDataCapability> CODEC = RecordCodecBuilder.create(obj -> obj.group(
Codec.list(ItemStack.CODEC).fieldOf("soulsToDrop").forGetter(c -> c.soulsToDrop),
UUIDUtil.CODEC.fieldOf("attackerForSouls").forGetter(c -> c.attackerForSouls),
Codec.FLOAT.fieldOf("totalSoulCount").forGetter(c -> c.totalSoulCount)
UUIDUtil.CODEC.fieldOf("attackerForSouls").forGetter(c -> c.attackerForSouls)
).apply(obj, MalumItemDataCapability::new));

public List<ItemStack> soulsToDrop;
public UUID attackerForSouls;
public float totalSoulCount;

public MalumItemDataCapability() {}

public MalumItemDataCapability(List<ItemStack> soulsToDrop, UUID attackerForSouls, float totalSoulCount) {
public MalumItemDataCapability(List<ItemStack> soulsToDrop, UUID attackerForSouls) {
this.soulsToDrop = soulsToDrop;
this.attackerForSouls = attackerForSouls;
this.totalSoulCount = totalSoulCount;
}

public static void registerCapabilities(RegisterCapabilitiesEvent event) {
event.registerEntity(CAPABILITY, EntityType.ITEM, GET_CAPABILITY);
public static void registerItemDataCapability(RegisterCapabilitiesEvent event) {
event.registerEntity(CAPABILITY, EntityType.ITEM, (item, ctx) -> {
CompoundTag tag = item.getPersistentData();
return CodecUtil.decodeNBT(MalumItemDataCapability.CODEC, tag);
});
}

public static ICapabilityProvider<ItemEntity, Void, MalumItemDataCapability> GET_CAPABILITY = (item, ctx) -> {
CompoundTag tag = item.getPersistentData();
return CodecUtil.decodeNBT(MalumItemDataCapability.CODEC, tag);
};

public static Optional<MalumItemDataCapability> getCapabilityOptional(ItemEntity entity) {
return Optional.ofNullable(entity.getCapability(CAPABILITY));
}

public static MalumItemDataCapability getCapability(ItemEntity entity) {
return getCapabilityOptional(entity).orElse(new MalumItemDataCapability(null, null, 0));
}

public void pullFromNBT(CompoundTag tag) {
MalumItemDataCapability capability = CodecUtil.decodeNBT(CODEC, tag);
this.soulsToDrop = capability.soulsToDrop;
this.attackerForSouls = capability.attackerForSouls;
this.totalSoulCount = capability.totalSoulCount;
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/sammy/malum/core/events/SetupEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ public class SetupEvents {
public static void registerCapabilities(RegisterCapabilitiesEvent event) {
MalumPlayerDataCapability.registerCapabilities(event);
MalumLivingEntityDataCapability.registerCapabilities(event);
MalumItemDataCapability.registerCapabilities(event);
MalumItemDataCapability.registerItemDataCapability(event);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,9 @@ private static void createSpiritEntities(Level level, Collection<ItemStack> spir
}
boolean noFancySpirits = CommonConfig.NO_FANCY_SPIRITS.getConfigValue();
for (int j = 0; j < stack.getCount(); j++) {
final ItemStack droppedSpirit = ItemHelper.copyWithNewCount(stack, 1);
if (noFancySpirits) {
ItemEntity itemEntity = new ItemEntity(level, position.x, position.y, position.z, stack);
ItemEntity itemEntity = new ItemEntity(level, position.x, position.y, position.z, droppedSpirit);
itemEntity.setDefaultPickUpDelay();
itemEntity.setDeltaMovement(
Mth.nextFloat(random, -0.1F, 0.1F),
Expand All @@ -220,7 +221,7 @@ private static void createSpiritEntities(Level level, Collection<ItemStack> spir
level.addFreshEntity(itemEntity);
continue;
}
SpiritItemEntity entity = new SpiritItemEntity(level, attackerUUID, ItemHelper.copyWithNewCount(stack, 1),
SpiritItemEntity entity = new SpiritItemEntity(level, attackerUUID, droppedSpirit,
position.x,
position.y,
position.z,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.sammy.malum.common.events;
package com.sammy.malum.core.systems.events;


import net.neoforged.bus.api.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public class RunicWorkbenchRecipeBuilder implements AutonamedRecipeBuilder<Runic
private ItemStack primaryInput;
private SpiritIngredient secondaryInput;
private final ItemStack output;
private final Map<String, Criterion<?>> criteria = new LinkedHashMap<>();

public RunicWorkbenchRecipeBuilder(ItemStack output) {
this.output = output;
Expand Down

0 comments on commit 63fd7d8

Please sign in to comment.