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; package carpet.mixins;
import carpet.fakes.BrainInterface; import carpet.fakes.BrainInterface;
import carpet.fakes.MemoryInterface;
import carpet.helpers.ParticleDisplay; import carpet.helpers.ParticleDisplay;
import carpet.utils.Messenger; import carpet.utils.Messenger;
import carpet.utils.MobAI; import carpet.utils.MobAI;
@@ -69,8 +70,7 @@ public abstract class VillagerEntity_aiMixin extends AbstractTraderEntity
} }
else else
{ {
String serialized = last_seen.get().toString(); time = ((MemoryInterface)last_seen.get()).getScarpetExpiry();
time = Integer.parseInt(serialized.substring(11, serialized.length()-1));
} }
boolean recentlySeen = time > 0; boolean recentlySeen = time > 0;
Optional<Long> optional_11 = this.brain.getOptionalMemory(MemoryModuleType.LAST_SLEPT); Optional<Long> optional_11 = this.brain.getOptionalMemory(MemoryModuleType.LAST_SLEPT);
@@ -1,8 +1,10 @@
package carpet.script.value; package carpet.script.value;
import carpet.fakes.BrainInterface;
import carpet.fakes.EntityInterface; import carpet.fakes.EntityInterface;
import carpet.fakes.ItemEntityInterface; import carpet.fakes.ItemEntityInterface;
import carpet.fakes.LivingEntityInterface; import carpet.fakes.LivingEntityInterface;
import carpet.fakes.MemoryInterface;
import carpet.fakes.MobEntityInterface; import carpet.fakes.MobEntityInterface;
import carpet.fakes.HungerManagerInterface; import carpet.fakes.HungerManagerInterface;
import carpet.helpers.Tracer; import carpet.helpers.Tracer;
@@ -13,6 +15,8 @@ import carpet.script.argument.Vector3Argument;
import carpet.script.exception.InternalExpressionException; import carpet.script.exception.InternalExpressionException;
import com.mojang.brigadier.StringReader; import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException; 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.brain.MemoryModuleType;
import net.minecraft.entity.ai.pathing.Path; import net.minecraft.entity.ai.pathing.Path;
import net.minecraft.nbt.StringTag; import net.minecraft.nbt.StringTag;
@@ -350,9 +354,12 @@ public class EntityValue extends Value
if (e instanceof LivingEntity) if (e instanceof LivingEntity)
{ {
LivingEntity livingEntity = (LivingEntity)e; LivingEntity livingEntity = (LivingEntity)e;
Optional<?> memory = livingEntity.getBrain().getOptionalMemory(moduleType); Brain<?> brain = livingEntity.getBrain();
if (memory==null || !memory.isPresent()) return Value.NULL; Map<MemoryModuleType<?>, Optional<? extends Memory<?>>> memories = ((BrainInterface)brain).getMobMemories();
return ValueConversions.fromEntityMemory(e, memory.get()); 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; return Value.NULL;
}); });
@@ -70,7 +70,14 @@ public class ValueConversions
return ListValue.wrap(nodes); 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) if (v instanceof GlobalPos)
{ {
+1
View File
@@ -56,6 +56,7 @@
"VillagerEntity_aiMixin", "VillagerEntity_aiMixin",
"Brain_Mixin", "Brain_Mixin",
"Memory_scarpetMixin",
"ServerWorld_fakePlayersMixin", "ServerWorld_fakePlayersMixin",
"ThrownEnderpearlEntity_fakePlayersMixin", "ThrownEnderpearlEntity_fakePlayersMixin",