Merge branch 'master' into future

This commit is contained in:
gnembon committed 2021-08-25 15:19:30 -03:00
commit 7e67966fd2
9 files changed
+56 -23

No files matched your search

+3 -2
View File
@@ -6,11 +6,12 @@ There is bunch of them - they require a number and spit out a number, doing what
### `fact(n)` ### `fact(n)`
Factorial of a number, a.k.a `n!`, just not in `scarpet`. Gets big... quick... Factorial of a number, a.k.a `n!`, just not in `scarpet`. Gets big... quick... Therefore, values larger
than `fact(20)` will not return the exact value, but a value with 'double-float' precision.
### `sqrt(n)` ### `sqrt(n)`
Square root. For other fancy roots, use `^`, math and yo noggin. Imagine square roots on a tree... Square root (not 'a squirt') of a number. For other fancy roots, use `^`, math and yo noggin. Imagine square roots on a tree...
### `abs(n)` ### `abs(n)`
@@ -22,6 +22,7 @@ import net.minecraft.util.DyeColor;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import java.util.Arrays; import java.util.Arrays;
import java.util.Locale;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.mojang.brigadier.arguments.IntegerArgumentType.getInteger; import static com.mojang.brigadier.arguments.IntegerArgumentType.getInteger;
@@ -111,7 +112,7 @@ public class SpawnCommand
{ {
throw new SimpleCommandExceptionType(Messenger.c("r Wrong mob type: "+string+" should be "+ Arrays.stream(SpawnGroup.values()).map(SpawnGroup::getName).collect(Collectors.joining(", ")))).create(); throw new SimpleCommandExceptionType(Messenger.c("r Wrong mob type: "+string+" should be "+ Arrays.stream(SpawnGroup.values()).map(SpawnGroup::getName).collect(Collectors.joining(", ")))).create();
} }
return SpawnGroup.valueOf(string.toUpperCase()); return SpawnGroup.byName(string.toLowerCase(Locale.ROOT));
} }
@@ -15,7 +15,7 @@ public class TestCommand
{ {
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) public static void register(CommandDispatcher<ServerCommandSource> dispatcher)
{ {
dispatcher.register(literal("test"). dispatcher.register(literal("testcarpet").
then(literal("dump"). then(literal("dump").
executes((c) -> CarpetServer.settingsManager.printAllRulesToLog(null)). executes((c) -> CarpetServer.settingsManager.printAllRulesToLog(null)).
then(argument("category", word()). then(argument("category", word()).
@@ -13,5 +13,5 @@ public interface RecipeManagerInterface
* Gets all the recipes for a given item. Also used for {@link carpet.helpers.HopperCounter#guessColor} to guess the * Gets all the recipes for a given item. Also used for {@link carpet.helpers.HopperCounter#guessColor} to guess the
* colour of an item to display it prettily * colour of an item to display it prettily
*/ */
List<Recipe<?>> getAllMatching(RecipeType type, Identifier output); List<Recipe<?>> getAllMatching(RecipeType<?> type, Identifier output);
} }
@@ -22,9 +22,11 @@ public class RecipeManager_scarpetMixin implements RecipeManagerInterface
@Shadow private Map<RecipeType<?>, Map<Identifier, Recipe<?>>> recipes; @Shadow private Map<RecipeType<?>, Map<Identifier, Recipe<?>>> recipes;
@Override @Override
public List<Recipe<?>> getAllMatching(RecipeType type, Identifier output) public List<Recipe<?>> getAllMatching(RecipeType<?> type, Identifier output)
{ {
Map<Identifier, Recipe<?>> typeRecipes = recipes.get(type); Map<Identifier, Recipe<?>> typeRecipes = recipes.get(type);
// happens when mods add recipe to the registry without updating recipe manager
if (typeRecipes == null) return Collections.emptyList();
if (typeRecipes.containsKey(output)) return Collections.singletonList(typeRecipes.get(output)); if (typeRecipes.containsKey(output)) return Collections.singletonList(typeRecipes.get(output));
return Lists.newArrayList(typeRecipes.values().stream().filter( return Lists.newArrayList(typeRecipes.values().stream().filter(
r -> Registry.ITEM.getId(r.getOutput().getItem()).equals(output)).collect(Collectors.toList())); r -> Registry.ITEM.getId(r.getOutput().getItem()).equals(output)).collect(Collectors.toList()));
@@ -135,8 +135,18 @@ public class EntityPlayerMPFake extends ServerPlayerEntity
this.getServerWorld().getChunkManager().updatePosition(this); this.getServerWorld().getChunkManager().updatePosition(this);
onTeleportationDone(); //<- causes hard crash but would need to be done to enable portals // not as of 1.17 onTeleportationDone(); //<- causes hard crash but would need to be done to enable portals // not as of 1.17
} }
super.tick(); try
this.playerTick(); {
super.tick();
this.playerTick();
}
catch (NullPointerException ignored)
{
// happens with that paper port thingy - not sure what that would fix, but hey
// the game not gonna crash violently.
}
} }
private void shakeOff() private void shakeOff()
+21 -13
View File
@@ -1162,20 +1162,28 @@ public class Expression
for (Map.Entry<String, String> pair : functionalEquivalence.entrySet()) { for (Map.Entry<String, String> pair : functionalEquivalence.entrySet()) {
String operator = pair.getKey(); String operator = pair.getKey();
String function = pair.getValue(); String function = pair.getValue();
if (symbol.equals(operator) || symbol.equals(function)) { if ((symbol.equals(operator) || symbol.equals(function)) && node.args.size() > 0)
List<ExpressionNode> newargs = new ArrayList<>(); {
boolean contracted = false; boolean leftOptimizable = operators.get(operator).isLeftAssoc();
for (ExpressionNode arg : node.args) { ExpressionNode optimizedChild = node.args.get(leftOptimizable?0:(node.args.size()-1));
String argsymbol = arg.token.surface; // child is unoptimized and also same class String type = optimizedChild.token.surface;
if ((argsymbol.equals(operator) || argsymbol.equals(function)) && (!(arg.op instanceof LazyValue.ContextFreeLazyValue))) { if ((type.equals(operator) || type.equals(function)) && (!(optimizedChild.op instanceof LazyValue.ContextFreeLazyValue)))
newargs.addAll(arg.args); {
contracted = true;
} else {
newargs.add(arg);
}
}
if (contracted) {
optimized = true; optimized = true;
List<ExpressionNode> newargs = new ArrayList<>();
if (leftOptimizable)
{
newargs.addAll(optimizedChild.args);
for (int i = 1; i < node.args.size(); i++)
newargs.add(node.args.get(i));
}
else
{
for (int i = 0; i < node.args.size()-1; i++)
newargs.add(node.args.get(i));
newargs.addAll(optimizedChild.args);
}
if (CarpetSettings.scriptsDebugging) if (CarpetSettings.scriptsDebugging)
CarpetScriptServer.LOG.info(" - " + symbol + "(" + node.args.size() + ") => " + function + "(" + newargs.size() + ") at line " + (node.token.lineno + 1) + ", node depth " + indent); CarpetScriptServer.LOG.info(" - " + symbol + "(" + node.args.size() + ") => " + function + "(" + newargs.size() + ") at line " + (node.token.lineno + 1) + ", node depth " + indent);
node.token.morph(Tokenizer.Token.TokenType.FUNCTION, function); node.token.morph(Tokenizer.Token.TokenType.FUNCTION, function);
@@ -93,7 +93,7 @@ public class Inventories {
CarpetContext cc = (CarpetContext)c; CarpetContext cc = (CarpetContext)c;
if (lv.size() < 1) throw new InternalExpressionException("'recipe_data' requires at least one argument"); if (lv.size() < 1) throw new InternalExpressionException("'recipe_data' requires at least one argument");
String recipeName = lv.get(0).getString(); String recipeName = lv.get(0).getString();
RecipeType type = RecipeType.CRAFTING; RecipeType<?> type = RecipeType.CRAFTING;
if (lv.size() > 1) if (lv.size() > 1)
{ {
String recipeType = lv.get(1).getString(); String recipeType = lv.get(1).getString();
@@ -20,12 +20,23 @@ public class Arithmetic {
expression.addUnaryFunction("fact", (v) -> expression.addUnaryFunction("fact", (v) ->
{ {
long number = NumericValue.asNumber(v).getLong(); long number = NumericValue.asNumber(v).getLong();
long factorial = 1; if (number < 21)
{
long factorial = 1;
for (int i = 1; i <= number; i++)
{
factorial = factorial * i;
}
return new NumericValue(factorial);
}
// values over 21 will exceed long limits
double factorial = 1.0;
for (int i = 1; i <= number; i++) for (int i = 1; i <= number; i++)
{ {
factorial = factorial * i; factorial = factorial * i;
} }
return new NumericValue(factorial); return new NumericValue(factorial);
}); });
expression.addMathematicalUnaryFunction("sin", (d) -> Math.sin(Math.toRadians(d))); expression.addMathematicalUnaryFunction("sin", (d) -> Math.sin(Math.toRadians(d)));
expression.addMathematicalUnaryFunction("cos", (d) -> Math.cos(Math.toRadians(d))); expression.addMathematicalUnaryFunction("cos", (d) -> Math.cos(Math.toRadians(d)));