From 52dabd3ff4cb4c24cb8232a335da820131c954ac Mon Sep 17 00:00:00 2001 From: agmas Date: Thu, 17 Oct 2024 14:52:16 +0400 Subject: [PATCH] Client-Side Support --- gradle.properties | 2 +- src/main/java/org/agmas/scythes/Scythes.java | 10 ++++++++++ src/main/java/org/agmas/scythes/items/Scythe.java | 10 ++++++++-- .../data/scythes/advancement/cloudscythe.json | 2 +- src/main/resources/fabric.mod.json | 9 +-------- 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/gradle.properties b/gradle.properties index d74d6ed..5065001 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ minecraft_version=1.21.1 yarn_mappings=1.21.1+build.3 loader_version=0.16.5 # Mod Properties -mod_version=1.0.9 +mod_version=1.1.1 maven_group=org.agmas archives_base_name=Scythes # Dependencies diff --git a/src/main/java/org/agmas/scythes/Scythes.java b/src/main/java/org/agmas/scythes/Scythes.java index 8d3db4c..675740f 100644 --- a/src/main/java/org/agmas/scythes/Scythes.java +++ b/src/main/java/org/agmas/scythes/Scythes.java @@ -1,5 +1,9 @@ package org.agmas.scythes; +import com.mojang.serialization.Codec; +import eu.pb4.polymer.networking.api.PolymerNetworking; +import eu.pb4.polymer.networking.api.client.PolymerClientNetworking; +import eu.pb4.polymer.networking.api.server.PolymerServerNetworking; import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; @@ -7,7 +11,10 @@ import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents; import net.minecraft.entity.player.PlayerAbilities; import net.minecraft.item.ItemGroups; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.nbt.NbtInt; import net.minecraft.network.packet.s2c.play.PlayerAbilitiesS2CPacket; +import net.minecraft.util.Identifier; import org.agmas.scythes.items.Scythe; import org.agmas.scythes.materials.CloudMaterial; @@ -17,10 +24,13 @@ public class Scythes implements ModInitializer { public static HashMap canDoubleJump = new HashMap<>(); + public static Identifier REGISTER_PACKET = Identifier.of("scythes", "register_packet"); @Override public void onInitialize() { ScythesItems.initalize(); + PolymerServerNetworking.setServerMetadata(REGISTER_PACKET, NbtInt.of(1)); + PolymerClientNetworking.setClientMetadata(REGISTER_PACKET, NbtInt.of(1)); ItemGroupEvents.modifyEntriesEvent(ItemGroups.COMBAT).register((a)->{ a.add(ScythesItems.WOODEN_SCYTHE); a.add(ScythesItems.STONE_SCYTHE); diff --git a/src/main/java/org/agmas/scythes/items/Scythe.java b/src/main/java/org/agmas/scythes/items/Scythe.java index 75c5e93..5519512 100644 --- a/src/main/java/org/agmas/scythes/items/Scythe.java +++ b/src/main/java/org/agmas/scythes/items/Scythe.java @@ -3,6 +3,7 @@ import eu.pb4.polymer.common.api.PolymerCommonUtils; import eu.pb4.polymer.core.api.item.PolymerItem; import eu.pb4.polymer.core.api.utils.PolymerUtils; +import eu.pb4.polymer.networking.api.server.PolymerServerNetworking; import eu.pb4.polymer.resourcepack.api.PolymerModelData; import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils; import net.minecraft.block.Block; @@ -18,6 +19,7 @@ import net.minecraft.entity.player.PlayerAbilities; import net.minecraft.item.*; import net.minecraft.item.tooltip.TooltipType; +import net.minecraft.nbt.NbtInt; import net.minecraft.network.packet.s2c.play.PlayerAbilitiesS2CPacket; import net.minecraft.recipe.Ingredient; import net.minecraft.registry.RegistryWrapper; @@ -73,7 +75,7 @@ public void inventoryTick(ItemStack stack, World world, Entity entity, int slot, if (selected) { if (abilities.flying) { Scythes.canDoubleJump.put(spe.getUuid(), false); - spe.setVelocity(spe.getRotationVector().multiply(1.3).x,spe.getRotationVector().multiply(0.9).y,spe.getRotationVector().multiply(1.3).z); + spe.setVelocity(spe.getRotationVector().multiply(1.2).x,spe.getRotationVector().multiply(1.2).y,spe.getRotationVector().multiply(1.2).z); spe.velocityDirty = true; spe.velocityModified = true; stack.damage(1, spe, EquipmentSlot.MAINHAND); @@ -111,6 +113,10 @@ public boolean postHit(ItemStack stack, LivingEntity target, LivingEntity attack @Override public Item getPolymerItem(ItemStack itemStack, @Nullable ServerPlayerEntity player) { - return item; + if (PolymerServerNetworking.getMetadata(player.networkHandler, Scythes.REGISTER_PACKET, NbtInt.TYPE) == NbtInt.of(1)) { + return this; + } else { + return item; + } } } diff --git a/src/main/resources/data/scythes/advancement/cloudscythe.json b/src/main/resources/data/scythes/advancement/cloudscythe.json index 18d50cc..4ccfdad 100644 --- a/src/main/resources/data/scythes/advancement/cloudscythe.json +++ b/src/main/resources/data/scythes/advancement/cloudscythe.json @@ -1,7 +1,7 @@ { "display": { "icon": { - "id": "minecraft:iron_hoe " + "id": "minecraft:iron_hoe" }, "title": { "text": "To the skies!" diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 1926098..f04de90 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -10,19 +10,12 @@ "icon": "assets/scythes/icon.png", "environment": "*", "entrypoints": { - "client": [ - "org.agmas.scythes.client.ScythesClient" - ], "main": [ "org.agmas.scythes.Scythes" ] }, "mixins": [ - "scythes.mixins.json", - { - "config": "scythes.client.mixins.json", - "environment": "client" - } + "scythes.mixins.json" ], "depends": { "fabricloader": ">=${loader_version}",