Adding absorption and xp API, and weather control (#540)
* fixes #537 * fixes #547
This commit is contained in:
1 parent
8acb322747
commit
42e67f27b7
9 files changed
+184
-20
No files matched your search
@@ -469,28 +469,42 @@ public class Auxiliary {
|
||||
if (lv.size() == 0 || lv.size() > 2) throw new InternalExpressionException("'print' takes one or two arguments");
|
||||
ServerCommandSource s = ((CarpetContext)c).s;
|
||||
Value res = lv.get(0).evalValue(c);
|
||||
if (lv.size() == 2)
|
||||
{
|
||||
ServerPlayerEntity player = EntityValue.getPlayerByValue(s.getMinecraftServer(), res);
|
||||
if (player == null) return LazyValue.NULL;
|
||||
s = player.getCommandSource();
|
||||
Value playersVal = Value.NULL;
|
||||
if (lv.size() == 2){
|
||||
playersVal = res;
|
||||
res = lv.get(1).evalValue(c);
|
||||
}
|
||||
if (res instanceof FormattedTextValue)
|
||||
{
|
||||
s.sendFeedback(((FormattedTextValue) res).getText(), false);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (s.getEntity() instanceof PlayerEntity)
|
||||
{
|
||||
Messenger.m((PlayerEntity) s.getEntity(), "w " + res.getString());
|
||||
|
||||
if(playersVal instanceof ListValue){
|
||||
|
||||
List<Value> players = ((ListValue) playersVal).getItems();
|
||||
for(Value playerVal:players){
|
||||
ServerPlayerEntity player = EntityValue.getPlayerByValue(s.getMinecraftServer(), playerVal);
|
||||
if (player == null) return LazyValue.NULL;
|
||||
if(res instanceof FormattedTextValue)
|
||||
player.getCommandSource().sendFeedback(((FormattedTextValue) res).getText(), false);
|
||||
else
|
||||
Messenger.m(player, "w "+res.getString());
|
||||
}
|
||||
|
||||
} else if(playersVal instanceof EntityValue){
|
||||
|
||||
ServerPlayerEntity player = EntityValue.getPlayerByValue(s.getMinecraftServer(), playersVal);
|
||||
if (player == null) return LazyValue.NULL;
|
||||
if(res instanceof FormattedTextValue)
|
||||
player.getCommandSource().sendFeedback(((FormattedTextValue) res).getText(), false);
|
||||
else
|
||||
Messenger.m(player, "w "+res.getString());
|
||||
|
||||
} else {
|
||||
|
||||
if (res instanceof FormattedTextValue)
|
||||
s.sendFeedback(((FormattedTextValue) res).getText(), false);
|
||||
else
|
||||
{
|
||||
Messenger.m(s, "w " + res.getString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Value finalRes = res;
|
||||
return (_c, _t) -> finalRes; // pass through for variables
|
||||
});
|
||||
|
||||
@@ -6,6 +6,7 @@ import carpet.fakes.BiomeArrayInterface;
|
||||
import carpet.fakes.ChunkGeneratorInterface;
|
||||
import carpet.fakes.ChunkTicketManagerInterface;
|
||||
import carpet.fakes.ServerChunkManagerInterface;
|
||||
import carpet.fakes.ServerWorldInterface;
|
||||
import carpet.fakes.SpawnHelperInnerInterface;
|
||||
import carpet.fakes.ThreadedAnvilChunkStorageInterface;
|
||||
import carpet.helpers.FeatureGenerator;
|
||||
@@ -58,6 +59,7 @@ import net.minecraft.item.SwordItem;
|
||||
import net.minecraft.item.TridentItem;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ChunkTicket;
|
||||
import net.minecraft.server.world.ChunkTicketType;
|
||||
@@ -89,6 +91,7 @@ import net.minecraft.world.gen.ChunkRandom;
|
||||
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.gen.feature.ConfiguredStructureFeature;
|
||||
import net.minecraft.world.gen.feature.StructureFeature;
|
||||
import net.minecraft.world.level.ServerWorldProperties;
|
||||
import net.minecraft.world.poi.PointOfInterest;
|
||||
import net.minecraft.world.poi.PointOfInterestStorage;
|
||||
import net.minecraft.world.poi.PointOfInterestType;
|
||||
@@ -413,6 +416,63 @@ public class WorldAccess {
|
||||
});
|
||||
|
||||
|
||||
expression.addLazyFunction("weather",-1,(c, t, lv) -> {
|
||||
ServerWorld world = ((CarpetContext) c).s.getWorld();
|
||||
|
||||
if(lv.size()==0)//cos it can thunder when raining or when clear.
|
||||
return (_c,_t)->new StringValue( world.isThundering()? "thunder" : (world.isRaining()? "rain":"clear"));
|
||||
|
||||
|
||||
Value weather = lv.get(0).evalValue(c);
|
||||
ServerWorldProperties worldProperties = ((ServerWorldInterface) world).getWorldPropertiesCM();
|
||||
|
||||
if(lv.size()==1) {
|
||||
int ticks;
|
||||
|
||||
switch (weather.getString()) {
|
||||
case "clear":
|
||||
ticks = worldProperties.getClearWeatherTime();
|
||||
break;
|
||||
case "rain":
|
||||
ticks = world.isRaining()? worldProperties.getRainTime():0;//cos if not it gives 1 for some reason
|
||||
break;
|
||||
case "thunder":
|
||||
ticks = world.isThundering()? worldProperties.getThunderTime():0;//same dealio here
|
||||
break;
|
||||
default:
|
||||
throw new InternalExpressionException("Weather can only be 'clear', 'rain' or 'thunder'");
|
||||
}
|
||||
return (_c,_t) -> new NumericValue(ticks);
|
||||
} else if(lv.size()==2){
|
||||
int ticks = ((NumericValue)lv.get(1).evalValue(c)).getInt();
|
||||
|
||||
switch (weather.getString()){
|
||||
case "clear":
|
||||
world.setWeather(ticks,0,false,false);
|
||||
break;
|
||||
|
||||
case "rain":
|
||||
world.setWeather(0,ticks,true,false);
|
||||
break;
|
||||
|
||||
case "thunder":
|
||||
world.setWeather(
|
||||
0,
|
||||
ticks,//this is used to set thunder time, idk why...
|
||||
true,
|
||||
true
|
||||
);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new InternalExpressionException("Weather can only be 'clear', 'rain' or 'thunder'");
|
||||
}
|
||||
|
||||
return LazyValue.TRUE;
|
||||
} else
|
||||
throw new InternalExpressionException("'weather' between 0 and 2 arguments");
|
||||
});
|
||||
|
||||
expression.addLazyFunction("pos", 1, (c, t, lv) ->
|
||||
{
|
||||
Value arg = lv.get(0).evalValue(c);
|
||||
|
||||
@@ -499,6 +499,31 @@ public class EntityValue extends Value
|
||||
return Value.NULL;
|
||||
});
|
||||
|
||||
put("absorption",(e, a)->{
|
||||
if(e instanceof PlayerEntity) return new NumericValue(((PlayerEntity) e).getAbsorptionAmount());
|
||||
return Value.NULL;
|
||||
});
|
||||
|
||||
put("xp",(e, a)->{
|
||||
if(e instanceof PlayerEntity) return new NumericValue(((PlayerEntity) e).totalExperience);
|
||||
return Value.NULL;
|
||||
});
|
||||
|
||||
put("xp_level", (e, a)->{
|
||||
if(e instanceof PlayerEntity) return new NumericValue(((PlayerEntity) e).experienceLevel);
|
||||
return Value.NULL;
|
||||
});
|
||||
|
||||
put("xp_progress", (e, a)->{
|
||||
if(e instanceof PlayerEntity) return new NumericValue(((PlayerEntity) e).experienceProgress);
|
||||
return Value.NULL;
|
||||
});
|
||||
|
||||
put("score", (e, a)->{
|
||||
if(e instanceof PlayerEntity) return new NumericValue(((PlayerEntity) e).getScore());
|
||||
return Value.NULL;
|
||||
});
|
||||
|
||||
put("jumping", (e, a) -> {
|
||||
if (e instanceof LivingEntity)
|
||||
{
|
||||
@@ -1328,8 +1353,24 @@ public class EntityValue extends Value
|
||||
if(e instanceof PlayerEntity) ((PlayerEntity) e).getHungerManager().addExhaustion((int) NumericValue.asNumber(v).getLong());
|
||||
});
|
||||
|
||||
put("absorption", (e, v) -> {
|
||||
if (e instanceof PlayerEntity) ((PlayerEntity) e).setAbsorptionAmount((float) NumericValue.asNumber(v).getLong());
|
||||
});
|
||||
|
||||
put("add_xp", (e, v) -> {
|
||||
if (e instanceof PlayerEntity) ((PlayerEntity) e).addExperience(NumericValue.asNumber(v).getInt());
|
||||
});
|
||||
|
||||
put("xp_level", (e, v) -> {
|
||||
if (e instanceof PlayerEntity) ((PlayerEntity) e).addExperienceLevels(NumericValue.asNumber(v).getInt()-((PlayerEntity) e).experienceLevel);
|
||||
});
|
||||
|
||||
put("xp_score", (e, v) -> {
|
||||
if (e instanceof PlayerEntity) ((PlayerEntity) e).setScore(NumericValue.asNumber(v).getInt());
|
||||
});
|
||||
|
||||
put("saturation", (e, v)-> {
|
||||
if(e instanceof PlayerEntity) ((PlayerEntity) e).getHungerManager().setSaturationLevelClient((float)NumericValue.asNumber(v).getLong());
|
||||
if(e instanceof PlayerEntity) ((PlayerEntity) e).getHungerManager().setSaturationLevelClient(NumericValue.asNumber(v).getFloat());
|
||||
});
|
||||
|
||||
put("air", (e, v) -> e.setAir(NumericValue.asNumber(v).getInt()));
|
||||
|
||||
Reference in new issue
Block a user