Merge branch 'master' into 1.17

This commit is contained in:
gnembon committed 2020-12-13 06:31:17 -04:00
commit e89f4444dc
15 files changed
+165 -23

No files matched your search

@@ -18,6 +18,7 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.block.BlockState;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.passive.MerchantEntity;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.entity.Entity;
@@ -35,6 +36,8 @@ import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.village.Merchant;
import net.minecraft.village.TradeOffer;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import org.apache.commons.lang3.tuple.Pair;
@@ -548,6 +551,20 @@ public class CarpetEventServer
), player::getCommandSource);
}
};
public static final Event PLAYER_TRADES = new Event("player_trades", 5, false)
{
@Override
public void onTrade(ServerPlayerEntity player, Merchant merchant, TradeOffer tradeOffer)
{
handler.call( () -> Arrays.asList(
new EntityValue(player),
merchant instanceof MerchantEntity ? new EntityValue((MerchantEntity) merchant) : Value.NULL,
ValueConversions.of(tradeOffer.getOriginalFirstBuyItem()),
ValueConversions.of(tradeOffer.getSecondBuyItem()),
ValueConversions.of(tradeOffer.getSellItem())
), player::getCommandSource);
}
};
public static final Event PLAYER_PICKS_UP_ITEM = new Event("player_picks_up_item", 2, false)
{
@Override
@@ -926,6 +943,7 @@ public class CarpetEventServer
public void onDamage(Entity target, float amount, DamageSource source) { }
public void onRecipeSelected(ServerPlayerEntity player, Identifier recipe, boolean fullStack) {}
public void onSlotSwitch(ServerPlayerEntity player, int from, int to) {}
public void onTrade(ServerPlayerEntity player, Merchant merchant, TradeOffer tradeOffer) {}
public void onWorldEvent(ServerWorld world, BlockPos pos) { }
@@ -530,7 +530,7 @@ public class Auxiliary {
if (pVal instanceof FormattedTextValue)
title = ((FormattedTextValue) pVal).getText();
else
title = Text.of(pVal.getString());
title = new LiteralText(pVal.getString());
}
TitleS2CPacket timesPacket;
if (lv.size() > 3)
@@ -135,23 +135,25 @@ public class DataStructures {
expression.addFunction("range", (lv) ->
{
long from = 0;
long to = 0;
long step = 1;
NumericValue from = Value.ZERO;
NumericValue to;
NumericValue step = Value.ONE;
int argsize = lv.size();
if (argsize == 0 || argsize > 3)
throw new InternalExpressionException("'range' accepts from 1 to 3 arguments, not "+argsize);
to = NumericValue.asNumber(lv.get(0)).getLong();
to = NumericValue.asNumber(lv.get(0));
if (lv.size() > 1)
{
from = to;
to = NumericValue.asNumber(lv.get(1)).getLong();
to = NumericValue.asNumber(lv.get(1));
if (lv.size() > 2)
{
step = NumericValue.asNumber(lv.get(2)).getLong();
step = NumericValue.asNumber(lv.get(2));
}
}
return LazyListValue.range(from, to, step);
return (from.isInteger() && to.isInteger() && step.isInteger())
? LazyListValue.rangeLong(from.getLong(), to.getLong(), step.getLong())
: LazyListValue.rangeDouble(from.getDouble(), to.getDouble(), step.getDouble());
});
expression.addLazyFunction("m", -1, (c, t, llv) ->
@@ -11,7 +11,7 @@ import java.util.Locale;
public abstract class LazyListValue extends AbstractListValue implements Iterator<Value>
{
public static LazyListValue range(long from, long to, long step)
public static LazyListValue rangeDouble(double from, double to, double step)
{
return new LazyListValue()
{
@@ -23,10 +23,10 @@ public abstract class LazyListValue extends AbstractListValue implements Iterato
this.limit = to;
this.stepp = step;
}
private long start;
private long current;
private long limit;
private long stepp;
private final double start;
private double current;
private final double limit;
private final double stepp;
@Override
public Value next()
{
@@ -50,7 +50,50 @@ public abstract class LazyListValue extends AbstractListValue implements Iterato
@Override
public String getString()
{
return String.format(Locale.ROOT, "[%d, %d, ..., %d)",start, start+stepp, limit);
return String.format(Locale.ROOT, "[%s, %s, ..., %s)",NumericValue.of(start).getString(), NumericValue.of(start+stepp).getString(), NumericValue.of( limit).getString());
}
};
}
public static LazyListValue rangeLong(long from, long to, long step)
{
return new LazyListValue()
{
{
if (step == 0)
throw new InternalExpressionException("Range will never end with a zero step");
this.start = from;
this.current = this.start;
this.limit = to;
this.stepp = step;
}
private final long start;
private long current;
private final long limit;
private final long stepp;
@Override
public Value next()
{
Value val = new NumericValue(current);
current += stepp;
return val;
}
@Override
public void reset()
{
current = start;
}
@Override
public boolean hasNext()
{
return stepp > 0?(current < limit):(current > limit);
}
@Override
public String getString()
{
return String.format(Locale.ROOT, "[%s, %s, ..., %s)",NumericValue.of(start).getString(), NumericValue.of(start+stepp).getString(), NumericValue.of( limit).getString());
}
};
}
@@ -15,6 +15,7 @@ import java.math.RoundingMode;
import java.util.Locale;
import static java.lang.Math.abs;
import static java.lang.Math.signum;
public class NumericValue extends Value
{
@@ -57,6 +58,7 @@ public class NumericValue extends Value
{
if (value.isInfinite()) return "INFINITY";
if (value.isNaN()) return "NaN";
if (abs(value) < epsilon) return (signum(value) < 0)?"-0":"0"; //zero rounding fails with big decimals
// dobules have 16 point precision, 12 is plenty to display
return BigDecimal.valueOf(value).round(displayRounding).stripTrailingZeros().toPlainString();
}
@@ -306,4 +308,9 @@ public class NumericValue extends Value
if (longValue != null) return new NumericValue(-longValue);
return new NumericValue(-value);
}
public boolean isInteger()
{
return longValue!= null || getDouble() == (double)getLong();
}
}
+6 -4
View File
@@ -13,10 +13,12 @@ import java.util.regex.PatternSyntaxException;
public abstract class Value implements Comparable<Value>, Cloneable
{
public static Value FALSE = new NumericValue(0);
public static Value TRUE = new NumericValue(1);
public static Value ZERO = FALSE;
public static Value NULL = new NullValue();
public static NumericValue FALSE = new NumericValue(0);
public static NumericValue TRUE = new NumericValue(1);
public static NumericValue ZERO = FALSE;
public static NumericValue ONE = TRUE;
public static NullValue NULL = new NullValue();
public String boundVariable;