adjusting to 1.16

This commit is contained in:
gnembon committed 2020-07-19 02:57:14 -03:00
1 parent c22c7b991a
commit 8833d33286
6 files changed
+45 -6

No files matched your search

@@ -0,0 +1,6 @@
package carpet.fakes;
public interface MemoryInterface
{
long getScarpetExpiry();
}
@@ -0,0 +1,18 @@
package carpet.mixins;
import carpet.fakes.MemoryInterface;
import net.minecraft.entity.ai.brain.Memory;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@Mixin(Memory.class)
public class Memory_scarpetMixin implements MemoryInterface
{
@Shadow private long expiry;
@Override
public long getScarpetExpiry()
{
return expiry;
}
}
@@ -1,6 +1,7 @@
package carpet.mixins;
import carpet.fakes.BrainInterface;
import carpet.fakes.MemoryInterface;
import carpet.helpers.ParticleDisplay;
import carpet.utils.Messenger;
import carpet.utils.MobAI;
@@ -69,8 +70,7 @@ public abstract class VillagerEntity_aiMixin extends AbstractTraderEntity
}
else
{
String serialized = last_seen.get().toString();
time = Integer.parseInt(serialized.substring(11, serialized.length()-1));
time = ((MemoryInterface)last_seen.get()).getScarpetExpiry();
}
boolean recentlySeen = time > 0;
Optional<Long> optional_11 = this.brain.getOptionalMemory(MemoryModuleType.LAST_SLEPT);
@@ -1,8 +1,10 @@
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.HungerManagerInterface;
import carpet.helpers.Tracer;
@@ -13,6 +15,8 @@ import carpet.script.argument.Vector3Argument;
import carpet.script.exception.InternalExpressionException;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.entity.ai.brain.Brain;
import net.minecraft.entity.ai.brain.Memory;
import net.minecraft.entity.ai.brain.MemoryModuleType;
import net.minecraft.entity.ai.pathing.Path;
import net.minecraft.nbt.StringTag;
@@ -350,9 +354,12 @@ public class EntityValue extends Value
if (e instanceof LivingEntity)
{
LivingEntity livingEntity = (LivingEntity)e;
Optional<?> memory = livingEntity.getBrain().getOptionalMemory(moduleType);
if (memory==null || !memory.isPresent()) return Value.NULL;
return ValueConversions.fromEntityMemory(e, memory.get());
Brain<?> brain = livingEntity.getBrain();
Map<MemoryModuleType<?>, Optional<? extends Memory<?>>> memories = ((BrainInterface)brain).getMobMemories();
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 Value.NULL;
});
@@ -70,7 +70,14 @@ public class ValueConversions
return ListValue.wrap(nodes);
}
public static Value fromEntityMemory(Entity e, Object v)
public static Value fromTimedMemory(Entity e, long expiry, Object v)
{
Value ret = fromEntityMemory(e, v);
if (ret == Value.NULL || expiry == Long.MAX_VALUE) return ret;
return ListValue.of(ret, new NumericValue(expiry));
}
private static Value fromEntityMemory(Entity e, Object v)
{
if (v instanceof GlobalPos)
{