Merge branch 'master' into future
# Conflicts: # gradle.properties # src/main/java/carpet/script/annotation/AnnotationParser.java # src/main/java/carpet/script/utils/BiomeInfo.java # src/main/resources/fabric.mod.json
This commit is contained in:
commit
529a5b358d
38 files changed
+247
-381
No files matched your search
@@ -1,10 +1,8 @@
|
||||
package carpet.script.value;
|
||||
|
||||
import carpet.fakes.BrainInterface;
|
||||
import carpet.fakes.EntityInterface;
|
||||
import carpet.fakes.ItemEntityInterface;
|
||||
import carpet.fakes.LivingEntityInterface;
|
||||
import carpet.fakes.MemoryInterface;
|
||||
import carpet.fakes.MobEntityInterface;
|
||||
import carpet.fakes.ServerPlayerEntityInterface;
|
||||
import carpet.fakes.ServerPlayerInteractionManagerInterface;
|
||||
@@ -633,11 +631,11 @@ public class EntityValue extends Value
|
||||
if (e instanceof LivingEntity livingEntity)
|
||||
{
|
||||
Brain<?> brain = livingEntity.getBrain();
|
||||
Map<MemoryModuleType<?>, Optional<? extends Memory<?>>> memories = ((BrainInterface)brain).getMobMemories();
|
||||
Map<MemoryModuleType<?>, Optional<? extends Memory<?>>> memories = brain.getMemories();
|
||||
Optional<? extends Memory<?>> optmemory = memories.get(moduleType);
|
||||
if (optmemory==null || !optmemory.isPresent()) return Value.NULL;
|
||||
Memory<?> memory = optmemory.get();
|
||||
return ValueConversions.fromTimedMemory(e, ((MemoryInterface)memory).getScarpetExpiry(), memory.getValue());
|
||||
return ValueConversions.fromTimedMemory(e, memory.getExpiry(), memory.getValue());
|
||||
}
|
||||
return Value.NULL;
|
||||
});
|
||||
@@ -1584,7 +1582,7 @@ public class EntityValue extends Value
|
||||
});
|
||||
|
||||
put("absorption", (e, v) -> {
|
||||
if (e instanceof PlayerEntity) ((PlayerEntity) e).setAbsorptionAmount((float) NumericValue.asNumber(v, "absorbtion").getLong());
|
||||
if (e instanceof PlayerEntity) ((PlayerEntity) e).setAbsorptionAmount(NumericValue.asNumber(v, "absorbtion").getFloat());
|
||||
});
|
||||
|
||||
put("add_xp", (e, v) -> {
|
||||
|
||||
@@ -19,18 +19,29 @@ public class ThreadValue extends Value
|
||||
private final long id;
|
||||
private static long sequence = 0L;
|
||||
|
||||
public ThreadValue(CompletableFuture<Value> taskFuture)
|
||||
{
|
||||
this.taskFuture = taskFuture;
|
||||
this.id = sequence++;
|
||||
}
|
||||
|
||||
public ThreadValue(Value pool, FunctionValue function, Expression expr, Tokenizer.Token token, Context ctx, List<Value> args)
|
||||
{
|
||||
id = sequence++;
|
||||
this(getCompletableFutureFromFunction(pool, function, expr, token, ctx, args));
|
||||
Thread.yield();
|
||||
}
|
||||
|
||||
public static CompletableFuture<Value> getCompletableFutureFromFunction(Value pool, FunctionValue function, Expression expr, Tokenizer.Token token, Context ctx, List<Value> args)
|
||||
{
|
||||
ExecutorService executor = ctx.host.getExecutor(pool);
|
||||
if (executor == null)
|
||||
{
|
||||
// app is shutting down - no more threads can be spawned.
|
||||
taskFuture = CompletableFuture.completedFuture(Value.NULL);
|
||||
return CompletableFuture.completedFuture(Value.NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
taskFuture = CompletableFuture.supplyAsync(
|
||||
return CompletableFuture.supplyAsync(
|
||||
() ->
|
||||
{
|
||||
try
|
||||
@@ -52,7 +63,6 @@ public class ThreadValue extends Value
|
||||
ctx.host.getExecutor(pool)
|
||||
);
|
||||
}
|
||||
Thread.yield();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user