diff --git a/src/main/generated/data/acesbs/loot_table/blocks/ordered_core.json b/src/main/generated/data/acesbs/loot_table/blocks/ordered_core.json new file mode 100644 index 0000000..d93d3ae --- /dev/null +++ b/src/main/generated/data/acesbs/loot_table/blocks/ordered_core.json @@ -0,0 +1,20 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "bonus_rolls": 0.0, + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ], + "entries": [ + { + "type": "minecraft:item", + "name": "acesbs:ordered_core" + } + ], + "rolls": 1.0 + } + ] +} \ No newline at end of file diff --git a/src/main/java/com/acethewildfire/acesbs/AcesBS.java b/src/main/java/com/acethewildfire/acesbs/AcesBS.java index 82c46f1..59719fe 100644 --- a/src/main/java/com/acethewildfire/acesbs/AcesBS.java +++ b/src/main/java/com/acethewildfire/acesbs/AcesBS.java @@ -7,7 +7,6 @@ import com.acethewildfire.acesbs.effect.ModEffects; import com.acethewildfire.acesbs.enchantment.ModEnchantmentEffects; import com.acethewildfire.acesbs.entity.ModEntities; import com.acethewildfire.acesbs.entity.custom.FrenEntity; -import com.acethewildfire.acesbs.entity.custom.VulgarBones; import com.acethewildfire.acesbs.item.ModItemGroups; import com.acethewildfire.acesbs.item.ModItems; import com.acethewildfire.acesbs.particle.ModParticles; @@ -20,12 +19,15 @@ import com.acethewildfire.acesbs.world.gen.ModWorldGeneration; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.event.player.AttackEntityCallback; import net.fabricmc.fabric.api.event.player.PlayerBlockBreakEvents; +import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry; +import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; import net.fabricmc.fabric.api.object.builder.v1.entity.FabricDefaultAttributeRegistry; import net.fabricmc.fabric.api.registry.CompostingChanceRegistry; import net.fabricmc.fabric.api.registry.FabricBrewingRecipeRegistryBuilder; import net.fabricmc.fabric.api.registry.FlammableBlockRegistry; import net.fabricmc.fabric.api.registry.StrippableBlockRegistry; import net.minecraft.entity.mob.SkeletonEntity; +import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.potion.Potions; import org.slf4j.Logger; @@ -94,5 +96,26 @@ public class AcesBS implements ModInitializer { FabricDefaultAttributeRegistry.register(ModEntities.FREN, FrenEntity.createAttributes()); FabricDefaultAttributeRegistry.register(ModEntities.VULGAR_BONES, SkeletonEntity.createAbstractSkeletonAttributes()); + + PayloadTypeRegistry.playC2S().register( + ModPackets.SetCommandPayload.ID, + ModPackets.SetCommandPayload.CODEC + ); + + ServerPlayNetworking.registerGlobalReceiver( + ModPackets.SetCommandPayload.ID, + (payload, context) -> { + + context.server().execute(() -> { + + var player = context.player(); + ItemStack stack = player.getMainHandStack(); + + stack.set(ModDataComponentTypes.COMMAND, payload.option()); + + }); + + } + ); } } \ No newline at end of file diff --git a/src/main/java/com/acethewildfire/acesbs/component/ModDataComponentTypes.java b/src/main/java/com/acethewildfire/acesbs/component/ModDataComponentTypes.java index 651a08d..8ae4612 100644 --- a/src/main/java/com/acethewildfire/acesbs/component/ModDataComponentTypes.java +++ b/src/main/java/com/acethewildfire/acesbs/component/ModDataComponentTypes.java @@ -3,6 +3,7 @@ package com.acethewildfire.acesbs.component; import com.acethewildfire.acesbs.AcesBS; import com.mojang.serialization.Codec; import net.minecraft.component.ComponentType; +import net.minecraft.network.codec.PacketCodecs; import net.minecraft.registry.Registries; import net.minecraft.registry.Registry; import net.minecraft.util.Identifier; @@ -18,6 +19,13 @@ public class ModDataComponentTypes { public static final ComponentType SMOKING = register("smoking", booleanBuilder -> booleanBuilder.codec(Codec.BOOL)); + public static final ComponentType COMMAND = + register("command", stringBuilder -> stringBuilder.codec(Codec.STRING).packetCodec(PacketCodecs.STRING)); + + public static final ComponentType COMMAND_ACTIVE = + register("command_active", booleanBuilder -> booleanBuilder.codec(Codec.BOOL).packetCodec(PacketCodecs.BOOL)); + + private static ComponentType register(String name, UnaryOperator> builderOperator){ return Registry.register(Registries.DATA_COMPONENT_TYPE, Identifier.of(AcesBS.MOD_ID, name), builderOperator.apply(ComponentType.builder()).build()); diff --git a/src/main/java/com/acethewildfire/acesbs/datagen/ModLootTableProvider.java b/src/main/java/com/acethewildfire/acesbs/datagen/ModLootTableProvider.java index 7f88ee0..3ab7d23 100644 --- a/src/main/java/com/acethewildfire/acesbs/datagen/ModLootTableProvider.java +++ b/src/main/java/com/acethewildfire/acesbs/datagen/ModLootTableProvider.java @@ -83,6 +83,8 @@ public class ModLootTableProvider extends FabricBlockLootTableProvider { addDrop(ModBlocks.LEMONWOOD_DOOR, doorDrops(ModBlocks.LEMONWOOD_DOOR)); addDrop(ModBlocks.LEMONWOOD_TRAPDOOR); + addDrop(ModBlocks.ORDERED_CORE); + addDrop(ModBlocks.ENTROPY_ORE, prismaSteelOreDrops(ModBlocks.ENTROPY_ORE, ModItems.RAW_ENTROPY, 1, 3)); addDrop(ModBlocks.DEEPSLATE_ENTROPY_ORE, prismaSteelOreDrops(ModBlocks.DEEPSLATE_ENTROPY_ORE, ModItems.RAW_ENTROPY, 1, 3)); addDrop(ModBlocks.INFERNAL_ASHES_ORE, prismaSteelOreDrops(ModBlocks.INFERNAL_ASHES_ORE, ModItems.INFERNAL_ASHES, 1, 3)); diff --git a/src/main/java/com/acethewildfire/acesbs/item/ModItemGroups.java b/src/main/java/com/acethewildfire/acesbs/item/ModItemGroups.java index 642f942..0a4bfd6 100644 --- a/src/main/java/com/acethewildfire/acesbs/item/ModItemGroups.java +++ b/src/main/java/com/acethewildfire/acesbs/item/ModItemGroups.java @@ -124,6 +124,7 @@ public class ModItemGroups { entries.add(PrismaSteelItems.PRISMA_STEEL_HAMMER); entries.add(PrismaSteelItems.PRISMA_STEEL_AXE); entries.add(PrismaSteelItems.PRISMA_STEEL_HOE); + entries.add(ModItems.COMMAND_CORE); diff --git a/src/main/java/com/acethewildfire/acesbs/item/ModItems.java b/src/main/java/com/acethewildfire/acesbs/item/ModItems.java index 0fd4318..35d1e39 100644 --- a/src/main/java/com/acethewildfire/acesbs/item/ModItems.java +++ b/src/main/java/com/acethewildfire/acesbs/item/ModItems.java @@ -2,24 +2,31 @@ package com.acethewildfire.acesbs.item; import com.acethewildfire.acesbs.AcesBS; import com.acethewildfire.acesbs.block.ModBlocks; +import com.acethewildfire.acesbs.component.ModDataComponentTypes; import com.acethewildfire.acesbs.entity.ModEntities; import com.acethewildfire.acesbs.item.custom.*; import com.acethewildfire.acesbs.potion.ModPotions; import com.acethewildfire.acesbs.sounds.ModSounds; +import net.fabricmc.fabric.api.event.player.AttackEntityCallback; import net.minecraft.client.gui.screen.Screen; import net.minecraft.component.DataComponentTypes; import net.minecraft.component.type.*; +import net.minecraft.entity.LivingEntity; import net.minecraft.entity.attribute.EntityAttributeModifier; import net.minecraft.entity.attribute.EntityAttributes; +import net.minecraft.entity.effect.StatusEffectInstance; +import net.minecraft.entity.effect.StatusEffects; import net.minecraft.item.*; import net.minecraft.item.tooltip.TooltipType; import net.minecraft.registry.Registries; import net.minecraft.registry.Registry; import net.minecraft.text.Text; +import net.minecraft.util.ActionResult; import net.minecraft.util.Formatting; import net.minecraft.util.Identifier; import java.util.List; +import java.util.Objects; public class ModItems { public static final Item ORACLE_LEMON = registerItem("oracle_lemon", new OracleLemon(new Item.Settings().component(DataComponentTypes.POTION_CONTENTS, new PotionContentsComponent(ModPotions.LEMON)))); @@ -96,6 +103,8 @@ public class ModItems { } }); + public static final Item COMMAND_CORE = registerItem("command_core", new CommandCore(new Item.Settings().maxCount(1))); + public static final Item KAUPEN_BOW = registerItem("kaupen_bow", new BowItem(new Item.Settings().maxDamage(500)) { @Override @@ -200,6 +209,27 @@ public class ModItems { PrismaSteelItems.registerPrismaItems(); AcesBS.LOGGER.info("Registering Mod Items for " + AcesBS.MOD_ID); + AttackEntityCallback.EVENT.register((player, world, hand, entity, hitResult) -> { + + // To you who reads this now, weep, as I did when I created this monster whom I have become + if (!world.isClient && entity instanceof LivingEntity target) { + for (ItemStack stack : player.getInventory().main) { + if (stack.isOf(ModItems.COMMAND_CORE)) { + if (Boolean.TRUE.equals(stack.get(ModDataComponentTypes.COMMAND_ACTIVE))){ + if (Objects.equals(stack.get(ModDataComponentTypes.COMMAND), "Omnipotence")){ + // 30 seconds = 600 ticks + target.addStatusEffect( + new StatusEffectInstance(StatusEffects.GLOWING, 600, 0) + ); + } + }; + } + } + } + + return ActionResult.PASS; + }); + // ItemGroupEvents.modifyEntriesEvent(ItemGroups.INGREDIENTS).register(fabricItemGroupEntries -> { // fabricItemGroupEntries.add(ORACLE_LEMON); // }); diff --git a/src/main/java/com/acethewildfire/acesbs/item/custom/CommandCore.java b/src/main/java/com/acethewildfire/acesbs/item/custom/CommandCore.java new file mode 100644 index 0000000..7a3a968 --- /dev/null +++ b/src/main/java/com/acethewildfire/acesbs/item/custom/CommandCore.java @@ -0,0 +1,85 @@ +package com.acethewildfire.acesbs.item.custom; + +import com.acethewildfire.acesbs.component.ModDataComponentTypes; +import com.acethewildfire.acesbs.screen.custom.CommandCoreScreen; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.component.DataComponentTypes; +import net.minecraft.entity.Entity; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.effect.StatusEffects; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.item.tooltip.TooltipType; +import net.minecraft.text.Text; +import net.minecraft.util.Hand; +import net.minecraft.util.TypedActionResult; +import net.minecraft.world.World; + +import java.util.List; + +public class CommandCore extends Item { + public CommandCore(Settings settings) { + super(settings); + } + + @Override + public TypedActionResult use(World world, PlayerEntity user, Hand hand) { + ItemStack itemStack = user.getStackInHand(hand); + + if (user.isInSneakingPose()){ + if (Boolean.TRUE.equals(itemStack.get(ModDataComponentTypes.COMMAND_ACTIVE))){ + itemStack.set(ModDataComponentTypes.COMMAND_ACTIVE, false); + itemStack.set(DataComponentTypes.ENCHANTMENT_GLINT_OVERRIDE, false); + } else { + itemStack.set(ModDataComponentTypes.COMMAND_ACTIVE, true); + itemStack.set(DataComponentTypes.ENCHANTMENT_GLINT_OVERRIDE, true); + } + } else { + if (world.isClient) { + // Open the selection screen client-side + MinecraftClient.getInstance().setScreen( + new CommandCoreScreen(itemStack) + ); + } + } + + + return TypedActionResult.success(user.getStackInHand(hand)); + } + + @Override + public void appendTooltip(ItemStack stack, TooltipContext context, List tooltip, TooltipType type) { + if(!Screen.hasShiftDown()){ + tooltip.add(Text.translatable("tooltip.acesbs.generic.shift_up")); + } else { + tooltip.add(Text.translatable("tooltip.acesbs.command_core")); + } + + if(stack.get(ModDataComponentTypes.COMMAND) != null) { + tooltip.add(Text.literal("Command: " + stack.get(ModDataComponentTypes.COMMAND))); + } else { + tooltip.add(Text.literal("Command: None")); + } + + super.appendTooltip(stack, context, tooltip, type); + } + + @Override + public void inventoryTick(ItemStack stack, World world, Entity entity, int slot, boolean selected) { + super.inventoryTick(stack, world, entity, slot, selected); + + String command = stack.get(ModDataComponentTypes.COMMAND); + + LivingEntity livingEntity = (LivingEntity) entity; + + if (Boolean.TRUE.equals(stack.get(ModDataComponentTypes.COMMAND_ACTIVE))){ + switch (command) { + case "TEST" -> { entity.setOnFireFor(1); } + case "Sight" -> { if (!world.isClient()) livingEntity.removeStatusEffect(StatusEffects.BLINDNESS); } + case null, default -> {} + } + } + } +} diff --git a/src/main/java/com/acethewildfire/acesbs/screen/custom/CommandCoreScreen.java b/src/main/java/com/acethewildfire/acesbs/screen/custom/CommandCoreScreen.java new file mode 100644 index 0000000..4c4ebbb --- /dev/null +++ b/src/main/java/com/acethewildfire/acesbs/screen/custom/CommandCoreScreen.java @@ -0,0 +1,94 @@ +package com.acethewildfire.acesbs.screen.custom; + +import com.acethewildfire.acesbs.component.ModDataComponentTypes; +import com.acethewildfire.acesbs.util.ModPackets; +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; +import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.tooltip.Tooltip; +import net.minecraft.client.gui.widget.ButtonWidget; +import net.minecraft.item.ItemStack; + +import net.minecraft.text.Text; + +import java.util.Map; +import java.util.TreeMap; + +public class CommandCoreScreen extends Screen { + + + private final ItemStack stack; + private final TreeMap options; + + public CommandCoreScreen(ItemStack stack) { + super(Text.literal("Select Option")); + this.stack = stack; + this.options = new TreeMap<>(); + options.put("Sight", "See when others can not"); + options.put("Omnipotence", "Let nothing escape your sight"); + options.put("Intimidate", "Warn any would be foes that you mean business"); + options.put("Immunity", "Most physical ailments have no effect on you"); + options.put("Immovable", "You cannot be moved against your will"); + options.put("Unstoppable", "You cannot be stopped by obstacles"); + options.put("Grounded", "You always have sure footing"); + options.put("Arborist", "You have an affinity with plants"); + options.put("Wither", "Causes foes to wither away"); + options.put("Immolate", "Causes foes to sacrifice themselves to you"); + options.put("Begone", "Removes a foe from your sight"); + options.put("Scorch", "Attackers are set on fire"); + options.put("Terrify", "Show a foe your true appearance"); + options.put("Grovel", "Forces a foe to collapse under your might"); + options.put("Satisfy", "Bless an ally with a full stomach"); + options.put("Soothe", "Soothe an ally, healing their wounds"); + options.put("Leap", "Launch yourself into the air"); + options.put("Lunge", "Launch yourself forward"); + +// options.put("", ""); + + + + + options.put("TEST", "Set yourself on fire"); + } + + @Override + protected void init() { + int y = 20; + int x = this.width / 4 - 50; + int count = 8; + + for (Map.Entry entry : options.entrySet()) { + String option = entry.getKey(); + String tooltip = entry.getValue(); + + ButtonWidget button = ButtonWidget.builder( + Text.literal(option), // Button text + button1 -> { + ClientPlayNetworking.send(new ModPackets.SetCommandPayload(option)); + MinecraftClient.getInstance().setScreen(null); // Close screen + } + ) + .size(100, 20) // width, height + .position(x, y) // x, y + .tooltip(Tooltip.of(Text.literal(tooltip))) + .build(); + + this.addDrawableChild(button); + y += 24; + count -= 1; + if (count <= 0){ + count = 8; + y = 20; + x = x + (this.width / 4); + } + } + } + + @Override + public boolean shouldPause() { + return false; // Doesn't pause the game + } + + +} diff --git a/src/main/java/com/acethewildfire/acesbs/util/ModModelPredicates.java b/src/main/java/com/acethewildfire/acesbs/util/ModModelPredicates.java index d1c3140..0bb047e 100644 --- a/src/main/java/com/acethewildfire/acesbs/util/ModModelPredicates.java +++ b/src/main/java/com/acethewildfire/acesbs/util/ModModelPredicates.java @@ -13,6 +13,9 @@ public class ModModelPredicates { ModelPredicateProviderRegistry.register(ModItems.WAND, Identifier.of(AcesBS.MOD_ID, "used"), (stack, world, entity, seed) -> stack.get(ModDataComponentTypes.COORDINATES) != null ? 1f : 0f); + ModelPredicateProviderRegistry.register(ModItems.COMMAND_CORE, Identifier.of(AcesBS.MOD_ID, "command_active"), + (stack, world, entity, seed) -> Boolean.TRUE.equals(stack.get(ModDataComponentTypes.COMMAND_ACTIVE)) ? 1f : 0f); + ModelPredicateProviderRegistry.register(ModItems.CIGARETTE, Identifier.of(AcesBS.MOD_ID, "smoking"), (stack, world, entity, seed) -> Boolean.TRUE.equals(stack.get(ModDataComponentTypes.SMOKING)) ? 1f : 0f); diff --git a/src/main/java/com/acethewildfire/acesbs/util/ModPackets.java b/src/main/java/com/acethewildfire/acesbs/util/ModPackets.java new file mode 100644 index 0000000..9665a56 --- /dev/null +++ b/src/main/java/com/acethewildfire/acesbs/util/ModPackets.java @@ -0,0 +1,30 @@ +package com.acethewildfire.acesbs.util; + +import com.acethewildfire.acesbs.AcesBS; +import net.minecraft.network.RegistryByteBuf; +import net.minecraft.network.codec.PacketCodec; +import net.minecraft.network.codec.PacketCodecs; +import net.minecraft.network.packet.CustomPayload; +import net.minecraft.util.Identifier; + +public class ModPackets { + public static final Identifier SET_COMMAND = Identifier.of(AcesBS.MOD_ID, "set_command"); + + public record SetCommandPayload(String option) implements CustomPayload { + + public static final Id ID = + new Id<>(Identifier.of("mymod", "set_option")); + + public static final PacketCodec CODEC = + PacketCodec.tuple( + PacketCodecs.STRING, + SetCommandPayload::option, + SetCommandPayload::new + ); + + @Override + public Id getId() { + return ID; + } + } +} diff --git a/src/main/resources/assets/acesbs/lang/en_us.json b/src/main/resources/assets/acesbs/lang/en_us.json index 9cd356e..5099d97 100644 --- a/src/main/resources/assets/acesbs/lang/en_us.json +++ b/src/main/resources/assets/acesbs/lang/en_us.json @@ -12,6 +12,7 @@ "item.acesbs.cooked_lemon": "Cooked Odd Lemon", "item.acesbs.green_bricks": "Green Bricks", "item.acesbs.wand": "Entropy Wand", + "item.acesbs.command_core": "Command Core", "item.minecraft.potion.effect.blindness": "Potion of Blindness", "item.minecraft.splash_potion.effect.blindness": "Splash Potion of Blindness", @@ -185,6 +186,8 @@ "tooltip.acesbs.cigarette_funny": "§o§7I am the danger of second hand smoke§r", + "tooltip.acesbs.command_core": "Assert your Command.", + "sounds.acesbs.lizard": "Lizard!", "sounds.acesbs.holy": "Angelic Music", "sounds.acesbs.fart": "Loud Echoing Fart", diff --git a/src/main/resources/assets/acesbs/models/item/command_core.json b/src/main/resources/assets/acesbs/models/item/command_core.json new file mode 100644 index 0000000..c7ab54e --- /dev/null +++ b/src/main/resources/assets/acesbs/models/item/command_core.json @@ -0,0 +1,14 @@ +{ + "parent": "minecraft:item/generated", + "textures": { + "layer0": "acesbs:item/command_core" + }, + "overrides": [ + { + "predicate": { + "acesbs:command_active": 1 + }, + "model": "acesbs:item/command_core_active" + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/acesbs/models/item/command_core_active.json b/src/main/resources/assets/acesbs/models/item/command_core_active.json new file mode 100644 index 0000000..ac890c4 --- /dev/null +++ b/src/main/resources/assets/acesbs/models/item/command_core_active.json @@ -0,0 +1,6 @@ +{ + "parent": "minecraft:item/generated", + "textures": { + "layer0": "acesbs:item/command_core_active" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/acesbs/textures/item/command_core.png b/src/main/resources/assets/acesbs/textures/item/command_core.png new file mode 100644 index 0000000..e678942 Binary files /dev/null and b/src/main/resources/assets/acesbs/textures/item/command_core.png differ diff --git a/src/main/resources/assets/acesbs/textures/item/command_core_active.png b/src/main/resources/assets/acesbs/textures/item/command_core_active.png new file mode 100644 index 0000000..d5e802f Binary files /dev/null and b/src/main/resources/assets/acesbs/textures/item/command_core_active.png differ