Skip to content
This repository has been archived by the owner on Feb 10, 2022. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
BisUmTo committed Oct 11, 2021
1 parent 5f00ad7 commit 323b353
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 25 deletions.
Binary file added carpet-school.zip
Binary file not shown.
2 changes: 2 additions & 0 deletions src/main/java/it/bisumto/carpetschool/CarpetSchool.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import it.bisumto.carpetschool.config.Config;
import it.bisumto.carpetschool.events.CarpetSchoolEvents;
import it.bisumto.carpetschool.functions.ChatFunctions;
import it.bisumto.carpetschool.functions.FlySpeedFunctions;
import it.bisumto.carpetschool.mixins.MinecraftClientAccessor;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.loader.api.FabricLoader;
Expand All @@ -32,6 +33,7 @@ public class CarpetSchool implements CarpetExtension, ModInitializer {
@Override
public void scarpetApi(CarpetExpression expression) {
ChatFunctions.apply(expression.getExpr());
FlySpeedFunctions.apply(expression.getExpr());
}

@Override
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/it/bisumto/carpetschool/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class Config {
public boolean ONLINECHAT;
@SerializedName("commands")
public boolean COMMANDS;
@SerializedName("spectatorwheel")
public boolean SPECTATORWHEEL;
@SerializedName("schoolname")
public String SCHOOLNAME;

Expand All @@ -33,6 +35,7 @@ public Config() {
this.ONLINECHAT = false;
this.COMMANDS = false;
this.SCHOOLNAME = "Castello delle Idee 2021 - Juvenes";
this.SPECTATORWHEEL = false;
}

public static Config getInstance() {
Expand Down
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 src/main/java/it/bisumto/carpetschool/mixins/MouseMixin.java
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();
}
}
83 changes: 58 additions & 25 deletions src/main/resources/.data/carpet-school/scripts/frazioni.sc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ _s_proporzione(p) -> _proporzione(
t = if(rand(2), p, [p:3,p:2,p:1,p:0]);
t = if(rand(2), t, [t:1,t:0,t:3,t:2]);
);
_icognita(i) -> if(i!=null, i, '?');
_incognita(i) -> if(i!=null, str(i), '?');

// OPERAZIONI PROPORZIONI
_per(k, p) -> _perL(k, _perR(k, p));
Expand Down Expand Up @@ -94,21 +94,21 @@ _semplificaL(p) -> (
);

// DOMANDA RISPOSTA
global_primi = [1,2,3,5,7,11,13,17,19,23];
_casuale() -> (
random_item = [if(!rand(6),-1,1)*(floor(rand(10))+1), global_item:1];
polinomio = [global_item, random_item];
loop(rand(2)+1,
_add_rand_item(polinomio, if(!rand(6),-1,1)*(floor(rand(10))+1))
rapporto = rand(global_primi);
b1 = floor(rand(8))+1;
b2 = floor(rand(8))+1;
if(b1 == b2, b1 += if(!rand(2),-1,1)*(floor(rand(10))+1));
if(b1 == 0, b1 += if(!rand(2),-1,1)*(floor(rand(10))+1));
f = [b1, b1*rapporto, b2, b2*rapporto];
if(b1*rapporto < 50,
f = _perL(floor(rand(5)+1), f);
);
inv = _n_inventory_list(player());
if(inv,
loop(rand(2)+1,
item = rand(inv);
monomio = [item:1, item:0];
polinomio += monomio
);
if(b2*rapporto < 50,
f = _perR(floor(rand(5)+1), f);
);
polinomio
f
);

_domanda() -> (
Expand All @@ -117,24 +117,43 @@ _domanda() -> (
print(format('b#ff0000 MATEMATICA CON MINECRAFT') + ' #2.' + (global_domanda+=1));
print(format('i Rispondi correttamente per ricevere un premio!\n'));

// TODO:
// polinomio = _casuale();
// //print(polinomio);
// print(_s_polinomio(polinomio) + '=\n');
proporzione = _casuale();
index = floor(rand(4));
global_risposta_corretta = proporzione:index;
proporzione:index = null;
print(format('b ' + _s_proporzione(proporzione)));

// r1 = _riduci(polinomio);
// r2 = copy(r1);
// r3 = copy(r1);
// r2:(rand(length(r2))):0 += if(!rand(6),-1,1)*(floor(rand(10))+1);
// r3:(rand(length(r2))):0 += if(!rand(6),-1,1)*(floor(rand(10))+1);
if(index == 0,
r1 = proporzione:1 * proporzione:3 / proporzione:2;
r2 = proporzione:2 * proporzione:3 / proporzione:1,
index == 1;
r1 = proporzione:0 * proporzione:2 / proporzione:3;
r2 = proporzione:2 * proporzione:3 / proporzione:0,
index == 2;
r1 = proporzione:1 * proporzione:3 / proporzione:0;
r2 = proporzione:0 * proporzione:1 / proporzione:3,
index == 3;
r1 = proporzione:0 * proporzione:2 / proporzione:1;
r1 = proporzione:0 * proporzione:1 / proporzione:2,
);
if(rand(6), r1 = (floor(rand(25))+1));
if(rand(6), r2 = (floor(rand(25))+1));
r1 = floor(r1);
r2 = floor(r2);
if(r1 == global_risposta_corretta,
r1 += if(!rand(2),-1,1)*(floor(rand(10))+1)
);
while(r2 == global_risposta_corretta || r2 == r1, 127,
r2 += if(!rand(2),-1,1)*(floor(rand(10))+1)
);

possibili_risposte = [r1,r2,r3];
possibili_risposte = [global_risposta_corretta,r1,r2];
risposte_disordinate = _c_shuffle(possibili_risposte);
global_risposta_corretta = possibili_risposte:0;

global_n_risposta_corretta = risposte_disordinate~global_risposta_corretta;

for(risposte_disordinate,
print(format(' ' + global_lettere:_i, '!/frazioni '+_i)+' '+format(' '+_,'!/frazioni '+_i)),
print(format(' ' + global_lettere:_i, '!/frazioni '+_i)+' '+format(' ? = '+_,'!/frazioni '+_i)),
);
print('=====================================================');
global_countdown = world_time();
Expand Down Expand Up @@ -162,11 +181,25 @@ _risposta(risp) -> (
);

// FREEZE
global_pos = {};
run('carpet creativeFlySpeed 0');
_freeze() -> (
if(run('tick freeze'):1:0~'normally',run('tick freeze'));
for(player('all'),
global_pos:_ = pos(_);
fly_speed(_, 0);
modify(_, 'gamemode', 'spectator')
)
);
_unfreeze() -> (
if(run('tick freeze'):1:0~'frozen',run('tick freeze'));
for(player('all'),
if(global_pos:_,
modify(_, 'gamemode', 'survival');
modify(_, 'pos', global_pos:_)
);
delete(global_pos:_)
);
);
_unfreeze();

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/carpet-school.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"CreateWorldScreenMixin",
"GameMenuScreenMixin",
"MinecraftClientAccessor",
"MouseMixin",
"PackScreenMixin",
"ServerPlayerEntityMixin",
"TitleScreenMixin"
Expand Down

0 comments on commit 323b353

Please sign in to comment.