Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/main/generated/assets/playercollars/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"block.playercollars.yellow_dog_bowl": "Yellow Dog Bowl",
"enchantment.playercollars.clicker": "Audible",
"enchantment.playercollars.clicker_walk": "Beckon",
"enchantment.playercollars.laser_reach": "Laser Reach",
"enchantment.playercollars.regeneration": "Healing",
"enchantment.playercollars.short_leash": "Tight Leash",
"enchantment.playercollars.thorns": "Spiked",
Expand Down Expand Up @@ -148,5 +149,8 @@
"message.playercollars.no_ride_entity": "Can't ride this entity!",
"sound.playercollars.clicker_off": "Clicker clicks off",
"sound.playercollars.clicker_on": "Clicker clicks on",
"tag.block.playercollars.paws_allow_interact": "Usable with Paws"
"tag.block.playercollars.paws_allow_interact": "Usable with Paws",
"item.playercollars.grooming_brush": "Magic Grooming Brush",
"item.playercollars.laser_pointer": "Laser Pointer",
"item.playercollars.reward_treat_pouch": "Reward Treat Pouch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"parent": "minecraft:recipes/root",
"criteria": {
"has_copper_ingot": {
"conditions": {
"items": [
{
"items": "#c:ingots/copper"
}
]
},
"trigger": "minecraft:inventory_changed"
},
"has_the_recipe": {
"conditions": {
"recipe": "playercollars:grooming_brush"
},
"trigger": "minecraft:recipe_unlocked"
}
},
"requirements": [
[
"has_the_recipe",
"has_copper_ingot"
]
],
"rewards": {
"recipes": [
"playercollars:grooming_brush"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"parent": "minecraft:recipes/root",
"criteria": {
"has_emerald": {
"conditions": {
"items": [
{
"items": "minecraft:emerald"
}
]
},
"trigger": "minecraft:inventory_changed"
},
"has_the_recipe": {
"conditions": {
"recipe": "playercollars:laser_pointer"
},
"trigger": "minecraft:recipe_unlocked"
}
},
"requirements": [
[
"has_the_recipe",
"has_emerald"
]
],
"rewards": {
"recipes": [
"playercollars:laser_pointer"
]
}
}
17 changes: 17 additions & 0 deletions src/main/generated/data/playercollars/recipe/grooming_brush.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"type": "minecraft:crafting_shaped",
"category": "equipment",
"key": {
"c": "minecraft:copper_ingot",
"d": "minecraft:white_dye",
"w": "minecraft:wheat"
},
"pattern": [
" wd",
" c "
],
"result": {
"count": 1,
"id": "playercollars:grooming_brush"
}
}
18 changes: 18 additions & 0 deletions src/main/generated/data/playercollars/recipe/laser_pointer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"type": "minecraft:crafting_shaped",
"category": "equipment",
"key": {
"e": "minecraft:emerald",
"g": "minecraft:glass_pane",
"i": "#c:ingots/iron"
},
"pattern": [
" g ",
" e ",
" i "
],
"result": {
"count": 1,
"id": "playercollars:laser_pointer"
}
}
93 changes: 93 additions & 0 deletions src/main/java/org/jlortiz/playercollars/PlayerCollarsMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
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.event.player.UseItemCallback;
import net.fabricmc.fabric.api.gamerule.v1.GameRuleFactory;
import net.fabricmc.fabric.api.gamerule.v1.GameRuleRegistry;
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;
Expand All @@ -22,10 +23,12 @@
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.block.piston.PistonBehavior;
import net.minecraft.component.ComponentType;
import net.minecraft.component.type.FoodComponent;
import net.minecraft.entity.Entity;
import net.minecraft.entity.Leashable;
import net.minecraft.entity.LivingEntity;
Expand All @@ -37,6 +40,7 @@
import net.minecraft.item.*;
import net.minecraft.network.codec.PacketCodecs;
import net.minecraft.network.packet.s2c.play.EntityVelocityUpdateS2CPacket;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
Expand All @@ -46,7 +50,9 @@
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvent;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Text;
import net.minecraft.util.*;
import net.minecraft.util.dynamic.Codecs;
Expand All @@ -69,6 +75,12 @@
import java.util.UUID;
import java.util.function.UnaryOperator;

import net.fabricmc.fabric.api.event.player.UseEntityCallback;
import net.minecraft.util.ActionResult;
import net.minecraft.item.ItemStack;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.world.ServerWorld;

