Skip to content

Commit

Permalink
Fix cloud scythe flight bug
Browse files Browse the repository at this point in the history
  • Loading branch information
agmass committed Sep 17, 2024
1 parent 1e53684 commit ce1777f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 14 deletions.
36 changes: 36 additions & 0 deletions src/main/java/org/agmas/scythes/Scythes.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@

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.network.packet.s2c.play.PlayerAbilitiesS2CPacket;
import org.agmas.scythes.items.Scythe;
import org.agmas.scythes.materials.CloudMaterial;

import java.util.HashMap;
import java.util.UUID;
Expand All @@ -24,6 +30,36 @@ public void onInitialize() {
a.add(ScythesItems.DIAMOND_SCYTHE);
a.add(ScythesItems.NETHERITE_SCYTHE);
});
ServerTickEvents.START_SERVER_TICK.register((s)->{
s.getPlayerManager().getPlayerList().forEach((p)->{

PlayerAbilities abilities = p.getAbilities();
if (!p.getAbilities().allowFlying && !p.interactionManager.getGameMode().isSurvivalLike()) {
boolean skip = false;
if (p.getInventory().getMainHandStack().getItem() instanceof Scythe ss) {
if (ss.toolMaterial.equals(CloudMaterial.INSTANCE)) {
skip = true;
}
}
if (!skip) {
p.interactionManager.getGameMode().setAbilities(abilities);
p.networkHandler.sendPacket(new PlayerAbilitiesS2CPacket(abilities));
}
}
if (p.getAbilities().allowFlying && p.interactionManager.getGameMode().isSurvivalLike()) {
boolean skip = false;
if (p.getInventory().getMainHandStack().getItem() instanceof Scythe ss) {
if (ss.toolMaterial.equals(CloudMaterial.INSTANCE)) {
skip = true;
}
}
if (!skip) {
p.interactionManager.getGameMode().setAbilities(abilities);
p.networkHandler.sendPacket(new PlayerAbilitiesS2CPacket(abilities));
}
}
});
});
PolymerResourcePackUtils.addModAssets("scythes");
}
}
15 changes: 1 addition & 14 deletions src/main/java/org/agmas/scythes/items/Scythe.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

public class Scythe extends ToolItem implements PolymerItem {

ToolMaterial toolMaterial;
public ToolMaterial toolMaterial;
PolymerModelData modelData;
Item item;

Expand Down Expand Up @@ -90,19 +90,6 @@ public void inventoryTick(ItemStack stack, World world, Entity entity, int slot,
abilities.allowFlying = true;
spe.networkHandler.sendPacket(new PlayerAbilitiesS2CPacket(abilities));
}
} else {
if (spe.getAbilities().allowFlying && spe.interactionManager.getGameMode().isSurvivalLike()) {
boolean skip = false;
if (spe.getInventory().getMainHandStack().getItem() instanceof Scythe s) {
if (s.toolMaterial.equals(CloudMaterial.INSTANCE)) {
skip = true;
}
}
if (!skip) {
spe.interactionManager.getGameMode().setAbilities(abilities);
spe.networkHandler.sendPacket(new PlayerAbilitiesS2CPacket(abilities));
}
}
}
}
}
Expand Down

0 comments on commit ce1777f

Please sign in to comment.