generated from neoforged/MDK
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
925d0ff
commit ae9f39d
Showing
7 changed files
with
109 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/main/java/com/leclowndu93150/flightutils/curio/FlightCapability.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package com.leclowndu93150.flightutils.curio; | ||
|
||
import com.leclowndu93150.flightutils.registry.ItemRegistry; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.neoforged.bus.api.IEventBus; | ||
import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent; | ||
import top.theillusivec4.curios.api.CuriosApi; | ||
import top.theillusivec4.curios.api.CuriosCapability; | ||
import top.theillusivec4.curios.api.SlotContext; | ||
import top.theillusivec4.curios.api.type.capability.ICurio; | ||
|
||
public class FlightCapability { | ||
|
||
private void startFlight(Player player){ | ||
if(!player.isCreative() && !player.isSpectator()){ | ||
player.getAbilities().mayfly = true; | ||
player.onUpdateAbilities(); | ||
} | ||
} | ||
|
||
private void stopFlight(Player player) { | ||
if (!player.isCreative() && !player.isSpectator()) { | ||
player.getAbilities().flying = false; | ||
player.getAbilities().mayfly = false; | ||
player.onUpdateAbilities(); | ||
} | ||
} | ||
|
||
public void registerCapabilities(final RegisterCapabilitiesEvent evt) { | ||
evt.registerItem( | ||
CuriosCapability.ITEM, | ||
(stack, context) -> new ICurio() { | ||
|
||
@Override | ||
public ItemStack getStack() { | ||
return ItemRegistry.ANGEL_RING.toStack(); | ||
} | ||
|
||
@Override | ||
public void curioTick(SlotContext slotContext) { | ||
if (slotContext.entity() instanceof Player player) { | ||
if (!player.getAbilities().mayfly) { | ||
startFlight(player); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public boolean canEquipFromUse(SlotContext slotContext) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean canEquip(SlotContext slotContext) { | ||
return CuriosApi.getCuriosHelper().findEquippedCurio(ItemRegistry.ANGEL_RING.get(), slotContext.entity()).isEmpty(); | ||
} | ||
|
||
@Override | ||
public void onEquip(SlotContext slotContext, ItemStack prevStack) { | ||
if (slotContext.getWearer() instanceof Player) | ||
startFlight((Player) slotContext.getWearer()); | ||
} | ||
|
||
@Override | ||
public void onUnequip(SlotContext slotContext, ItemStack newStack) { | ||
if (slotContext.getWearer() instanceof Player) | ||
stopFlight((Player) slotContext.getWearer()); | ||
} | ||
|
||
} | ||
|
||
); | ||
} | ||
} | ||
|
12 changes: 10 additions & 2 deletions
12
src/main/java/com/leclowndu93150/flightutils/items/AngelRingItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,19 @@ | ||
package com.leclowndu93150.flightutils.items; | ||
|
||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.item.ItemStack; | ||
import org.jetbrains.annotations.NotNull; | ||
import top.theillusivec4.curios.api.type.capability.ICurioItem; | ||
|
||
public class AngelRingItem extends Item { | ||
|
||
public class AngelRingItem extends Item implements ICurioItem { | ||
|
||
public AngelRingItem(Properties pProperties) { | ||
super(pProperties); | ||
} | ||
|
||
@Override | ||
public int getMaxStackSize(@NotNull ItemStack stack) { | ||
return 1; | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/leclowndu93150/flightutils/items/IntertiaRingItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,17 @@ | ||
package com.leclowndu93150.flightutils.items; | ||
|
||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.item.ItemStack; | ||
|
||
public class IntertiaRingItem extends Item { | ||
|
||
public IntertiaRingItem(Properties pProperties) { | ||
super(pProperties); | ||
} | ||
|
||
@Override | ||
public int getMaxStackSize(ItemStack stack) { | ||
return 1; | ||
} | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/com/leclowndu93150/flightutils/items/MiningRingItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,16 @@ | ||
package com.leclowndu93150.flightutils.items; | ||
|
||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.item.ItemStack; | ||
|
||
public class MiningRingItem extends Item { | ||
|
||
public MiningRingItem(Properties pProperties) { | ||
super(pProperties); | ||
} | ||
|
||
@Override | ||
public int getMaxStackSize(ItemStack stack) { | ||
return 1; | ||
} | ||
} |