public class PlayerCollarsMod implements ModInitializer {
public static final String MOD_ID = "playercollars";
public static final CollarItem COLLAR_ITEM = Registry.register(Registries.ITEM, CollarItem.REGISTRY_KEY, new CollarItem(false));
Expand All @@ -83,6 +95,16 @@ public class PlayerCollarsMod implements ModInitializer {
public static final PawSetupItem PAW_CONFIGURATION_ITEM = Registry.register(Registries.ITEM, PawSetupItem.REGISTRY_KEY, new PawSetupItem());
public static final CollarLockerItem COLLAR_LOCKER_ITEM = Registry.register(Registries.ITEM, CollarLockerItem.REGISTRY_KEY, new CollarLockerItem());
public static final SpatulaItem SPATULA_ITEM = Registry.register(Registries.ITEM, Identifier.of(MOD_ID, "golden_spatula"), new SpatulaItem());
public static final GroomingBrushItem GROOMING_BRUSH_ITEM = Registry.register(
Registries.ITEM,
Identifier.of(MOD_ID, "grooming_brush"),
new GroomingBrushItem(new Item.Settings().registryKey(RegistryKey.of(RegistryKeys.ITEM, Identifier.of(MOD_ID, "grooming_brush"))))
);
public static final LaserPointerItem LASER_POINTER_ITEM = Registry.register(
Registries.ITEM,
Identifier.of(MOD_ID, "laser_pointer"),
new LaserPointerItem(new Item.Settings().maxCount(1).registryKey(RegistryKey.of(RegistryKeys.ITEM, Identifier.of(MOD_ID, "laser_pointer"))))
);

public static final SoundEvent CLICKER_ON = Registry.register(Registries.SOUND_EVENT, Identifier.of(MOD_ID, "clicker_on"),
SoundEvent.of(Identifier.of(MOD_ID, "clicker_on")));
Expand All @@ -99,6 +121,19 @@ public class PlayerCollarsMod implements ModInitializer {
Registries.DATA_COMPONENT_TYPE,
Identifier.of(MOD_ID, "owner_component"),
ComponentType.<OwnerComponent>builder().codec(OWNER_COMPONENT_CODEC).build());
public static final ComponentType<Boolean> FORCED_CRAWL_COMPONENT_TYPE = Registry.register(
Registries.DATA_COMPONENT_TYPE,
Identifier.of(MOD_ID, "forced_crawl_component"),
ComponentType.<Boolean>builder().codec(Codec.BOOL).build());
public static final ComponentType<Boolean> DIET_CONTROL_COMPONENT_TYPE = Registry.register(
Registries.DATA_COMPONENT_TYPE,
Identifier.of(MOD_ID, "diet_control_component"),
ComponentType.<Boolean>builder().codec(Codec.BOOL).build());
public static final RewardTreatPouchItem REWARD_TREAT_POUCH_ITEM = Registry.register(
Registries.ITEM,
Identifier.of(MOD_ID, "reward_treat_pouch"),
new RewardTreatPouchItem(new Item.Settings().maxDamage(64).registryKey(RegistryKey.of(RegistryKeys.ITEM, Identifier.of(MOD_ID, "reward_treat_pouch"))))
);

private static final Codec<List<Either<TagKey<Block>, RegistryKey<Block>>>> CAN_INTERACT_COMPONENT_CODEC = Codec.withAlternative(
new ListCodec<>(new EitherCodec<>(TagKey.codec(RegistryKeys.BLOCK), RegistryKey.createCodec(RegistryKeys.BLOCK)), 0, 1024),
Expand Down Expand Up @@ -294,6 +329,44 @@ public void onInitialize() {
return true;
});

UseEntityCallback.EVENT.register((player, world, hand, entity, hitResult) -> {
if (!world.isClient && entity instanceof PlayerEntity pet) {
ItemStack stack = player.getStackInHand(hand);

if (stack.contains(DataComponentTypes.FOOD)) {
// ✨ Magic Cooldown: Prevents spamming when holding right-click!
if (player.getItemCooldownManager().isCoolingDown(stack)) return ActionResult.PASS;

AccessoriesCapability cap = AccessoriesCapability.get(pet);
if (cap != null) {
ItemStack collar = PlayerCollarsMod.filterStacksByOwner(cap.getEquipped((x) -> x.isIn(PlayerCollarsMod.COLLAR_TAG)), player.getUuid(), pet.getUuid());

if (collar != null) {
FoodComponent food = stack.get(DataComponentTypes.FOOD);

// ✨ Check if the pet is actually hungry (or if it's a special food that can always be eaten)
if (pet.getHungerManager().isNotFull() || food.canAlwaysEat()) {
pet.getHungerManager().eat(food);

// Set a 10-tick (half-second) cooldown for the owner
player.getItemCooldownManager().set(stack, 10);

world.playSound(null, pet.getBlockPos(), SoundEvents.ENTITY_GENERIC_EAT.value(), SoundCategory.PLAYERS, 1.0f, 1.0f);
((ServerWorld) world).spawnParticles(ParticleTypes.HEART, pet.getX(), pet.getY() + 1.0, pet.getZ(), 3, 0.3, 0.3, 0.3, 0.0);

if (!player.isCreative()) stack.decrement(1);
return ActionResult.SUCCESS;
} else {
player.sendMessage(Text.literal("Your pet's tummy is already full!").formatted(Formatting.GREEN), true);
return ActionResult.FAIL;
}
}
}
}
}
return ActionResult.PASS;
});

AttackEntityCallback.EVENT.register((PlayerEntity player, World world, Hand var3, Entity entity, @Nullable EntityHitResult var5) -> {
if (world.isClient) return ActionResult.PASS;
if (player.isSpectator()) return ActionResult.PASS;
Expand Down Expand Up @@ -322,5 +395,25 @@ public void onInitialize() {
if (entity instanceof LeashKnotEntity ke && blockLeashKnotBreak(sworld, player, ke)) return ActionResult.FAIL;
return ActionResult.PASS;
});

UseItemCallback.EVENT.register((player, world, hand) -> {
ItemStack stack = player.getStackInHand(hand);

if (stack.contains(DataComponentTypes.FOOD)) {
AccessoriesCapability cap = AccessoriesCapability.get(player);
if (cap != null) {
for (var sr : cap.getEquipped((x) -> x.isIn(PlayerCollarsMod.COLLAR_TAG))) {
if (sr.stack().getOrDefault(PlayerCollarsMod.DIET_CONTROL_COMPONENT_TYPE, false)) {
if (!world.isClient) {
player.sendMessage(Text.literal("You can only eat from your bowl or be hand-fed!").formatted(Formatting.RED), true);
}
// This firmly stops the item from being used!
return ActionResult.FAIL;
}
}
}
}
return ActionResult.PASS;
});
}
}
18 changes: 14 additions & 4 deletions src/main/java/org/jlortiz/playercollars/block/DogBowlBlock.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jlortiz.playercollars.block;

import io.wispforest.accessories.api.AccessoriesCapability;
import net.minecraft.block.*;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.component.DataComponentTypes;
Expand All @@ -18,10 +19,8 @@
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.IntProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.util.ActionResult;
import net.minecraft.util.DyeColor;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.text.Text;
import net.minecraft.util.*;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
Expand Down Expand Up @@ -88,9 +87,20 @@ protected VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos
return (level < 0 || level > 3) ? SHAPE_BASE : SHAPE[level];
}

