Skip to content

Commit

Permalink
Client-Side Support
Browse files Browse the repository at this point in the history
  • Loading branch information
agmass committed Oct 17, 2024
1 parent 1355b7c commit 52dabd3
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/agmas/scythes/Scythes.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
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;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
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;

Expand All @@ -17,10 +24,13 @@
public class Scythes implements ModInitializer {

public static HashMap<UUID, Boolean> 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);
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/org/agmas/scythes/items/Scythe.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"display": {
"icon": {
"id": "minecraft:iron_hoe "
"id": "minecraft:iron_hoe"
},
"title": {
"text": "To the skies!"
Expand Down
9 changes: 1 addition & 8 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down

0 comments on commit 52dabd3

Please sign in to comment.