Merge branch 'master' into 1.17
This commit is contained in:
commit
988357317a
13 files changed
+111
-8
No files matched your search
@@ -0,0 +1,5 @@
|
||||
package carpet.fakes;
|
||||
|
||||
public interface ClientSettingsC2SPacketInterface {
|
||||
public String getLanguage();
|
||||
}
|
||||
@@ -7,5 +7,5 @@ public interface ServerPlayerEntityInterface
|
||||
EntityPlayerActionPack getActionPack();
|
||||
void invalidateEntityObjectReference();
|
||||
boolean isInvalidEntityObject();
|
||||
|
||||
String getLanguage();
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.fakes.ClientSettingsC2SPacketInterface;
|
||||
import net.minecraft.network.packet.c2s.play.ClientSettingsC2SPacket;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
@Mixin(ClientSettingsC2SPacket.class)
|
||||
public class ClientSettingsC2SPacket_scarpetMixin implements ClientSettingsC2SPacketInterface {
|
||||
@Shadow
|
||||
private String language;
|
||||
|
||||
@Override
|
||||
public String getLanguage(){
|
||||
return this.language;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.fakes.ClientSettingsC2SPacketInterface;
|
||||
import carpet.fakes.EntityInterface;
|
||||
import carpet.fakes.ServerPlayerEntityInterface;
|
||||
import carpet.script.EntityEventsGroup;
|
||||
@@ -7,6 +8,7 @@ import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.damage.DamageSource;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.network.packet.c2s.play.ClientSettingsC2SPacket;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.stat.Stat;
|
||||
@@ -126,4 +128,16 @@ public abstract class ServerPlayerEntity_scarpetEventMixin extends PlayerEntity
|
||||
{
|
||||
return isInvalidReference;
|
||||
}
|
||||
|
||||
//getting player language
|
||||
private String language;
|
||||
|
||||
public String getLanguage(){
|
||||
return this.language;
|
||||
}
|
||||
|
||||
@Inject(method = "setClientSettings", at = @At("HEAD"))
|
||||
public void setClientSettings(ClientSettingsC2SPacket packet, CallbackInfo ci){
|
||||
this.language = ((ClientSettingsC2SPacketInterface) packet).getLanguage();
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ public class Throwables {
|
||||
public static final Throwables IO_EXCEPTION = register("io_exception", THROWN_EXCEPTION_TYPE);
|
||||
public static final Throwables NBT_ERROR = register("nbt_error", IO_EXCEPTION);
|
||||
public static final Throwables JSON_ERROR = register("json_error", IO_EXCEPTION);
|
||||
public static final Throwables B64_ERROR = register("b64_error", IO_EXCEPTION);
|
||||
public static final Throwables USER_DEFINED = register("user_exception", THROWN_EXCEPTION_TYPE);
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,6 +4,9 @@ import carpet.script.Context;
|
||||
import carpet.script.Expression;
|
||||
import carpet.script.LazyValue;
|
||||
import carpet.script.exception.InternalExpressionException;
|
||||
import carpet.script.exception.ThrowStatement;
|
||||
import carpet.script.exception.Throwables;
|
||||
import carpet.script.utils.ScarpetJsonDeserializer;
|
||||
import carpet.script.value.ContainerValueInterface;
|
||||
import carpet.script.value.LContainerValue;
|
||||
import carpet.script.value.LazyListValue;
|
||||
@@ -12,8 +15,12 @@ import carpet.script.value.MapValue;
|
||||
import carpet.script.value.NumericValue;
|
||||
import carpet.script.value.StringValue;
|
||||
import carpet.script.value.Value;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Base64;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -320,5 +327,23 @@ public class DataStructures {
|
||||
Value ret = new NumericValue(((ContainerValueInterface) container).delete(lv.get(lv.size()-1).evalValue(c)));
|
||||
return (cc, tt) -> ret;
|
||||
});
|
||||
|
||||
expression.addUnaryFunction("encode_b64", v -> StringValue.of(Base64.getEncoder().encodeToString(v.getString().getBytes())));
|
||||
expression.addUnaryFunction("decode_b64", v -> {
|
||||
try {
|
||||
return StringValue.of(new String(Base64.getDecoder().decode(v.getString()), StandardCharsets.ISO_8859_1));//using this charset cos it's the one used in decoding function
|
||||
} catch (IllegalArgumentException iae){
|
||||
throw new ThrowStatement("Invalid b64 string: " + v.getString(), Throwables.B64_ERROR);
|
||||
}
|
||||
});
|
||||
|
||||
expression.addUnaryFunction("encode_json", v -> StringValue.of(v.toJson().toString()));
|
||||
expression.addUnaryFunction("decode_json", v -> {
|
||||
try {
|
||||
return new ScarpetJsonDeserializer().deserialize(new JsonParser().parse(v.getString()), null, null);
|
||||
} catch (JsonParseException jpe){
|
||||
throw new ThrowStatement("Invalid json string: " + v.getString(), Throwables.JSON_ERROR);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -551,6 +551,12 @@ public class EntityValue extends Value
|
||||
});
|
||||
|
||||
put("air", (e, a) -> new NumericValue(e.getAir()));
|
||||
put("language", (e, a)->{
|
||||
if(!(e instanceof ServerPlayerEntity))
|
||||
return NULL;
|
||||
String lang = ((ServerPlayerEntityInterface) e).getLanguage();
|
||||
return StringValue.of(lang);
|
||||
});
|
||||
put("persistence", (e, a) -> {
|
||||
if (e instanceof MobEntity) return new NumericValue(((MobEntity) e).isPersistent());
|
||||
return Value.NULL;
|
||||
|
||||
Reference in new issue
Block a user