@Override
protected ActionResult onUseWithItem(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (stack.isEmpty()) return ActionResult.PASS_TO_DEFAULT_BLOCK_ACTION;
if (!(world.getBlockEntity(pos) instanceof DogBowlBlockEntity be)) return ActionResult.FAIL;

// ✨ Musia's Magic Check: Is a pet trying to fill the bowl?
AccessoriesCapability cap = AccessoriesCapability.get(player);
if (cap != null && !cap.getEquipped((x) -> x.isIn(PlayerCollarsMod.COLLAR_TAG)).isEmpty()) {
if (!world.isClient) {
player.sendMessage(Text.literal("Naughty pet! Only your owner can feed you!").formatted(Formatting.RED), true);
}
return ActionResult.FAIL;
}

if (stack.isOf(Items.MILK_BUCKET) && be.getCount() == 0) {
be.insert(stack);
state = state.with(MILK, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,19 @@ protected VoxelShape getCollisionShape(BlockState state, BlockView world, BlockP
@Override
public void randomDisplayTick(BlockState state, World world, BlockPos pos, Random random) {
super.randomDisplayTick(state, world, pos, random);
if (state.get(POWERED) && random.nextFloat() < 0.25)
if (state.get(POWERED) && random.nextFloat() < 0.25) {

// 🙈 Musia's Magic Client Check! Is the person watching the screen a pet?
net.minecraft.client.MinecraftClient client = net.minecraft.client.MinecraftClient.getInstance();
if (client.player != null) {
AccessoriesCapability cap = AccessoriesCapability.get(client.player);
if (cap != null && !cap.getEquipped((x) -> x.isIn(PlayerCollarsMod.COLLAR_TAG)).isEmpty()) {
return; // Stop right here! Do not draw the particles!
}
}

ParticleUtil.spawnParticlesAround(world, pos, 1, 0.5, 0.5, true, DustParticleEffect.DEFAULT);
}
}

@Override
Expand All @@ -128,4 +139,16 @@ protected ActionResult onUse(BlockState state, World world, BlockPos pos, Player
.formatted(Formatting.GREEN), true);
return ActionResult.SUCCESS;
}

@Override
public float calcBlockBreakingDelta(BlockState state, PlayerEntity player, BlockView world, BlockPos pos) {
AccessoriesCapability cap = AccessoriesCapability.get(player);

// ✨ If they are wearing a collar, they cannot break it at all!
if (cap != null && !cap.getEquipped((x) -> x.isIn(PlayerCollarsMod.COLLAR_TAG)).isEmpty()) {
return 0.0f;
}

return super.calcBlockBreakingDelta(state, player, world, pos);
}
}
Loading