generated from NeoForgeMDKs/MDK-1.21-NeoGradle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
160 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...lities/augmentation/AugmentationSlot.java → ...odjam/capabilities/augmentation/Slot.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/com/portingdeadmods/modjam/content/augments/AugmentHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/com/portingdeadmods/modjam/content/items/AugmentDebugItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/main/java/com/portingdeadmods/modjam/events/PlayerCloneEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/com/portingdeadmods/modjam/registries/MJDataAttachments.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters