tweaks to entity API code
This commit is contained in:
1 parent
1aa237379e
commit
1e9a8726be
6 files changed
+72
-44
No files matched your search
@@ -2,6 +2,7 @@ package carpet.script.value;
|
||||
|
||||
import carpet.fakes.EntityInterface;
|
||||
import carpet.fakes.ItemEntityInterface;
|
||||
import carpet.fakes.LivingEntityInterface;
|
||||
import carpet.fakes.MobEntityInterface;
|
||||
import carpet.helpers.Tracer;
|
||||
import carpet.patches.EntityPlayerMPFake;
|
||||
@@ -61,7 +62,7 @@ import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static carpet.script.value.NBTSerializableValue.nameFromRegistryId;
|
||||
import static carpet.utils.MobAI.jump;
|
||||
import static carpet.utils.MobAI.genericJump;
|
||||
|
||||
// TODO: decide whether copy(entity) should duplicate entity in the world.
|
||||
public class EntityValue extends Value
|
||||
@@ -281,13 +282,13 @@ public class EntityValue extends Value
|
||||
put("sneaking", (e, a) -> e.isSneaking()?Value.TRUE:Value.FALSE);
|
||||
put("sprinting", (e, a) -> e.isSprinting()?Value.TRUE:Value.FALSE);
|
||||
put("swimming", (e, a) -> e.isSwimming()?Value.TRUE:Value.FALSE);
|
||||
/*put("jumping", (e, a) -> {
|
||||
put("jumping", (e, a) -> {
|
||||
if (e instanceof LivingEntity)
|
||||
{
|
||||
return ((LivingEntity) e).getJumping()?Value.TRUE:Value.FALSE;
|
||||
return ((LivingEntityInterface) e).isJumpingCM()?Value.TRUE:Value.FALSE;
|
||||
}
|
||||
return Value.NULL;
|
||||
});*/ //needs mixing
|
||||
});
|
||||
put("gamemode", (e, a) -> {
|
||||
if (e instanceof ServerPlayerEntity)
|
||||
{
|
||||
@@ -376,6 +377,7 @@ public class EntityValue extends Value
|
||||
StatusEffectInstance pe = ((LivingEntity) e).getStatusEffect(potion);
|
||||
return ListValue.of( new NumericValue(pe.getAmplifier()), new NumericValue(pe.getDuration()) );
|
||||
});
|
||||
|
||||
put("health", (e, a) ->
|
||||
{
|
||||
if (e instanceof LivingEntity)
|
||||
@@ -531,8 +533,6 @@ public class EntityValue extends Value
|
||||
//((ServerWorld)e.getEntityWorld()).method_14178().sendToNearbyPlayers(e, new EntityVelocityUpdateS2CPacket(e));
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static final Map<String, BiConsumer<Entity, Value>> featureModifiers = new HashMap<String, BiConsumer<Entity, Value>>() {{
|
||||
put("remove", (entity, value) -> entity.remove());
|
||||
put("age", (e, v) -> e.age = Math.abs((int)NumericValue.asNumber(v).getLong()) );
|
||||
@@ -896,25 +896,27 @@ public class EntityValue extends Value
|
||||
});
|
||||
|
||||
put("gamemode", (e,v)->{
|
||||
if(!(e instanceof ServerPlayerEntity)){
|
||||
return;
|
||||
}
|
||||
switch(v.getString().toLowerCase()){
|
||||
case "survival": case "0":((ServerPlayerEntity) e).setGameMode(GameMode.SURVIVAL);break;
|
||||
case "creative": case "1":((ServerPlayerEntity) e).setGameMode(GameMode.CREATIVE);break;
|
||||
case "adventure": case "2":((ServerPlayerEntity) e).setGameMode(GameMode.ADVENTURE);break;
|
||||
case "spectator": case "3":((ServerPlayerEntity) e).setGameMode(GameMode.SPECTATOR);break;
|
||||
}
|
||||
if(!(e instanceof ServerPlayerEntity)) return;
|
||||
GameMode toSet = v instanceof NumericValue ?
|
||||
GameMode.byId(((NumericValue) v).getInt(), null) :
|
||||
GameMode.byName(v.getString().toLowerCase(Locale.ROOT), null);
|
||||
if (toSet != null) ((ServerPlayerEntity) e).setGameMode(toSet);
|
||||
});
|
||||
|
||||
put("jumping",(e,v)->{
|
||||
if(!(e instanceof LivingEntity)) return;
|
||||
|
||||
((LivingEntity) e).setJumping(v.getBoolean());
|
||||
});
|
||||
|
||||
put("jump",(e,v)->{
|
||||
jump((LivingEntity)e);
|
||||
if (e instanceof LivingEntity)
|
||||
{
|
||||
((LivingEntityInterface)e).doJumpCM();
|
||||
}
|
||||
else
|
||||
{
|
||||
genericJump(e);
|
||||
}
|
||||
});
|
||||
|
||||
put("silent",(e,v)->{
|
||||
@@ -933,10 +935,6 @@ public class EntityValue extends Value
|
||||
e.setFireTicks((int)NumericValue.asNumber(v).getLong());
|
||||
});
|
||||
|
||||
put("age",(e,v)->{
|
||||
e.age=(int)NumericValue.asNumber(v).getLong();
|
||||
});
|
||||
|
||||
// gamemode [check]
|
||||
// spectate [check]
|
||||
// "fire" [check]
|
||||
|
||||
Reference in new issue
Block a user