added 'portal_cooldown' and 'portal_timer' to entity API (query and modify)

This commit is contained in:
gnembon committed 2020-05-20 02:09:57 -03:00
1 parent 66c222a77a
commit ab86fc9292
5 files changed
+65

No files matched your search

+16
View File
@@ -2526,6 +2526,14 @@ Breeding age of passive entity, in ticks. If negative, time to adulthood, if pos
For living entities, the number of ticks they fall outside of immediate player presence. For living entities, the number of ticks they fall outside of immediate player presence.
### `query(e, 'portal_cooldown')`
Number of ticks remaining until an entity can use a portal again.
### `query(e, 'portal_timer')`
Number of ticks an entity sits in a portal.
### `query(e, 'item')` ### `query(e, 'item')`
The item triple (name, count, nbt) if its an item entity, `null` otherwise The item triple (name, count, nbt) if its an item entity, `null` otherwise
@@ -2739,6 +2747,14 @@ Sets the breeding age for the animal.
Sets a custom despawn timer value. Sets a custom despawn timer value.
### `modify(e, 'portal_cooldown', number)`
Sets a custom number of ticks remaining until an entity can use a portal again.
### `modify(e, 'portal_timer', number)`
Sets a custom number of ticks an entity sits in a portal.
### `modify(e, 'dismount')` ### `modify(e, 'dismount')`
Dismounts riding entity. Dismounts riding entity.
+16
View File
@@ -204,6 +204,14 @@ Breeding age of passive entity, in ticks. If negative, time to adulthood, if pos
For living entities, the number of ticks they fall outside of immediate player presence. For living entities, the number of ticks they fall outside of immediate player presence.
### `query(e, 'portal_cooldown')`
Number of ticks remaining until an entity can use a portal again.
### `query(e, 'portal_timer')`
Number of ticks an entity sits in a portal.
### `query(e, 'item')` ### `query(e, 'item')`
The item triple (name, count, nbt) if its an item entity, `null` otherwise The item triple (name, count, nbt) if its an item entity, `null` otherwise
@@ -417,6 +425,14 @@ Sets the breeding age for the animal.
Sets a custom despawn timer value. Sets a custom despawn timer value.
### `modify(e, 'portal_cooldown', number)`
Sets a custom number of ticks remaining until an entity can use a portal again.
### `modify(e, 'portal_timer', number)`
Sets a custom number of ticks an entity sits in a portal.
### `modify(e, 'dismount')` ### `modify(e, 'dismount')`
Dismounts riding entity. Dismounts riding entity.
@@ -11,4 +11,8 @@ public interface EntityInterface
boolean isPermanentVehicle(); boolean isPermanentVehicle();
void setPermanentVehicle(boolean permanent); void setPermanentVehicle(boolean permanent);
int getPortalTimer();
void setPortalTimer(int amount);
} }
@@ -14,6 +14,7 @@ public abstract class Entity_scarpetEventsMixin implements EntityInterface
{ {
@Shadow public boolean removed; @Shadow public boolean removed;
@Shadow protected int netherPortalTime;
private boolean permanentVehicle; private boolean permanentVehicle;
private final EntityEventsGroup events = new EntityEventsGroup(); private final EntityEventsGroup events = new EntityEventsGroup();
@@ -36,6 +37,18 @@ public abstract class Entity_scarpetEventsMixin implements EntityInterface
permanentVehicle = permanent; permanentVehicle = permanent;
} }
@Override
public int getPortalTimer()
{
return netherPortalTime;
}
@Override
public void setPortalTimer(int amount)
{
netherPortalTime = amount;
}
@Inject(method = "tick", at = @At("HEAD")) @Inject(method = "tick", at = @At("HEAD"))
private void onTickCall(CallbackInfo ci) private void onTickCall(CallbackInfo ci)
{ {
@@ -259,6 +259,8 @@ public class EntityValue extends Value
put("item", (e, a) -> (e instanceof ItemEntity)?ListValue.fromItemStack(((ItemEntity) e).getStack()):Value.NULL); put("item", (e, a) -> (e instanceof ItemEntity)?ListValue.fromItemStack(((ItemEntity) e).getStack()):Value.NULL);
put("count", (e, a) -> (e instanceof ItemEntity)?new NumericValue(((ItemEntity) e).getStack().getCount()):Value.NULL); put("count", (e, a) -> (e instanceof ItemEntity)?new NumericValue(((ItemEntity) e).getStack().getCount()):Value.NULL);
put("pickup_delay", (e, a) -> (e instanceof ItemEntity)?new NumericValue(((ItemEntityInterface) e).getPickupDelayCM()):Value.NULL); put("pickup_delay", (e, a) -> (e instanceof ItemEntity)?new NumericValue(((ItemEntityInterface) e).getPickupDelayCM()):Value.NULL);
put("portal_cooldown", (e , a) ->new NumericValue(((EntityInterface)e).getPortalTimer()));
put("portal_timer", (e , a) ->new NumericValue(e.netherPortalCooldown));
// ItemEntity -> despawn timer via ssGetAge // ItemEntity -> despawn timer via ssGetAge
put("is_baby", (e, a) -> (e instanceof LivingEntity)?new NumericValue(((LivingEntity) e).isBaby()):Value.NULL); put("is_baby", (e, a) -> (e instanceof LivingEntity)?new NumericValue(((LivingEntity) e).isBaby()):Value.NULL);
put("target", (e, a) -> { put("target", (e, a) -> {
@@ -825,6 +827,20 @@ public class EntityValue extends Value
} }
}); });
put("portal_cooldown", (e , v) ->
{
if (v==null)
throw new InternalExpressionException("'portal_cooldown' requires a value to set");
e.netherPortalCooldown = NumericValue.asNumber(v).getInt();
});
put("portal_timer", (e , v) ->
{
if (v==null)
throw new InternalExpressionException("'portal_timer' requires a value to set");
((EntityInterface) e).setPortalTimer(NumericValue.asNumber(v).getInt());
});
put("ai", (e, v) -> put("ai", (e, v) ->
{ {
if (e instanceof MobEntity) if (e instanceof MobEntity)