only for Zigy

This commit is contained in:
neroduckale 2024-06-24 23:09:09 +05:00
parent cc6313dfc0
commit bc8df2d36c
17 changed files with 325 additions and 45 deletions

View file

@ -16,7 +16,22 @@ repositories {
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
// for more information about repositories.
maven {
name "KosmX's maven"
url 'https://maven.kosmx.dev/'
}
maven {
name "zigythebirdMods"
url "https://maven.zigythebird.com/mods"
}
//For some external mods.
//You won't need to add any mods downloaded from these places as dependencies only player animator.
mavenCentral()
maven { url 'https://libs.azuredoom.com:4443/mods' }
maven { url 'https://api.modrinth.com/maven' }
maven { url "https://maven.terraformersmc.com/releases/" }
maven { url = "https://jitpack.io" }
}
dependencies {
@ -27,6 +42,12 @@ dependencies {
// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
include modImplementation("dev.kosmx.player-anim:player-animation-lib-fabric:${project.player_anim}")
modImplementation "com.zigythebird.multiloaderutils:zigysmultiloaderutils-fabric-$project.minecraft_version:$project.multiloaderutils_version"
modImplementation "com.zigythebird.playeranimatorapi:playeranimatorapi-fabric-$project.minecraft_version:$project.playeranimatorapi_version"
modApi("com.github.Virtuoel:Pehkui:3.8.3", {
exclude group: "net.fabricmc.fabric-api"
})
}
processResources {

View file

@ -12,3 +12,6 @@ archives_base_name=untitled
# Dependencies
# check this on https://modmuss50.me/fabric.html
fabric_version=0.91.0+1.20.1
player_anim=1.0.2-rc1+1.20
multiloaderutils_version=1.2.4
playeranimatorapi_version=2.0.4

View file

@ -2,22 +2,34 @@ package ru.neroduckale;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.neroduckale.register.*;
import ru.neroduckale.vapes.Vape;
public class NeroduckaleVapes implements ModInitializer {
public static final Logger LOGGER = LoggerFactory.getLogger("nerovapes");
public static final String MOD_ID = "nerovapes";
public static final String MOD_ID = "nerovapes";
@Override
public void onInitialize() {
RegisterGUI.registerGUIs();
RegisterItems.registerModItems();
RegisterItemGroup.registerItemGroups();
RegisterSounds.registerSounds();
RegisterParticles.registerParticles();
LOGGER.info("Hello Fabric world!");
}
@Override
public void onInitialize() {
RegisterGUI.registerGUIs();
RegisterItems.registerModItems();
RegisterItemGroup.registerItemGroups();
RegisterSounds.registerSounds();
RegisterParticles.registerParticles();
LOGGER.info("Hello Fabric world!");
ServerPlayNetworking.registerGlobalReceiver(new Identifier("nerovapes", "ring"), (server, player, handler, buf, responseSender) -> {
server.execute(() -> {
if (player.getStackInHand(Hand.MAIN_HAND).getItem() instanceof Vape vape) {
vape.newRing(player, server.getOverworld());
}
});
});
}
}

View file

@ -0,0 +1,12 @@
package ru.neroduckale.animation;
import dev.kosmx.playerAnim.api.layered.IAnimation;
import dev.kosmx.playerAnim.api.layered.ModifierLayer;
public interface IExampleAnimatedPlayer {
/**
* Use your mod ID in the method name to avoid collisions with other mods
* @return Mod animation container
*/
ModifierLayer<IAnimation> nerovapes_getModAnimation();
}

View file

@ -0,0 +1,58 @@
package ru.neroduckale.gui;
import com.mojang.blaze3d.systems.RenderSystem;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.entity.boss.BossBar;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Colors;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.ColorHelper;
import net.minecraft.util.math.MathHelper;
import ru.neroduckale.vapes.Vape;
public class HudRemainingTime implements HudRenderCallback {
private static final Identifier BARS_TEXTURE = new Identifier("textures/gui/bars.png");
private static final int WIDTH = 182;
private static final int HEIGHT = 5;
@Override
public void onHudRender(DrawContext drawContext, float tickDelta) {
if (MinecraftClient.getInstance().player == null) {
return;
}
if (MinecraftClient.getInstance().player.getStackInHand(Hand.MAIN_HAND).getItem() instanceof Vape) {
if (MinecraftClient.getInstance().player.getActiveHand().equals(Hand.MAIN_HAND)) {
int i = drawContext.getScaledWindowWidth();
int j = 12;
int k = i / 2 - 91;
this.renderBossBar(drawContext, k, j, MinecraftClient.getInstance().player.getStackInHand(Hand.MAIN_HAND));
}
}
}
private void renderBossBar(DrawContext context, int x, int y, ItemStack itemStack) {
var vape = (Vape) itemStack.getItem();
this.renderBossBar(context, x, y, itemStack, 182, 0, false);
this.renderBossBar(context, x, y, itemStack, vape.getPercent(itemStack), 5, true);
}
private void renderBossBar(DrawContext context, int x, int y, ItemStack itemStack, int width, int height, boolean solid) {
if (width == 0 && solid) {
context.drawTexture(BARS_TEXTURE, x, y, 0, 20, 182, 5);
return;
}
context.drawTexture(BARS_TEXTURE, x, y, 0, 10, width, 5);
if (solid) {
context.drawTexture(BARS_TEXTURE, x, y, 0, 15, width, 5);
}
}
}

View file

@ -0,0 +1,42 @@
package ru.neroduckale.mixin;
import com.mojang.authlib.GameProfile;
import dev.kosmx.playerAnim.api.layered.IAnimation;
import dev.kosmx.playerAnim.api.layered.ModifierLayer;
import dev.kosmx.playerAnim.minecraftApi.PlayerAnimationAccess;
import ru.neroduckale.animation.IExampleAnimatedPlayer;
import net.minecraft.client.network.AbstractClientPlayerEntity;
import net.minecraft.client.world.ClientWorld;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(AbstractClientPlayerEntity.class)
public class ClientPlayerEntityMixin implements IExampleAnimatedPlayer {
//Unique annotation will rename private methods/fields if needed to avoid collisions.
@Unique
private final ModifierLayer<IAnimation> modAnimationContainer = new ModifierLayer<>();
/**
* Add the animation registration to the end of the constructor
* Or you can use {@link dev.kosmx.playerAnim.minecraftApi.PlayerAnimationAccess#REGISTER_ANIMATION_EVENT} event for this
*/
@Inject(method = "<init>", at = @At(value = "RETURN"))
private void init(ClientWorld world, GameProfile profile, CallbackInfo ci) {
//Mixin does not know (yet) that this will be merged with AbstractClientPlayerEntity
PlayerAnimationAccess.getPlayerAnimLayer((AbstractClientPlayerEntity) (Object)this).addAnimLayer(1000, modAnimationContainer); //Register the layer with a priority
//The priority will tell, how important is this animation compared to other mods. Higher number means higher priority
//Mods with higher priority will override the lower priority mods (if they want to animation anything)
}
/**
* Override the interface function, so we can use it in the future
*/
@Override
public ModifierLayer<IAnimation> nerovapes_getModAnimation() {
return modAnimationContainer;
}
}

View file

@ -1,11 +1,24 @@
package ru.neroduckale;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.client.particle.v1.ParticleFactoryRegistry;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.minecraft.client.gui.screen.ingame.HandledScreens;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import ru.neroduckale.gui.HudRemainingTime;
import ru.neroduckale.particles.Particles;
import ru.neroduckale.particles.Particles2;
import ru.neroduckale.particles.RingParticle;
import ru.neroduckale.register.RegisterGUI;
import ru.neroduckale.gui.prikolscreen;
import ru.neroduckale.register.RegisterKeybinds;
import ru.neroduckale.register.RegisterParticles;
import ru.neroduckale.vapes.Vape;
public class neroduckalevapesclient implements ClientModInitializer {
@Override
@ -14,5 +27,18 @@ public class neroduckalevapesclient implements ClientModInitializer {
ParticleFactoryRegistry.getInstance().register(RegisterParticles.MY_CLOUD, Particles.Factory::new);
ParticleFactoryRegistry.getInstance().register(RegisterParticles.MY_CLOUD1, Particles2.Factory::new);
ParticleFactoryRegistry.getInstance().register(RegisterParticles.RING_PARTICLE, RingParticle.Factory::new);
RegisterKeybinds.registerKeybinds();
ClientTickEvents.END_CLIENT_TICK.register(client -> {
while (RegisterKeybinds.MY_KEY_FIRST.wasPressed()) {
if (client.player.getStackInHand(Hand.MAIN_HAND).getItem() instanceof Vape) {
PacketByteBuf buf = PacketByteBufs.create();
ClientPlayNetworking.send(new Identifier("nerovapes", "ring"), buf);
}
}
});
HudRenderCallback.EVENT.register(new HudRemainingTime());
}
}

View file

@ -1,4 +1,4 @@
package ru.neroduckale;
package ru.neroduckale.particles;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
@ -10,7 +10,6 @@ import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import java.util.List;
import java.util.Random;
@Environment(EnvType.CLIENT)
public class Particles extends SpriteBillboardParticle {

View file

@ -1,4 +1,4 @@
package ru.neroduckale;
package ru.neroduckale.particles;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
@ -10,7 +10,6 @@ import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import java.util.List;
import java.util.Random;
@Environment(EnvType.CLIENT)
public class Particles2 extends SpriteBillboardParticle {

View file

@ -1,4 +1,4 @@
package ru.neroduckale;
package ru.neroduckale.particles;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
@ -10,13 +10,15 @@ import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import java.util.List;
import java.util.Random;
@Environment(EnvType.CLIENT)
public class RingParticle extends SpriteBillboardParticle {
private final SpriteProvider spriteProvider;
private static final double MAX_SQUARED_COLLISION_CHECK_DISTANCE = MathHelper.square((double)100.0);
private boolean stopped;
float randomX = -0.01f + random.nextFloat() * (0.01f - -0.01f);
float randomZ = -0.01f + random.nextFloat() * (0.01f - -0.01f);
protected RingParticle(ClientWorld clientWorld, double x, double y, double z, double velX, double velY, double velZ, SpriteProvider spriteProvider) {
@ -52,7 +54,7 @@ public class RingParticle extends SpriteBillboardParticle {
if (this.age >= (this.maxAge / 3)) {
this.alpha -= 0.02f;
this.velocityY += 0.005f;
this.velocityY += 0.01f;
}
if (this.age >= (this.maxAge / 3) * 2) {
this.scale += 0.04f;

View file

@ -7,12 +7,13 @@ import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;
import ru.neroduckale.NeroduckaleVapes;
import ru.neroduckale.fluids.ExampleFluid;
import ru.neroduckale.util.power;
import ru.neroduckale.vapes.Vape;
import static ru.neroduckale.NeroduckaleVapes.MOD_ID;
public class RegisterItems {
public static final Item pasito2 = registerItem("pasito2", new Vape(new FabricItemSettings(), 60, 1));
public static final Item pasito2 = registerItem("pasito2", new Vape(new FabricItemSettings(), 60, 1, power.HIGHPOWER));
public static final Item ExpampleFluid = registerItem("fluid", new ExampleFluid(new FabricItemSettings(), "SKALA - Кактус со льдом"));
/**
*

View file

@ -0,0 +1,22 @@
package ru.neroduckale.register;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import net.minecraft.registry.Registry;
import org.lwjgl.glfw.GLFW;
import ru.neroduckale.NeroduckaleVapes;
public class RegisterKeybinds {
private static final String CATEGORY = "The My KeyBinds for Mcmodding";
public static final KeyBinding
MY_KEY_FIRST = KeyBindingHelper.registerKeyBinding(
new KeyBinding("key.nerovapes.ring", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_INSERT, "category.nerovapes.vapes"));
public static void registerKeybinds() {
NeroduckaleVapes.LOGGER.info("Registering keybinds for nerovapes");
}
}

View file

@ -0,0 +1,14 @@
package ru.neroduckale.util;
public enum power {
LOWPOWER (1),
HIGHPOWER (2),
BOXMODPOWER (3),
;
power(int i) {
this.power = i;
}
public int power;
}

View file

@ -1,6 +1,13 @@
package ru.neroduckale.vapes;
import com.mojang.authlib.yggdrasil.response.User;
import com.zigythebird.playeranimatorapi.API.PlayerAnimAPI;
import dev.kosmx.playerAnim.api.layered.KeyframeAnimationPlayer;
import dev.kosmx.playerAnim.api.layered.modifier.AbstractFadeModifier;
import dev.kosmx.playerAnim.core.data.KeyframeAnimation;
import dev.kosmx.playerAnim.core.util.Ease;
import dev.kosmx.playerAnim.minecraftApi.PlayerAnimationRegistry;
import net.fabricmc.fabric.mixin.event.lifecycle.WorldMixin;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
@ -13,32 +20,38 @@ import net.minecraft.screen.ScreenHandler;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.Text;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.TypedActionResult;
import net.minecraft.util.UseAction;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import ru.neroduckale.NeroduckaleVapes;
import ru.neroduckale.animation.IExampleAnimatedPlayer;
import ru.neroduckale.register.RegisterParticles;
import ru.neroduckale.util.ImplementedInventory;
import ru.neroduckale.fluids.ExampleFluid;
import ru.neroduckale.gui.prikolscreenhandler;
import ru.neroduckale.register.RegisterSounds;
import ru.neroduckale.util.power;
import java.math.BigDecimal;
import java.math.RoundingMode;
public class Vape extends Item implements NamedScreenHandlerFactory, ImplementedInventory {
public int mlbak;
public int rasxod;
public power power;
private final DefaultedList<ItemStack> inventory = DefaultedList.ofSize(2, ItemStack.EMPTY);
public Vape(Settings settings, int mlbak, int rasxod) {
public Vape(Settings settings, int mlbak, int rasxod, power power) {
super(settings.maxCount(1));
this.rasxod = rasxod;
this.mlbak = mlbak;
this.power = power;
}
//
@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
if (!world.isClient()) {
@ -55,6 +68,8 @@ public class Vape extends Item implements NamedScreenHandlerFactory, Implemented
nbt.putInt("amountjija", stack.getNbt().getInt("amountjija") - rasxod);
stack.setNbt(nbt);
user.setCurrentHand(hand);
PlayerAnimAPI.playPlayerAnim((ServerWorld) world, user, new Identifier("nerovapes", "vapeup"));
} else {
var stack = user.getStackInHand(hand);
if (stack.getNbt().getInt("amountjija") <= 0) {
@ -65,7 +80,6 @@ public class Vape extends Item implements NamedScreenHandlerFactory, Implemented
return TypedActionResult.success(user.getStackInHand(hand));
}
user.setCurrentHand(hand);
}
user.playSound(RegisterSounds.VAPE, 2f, 1f);
return TypedActionResult.pass(user.getStackInHand(hand));
@ -74,7 +88,6 @@ public class Vape extends Item implements NamedScreenHandlerFactory, Implemented
public static void spawnParticles(World world, PlayerEntity user, Vec3d vec3d, int count) {
var sw = (ServerWorld) world;
sw.spawnParticles(RegisterParticles.MY_CLOUD, user.getX(), user.getEyeY(), user.getZ(), 0, vec3d.getX(), vec3d.getY(), vec3d.getZ(), 0.1f);
sw.spawnParticles(RegisterParticles.RING_PARTICLE, user.getX(), user.getEyeY(), user.getZ(), 0, vec3d.getX(), vec3d.getY(), vec3d.getZ(), 0.1f);
for (int i = 0; i < count; i++) {
sw.spawnParticles(RegisterParticles.MY_CLOUD1, user.getX(), user.getEyeY(), user.getZ(), 0, vec3d.getX(), vec3d.getY(), vec3d.getZ(), 0.1f);
}
@ -103,6 +116,7 @@ public class Vape extends Item implements NamedScreenHandlerFactory, Implemented
if (!stack.hasNbt()) {
NbtCompound nbtCompound = new NbtCompound();
nbtCompound.putInt("amountjija", mlbak);
nbtCompound.putInt("usageticks", 60);
stack.setNbt(nbtCompound);
}
if (inventory.get(0) != ItemStack.EMPTY && inventory.get(0).getItem() instanceof ExampleFluid && entity instanceof PlayerEntity user) {
@ -132,27 +146,74 @@ public class Vape extends Item implements NamedScreenHandlerFactory, Implemented
return stack.getNbt().getInt("amountjija");
}
@Override
public void usageTick(World world, LivingEntity user, ItemStack stack, int remainingUseTicks) {
}
@Override
public int getMaxUseTime(ItemStack stack) {
return 72000;
return 2400;
}
public void newRing(PlayerEntity user, ServerWorld sw) {
if (user.getStackInHand(Hand.MAIN_HAND).getNbt().getInt("amountjija") <= 0) {
user.sendMessage(Text.of("Жижи нет"), true);
return;
}
if (user.getItemCooldownManager().getCooldownProgress(this, 0) != 0) return;
NbtCompound nbt = new NbtCompound();
nbt.putInt("amountjija", user.getStackInHand(Hand.MAIN_HAND).getNbt().getInt("amountjija") - rasxod);
user.getStackInHand(Hand.MAIN_HAND).setNbt(nbt);
Vec3d vec3d = Vec3d.fromPolar(user.getPitch(), user.getYaw());
vec3d.multiply(0.03f);
sw.spawnParticles(RegisterParticles.RING_PARTICLE, user.getX(), user.getEyeY(), user.getZ(), 0, vec3d.getX(), vec3d.getY(), vec3d.getZ(), 0.1f);
user.getItemCooldownManager().set(this, 20);
}
@Override
public void onStoppedUsing(ItemStack stack, World world, LivingEntity entity, int remainingUseTicks) {
PlayerEntity user = (PlayerEntity) entity;
PlayerEntity user = (PlayerEntity) entity;
if (!world.isClient()) {
user.getItemCooldownManager().set(this, 20);
Vec3d vec3d = Vec3d.fromPolar(user.getPitch(), user.getYaw());
vec3d.multiply(0.05f);
float intp = getMaxUseTime(stack) - remainingUseTicks;
float pizdec = intp / 20;
spawnParticles(world, user, vec3d, Math.round(pizdec));
NeroduckaleVapes.LOGGER.error(String.valueOf(pizdec));
vec3d.multiply(0.1f);
float intp = 2400 - remainingUseTicks; // Сколько тиков прошло
float pizdec = intp / 20; // сколько секунд прошло
float finallyy = pizdec * power.power;
spawnParticles(world, user, vec3d, Math.round(finallyy));
PlayerAnimAPI.stopPlayerAnim((ServerWorld) world, user, new Identifier("nerovapes", "vapeup"));
}
stack.getNbt().putInt("usageticks", 60);
}
@Override
public void usageTick(World world, LivingEntity user, ItemStack stack, int remainingUseTicks) {
int ticks = 2400 - remainingUseTicks; // СКОЛЬКО ТИКОВ ПРОШЛО
int max = remainingUseTicks - 2340; //СКОЛЬКО ОСТАЛОСЬ ПРИ MAX = 60
if (ticks > 59) {
if (ticks % 10 == 0) {
user.damage(world.getDamageSources().fall(), 2);
}
}
if (world.isClient) {
stack.getNbt().putInt("usageticks", max);
}
}
public int getPercent(ItemStack stack) {
var a = stack.getNbt().getInt("usageticks");
if (a > 60) {
a = 60;
}
if (a == 0) {
a = 1;
}
float one = 60f / a;
BigDecimal d = new BigDecimal(one);
d = d.setScale(2, RoundingMode.DOWN);
float two = 100 / d.floatValue();
int three = Math.round(two);
int finalresult = (183 * three) / 100;
if (finalresult <= 0) finalresult = 0;
return finalresult;
}
}

View file

@ -1,5 +1,7 @@
{
"item.nerovapes.pasito2": "Пасито 2",
"item.nerovapes.fluid": "Жижка",
"sound.nerovapes.vape": "Кто то попарил."
"sound.nerovapes.vape": "Кто то попарил.",
"key.nerovapes.ring": "Выпустить кольцо",
"category.nerovapes.vapes": "NERODUCKALE VAPES"
}

View file

@ -22,6 +22,9 @@
"ru.neroduckale.neroduckalevapesclient"
]
},
"mixins": [
"nerovapes.mixins.json"
],
"depends": {
"fabricloader": ">=0.14.25",
"fabric": "*",

View file

@ -1,8 +1,11 @@
{
"required": true,
"package": "ru.neroduckale.mixin",
"compatibilityLevel": "JAVA_17",
"injectors": {
"defaultRequire": 1
}
"required": true,
"package": "ru.neroduckale.mixin",
"compatibilityLevel": "JAVA_17",
"injectors": {
"defaultRequire": 1
},
"client": [
"ClientPlayerEntityMixin"
]
}