Skip to content

Commit

Permalink
Implement simple test augment
Browse files Browse the repository at this point in the history
  • Loading branch information
ktpatient committed Sep 6, 2024
1 parent 8f173c0 commit 3328300
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.portingdeadmods.modjam.content.augments;

import net.minecraft.world.entity.player.Player;
import net.neoforged.neoforge.event.level.BlockEvent;

@SuppressWarnings("unused")
public class Augment {
public static void onBreak(BlockEvent.BreakEvent event){
Player player = event.getPlayer();
event.setCanceled(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,52 @@
import com.portingdeadmods.modjam.ModJam;
import com.portingdeadmods.modjam.capabilities.augmentation.Slot;
import com.portingdeadmods.modjam.registries.MJDataAttachments;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Player;
import net.neoforged.neoforge.attachment.AttachmentType;

import java.util.function.Supplier;

public class AugmentHelper {
public static int getId(Player player, Slot slot){
switch (slot) {
private static Supplier<AttachmentType<Integer>> getAttachment(Slot slot){
switch (slot){
case HEAD -> {
return player.getData(MJDataAttachments.HEAD_AUGMENTATION);
return MJDataAttachments.HEAD_AUGMENTATION;
}
case BODY -> {
return player.getData(MJDataAttachments.BODY_AUGMENTATION);
return MJDataAttachments.BODY_AUGMENTATION;
}
case LEGS -> {
return player.getData(MJDataAttachments.LEGS_AUGMENTATION);
return MJDataAttachments.LEGS_AUGMENTATION;
}
case ARMS -> {
return player.getData(MJDataAttachments.ARMS_AUGMENTATION);
return MJDataAttachments.ARMS_AUGMENTATION;
}
case HEART -> {
return player.getData(MJDataAttachments.HEART_AUGMENTATION);
return MJDataAttachments.HEART_AUGMENTATION;
}
}
ModJam.LOGGER.warn("Error parsing Augment {}", slot.name());
return -2;
ModJam.LOGGER.warn("Error parsing slot {} (I thought this was unreachable)", slot.name());
return MJDataAttachments.HEAD_AUGMENTATION;
}
public static int getId(Player player, Slot slot){
return player.getData(getAttachment(slot));
// 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);
}
}
player.setData(getAttachment(slot), id);
}
public static void incId(Player player, Slot slot){
setId(player, slot, AugmentHelper.getId(player, slot) + 1);
player.sendSystemMessage(Component.literal("Incremented to Id "+getId(player, slot)+" for slot "+slot.name()));

}
public static void decId(Player player, Slot slot){
setId(player, slot, AugmentHelper.getId(player, slot) - 1);
player.sendSystemMessage(Component.literal("Decremented to Id "+getId(player, slot)+" for slot "+slot.name()));
}
public static boolean playerHasAugment(Player player, Slot slot, Augments augment){
return getId(player, slot) == augment.id;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.portingdeadmods.modjam.content.augments;

public enum Augments {
TEST_AUGMENT(69);

public final int id;
Augments(int id){
this.id = id;
}
}
Original file line number Diff line number Diff line change
@@ -1,38 +1,50 @@
package com.portingdeadmods.modjam.content.items;

import com.mojang.blaze3d.platform.InputConstants;
import com.portingdeadmods.modjam.capabilities.augmentation.Slot;
import com.portingdeadmods.modjam.content.augments.AugmentHelper;
import com.portingdeadmods.modjam.registries.MJDataAttachments;
import net.minecraft.client.Minecraft;
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.Block;
import net.minecraft.world.level.block.Blocks;
import org.jetbrains.annotations.NotNull;

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

@Override
public boolean onDroppedByPlayer(ItemStack item, Player player) {
public boolean onDroppedByPlayer(@NotNull 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) {
public @NotNull InteractionResult useOn(UseOnContext context) {
Level level = context.getLevel();
Player player = context.getPlayer();
Block clickedBlock = level.getBlockState(context.getClickedPos()).getBlock();

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);
if (clickedBlock == Blocks.DIRT){
if (InputConstants.isKeyDown(Minecraft.getInstance().getWindow().getWindow(),InputConstants.KEY_LSHIFT)){
AugmentHelper.decId(player, Slot.HEAD);
} else {
AugmentHelper.incId(player, Slot.HEAD);
}
} else if (clickedBlock == Blocks.STONE){
if (InputConstants.isKeyDown(Minecraft.getInstance().getWindow().getWindow(),InputConstants.KEY_LSHIFT)){
AugmentHelper.decId(player, Slot.BODY);
} else {
AugmentHelper.incId(player, Slot.BODY);
}
}


Expand Down
23 changes: 23 additions & 0 deletions src/main/java/com/portingdeadmods/modjam/events/AugmentEvents.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.portingdeadmods.modjam.events;

import com.portingdeadmods.modjam.ModJam;
import com.portingdeadmods.modjam.capabilities.augmentation.Slot;
import com.portingdeadmods.modjam.content.augments.Augment;
import com.portingdeadmods.modjam.content.augments.AugmentHelper;
import com.portingdeadmods.modjam.content.augments.Augments;
import net.minecraft.world.entity.player.Player;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.event.level.BlockEvent;

@SuppressWarnings("unused")
@EventBusSubscriber(modid = ModJam.MODID)
public class AugmentEvents {
@SubscribeEvent
public static void breakEvent(BlockEvent.BreakEvent event){
Player player = event.getPlayer();
if(AugmentHelper.playerHasAugment(player, Slot.HEAD, Augments.TEST_AUGMENT)){
Augment.onBreak(event);
}
}
}

0 comments on commit 3328300

Please sign in to comment.