more entity events and entity item api
This commit is contained in:
1 parent
25b37913f2
commit
06b3f7c532
9 files changed
+121
-21
No files matched your search
@@ -9,6 +9,7 @@ import carpet.script.value.StringValue;
|
||||
import carpet.script.value.Value;
|
||||
import carpet.settings.CarpetSettings;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.damage.DamageSource;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.entity.Entity;
|
||||
@@ -390,6 +391,15 @@ public class CarpetEventServer
|
||||
{
|
||||
return makeEventCall(cc, function, extraArgs, 1);
|
||||
}
|
||||
public ScheduledCall makeTickCall(CarpetContext cc, String function, List<Value> extraArgs)
|
||||
{
|
||||
return makeEventCall(cc, function, extraArgs, 1);
|
||||
}
|
||||
public ScheduledCall makeDamageCall(CarpetContext cc, String function, List<Value> extraArgs)
|
||||
{
|
||||
return makeEventCall(cc, function, extraArgs, 3);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void onEntityDeath(ScheduledCall call, Entity e, String reason)
|
||||
@@ -400,5 +410,20 @@ public class CarpetEventServer
|
||||
{
|
||||
removeCall.execute(Collections.singletonList((c, t) -> new EntityValue(entity)));
|
||||
}
|
||||
public void onEntityTick(ScheduledCall tickCall, Entity entity)
|
||||
{
|
||||
tickCall.execute(Collections.singletonList((c, t) -> new EntityValue(entity)));
|
||||
}
|
||||
public void onEntityDamage(ScheduledCall call, Entity e, float amount, DamageSource source)
|
||||
{
|
||||
call.execute(Arrays.asList(
|
||||
(c, t) -> new EntityValue(e),
|
||||
(c, t) -> new NumericValue(amount),
|
||||
(c, t) -> new StringValue(source.getName()),
|
||||
(c, t) -> source.getAttacker()==null?Value.NULL:new EntityValue(source.getAttacker())
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package carpet.script.value;
|
||||
|
||||
import carpet.fakes.EntityInterface;
|
||||
import carpet.fakes.ItemEntityInterface;
|
||||
import carpet.fakes.MobEntityInterface;
|
||||
import carpet.helpers.Tracer;
|
||||
import carpet.script.CarpetContext;
|
||||
@@ -216,8 +217,8 @@ public class EntityValue extends Value
|
||||
put("age", (e, a) -> new NumericValue(e.age));
|
||||
put("item", (e, a) -> (e instanceof ItemEntity)?new StringValue(((ItemEntity) e).getStack().getName().getString()):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).getPickupDelay()):Value.NULL);
|
||||
// ItemEntity -> despawn timer via ssGetAge
|
||||
// TODO item pickup delay read and write
|
||||
put("is_baby", (e, a) -> (e instanceof LivingEntity)?new NumericValue(((LivingEntity) e).isBaby()):Value.NULL);
|
||||
put("target", (e, a) -> {
|
||||
if (e instanceof MobEntity)
|
||||
@@ -692,6 +693,13 @@ public class EntityValue extends Value
|
||||
}
|
||||
}); //requires mixing
|
||||
|
||||
put("pickup_delay", (e, v) ->
|
||||
{
|
||||
if (e instanceof ItemEntity)
|
||||
{
|
||||
((ItemEntity) e).setPickupDelay((int)NumericValue.asNumber(v).getLong());
|
||||
}
|
||||
});
|
||||
|
||||
// gamemode
|
||||
// spectate
|
||||
@@ -721,5 +729,7 @@ public class EntityValue extends Value
|
||||
private static Map<String, Fluff.QuadConsumer<CarpetContext, Entity, String, List<Value>>> events = new HashMap<String, Fluff.QuadConsumer<CarpetContext, Entity, String, List<Value>>>() {{
|
||||
put("on_death", (c, e, f, l) -> ((EntityInterface)e).setDeathCallback(c, f, l));
|
||||
put("on_removed", (c, e, f, l) -> ((EntityInterface)e).setRemovedCallback(c, f, l));
|
||||
put("on_tick", (c, e, f, l) -> ((EntityInterface)e).setTickCallback(c, f, l));
|
||||
put("on_damage", (c, e, f, l) -> ((EntityInterface)e).setDamageCallback(c, f, l));
|
||||
}};
|
||||
}
|
||||
Reference in new issue
Block a user