Command Core Functionality

This commit is contained in:
Vos
2026-03-12 17:47:27 -05:00
parent e3a1e02ae8
commit fdfb322026
15 changed files with 320 additions and 1 deletions
@@ -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
}
]
}
@@ -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());
});
}
);
}
}
@@ -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<Boolean> SMOKING =
register("smoking", booleanBuilder -> booleanBuilder.codec(Codec.BOOL));
public static final ComponentType<String> COMMAND =
register("command", stringBuilder -> stringBuilder.codec(Codec.STRING).packetCodec(PacketCodecs.STRING));
public static final ComponentType<Boolean> COMMAND_ACTIVE =
register("command_active", booleanBuilder -> booleanBuilder.codec(Codec.BOOL).packetCodec(PacketCodecs.BOOL));
private static <T>ComponentType<T> register(String name, UnaryOperator<ComponentType.Builder<T>> builderOperator){
return Registry.register(Registries.DATA_COMPONENT_TYPE, Identifier.of(AcesBS.MOD_ID, name),
builderOperator.apply(ComponentType.builder()).build());
@@ -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));
@@ -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);
@@ -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);
// });
@@ -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<ItemStack> 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<Text> 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 -> {}
}
}
}
}
@@ -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<String, String> 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<String, String> 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
}
}
@@ -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);
@@ -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<SetCommandPayload> ID =
new Id<>(Identifier.of("mymod", "set_option"));
public static final PacketCodec<RegistryByteBuf, SetCommandPayload> CODEC =
PacketCodec.tuple(
PacketCodecs.STRING,
SetCommandPayload::option,
SetCommandPayload::new
);
@Override
public Id<? extends CustomPayload> getId() {
return ID;
}
}
}
@@ -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",
@@ -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"
}
]
}
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "acesbs:item/command_core_active"
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 341 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 419 B