This repository has been archived by the owner on Feb 10, 2022. It is now read-only.
forked from gnembon/fabric-carpet-extension-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
7 changed files
with
118 additions
and
25 deletions.
There are no files selected for viewing
Binary file not shown.
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
31 changes: 31 additions & 0 deletions
31
src/main/java/it/bisumto/carpetschool/functions/FlySpeedFunctions.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,31 @@ | ||
package it.bisumto.carpetschool.functions; | ||
|
||
import carpet.script.Expression; | ||
import carpet.script.exception.InternalExpressionException; | ||
import carpet.script.value.EntityValue; | ||
import carpet.script.value.NumericValue; | ||
import carpet.script.value.Value; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.stat.Stat; | ||
import net.minecraft.stat.StatType; | ||
import net.minecraft.util.Identifier; | ||
|
||
public class FlySpeedFunctions { | ||
public static void apply(Expression expression) { | ||
// fly_speed(speed) | ||
expression.addLazyFunction("fly_speed", 2, (c, t, lv) -> { | ||
Value v = lv.get(0).evalValue(c); | ||
if (!(v instanceof EntityValue) || !(((EntityValue) v).getEntity() instanceof PlayerEntity e)) | ||
throw new InternalExpressionException("First argument to modify should be a player"); | ||
float speed = (float) lv.get(1).evalValue(c).readDoubleNumber(); | ||
e.getAbilities().setFlySpeed(speed); | ||
|
||
return (_c, _t) -> new NumericValue(speed); | ||
}); | ||
} | ||
|
||
private static <T> Stat<T> getStat(StatType<T> type, Identifier id) { | ||
T key = type.getRegistry().get(id); | ||
return key != null && type.hasStat(key) ? type.getOrCreateStat(key) : null; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/it/bisumto/carpetschool/mixins/MouseMixin.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,23 @@ | ||
package it.bisumto.carpetschool.mixins; | ||
|
||
import it.bisumto.carpetschool.config.Config; | ||
import net.minecraft.client.Mouse; | ||
import net.minecraft.client.gui.screen.world.CreateWorldScreen; | ||
import net.minecraft.client.gui.widget.CyclingButtonWidget; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
@Mixin(Mouse.class) | ||
public class MouseMixin { | ||
@Inject(method = "onMouseScroll", | ||
at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerAbilities;setFlySpeed(F)V"), | ||
cancellable = true | ||
) | ||
void onMouseScrollMixin(long window, double horizontal, double vertical, CallbackInfo ci){ | ||
if(!Config.getInstance().SPECTATORWHEEL) ci.cancel(); | ||
} | ||
} |
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