Skip to content

Commit

Permalink
New Augmentation impl
Browse files Browse the repository at this point in the history
  • Loading branch information
ktpatient committed Sep 6, 2024
1 parent c473f08 commit 1df1802
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/main/java/com/portingdeadmods/modjam/ModJam.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.portingdeadmods.modjam.content.items.PrismMonocleItem;
import com.portingdeadmods.modjam.data.MJDataComponents;
import com.portingdeadmods.modjam.registries.*;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.event.entity.player.PlayerEvent;
import net.neoforged.neoforge.registries.NewRegistryEvent;
import org.slf4j.Logger;

Expand All @@ -23,6 +25,7 @@ public ModJam(IEventBus modEventBus, ModContainer modContainer) {

MJItems.ITEMS.register(modEventBus);
MJBlocks.BLOCKS.register(modEventBus);
MJDataAttachments.ATTACHMENTS.register(modEventBus);
MJFluids.FLUIDS.register(modEventBus);
MJFluidTypes.FLUID_TYPES.register(modEventBus);
MJCreativeTabs.CREATIVE_MODE_TABS.register(modEventBus);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.portingdeadmods.modjam.capabilities.augmentation;

public enum AugmentationSlot {
public enum Slot {
HEAD,BODY,ARMS,LEGS,HEART
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.portingdeadmods.modjam.content.augments;

import com.portingdeadmods.modjam.ModJam;
import com.portingdeadmods.modjam.capabilities.augmentation.Slot;
import com.portingdeadmods.modjam.registries.MJDataAttachments;
import net.minecraft.world.entity.player.Player;

public class AugmentHelper {
public static int getId(Player player, Slot slot){
switch (slot) {
case HEAD -> {
return player.getData(MJDataAttachments.HEAD_AUGMENTATION);
}
case BODY -> {
return player.getData(MJDataAttachments.BODY_AUGMENTATION);
}
case LEGS -> {
return player.getData(MJDataAttachments.LEGS_AUGMENTATION);
}
case ARMS -> {
return player.getData(MJDataAttachments.ARMS_AUGMENTATION);
}
case HEART -> {
return player.getData(MJDataAttachments.HEART_AUGMENTATION);
}
}
ModJam.LOGGER.warn("Error parsing Augment {}", slot.name());
return -2;
}

public static void setId(Player player, Slot slot , int id){
switch (slot){
case HEAD -> {
player.setData(MJDataAttachments.HEAD_AUGMENTATION, id);
}
case BODY -> {
player.setData(MJDataAttachments.BODY_AUGMENTATION, id);
}
case LEGS -> {
player.setData(MJDataAttachments.LEGS_AUGMENTATION, id);
}
case ARMS -> {
player.setData(MJDataAttachments.ARMS_AUGMENTATION, id);
}
case HEART -> {
player.setData(MJDataAttachments.HEART_AUGMENTATION, id);
}
}
}
public static void incId(Player player, Slot slot){
setId(player, slot, AugmentHelper.getId(player, slot) + 1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.portingdeadmods.modjam.content.items;

import com.portingdeadmods.modjam.capabilities.augmentation.Slot;
import com.portingdeadmods.modjam.content.augments.AugmentHelper;
import com.portingdeadmods.modjam.registries.MJDataAttachments;
import net.minecraft.network.chat.Component;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;

public class AugmentDebugItem extends Item {
public AugmentDebugItem(Properties properties) {
super(properties);
}

@Override
public boolean onDroppedByPlayer(ItemStack item, Player player) {
player.sendSystemMessage(Component.literal("Head Id = " + AugmentHelper.getId(player, Slot.HEAD)));
player.sendSystemMessage(Component.literal("Body Id = " + AugmentHelper.getId(player, Slot.BODY)));
return super.onDroppedByPlayer(item, player);
}

@Override
public InteractionResult useOn(UseOnContext context) {
Level level = context.getLevel();
Player player = context.getPlayer();

if (level.getBlockState(context.getClickedPos()) == Blocks.DIRT.defaultBlockState()){
AugmentHelper.incId(player, Slot.HEAD);
} else if (level.getBlockState(context.getClickedPos()) == Blocks.STONE.defaultBlockState()){
AugmentHelper.incId(player, Slot.BODY);
}


return super.useOn(context);
}
}
2 changes: 2 additions & 0 deletions src/main/java/com/portingdeadmods/modjam/events/MJEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.portingdeadmods.modjam.client.hud.PrismMonocleOverlay;
import com.portingdeadmods.modjam.client.renderer.blockentities.AquaticCatalystBERenderer;
import com.portingdeadmods.modjam.registries.MJBlockEntityTypes;
import com.portingdeadmods.modjam.registries.MJDataAttachments;
import net.minecraft.client.Camera;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.FogRenderer;
Expand All @@ -20,6 +21,7 @@
import net.neoforged.neoforge.client.event.RegisterGuiLayersEvent;
import net.neoforged.neoforge.client.extensions.common.IClientFluidTypeExtensions;
import net.neoforged.neoforge.client.extensions.common.RegisterClientExtensionsEvent;
import net.neoforged.neoforge.event.entity.player.PlayerEvent;
import net.neoforged.neoforge.fluids.FluidType;
import net.neoforged.neoforge.registries.NeoForgeRegistries;
import org.jetbrains.annotations.NotNull;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.portingdeadmods.modjam.events;

import com.portingdeadmods.modjam.ModJam;
import com.portingdeadmods.modjam.registries.MJDataAttachments;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.attachment.AttachmentType;
import net.neoforged.neoforge.event.entity.player.PlayerEvent;
import top.theillusivec4.curios.api.type.data.IEntitiesData;

import java.util.function.Supplier;

@EventBusSubscriber(modid = ModJam.MODID)
public class PlayerCloneEvent {
private static void copyPlayerAttachment(PlayerEvent.Clone event, Supplier<AttachmentType<Integer>> attachment){
if (event.isWasDeath() && event.getOriginal().hasData(attachment)){
event.getEntity().setData(attachment, event.getOriginal().getData(attachment));
}
}
@SubscribeEvent
public static void onPlayerClone(PlayerEvent.Clone event){
copyPlayerAttachment(event, MJDataAttachments.HEAD_AUGMENTATION);
copyPlayerAttachment(event, MJDataAttachments.BODY_AUGMENTATION);
copyPlayerAttachment(event, MJDataAttachments.ARMS_AUGMENTATION);
copyPlayerAttachment(event, MJDataAttachments.LEGS_AUGMENTATION);
copyPlayerAttachment(event, MJDataAttachments.HEART_AUGMENTATION);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.portingdeadmods.modjam.registries;

import com.mojang.serialization.Codec;
import com.portingdeadmods.modjam.ModJam;
import net.neoforged.neoforge.attachment.AttachmentType;
import net.neoforged.neoforge.registries.DeferredRegister;
import net.neoforged.neoforge.registries.NeoForgeRegistries;

import java.util.function.Supplier;

public class MJDataAttachments {
public static final DeferredRegister<AttachmentType<?>> ATTACHMENTS = DeferredRegister.create(NeoForgeRegistries.ATTACHMENT_TYPES, ModJam.MODID);

public static final Supplier<AttachmentType<Integer>> HEAD_AUGMENTATION = ATTACHMENTS.register(
"head_augment_id", ()-> AttachmentType.<Integer>builder(()->0).serialize(Codec.INT).build()
);
public static final Supplier<AttachmentType<Integer>> BODY_AUGMENTATION = ATTACHMENTS.register(
"body_augment_id", ()-> AttachmentType.<Integer>builder(()->0).serialize(Codec.INT).build()
);
public static final Supplier<AttachmentType<Integer>> ARMS_AUGMENTATION = ATTACHMENTS.register(
"arms_augment_id", ()-> AttachmentType.<Integer>builder(()->0).serialize(Codec.INT).build()
);
public static final Supplier<AttachmentType<Integer>> LEGS_AUGMENTATION = ATTACHMENTS.register(
"legs_augment_id", ()-> AttachmentType.<Integer>builder(()->0).serialize(Codec.INT).build()
);
public static final Supplier<AttachmentType<Integer>> HEART_AUGMENTATION = ATTACHMENTS.register(
"heart_augment_id", ()-> AttachmentType.<Integer>builder(()->0).serialize(Codec.INT).build()
);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.portingdeadmods.modjam.registries;

import com.portingdeadmods.modjam.ModJam;
import com.portingdeadmods.modjam.content.items.AugmentDebugItem;
import com.portingdeadmods.modjam.content.items.ExamplePowerItem;
import com.portingdeadmods.modjam.content.items.PrismMonocleItem;
import net.minecraft.world.item.BlockItem;
Expand All @@ -25,10 +26,11 @@ public final class MJItems {
Item::new, new Item.Properties());
public static final DeferredItem<PrismMonocleItem> PRISM_MONOCLE = registerItem("prism_monocle",
PrismMonocleItem::new, new Item.Properties());

public static final DeferredItem<BucketItem> SALT_WATER_BUCKET = registerItemBucket("salt_water_bucket",
() -> new BucketItem(MJFluids.SALT_WATER_SOURCE.get(), new Item.Properties().craftRemainder(Items.BUCKET).stacksTo(1)));

public static final DeferredItem<AugmentDebugItem> AUGMENT_DEBUG_ITEM = registerItem("augment_debug_item", AugmentDebugItem::new, new Item.Properties());

public static <T extends Item> DeferredItem<T> registerItem(String name, Function<Item.Properties, T> itemConstructor, Item.Properties properties) {
return registerItem(name, itemConstructor, properties, true);
}
Expand Down

0 comments on commit 1df1802

Please sign in to comment.