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

+8 -1
View File
@@ -1710,6 +1710,8 @@ map(range(10),_*_) => [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
reduce(range(10),_a+_, 0) => 45
range(5,10) => [5, 6, 7, 8, 9]
range(20, 10, -2) => [20, 18, 16, 14, 12]
range(-0.3, 0.3, 0.1) => [-0.3, -0.2, -0.1, 0, 0.1, 0.2]
range(0.3, -0.3, -0.1) => [0.3, 0.2, 0.1, -0, -0.1, -0.2]
</pre>
## Map operations
@@ -4051,7 +4053,12 @@ adjusted.
### `__on_player_interacts_with_entity(player, entity, hand)`
Triggered when player right clicks (interacts) with an entity, even if the entity has no vanilla interaction with the player or
the item they are holding. The event is invoked after receiving a packet from the client, before anything happens server side
with that interaction
with that interaction.
### `__on_player_trades(player, entity, buy, buyB, sell)`
Triggered when player trades with a merchant. The event is invoked after the server allow the trade, but before the inventory
changes and merchant updates its trade-uses counter.
The parameter `entity` can be `null` if the merchant is not an entity.
### `__on_player_collides_with_entity(player, entity)`
Triggered every time a player - entity collisions are calculated, before effects of collisions are applied in the game.
+6 -1
View File
@@ -114,7 +114,12 @@ adjusted.
### `__on_player_interacts_with_entity(player, entity, hand)`
Triggered when player right clicks (interacts) with an entity, even if the entity has no vanilla interaction with the player or
the item they are holding. The event is invoked after receiving a packet from the client, before anything happens server side
with that interaction
with that interaction.
### `__on_player_trades(player, entity, buy, buyB, sell)`
Triggered when player trades with a merchant. The event is invoked after the server allow the trade, but before the inventory
changes and merchant updates its trade-uses counter.
The parameter `entity` can be `null` if the merchant is not an entity.
### `__on_player_collides_with_entity(player, entity)`
Triggered every time a player - entity collisions are calculated, before effects of collisions are applied in the game.
+2
View File
@@ -215,6 +215,8 @@ map(range(10),_*_) => [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
reduce(range(10),_a+_, 0) => 45
range(5,10) => [5, 6, 7, 8, 9]
range(20, 10, -2) => [20, 18, 16, 14, 12]
range(-0.3, 0.3, 0.1) => [-0.3, -0.2, -0.1, 0, 0.1, 0.2]
range(0.3, -0.3, -0.1) => [0.3, 0.2, 0.1, -0, -0.1, -0.2]
</pre>
## Map operations
@@ -69,7 +69,7 @@ public abstract class PlayerManager_fakePlayersMixin
ServerPlayerEntity serverPlayerEntity_3 = (ServerPlayerEntity) var5.next();
if(serverPlayerEntity_3 instanceof EntityPlayerMPFake)
{
serverPlayerEntity_3.kill();
((EntityPlayerMPFake)serverPlayerEntity_3).kill(new TranslatableText("multiplayer.disconnect.duplicate_login"));
continue;
}
serverPlayerEntity_3.networkHandler.disconnect(new TranslatableText("multiplayer.disconnect.duplicate_login"));
@@ -0,0 +1,33 @@
package carpet.mixins;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.slot.TradeOutputSlot;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.village.Merchant;
import net.minecraft.village.TradeOffer;
import org.spongepowered.asm.mixin.Final;
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.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import static carpet.script.CarpetEventServer.Event.PLAYER_TRADES;
@Mixin(value = TradeOutputSlot.class)
public abstract class TradeOutputSlot_scarpetEventMixin {
@Shadow @Final private Merchant merchant;
@Inject(method = "onTakeItem", at = @At(value = "INVOKE",
target = "Lnet/minecraft/village/Merchant;trade(Lnet/minecraft/village/TradeOffer;)V"),
locals = LocalCapture.CAPTURE_FAILHARD
)
private void onTrade(PlayerEntity player, ItemStack stack, CallbackInfoReturnable cir, TradeOffer tradeOffer) {
if(PLAYER_TRADES.isNeeded() && !this.merchant.getMerchantWorld().isClient())
{
PLAYER_TRADES.onTrade((ServerPlayerEntity) player, merchant, tradeOffer);
}
}
}
@@ -9,6 +9,7 @@ import net.minecraft.network.packet.s2c.play.PlayerListS2CPacket;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.player.HungerManager;
import net.minecraft.network.NetworkSide;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.ServerTask;
@@ -93,9 +94,14 @@ public class EntityPlayerMPFake extends ServerPlayerEntity
@Override
public void kill()
{
kill(Messenger.s("Killed"));
}
public void kill(Text reason)
{
this.server.send(new ServerTask(this.server.getTicks(), () -> {
this.networkHandler.onDisconnected(Messenger.s("Killed"));
this.networkHandler.onDisconnected(reason);
}));
}
@@ -118,7 +124,7 @@ public class EntityPlayerMPFake extends ServerPlayerEntity
super.onDeath(cause);
setHealth(20);
this.hungerManager = new HungerManager();
kill();
kill(this.getDamageTracker().getDeathMessage());
}
@Override
@@ -6,6 +6,7 @@ import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
public class NetHandlerPlayServerFake extends ServerPlayNetworkHandler
{
@@ -22,6 +23,10 @@ public class NetHandlerPlayServerFake extends ServerPlayNetworkHandler
@Override
public void disconnect(Text message)
{
if (player instanceof EntityPlayerMPFake && message instanceof TranslatableText && ((TranslatableText) message).getKey().equals("multiplayer.disconnect.idling"))
{
((EntityPlayerMPFake) player).kill(new TranslatableText(((TranslatableText) message).getKey()));
}
}
}
@@ -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;
@@ -292,3 +292,14 @@ __on_player_picks_up_item(player, item) ->
print(' Player '+player+' injects '+item);
);
__on_player_trades(player, entity, buy, buyB, sell) ->
(
print('');
print('__on_player_trades(player, item)');
print('player trades:');
print(' - player: '+player);
print(' - entity: '+ entity);
print(' - buy: '+ buy);
print(' - buyB: '+ buyB);
print(' - sell: '+ sell);
);
+1
View File
@@ -166,6 +166,7 @@
"BlockItem_scarpetEventMixin",
"PlayerManager_scarpetEventsMixin",
"PlayerInventory_scarpetEventMixin",
"TradeOutputSlot_scarpetEventMixin",
"ChunkTicketManager_scarpetMixin",
"StatType_scarpetMixin",