Initial commit

This commit is contained in:
2025-09-30 15:56:27 +02:00
commit f67c0fe3af
13 changed files with 660 additions and 0 deletions

View File

@@ -0,0 +1,76 @@
package com.kasetoatz.stasisrods.mixin;
import net.minecraft.block.BlockState;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.NbtComponent;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.decoration.ArmorStandEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.FishingRodItem;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.tag.BlockTags;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import static com.kasetoatz.stasisrods.util.Util.spawnPlaceholder;
import static com.kasetoatz.stasisrods.util.Util.tryDiscardPlaceholder;
@Mixin(FishingRodItem.class)
public class FishingRodItemMixin
{
@Inject(method="use", at=@At("HEAD"), cancellable = true)
public void use(World world, PlayerEntity user, Hand hand, CallbackInfoReturnable<ActionResult> cir)
{
ItemStack stack = user.getStackInHand(hand);
if (tryDiscardPlaceholder(stack, world.getServer()))
{
stack.damage(1, user, LivingEntity.getSlotForHand(hand));
world.playSound(
null,
user.getX(),
user.getY(),
user.getZ(),
SoundEvents.ENTITY_FISHING_BOBBER_RETRIEVE,
SoundCategory.NEUTRAL,
1.0F,
0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F)
);
cir.setReturnValue(ActionResult.SUCCESS);
return;
}
HitResult hitResult = user.raycast(user.getAttributeValue(EntityAttributes.BLOCK_INTERACTION_RANGE), 0F, false);
if (hitResult.getType() != HitResult.Type.BLOCK)
{
return;
}
BlockState state = world.getBlockState(((BlockHitResult)hitResult).getBlockPos());
if (!state.isIn(BlockTags.PRESSURE_PLATES))
{
return;
}
world.playSound(
null,
user.getX(),
user.getY(),
user.getZ(),
SoundEvents.ENTITY_FISHING_BOBBER_THROW,
SoundCategory.NEUTRAL,
0.5F,
0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F)
);
ArmorStandEntity placeholder = spawnPlaceholder(world, hitResult.getPos());
stack.set(DataComponentTypes.CUSTOM_DATA, NbtComponent.DEFAULT.apply(nbt -> nbt.putString("placeholder", placeholder.getUuidAsString())));
cir.setReturnValue(ActionResult.SUCCESS);
}
}

View File

@@ -0,0 +1,59 @@
package com.kasetoatz.stasisrods.util;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.NbtComponent;
import net.minecraft.entity.Entity;
import net.minecraft.entity.decoration.ArmorStandEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import java.util.UUID;
public class Util
{
public static boolean tryDiscardPlaceholder(ItemStack stack, MinecraftServer server)
{
NbtComponent data = stack.get(DataComponentTypes.CUSTOM_DATA);
if (data == null)
{
return false;
}
String uuid = data.copyNbt().getString("placeholder", null);
if (uuid == null)
{
return false;
}
UUID id = UUID.fromString(uuid);
boolean found = false;
for (ServerWorld world : server.getWorlds())
{
Entity entity = world.getEntity(id);
if (entity == null)
{
continue;
}
if (entity.isRemoved())
{
stack.set(DataComponentTypes.CUSTOM_DATA, data.apply(nbt -> nbt.remove("placeholder")));
return false;
}
entity.discard();
found = true;
break;
}
return found;
}
public static ArmorStandEntity spawnPlaceholder(World world, Vec3d pos)
{
ArmorStandEntity placeholder = new ArmorStandEntity(world, pos.getX(), pos.getY(), pos.getZ());
placeholder.setHideBasePlate(true);
placeholder.setInvisible(true);
placeholder.setInvulnerable(true);
world.spawnEntity(placeholder);
return placeholder;
}
}

View File

@@ -0,0 +1,19 @@
{
"schemaVersion": 1,
"id": "stasisrods",
"version": "${version}",
"name": "UnbreakableFishingRods",
"description": "",
"authors": [],
"contact": {},
"license": "MIT",
"environment": "server",
"mixins": [
"stasisrods.mixins.json"
],
"depends": {
"fabricloader": ">=${loader_version}",
"fabric": "*",
"minecraft": "${minecraft_version}"
}
}

View File

@@ -0,0 +1,17 @@
{
"required": true,
"minVersion": "0.8",
"package": "com.kasetoatz.stasisrods.mixin",
"compatibilityLevel": "JAVA_21",
"mixins": [
"FishingRodItemMixin"
],
"client": [
],
"injectors": {
"defaultRequire": 1
},
"overwrites": {
"requireAnnotations": true
}
}