Merge branch 'master' into 1.15

This commit is contained in:
gnembon committed 2019-09-04 22:06:05 -03:00
commit 2fcef289f0
10 files changed
+127 -33

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;
@@ -291,11 +292,7 @@ public class CarpetEventServer
ItemStack itemstack = player.getStackInHand(enumhand);
return Arrays.asList(
((c, t) -> new EntityValue(player)),
((c, t) -> ListValue.of(
new StringValue(Registry.ITEM.getId(itemstack.getItem()).getPath()),
new NumericValue(itemstack.getCount()),
new StringValue(itemstack.toTag(new CompoundTag()).toString())
)),
((c, t) -> ListValue.fromItemStack(itemstack)),
((c, t) -> new StringValue(enumhand == Hand.MAIN_HAND ? "mainhand" : "offhand"))
);
}, player::getCommandSource);
@@ -320,11 +317,7 @@ public class CarpetEventServer
Vec3d vec3d = hitRes.getPos().subtract(blockpos.getX(), blockpos.getY(), blockpos.getZ());
return Arrays.asList(
((c, t) -> new EntityValue(player)),
((c, t) -> ListValue.of(
new StringValue(Registry.ITEM.getId(itemstack.getItem()).getPath()),
new NumericValue(itemstack.getCount()),
new StringValue(itemstack.toTag(new CompoundTag()).toString())
)),
((c, t) -> ListValue.fromItemStack(itemstack)),
((c, t) -> new StringValue(enumhand == Hand.MAIN_HAND ? "mainhand" : "offhand")),
((c, t) -> new BlockValue(null, player.world, blockpos)),
((c, t) -> new StringValue(enumfacing.getName())),
@@ -390,6 +383,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 +402,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;
@@ -214,8 +215,9 @@ public class EntityValue extends Value
put("width", (e, a) -> new NumericValue(e.getDimensions(EntityPose.STANDING).width));
put("eye_height", (e, a) -> new NumericValue(e.getEyeHeight(EntityPose.STANDING)));
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("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("pickup_delay", (e, a) -> (e instanceof ItemEntity)?new NumericValue(((ItemEntityInterface) e).getPickupDelay()):Value.NULL);
// ItemEntity -> despawn timer via ssGetAge
put("is_baby", (e, a) -> (e instanceof LivingEntity)?new NumericValue(((LivingEntity) e).isBaby()):Value.NULL);
put("target", (e, a) -> {
@@ -691,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
@@ -720,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));
}};
}