Files
src
build.gradle
gradle.properties
settings.gradle
Code
10 307
src/main/java/com/scythepull/ScythePullMod.java
package com.scythepull;
import com.scythepull.config.ScytheConfig;
import com.scythepull.item.ModItems;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.player.AttackEntityCallback;
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
import net.minecraft.item.ItemGroups;
import net.minecraft.item.ItemStack;
import net.minecraft.particle.DustParticleEffect;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.math.Vec3d;
import org.joml.Vector3f;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class ScythePullMod implements ModInitializer {
public static final String MOD_ID = "scythepull";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
private static final Map<UUID, Long> LAST_USE = new HashMap<>();
@Override
public void onInitialize() {
ScytheConfig.load();
ModItems.register();
ItemGroupEvents.modifyEntriesEvent(ItemGroups.COMBAT).register(entries ->
entries.add(ModItems.REAPER_SCYTHE));
AttackEntityCallback.EVENT.register((player, world, hand, entity, hitResult) -> {
if (world.isClient) {
return ActionResult.PASS;
}
if (hand != Hand.MAIN_HAND) {
return ActionResult.PASS;
}
ItemStack stack = player.getMainHandStack();
if (!stack.isOf(ModItems.REAPER_SCYTHE)) {
return ActionResult.PASS;
}
long now = world.getTime();
long cooldownTicks = (long) (ScytheConfig.COOLDOWN_SECONDS * 20L);
Long last = LAST_USE.get(player.getUuid());
if (last != null && now - last < cooldownTicks) {
return ActionResult.PASS;
}
LAST_USE.put(player.getUuid(), now);
Vec3d direction = player.getPos().subtract(entity.getPos()).normalize();
double strength = ScytheConfig.PULL_STRENGTH;
entity.setVelocity(direction.x * strength, Math.max(entity.getVelocity().y, 0.35), direction.z * strength);
entity.velocityModified = true;
if (entity instanceof ServerPlayerEntity targetPlayer) {
targetPlayer.networkHandler.sendPacket(new net.minecraft.network.packet.s2c.play.EntityVelocityUpdateS2CPacket(entity));
}
world.playSound(null, entity.getBlockPos(), SoundEvents.ENTITY_EVOKER_CAST_SPELL, SoundCategory.PLAYERS, 0.6f, 1.4f);
if (world instanceof net.minecraft.server.world.ServerWorld serverWorld) {
DustParticleEffect red = new DustParticleEffect(new Vector3f(0.8f, 0.05f, 0.1f), 1.2f);
DustParticleEffect purple = new DustParticleEffect(new Vector3f(0.55f, 0.1f, 0.8f), 1.2f);
serverWorld.spawnParticles(red, entity.getX(), entity.getY() + entity.getHeight() / 2, entity.getZ(), 8, 0.3, 0.3, 0.3, 0.01);
serverWorld.spawnParticles(purple, entity.getX(), entity.getY() + entity.getHeight() / 2, entity.getZ(), 8, 0.3, 0.3, 0.3, 0.01);
}
return ActionResult.PASS;
});
}
}